evolution-3.6.4/mail/e-mail-account-manager.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-account-manager.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-account-manager.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-manager.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-manager.h"
 20 
 21 #include <config.h>
 22 #include <glib/gi18n-lib.h>
 23 #include <gdk/gdkkeysyms.h>
 24 
 25 #include <libemail-engine/e-mail-session.h>
 26 #include <mail/e-mail-account-tree-view.h>
 27 
 28 #define E_MAIL_ACCOUNT_MANAGER_GET_PRIVATE(obj) \
 29 	(G_TYPE_INSTANCE_GET_PRIVATE \
 30 	((obj), E_TYPE_MAIL_ACCOUNT_MANAGER, EMailAccountManagerPrivate))
 31 
 32 #define DEFAULT_ORDER_RESPONSE GTK_RESPONSE_APPLY
 33 
 34 struct _EMailAccountManagerPrivate {
 35 	EMailAccountStore *store;
 36 	gulong row_changed_handler_id;
 37 
 38 	GtkWidget *tree_view;		/* not referenced */
 39 	GtkWidget *add_button;		/* not referenced */
 40 	GtkWidget *edit_button;		/* not referenced */
 41 	GtkWidget *delete_button;	/* not referenced */
 42 	GtkWidget *default_button;	/* not referenced */
 43 };
 44 
 45 enum {
 46 	PROP_0,
 47 	PROP_STORE
 48 };
 49 
 50 enum {
 51 	ADD_ACCOUNT,
 52 	EDIT_ACCOUNT,
 53 	LAST_SIGNAL
 54 };
 55 
 56 static guint signals[LAST_SIGNAL];
 57 
 58 G_DEFINE_TYPE (
 59 	EMailAccountManager,
 60 	e_mail_account_manager,
 61 	GTK_TYPE_TABLE)
 62 
 63 static void
 64 mail_account_manager_add_cb (EMailAccountManager *manager)
 65 {
 66 	e_mail_account_manager_add_account (manager);
 67 }
 68 
 69 static void
 70 mail_account_manager_edit_cb (EMailAccountManager *manager)
 71 {
 72 	EMailAccountTreeView *tree_view;
 73 	EMailAccountStore *store;
 74 	ESourceRegistry *registry;
 75 	EMailSession *session;
 76 	CamelService *service;
 77 	ESource *source;
 78 	const gchar *uid;
 79 
 80 	store = e_mail_account_manager_get_store (manager);
 81 	session = e_mail_account_store_get_session (store);
 82 	registry = e_mail_session_get_registry (session);
 83 
 84 	tree_view = E_MAIL_ACCOUNT_TREE_VIEW (manager->priv->tree_view);
 85 	service = e_mail_account_tree_view_get_selected_service (tree_view);
 86 
 87 	uid = camel_service_get_uid (service);
 88 	source = e_source_registry_ref_source (registry, uid);
 89 	g_return_if_fail (source != NULL);
 90 
 91 	e_mail_account_manager_edit_account (manager, source);
 92 
 93 	g_object_unref (source);
 94 }
 95 
 96 static void
 97 mail_account_manager_remove_cb (EMailAccountManager *manager)
 98 {
 99 	EMailAccountTreeView *tree_view;
100 	EMailAccountStore *store;
101 	CamelService *service;
102 	gpointer parent;
103 
104 	tree_view = E_MAIL_ACCOUNT_TREE_VIEW (manager->priv->tree_view);
105 	service = e_mail_account_tree_view_get_selected_service (tree_view);
106 
107 	parent = gtk_widget_get_toplevel (GTK_WIDGET (manager));
108 	parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
109 
110 	store = e_mail_account_manager_get_store (manager);
111 	e_mail_account_store_remove_service (store, parent, service);
112 }
113 
114 static void
115 mail_account_manager_enable_cb (EMailAccountManager *manager)
116 {
117 	EMailAccountTreeView *tree_view;
118 	EMailAccountStore *store;
119 	CamelService *service;
120 	gpointer parent;
121 
122 	tree_view = E_MAIL_ACCOUNT_TREE_VIEW (manager->priv->tree_view);
123 	service = e_mail_account_tree_view_get_selected_service (tree_view);
124 
125 	parent = gtk_widget_get_toplevel (GTK_WIDGET (manager));
126 	parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
127 
128 	store = e_mail_account_manager_get_store (manager);
129 	e_mail_account_store_enable_service (store, parent, service);
130 }
131 
132 static void
133 mail_account_manager_disable_cb (EMailAccountManager *manager)
134 {
135 	EMailAccountTreeView *tree_view;
136 	EMailAccountStore *store;
137 	CamelService *service;
138 	gpointer parent;
139 
140 	tree_view = E_MAIL_ACCOUNT_TREE_VIEW (manager->priv->tree_view);
141 	service = e_mail_account_tree_view_get_selected_service (tree_view);
142 
143 	parent = gtk_widget_get_toplevel (GTK_WIDGET (manager));
144 	parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
145 
146 	store = e_mail_account_manager_get_store (manager);
147 	e_mail_account_store_disable_service (store, parent, service);
148 }
149 
150 static void
151 mail_account_manager_default_cb (EMailAccountManager *manager)
152 {
153 	EMailAccountTreeView *tree_view;
154 	EMailAccountStore *store;
155 	CamelService *service;
156 
157 	tree_view = E_MAIL_ACCOUNT_TREE_VIEW (manager->priv->tree_view);
158 	service = e_mail_account_tree_view_get_selected_service (tree_view);
159 
160 	store = e_mail_account_manager_get_store (manager);
161 	e_mail_account_store_set_default_service (store, service);
162 }
163 
164 static void
165 mail_account_manager_row_activated_cb (GtkTreeView *tree_view,
166                                        GtkTreePath *path,
167                                        GtkTreeViewColumn *column,
168                                        EMailAccountManager *manager)
169 {
170 	GtkWidget *edit_button;
171 
172 	edit_button = manager->priv->edit_button;
173 
174 	if (gtk_widget_is_sensitive (edit_button))
175 		gtk_button_clicked (GTK_BUTTON (edit_button));
176 }
177 
178 static void
179 mail_account_manager_info_bar_response_cb (EMailAccountManager *manager,
180                                            gint response)
181 {
182 	EMailAccountStore *store;
183 
184 	store = e_mail_account_manager_get_store (manager);
185 
186 	if (response == DEFAULT_ORDER_RESPONSE)
187 		e_mail_account_store_reorder_services (store, NULL);
188 }
189 
190 static gboolean
191 mail_account_manager_key_press_event_cb (EMailAccountManager *manager,
192                                          GdkEventKey *event)
193 {
194 	if (event->keyval == GDK_KEY_Delete) {
195 		mail_account_manager_remove_cb (manager);
196 		return TRUE;
197 	}
198 
199 	return FALSE;
200 }
201 
202 static void
203 mail_account_manager_row_changed_cb (GtkTreeModel *tree_model,
204                                      GtkTreePath *path,
205                                      GtkTreeIter *iter,
206                                      EMailAccountManager *manager)
207 {
208 	GtkTreeView *tree_view;
209 	GtkTreeSelection *selection;
210 
211 	tree_view = GTK_TREE_VIEW (manager->priv->tree_view);
212 	selection = gtk_tree_view_get_selection (tree_view);
213 
214 	/* Update buttons for the selected row (which is not
215 	 * necessarily the row that changed, but do it anyway). */
216 	g_signal_emit_by_name (selection, "changed");
217 }
218 
219 static void
220 mail_account_manager_selection_changed_cb (EMailAccountManager *manager,
221                                            GtkTreeSelection *selection)
222 {
223 	GtkTreeModel *tree_model;
224 	GtkTreeIter iter;
225 	EMailAccountStore *store;
226 	CamelService *default_service;
227 	CamelService *service;
228 	GtkWidget *add_button;
229 	GtkWidget *edit_button;
230 	GtkWidget *delete_button;
231 	GtkWidget *default_button;
232 	gboolean builtin;
233 	gboolean sensitive;
234 	gboolean not_default;
235 	gboolean removable;
236 
237 	add_button = manager->priv->add_button;
238 	edit_button = manager->priv->edit_button;
239 	delete_button = manager->priv->delete_button;
240 	default_button = manager->priv->default_button;
241 
242 	if (gtk_tree_selection_get_selected (selection, &tree_model, &iter)) {
243 		gtk_tree_model_get (
244 			tree_model, &iter,
245 			E_MAIL_ACCOUNT_STORE_COLUMN_SERVICE, &service,
246 			E_MAIL_ACCOUNT_STORE_COLUMN_BUILTIN, &builtin,
247 			-1);
248 		removable = !builtin;
249 	} else {
250 		service = NULL;
251 		builtin = FALSE;
252 		removable = FALSE;
253 	}
254 
255 	store = e_mail_account_manager_get_store (manager);
256 	default_service = e_mail_account_store_get_default_service (store);
257 	not_default = (service != default_service);
258 
259 	if (service == NULL)
260 		gtk_widget_grab_focus (add_button);
261 	else {
262 		ESource *source;
263 		EMailSession *session;
264 		ESourceRegistry *registry;
265 		const gchar *uid;
266 
267 		session = e_mail_account_store_get_session (store);
268 		registry = e_mail_session_get_registry (session);
269 
270 		uid = camel_service_get_uid (service);
271 		source = e_source_registry_ref_source (registry, uid);
272 
273 		if (source != NULL) {
274 			ESource *collection;
275 			const gchar *extension_name;
276 
277 			extension_name = E_SOURCE_EXTENSION_COLLECTION;
278 			collection = e_source_registry_find_extension (
279 				registry, source, extension_name);
280 			if (collection != NULL) {
281 				g_object_unref (source);
282 				source = collection;
283 			}
284 
285 			removable = e_source_get_removable (source);
286 
287 			g_object_unref (source);
288 		}
289 	}
290 
291 	sensitive = (service != NULL && !builtin);
292 	gtk_widget_set_sensitive (edit_button, sensitive);
293 
294 	sensitive = (service != NULL && removable);
295 	gtk_widget_set_sensitive (delete_button, sensitive);
296 
297 	sensitive = (service != NULL && !builtin && not_default);
298 	gtk_widget_set_sensitive (default_button, sensitive);
299 }
300 
301 static void
302 mail_account_manager_set_store (EMailAccountManager *manager,
303                                 EMailAccountStore *store)
304 {
305 	g_return_if_fail (E_IS_MAIL_ACCOUNT_STORE (store));
306 	g_return_if_fail (manager->priv->store == NULL);
307 
308 	manager->priv->store = g_object_ref (store);
309 }
310 
311 static void
312 mail_account_manager_set_property (GObject *object,
313                                    guint property_id,
314                                    const GValue *value,
315                                    GParamSpec *pspec)
316 {
317 	switch (property_id) {
318 		case PROP_STORE:
319 			mail_account_manager_set_store (
320 				E_MAIL_ACCOUNT_MANAGER (object),
321 				g_value_get_object (value));
322 			return;
323 	}
324 
325 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
326 }
327 
328 static void
329 mail_account_manager_get_property (GObject *object,
330                                    guint property_id,
331                                    GValue *value,
332                                    GParamSpec *pspec)
333 {
334 	switch (property_id) {
335 		case PROP_STORE:
336 			g_value_set_object (
337 				value,
338 				e_mail_account_manager_get_store (
339 				E_MAIL_ACCOUNT_MANAGER (object)));
340 			return;
341 	}
342 
343 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
344 }
345 
346 static void
347 mail_account_manager_dispose (GObject *object)
348 {
349 	EMailAccountManagerPrivate *priv;
350 
351 	priv = E_MAIL_ACCOUNT_MANAGER_GET_PRIVATE (object);
352 
353 	if (priv->store != NULL) {
354 		g_signal_handler_disconnect (
355 			priv->store, priv->row_changed_handler_id);
356 		g_object_unref (priv->store);
357 		priv->store = NULL;
358 	}
359 
360 	/* Chain up to parent's dispose() method. */
361 	G_OBJECT_CLASS (e_mail_account_manager_parent_class)->dispose (object);
362 }
363 
364 static void
365 mail_account_manager_constructed (GObject *object)
366 {
367 	EMailAccountManager *manager;
368 	EMailAccountStore *store;
369 	GtkTreeSelection *selection;
370 	GtkWidget *container;
371 	GtkWidget *widget;
372 	gulong handler_id;
373 
374 	manager = E_MAIL_ACCOUNT_MANAGER (object);
375 	store = e_mail_account_manager_get_store (manager);
376 
377 	/* Chain up to parent's constructed() method. */
378 	G_OBJECT_CLASS (e_mail_account_manager_parent_class)->
379 		constructed (object);
380 
381 	g_object_bind_property (
382 		store, "busy",
383 		manager, "sensitive",
384 		G_BINDING_SYNC_CREATE |
385 		G_BINDING_INVERT_BOOLEAN);
386 
387 	handler_id = g_signal_connect (
388 		store, "row-changed",
389 		G_CALLBACK (mail_account_manager_row_changed_cb),
390 		manager);
391 
392 	/* We disconnect the handler in dispose(). */
393 	manager->priv->row_changed_handler_id = handler_id;
394 
395 	gtk_table_resize (GTK_TABLE (manager), 2, 2);
396 	gtk_table_set_col_spacings (GTK_TABLE (manager), 6);
397 	gtk_table_set_row_spacings (GTK_TABLE (manager), 0);
398 
399 	container = GTK_WIDGET (manager);
400 
401 	widget = gtk_scrolled_window_new (NULL, NULL);
402 	gtk_scrolled_window_set_policy (
403 		GTK_SCROLLED_WINDOW (widget),
404 		GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
405 	gtk_scrolled_window_set_shadow_type (
406 		GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
407 	gtk_table_attach (
408 		GTK_TABLE (container), widget, 0, 1, 0, 1,
409 		GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
410 	gtk_widget_show (widget);
411 
412 	container = widget;
413 
414 	widget = e_mail_account_tree_view_new (store);
415 	gtk_container_add (GTK_CONTAINER (container), widget);
416 	manager->priv->tree_view = widget;  /* not referenced */
417 	gtk_widget_show (widget);
418 
419 	g_signal_connect_swapped (
420 		widget, "enable",
421 		G_CALLBACK (mail_account_manager_enable_cb), manager);
422 
423 	g_signal_connect_swapped (
424 		widget, "disable",
425 		G_CALLBACK (mail_account_manager_disable_cb), manager);
426 
427 	g_signal_connect_swapped (
428 		widget, "key-press-event",
429 		G_CALLBACK (mail_account_manager_key_press_event_cb),
430 		manager);
431 
432 	g_signal_connect (
433 		widget, "row-activated",
434 		G_CALLBACK (mail_account_manager_row_activated_cb), manager);
435 
436 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
437 
438 	g_signal_connect_swapped (
439 		selection, "changed",
440 		G_CALLBACK (mail_account_manager_selection_changed_cb),
441 		manager);
442 
443 	container = GTK_WIDGET (manager);
444 
445 	widget = gtk_frame_new (NULL);
446 	gtk_frame_set_shadow_type (
447 		GTK_FRAME (widget), GTK_SHADOW_IN);
448 	gtk_table_attach (
449 		GTK_TABLE (container), widget,
450 		0, 1, 1, 2, GTK_FILL, 0, 0, 0);
451 	gtk_widget_show (widget);
452 
453 	container = widget;
454 
455 	widget = gtk_info_bar_new ();
456 	gtk_info_bar_set_message_type (
457 		GTK_INFO_BAR (widget), GTK_MESSAGE_INFO);
458 	gtk_info_bar_add_button (
459 		GTK_INFO_BAR (widget),
460 		_("_Restore Default"),
461 		DEFAULT_ORDER_RESPONSE);
462 	gtk_container_add (GTK_CONTAINER (container), widget);
463 	gtk_widget_show (widget);
464 
465 	g_signal_connect_swapped (
466 		widget, "response",
467 		G_CALLBACK (mail_account_manager_info_bar_response_cb),
468 		manager);
469 
470 	container = gtk_info_bar_get_content_area (GTK_INFO_BAR (widget));
471 
472 	widget = gtk_label_new (
473 		_("You can drag and drop account names to reorder them."));
474 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
475 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
476 	gtk_widget_show (widget);
477 
478 	container = GTK_WIDGET (manager);
479 
480 	widget = gtk_vbutton_box_new ();
481 	gtk_button_box_set_layout (
482 		GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_START);
483 	gtk_box_set_spacing (GTK_BOX (widget), 6);
484 	gtk_table_attach (
485 		GTK_TABLE (container), widget,
486 		1, 2, 0, 2, 0, GTK_FILL, 0, 0);
487 	gtk_widget_show (widget);
488 
489 	container = widget;
490 
491 	widget = gtk_button_new_from_stock (GTK_STOCK_ADD);
492 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
493 	manager->priv->add_button = widget;  /* not referenced */
494 	gtk_widget_show (widget);
495 
496 	g_signal_connect_swapped (
497 		widget, "clicked",
498 		G_CALLBACK (mail_account_manager_add_cb), manager);
499 
500 	widget = gtk_button_new_from_stock (GTK_STOCK_EDIT);
501 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
502 	manager->priv->edit_button = widget;  /* not referenced */
503 	gtk_widget_show (widget);
504 
505 	g_signal_connect_swapped (
506 		widget, "clicked",
507 		G_CALLBACK (mail_account_manager_edit_cb), manager);
508 
509 	widget = gtk_button_new_from_stock (GTK_STOCK_DELETE);
510 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
511 	manager->priv->delete_button = widget;  /* not referenced */
512 	gtk_widget_show (widget);
513 
514 	g_signal_connect_swapped (
515 		widget, "clicked",
516 		G_CALLBACK (mail_account_manager_remove_cb), manager);
517 
518 	widget = gtk_button_new_with_mnemonic (_("De_fault"));
519 	gtk_button_set_image (
520 		GTK_BUTTON (widget),
521 		gtk_image_new_from_icon_name (
522 		"emblem-default", GTK_ICON_SIZE_BUTTON));
523 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
524 	manager->priv->default_button = widget;  /* not referenced */
525 	gtk_widget_show (widget);
526 
527 	g_signal_connect_swapped (
528 		widget, "clicked",
529 		G_CALLBACK (mail_account_manager_default_cb), manager);
530 
531 	/* Initialize button states. */
532 	g_signal_emit_by_name (selection, "changed");
533 }
534 
535 static void
536 e_mail_account_manager_class_init (EMailAccountManagerClass *class)
537 {
538 	GObjectClass *object_class;
539 
540 	g_type_class_add_private (class, sizeof (EMailAccountManagerPrivate));
541 
542 	object_class = G_OBJECT_CLASS (class);
543 	object_class->set_property = mail_account_manager_set_property;
544 	object_class->get_property = mail_account_manager_get_property;
545 	object_class->dispose = mail_account_manager_dispose;
546 	object_class->constructed = mail_account_manager_constructed;
547 
548 	g_object_class_install_property (
549 		object_class,
550 		PROP_STORE,
551 		g_param_spec_object (
552 			"store",
553 			"Store",
554 			NULL,
555 			E_TYPE_MAIL_ACCOUNT_STORE,
556 			G_PARAM_READWRITE |
557 			G_PARAM_CONSTRUCT_ONLY |
558 			G_PARAM_STATIC_STRINGS));
559 
560 	signals[ADD_ACCOUNT] = g_signal_new (
561 		"add-account",
562 		G_OBJECT_CLASS_TYPE (class),
563 		G_SIGNAL_RUN_LAST,
564 		G_STRUCT_OFFSET (EMailAccountManagerClass, add_account),
565 		NULL, NULL,
566 		g_cclosure_marshal_VOID__VOID,
567 		G_TYPE_NONE, 0);
568 
569 	signals[EDIT_ACCOUNT] = g_signal_new (
570 		"edit-account",
571 		G_OBJECT_CLASS_TYPE (class),
572 		G_SIGNAL_RUN_LAST,
573 		G_STRUCT_OFFSET (EMailAccountManagerClass, edit_account),
574 		NULL, NULL,
575 		g_cclosure_marshal_VOID__OBJECT,
576 		G_TYPE_NONE, 1,
577 		E_TYPE_SOURCE);
578 }
579 
580 static void
581 e_mail_account_manager_init (EMailAccountManager *manager)
582 {
583 	manager->priv = E_MAIL_ACCOUNT_MANAGER_GET_PRIVATE (manager);
584 }
585 
586 GtkWidget *
587 e_mail_account_manager_new (EMailAccountStore *store)
588 {
589 	g_return_val_if_fail (E_IS_MAIL_ACCOUNT_STORE (store), NULL);
590 
591 	return g_object_new (
592 		E_TYPE_MAIL_ACCOUNT_MANAGER,
593 		"store", store, NULL);
594 }
595 
596 EMailAccountStore *
597 e_mail_account_manager_get_store (EMailAccountManager *manager)
598 {
599 	g_return_val_if_fail (E_IS_MAIL_ACCOUNT_MANAGER (manager), NULL);
600 
601 	return manager->priv->store;
602 }
603 
604 void
605 e_mail_account_manager_add_account (EMailAccountManager *manager)
606 {
607 	g_return_if_fail (E_IS_MAIL_ACCOUNT_MANAGER (manager));
608 
609 	g_signal_emit (manager, signals[ADD_ACCOUNT], 0);
610 }
611 
612 void
613 e_mail_account_manager_edit_account (EMailAccountManager *manager,
614                                      ESource *source)
615 {
616 	g_return_if_fail (E_IS_MAIL_ACCOUNT_MANAGER (manager));
617 	g_return_if_fail (E_IS_SOURCE (source));
618 
619 	g_signal_emit (manager, signals[EDIT_ACCOUNT], 0, source);
620 }