1 /*
2  * e-mail-signature-manager.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 "e-mail-signature-manager.h"
19 
20 #include <glib/gi18n.h>
21 #include <glib/gstdio.h>
22 #include <gdk/gdkkeysyms.h>
23 
24 #include <libedataserver/libedataserver.h>
25 
26 #include "e-dialog-widgets.h"
27 #include "e-misc-utils.h"
28 #include "e-mail-signature-preview.h"
29 #include "e-mail-signature-tree-view.h"
30 #include "e-mail-signature-script-dialog.h"
31 
32 #define E_MAIL_SIGNATURE_MANAGER_GET_PRIVATE(obj) \
33 	(G_TYPE_INSTANCE_GET_PRIVATE \
34 	((obj), E_TYPE_MAIL_SIGNATURE_MANAGER, EMailSignatureManagerPrivate))
35 
36 #define PREVIEW_HEIGHT 200
37 
38 struct _EMailSignatureManagerPrivate {
39 	ESourceRegistry *registry;
40 
41 	GtkWidget *tree_view;		/* not referenced */
42 	GtkWidget *add_button;		/* not referenced */
43 	GtkWidget *add_script_button;	/* not referenced */
44 	GtkWidget *edit_button;		/* not referenced */
45 	GtkWidget *remove_button;	/* not referenced */
46 	GtkWidget *preview;		/* not referenced */
47 	GtkWidget *preview_frame;	/* not referenced */
48 
49 	gboolean prefer_html;
50 };
51 
52 enum {
53 	PROP_0,
54 	PROP_PREFER_HTML,
55 	PROP_REGISTRY
56 };
57 
58 enum {
59 	ADD_SIGNATURE,
60 	ADD_SIGNATURE_SCRIPT,
61 	EDITOR_CREATED,
62 	EDIT_SIGNATURE,
63 	REMOVE_SIGNATURE,
64 	LAST_SIGNAL
65 };
66 
67 static guint signals[LAST_SIGNAL];
68 
G_DEFINE_TYPE(EMailSignatureManager,e_mail_signature_manager,GTK_TYPE_PANED)69 G_DEFINE_TYPE (
70 	EMailSignatureManager,
71 	e_mail_signature_manager,
72 	GTK_TYPE_PANED)
73 
74 static void
75 mail_signature_manager_emit_editor_created (EMailSignatureManager *manager,
76                                             GtkWidget *editor)
77 {
78 	g_return_if_fail (E_IS_MAIL_SIGNATURE_EDITOR (editor));
79 
80 	g_signal_emit (manager, signals[EDITOR_CREATED], 0, editor);
81 }
82 
83 static gboolean
mail_signature_manager_key_press_event_cb(EMailSignatureManager * manager,GdkEventKey * event)84 mail_signature_manager_key_press_event_cb (EMailSignatureManager *manager,
85                                            GdkEventKey *event)
86 {
87 	if (event->keyval == GDK_KEY_Delete) {
88 		e_mail_signature_manager_remove_signature (manager);
89 		return TRUE;
90 	}
91 
92 	return FALSE;
93 }
94 
95 static void
mail_signature_manager_run_script_dialog(EMailSignatureManager * manager,ESource * source,const gchar * title)96 mail_signature_manager_run_script_dialog (EMailSignatureManager *manager,
97                                           ESource *source,
98                                           const gchar *title)
99 {
100 	ESourceRegistry *registry;
101 	GtkWidget *dialog;
102 	gpointer parent;
103 
104 	registry = e_mail_signature_manager_get_registry (manager);
105 
106 	parent = gtk_widget_get_toplevel (GTK_WIDGET (manager));
107 	parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
108 
109 	dialog = e_mail_signature_script_dialog_new (registry, parent, source);
110 	gtk_window_set_title (GTK_WINDOW (dialog), title);
111 
112 	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
113 		EAsyncClosure *closure;
114 		GAsyncResult *result;
115 		GError *error = NULL;
116 
117 		closure = e_async_closure_new ();
118 
119 		/* FIXME Make this cancellable. */
120 		e_mail_signature_script_dialog_commit (
121 			E_MAIL_SIGNATURE_SCRIPT_DIALOG (dialog), NULL,
122 			e_async_closure_callback, closure);
123 
124 		result = e_async_closure_wait (closure);
125 
126 		e_mail_signature_script_dialog_commit_finish (
127 			E_MAIL_SIGNATURE_SCRIPT_DIALOG (dialog),
128 			result, &error);
129 
130 		e_async_closure_free (closure);
131 
132 		/* FIXME Make this into an EAlert. */
133 		if (error != NULL) {
134 			g_warning ("%s: %s", G_STRFUNC, error->message);
135 			g_error_free (error);
136 		}
137 	}
138 
139 	gtk_widget_destroy (dialog);
140 }
141 
142 static void
mail_signature_manager_selection_changed_cb(EMailSignatureManager * manager,GtkTreeSelection * selection)143 mail_signature_manager_selection_changed_cb (EMailSignatureManager *manager,
144                                              GtkTreeSelection *selection)
145 {
146 	EMailSignaturePreview *preview;
147 	EMailSignatureTreeView *tree_view;
148 	ESource *source;
149 	GtkWidget *edit_button;
150 	GtkWidget *remove_button;
151 	gboolean sensitive;
152 	const gchar *uid = NULL;
153 
154 	edit_button = manager->priv->edit_button;
155 	remove_button = manager->priv->remove_button;
156 
157 	tree_view = E_MAIL_SIGNATURE_TREE_VIEW (manager->priv->tree_view);
158 	source = e_mail_signature_tree_view_ref_selected_source (tree_view);
159 
160 	if (source != NULL)
161 		uid = e_source_get_uid (source);
162 
163 	preview = E_MAIL_SIGNATURE_PREVIEW (manager->priv->preview);
164 	e_mail_signature_preview_set_source_uid (preview, uid);
165 
166 	sensitive = (source != NULL);
167 	gtk_widget_set_sensitive (edit_button, sensitive);
168 	gtk_widget_set_sensitive (remove_button, sensitive);
169 
170 	if (source != NULL)
171 		g_object_unref (source);
172 }
173 
174 static void
mail_signature_manager_set_registry(EMailSignatureManager * manager,ESourceRegistry * registry)175 mail_signature_manager_set_registry (EMailSignatureManager *manager,
176                                      ESourceRegistry *registry)
177 {
178 	g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
179 	g_return_if_fail (manager->priv->registry == NULL);
180 
181 	manager->priv->registry = g_object_ref (registry);
182 }
183 
184 static void
mail_signature_manager_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)185 mail_signature_manager_set_property (GObject *object,
186                                 guint property_id,
187                                 const GValue *value,
188                                 GParamSpec *pspec)
189 {
190 	switch (property_id) {
191 		case PROP_PREFER_HTML:
192 			e_mail_signature_manager_set_prefer_html (
193 				E_MAIL_SIGNATURE_MANAGER (object),
194 				g_value_get_boolean (value));
195 			return;
196 
197 		case PROP_REGISTRY:
198 			mail_signature_manager_set_registry (
199 				E_MAIL_SIGNATURE_MANAGER (object),
200 				g_value_get_object (value));
201 			return;
202 	}
203 
204 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
205 }
206 
207 static void
mail_signature_manager_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)208 mail_signature_manager_get_property (GObject *object,
209                                 guint property_id,
210                                 GValue *value,
211                                 GParamSpec *pspec)
212 {
213 	switch (property_id) {
214 		case PROP_PREFER_HTML:
215 			g_value_set_boolean (
216 				value,
217 				e_mail_signature_manager_get_prefer_html (
218 				E_MAIL_SIGNATURE_MANAGER (object)));
219 			return;
220 
221 		case PROP_REGISTRY:
222 			g_value_set_object (
223 				value,
224 				e_mail_signature_manager_get_registry (
225 				E_MAIL_SIGNATURE_MANAGER (object)));
226 			return;
227 	}
228 
229 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
230 }
231 
232 static void
mail_signature_manager_dispose(GObject * object)233 mail_signature_manager_dispose (GObject *object)
234 {
235 	EMailSignatureManagerPrivate *priv;
236 
237 	priv = E_MAIL_SIGNATURE_MANAGER_GET_PRIVATE (object);
238 	g_clear_object (&priv->registry);
239 
240 	/* Chain up to parent's dispose() method. */
241 	G_OBJECT_CLASS (e_mail_signature_manager_parent_class)->
242 		dispose (object);
243 }
244 
245 static void
mail_signature_manager_constructed(GObject * object)246 mail_signature_manager_constructed (GObject *object)
247 {
248 	EMailSignatureManager *manager;
249 	GtkTreeSelection *selection;
250 	ESourceRegistry *registry;
251 	GSettings *settings;
252 	GtkWidget *container;
253 	GtkWidget *widget;
254 	GtkWidget *hbox;
255 
256 	/* Chain up to parent's constructed() method. */
257 	G_OBJECT_CLASS (e_mail_signature_manager_parent_class)->constructed (object);
258 
259 	manager = E_MAIL_SIGNATURE_MANAGER (object);
260 	registry = e_mail_signature_manager_get_registry (manager);
261 
262 	gtk_orientable_set_orientation (
263 		GTK_ORIENTABLE (manager), GTK_ORIENTATION_VERTICAL);
264 
265 	container = GTK_WIDGET (manager);
266 
267 	widget = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
268 	gtk_alignment_set_padding (GTK_ALIGNMENT (widget), 0, 12, 0, 0);
269 	gtk_paned_pack1 (GTK_PANED (container), widget, TRUE, FALSE);
270 	gtk_widget_show (widget);
271 
272 	container = widget;
273 
274 	widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
275 	gtk_container_add (GTK_CONTAINER (container), widget);
276 	gtk_widget_show (widget);
277 
278 	container = hbox = widget;
279 
280 	widget = gtk_scrolled_window_new (NULL, NULL);
281 	gtk_scrolled_window_set_policy (
282 		GTK_SCROLLED_WINDOW (widget),
283 		GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
284 	gtk_scrolled_window_set_shadow_type (
285 		GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
286 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
287 	gtk_widget_show (widget);
288 
289 	container = widget;
290 
291 	widget = e_mail_signature_tree_view_new (registry);
292 	gtk_container_add (GTK_CONTAINER (container), widget);
293 	manager->priv->tree_view = widget;  /* not referenced */
294 	gtk_widget_show (widget);
295 
296 	g_signal_connect_swapped (
297 		widget, "key-press-event",
298 		G_CALLBACK (mail_signature_manager_key_press_event_cb),
299 		manager);
300 
301 	g_signal_connect_swapped (
302 		widget, "row-activated",
303 		G_CALLBACK (e_mail_signature_manager_edit_signature),
304 		manager);
305 
306 	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
307 
308 	g_signal_connect_swapped (
309 		selection, "changed",
310 		G_CALLBACK (mail_signature_manager_selection_changed_cb),
311 		manager);
312 
313 	container = hbox;
314 
315 	widget = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
316 	gtk_button_box_set_layout (
317 		GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_START);
318 	gtk_box_set_spacing (GTK_BOX (widget), 6);
319 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, TRUE, 0);
320 	gtk_widget_show (widget);
321 
322 	container = widget;
323 
324 	widget = e_dialog_button_new_with_icon ("list-add", _("_Add"));
325 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
326 	manager->priv->add_button = widget;  /* not referenced */
327 	gtk_widget_show (widget);
328 
329 	g_signal_connect_swapped (
330 		widget, "clicked",
331 		G_CALLBACK (e_mail_signature_manager_add_signature),
332 		manager);
333 
334 	widget = e_dialog_button_new_with_icon ("system-run", _("Add _Script"));
335 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
336 	manager->priv->add_script_button = widget;  /* not referenced */
337 	gtk_widget_show (widget);
338 
339 	settings = e_util_ref_settings ("org.gnome.desktop.lockdown");
340 
341 	g_settings_bind (
342 		settings, "disable-command-line",
343 		widget, "visible",
344 		G_SETTINGS_BIND_GET |
345 		G_SETTINGS_BIND_INVERT_BOOLEAN);
346 
347 	g_object_unref (settings);
348 
349 	g_signal_connect_swapped (
350 		widget, "clicked",
351 		G_CALLBACK (e_mail_signature_manager_add_signature_script),
352 		manager);
353 
354 	widget = gtk_button_new_with_mnemonic (_("_Edit"));
355 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
356 	manager->priv->edit_button = widget;  /* not referenced */
357 	gtk_widget_show (widget);
358 
359 	g_signal_connect_swapped (
360 		widget, "clicked",
361 		G_CALLBACK (e_mail_signature_manager_edit_signature),
362 		manager);
363 
364 	widget = e_dialog_button_new_with_icon ("list-remove", _("_Remove"));
365 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
366 	manager->priv->remove_button = widget;  /* not referenced */
367 	gtk_widget_show (widget);
368 
369 	g_signal_connect_swapped (
370 		widget, "clicked",
371 		G_CALLBACK (e_mail_signature_manager_remove_signature),
372 		manager);
373 
374 	container = GTK_WIDGET (manager);
375 
376 	widget = gtk_frame_new (NULL);
377 	gtk_frame_set_shadow_type (GTK_FRAME (widget), GTK_SHADOW_IN);
378 	gtk_paned_pack2 (GTK_PANED (container), widget, FALSE, FALSE);
379 	manager->priv->preview_frame = widget;  /* not referenced */
380 	gtk_widget_show (widget);
381 
382 	container = widget;
383 
384 	widget = e_mail_signature_preview_new (registry);
385 	gtk_container_add (GTK_CONTAINER (container), widget);
386 	manager->priv->preview = widget;  /* not referenced */
387 	gtk_widget_show (widget);
388 
389 	gtk_paned_set_position (GTK_PANED (manager), PREVIEW_HEIGHT);
390 }
391 
392 static void
mail_signature_manager_editor_created_add_signature_cb(GObject * source_object,GAsyncResult * result,gpointer user_data)393 mail_signature_manager_editor_created_add_signature_cb (GObject *source_object,
394 							GAsyncResult *result,
395 							gpointer user_data)
396 {
397 	EMailSignatureManager *manager = user_data;
398 	EHTMLEditor *editor;
399 	EContentEditor *cnt_editor;
400 	GtkWidget *widget;
401 	GError *error = NULL;
402 
403 	g_return_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager));
404 
405 	widget = e_mail_signature_editor_new_finish (result, &error);
406 	if (error) {
407 		g_warning ("%s: Failed to create signature editor: %s", G_STRFUNC, error->message);
408 		g_clear_error (&error);
409 		g_clear_object (&manager);
410 		return;
411 	}
412 
413 	editor = e_mail_signature_editor_get_editor (E_MAIL_SIGNATURE_EDITOR (widget));
414 	cnt_editor = e_html_editor_get_content_editor (editor);
415 	e_content_editor_set_html_mode (cnt_editor, manager->priv->prefer_html);
416 
417 	mail_signature_manager_emit_editor_created (manager, widget);
418 
419 	gtk_widget_grab_focus (manager->priv->tree_view);
420 
421 	g_clear_object (&manager);
422 }
423 
424 static void
mail_signature_manager_add_signature(EMailSignatureManager * manager)425 mail_signature_manager_add_signature (EMailSignatureManager *manager)
426 {
427 	ESourceRegistry *registry;
428 
429 	registry = e_mail_signature_manager_get_registry (manager);
430 
431 	e_mail_signature_editor_new (registry, NULL,
432 		mail_signature_manager_editor_created_add_signature_cb, g_object_ref (manager));
433 }
434 
435 static void
mail_signature_manager_add_signature_script(EMailSignatureManager * manager)436 mail_signature_manager_add_signature_script (EMailSignatureManager *manager)
437 {
438 	const gchar *title;
439 
440 	title = _("Add Signature Script");
441 	mail_signature_manager_run_script_dialog (manager, NULL, title);
442 
443 	gtk_widget_grab_focus (manager->priv->tree_view);
444 }
445 
446 static void
mail_signature_manager_editor_created(EMailSignatureManager * manager,EMailSignatureEditor * editor)447 mail_signature_manager_editor_created (EMailSignatureManager *manager,
448                                        EMailSignatureEditor *editor)
449 {
450 	GtkWindowPosition position;
451 	gpointer parent;
452 
453 	position = GTK_WIN_POS_CENTER_ON_PARENT;
454 	parent = gtk_widget_get_toplevel (GTK_WIDGET (manager));
455 	parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
456 
457 	gtk_window_set_transient_for (GTK_WINDOW (editor), parent);
458 	gtk_window_set_position (GTK_WINDOW (editor), position);
459 	gtk_widget_set_size_request (GTK_WIDGET (editor), 450, 300);
460 	gtk_widget_show (GTK_WIDGET (editor));
461 }
462 
463 static void
mail_signature_manager_editor_created_edit_signature_cb(GObject * source_object,GAsyncResult * result,gpointer user_data)464 mail_signature_manager_editor_created_edit_signature_cb (GObject *source_object,
465 							 GAsyncResult *result,
466 							 gpointer user_data)
467 {
468 	EMailSignatureManager *manager = user_data;
469 	GtkWidget *widget;
470 	GError *error = NULL;
471 
472 	g_return_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager));
473 
474 	widget = e_mail_signature_editor_new_finish (result, &error);
475 	if (error) {
476 		g_warning ("%s: Failed to create signature editor: %s", G_STRFUNC, error->message);
477 		g_clear_error (&error);
478 		g_clear_object (&manager);
479 		return;
480 	}
481 
482 	mail_signature_manager_emit_editor_created (manager, widget);
483 
484 	g_clear_object (&manager);
485 }
486 
487 static void
mail_signature_manager_edit_signature(EMailSignatureManager * manager)488 mail_signature_manager_edit_signature (EMailSignatureManager *manager)
489 {
490 	EMailSignatureTreeView *tree_view;
491 	ESourceMailSignature *extension;
492 	ESourceRegistry *registry;
493 	ESource *source;
494 	GFileInfo *file_info;
495 	GFile *file;
496 	const gchar *attribute;
497 	const gchar *extension_name;
498 	const gchar *title;
499 	GError *error = NULL;
500 
501 	registry = e_mail_signature_manager_get_registry (manager);
502 	tree_view = E_MAIL_SIGNATURE_TREE_VIEW (manager->priv->tree_view);
503 	source = e_mail_signature_tree_view_ref_selected_source (tree_view);
504 	g_return_if_fail (source != NULL);
505 
506 	extension_name = E_SOURCE_EXTENSION_MAIL_SIGNATURE;
507 	extension = e_source_get_extension (source, extension_name);
508 	file = e_source_mail_signature_get_file (extension);
509 
510 	attribute = G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE;
511 
512 	/* XXX This blocks but it should just be a local file. */
513 	file_info = g_file_query_info (
514 		file, attribute, G_FILE_QUERY_INFO_NONE, NULL, &error);
515 
516 	/* FIXME Make this into an EAlert. */
517 	if (error != NULL) {
518 		g_warn_if_fail (file_info == NULL);
519 		g_warning ("%s: %s", G_STRFUNC, error->message);
520 		g_object_unref (source);
521 		g_error_free (error);
522 		return;
523 	}
524 
525 	if (g_file_info_get_attribute_boolean (file_info, attribute))
526 		goto script;
527 
528 	e_mail_signature_editor_new (registry, source,
529 		mail_signature_manager_editor_created_edit_signature_cb, g_object_ref (manager));
530 
531 	goto exit;
532 
533 script:
534 	title = _("Edit Signature Script");
535 	mail_signature_manager_run_script_dialog (manager, source, title);
536 
537 exit:
538 	gtk_widget_grab_focus (GTK_WIDGET (tree_view));
539 
540 	g_object_unref (file_info);
541 	g_object_unref (source);
542 }
543 
544 static void
mail_signature_manager_remove_signature(EMailSignatureManager * manager)545 mail_signature_manager_remove_signature (EMailSignatureManager *manager)
546 {
547 	EMailSignatureTreeView *tree_view;
548 	ESourceMailSignature *extension;
549 	ESource *source;
550 	GFile *file;
551 	const gchar *extension_name;
552 	GError *error = NULL;
553 
554 	tree_view = E_MAIL_SIGNATURE_TREE_VIEW (manager->priv->tree_view);
555 	source = e_mail_signature_tree_view_ref_selected_source (tree_view);
556 
557 	if (source == NULL)
558 		return;
559 
560 	extension_name = E_SOURCE_EXTENSION_MAIL_SIGNATURE;
561 	extension = e_source_get_extension (source, extension_name);
562 
563 	file = e_source_mail_signature_get_file (extension);
564 
565 	/* XXX This blocks but it should just be a local file. */
566 	if (!g_file_delete (file, NULL, &error)) {
567 		g_warning ("%s", error->message);
568 		g_clear_error (&error);
569 	}
570 
571 	/* Remove the mail signature data source asynchronously.
572 	 * XXX No callback function because there's not much we can do
573 	 *     if this fails.  We should probably implement EAlertSink. */
574 	e_source_remove (source, NULL, NULL, NULL);
575 
576 	gtk_widget_grab_focus (GTK_WIDGET (tree_view));
577 
578 	g_object_unref (source);
579 }
580 
581 static void
e_mail_signature_manager_class_init(EMailSignatureManagerClass * class)582 e_mail_signature_manager_class_init (EMailSignatureManagerClass *class)
583 {
584 	GObjectClass *object_class;
585 
586 	g_type_class_add_private (
587 		class, sizeof (EMailSignatureManagerPrivate));
588 
589 	object_class = G_OBJECT_CLASS (class);
590 	object_class->set_property = mail_signature_manager_set_property;
591 	object_class->get_property = mail_signature_manager_get_property;
592 	object_class->dispose = mail_signature_manager_dispose;
593 	object_class->constructed = mail_signature_manager_constructed;
594 
595 	class->add_signature = mail_signature_manager_add_signature;
596 	class->add_signature_script =
597 		mail_signature_manager_add_signature_script;
598 	class->editor_created = mail_signature_manager_editor_created;
599 	class->edit_signature = mail_signature_manager_edit_signature;
600 	class->remove_signature = mail_signature_manager_remove_signature;
601 
602 	g_object_class_install_property (
603 		object_class,
604 		PROP_PREFER_HTML,
605 		g_param_spec_boolean (
606 			"prefer-html",
607 			"Prefer HTML",
608 			NULL,
609 			TRUE,
610 			G_PARAM_READWRITE |
611 			G_PARAM_CONSTRUCT |
612 			G_PARAM_STATIC_STRINGS));
613 
614 	g_object_class_install_property (
615 		object_class,
616 		PROP_REGISTRY,
617 		g_param_spec_object (
618 			"registry",
619 			"Registry",
620 			NULL,
621 			E_TYPE_SOURCE_REGISTRY,
622 			G_PARAM_READWRITE |
623 			G_PARAM_CONSTRUCT |
624 			G_PARAM_STATIC_STRINGS));
625 
626 	signals[ADD_SIGNATURE] = g_signal_new (
627 		"add-signature",
628 		G_OBJECT_CLASS_TYPE (class),
629 		G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
630 		G_STRUCT_OFFSET (EMailSignatureManagerClass, add_signature),
631 		NULL, NULL,
632 		g_cclosure_marshal_VOID__VOID,
633 		G_TYPE_NONE, 0);
634 
635 	signals[ADD_SIGNATURE_SCRIPT] = g_signal_new (
636 		"add-signature-script",
637 		G_OBJECT_CLASS_TYPE (class),
638 		G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
639 		G_STRUCT_OFFSET (
640 			EMailSignatureManagerClass, add_signature_script),
641 		NULL, NULL,
642 		g_cclosure_marshal_VOID__VOID,
643 		G_TYPE_NONE, 0);
644 
645 	signals[EDITOR_CREATED] = g_signal_new (
646 		"editor-created",
647 		G_OBJECT_CLASS_TYPE (class),
648 		G_SIGNAL_RUN_LAST,
649 		G_STRUCT_OFFSET (EMailSignatureManagerClass, editor_created),
650 		NULL, NULL,
651 		g_cclosure_marshal_VOID__OBJECT,
652 		G_TYPE_NONE, 1,
653 		E_TYPE_MAIL_SIGNATURE_EDITOR);
654 
655 	signals[EDIT_SIGNATURE] = g_signal_new (
656 		"edit-signature",
657 		G_OBJECT_CLASS_TYPE (class),
658 		G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
659 		G_STRUCT_OFFSET (EMailSignatureManagerClass, edit_signature),
660 		NULL, NULL,
661 		g_cclosure_marshal_VOID__VOID,
662 		G_TYPE_NONE, 0);
663 
664 	signals[REMOVE_SIGNATURE] = g_signal_new (
665 		"remove-signature",
666 		G_OBJECT_CLASS_TYPE (class),
667 		G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
668 		G_STRUCT_OFFSET (EMailSignatureManagerClass, remove_signature),
669 		NULL, NULL,
670 		g_cclosure_marshal_VOID__VOID,
671 		G_TYPE_NONE, 0);
672 }
673 
674 static void
e_mail_signature_manager_init(EMailSignatureManager * manager)675 e_mail_signature_manager_init (EMailSignatureManager *manager)
676 {
677 	manager->priv = E_MAIL_SIGNATURE_MANAGER_GET_PRIVATE (manager);
678 }
679 
680 GtkWidget *
e_mail_signature_manager_new(ESourceRegistry * registry)681 e_mail_signature_manager_new (ESourceRegistry *registry)
682 {
683 	g_return_val_if_fail (E_IS_SOURCE_REGISTRY (registry), NULL);
684 
685 	return g_object_new (
686 		E_TYPE_MAIL_SIGNATURE_MANAGER,
687 		"registry", registry, NULL);
688 }
689 
690 void
e_mail_signature_manager_add_signature(EMailSignatureManager * manager)691 e_mail_signature_manager_add_signature (EMailSignatureManager *manager)
692 {
693 	g_return_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager));
694 
695 	g_signal_emit (manager, signals[ADD_SIGNATURE], 0);
696 }
697 
698 void
e_mail_signature_manager_add_signature_script(EMailSignatureManager * manager)699 e_mail_signature_manager_add_signature_script (EMailSignatureManager *manager)
700 {
701 	g_return_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager));
702 
703 	g_signal_emit (manager, signals[ADD_SIGNATURE_SCRIPT], 0);
704 }
705 
706 void
e_mail_signature_manager_edit_signature(EMailSignatureManager * manager)707 e_mail_signature_manager_edit_signature (EMailSignatureManager *manager)
708 {
709 	g_return_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager));
710 
711 	g_signal_emit (manager, signals[EDIT_SIGNATURE], 0);
712 }
713 
714 void
e_mail_signature_manager_remove_signature(EMailSignatureManager * manager)715 e_mail_signature_manager_remove_signature (EMailSignatureManager *manager)
716 {
717 	g_return_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager));
718 
719 	g_signal_emit (manager, signals[REMOVE_SIGNATURE], 0);
720 }
721 
722 gboolean
e_mail_signature_manager_get_prefer_html(EMailSignatureManager * manager)723 e_mail_signature_manager_get_prefer_html (EMailSignatureManager *manager)
724 {
725 	g_return_val_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager), FALSE);
726 
727 	return manager->priv->prefer_html;
728 }
729 
730 void
e_mail_signature_manager_set_prefer_html(EMailSignatureManager * manager,gboolean prefer_html)731 e_mail_signature_manager_set_prefer_html (EMailSignatureManager *manager,
732                                           gboolean prefer_html)
733 {
734 	g_return_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager));
735 
736 	if (manager->priv->prefer_html == prefer_html)
737 		return;
738 
739 	manager->priv->prefer_html = prefer_html;
740 
741 	g_object_notify (G_OBJECT (manager), "prefer-html");
742 }
743 
744 ESourceRegistry *
e_mail_signature_manager_get_registry(EMailSignatureManager * manager)745 e_mail_signature_manager_get_registry (EMailSignatureManager *manager)
746 {
747 	g_return_val_if_fail (E_IS_MAIL_SIGNATURE_MANAGER (manager), NULL);
748 
749 	return manager->priv->registry;
750 }
751