evolution-3.6.4/mail/e-mail-tag-editor.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-tag-editor.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-tag-editor.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  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		Jeffrey Stedfast <fejj@ximian.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include "e-mail-tag-editor.h"
 29 
 30 #include <time.h>
 31 #include <glib/gi18n-lib.h>
 32 
 33 #include "e-util/e-util.h"
 34 #include "widgets/misc/e-dateedit.h"
 35 
 36 #define E_MAIL_TAG_EDITOR_GET_PRIVATE(obj) \
 37 	(G_TYPE_INSTANCE_GET_PRIVATE \
 38 	((obj), E_TYPE_MAIL_TAG_EDITOR, EMailTagEditorPrivate))
 39 
 40 #define DEFAULT_FLAG 2  /* "Follow-Up" */
 41 
 42 struct _EMailTagEditorPrivate {
 43 	GtkTreeView *message_list;
 44 	GtkComboBox *combo_entry;
 45 	EDateEdit *target_date;
 46 
 47 	gboolean completed;
 48 	time_t completed_date;
 49 
 50 	/* EDateEdit settings */
 51 	gint week_start_day;
 52 	gboolean use_24_hour_format;
 53 };
 54 
 55 enum {
 56 	PROP_0,
 57 	PROP_COMPLETED,
 58 	PROP_USE_24_HOUR_FORMAT,
 59 	PROP_WEEK_START_DAY
 60 };
 61 
 62 enum {
 63 	COLUMN_FROM,
 64 	COLUMN_SUBJECT
 65 };
 66 
 67 G_DEFINE_TYPE (EMailTagEditor, e_mail_tag_editor, GTK_TYPE_DIALOG)
 68 
 69 static void
 70 mail_tag_editor_clear_clicked_cb (EMailTagEditor *editor)
 71 {
 72 	gtk_combo_box_set_active (editor->priv->combo_entry, DEFAULT_FLAG);
 73 	e_date_edit_set_time (editor->priv->target_date, (time_t) -1);
 74 	e_mail_tag_editor_set_completed (editor, FALSE);
 75 }
 76 
 77 static void
 78 mail_tag_editor_set_property (GObject *object,
 79                               guint property_id,
 80                               const GValue *value,
 81                               GParamSpec *pspec)
 82 {
 83 	switch (property_id) {
 84 		case PROP_COMPLETED:
 85 			e_mail_tag_editor_set_completed (
 86 				E_MAIL_TAG_EDITOR (object),
 87 				g_value_get_boolean (value));
 88 			return;
 89 
 90 		case PROP_USE_24_HOUR_FORMAT:
 91 			e_mail_tag_editor_set_use_24_hour_format (
 92 				E_MAIL_TAG_EDITOR (object),
 93 				g_value_get_boolean (value));
 94 			return;
 95 
 96 		case PROP_WEEK_START_DAY:
 97 			e_mail_tag_editor_set_week_start_day (
 98 				E_MAIL_TAG_EDITOR (object),
 99 				g_value_get_int (value));
100 			return;
101 	}
102 
103 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
104 }
105 
106 static void
107 mail_tag_editor_get_property (GObject *object,
108                               guint property_id,
109                               GValue *value,
110                               GParamSpec *pspec)
111 {
112 	switch (property_id) {
113 		case PROP_COMPLETED:
114 			g_value_set_boolean (
115 				value,
116 				e_mail_tag_editor_get_completed (
117 				E_MAIL_TAG_EDITOR (object)));
118 			return;
119 
120 		case PROP_USE_24_HOUR_FORMAT:
121 			g_value_set_boolean (
122 				value,
123 				e_mail_tag_editor_get_use_24_hour_format (
124 				E_MAIL_TAG_EDITOR (object)));
125 			return;
126 
127 		case PROP_WEEK_START_DAY:
128 			g_value_set_int (
129 				value,
130 				e_mail_tag_editor_get_week_start_day (
131 				E_MAIL_TAG_EDITOR (object)));
132 			return;
133 	}
134 
135 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
136 }
137 
138 static void
139 mail_tag_editor_realize (GtkWidget *widget)
140 {
141 	GtkWidget *action_area;
142 	GtkWidget *content_area;
143 
144 	/* Chain up to parent's realize() method. */
145 	GTK_WIDGET_CLASS (e_mail_tag_editor_parent_class)->realize (widget);
146 
147 	/* XXX Override GTK's brain-dead border width defaults. */
148 
149 	action_area = gtk_dialog_get_action_area (GTK_DIALOG (widget));
150 	content_area = gtk_dialog_get_content_area (GTK_DIALOG (widget));
151 
152 	gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
153 	gtk_container_set_border_width (GTK_CONTAINER (action_area), 12);
154 }
155 
156 static CamelTag *
157 mail_tag_editor_get_tag_list (EMailTagEditor *editor)
158 {
159 	CamelTag *tag_list = NULL;
160 	time_t date;
161 	gchar *text = NULL;
162 	GtkWidget *entry;
163 
164 	entry = gtk_bin_get_child (GTK_BIN (editor->priv->combo_entry));
165 	if (entry)
166 		text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
167 	camel_tag_set (&tag_list, "follow-up", text);
168 	g_free (text);
169 
170 	date = e_date_edit_get_time (editor->priv->target_date);
171 	if (date != (time_t) -1) {
172 		text = camel_header_format_date (date, 0);
173 		camel_tag_set (&tag_list, "due-by", text);
174 		g_free (text);
175 	} else
176 		camel_tag_set (&tag_list, "due-by", "");
177 
178 	if (e_mail_tag_editor_get_completed (editor)) {
179 		text = camel_header_format_date (
180 			editor->priv->completed_date, 0);
181 		camel_tag_set (&tag_list, "completed-on", text);
182 		g_free (text);
183 	} else
184 		camel_tag_set (&tag_list, "completed-on", "");
185 
186 	return tag_list;
187 }
188 
189 static void
190 mail_tag_editor_set_tag_list (EMailTagEditor *editor,
191                               CamelTag *tag_list)
192 {
193 	GtkWidget *child;
194 	const gchar *text;
195 	time_t date;
196 
197 	/* Extract the GtkEntry from the GtkComboBoxEntry. */
198 	child = gtk_bin_get_child (GTK_BIN (editor->priv->combo_entry));
199 
200 	/* XXX This is kind of cheating.  Since we only store the
201 	 *     translated tag there's no sure-fire way to determine
202 	 *     the corresponding combo box index (e.g. the tag may
203 	 *     have been set while running in a different locale). */
204 	text = camel_tag_get (&tag_list, "follow-up");
205 	if (text != NULL)
206 		gtk_entry_set_text (GTK_ENTRY (child), text);
207 
208 	text = camel_tag_get (&tag_list, "due-by");
209 	if (text != NULL && *text != '\0') {
210 		date = camel_header_decode_date (text, NULL);
211 		e_date_edit_set_time (editor->priv->target_date, date);
212 	} else
213 		e_date_edit_set_time (editor->priv->target_date, (time_t) -1);
214 
215 	text = camel_tag_get (&tag_list, "completed-on");
216 	if (text != NULL && *text != '\0') {
217 		date = camel_header_decode_date (text, NULL);
218 		if (date != (time_t) 0) {
219 			e_mail_tag_editor_set_completed (editor, TRUE);
220 			editor->priv->completed_date = date;
221 		}
222 	}
223 }
224 
225 static void
226 e_mail_tag_editor_class_init (EMailTagEditorClass *class)
227 {
228 	GObjectClass *object_class;
229 	GtkWidgetClass *widget_class;
230 
231 	g_type_class_add_private (class, sizeof (EMailTagEditorPrivate));
232 
233 	object_class = G_OBJECT_CLASS (class);
234 	object_class->set_property = mail_tag_editor_set_property;
235 	object_class->get_property = mail_tag_editor_get_property;
236 
237 	widget_class = GTK_WIDGET_CLASS (class);
238 	widget_class->realize = mail_tag_editor_realize;
239 
240 	class->get_tag_list = mail_tag_editor_get_tag_list;
241 	class->set_tag_list = mail_tag_editor_set_tag_list;
242 
243 	g_object_class_install_property (
244 		object_class,
245 		PROP_COMPLETED,
246 		g_param_spec_boolean (
247 			"completed",
248 			"Completed",
249 			NULL,
250 			FALSE,
251 			G_PARAM_READWRITE));
252 
253 	g_object_class_install_property (
254 		object_class,
255 		PROP_USE_24_HOUR_FORMAT,
256 		g_param_spec_boolean (
257 			"use-24-hour-format",
258 			"Use 24-Hour Format",
259 			NULL,
260 			TRUE,
261 			G_PARAM_READWRITE));
262 
263 	g_object_class_install_property (
264 		object_class,
265 		PROP_WEEK_START_DAY,
266 		g_param_spec_int (
267 			"week-start-day",
268 			"Week Start Day",
269 			NULL,
270 			0,  /* Monday */
271 			6,  /* Sunday */
272 			0,
273 			G_PARAM_READWRITE));
274 }
275 
276 static void
277 e_mail_tag_editor_init (EMailTagEditor *editor)
278 {
279 	GtkBuilder *builder;
280 	GtkDialog *dialog;
281 	GtkWidget *widget;
282 	GtkWidget *content_area;
283 	GtkWindow *window;
284 	GtkCellRenderer *renderer;
285 	GtkListStore *store;
286 
287 	editor->priv = E_MAIL_TAG_EDITOR_GET_PRIVATE (editor);
288 
289 	dialog = GTK_DIALOG (editor);
290 	window = GTK_WINDOW (editor);
291 
292 	gtk_window_set_default_size (window, 400, 500);
293 	gtk_window_set_title (window, _("Flag to Follow Up"));
294 	gtk_window_set_icon_name (window, "stock_mail-flag-for-followup");
295 
296 	gtk_dialog_add_buttons (
297 		dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
298 		GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
299 
300 	gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
301 
302 	content_area = gtk_dialog_get_content_area (dialog);
303 
304 	/* Load the rest of the UI from the builder file. */
305 
306 	builder = gtk_builder_new ();
307 	e_load_ui_builder_definition (builder, "mail-dialogs.ui");
308 
309 	widget = e_builder_get_widget (builder, "toplevel");
310 	gtk_box_pack_start (GTK_BOX (content_area), widget, TRUE, TRUE, 6);
311 
312 	widget = e_builder_get_widget (builder, "pixmap");
313 	g_object_bind_property (
314 		window, "icon-name",
315 		widget, "icon-name",
316 		G_BINDING_SYNC_CREATE);
317 
318 	widget = e_builder_get_widget (builder, "message_list");
319 	editor->priv->message_list = GTK_TREE_VIEW (widget);
320 
321 	store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
322 	gtk_tree_view_set_model (
323 		GTK_TREE_VIEW (widget), GTK_TREE_MODEL (store));
324 
325 	renderer = gtk_cell_renderer_text_new ();
326 	gtk_tree_view_insert_column_with_attributes (
327 		GTK_TREE_VIEW (widget), -1, _("From"),
328 		renderer, "text", 0, NULL);
329 
330 	renderer = gtk_cell_renderer_text_new ();
331 	gtk_tree_view_insert_column_with_attributes (
332 		GTK_TREE_VIEW (widget), -1, _("Subject"),
333 		renderer, "text", 1, NULL);
334 
335 	widget = e_builder_get_widget (builder, "combo");
336 	editor->priv->combo_entry = GTK_COMBO_BOX (widget);
337 	gtk_combo_box_set_active (GTK_COMBO_BOX (widget), DEFAULT_FLAG);
338 
339 	widget = e_builder_get_widget (builder, "target_date");
340 	editor->priv->target_date = E_DATE_EDIT (widget);
341 	g_object_bind_property (
342 		editor, "use-24-hour-format",
343 		widget, "use-24-hour-format",
344 		G_BINDING_SYNC_CREATE);
345 	g_object_bind_property (
346 		editor, "week-start-day",
347 		widget, "week-start-day",
348 		G_BINDING_SYNC_CREATE);
349 
350 	widget = e_builder_get_widget (builder, "completed");
351 	g_object_bind_property (
352 		editor, "completed",
353 		widget, "active",
354 		G_BINDING_BIDIRECTIONAL |
355 		G_BINDING_SYNC_CREATE);
356 
357 	widget = e_builder_get_widget (builder, "clear");
358 	g_signal_connect_swapped (
359 		widget, "clicked",
360 		G_CALLBACK (mail_tag_editor_clear_clicked_cb), editor);
361 
362 	g_object_unref (builder);
363 }
364 
365 GtkWidget *
366 e_mail_tag_editor_new (void)
367 {
368 	return g_object_new (E_TYPE_MAIL_TAG_EDITOR, NULL);
369 }
370 
371 gboolean
372 e_mail_tag_editor_get_completed (EMailTagEditor *editor)
373 {
374 	g_return_val_if_fail (E_IS_MAIL_TAG_EDITOR (editor), FALSE);
375 
376 	return editor->priv->completed;
377 }
378 
379 void
380 e_mail_tag_editor_set_completed (EMailTagEditor *editor,
381                                  gboolean completed)
382 {
383 	g_return_if_fail (E_IS_MAIL_TAG_EDITOR (editor));
384 
385 	if (editor->priv->completed == completed)
386 		return;
387 
388 	editor->priv->completed = completed;
389 	editor->priv->completed_date = completed ? time (NULL) : 0;
390 
391 	g_object_notify (G_OBJECT (editor), "completed");
392 }
393 
394 gint
395 e_mail_tag_editor_get_week_start_day (EMailTagEditor *editor)
396 {
397 	g_return_val_if_fail (E_IS_MAIL_TAG_EDITOR (editor), 1);
398 
399 	return editor->priv->week_start_day;
400 }
401 
402 void
403 e_mail_tag_editor_set_week_start_day (EMailTagEditor *editor,
404                                       gint week_start_day)
405 {
406 	g_return_if_fail (E_IS_MAIL_TAG_EDITOR (editor));
407 	g_return_if_fail (week_start_day >= 0 && week_start_day < 7);
408 
409 	if (editor->priv->week_start_day == week_start_day)
410 		return;
411 
412 	editor->priv->week_start_day = week_start_day;
413 
414 	g_object_notify (G_OBJECT (editor), "week-start-day");
415 }
416 
417 gboolean
418 e_mail_tag_editor_get_use_24_hour_format (EMailTagEditor *editor)
419 {
420 	g_return_val_if_fail (E_IS_MAIL_TAG_EDITOR (editor), TRUE);
421 
422 	return editor->priv->use_24_hour_format;
423 }
424 
425 void
426 e_mail_tag_editor_set_use_24_hour_format (EMailTagEditor *editor,
427                                           gboolean use_24_hour_format)
428 {
429 	g_return_if_fail (E_IS_MAIL_TAG_EDITOR (editor));
430 
431 	if (editor->priv->use_24_hour_format == use_24_hour_format)
432 		return;
433 
434 	editor->priv->use_24_hour_format = use_24_hour_format;
435 
436 	g_object_notify (G_OBJECT (editor), "use-24-hour-format");
437 }
438 
439 CamelTag *
440 e_mail_tag_editor_get_tag_list (EMailTagEditor *editor)
441 {
442 	EMailTagEditorClass *class;
443 
444 	g_return_val_if_fail (E_IS_MAIL_TAG_EDITOR (editor), NULL);
445 
446 	class = E_MAIL_TAG_EDITOR_GET_CLASS (editor);
447 	g_return_val_if_fail (class->get_tag_list != NULL, NULL);
448 
449 	return class->get_tag_list (editor);
450 }
451 
452 void
453 e_mail_tag_editor_set_tag_list (EMailTagEditor *editor,
454                                 CamelTag *tag_list)
455 {
456 	EMailTagEditorClass *class;
457 
458 	g_return_if_fail (E_IS_MAIL_TAG_EDITOR (editor));
459 	g_return_if_fail (tag_list != NULL);
460 
461 	class = E_MAIL_TAG_EDITOR_GET_CLASS (editor);
462 	g_return_if_fail (class->set_tag_list != NULL);
463 
464 	class->set_tag_list (editor, tag_list);
465 }
466 
467 void
468 e_mail_tag_editor_add_message (EMailTagEditor *editor,
469                                const gchar *from,
470                                const gchar *subject)
471 {
472 	GtkTreeModel *model;
473 	GtkTreeIter iter;
474 
475 	g_return_if_fail (E_MAIL_TAG_EDITOR (editor));
476 
477 	model = gtk_tree_view_get_model (editor->priv->message_list);
478 
479 	gtk_list_store_append (GTK_LIST_STORE (model), &iter);
480 
481 	gtk_list_store_set (
482 		GTK_LIST_STORE (model), &iter,
483 		COLUMN_FROM, from, COLUMN_SUBJECT, subject, -1);
484 }