evolution-3.6.4/mail/e-mail-account-tree-view.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-account-tree-view.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-account-tree-view.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-account-tree-view.c
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #include "e-mail-account-tree-view.h"
 20 
 21 #include <config.h>
 22 #include <glib/gi18n-lib.h>
 23 
 24 #define E_MAIL_ACCOUNT_TREE_VIEW_GET_PRIVATE(obj) \
 25 	(G_TYPE_INSTANCE_GET_PRIVATE \
 26 	((obj), E_TYPE_MAIL_ACCOUNT_TREE_VIEW, EMailAccountTreeViewPrivate))
 27 
 28 struct _EMailAccountTreeViewPrivate {
 29 	gint placeholder;
 30 };
 31 
 32 enum {
 33 	ENABLE,
 34 	DISABLE,
 35 	LAST_SIGNAL
 36 };
 37 
 38 static guint signals[LAST_SIGNAL];
 39 
 40 G_DEFINE_TYPE (
 41 	EMailAccountTreeView,
 42 	e_mail_account_tree_view,
 43 	GTK_TYPE_TREE_VIEW)
 44 
 45 static void
 46 mail_account_tree_view_enabled_toggled_cb (GtkCellRendererToggle *cell_renderer,
 47                                            const gchar *path_string,
 48                                            EMailAccountTreeView *tree_view)
 49 {
 50 	GtkTreeSelection *selection;
 51 	GtkTreePath *path;
 52 
 53 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
 54 
 55 	/* Change the selection first so we act on the correct service. */
 56 	path = gtk_tree_path_new_from_string (path_string);
 57 	gtk_tree_selection_select_path (selection, path);
 58 	gtk_tree_path_free (path);
 59 
 60 	if (gtk_cell_renderer_toggle_get_active (cell_renderer))
 61 		g_signal_emit (tree_view, signals[DISABLE], 0);
 62 	else
 63 		g_signal_emit (tree_view, signals[ENABLE], 0);
 64 }
 65 
 66 static void
 67 mail_account_tree_view_constructed (GObject *object)
 68 {
 69 	GtkTreeView *tree_view;
 70 	GtkTreeViewColumn *column;
 71 	GtkCellRenderer *cell_renderer;
 72 
 73 	/* Chain up to parent's constructed() method. */
 74 	G_OBJECT_CLASS (e_mail_account_tree_view_parent_class)->
 75 		constructed (object);
 76 
 77 	tree_view = GTK_TREE_VIEW (object);
 78 
 79 	gtk_tree_view_set_reorderable (tree_view, TRUE);
 80 
 81 	/* Column: Enabled */
 82 
 83 	column = gtk_tree_view_column_new ();
 84 	gtk_tree_view_column_set_expand (column, FALSE);
 85 	gtk_tree_view_column_set_title (column, _("Enabled"));
 86 
 87 	cell_renderer = gtk_cell_renderer_toggle_new ();
 88 	gtk_tree_view_column_pack_start (column, cell_renderer, TRUE);
 89 
 90 	g_signal_connect (
 91 		cell_renderer, "toggled",
 92 		G_CALLBACK (mail_account_tree_view_enabled_toggled_cb),
 93 		tree_view);
 94 
 95 	gtk_tree_view_column_add_attribute (
 96 		column, cell_renderer, "active",
 97 		E_MAIL_ACCOUNT_STORE_COLUMN_ENABLED);
 98 
 99 	gtk_tree_view_column_add_attribute (
100 		column, cell_renderer, "visible",
101 		E_MAIL_ACCOUNT_STORE_COLUMN_ENABLED_VISIBLE);
102 
103 	gtk_tree_view_append_column (tree_view, column);
104 
105 	/* Column: Account Name */
106 
107 	column = gtk_tree_view_column_new ();
108 	gtk_tree_view_column_set_expand (column, TRUE);
109 	gtk_tree_view_column_set_title (column, _("Account Name"));
110 
111 	cell_renderer = gtk_cell_renderer_text_new ();
112 	g_object_set (cell_renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
113 	gtk_tree_view_column_pack_start (column, cell_renderer, FALSE);
114 
115 	gtk_tree_view_column_add_attribute (
116 		column, cell_renderer, "text",
117 		E_MAIL_ACCOUNT_STORE_COLUMN_DISPLAY_NAME);
118 
119 	cell_renderer = gtk_cell_renderer_pixbuf_new ();
120 	g_object_set (
121 		cell_renderer, "icon-name", "goa-panel",
122 		"stock-size", GTK_ICON_SIZE_MENU, NULL);
123 	gtk_tree_view_column_pack_start (column, cell_renderer, FALSE);
124 
125 	gtk_tree_view_column_add_attribute (
126 		column, cell_renderer, "visible",
127 		E_MAIL_ACCOUNT_STORE_COLUMN_ONLINE_ACCOUNT);
128 
129 	/* This renderer is just an empty space filler. */
130 	cell_renderer = gtk_cell_renderer_pixbuf_new ();
131 	gtk_tree_view_column_pack_start (column, cell_renderer, TRUE);
132 
133 	cell_renderer = gtk_cell_renderer_text_new ();
134 	g_object_set (cell_renderer, "text", _("Default"), NULL);
135 	gtk_tree_view_column_pack_end (column, cell_renderer, FALSE);
136 
137 	gtk_tree_view_column_add_attribute (
138 		column, cell_renderer, "visible",
139 		E_MAIL_ACCOUNT_STORE_COLUMN_DEFAULT);
140 
141 	cell_renderer = gtk_cell_renderer_pixbuf_new ();
142 	g_object_set (
143 		cell_renderer, "icon-name", "emblem-default",
144 		"stock-size", GTK_ICON_SIZE_MENU, NULL);
145 	gtk_tree_view_column_pack_end (column, cell_renderer, FALSE);
146 
147 	gtk_tree_view_column_add_attribute (
148 		column, cell_renderer, "visible",
149 		E_MAIL_ACCOUNT_STORE_COLUMN_DEFAULT);
150 
151 	gtk_tree_view_append_column (tree_view, column);
152 
153 	/* Column: Type */
154 
155 	column = gtk_tree_view_column_new ();
156 	gtk_tree_view_column_set_expand (column, FALSE);
157 	gtk_tree_view_column_set_title (column, _("Type"));
158 
159 	cell_renderer = gtk_cell_renderer_text_new ();
160 	gtk_tree_view_column_pack_start (column, cell_renderer, TRUE);
161 
162 	gtk_tree_view_column_add_attribute (
163 		column, cell_renderer, "text",
164 		E_MAIL_ACCOUNT_STORE_COLUMN_BACKEND_NAME);
165 
166 	gtk_tree_view_append_column (tree_view, column);
167 }
168 
169 static void
170 mail_account_tree_view_drag_end (GtkWidget *widget,
171                                  GdkDragContext *context)
172 {
173 	GtkTreeModel *tree_model;
174 
175 	/* Chain up to parent's drag_end() method. */
176 	GTK_WIDGET_CLASS (e_mail_account_tree_view_parent_class)->
177 		drag_end (widget, context);
178 
179 	tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
180 	g_return_if_fail (E_IS_MAIL_ACCOUNT_STORE (tree_model));
181 
182 	g_signal_emit_by_name (tree_model, "services-reordered", FALSE);
183 }
184 
185 static void
186 e_mail_account_tree_view_class_init (EMailAccountTreeViewClass *class)
187 {
188 	GObjectClass *object_class;
189 	GtkWidgetClass *widget_class;
190 
191 	g_type_class_add_private (class, sizeof (EMailAccountTreeViewPrivate));
192 
193 	object_class = G_OBJECT_CLASS (class);
194 	object_class->constructed = mail_account_tree_view_constructed;
195 
196 	widget_class = GTK_WIDGET_CLASS (class);
197 	widget_class->drag_end = mail_account_tree_view_drag_end;
198 
199 	signals[ENABLE] = g_signal_new (
200 		"enable",
201 		G_TYPE_FROM_CLASS (class),
202 		G_SIGNAL_RUN_LAST,
203 		G_STRUCT_OFFSET (EMailAccountTreeViewClass, enable),
204 		NULL, NULL,
205 		g_cclosure_marshal_VOID__VOID,
206 		G_TYPE_NONE, 0);
207 
208 	signals[DISABLE] = g_signal_new (
209 		"disable",
210 		G_TYPE_FROM_CLASS (class),
211 		G_SIGNAL_RUN_LAST,
212 		G_STRUCT_OFFSET (EMailAccountTreeViewClass, disable),
213 		NULL, NULL,
214 		g_cclosure_marshal_VOID__VOID,
215 		G_TYPE_NONE, 0);
216 }
217 
218 static void
219 e_mail_account_tree_view_init (EMailAccountTreeView *tree_view)
220 {
221 	tree_view->priv = E_MAIL_ACCOUNT_TREE_VIEW_GET_PRIVATE (tree_view);
222 }
223 
224 GtkWidget *
225 e_mail_account_tree_view_new (EMailAccountStore *store)
226 {
227 	g_return_val_if_fail (E_IS_MAIL_ACCOUNT_STORE (store), NULL);
228 
229 	return g_object_new (
230 		E_TYPE_MAIL_ACCOUNT_TREE_VIEW,
231 		"model", store, NULL);
232 }
233 
234 CamelService *
235 e_mail_account_tree_view_get_selected_service (EMailAccountTreeView *tree_view)
236 {
237 	GtkTreeSelection *selection;
238 	GtkTreeModel *tree_model;
239 	GtkTreeIter iter;
240 	CamelService *service;
241 	GValue value = G_VALUE_INIT;
242 	gint column;
243 
244 	g_return_val_if_fail (E_IS_MAIL_ACCOUNT_TREE_VIEW (tree_view), NULL);
245 
246 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
247 
248 	if (!gtk_tree_selection_get_selected (selection, &tree_model, &iter))
249 		return NULL;
250 
251 	/* By convention, "get" functions don't return a new object
252 	 * reference, so use gtk_tree_model_get_value() to avoid it.
253 	 * The caller can always reference the object if needed. */
254 
255 	column = E_MAIL_ACCOUNT_STORE_COLUMN_SERVICE;
256 	gtk_tree_model_get_value (tree_model, &iter, column, &value);
257 	service = g_value_get_object (&value);
258 	g_value_unset (&value);
259 
260 	g_warn_if_fail (CAMEL_IS_SERVICE (service));
261 
262 	return service;
263 }
264 
265 void
266 e_mail_account_tree_view_set_selected_service (EMailAccountTreeView *tree_view,
267                                                CamelService *service)
268 {
269 	GtkTreeSelection *selection;
270 	GtkTreeModel *tree_model;
271 	GtkTreeIter iter;
272 	gboolean iter_set;
273 
274 	g_return_if_fail (E_IS_MAIL_ACCOUNT_TREE_VIEW (tree_view));
275 	g_return_if_fail (CAMEL_IS_SERVICE (service));
276 
277 	tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
278 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
279 
280 	iter_set = gtk_tree_model_get_iter_first (tree_model, &iter);
281 
282 	while (iter_set) {
283 		GValue value = G_VALUE_INIT;
284 		CamelService *candidate;
285 		gint column;
286 
287 		column = E_MAIL_ACCOUNT_STORE_COLUMN_SERVICE;
288 		gtk_tree_model_get_value (tree_model, &iter, column, &value);
289 		candidate = g_value_get_object (&value);
290 		g_value_unset (&value);
291 
292 		g_warn_if_fail (CAMEL_IS_SERVICE (candidate));
293 
294 		if (service == candidate) {
295 			gtk_tree_selection_select_iter (selection, &iter);
296 			break;
297 		}
298 
299 		iter_set = gtk_tree_model_iter_next (tree_model, &iter);
300 	}
301 }