evolution-3.6.4/mail/e-mail-label-dialog.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-label-dialog.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-label-dialog.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-label-dialog.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-dialog.h"
 27 
 28 #include <glib/gi18n.h>
 29 
 30 #define E_MAIL_LABEL_DIALOG_GET_PRIVATE(obj) \
 31 	(G_TYPE_INSTANCE_GET_PRIVATE \
 32 	((obj), E_TYPE_MAIL_LABEL_DIALOG, EMailLabelDialogPrivate))
 33 
 34 struct _EMailLabelDialogPrivate {
 35 	GtkWidget *entry;
 36 	GtkWidget *colorsel;
 37 };
 38 
 39 enum {
 40 	PROP_0,
 41 	PROP_LABEL_COLOR,
 42 	PROP_LABEL_NAME
 43 };
 44 
 45 G_DEFINE_TYPE (EMailLabelDialog, e_mail_label_dialog, GTK_TYPE_DIALOG)
 46 
 47 static void
 48 mail_label_dialog_entry_changed_cb (EMailLabelDialog *dialog)
 49 {
 50 	const gchar *text;
 51 	gboolean sensitive;
 52 
 53 	text = gtk_entry_get_text (GTK_ENTRY (dialog->priv->entry));
 54 	sensitive = (text != NULL && *text != '\0');
 55 
 56 	gtk_dialog_set_response_sensitive (
 57 		GTK_DIALOG (dialog), GTK_RESPONSE_OK, sensitive);
 58 }
 59 
 60 static void
 61 mail_label_dialog_set_property (GObject *object,
 62                                 guint property_id,
 63                                 const GValue *value,
 64                                 GParamSpec *pspec)
 65 {
 66 	switch (property_id) {
 67 		case PROP_LABEL_COLOR:
 68 			e_mail_label_dialog_set_label_color (
 69 				E_MAIL_LABEL_DIALOG (object),
 70 				g_value_get_boxed (value));
 71 			return;
 72 
 73 		case PROP_LABEL_NAME:
 74 			e_mail_label_dialog_set_label_name (
 75 				E_MAIL_LABEL_DIALOG (object),
 76 				g_value_get_string (value));
 77 			return;
 78 	}
 79 
 80 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 81 }
 82 
 83 static void
 84 mail_label_dialog_get_property (GObject *object,
 85                                 guint property_id,
 86                                 GValue *value,
 87                                 GParamSpec *pspec)
 88 {
 89 	GdkColor color;
 90 
 91 	switch (property_id) {
 92 		case PROP_LABEL_COLOR:
 93 			e_mail_label_dialog_get_label_color (
 94 				E_MAIL_LABEL_DIALOG (object), &color);
 95 			g_value_set_boxed (value, &color);
 96 			return;
 97 
 98 		case PROP_LABEL_NAME:
 99 			g_value_set_string (
100 				value, e_mail_label_dialog_get_label_name (
101 				E_MAIL_LABEL_DIALOG (object)));
102 			return;
103 	}
104 
105 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
106 }
107 
108 static void
109 mail_label_dialog_dispose (GObject *object)
110 {
111 	EMailLabelDialogPrivate *priv;
112 
113 	priv = E_MAIL_LABEL_DIALOG_GET_PRIVATE (object);
114 
115 	if (priv->entry != NULL) {
116 		g_object_unref (priv->entry);
117 		priv->entry = NULL;
118 	}
119 
120 	if (priv->colorsel != NULL) {
121 		g_object_unref (priv->colorsel);
122 		priv->colorsel = NULL;
123 	}
124 
125 	/* Chain up to parent's dispose() method. */
126 	G_OBJECT_CLASS (e_mail_label_dialog_parent_class)->dispose (object);
127 }
128 
129 static void
130 mail_label_dialog_constructed (GObject *object)
131 {
132 	GtkWidget *action_area;
133 	GtkWidget *content_area;
134 
135 	/* XXX Override GTK's style property defaults for GtkDialog.
136 	 *     Hopefully GTK+ 3.0 will fix the broken defaults. */
137 
138 	action_area = gtk_dialog_get_action_area (GTK_DIALOG (object));
139 	content_area = gtk_dialog_get_content_area (GTK_DIALOG (object));
140 
141 	gtk_box_set_spacing (GTK_BOX (content_area), 12);
142 	gtk_container_set_border_width (GTK_CONTAINER (object), 12);
143 	gtk_container_set_border_width (GTK_CONTAINER (action_area), 0);
144 	gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
145 
146 	/* Chain up to parent's constructed() method. */
147 	G_OBJECT_CLASS (e_mail_label_dialog_parent_class)->constructed (object);
148 }
149 
150 static void
151 e_mail_label_dialog_class_init (EMailLabelDialogClass *class)
152 {
153 	GObjectClass *object_class;
154 
155 	g_type_class_add_private (class, sizeof (EMailLabelDialogPrivate));
156 
157 	object_class = G_OBJECT_CLASS (class);
158 	object_class->set_property = mail_label_dialog_set_property;
159 	object_class->get_property = mail_label_dialog_get_property;
160 	object_class->dispose = mail_label_dialog_dispose;
161 	object_class->constructed = mail_label_dialog_constructed;
162 
163 	g_object_class_install_property (
164 		object_class,
165 		PROP_LABEL_COLOR,
166 		g_param_spec_boxed (
167 			"label-color",
168 			"Label Color",
169 			NULL,
170 			GDK_TYPE_COLOR,
171 			G_PARAM_READWRITE));
172 
173 	g_object_class_install_property (
174 		object_class,
175 		PROP_LABEL_NAME,
176 		g_param_spec_string (
177 			"label-name",
178 			"Label Name",
179 			NULL,
180 			NULL,
181 			G_PARAM_READWRITE));
182 }
183 
184 static void
185 e_mail_label_dialog_init (EMailLabelDialog *dialog)
186 {
187 	GtkWidget *content_area;
188 	GtkWidget *container;
189 	GtkWidget *widget;
190 
191 	dialog->priv = E_MAIL_LABEL_DIALOG_GET_PRIVATE (dialog);
192 
193 	content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
194 
195 	gtk_dialog_add_button (
196 		GTK_DIALOG (dialog),
197 		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
198 
199 	gtk_dialog_add_button (
200 		GTK_DIALOG (dialog),
201 		GTK_STOCK_OK, GTK_RESPONSE_OK);
202 
203 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
204 
205 	container = content_area;
206 
207 	widget = gtk_hbox_new (FALSE, 6);
208 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
209 	gtk_widget_show (widget);
210 
211 	container = widget;
212 
213 	widget = gtk_entry_new ();
214 	gtk_entry_set_activates_default (GTK_ENTRY (widget), TRUE);
215 	gtk_box_pack_end (GTK_BOX (container), widget, TRUE, TRUE, 0);
216 	dialog->priv->entry = g_object_ref (widget);
217 	gtk_widget_show (widget);
218 
219 	g_signal_connect_swapped (
220 		widget, "changed",
221 		G_CALLBACK (mail_label_dialog_entry_changed_cb), dialog);
222 
223 	mail_label_dialog_entry_changed_cb (dialog);
224 
225 	widget = gtk_label_new_with_mnemonic (_("_Label name:"));
226 	gtk_label_set_mnemonic_widget (
227 		GTK_LABEL (widget), dialog->priv->entry);
228 	gtk_box_pack_end (GTK_BOX (container), widget, FALSE, FALSE, 0);
229 	gtk_widget_show (widget);
230 
231 	container = content_area;
232 
233 	widget = gtk_color_selection_new ();
234 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
235 	dialog->priv->colorsel = g_object_ref (widget);
236 	gtk_widget_show (widget);
237 }
238 
239 GtkWidget *
240 e_mail_label_dialog_new (GtkWindow *parent)
241 {
242 	return g_object_new (
243 		E_TYPE_MAIL_LABEL_DIALOG,
244 		"transient-for", parent, NULL);
245 }
246 
247 const gchar *
248 e_mail_label_dialog_get_label_name (EMailLabelDialog *dialog)
249 {
250 	GtkEntry *entry;
251 
252 	g_return_val_if_fail (E_IS_MAIL_LABEL_DIALOG (dialog), NULL);
253 
254 	entry = GTK_ENTRY (dialog->priv->entry);
255 
256 	return gtk_entry_get_text (entry);
257 }
258 
259 void
260 e_mail_label_dialog_set_label_name (EMailLabelDialog *dialog,
261                                     const gchar *label_name)
262 {
263 	GtkEntry *entry;
264 
265 	g_return_if_fail (E_IS_MAIL_LABEL_DIALOG (dialog));
266 
267 	entry = GTK_ENTRY (dialog->priv->entry);
268 
269 	if (g_strcmp0 (gtk_entry_get_text (entry), label_name) == 0)
270 		return;
271 
272 	gtk_entry_set_text (entry, label_name);
273 
274 	g_object_notify (G_OBJECT (dialog), "label-name");
275 }
276 
277 void
278 e_mail_label_dialog_get_label_color (EMailLabelDialog *dialog,
279                                      GdkColor *label_color)
280 {
281 	GtkColorSelection *colorsel;
282 
283 	g_return_if_fail (E_IS_MAIL_LABEL_DIALOG (dialog));
284 	g_return_if_fail (label_color != NULL);
285 
286 	colorsel = GTK_COLOR_SELECTION (dialog->priv->colorsel);
287 
288 	gtk_color_selection_get_current_color (colorsel, label_color);
289 }
290 
291 void
292 e_mail_label_dialog_set_label_color (EMailLabelDialog *dialog,
293                                      const GdkColor *label_color)
294 {
295 	GtkColorSelection *colorsel;
296 
297 	g_return_if_fail (E_IS_MAIL_LABEL_DIALOG (dialog));
298 	g_return_if_fail (label_color != NULL);
299 
300 	colorsel = GTK_COLOR_SELECTION (dialog->priv->colorsel);
301 
302 	gtk_color_selection_set_current_color (colorsel, label_color);
303 
304 	g_object_notify (G_OBJECT (dialog), "label-color");
305 }