evolution-3.6.4/modules/mailto-handler/evolution-mailto-handler.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found evolution-mailto-handler.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found evolution-mailto-handler.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  * evolution-mailto-handler.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 <glib/gi18n-lib.h>
 24 #include <libebackend/libebackend.h>
 25 
 26 #include <shell/e-shell.h>
 27 
 28 /* Standard GObject macros */
 29 #define E_TYPE_MAILTO_HANDLER \
 30 	(e_mailto_handler_get_type ())
 31 #define E_MAILTO_HANDLER(obj) \
 32 	(G_TYPE_CHECK_INSTANCE_CAST \
 33 	((obj), E_TYPE_MAILTO_HANDLER, EMailtoHandler))
 34 
 35 #define MAILTO_COMMAND \
 36 	"evolution --component=mail"
 37 
 38 #define MAILTO_HANDLER "x-scheme-handler/mailto"
 39 
 40 typedef struct _EMailtoHandler EMailtoHandler;
 41 typedef struct _EMailtoHandlerClass EMailtoHandlerClass;
 42 
 43 struct _EMailtoHandler {
 44 	EExtension parent;
 45 };
 46 
 47 struct _EMailtoHandlerClass {
 48 	EExtensionClass parent_class;
 49 };
 50 
 51 /* Module Entry Points */
 52 void e_module_load (GTypeModule *type_module);
 53 void e_module_unload (GTypeModule *type_module);
 54 
 55 /* Forward Declarations */
 56 GType e_mailto_handler_get_type (void);
 57 
 58 G_DEFINE_DYNAMIC_TYPE (EMailtoHandler, e_mailto_handler, E_TYPE_EXTENSION)
 59 
 60 static EShell *
 61 mailto_handler_get_shell (EMailtoHandler *extension)
 62 {
 63 	EExtensible *extensible;
 64 
 65 	extensible = e_extension_get_extensible (E_EXTENSION (extension));
 66 
 67 	return E_SHELL (extensible);
 68 }
 69 
 70 static gboolean
 71 mailto_handler_is_evolution (/*const */ GAppInfo *app_info)
 72 {
 73 	gint argc;
 74 	gchar **argv;
 75 	gchar *basename;
 76 	gboolean is_evolution;
 77 	const gchar *mailto_command;
 78 
 79 	if (app_info == NULL)
 80 		return FALSE;
 81 
 82 	mailto_command = g_app_info_get_commandline (app_info);
 83 	if (mailto_command == NULL)
 84 		return FALSE;
 85 
 86 	/* Tokenize the mailto command. */
 87 	if (!g_shell_parse_argv (mailto_command, &argc, &argv, NULL))
 88 		return FALSE;
 89 
 90 	g_return_val_if_fail (argc > 0, FALSE);
 91 
 92 	/* Check the basename of the first token. */
 93 	basename = g_path_get_basename (argv[0]);
 94 	is_evolution = g_str_has_prefix (basename, "evolution");
 95 	g_free (basename);
 96 
 97 	g_strfreev (argv);
 98 
 99 	return is_evolution;
100 }
101 
102 static gboolean
103 mailto_handler_prompt (EMailtoHandler *extension)
104 {
105 	EShell *shell;
106 	EShellSettings *shell_settings;
107 	GtkWidget *container;
108 	GtkWidget *dialog;
109 	GtkWidget *widget;
110 	const gchar *text;
111 	gchar *markup;
112 	gint response;
113 
114 	shell = mailto_handler_get_shell (extension);
115 	shell_settings = e_shell_get_shell_settings (shell);
116 
117 	dialog = gtk_dialog_new_with_buttons (
118 		"", NULL, 0,
119 		GTK_STOCK_NO, GTK_RESPONSE_NO,
120 		GTK_STOCK_YES, GTK_RESPONSE_YES,
121 		NULL);
122 
123 	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
124 	gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
125 
126 	container = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
127 
128 	widget = gtk_hbox_new (FALSE, 12);
129 	gtk_container_set_border_width (GTK_CONTAINER (widget), 5);
130 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
131 	gtk_widget_show (widget);
132 
133 	container = widget;
134 
135 	widget = gtk_image_new_from_stock (
136 		GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
137 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
138 	gtk_widget_show (widget);
139 
140 	widget = gtk_vbox_new (FALSE, 12);
141 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
142 	gtk_widget_show (widget);
143 
144 	container = widget;
145 
146 	text = _("Do you want to make Evolution your default email client?");
147 	markup = g_markup_printf_escaped ("<b>%s</b>", text);
148 	widget = gtk_label_new (NULL);
149 	gtk_label_set_markup (GTK_LABEL (widget), markup);
150 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
151 	gtk_widget_show (widget);
152 	g_free (markup);
153 
154 	text = _("_Do not show this message again");
155 	widget = gtk_check_button_new_with_mnemonic (text);
156 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 12);
157 	gtk_widget_show (widget);
158 
159 	g_object_bind_property (
160 		shell_settings, "mailto-handler-check",
161 		widget, "active",
162 		G_BINDING_BIDIRECTIONAL |
163 		G_BINDING_SYNC_CREATE |
164 		G_BINDING_INVERT_BOOLEAN);
165 
166 	/* Direct input focus away from the checkbox. */
167 	widget = gtk_dialog_get_widget_for_response (
168 		GTK_DIALOG (dialog), GTK_RESPONSE_YES);
169 	gtk_widget_grab_focus (widget);
170 
171 	response = gtk_dialog_run (GTK_DIALOG (dialog));
172 
173 	gtk_widget_destroy (dialog);
174 
175 	return (response == GTK_RESPONSE_YES);
176 }
177 
178 static void
179 mailto_handler_check (EMailtoHandler *extension)
180 {
181 	EShell *shell;
182 	EShellSettings *shell_settings;
183 	gboolean check_mailto_handler = TRUE;
184 	GAppInfo *app_info = NULL;
185 	GError *error = NULL;
186 
187 	shell = mailto_handler_get_shell (extension);
188 	shell_settings = e_shell_get_shell_settings (shell);
189 
190 	g_object_get (
191 		shell_settings,
192 		"mailto-handler-check", &check_mailto_handler,
193 		NULL);
194 
195 	/* Should we check the "mailto" URI handler? */
196 	if (!check_mailto_handler)
197 		goto exit;
198 
199 	app_info = g_app_info_get_default_for_type (MAILTO_HANDLER, FALSE);
200 
201 	/* Is Evolution already handling "mailto" URIs? */
202 	if (mailto_handler_is_evolution (app_info))
203 		goto exit;
204 
205 	/* Does the user want Evolution to handle them? */
206 	if (!mailto_handler_prompt (extension))
207 		goto exit;
208 
209 	if (app_info)
210 		g_object_unref (app_info);
211 
212 	/* Configure Evolution to be the "mailto" URI handler. */
213 	app_info = g_app_info_create_from_commandline (
214 		MAILTO_COMMAND,
215 		_("Evolution"),
216 		G_APP_INFO_CREATE_SUPPORTS_URIS,
217 		&error);
218 
219 	if (app_info && !error)
220 		g_app_info_set_as_default_for_type (app_info, MAILTO_HANDLER, &error);
221 
222 exit:
223 	if (app_info)
224 		g_object_unref (app_info);
225 
226 	if (error) {
227 		g_warning ("Failed to register as default handler: %s", error->message);
228 		g_error_free (error);
229 	}
230 }
231 
232 static void
233 mailto_handler_constructed (GObject *object)
234 {
235 	EShell *shell;
236 	EMailtoHandler *extension;
237 
238 	extension = E_MAILTO_HANDLER (object);
239 
240 	shell = mailto_handler_get_shell (extension);
241 
242 	e_shell_settings_install_property_for_key (
243 		"mailto-handler-check",
244 		"org.gnome.evolution.mail",
245 		"prompt-check-if-default-mailer");
246 
247 	g_signal_connect_swapped (
248 		shell, "event::ready-to-start",
249 		G_CALLBACK (mailto_handler_check), extension);
250 
251 	/* Chain up to parent's constructed() method. */
252 	G_OBJECT_CLASS (e_mailto_handler_parent_class)->constructed (object);
253 }
254 
255 static void
256 e_mailto_handler_class_init (EMailtoHandlerClass *class)
257 {
258 	GObjectClass *object_class;
259 	EExtensionClass *extension_class;
260 
261 	object_class = G_OBJECT_CLASS (class);
262 	object_class->constructed = mailto_handler_constructed;
263 
264 	extension_class = E_EXTENSION_CLASS (class);
265 	extension_class->extensible_type = E_TYPE_SHELL;
266 }
267 
268 static void
269 e_mailto_handler_class_finalize (EMailtoHandlerClass *class)
270 {
271 }
272 
273 static void
274 e_mailto_handler_init (EMailtoHandler *extension)
275 {
276 }
277 
278 G_MODULE_EXPORT void
279 e_module_load (GTypeModule *type_module)
280 {
281 	e_mailto_handler_register_type (type_module);
282 }
283 
284 G_MODULE_EXPORT void
285 e_module_unload (GTypeModule *type_module)
286 {
287 }