1 /*
2  * e-settings-mail-formatter.c
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #include "evolution-config.h"
19 
20 #include "e-settings-mail-formatter.h"
21 
22 #include <e-util/e-util.h>
23 #include <em-format/e-mail-formatter.h>
24 #include <mail/e-mail-reader-utils.h>
25 
G_DEFINE_DYNAMIC_TYPE(ESettingsMailFormatter,e_settings_mail_formatter,E_TYPE_EXTENSION)26 G_DEFINE_DYNAMIC_TYPE (
27 	ESettingsMailFormatter,
28 	e_settings_mail_formatter,
29 	E_TYPE_EXTENSION)
30 
31 static EMailFormatter *
32 settings_mail_formatter_get_extensible (ESettingsMailFormatter *extension)
33 {
34 	EExtensible *extensible;
35 
36 	extensible = e_extension_get_extensible (E_EXTENSION (extension));
37 
38 	return E_MAIL_FORMATTER (extensible);
39 }
40 
41 static gboolean
settings_mail_formatter_map_string_to_rgba(GValue * value,GVariant * variant,gpointer user_data)42 settings_mail_formatter_map_string_to_rgba (GValue *value,
43                                             GVariant *variant,
44                                             gpointer user_data)
45 {
46 	GdkRGBA rgba;
47 	const gchar *string;
48 	gboolean success = FALSE;
49 
50 	string = g_variant_get_string (variant, NULL);
51 	if (gdk_rgba_parse (&rgba, string)) {
52 		g_value_set_boxed (value, &rgba);
53 		success = TRUE;
54 	}
55 
56 	return success;
57 }
58 
59 static void
settings_mail_formatter_constructed(GObject * object)60 settings_mail_formatter_constructed (GObject *object)
61 {
62 	ESettingsMailFormatter *extension;
63 	EMailFormatter *formatter;
64 	GSettings *settings;
65 
66 	extension = E_SETTINGS_MAIL_FORMATTER (object);
67 	formatter = settings_mail_formatter_get_extensible (extension);
68 
69 	settings = e_util_ref_settings ("org.gnome.evolution.mail");
70 
71 	g_settings_bind_with_mapping (
72 		settings, "citation-color",
73 		formatter, "citation-color",
74 		G_SETTINGS_BIND_GET,
75 		settings_mail_formatter_map_string_to_rgba,
76 		(GSettingsBindSetMapping) NULL,
77 		NULL, (GDestroyNotify) NULL);
78 
79 	g_settings_bind (
80 		settings, "mark-citations",
81 		formatter, "mark-citations",
82 		G_SETTINGS_BIND_GET);
83 
84 	g_settings_bind (
85 		settings, "image-loading-policy",
86 		formatter, "image-loading-policy",
87 		G_SETTINGS_BIND_GET);
88 
89 	g_settings_bind (
90 		settings, "show-sender-photo",
91 		formatter, "show-sender-photo",
92 		G_SETTINGS_BIND_GET);
93 
94 	g_settings_bind (
95 		settings, "show-real-date",
96 		formatter, "show-real-date",
97 		G_SETTINGS_BIND_GET);
98 
99 	g_settings_bind (
100 		settings, "show-animated-images",
101 		formatter, "animate-images",
102 		G_SETTINGS_BIND_GET);
103 
104 	g_object_unref (settings);
105 
106 	/* Chain up to parent's constructed() method. */
107 	G_OBJECT_CLASS (e_settings_mail_formatter_parent_class)->constructed (object);
108 }
109 
110 static void
e_settings_mail_formatter_class_init(ESettingsMailFormatterClass * class)111 e_settings_mail_formatter_class_init (ESettingsMailFormatterClass *class)
112 {
113 	GObjectClass *object_class;
114 	EExtensionClass *extension_class;
115 
116 	object_class = G_OBJECT_CLASS (class);
117 	object_class->constructed = settings_mail_formatter_constructed;
118 
119 	extension_class = E_EXTENSION_CLASS (class);
120 	extension_class->extensible_type = E_TYPE_MAIL_FORMATTER;
121 }
122 
123 static void
e_settings_mail_formatter_class_finalize(ESettingsMailFormatterClass * class)124 e_settings_mail_formatter_class_finalize (ESettingsMailFormatterClass *class)
125 {
126 }
127 
128 static void
e_settings_mail_formatter_init(ESettingsMailFormatter * extension)129 e_settings_mail_formatter_init (ESettingsMailFormatter *extension)
130 {
131 }
132 
133 void
e_settings_mail_formatter_type_register(GTypeModule * type_module)134 e_settings_mail_formatter_type_register (GTypeModule *type_module)
135 {
136 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
137 	 *     function, so we have to wrap it with a public function in
138 	 *     order to register types from a separate compilation unit. */
139 	e_settings_mail_formatter_register_type (type_module);
140 }
141 
142