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

No issues found

 1 /*
 2  * e-alarm-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-alarm-selector.h"
20 
21 G_DEFINE_TYPE (
22 	EAlarmSelector,
23 	e_alarm_selector,
24 	E_TYPE_SOURCE_SELECTOR)
25 
26 static gboolean
27 alarm_selector_get_source_selected (ESourceSelector *selector,
28                                     ESource *source)
29 {
30 	ESourceAlarms *extension;
31 	const gchar *extension_name;
32 
33 	/* Make sure this source is a calendar. */
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_ALARMS;
39 	extension = e_source_get_extension (source, extension_name);
40 	g_return_val_if_fail (E_IS_SOURCE_ALARMS (extension), FALSE);
41 
42 	return e_source_alarms_get_include_me (extension);
43 }
44 
45 static void
46 alarm_selector_set_source_selected (ESourceSelector *selector,
47                                     ESource *source,
48                                     gboolean selected)
49 {
50 	ESourceAlarms *extension;
51 	const gchar *extension_name;
52 
53 	/* Make sure this source is a calendar. */
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_ALARMS;
59 	extension = e_source_get_extension (source, extension_name);
60 	g_return_if_fail (E_IS_SOURCE_ALARMS (extension));
61 
62 	if (selected != e_source_alarms_get_include_me (extension)) {
63 		e_source_alarms_set_include_me (extension, selected);
64 		e_source_selector_queue_write (selector, source);
65 	}
66 }
67 
68 static void
69 e_alarm_selector_class_init (EAlarmSelectorClass *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 					alarm_selector_get_source_selected;
76 	source_selector_class->set_source_selected =
77 					alarm_selector_set_source_selected;
78 }
79 
80 static void
81 e_alarm_selector_init (EAlarmSelector *selector)
82 {
83 }
84 
85 GtkWidget *
86 e_alarm_selector_new (ESourceRegistry *registry)
87 {
88 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
89 
90 	return g_object_new (
91 		E_TYPE_ALARM_SELECTOR,
92 		"extension-name", E_SOURCE_EXTENSION_CALENDAR,
93 		"registry", registry, NULL);
94 }