evolution-3.6.4/modules/mail/e-mail-config-web-view-gtkhtml.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-config-web-view-gtkhtml.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-config-web-view-gtkhtml.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-web-view.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 #ifdef HAVE_CONFIG_H
 20 #include <config.h>
 21 #endif
 22 
 23 #include <stdio.h>
 24 #include <string.h>
 25 
 26 #include "e-mail-config-web-view-gtkhtml.h"
 27 
 28 #include <shell/e-shell.h>
 29 #include <misc/e-web-view-gtkhtml.h>
 30 
 31 #define E_MAIL_CONFIG_WEB_VIEW_GTKHTML_GET_PRIVATE(obj) \
 32 	(G_TYPE_INSTANCE_GET_PRIVATE \
 33 	((obj), E_TYPE_MAIL_CONFIG_WEB_VIEW_GTKHTML, EMailConfigWebViewGtkHTMLPrivate))
 34 
 35 struct _EMailConfigWebViewGtkHTMLPrivate {
 36 	GtkCssProvider *css_provider;
 37 	EShellSettings *shell_settings;
 38 };
 39 
 40 G_DEFINE_DYNAMIC_TYPE (
 41 	EMailConfigWebViewGtkHTML,
 42 	e_mail_config_web_view_gtkhtml,
 43 	E_TYPE_EXTENSION)
 44 
 45 /* replaces content of color string */
 46 static void
 47 mail_config_web_view_gtkhtml_fix_color_string (gchar *color_string)
 48 {
 49 	GdkColor color;
 50 
 51 	if (color_string == NULL)
 52 		return;
 53 
 54 	if (strlen (color_string) < 13)
 55 		return;
 56 
 57 	if (!gdk_color_parse (color_string, &color))
 58 		return;
 59 
 60 	sprintf (
 61 		color_string, "#%02x%02x%02x",
 62 		(gint) color.red * 256 / 65536,
 63 		(gint) color.green * 256 / 65536,
 64 		(gint) color.blue * 256 / 65536);
 65 }
 66 
 67 static void
 68 mail_config_web_view_gtkhtml_load_style (EMailConfigWebViewGtkHTML *extension)
 69 {
 70 	GString *buffer;
 71 	gchar *citation_color;
 72 	gchar *monospace_font;
 73 	gchar *spell_color;
 74 	gchar *variable_font;
 75 	gboolean custom_fonts;
 76 	gboolean mark_citations;
 77 	EExtensible *extensible;
 78 	EShellSettings *shell_settings;
 79 	GtkStyleContext *style_context;
 80 	GError *error = NULL;
 81 
 82 	/* Some of our mail and composer preferences are passed down to
 83 	 * GtkHtml through style properties, unfortunately.  This builds
 84 	 * a style sheet for the EWebView using values from GSettings. */
 85 
 86 	shell_settings = extension->priv->shell_settings;
 87 
 88 	custom_fonts = e_shell_settings_get_boolean (
 89 		shell_settings, "mail-use-custom-fonts");
 90 
 91 	monospace_font = e_shell_settings_get_string (
 92 		shell_settings, "mail-font-monospace");
 93 
 94 	variable_font = e_shell_settings_get_string (
 95 		shell_settings, "mail-font-variable");
 96 
 97 	mark_citations = e_shell_settings_get_boolean (
 98 		shell_settings, "mail-mark-citations");
 99 
100 	citation_color = e_shell_settings_get_string (
101 		shell_settings, "mail-citation-color");
102 
103 	spell_color = e_shell_settings_get_string (
104 		shell_settings, "composer-spell-color");
105 
106 	buffer = g_string_new ("EWebViewGtkHTML {\n");
107 
108 	mail_config_web_view_gtkhtml_fix_color_string (citation_color);
109 	mail_config_web_view_gtkhtml_fix_color_string (spell_color);
110 
111 	if (custom_fonts && variable_font != NULL)
112 		g_string_append_printf (
113 			buffer, "  font: %s;\n", variable_font);
114 
115 	if (custom_fonts && monospace_font != NULL)
116 		g_string_append_printf (
117 			buffer, "  -GtkHTML-fixed-font-name: '%s';\n",
118 			monospace_font);
119 
120 	if (mark_citations && citation_color != NULL)
121 		g_string_append_printf (
122 			buffer, "  -GtkHTML-cite-color: %s;\n",
123 			citation_color);
124 
125 	if (spell_color != NULL)
126 		g_string_append_printf (
127 			buffer, "  -GtkHTML-spell-error-color: %s;\n",
128 			spell_color);
129 
130 	g_string_append (buffer, "}\n");
131 
132 	gtk_css_provider_load_from_data (
133 		extension->priv->css_provider,
134 		buffer->str, buffer->len, &error);
135 
136 	if (error != NULL) {
137 		g_warning ("%s", error->message);
138 		g_error_free (error);
139 	}
140 
141 	g_string_free (buffer, TRUE);
142 
143 	g_free (monospace_font);
144 	g_free (variable_font);
145 	g_free (citation_color);
146 	g_free (spell_color);
147 
148 	extensible = e_extension_get_extensible (E_EXTENSION (extension));
149 	style_context = gtk_widget_get_style_context (GTK_WIDGET (extensible));
150 	gtk_style_context_invalidate (style_context);
151 }
152 
153 static void
154 mail_config_web_view_gtkhtml_realize (GtkWidget *widget,
155                                       EMailConfigWebViewGtkHTML *extension)
156 {
157 	EShellSettings *shell_settings;
158 
159 	shell_settings = extension->priv->shell_settings;
160 
161 	g_object_bind_property (
162 		shell_settings, "composer-inline-spelling",
163 		widget, "inline-spelling",
164 		G_BINDING_SYNC_CREATE);
165 
166 	g_object_bind_property (
167 		shell_settings, "composer-magic-links",
168 		widget, "magic-links",
169 		G_BINDING_SYNC_CREATE);
170 
171 	g_object_bind_property (
172 		shell_settings, "composer-magic-smileys",
173 		widget, "magic-smileys",
174 		G_BINDING_SYNC_CREATE);
175 
176 	gtk_style_context_add_provider (
177 		gtk_widget_get_style_context (widget),
178 		GTK_STYLE_PROVIDER (extension->priv->css_provider),
179 		GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
180 
181 	mail_config_web_view_gtkhtml_load_style (extension);
182 
183 	/* Reload the style sheet when certain settings change. */
184 
185 	g_signal_connect_swapped (
186 		shell_settings, "notify::mail-use-custom-fonts",
187 		G_CALLBACK (mail_config_web_view_gtkhtml_load_style),
188 		extension);
189 
190 	g_signal_connect_swapped (
191 		shell_settings, "notify::mail-font-monospace",
192 		G_CALLBACK (mail_config_web_view_gtkhtml_load_style),
193 		extension);
194 
195 	g_signal_connect_swapped (
196 		shell_settings, "notify::mail-font-variable",
197 		G_CALLBACK (mail_config_web_view_gtkhtml_load_style),
198 		extension);
199 
200 	g_signal_connect_swapped (
201 		shell_settings, "notify::mail-mark-citations",
202 		G_CALLBACK (mail_config_web_view_gtkhtml_load_style),
203 		extension);
204 
205 	g_signal_connect_swapped (
206 		shell_settings, "notify::mail-citation-color",
207 		G_CALLBACK (mail_config_web_view_gtkhtml_load_style),
208 		extension);
209 
210 	g_signal_connect_swapped (
211 		shell_settings, "notify::composer-spell-color",
212 		G_CALLBACK (mail_config_web_view_gtkhtml_load_style),
213 		extension);
214 }
215 
216 static void
217 mail_config_web_view_gtkhtml_dispose (GObject *object)
218 {
219 	EMailConfigWebViewGtkHTMLPrivate *priv;
220 
221 	priv = E_MAIL_CONFIG_WEB_VIEW_GTKHTML_GET_PRIVATE (object);
222 
223 	if (priv->css_provider != NULL) {
224 		g_object_unref (priv->css_provider);
225 		priv->css_provider = NULL;
226 	}
227 
228 	if (priv->shell_settings != NULL) {
229 		g_signal_handlers_disconnect_by_func (
230 			priv->shell_settings,
231 			mail_config_web_view_gtkhtml_load_style, object);
232 		g_object_unref (priv->shell_settings);
233 		priv->shell_settings = NULL;
234 	}
235 
236 	/* Chain up to parent's dispose() method. */
237 	G_OBJECT_CLASS (e_mail_config_web_view_gtkhtml_parent_class)->
238 		dispose (object);
239 }
240 
241 static void
242 mail_config_web_view_gtkhtml_constructed (GObject *object)
243 {
244 	EShell *shell;
245 	EShellSettings *shell_settings;
246 	EMailConfigWebViewGtkHTML *extension;
247 	EExtensible *extensible;
248 
249 	shell = e_shell_get_default ();
250 	shell_settings = e_shell_get_shell_settings (shell);
251 
252 	extension = (EMailConfigWebViewGtkHTML *) object;
253 	extensible = e_extension_get_extensible (E_EXTENSION (extension));
254 
255 	extension->priv->css_provider = gtk_css_provider_new ();
256 	extension->priv->shell_settings = g_object_ref (shell_settings);
257 
258 	/* Wait to bind shell settings until the EWebView is realized
259 	 * so GtkhtmlEditor has a chance to install a GtkHTMLEditorAPI.
260 	 * Otherwise our settings will have no effect. */
261 
262 	g_signal_connect (
263 		extensible, "realize",
264 		G_CALLBACK (mail_config_web_view_gtkhtml_realize), extension);
265 
266 	/* Chain up to parent's constructed() method. */
267 	G_OBJECT_CLASS (e_mail_config_web_view_gtkhtml_parent_class)->
268 		constructed (object);
269 }
270 
271 static void
272 e_mail_config_web_view_gtkhtml_class_init (EMailConfigWebViewGtkHTMLClass *class)
273 {
274 	GObjectClass *object_class;
275 	EExtensionClass *extension_class;
276 
277 	g_type_class_add_private (
278 		class, sizeof (EMailConfigWebViewGtkHTMLPrivate));
279 
280 	object_class = G_OBJECT_CLASS (class);
281 	object_class->dispose = mail_config_web_view_gtkhtml_dispose;
282 	object_class->constructed = mail_config_web_view_gtkhtml_constructed;
283 
284 	extension_class = E_EXTENSION_CLASS (class);
285 	extension_class->extensible_type = E_TYPE_WEB_VIEW_GTKHTML;
286 }
287 
288 static void
289 e_mail_config_web_view_gtkhtml_class_finalize (EMailConfigWebViewGtkHTMLClass *class)
290 {
291 }
292 
293 static void
294 e_mail_config_web_view_gtkhtml_init (EMailConfigWebViewGtkHTML *extension)
295 {
296 	extension->priv =
297 		E_MAIL_CONFIG_WEB_VIEW_GTKHTML_GET_PRIVATE (extension);
298 }
299 
300 void
301 e_mail_config_web_view_gtkhtml_type_register (GTypeModule *type_module)
302 {
303 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
304 	 *     function, so we have to wrap it with a public function in
305 	 *     order to register types from a separate compilation unit. */
306 	e_mail_config_web_view_gtkhtml_register_type (type_module);
307 }