No issues found
1 /*
2 * evolution-cal-config-contacts.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 <config.h>
20 #include <glib/gi18n-lib.h>
21
22 #include <libebackend/libebackend.h>
23
24 #include <misc/e-cal-source-config.h>
25 #include <misc/e-book-source-config.h>
26 #include <misc/e-source-config-backend.h>
27
28 #include "e-contacts-selector.h"
29 #include "e-source-contacts.h"
30
31 /* This file contains two extension classes: an ESourceConfigBackend
32 * for "contacts" calendars and an EExtension for EBookSourceConfig. */
33
34 /**************************** ECalConfigContacts *****************************/
35
36 typedef ESourceConfigBackend ECalConfigContacts;
37 typedef ESourceConfigBackendClass ECalConfigContactsClass;
38
39 /* Forward Declarations */
40 GType e_cal_config_contacts_get_type (void);
41
42 G_DEFINE_DYNAMIC_TYPE (
43 ECalConfigContacts,
44 e_cal_config_contacts,
45 E_TYPE_SOURCE_CONFIG_BACKEND)
46
47 static gboolean
48 cal_config_contacts_allow_creation (ESourceConfigBackend *backend)
49 {
50 return FALSE;
51 }
52
53 static void
54 cal_config_contacts_insert_widgets (ESourceConfigBackend *backend,
55 ESource *scratch_source)
56 {
57 ESourceConfig *config;
58 ESourceRegistry *registry;
59 GtkWidget *container;
60 GtkWidget *widget;
61
62 config = e_source_config_backend_get_config (backend);
63 registry = e_source_config_get_registry (config);
64
65 /* Extra padding between the selector and the options above. */
66 widget = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
67 gtk_alignment_set_padding (GTK_ALIGNMENT (widget), 12, 0, 0, 0);
68 e_source_config_insert_widget (config, scratch_source, NULL, widget);
69 gtk_widget_show (widget);
70
71 container = widget;
72
73 widget = gtk_label_new (_("Choose which address books to use."));
74 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
75 gtk_container_add (GTK_CONTAINER (container), widget);
76 gtk_widget_show (widget);
77
78 widget = gtk_scrolled_window_new (NULL, NULL);
79 gtk_scrolled_window_set_policy (
80 GTK_SCROLLED_WINDOW (widget),
81 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
82 gtk_scrolled_window_set_shadow_type (
83 GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
84 gtk_widget_set_size_request (widget, 320, 200);
85 e_source_config_insert_widget (config, scratch_source, NULL, widget);
86 gtk_widget_show (widget);
87
88 container = widget;
89
90 widget = e_contacts_selector_new (registry);
91 gtk_container_add (GTK_CONTAINER (container), widget);
92 gtk_widget_show (widget);
93 }
94
95 static void
96 e_cal_config_contacts_class_init (ESourceConfigBackendClass *class)
97 {
98 EExtensionClass *extension_class;
99
100 extension_class = E_EXTENSION_CLASS (class);
101 extension_class->extensible_type = E_TYPE_CAL_SOURCE_CONFIG;
102
103 class->parent_uid = "contacts-stub";
104 class->backend_name = "contacts";
105 class->allow_creation = cal_config_contacts_allow_creation;
106 class->insert_widgets = cal_config_contacts_insert_widgets;
107 }
108
109 static void
110 e_cal_config_contacts_class_finalize (ESourceConfigBackendClass *class)
111 {
112 }
113
114 static void
115 e_cal_config_contacts_init (ESourceConfigBackend *backend)
116 {
117 }
118
119 /*************************** EBookConfigBirthdays ****************************/
120
121 /* Standard GObject macros */
122 #define E_TYPE_BOOK_CONFIG_BIRTHDAYS \
123 (e_book_config_birthdays_get_type ())
124 #define E_BOOK_CONFIG_BIRTHDAYS(obj) \
125 (G_TYPE_CHECK_INSTANCE_CAST \
126 ((obj), E_TYPE_BOOK_CONFIG_BIRTHDAYS, EBookConfigBirthdays))
127
128 typedef struct _EBookConfigBirthdays EBookConfigBirthdays;
129 typedef struct _EBookConfigBirthdaysClass EBookConfigBirthdaysClass;
130
131 struct _EBookConfigBirthdays {
132 EExtension parent;
133 GtkWidget *button;
134 };
135
136 struct _EBookConfigBirthdaysClass {
137 EExtensionClass parent_class;
138 };
139
140 /* Forward Declarations */
141 GType e_book_config_birthdays_get_type (void);
142
143 G_DEFINE_DYNAMIC_TYPE (
144 EBookConfigBirthdays,
145 e_book_config_birthdays,
146 E_TYPE_EXTENSION)
147
148 static ESourceConfig *
149 book_config_birthdays_get_config (EBookConfigBirthdays *birthdays)
150 {
151 EExtensible *extensible;
152
153 extensible = e_extension_get_extensible (E_EXTENSION (birthdays));
154
155 return E_SOURCE_CONFIG (extensible);
156 }
157
158 static void
159 book_config_birthdays_dispose (GObject *object)
160 {
161 EBookConfigBirthdays *birthdays;
162
163 birthdays = E_BOOK_CONFIG_BIRTHDAYS (object);
164
165 if (birthdays->button != NULL) {
166 g_object_unref (birthdays->button);
167 birthdays->button = NULL;
168 }
169
170 /* Chain up to parent's dispose() method. */
171 G_OBJECT_CLASS (e_book_config_birthdays_parent_class)->dispose (object);
172 }
173
174 static void
175 book_config_birthdays_init_candidate (ESourceConfig *config,
176 ESource *scratch_source,
177 EBookConfigBirthdays *birthdays)
178 {
179 ESourceExtension *extension;
180 const gchar *extension_name;
181
182 extension_name = E_SOURCE_EXTENSION_CONTACTS_BACKEND;
183 extension = e_source_get_extension (scratch_source, extension_name);
184
185 g_object_bind_property (
186 extension, "include-me",
187 birthdays->button, "active",
188 G_BINDING_BIDIRECTIONAL |
189 G_BINDING_SYNC_CREATE);
190 }
191
192 static void
193 book_config_birthdays_constructed (GObject *object)
194 {
195 ESourceConfig *config;
196 EBookConfigBirthdays *birthdays;
197 GtkWidget *widget;
198 const gchar *label;
199
200 birthdays = E_BOOK_CONFIG_BIRTHDAYS (object);
201 config = book_config_birthdays_get_config (birthdays);
202
203 label = _("Use in Birthdays & Anniversaries calendar");
204 widget = gtk_check_button_new_with_label (label);
205 e_source_config_insert_widget (config, NULL, NULL, widget);
206 birthdays->button = g_object_ref_sink (widget);
207 gtk_widget_show (widget);
208
209 g_signal_connect (
210 config, "init-candidate",
211 G_CALLBACK (book_config_birthdays_init_candidate),
212 birthdays);
213 }
214
215 static void
216 e_book_config_birthdays_class_init (EBookConfigBirthdaysClass *class)
217 {
218 GObjectClass *object_class;
219 EExtensionClass *extension_class;
220
221 object_class = G_OBJECT_CLASS (class);
222 object_class->dispose = book_config_birthdays_dispose;
223 object_class->constructed = book_config_birthdays_constructed;
224
225 extension_class = E_EXTENSION_CLASS (class);
226 extension_class->extensible_type = E_TYPE_BOOK_SOURCE_CONFIG;
227 }
228
229 static void
230 e_book_config_birthdays_class_finalize (EBookConfigBirthdaysClass *class)
231 {
232 }
233
234 static void
235 e_book_config_birthdays_init (EBookConfigBirthdays *birthdays)
236 {
237 }
238
239 /* Module Entry Points */
240 void e_module_load (GTypeModule *type_module);
241 void e_module_unload (GTypeModule *type_module);
242
243 G_MODULE_EXPORT void
244 e_module_load (GTypeModule *type_module)
245 {
246 e_source_contacts_type_register (type_module);
247 e_contacts_selector_type_register (type_module);
248
249 e_cal_config_contacts_register_type (type_module);
250 e_book_config_birthdays_register_type (type_module);
251 }
252
253 G_MODULE_EXPORT void
254 e_module_unload (GTypeModule *type_module)
255 {
256 }