No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-label-manager.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-label-manager.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-label-manager.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 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
19 *
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "e-mail-label-manager.h"
27
28 #include <glib/gi18n.h>
29 #include "e-mail-label-dialog.h"
30 #include "e-mail-label-tree-view.h"
31
32 #define E_MAIL_LABEL_MANAGER_GET_PRIVATE(obj) \
33 (G_TYPE_INSTANCE_GET_PRIVATE \
34 ((obj), E_TYPE_MAIL_LABEL_MANAGER, EMailLabelManagerPrivate))
35
36 struct _EMailLabelManagerPrivate {
37 GtkWidget *tree_view;
38 GtkWidget *add_button;
39 GtkWidget *edit_button;
40 GtkWidget *remove_button;
41 };
42
43 enum {
44 PROP_0,
45 PROP_LIST_STORE
46 };
47
48 enum {
49 ADD_LABEL,
50 EDIT_LABEL,
51 REMOVE_LABEL,
52 LAST_SIGNAL
53 };
54
55 static guint signals[LAST_SIGNAL];
56
57 G_DEFINE_TYPE (EMailLabelManager, e_mail_label_manager, GTK_TYPE_TABLE)
58
59 static void
60 mail_label_manager_selection_changed_cb (EMailLabelManager *manager,
61 GtkTreeSelection *selection)
62 {
63 GtkWidget *edit_button;
64 GtkWidget *remove_button;
65 GtkTreeModel *model;
66 GtkTreeIter iter;
67
68 edit_button = manager->priv->edit_button;
69 remove_button = manager->priv->remove_button;
70
71 if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
72 EMailLabelListStore *store;
73 gboolean sensitive;
74 gchar *label_tag;
75
76 store = E_MAIL_LABEL_LIST_STORE (model);
77 label_tag = e_mail_label_list_store_get_tag (store, &iter);
78 sensitive = !e_mail_label_tag_is_default (label_tag);
79 g_free (label_tag);
80
81 /* Disallow removing default labels. */
82 gtk_widget_set_sensitive (edit_button, TRUE);
83 gtk_widget_set_sensitive (remove_button, sensitive);
84 } else {
85 gtk_widget_set_sensitive (edit_button, FALSE);
86 gtk_widget_set_sensitive (remove_button, FALSE);
87 }
88 }
89
90 static void
91 mail_label_manager_set_property (GObject *object,
92 guint property_id,
93 const GValue *value,
94 GParamSpec *pspec)
95 {
96 switch (property_id) {
97 case PROP_LIST_STORE:
98 e_mail_label_manager_set_list_store (
99 E_MAIL_LABEL_MANAGER (object),
100 g_value_get_object (value));
101 return;
102 }
103
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
105 }
106
107 static void
108 mail_label_manager_get_property (GObject *object,
109 guint property_id,
110 GValue *value,
111 GParamSpec *pspec)
112 {
113 switch (property_id) {
114 case PROP_LIST_STORE:
115 g_value_set_object (
116 value, e_mail_label_manager_get_list_store (
117 E_MAIL_LABEL_MANAGER (object)));
118 return;
119 }
120
121 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
122 }
123
124 static void
125 mail_label_manager_dispose (GObject *object)
126 {
127 EMailLabelManagerPrivate *priv;
128
129 priv = E_MAIL_LABEL_MANAGER_GET_PRIVATE (object);
130
131 if (priv->tree_view != NULL) {
132 g_object_unref (priv->tree_view);
133 priv->tree_view = NULL;
134 }
135
136 if (priv->add_button != NULL) {
137 g_object_unref (priv->add_button);
138 priv->add_button = NULL;
139 }
140
141 if (priv->edit_button != NULL) {
142 g_object_unref (priv->edit_button);
143 priv->edit_button = NULL;
144 }
145
146 if (priv->remove_button != NULL) {
147 g_object_unref (priv->remove_button);
148 priv->remove_button = NULL;
149 }
150
151 /* Chain up to parent's dispose() method. */
152 G_OBJECT_CLASS (e_mail_label_manager_parent_class)->dispose (object);
153 }
154
155 static void
156 mail_label_manager_add_label (EMailLabelManager *manager)
157 {
158 EMailLabelDialog *label_dialog;
159 GtkTreeView *tree_view;
160 GtkTreeModel *model;
161 GtkWidget *dialog;
162 gpointer parent;
163 GdkColor label_color;
164 const gchar *label_name;
165
166 parent = gtk_widget_get_toplevel (GTK_WIDGET (manager));
167 parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
168 dialog = e_mail_label_dialog_new (parent);
169
170 gtk_window_set_title (GTK_WINDOW (dialog), _("Add Label"));
171
172 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
173 goto exit;
174
175 label_dialog = E_MAIL_LABEL_DIALOG (dialog);
176 label_name = e_mail_label_dialog_get_label_name (label_dialog);
177 e_mail_label_dialog_get_label_color (label_dialog, &label_color);
178
179 tree_view = GTK_TREE_VIEW (manager->priv->tree_view);
180 model = gtk_tree_view_get_model (tree_view);
181
182 e_mail_label_list_store_set (
183 E_MAIL_LABEL_LIST_STORE (model),
184 NULL, label_name, &label_color);
185
186 exit:
187 gtk_widget_destroy (dialog);
188 }
189
190 static void
191 mail_label_manager_edit_label (EMailLabelManager *manager)
192 {
193 EMailLabelDialog *label_dialog;
194 EMailLabelListStore *label_store;
195 GtkTreeSelection *selection;
196 GtkTreeView *tree_view;
197 GtkTreeModel *model;
198 GtkTreeIter iter;
199 GtkWidget *dialog;
200 GtkWidget *parent;
201 GdkColor label_color;
202 const gchar *new_name;
203 gchar *label_name;
204
205 tree_view = GTK_TREE_VIEW (manager->priv->tree_view);
206 selection = gtk_tree_view_get_selection (tree_view);
207
208 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
209 return;
210
211 label_store = E_MAIL_LABEL_LIST_STORE (model);
212 label_name = e_mail_label_list_store_get_name (label_store, &iter);
213 e_mail_label_list_store_get_color (label_store, &iter, &label_color);
214
215 parent = gtk_widget_get_toplevel (GTK_WIDGET (manager));
216 dialog = e_mail_label_dialog_new (GTK_WINDOW (parent));
217 label_dialog = E_MAIL_LABEL_DIALOG (dialog);
218
219 e_mail_label_dialog_set_label_name (label_dialog, label_name);
220 e_mail_label_dialog_set_label_color (label_dialog, &label_color);
221 gtk_window_set_title (GTK_WINDOW (dialog), _("Edit Label"));
222
223 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK)
224 goto exit;
225
226 new_name = e_mail_label_dialog_get_label_name (label_dialog);
227 e_mail_label_dialog_get_label_color (label_dialog, &label_color);
228
229 e_mail_label_list_store_set (
230 label_store, &iter, new_name, &label_color);
231
232 exit:
233 gtk_widget_destroy (dialog);
234
235 g_free (label_name);
236 }
237
238 static void
239 mail_label_manager_remove_label (EMailLabelManager *manager)
240 {
241 GtkTreeSelection *selection;
242 GtkTreeView *tree_view;
243 GtkTreeModel *model;
244 GtkTreeIter iter;
245
246 tree_view = GTK_TREE_VIEW (manager->priv->tree_view);
247 selection = gtk_tree_view_get_selection (tree_view);
248
249 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
250 return;
251
252 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
253 }
254
255 static void
256 e_mail_label_manager_class_init (EMailLabelManagerClass *class)
257 {
258 GObjectClass *object_class;
259
260 g_type_class_add_private (class, sizeof (EMailLabelManagerPrivate));
261
262 object_class = G_OBJECT_CLASS (class);
263 object_class->set_property = mail_label_manager_set_property;
264 object_class->get_property = mail_label_manager_get_property;
265 object_class->dispose = mail_label_manager_dispose;
266
267 class->add_label = mail_label_manager_add_label;
268 class->edit_label = mail_label_manager_edit_label;
269 class->remove_label = mail_label_manager_remove_label;
270
271 g_object_class_install_property (
272 object_class,
273 PROP_LIST_STORE,
274 g_param_spec_object (
275 "list-store",
276 "List Store",
277 NULL,
278 E_TYPE_MAIL_LABEL_LIST_STORE,
279 G_PARAM_READWRITE));
280
281 signals[ADD_LABEL] = g_signal_new (
282 "add-label",
283 G_OBJECT_CLASS_TYPE (class),
284 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
285 G_STRUCT_OFFSET (EMailLabelManagerClass, add_label),
286 NULL, NULL,
287 g_cclosure_marshal_VOID__VOID,
288 G_TYPE_NONE, 0);
289
290 signals[EDIT_LABEL] = g_signal_new (
291 "edit-label",
292 G_OBJECT_CLASS_TYPE (class),
293 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
294 G_STRUCT_OFFSET (EMailLabelManagerClass, edit_label),
295 NULL, NULL,
296 g_cclosure_marshal_VOID__VOID,
297 G_TYPE_NONE, 0);
298
299 signals[REMOVE_LABEL] = g_signal_new (
300 "remove-label",
301 G_OBJECT_CLASS_TYPE (class),
302 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
303 G_STRUCT_OFFSET (EMailLabelManagerClass, remove_label),
304 NULL, NULL,
305 g_cclosure_marshal_VOID__VOID,
306 G_TYPE_NONE, 0);
307 }
308
309 static void
310 e_mail_label_manager_init (EMailLabelManager *manager)
311 {
312 GtkTreeSelection *selection;
313 GtkWidget *container;
314 GtkWidget *widget;
315
316 manager->priv = E_MAIL_LABEL_MANAGER_GET_PRIVATE (manager);
317
318 gtk_table_resize (GTK_TABLE (manager), 2, 2);
319 gtk_table_set_col_spacings (GTK_TABLE (manager), 6);
320 gtk_table_set_row_spacings (GTK_TABLE (manager), 12);
321
322 container = GTK_WIDGET (manager);
323
324 widget = gtk_scrolled_window_new (NULL, NULL);
325 gtk_scrolled_window_set_policy (
326 GTK_SCROLLED_WINDOW (widget),
327 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
328 gtk_scrolled_window_set_shadow_type (
329 GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
330 gtk_table_attach (
331 GTK_TABLE (container), widget, 0, 1, 0, 1,
332 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
333 gtk_widget_show (widget);
334
335 container = widget;
336
337 widget = e_mail_label_tree_view_new ();
338 gtk_container_add (GTK_CONTAINER (container), widget);
339 manager->priv->tree_view = g_object_ref (widget);
340 gtk_widget_show (widget);
341
342 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
343
344 g_signal_connect_swapped (
345 selection, "changed",
346 G_CALLBACK (mail_label_manager_selection_changed_cb),
347 manager);
348
349 container = GTK_WIDGET (manager);
350
351 /* FIXME Clarify this. What menu? */
352 widget = gtk_label_new (
353 _("Note: Underscore in the label name is used\n"
354 "as mnemonic identifier in menu."));
355 gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_CENTER);
356 gtk_table_attach (
357 GTK_TABLE (container), widget,
358 0, 1, 1, 2, 0, 0, 0, 0);
359 gtk_widget_show (widget);
360
361 widget = gtk_vbutton_box_new ();
362 gtk_button_box_set_layout (
363 GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_START);
364 gtk_box_set_spacing (GTK_BOX (widget), 6);
365 gtk_table_attach (
366 GTK_TABLE (container), widget,
367 1, 2, 0, 2, 0, GTK_FILL, 0, 0);
368 gtk_widget_show (widget);
369
370 container = widget;
371
372 widget = gtk_button_new_from_stock (GTK_STOCK_ADD);
373 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
374 manager->priv->add_button = g_object_ref (widget);
375 gtk_widget_show (widget);
376
377 g_signal_connect_swapped (
378 widget, "clicked",
379 G_CALLBACK (e_mail_label_manager_add_label), manager);
380
381 widget = gtk_button_new_from_stock (GTK_STOCK_EDIT);
382 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
383 manager->priv->edit_button = g_object_ref (widget);
384 gtk_widget_show (widget);
385
386 g_signal_connect_swapped (
387 widget, "clicked",
388 G_CALLBACK (e_mail_label_manager_edit_label), manager);
389
390 widget = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
391 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
392 manager->priv->remove_button = g_object_ref (widget);
393 gtk_widget_show (widget);
394
395 g_signal_connect_swapped (
396 widget, "clicked",
397 G_CALLBACK (e_mail_label_manager_remove_label), manager);
398 }
399
400 GtkWidget *
401 e_mail_label_manager_new (void)
402 {
403 return g_object_new (E_TYPE_MAIL_LABEL_MANAGER, NULL);
404 }
405
406 void
407 e_mail_label_manager_add_label (EMailLabelManager *manager)
408 {
409 g_return_if_fail (E_IS_MAIL_LABEL_MANAGER (manager));
410
411 g_signal_emit (manager, signals[ADD_LABEL], 0);
412 }
413
414 void
415 e_mail_label_manager_edit_label (EMailLabelManager *manager)
416 {
417 g_return_if_fail (E_IS_MAIL_LABEL_MANAGER (manager));
418
419 g_signal_emit (manager, signals[EDIT_LABEL], 0);
420 }
421
422 void
423 e_mail_label_manager_remove_label (EMailLabelManager *manager)
424 {
425 g_return_if_fail (E_IS_MAIL_LABEL_MANAGER (manager));
426
427 g_signal_emit (manager, signals[REMOVE_LABEL], 0);
428 }
429
430 EMailLabelListStore *
431 e_mail_label_manager_get_list_store (EMailLabelManager *manager)
432 {
433 GtkTreeView *tree_view;
434 GtkTreeModel *model;
435
436 g_return_val_if_fail (E_IS_MAIL_LABEL_MANAGER (manager), NULL);
437
438 tree_view = GTK_TREE_VIEW (manager->priv->tree_view);
439 model = gtk_tree_view_get_model (tree_view);
440
441 return E_MAIL_LABEL_LIST_STORE (model);
442 }
443
444 void
445 e_mail_label_manager_set_list_store (EMailLabelManager *manager,
446 EMailLabelListStore *list_store)
447 {
448 GtkTreeView *tree_view;
449
450 g_return_if_fail (E_IS_MAIL_LABEL_MANAGER (manager));
451 g_return_if_fail (E_IS_MAIL_LABEL_LIST_STORE (list_store));
452
453 tree_view = GTK_TREE_VIEW (manager->priv->tree_view);
454 gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (list_store));
455
456 g_object_notify (G_OBJECT (manager), "list-store");
457 }