evolution-3.6.4/modules/cal-config-contacts/e-contacts-selector.c

No issues found

  1 /*
  2  * e-contacts-selector.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-contacts-selector.h"
 20 
 21 #include "e-source-contacts.h"
 22 
 23 G_DEFINE_DYNAMIC_TYPE (
 24 	EContactsSelector,
 25 	e_contacts_selector,
 26 	E_TYPE_SOURCE_SELECTOR)
 27 
 28 static gboolean
 29 contacts_selector_get_source_selected (ESourceSelector *selector,
 30                                        ESource *source)
 31 {
 32 	ESourceContacts *extension;
 33 	const gchar *extension_name;
 34 
 35 	extension_name = e_source_selector_get_extension_name (selector);
 36 
 37 	/* Make sure this source is an address book. */
 38 	if (!e_source_has_extension (source, extension_name))
 39 		return FALSE;
 40 
 41 	extension_name = E_SOURCE_EXTENSION_CONTACTS_BACKEND;
 42 	extension = e_source_get_extension (source, extension_name);
 43 	g_return_val_if_fail (E_IS_SOURCE_CONTACTS (extension), FALSE);
 44 
 45 	return e_source_contacts_get_include_me (extension);
 46 }
 47 
 48 static void
 49 contacts_selector_set_source_selected (ESourceSelector *selector,
 50                                        ESource *source,
 51                                        gboolean selected)
 52 {
 53 	ESourceContacts *extension;
 54 	const gchar *extension_name;
 55 
 56 	/* Make sure this source is an address book. */
 57 	extension_name = e_source_selector_get_extension_name (selector);
 58 	if (!e_source_has_extension (source, extension_name))
 59 		return;
 60 
 61 	extension_name = E_SOURCE_EXTENSION_CONTACTS_BACKEND;
 62 	extension = e_source_get_extension (source, extension_name);
 63 	g_return_if_fail (E_IS_SOURCE_CONTACTS (extension));
 64 
 65 	if (selected != e_source_contacts_get_include_me (extension)) {
 66 		e_source_contacts_set_include_me (extension, selected);
 67 		e_source_selector_queue_write (selector, source);
 68 	}
 69 }
 70 
 71 static void
 72 e_contacts_selector_class_init (EContactsSelectorClass *class)
 73 {
 74 	ESourceSelectorClass *source_selector_class;
 75 
 76 	source_selector_class = E_SOURCE_SELECTOR_CLASS (class);
 77 	source_selector_class->get_source_selected =
 78 				contacts_selector_get_source_selected;
 79 	source_selector_class->set_source_selected =
 80 				contacts_selector_set_source_selected;
 81 }
 82 
 83 static void
 84 e_contacts_selector_class_finalize (EContactsSelectorClass *class)
 85 {
 86 }
 87 
 88 static void
 89 e_contacts_selector_init (EContactsSelector *selector)
 90 {
 91 	e_source_selector_set_show_colors (
 92 		E_SOURCE_SELECTOR (selector), FALSE);
 93 }
 94 
 95 void
 96 e_contacts_selector_type_register (GTypeModule *type_module)
 97 {
 98 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
 99 	 *     function, so we have to wrap it with a public function in
100 	 *     order to register types from a separate compilation unit. */
101 	e_contacts_selector_register_type (type_module);
102 }
103 
104 GtkWidget *
105 e_contacts_selector_new (ESourceRegistry *registry)
106 {
107 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
108 
109 	return g_object_new (
110 		E_TYPE_CONTACTS_SELECTOR,
111 		"extension-name", E_SOURCE_EXTENSION_ADDRESS_BOOK,
112 		"registry", registry, NULL);
113 }