No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-config-sidebar.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-config-sidebar.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-config-sidebar.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-sidebar.h"
20
21 #define E_MAIL_CONFIG_SIDEBAR_GET_PRIVATE(obj) \
22 (G_TYPE_INSTANCE_GET_PRIVATE \
23 ((obj), E_TYPE_MAIL_CONFIG_SIDEBAR, EMailConfigSidebarPrivate))
24
25 struct _EMailConfigSidebarPrivate {
26 EMailConfigNotebook *notebook;
27 gint active;
28
29 GHashTable *buttons_to_pages;
30 GHashTable *pages_to_buttons;
31
32 gulong page_added_handler_id;
33 gulong page_removed_handler_id;
34 gulong page_reordered_handler_id;
35 };
36
37 enum {
38 PROP_0,
39 PROP_ACTIVE,
40 PROP_NOTEBOOK
41 };
42
43 G_DEFINE_TYPE (
44 EMailConfigSidebar,
45 e_mail_config_sidebar,
46 GTK_TYPE_BUTTON_BOX)
47
48 static void
49 mail_config_sidebar_button_toggled (GtkToggleButton *button,
50 EMailConfigSidebar *sidebar)
51 {
52 if (gtk_toggle_button_get_active (button)) {
53 GHashTable *hash_table;
54 GtkNotebook *notebook;
55 GtkWidget *page;
56 gint page_num;
57
58 hash_table = sidebar->priv->buttons_to_pages;
59 page = g_hash_table_lookup (hash_table, button);
60 g_return_if_fail (GTK_IS_WIDGET (page));
61
62 notebook = GTK_NOTEBOOK (sidebar->priv->notebook);
63 page_num = gtk_notebook_page_num (notebook, page);
64 e_mail_config_sidebar_set_active (sidebar, page_num);
65 }
66 }
67
68 static void
69 mail_config_sidebar_notebook_page_added (GtkNotebook *notebook,
70 GtkWidget *page,
71 guint page_num,
72 EMailConfigSidebar *sidebar)
73 {
74 GtkRadioButton *group_member;
75 GtkWidget *button;
76 GList *keys;
77 gchar *tab_label = NULL;
78
79 /* Grab another radio button if we have any. */
80 keys = g_hash_table_get_keys (sidebar->priv->buttons_to_pages);
81 group_member = (keys != NULL) ? GTK_RADIO_BUTTON (keys->data) : NULL;
82 g_list_free (keys);
83
84 gtk_container_child_get (
85 GTK_CONTAINER (notebook), page,
86 "tab-label", &tab_label, NULL);
87
88 button = gtk_radio_button_new_with_label_from_widget (
89 group_member, tab_label);
90 g_object_set (button, "draw-indicator", FALSE, NULL);
91 gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
92 gtk_box_pack_start (GTK_BOX (sidebar), button, FALSE, FALSE, 0);
93 gtk_box_reorder_child (GTK_BOX (sidebar), button, page_num);
94 gtk_widget_show (button);
95
96 g_signal_connect (
97 button, "toggled",
98 G_CALLBACK (mail_config_sidebar_button_toggled), sidebar);
99
100 g_hash_table_insert (
101 sidebar->priv->pages_to_buttons,
102 g_object_ref (page), g_object_ref (button));
103
104 g_hash_table_insert (
105 sidebar->priv->buttons_to_pages,
106 g_object_ref (button), g_object_ref (page));
107 }
108
109 static void
110 mail_config_sidebar_notebook_page_removed (GtkNotebook *notebook,
111 GtkWidget *page,
112 guint page_num,
113 EMailConfigSidebar *sidebar)
114 {
115 GHashTable *hash_table;
116 GtkWidget *button;
117
118 hash_table = sidebar->priv->pages_to_buttons;
119 button = g_hash_table_lookup (hash_table, page);
120 g_return_if_fail (GTK_IS_WIDGET (button));
121
122 gtk_container_remove (GTK_CONTAINER (sidebar), button);
123
124 g_hash_table_remove (sidebar->priv->pages_to_buttons, page);
125 g_hash_table_remove (sidebar->priv->buttons_to_pages, button);
126 }
127
128 static void
129 mail_config_sidebar_notebook_page_reordered (GtkNotebook *notebook,
130 GtkWidget *page,
131 guint page_num,
132 EMailConfigSidebar *sidebar)
133 {
134 GHashTable *hash_table;
135 GtkWidget *button;
136
137 hash_table = sidebar->priv->pages_to_buttons;
138 button = g_hash_table_lookup (hash_table, page);
139 g_return_if_fail (GTK_IS_WIDGET (button));
140
141 gtk_box_reorder_child (GTK_BOX (sidebar), button, page_num);
142 }
143
144 static void
145 mail_config_sidebar_set_notebook (EMailConfigSidebar *sidebar,
146 EMailConfigNotebook *notebook)
147 {
148 g_return_if_fail (E_IS_MAIL_CONFIG_NOTEBOOK (notebook));
149 g_return_if_fail (sidebar->priv->notebook == NULL);
150
151 sidebar->priv->notebook = g_object_ref (notebook);
152 }
153
154 static void
155 mail_config_sidebar_set_property (GObject *object,
156 guint property_id,
157 const GValue *value,
158 GParamSpec *pspec)
159 {
160 switch (property_id) {
161 case PROP_ACTIVE:
162 e_mail_config_sidebar_set_active (
163 E_MAIL_CONFIG_SIDEBAR (object),
164 g_value_get_int (value));
165 return;
166
167 case PROP_NOTEBOOK:
168 mail_config_sidebar_set_notebook (
169 E_MAIL_CONFIG_SIDEBAR (object),
170 g_value_get_object (value));
171 return;
172 }
173
174 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
175 }
176
177 static void
178 mail_config_sidebar_get_property (GObject *object,
179 guint property_id,
180 GValue *value,
181 GParamSpec *pspec)
182 {
183 switch (property_id) {
184 case PROP_ACTIVE:
185 g_value_set_int (
186 value,
187 e_mail_config_sidebar_get_active (
188 E_MAIL_CONFIG_SIDEBAR (object)));
189 return;
190
191 case PROP_NOTEBOOK:
192 g_value_set_object (
193 value,
194 e_mail_config_sidebar_get_notebook (
195 E_MAIL_CONFIG_SIDEBAR (object)));
196 return;
197 }
198
199 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
200 }
201
202 static void
203 mail_config_sidebar_dispose (GObject *object)
204 {
205 EMailConfigSidebarPrivate *priv;
206
207 priv = E_MAIL_CONFIG_SIDEBAR_GET_PRIVATE (object);
208
209 if (priv->notebook != NULL) {
210 g_signal_handler_disconnect (
211 priv->notebook, priv->page_added_handler_id);
212 g_signal_handler_disconnect (
213 priv->notebook, priv->page_removed_handler_id);
214 g_signal_handler_disconnect (
215 priv->notebook, priv->page_reordered_handler_id);
216 g_object_unref (priv->notebook);
217 priv->notebook = NULL;
218 }
219
220 g_hash_table_remove_all (priv->buttons_to_pages);
221 g_hash_table_remove_all (priv->pages_to_buttons);
222
223 /* Chain up to parent's dispose() method. */
224 G_OBJECT_CLASS (e_mail_config_sidebar_parent_class)->dispose (object);
225 }
226
227 static void
228 mail_config_sidebar_finalize (GObject *object)
229 {
230 EMailConfigSidebarPrivate *priv;
231
232 priv = E_MAIL_CONFIG_SIDEBAR_GET_PRIVATE (object);
233
234 g_hash_table_destroy (priv->buttons_to_pages);
235 g_hash_table_destroy (priv->pages_to_buttons);
236
237 /* Chain up to parent's finalize() method. */
238 G_OBJECT_CLASS (e_mail_config_sidebar_parent_class)->finalize (object);
239 }
240
241 static void
242 mail_config_sidebar_constructed (GObject *object)
243 {
244 EMailConfigSidebar *sidebar;
245 GtkNotebook *notebook;
246 gulong handler_id;
247 gint n_pages, ii;
248
249 sidebar = E_MAIL_CONFIG_SIDEBAR (object);
250
251 /* Chain up to parent's constructed() method. */
252 G_OBJECT_CLASS (e_mail_config_sidebar_parent_class)->
253 constructed (object);
254
255 gtk_orientable_set_orientation (
256 GTK_ORIENTABLE (sidebar), GTK_ORIENTATION_VERTICAL);
257
258 gtk_button_box_set_layout (
259 GTK_BUTTON_BOX (sidebar), GTK_BUTTONBOX_START);
260
261 gtk_box_set_homogeneous (GTK_BOX (sidebar), TRUE);
262 gtk_box_set_spacing (GTK_BOX (sidebar), 6);
263
264 /* Add buttons for existing notebook pages before
265 * binding to properties or connecting to signals. */
266
267 notebook = GTK_NOTEBOOK (sidebar->priv->notebook);
268 n_pages = gtk_notebook_get_n_pages (notebook);
269
270 for (ii = 0; ii < n_pages; ii++) {
271 GtkWidget *page;
272
273 page = gtk_notebook_get_nth_page (notebook, ii);
274 mail_config_sidebar_notebook_page_added (
275 notebook, page, (guint) ii, sidebar);
276 }
277
278 g_object_bind_property (
279 sidebar, "active",
280 notebook, "page",
281 G_BINDING_BIDIRECTIONAL |
282 G_BINDING_SYNC_CREATE);
283
284 handler_id = g_signal_connect (
285 notebook, "page-added",
286 G_CALLBACK (mail_config_sidebar_notebook_page_added),
287 sidebar);
288 sidebar->priv->page_added_handler_id = handler_id;
289
290 handler_id = g_signal_connect (
291 notebook, "page-removed",
292 G_CALLBACK (mail_config_sidebar_notebook_page_removed),
293 sidebar);
294 sidebar->priv->page_removed_handler_id = handler_id;
295
296 handler_id = g_signal_connect (
297 notebook, "page-reordered",
298 G_CALLBACK (mail_config_sidebar_notebook_page_reordered),
299 sidebar);
300 sidebar->priv->page_reordered_handler_id = handler_id;
301 }
302
303 static void
304 e_mail_config_sidebar_class_init (EMailConfigSidebarClass *class)
305 {
306 GObjectClass *object_class;
307
308 g_type_class_add_private (class, sizeof (EMailConfigSidebarPrivate));
309
310 object_class = G_OBJECT_CLASS (class);
311 object_class->set_property = mail_config_sidebar_set_property;
312 object_class->get_property = mail_config_sidebar_get_property;
313 object_class->dispose = mail_config_sidebar_dispose;
314 object_class->finalize = mail_config_sidebar_finalize;
315 object_class->constructed = mail_config_sidebar_constructed;
316
317 /* Use the same constraints as GtkNotebook:page. */
318 g_object_class_install_property (
319 object_class,
320 PROP_ACTIVE,
321 g_param_spec_int (
322 "active",
323 "Active",
324 "Index of the currently active button",
325 -1, G_MAXINT, -1,
326 G_PARAM_READWRITE |
327 G_PARAM_STATIC_STRINGS));
328
329 g_object_class_install_property (
330 object_class,
331 PROP_NOTEBOOK,
332 g_param_spec_object (
333 "notebook",
334 "Notebook",
335 "Mail configuration notebook",
336 E_TYPE_MAIL_CONFIG_NOTEBOOK,
337 G_PARAM_READWRITE |
338 G_PARAM_CONSTRUCT_ONLY |
339 G_PARAM_STATIC_STRINGS));
340 }
341
342 static void
343 e_mail_config_sidebar_init (EMailConfigSidebar *sidebar)
344 {
345 GHashTable *buttons_to_pages;
346 GHashTable *pages_to_buttons;
347
348 buttons_to_pages = g_hash_table_new_full (
349 (GHashFunc) g_direct_hash,
350 (GEqualFunc) g_direct_equal,
351 (GDestroyNotify) g_object_unref,
352 (GDestroyNotify) g_object_unref);
353
354 pages_to_buttons = g_hash_table_new_full (
355 (GHashFunc) g_direct_hash,
356 (GEqualFunc) g_direct_equal,
357 (GDestroyNotify) g_object_unref,
358 (GDestroyNotify) g_object_unref);
359
360 sidebar->priv = E_MAIL_CONFIG_SIDEBAR_GET_PRIVATE (sidebar);
361 sidebar->priv->buttons_to_pages = buttons_to_pages;
362 sidebar->priv->pages_to_buttons = pages_to_buttons;
363 }
364
365 GtkWidget *
366 e_mail_config_sidebar_new (EMailConfigNotebook *notebook)
367 {
368 g_return_val_if_fail (E_IS_MAIL_CONFIG_NOTEBOOK (notebook), NULL);
369
370 return g_object_new (
371 E_TYPE_MAIL_CONFIG_SIDEBAR,
372 "notebook", notebook, NULL);
373 }
374
375 gint
376 e_mail_config_sidebar_get_active (EMailConfigSidebar *sidebar)
377 {
378 g_return_val_if_fail (E_IS_MAIL_CONFIG_SIDEBAR (sidebar), -1);
379
380 return sidebar->priv->active;
381 }
382
383 void
384 e_mail_config_sidebar_set_active (EMailConfigSidebar *sidebar,
385 gint active)
386 {
387 GtkNotebook *notebook;
388 GtkWidget *page;
389
390 g_return_if_fail (E_IS_MAIL_CONFIG_SIDEBAR (sidebar));
391
392 notebook = GTK_NOTEBOOK (sidebar->priv->notebook);
393 page = gtk_notebook_get_nth_page (notebook, active);
394
395 sidebar->priv->active = (page != NULL) ? active : -1;
396
397 g_object_notify (G_OBJECT (sidebar), "active");
398
399 if (page != NULL) {
400 GHashTable *hash_table;
401 GtkToggleButton *button;
402
403 hash_table = sidebar->priv->pages_to_buttons;
404 button = g_hash_table_lookup (hash_table, page);
405 gtk_toggle_button_set_active (button, TRUE);
406 }
407 }
408
409 EMailConfigNotebook *
410 e_mail_config_sidebar_get_notebook (EMailConfigSidebar *sidebar)
411 {
412 g_return_val_if_fail (E_IS_MAIL_CONFIG_SIDEBAR (sidebar), NULL);
413
414 return sidebar->priv->notebook;
415 }