evolution-3.6.4/widgets/misc/e-autocomplete-selector.c

No issues found

 1 /*
 2  * e-autocomplete-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-autocomplete-selector.h"
20 
21 G_DEFINE_TYPE (
22 	EAutocompleteSelector,
23 	e_autocomplete_selector,
24 	E_TYPE_SOURCE_SELECTOR)
25 
26 static gboolean
27 autocomplete_selector_get_source_selected (ESourceSelector *selector,
28                                            ESource *source)
29 {
30 	ESourceAutocomplete *extension;
31 	const gchar *extension_name;
32 
33 	/* Make sure this source is an address book. */
34 	extension_name = e_source_selector_get_extension_name (selector);
35 	if (!e_source_has_extension (source, extension_name))
36 		return FALSE;
37 
38 	extension_name = E_SOURCE_EXTENSION_AUTOCOMPLETE;
39 	extension = e_source_get_extension (source, extension_name);
40 	g_return_val_if_fail (E_IS_SOURCE_AUTOCOMPLETE (extension), FALSE);
41 
42 	return e_source_autocomplete_get_include_me (extension);
43 }
44 
45 static void
46 autocomplete_selector_set_source_selected (ESourceSelector *selector,
47                                            ESource *source,
48                                            gboolean selected)
49 {
50 	ESourceAutocomplete *extension;
51 	const gchar *extension_name;
52 
53 	/* Make sure this source is an address book. */
54 	extension_name = e_source_selector_get_extension_name (selector);
55 	if (!e_source_has_extension (source, extension_name))
56 		return;
57 
58 	extension_name = E_SOURCE_EXTENSION_AUTOCOMPLETE;
59 	extension = e_source_get_extension (source, extension_name);
60 	g_return_if_fail (E_IS_SOURCE_AUTOCOMPLETE (extension));
61 
62 	if (selected != e_source_autocomplete_get_include_me (extension)) {
63 		e_source_autocomplete_set_include_me (extension, selected);
64 		e_source_selector_queue_write (selector, source);
65 	}
66 }
67 
68 static void
69 e_autocomplete_selector_class_init (EAutocompleteSelectorClass *class)
70 {
71 	ESourceSelectorClass *source_selector_class;
72 
73 	source_selector_class = E_SOURCE_SELECTOR_CLASS (class);
74 	source_selector_class->get_source_selected =
75 				autocomplete_selector_get_source_selected;
76 	source_selector_class->set_source_selected =
77 				autocomplete_selector_set_source_selected;
78 }
79 
80 static void
81 e_autocomplete_selector_init (EAutocompleteSelector *selector)
82 {
83 	e_source_selector_set_show_colors (
84 		E_SOURCE_SELECTOR (selector), FALSE);
85 }
86 
87 GtkWidget *
88 e_autocomplete_selector_new (ESourceRegistry *registry)
89 {
90 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
91 
92 	return g_object_new (
93 		E_TYPE_AUTOCOMPLETE_SELECTOR,
94 		"extension-name", E_SOURCE_EXTENSION_ADDRESS_BOOK,
95 		"registry", registry, NULL);
96 }