1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/*
* test-mail-signatures.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*/
#include <stdlib.h>
#include <libedataserver/libedataserver.h>
#include <e-util/e-util.h>
static GCancellable *cancellable = NULL;
static void
signature_loaded_cb (EMailSignatureComboBox *combo_box,
GAsyncResult *result,
EWebView *web_view)
{
gchar *contents = NULL;
gboolean is_html;
GError *error = NULL;
e_mail_signature_combo_box_load_selected_finish (
combo_box, result, &contents, NULL, &is_html, &error);
/* Ignore cancellations. */
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_warn_if_fail (contents == NULL);
g_object_unref (web_view);
g_error_free (error);
return;
} else if (error != NULL) {
g_warn_if_fail (contents == NULL);
e_alert_submit (
E_ALERT_SINK (web_view),
"widgets:no-load-signature",
error->message, NULL);
g_object_unref (web_view);
g_error_free (error);
return;
}
if (contents == NULL)
e_web_view_clear (web_view);
else if (is_html)
e_web_view_load_string (web_view, contents);
else {
gchar *string;
string = g_markup_printf_escaped ("<pre>%s</pre>", contents);
e_web_view_load_string (web_view, string);
g_free (string);
}
g_free (contents);
g_object_unref (web_view);
}
static void
signature_combo_changed_cb (EMailSignatureComboBox *combo_box,
EWebView *web_view)
{
if (cancellable != NULL) {
g_cancellable_cancel (cancellable);
g_object_unref (cancellable);
}
cancellable = g_cancellable_new ();
e_mail_signature_combo_box_load_selected (
combo_box, G_PRIORITY_DEFAULT, cancellable,
(GAsyncReadyCallback) signature_loaded_cb,
g_object_ref (web_view));
}
gint
main (gint argc,
gchar **argv)
{
ESourceRegistry *registry;
GtkWidget *container;
GtkWidget *widget;
GtkWidget *vbox;
GtkWidget *identity_combo;
GtkWidget *signature_combo;
GError *error = NULL;
gtk_init (&argc, &argv);
registry = e_source_registry_new_sync (NULL, &error);
if (error != NULL) {
g_printerr ("%s\n", error->message);
exit (EXIT_FAILURE);
}
/* Construct the widgets. */
widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (widget), "Mail Signatures");
gtk_window_set_default_size (GTK_WINDOW (widget), 400, 400);
gtk_container_set_border_width (GTK_CONTAINER (widget), 12);
gtk_widget_show (widget);
g_signal_connect (
widget, "delete-event",
G_CALLBACK (gtk_main_quit), NULL);
container = widget;
widget = gtk_vbox_new (FALSE, 12);
gtk_container_add (GTK_CONTAINER (container), widget);
gtk_widget_show (widget);
container = vbox = widget;
widget = gtk_label_new ("<b>EMailSignatureComboBox</b>");
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
widget = gtk_vbox_new (FALSE, 6);
gtk_widget_set_margin_left (widget, 12);
gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
gtk_widget_show (widget);
container = widget;
widget = e_mail_signature_combo_box_new (registry);
gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
signature_combo = widget;
gtk_widget_show (widget);
widget = e_mail_identity_combo_box_new (registry);
gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
identity_combo = widget;
gtk_widget_show (widget);
widget = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (
GTK_SCROLLED_WINDOW (widget),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (
GTK_SCROLLED_WINDOW (widget), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
gtk_widget_show (widget);
container = widget;
widget = e_web_view_new ();
gtk_container_add (GTK_CONTAINER (container), widget);
gtk_widget_show (widget);
g_signal_connect (
signature_combo, "changed",
G_CALLBACK (signature_combo_changed_cb), widget);
container = vbox;
widget = gtk_label_new ("<b>EMailSignatureManager</b>");
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
widget = e_mail_signature_manager_new (registry);
gtk_widget_set_margin_left (widget, 12);
gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
gtk_widget_show (widget);
g_object_bind_property (
identity_combo, "active-id",
signature_combo, "identity-uid",
G_BINDING_SYNC_CREATE);
gtk_main ();
return 0;
}
|