No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-config-service-notebook.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-config-service-notebook.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-config-service-notebook.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-config-service-notebook.h"
20
21 #define E_MAIL_CONFIG_SERVICE_NOTEBOOK_GET_PRIVATE(obj) \
22 (G_TYPE_INSTANCE_GET_PRIVATE \
23 ((obj), E_TYPE_MAIL_CONFIG_SERVICE_NOTEBOOK, EMailConfigServiceNotebookPrivate))
24
25 #define CHILD_BACKEND_KEY_FORMAT \
26 "__e_mail_config_service_notebook_%p_child_backend__"
27
28 struct _EMailConfigServiceNotebookPrivate {
29 EMailConfigServiceBackend *active_backend;
30 gchar *child_backend_key;
31 };
32
33 enum {
34 PROP_0,
35 PROP_ACTIVE_BACKEND
36 };
37
38 enum {
39 PROP_CHILD_0,
40 PROP_CHILD_BACKEND
41 };
42
43 G_DEFINE_TYPE (
44 EMailConfigServiceNotebook,
45 e_mail_config_service_notebook,
46 GTK_TYPE_NOTEBOOK)
47
48 static void
49 mail_config_service_notebook_set_child_backend (EMailConfigServiceNotebook *notebook,
50 GtkWidget *child,
51 EMailConfigServiceBackend *backend)
52 {
53 const gchar *key;
54
55 key = notebook->priv->child_backend_key;
56
57 if (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend))
58 g_object_set_data_full (
59 G_OBJECT (child), key,
60 g_object_ref (backend),
61 (GDestroyNotify) g_object_unref);
62 }
63
64 static EMailConfigServiceBackend *
65 mail_config_service_notebook_get_child_backend (EMailConfigServiceNotebook *notebook,
66 GtkWidget *child)
67 {
68 const gchar *key;
69
70 key = notebook->priv->child_backend_key;
71
72 return g_object_get_data (G_OBJECT (child), key);
73 }
74
75 static gboolean
76 mail_config_service_notebook_page_num_to_backend (GBinding *binding,
77 const GValue *source_value,
78 GValue *target_value,
79 gpointer user_data)
80 {
81 EMailConfigServiceBackend *backend;
82 GtkNotebook *notebook;
83 GtkWidget *child;
84 gint page_num;
85
86 /* The binding's source and target are the same instance. */
87 notebook = GTK_NOTEBOOK (g_binding_get_source (binding));
88
89 page_num = g_value_get_int (source_value);
90 child = gtk_notebook_get_nth_page (notebook, page_num);
91
92 if (child != NULL)
93 backend = mail_config_service_notebook_get_child_backend (
94 E_MAIL_CONFIG_SERVICE_NOTEBOOK (notebook), child);
95 else
96 backend = NULL;
97
98 g_value_set_object (target_value, backend);
99
100 return TRUE;
101 }
102
103 static gboolean
104 mail_config_service_notebook_backend_to_page_num (GBinding *binding,
105 const GValue *source_value,
106 GValue *target_value,
107 gpointer user_data)
108 {
109 EMailConfigServiceBackend *backend;
110 GtkNotebook *notebook;
111 gint n_pages, ii;
112
113 /* The binding's source and target are the same instance. */
114 notebook = GTK_NOTEBOOK (g_binding_get_source (binding));
115
116 backend = g_value_get_object (source_value);
117 n_pages = gtk_notebook_get_n_pages (notebook);
118
119 for (ii = 0; ii < n_pages; ii++) {
120 GtkWidget *child;
121 EMailConfigServiceBackend *candidate;
122
123 child = gtk_notebook_get_nth_page (notebook, ii);
124 candidate = mail_config_service_notebook_get_child_backend (
125 E_MAIL_CONFIG_SERVICE_NOTEBOOK (notebook), child);
126
127 if (backend == candidate) {
128 g_value_set_int (target_value, ii);
129 return TRUE;
130 }
131 }
132
133 return FALSE;
134 }
135
136 static void
137 mail_config_service_notebook_set_property (GObject *object,
138 guint property_id,
139 const GValue *value,
140 GParamSpec *pspec)
141 {
142 switch (property_id) {
143 case PROP_ACTIVE_BACKEND:
144 e_mail_config_service_notebook_set_active_backend (
145 E_MAIL_CONFIG_SERVICE_NOTEBOOK (object),
146 g_value_get_object (value));
147 return;
148 }
149
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
151 }
152
153 static void
154 mail_config_service_notebook_get_property (GObject *object,
155 guint property_id,
156 GValue *value,
157 GParamSpec *pspec)
158 {
159 switch (property_id) {
160 case PROP_ACTIVE_BACKEND:
161 g_value_set_object (
162 value,
163 e_mail_config_service_notebook_get_active_backend (
164 E_MAIL_CONFIG_SERVICE_NOTEBOOK (object)));
165 return;
166 }
167
168 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
169 }
170
171 static void
172 mail_config_service_notebook_dispose (GObject *object)
173 {
174 EMailConfigServiceNotebookPrivate *priv;
175
176 priv = E_MAIL_CONFIG_SERVICE_NOTEBOOK_GET_PRIVATE (object);
177
178 if (priv->active_backend != NULL) {
179 g_object_unref (priv->active_backend);
180 priv->active_backend = NULL;
181 }
182
183 /* Chain up to parent's dispose() method. */
184 G_OBJECT_CLASS (e_mail_config_service_notebook_parent_class)->
185 dispose (object);
186 }
187
188 static void
189 mail_config_service_notebook_finalize (GObject *object)
190 {
191 EMailConfigServiceNotebookPrivate *priv;
192
193 priv = E_MAIL_CONFIG_SERVICE_NOTEBOOK_GET_PRIVATE (object);
194
195 g_free (priv->child_backend_key);
196
197 /* Chain up to parent's finalize() method. */
198 G_OBJECT_CLASS (e_mail_config_service_notebook_parent_class)->
199 finalize (object);
200 }
201
202 static void
203 mail_config_service_notebook_constructed (GObject *object)
204 {
205 /* Chain up to parent's constructed() method. */
206 G_OBJECT_CLASS (e_mail_config_service_notebook_parent_class)->
207 constructed (object);
208
209 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (object), FALSE);
210
211 /* Current page is still -1 so skip G_BINDING_SYNC_CREATE. */
212 g_object_bind_property_full (
213 object, "page",
214 object, "active-backend",
215 G_BINDING_BIDIRECTIONAL,
216 mail_config_service_notebook_page_num_to_backend,
217 mail_config_service_notebook_backend_to_page_num,
218 NULL, (GDestroyNotify) NULL);
219 }
220
221 static void
222 mail_config_service_notebook_set_child_property (GtkContainer *container,
223 GtkWidget *child,
224 guint property_id,
225 const GValue *value,
226 GParamSpec *pspec)
227 {
228 switch (property_id) {
229 case PROP_CHILD_BACKEND:
230 mail_config_service_notebook_set_child_backend (
231 E_MAIL_CONFIG_SERVICE_NOTEBOOK (container),
232 child, g_value_get_object (value));
233 return;
234 }
235
236 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (
237 container, property_id, pspec);
238 }
239
240 static void
241 mail_config_service_notebook_get_child_property (GtkContainer *container,
242 GtkWidget *child,
243 guint property_id,
244 GValue *value,
245 GParamSpec *pspec)
246 {
247 switch (property_id) {
248 case PROP_CHILD_BACKEND:
249 g_value_set_object (
250 value,
251 mail_config_service_notebook_get_child_backend (
252 E_MAIL_CONFIG_SERVICE_NOTEBOOK (container), child));
253 return;
254 }
255
256 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (
257 container, property_id, pspec);
258 }
259
260 static void
261 e_mail_config_service_notebook_class_init (EMailConfigServiceNotebookClass *class)
262 {
263 GObjectClass *object_class;
264 GtkContainerClass *container_class;
265
266 g_type_class_add_private (
267 class, sizeof (EMailConfigServiceNotebookPrivate));
268
269 object_class = G_OBJECT_CLASS (class);
270 object_class->set_property = mail_config_service_notebook_set_property;
271 object_class->get_property = mail_config_service_notebook_get_property;
272 object_class->dispose = mail_config_service_notebook_dispose;
273 object_class->finalize = mail_config_service_notebook_finalize;
274 object_class->constructed = mail_config_service_notebook_constructed;
275
276 container_class = GTK_CONTAINER_CLASS (class);
277 container_class->set_child_property = mail_config_service_notebook_set_child_property;
278 container_class->get_child_property = mail_config_service_notebook_get_child_property;
279
280 g_object_class_install_property (
281 object_class,
282 PROP_ACTIVE_BACKEND,
283 g_param_spec_object (
284 "active-backend",
285 "Active Backend",
286 "The service backend for the current page",
287 E_TYPE_MAIL_CONFIG_SERVICE_BACKEND,
288 G_PARAM_READWRITE |
289 G_PARAM_STATIC_STRINGS));
290
291 /* Child property for notebook pages. */
292 gtk_container_class_install_child_property (
293 container_class,
294 PROP_CHILD_BACKEND,
295 g_param_spec_object (
296 "backend",
297 "Backend",
298 "The service backend for this page",
299 E_TYPE_MAIL_CONFIG_SERVICE_BACKEND,
300 G_PARAM_READWRITE |
301 G_PARAM_STATIC_STRINGS));
302 }
303
304 static void
305 e_mail_config_service_notebook_init (EMailConfigServiceNotebook *notebook)
306 {
307 gchar *key;
308
309 notebook->priv = E_MAIL_CONFIG_SERVICE_NOTEBOOK_GET_PRIVATE (notebook);
310
311 key = g_strdup_printf (CHILD_BACKEND_KEY_FORMAT, notebook);
312 notebook->priv->child_backend_key = key;
313 }
314
315 GtkWidget *
316 e_mail_config_service_notebook_new (void)
317 {
318 return g_object_new (E_TYPE_MAIL_CONFIG_SERVICE_NOTEBOOK, NULL);
319 }
320
321 gint
322 e_mail_config_service_notebook_add_page (EMailConfigServiceNotebook *notebook,
323 EMailConfigServiceBackend *backend,
324 GtkWidget *child)
325 {
326 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_NOTEBOOK (notebook), -1);
327 g_return_val_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend), -1);
328 g_return_val_if_fail (GTK_IS_WIDGET (child), -1);
329
330 gtk_widget_show (child);
331
332 mail_config_service_notebook_set_child_backend (
333 notebook, child, backend);
334
335 return gtk_notebook_append_page (GTK_NOTEBOOK (notebook), child, NULL);
336 }
337
338 EMailConfigServiceBackend *
339 e_mail_config_service_notebook_get_active_backend (EMailConfigServiceNotebook *notebook)
340 {
341 g_return_val_if_fail (
342 E_IS_MAIL_CONFIG_SERVICE_NOTEBOOK (notebook), NULL);
343
344 return notebook->priv->active_backend;
345 }
346
347 void
348 e_mail_config_service_notebook_set_active_backend (EMailConfigServiceNotebook *notebook,
349 EMailConfigServiceBackend *backend)
350 {
351 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_NOTEBOOK (notebook));
352
353 if (notebook->priv->active_backend == backend)
354 return;
355
356 if (backend != NULL) {
357 g_return_if_fail (E_IS_MAIL_CONFIG_SERVICE_BACKEND (backend));
358 g_object_ref (backend);
359 }
360
361 if (notebook->priv->active_backend != NULL)
362 g_object_unref (notebook->priv->active_backend);
363
364 notebook->priv->active_backend = backend;
365
366 g_object_notify (G_OBJECT (notebook), "active-backend");
367 }