evolution-3.6.4/mail/e-mail-config-defaults-page.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-config-defaults-page.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-config-defaults-page.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-config-defaults-page.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-defaults-page.h"
 20 
 21 #include <config.h>
 22 #include <glib/gi18n-lib.h>
 23 
 24 #include <libebackend/libebackend.h>
 25 
 26 #include <libemail-engine/e-mail-folder-utils.h>
 27 
 28 #include <mail/e-mail-config-page.h>
 29 #include <mail/em-folder-selection-button.h>
 30 
 31 #define E_MAIL_CONFIG_DEFAULTS_PAGE_GET_PRIVATE(obj) \
 32 	(G_TYPE_INSTANCE_GET_PRIVATE \
 33 	((obj), E_TYPE_MAIL_CONFIG_DEFAULTS_PAGE, EMailConfigDefaultsPagePrivate))
 34 
 35 struct _EMailConfigDefaultsPagePrivate {
 36 	EMailSession *session;
 37 	ESource *account_source;
 38 	ESource *identity_source;
 39 
 40 	GtkWidget *drafts_button;  /* not referenced */
 41 	GtkWidget *sent_button;    /* not referenced */
 42 	GtkWidget *trash_toggle;   /* not referenced */
 43 	GtkWidget *junk_toggle;    /* not referenced */
 44 };
 45 
 46 enum {
 47 	PROP_0,
 48 	PROP_ACCOUNT_SOURCE,
 49 	PROP_IDENTITY_SOURCE,
 50 	PROP_SESSION
 51 };
 52 
 53 /* Forward Declarations */
 54 static void	e_mail_config_defaults_page_interface_init
 55 					(EMailConfigPageInterface *interface);
 56 
 57 G_DEFINE_TYPE_WITH_CODE (
 58 	EMailConfigDefaultsPage,
 59 	e_mail_config_defaults_page,
 60 	GTK_TYPE_BOX,
 61 	G_IMPLEMENT_INTERFACE (
 62 		E_TYPE_EXTENSIBLE, NULL)
 63 	G_IMPLEMENT_INTERFACE (
 64 		E_TYPE_MAIL_CONFIG_PAGE,
 65 		e_mail_config_defaults_page_interface_init))
 66 
 67 static CamelSettings *
 68 mail_config_defaults_page_maybe_get_settings (EMailConfigDefaultsPage *page)
 69 {
 70 	ESource *source;
 71 	ESourceCamel *camel_ext;
 72 	ESourceBackend *backend_ext;
 73 	const gchar *backend_name;
 74 	const gchar *extension_name;
 75 
 76 	source = e_mail_config_defaults_page_get_account_source (page);
 77 
 78 	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
 79 	backend_ext = e_source_get_extension (source, extension_name);
 80 	backend_name = e_source_backend_get_backend_name (backend_ext);
 81 	extension_name = e_source_camel_get_extension_name (backend_name);
 82 
 83 	/* Avoid accidentally creating a backend-specific extension
 84 	 * in the mail account source if the mail account source is
 85 	 * part of a collection, in which case the backend-specific
 86 	 * extension is kept in the top-level collection source. */
 87 	if (!e_source_has_extension (source, extension_name))
 88 		return NULL;
 89 
 90 	camel_ext = e_source_get_extension (source, extension_name);
 91 
 92 	return e_source_camel_get_settings (camel_ext);
 93 }
 94 
 95 static CamelStore *
 96 mail_config_defaults_page_ref_store (EMailConfigDefaultsPage *page)
 97 {
 98 	ESource *source;
 99 	EMailSession *session;
100 	CamelService *service;
101 	const gchar *uid;
102 
103 	session = e_mail_config_defaults_page_get_session (page);
104 	source = e_mail_config_defaults_page_get_account_source (page);
105 
106 	uid = e_source_get_uid (source);
107 	service = camel_session_ref_service (CAMEL_SESSION (session), uid);
108 
109 	if (service == NULL)
110 		return NULL;
111 
112 	if (!CAMEL_IS_STORE (service)) {
113 		g_object_unref (service);
114 		return NULL;
115 	}
116 
117 	return CAMEL_STORE (service);
118 }
119 
120 static gboolean
121 mail_config_defaults_page_addrs_to_string (GBinding *binding,
122                                            const GValue *source_value,
123                                            GValue *target_value,
124                                            gpointer unused)
125 {
126 	gchar **strv;
127 
128 	strv = g_value_dup_boxed (source_value);
129 
130 	if (strv != NULL) {
131 		gchar *string = g_strjoinv ("; ", strv);
132 		g_value_set_string (target_value, string);
133 		g_free (string);
134 	} else {
135 		g_value_set_string (target_value, "");
136 	}
137 
138 	g_strfreev (strv);
139 
140 	return TRUE;
141 }
142 
143 static gboolean
144 mail_config_defaults_page_string_to_addrs (GBinding *binding,
145                                            const GValue *source_value,
146                                            GValue *target_value,
147                                            gpointer unused)
148 {
149 	CamelInternetAddress *address;
150 	const gchar *string;
151 	gchar **strv;
152 	gint n_addresses, ii;
153 
154 	string = g_value_get_string (source_value);
155 
156 	address = camel_internet_address_new ();
157 	n_addresses = camel_address_decode (CAMEL_ADDRESS (address), string);
158 
159 	if (n_addresses < 0) {
160 		g_object_unref (address);
161 		return FALSE;
162 
163 	} else if (n_addresses == 0) {
164 		g_value_set_boxed (target_value, NULL);
165 		g_object_unref (address);
166 		return TRUE;
167 	}
168 
169 	strv = g_new0 (gchar *, n_addresses + 1);
170 
171 	for (ii = 0; ii < n_addresses; ii++) {
172 		const gchar *name = NULL;
173 		const gchar *addr = NULL;
174 
175 		camel_internet_address_get (address, ii, &name, &addr);
176 		strv[ii] = camel_internet_address_format_address (name, addr);
177 	}
178 
179 	g_value_take_boxed (target_value, strv);
180 
181 	return TRUE;
182 }
183 
184 static gboolean
185 mail_config_defaults_page_folder_name_to_uri (GBinding *binding,
186                                               const GValue *source_value,
187                                               GValue *target_value,
188                                               gpointer data)
189 {
190 	EMailConfigDefaultsPage *page;
191 	CamelStore *store;
192 	const gchar *folder_name;
193 	gchar *folder_uri = NULL;
194 
195 	page = E_MAIL_CONFIG_DEFAULTS_PAGE (data);
196 	store = mail_config_defaults_page_ref_store (page);
197 	g_return_val_if_fail (store != NULL, FALSE);
198 
199 	folder_name = g_value_get_string (source_value);
200 
201 	if (folder_name != NULL)
202 		folder_uri = e_mail_folder_uri_build (store, folder_name);
203 
204 	g_value_set_string (target_value, folder_uri);
205 
206 	g_free (folder_uri);
207 
208 	g_object_unref (store);
209 
210 	return TRUE;
211 }
212 
213 static gboolean
214 mail_config_defaults_page_folder_uri_to_name (GBinding *binding,
215                                               const GValue *source_value,
216                                               GValue *target_value,
217                                               gpointer data)
218 {
219 	EMailConfigDefaultsPage *page;
220 	EMailSession *session;
221 	const gchar *folder_uri;
222 	gchar *folder_name = NULL;
223 	GError *error = NULL;
224 
225 	page = E_MAIL_CONFIG_DEFAULTS_PAGE (data);
226 	session = e_mail_config_defaults_page_get_session (page);
227 
228 	folder_uri = g_value_get_string (source_value);
229 
230 	if (folder_uri == NULL) {
231 		g_value_set_string (target_value, NULL);
232 		return TRUE;
233 	}
234 
235 	e_mail_folder_uri_parse (
236 		CAMEL_SESSION (session), folder_uri,
237 		NULL, &folder_name, &error);
238 
239 	if (error != NULL) {
240 		g_warn_if_fail (folder_name == NULL);
241 		g_warning ("%s: %s", G_STRFUNC, error->message);
242 		g_error_free (error);
243 		return FALSE;
244 	}
245 
246 	g_return_val_if_fail (folder_name != NULL, FALSE);
247 
248 	g_value_set_string (target_value, folder_name);
249 
250 	g_free (folder_name);
251 
252 	return TRUE;
253 }
254 
255 static void
256 mail_config_defaults_page_restore_folders (EMailConfigDefaultsPage *page)
257 {
258 	EMFolderSelectionButton *button;
259 	EMailSession *session;
260 	EMailLocalFolder type;
261 	const gchar *folder_uri;
262 
263 	session = e_mail_config_defaults_page_get_session (page);
264 
265 	type = E_MAIL_LOCAL_FOLDER_DRAFTS;
266 	button = EM_FOLDER_SELECTION_BUTTON (page->priv->drafts_button);
267 	folder_uri = e_mail_session_get_local_folder_uri (session, type);
268 	em_folder_selection_button_set_folder_uri (button, folder_uri);
269 
270 	if (gtk_widget_is_sensitive (page->priv->sent_button)) {
271 		type = E_MAIL_LOCAL_FOLDER_SENT;
272 		button = EM_FOLDER_SELECTION_BUTTON (page->priv->sent_button);
273 		folder_uri = e_mail_session_get_local_folder_uri (session, type);
274 		em_folder_selection_button_set_folder_uri (button, folder_uri);
275 	}
276 }
277 
278 static void
279 mail_config_defaults_page_restore_real_folder (GtkToggleButton *toggle_button)
280 {
281 	gtk_toggle_button_set_active (toggle_button, FALSE);
282 }
283 
284 static GtkWidget *
285 mail_config_defaults_page_add_real_folder (EMailConfigDefaultsPage *page,
286                                            GtkSizeGroup *size_group,
287                                            GtkButton *revert_button,
288                                            const gchar *toggle_label,
289                                            const gchar *dialog_caption,
290                                            const gchar *property_name,
291                                            const gchar *use_property_name)
292 {
293 	GtkWidget *box;
294 	GtkWidget *check_button;
295 	GtkWidget *folder_button;
296 	EMailSession *session;
297 	CamelSettings *settings;
298 	CamelStore *store;
299 	GObjectClass *class;
300 
301 	session = e_mail_config_defaults_page_get_session (page);
302 	settings = mail_config_defaults_page_maybe_get_settings (page);
303 
304 	if (settings == NULL)
305 		return NULL;
306 
307 	/* These folder settings are backend-specific, so check if
308 	 * the CamelSettings class has the property names we need. */
309 
310 	class = G_OBJECT_GET_CLASS (settings);
311 
312 	if (g_object_class_find_property (class, property_name) == NULL)
313 		return NULL;
314 
315 	if (g_object_class_find_property (class, use_property_name) == NULL)
316 		return NULL;
317 
318 	store = mail_config_defaults_page_ref_store (page);
319 	g_return_val_if_fail (store != NULL, NULL);
320 
321 	/* We're good to go. */
322 
323 	box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
324 
325 	check_button = gtk_check_button_new_with_mnemonic (toggle_label);
326 	g_object_set (check_button, "xalign", 1.0, NULL);
327 	gtk_size_group_add_widget (size_group, check_button);
328 	gtk_box_pack_start (GTK_BOX (box), check_button, FALSE, FALSE, 0);
329 	gtk_widget_show (check_button);
330 
331 	g_object_bind_property (
332 		settings, use_property_name,
333 		check_button, "active",
334 		G_BINDING_BIDIRECTIONAL |
335 		G_BINDING_SYNC_CREATE);
336 
337 	folder_button = em_folder_selection_button_new (
338 		session, "", dialog_caption);
339 	em_folder_selection_button_set_store (
340 		EM_FOLDER_SELECTION_BUTTON (folder_button), store);
341 	gtk_box_pack_start (GTK_BOX (box), folder_button, TRUE, TRUE, 0);
342 	gtk_widget_show (folder_button);
343 
344 	/* XXX CamelSettings only stores the folder's path name, but the
345 	 *     EMFolderSelectionButton requires a full folder URI, so we
346 	 *     have to do some fancy transforms for the binding to work. */
347 	g_object_bind_property_full (
348 		settings, property_name,
349 		folder_button, "folder-uri",
350 		G_BINDING_BIDIRECTIONAL |
351 		G_BINDING_SYNC_CREATE,
352 		mail_config_defaults_page_folder_name_to_uri,
353 		mail_config_defaults_page_folder_uri_to_name,
354 		g_object_ref (page),
355 		(GDestroyNotify) g_object_unref);
356 
357 	g_object_bind_property (
358 		check_button, "active",
359 		folder_button, "sensitive",
360 		G_BINDING_SYNC_CREATE);
361 
362 	g_signal_connect_swapped (
363 		revert_button, "clicked",
364 		G_CALLBACK (mail_config_defaults_page_restore_real_folder),
365 		check_button);
366 
367 	g_object_unref (store);
368 
369 	return box;
370 }
371 
372 static void
373 mail_config_defaults_page_set_account_source (EMailConfigDefaultsPage *page,
374                                               ESource *account_source)
375 {
376 	g_return_if_fail (E_IS_SOURCE (account_source));
377 	g_return_if_fail (page->priv->account_source == NULL);
378 
379 	page->priv->account_source = g_object_ref (account_source);
380 }
381 
382 static void
383 mail_config_defaults_page_set_identity_source (EMailConfigDefaultsPage *page,
384                                                ESource *identity_source)
385 {
386 	g_return_if_fail (E_IS_SOURCE (identity_source));
387 	g_return_if_fail (page->priv->identity_source == NULL);
388 
389 	page->priv->identity_source = g_object_ref (identity_source);
390 }
391 
392 static void
393 mail_config_defaults_page_set_session (EMailConfigDefaultsPage *page,
394                                        EMailSession *session)
395 {
396 	g_return_if_fail (E_IS_MAIL_SESSION (session));
397 	g_return_if_fail (page->priv->session == NULL);
398 
399 	page->priv->session = g_object_ref (session);
400 }
401 
402 static void
403 mail_config_defaults_page_set_property (GObject *object,
404                                         guint property_id,
405                                         const GValue *value,
406                                         GParamSpec *pspec)
407 {
408 	switch (property_id) {
409 		case PROP_ACCOUNT_SOURCE:
410 			mail_config_defaults_page_set_account_source (
411 				E_MAIL_CONFIG_DEFAULTS_PAGE (object),
412 				g_value_get_object (value));
413 			return;
414 
415 		case PROP_IDENTITY_SOURCE:
416 			mail_config_defaults_page_set_identity_source (
417 				E_MAIL_CONFIG_DEFAULTS_PAGE (object),
418 				g_value_get_object (value));
419 			return;
420 
421 		case PROP_SESSION:
422 			mail_config_defaults_page_set_session (
423 				E_MAIL_CONFIG_DEFAULTS_PAGE (object),
424 				g_value_get_object (value));
425 			return;
426 	}
427 
428 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
429 }
430 
431 static void
432 mail_config_defaults_page_get_property (GObject *object,
433                                         guint property_id,
434                                         GValue *value,
435                                         GParamSpec *pspec)
436 {
437 	switch (property_id) {
438 		case PROP_ACCOUNT_SOURCE:
439 			g_value_set_object (
440 				value,
441 				e_mail_config_defaults_page_get_account_source (
442 				E_MAIL_CONFIG_DEFAULTS_PAGE (object)));
443 			return;
444 
445 		case PROP_IDENTITY_SOURCE:
446 			g_value_set_object (
447 				value,
448 				e_mail_config_defaults_page_get_identity_source (
449 				E_MAIL_CONFIG_DEFAULTS_PAGE (object)));
450 			return;
451 
452 		case PROP_SESSION:
453 			g_value_set_object (
454 				value,
455 				e_mail_config_defaults_page_get_session (
456 				E_MAIL_CONFIG_DEFAULTS_PAGE (object)));
457 			return;
458 	}
459 
460 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
461 }
462 
463 static void
464 mail_config_defaults_page_dispose (GObject *object)
465 {
466 	EMailConfigDefaultsPagePrivate *priv;
467 
468 	priv = E_MAIL_CONFIG_DEFAULTS_PAGE_GET_PRIVATE (object);
469 
470 	if (priv->identity_source != NULL) {
471 		g_object_unref (priv->identity_source);
472 		priv->identity_source = NULL;
473 	}
474 
475 	if (priv->session != NULL) {
476 		g_object_unref (priv->session);
477 		priv->session = NULL;
478 	}
479 
480 	/* Chain up to parent's dispose() method. */
481 	G_OBJECT_CLASS (e_mail_config_defaults_page_parent_class)->
482 		dispose (object);
483 }
484 
485 static void
486 mail_config_defaults_page_constructed (GObject *object)
487 {
488 	EMailConfigDefaultsPage *page;
489 	EMailSession *session;
490 	ESource *source;
491 	ESourceBackend *account_ext;
492 	ESourceMailComposition *composition_ext;
493 	ESourceMailSubmission *submission_ext;
494 	ESourceMDN *mdn_ext;
495 	GtkLabel *label;
496 	GtkButton *button;
497 	GtkWidget *widget;
498 	GtkWidget *container;
499 	GtkSizeGroup *size_group;
500 	GEnumClass *enum_class;
501 	GEnumValue *enum_value;
502 	EMdnResponsePolicy policy;
503 	CamelProvider *provider = NULL;
504 	const gchar *extension_name;
505 	const gchar *text;
506 	gchar *markup;
507 
508 	page = E_MAIL_CONFIG_DEFAULTS_PAGE (object);
509 
510 	/* Chain up to parent's constructed() method. */
511 	G_OBJECT_CLASS (e_mail_config_defaults_page_parent_class)->
512 		constructed (object);
513 
514 	source = e_mail_config_defaults_page_get_account_source (page);
515 	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
516 	account_ext = e_source_get_extension (source, extension_name);
517 	if (e_source_backend_get_backend_name (account_ext))
518 		provider = camel_provider_get (e_source_backend_get_backend_name (account_ext), NULL);
519 
520 	session = e_mail_config_defaults_page_get_session (page);
521 	source = e_mail_config_defaults_page_get_identity_source (page);
522 
523 	extension_name = E_SOURCE_EXTENSION_MAIL_COMPOSITION;
524 	composition_ext = e_source_get_extension (source, extension_name);
525 
526 	extension_name = E_SOURCE_EXTENSION_MAIL_SUBMISSION;
527 	submission_ext = e_source_get_extension (source, extension_name);
528 
529 	extension_name = E_SOURCE_EXTENSION_MDN;
530 	mdn_ext = e_source_get_extension (source, extension_name);
531 
532 	gtk_orientable_set_orientation (
533 		GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);
534 
535 	gtk_box_set_spacing (GTK_BOX (page), 12);
536 
537 	size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
538 
539 	/*** Special Folders ***/
540 
541 	widget = gtk_grid_new ();
542 	gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
543 	gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
544 	gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
545 	gtk_widget_show (widget);
546 
547 	container = widget;
548 
549 	text = _("Special Folders");
550 	markup = g_markup_printf_escaped ("<b>%s</b>", text);
551 	widget = gtk_label_new (markup);
552 	gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
553 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
554 	gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 2, 1);
555 	gtk_widget_show (widget);
556 	g_free (markup);
557 
558 	text = _("Draft Messages _Folder:");
559 	widget = gtk_label_new_with_mnemonic (text);
560 	gtk_widget_set_margin_left (widget, 12);
561 	gtk_size_group_add_widget (size_group, widget);
562 	gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
563 	gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
564 	gtk_widget_show (widget);
565 
566 	label = GTK_LABEL (widget);
567 
568 	text = _("Choose a folder for saving draft messages.");
569 	widget = em_folder_selection_button_new (session, "", text);
570 	gtk_widget_set_hexpand (widget, TRUE);
571 	gtk_label_set_mnemonic_widget (label, widget);
572 	gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 1, 1);
573 	page->priv->drafts_button = widget;  /* not referenced */
574 	gtk_widget_show (widget);
575 
576 	g_object_bind_property (
577 		composition_ext, "drafts-folder",
578 		widget, "folder-uri",
579 		G_BINDING_BIDIRECTIONAL |
580 		G_BINDING_SYNC_CREATE);
581 
582 	text = _("Sent _Messages Folder:");
583 	widget = gtk_label_new_with_mnemonic (text);
584 	gtk_widget_set_margin_left (widget, 12);
585 	gtk_size_group_add_widget (size_group, widget);
586 	gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
587 	gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
588 	gtk_widget_show (widget);
589 
590 	label = GTK_LABEL (widget);
591 
592 	text = _("Choose a folder for saving sent messages.");
593 	widget = em_folder_selection_button_new (session, "", text);
594 	gtk_widget_set_hexpand (widget, TRUE);
595 	gtk_label_set_mnemonic_widget (label, widget);
596 	gtk_grid_attach (GTK_GRID (container), widget, 1, 2, 1, 1);
597 	page->priv->sent_button = widget;  /* not referenced */
598 	gtk_widget_show (widget);
599 
600 	if (provider && (provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER) != 0) {
601 		gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
602 		gtk_widget_set_sensitive (widget, FALSE);
603 	}
604 
605 	g_object_bind_property (
606 		submission_ext, "sent-folder",
607 		widget, "folder-uri",
608 		G_BINDING_BIDIRECTIONAL |
609 		G_BINDING_SYNC_CREATE);
610 
611 	widget = gtk_button_new_with_mnemonic (_("_Restore Defaults"));
612 	gtk_widget_set_halign (widget, GTK_ALIGN_START);
613 	gtk_grid_attach (GTK_GRID (container), widget, 1, 5, 1, 1);
614 	gtk_widget_show (widget);
615 
616 	g_signal_connect_swapped (
617 		widget, "clicked",
618 		G_CALLBACK (mail_config_defaults_page_restore_folders),
619 		page);
620 
621 	button = GTK_BUTTON (widget);
622 
623 	widget = mail_config_defaults_page_add_real_folder (
624 		page, size_group, button,
625 		_("Use a Real Folder for _Trash:"),
626 		_("Choose a folder for deleted messages."),
627 		"real-trash-path", "use-real-trash-path");
628 	if (widget != NULL) {
629 		gtk_grid_attach (GTK_GRID (container), widget, 0, 3, 2, 1);
630 		gtk_widget_show (widget);
631 	}
632 
633 	widget = mail_config_defaults_page_add_real_folder (
634 		page, size_group, button,
635 		_("Use a Real Folder for _Junk:"),
636 		_("Choose a folder for junk messages."),
637 		"real-junk-path", "use-real-junk-path");
638 	if (widget != NULL) {
639 		gtk_grid_attach (GTK_GRID (container), widget, 0, 4, 2, 1);
640 		gtk_widget_show (widget);
641 	}
642 
643 	/*** Composing Messages ***/
644 
645 	widget = gtk_grid_new ();
646 	gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
647 	gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
648 	gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
649 	gtk_widget_show (widget);
650 
651 	container = widget;
652 
653 	text = _("Composing Messages");
654 	markup = g_markup_printf_escaped ("<b>%s</b>", text);
655 	widget = gtk_label_new (markup);
656 	gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
657 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
658 	gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
659 	gtk_widget_show (widget);
660 	g_free (markup);
661 
662 	text = _("Alway_s carbon-copy (cc) to:");
663 	widget = gtk_label_new_with_mnemonic (text);
664 	gtk_widget_set_margin_left (widget, 12);
665 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
666 	gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
667 	gtk_widget_show (widget);
668 
669 	label = GTK_LABEL (widget);
670 
671 	widget = gtk_entry_new ();
672 	gtk_widget_set_hexpand (widget, TRUE);
673 	gtk_widget_set_margin_left (widget, 12);
674 	gtk_label_set_mnemonic_widget (label, widget);
675 	gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
676 	gtk_widget_show (widget);
677 
678 	g_object_bind_property_full (
679 		composition_ext, "cc",
680 		widget, "text",
681 		G_BINDING_BIDIRECTIONAL |
682 		G_BINDING_SYNC_CREATE,
683 		mail_config_defaults_page_addrs_to_string,
684 		mail_config_defaults_page_string_to_addrs,
685 		NULL, (GDestroyNotify) NULL);
686 
687 	text = _("Always _blind carbon-copy (bcc) to:");
688 	widget = gtk_label_new_with_mnemonic (text);
689 	gtk_widget_set_margin_left (widget, 12);
690 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
691 	gtk_grid_attach (GTK_GRID (container), widget, 0, 3, 1, 1);
692 	gtk_widget_show (widget);
693 
694 	label = GTK_LABEL (widget);
695 
696 	widget = gtk_entry_new ();
697 	gtk_widget_set_hexpand (widget, TRUE);
698 	gtk_widget_set_margin_left (widget, 12);
699 	gtk_label_set_mnemonic_widget (label, widget);
700 	gtk_grid_attach (GTK_GRID (container), widget, 0, 4, 1, 1);
701 	gtk_widget_show (widget);
702 
703 	g_object_bind_property_full (
704 		composition_ext, "bcc",
705 		widget, "text",
706 		G_BINDING_BIDIRECTIONAL |
707 		G_BINDING_SYNC_CREATE,
708 		mail_config_defaults_page_addrs_to_string,
709 		mail_config_defaults_page_string_to_addrs,
710 		NULL, (GDestroyNotify) NULL);
711 
712 	/*** Message Receipts ***/
713 
714 	widget = gtk_grid_new ();
715 	gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
716 	gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
717 	gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
718 	gtk_widget_show (widget);
719 
720 	container = widget;
721 
722 	text = _("Message Receipts");
723 	markup = g_markup_printf_escaped ("<b>%s</b>", text);
724 	widget = gtk_label_new (markup);
725 	gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
726 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
727 	gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 2, 1);
728 	gtk_widget_show (widget);
729 	g_free (markup);
730 
731 	text = _("S_end message receipts:");
732 	widget = gtk_label_new_with_mnemonic (text);
733 	gtk_widget_set_margin_left (widget, 12);
734 	gtk_size_group_add_widget (size_group, widget);
735 	gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
736 	gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
737 	gtk_widget_show (widget);
738 
739 	label = GTK_LABEL (widget);
740 
741 	widget = gtk_combo_box_text_new ();
742 	gtk_widget_set_hexpand (widget, TRUE);
743 	gtk_label_set_mnemonic_widget (label, widget);
744 	gtk_grid_attach (GTK_GRID (container), widget, 1, 1, 1, 1);
745 	gtk_widget_show (widget);
746 
747 	/* XXX This is a pain in the butt, but we want to avoid hard-coding
748 	 *     string values from the EMdnResponsePolicy enum class in case
749 	 *     they change in the future. */
750 	enum_class = g_type_class_ref (E_TYPE_MDN_RESPONSE_POLICY);
751 	policy = E_MDN_RESPONSE_POLICY_NEVER;
752 	enum_value = g_enum_get_value (enum_class, policy);
753 	g_return_if_fail (enum_value != NULL);
754 	gtk_combo_box_text_append (
755 		GTK_COMBO_BOX_TEXT (widget),
756 		enum_value->value_nick, _("Never"));
757 	policy = E_MDN_RESPONSE_POLICY_ALWAYS;
758 	enum_value = g_enum_get_value (enum_class, policy);
759 	g_return_if_fail (enum_value != NULL);
760 	gtk_combo_box_text_append (
761 		GTK_COMBO_BOX_TEXT (widget),
762 		enum_value->value_nick, _("Always"));
763 	policy = E_MDN_RESPONSE_POLICY_ASK;
764 	enum_value = g_enum_get_value (enum_class, policy);
765 	g_return_if_fail (enum_value != NULL);
766 	gtk_combo_box_text_append (
767 		GTK_COMBO_BOX_TEXT (widget),
768 		enum_value->value_nick, _("Ask for each message"));
769 	g_type_class_unref (enum_class);
770 
771 	g_object_bind_property_full (
772 		mdn_ext, "response-policy",
773 		widget, "active-id",
774 		G_BINDING_BIDIRECTIONAL |
775 		G_BINDING_SYNC_CREATE,
776 		e_binding_transform_enum_value_to_nick,
777 		e_binding_transform_enum_nick_to_value,
778 		NULL, (GDestroyNotify) NULL);
779 
780 	g_object_unref (size_group);
781 
782 	e_extensible_load_extensions (E_EXTENSIBLE (page));
783 }
784 
785 static void
786 e_mail_config_defaults_page_class_init (EMailConfigDefaultsPageClass *class)
787 {
788 	GObjectClass *object_class;
789 
790 	g_type_class_add_private (
791 		class, sizeof (EMailConfigDefaultsPagePrivate));
792 
793 	object_class = G_OBJECT_CLASS (class);
794 	object_class->set_property = mail_config_defaults_page_set_property;
795 	object_class->get_property = mail_config_defaults_page_get_property;
796 	object_class->dispose = mail_config_defaults_page_dispose;
797 	object_class->constructed = mail_config_defaults_page_constructed;
798 
799 	g_object_class_install_property (
800 		object_class,
801 		PROP_ACCOUNT_SOURCE,
802 		g_param_spec_object (
803 			"account-source",
804 			"Account Source",
805 			"Mail account source being edited",
806 			E_TYPE_SOURCE,
807 			G_PARAM_READWRITE |
808 			G_PARAM_CONSTRUCT_ONLY |
809 			G_PARAM_STATIC_STRINGS));
810 
811 	g_object_class_install_property (
812 		object_class,
813 		PROP_IDENTITY_SOURCE,
814 		g_param_spec_object (
815 			"identity-source",
816 			"Identity Source",
817 			"Mail identity source being edited",
818 			E_TYPE_SOURCE,
819 			G_PARAM_READWRITE |
820 			G_PARAM_CONSTRUCT_ONLY |
821 			G_PARAM_STATIC_STRINGS));
822 
823 	g_object_class_install_property (
824 		object_class,
825 		PROP_SESSION,
826 		g_param_spec_object (
827 			"session",
828 			"Session",
829 			"Mail session",
830 			E_TYPE_MAIL_SESSION,
831 			G_PARAM_READWRITE |
832 			G_PARAM_CONSTRUCT_ONLY |
833 			G_PARAM_STATIC_STRINGS));
834 }
835 
836 static void
837 e_mail_config_defaults_page_interface_init (EMailConfigPageInterface *interface)
838 {
839 	interface->title = _("Defaults");
840 	interface->sort_order = E_MAIL_CONFIG_DEFAULTS_PAGE_SORT_ORDER;
841 }
842 
843 static void
844 e_mail_config_defaults_page_init (EMailConfigDefaultsPage *page)
845 {
846 	page->priv = E_MAIL_CONFIG_DEFAULTS_PAGE_GET_PRIVATE (page);
847 }
848 
849 EMailConfigPage *
850 e_mail_config_defaults_page_new (EMailSession *session,
851                                  ESource *account_source,
852                                  ESource *identity_source)
853 {
854 	g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
855 	g_return_val_if_fail (E_IS_SOURCE (account_source), NULL);
856 	g_return_val_if_fail (E_IS_SOURCE (identity_source), NULL);
857 
858 	return g_object_new (
859 		E_TYPE_MAIL_CONFIG_DEFAULTS_PAGE,
860 		"account-source", account_source,
861 		"identity-source", identity_source,
862 		"session", session, NULL);
863 }
864 
865 EMailSession *
866 e_mail_config_defaults_page_get_session (EMailConfigDefaultsPage *page)
867 {
868 	g_return_val_if_fail (E_IS_MAIL_CONFIG_DEFAULTS_PAGE (page), NULL);
869 
870 	return page->priv->session;
871 }
872 
873 ESource *
874 e_mail_config_defaults_page_get_account_source (EMailConfigDefaultsPage *page)
875 {
876 	g_return_val_if_fail (E_IS_MAIL_CONFIG_DEFAULTS_PAGE (page), NULL);
877 
878 	return page->priv->account_source;
879 }
880 
881 ESource *
882 e_mail_config_defaults_page_get_identity_source (EMailConfigDefaultsPage *page)
883 {
884 	g_return_val_if_fail (E_IS_MAIL_CONFIG_DEFAULTS_PAGE (page), NULL);
885 
886 	return page->priv->identity_source;
887 }