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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
/*
* e-mail-config-imap-headers-page.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 "e-mail-config-imap-headers-page.h"
#include <config.h>
#include <glib/gi18n-lib.h>
#include <libedataserver/e-source-camel.h>
#include <libedataserver/e-source-mail-account.h>
#include <mail/e-mail-config-security-page.h>
#include "e-mail-config-header-manager.h"
#define E_MAIL_CONFIG_IMAP_HEADERS_PAGE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE, EMailConfigImapHeadersPagePrivate))
#define E_MAIL_CONFIG_IMAP_HEADERS_PAGE_SORT_ORDER \
(E_MAIL_CONFIG_SECURITY_PAGE_SORT_ORDER + 10)
struct _EMailConfigImapHeadersPagePrivate {
ESource *account_source;
CamelSettings *settings;
GtkToggleButton *fetch_all_headers; /* not referenced */
GtkToggleButton *fetch_bas_headers; /* not referenced */
GtkToggleButton *fetch_bml_headers; /* not referenced */
};
enum {
PROP_0,
PROP_ACCOUNT_SOURCE
};
/* Forward Declarations */
static void e_mail_config_imap_headers_page_interface_init
(EMailConfigPageInterface *interface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (
EMailConfigImapHeadersPage,
e_mail_config_imap_headers_page,
GTK_TYPE_BOX,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (
E_TYPE_MAIL_CONFIG_PAGE,
e_mail_config_imap_headers_page_interface_init))
static void
mail_config_imap_headers_page_all_toggled (GtkToggleButton *toggle_button,
EMailConfigImapHeadersPage *page)
{
if (gtk_toggle_button_get_active (toggle_button)) {
CamelSettings *settings;
CamelFetchHeadersType fetch_headers;
settings = page->priv->settings;
fetch_headers = CAMEL_FETCH_HEADERS_ALL;
g_object_set (settings, "fetch-headers", fetch_headers, NULL);
}
}
static void
mail_config_imap_headers_page_bas_toggled (GtkToggleButton *toggle_button,
EMailConfigImapHeadersPage *page)
{
if (gtk_toggle_button_get_active (toggle_button)) {
CamelSettings *settings;
CamelFetchHeadersType fetch_headers;
settings = page->priv->settings;
fetch_headers = CAMEL_FETCH_HEADERS_BASIC;
g_object_set (settings, "fetch-headers", fetch_headers, NULL);
}
}
static void
mail_config_imap_headers_page_bml_toggled (GtkToggleButton *toggle_button,
EMailConfigImapHeadersPage *page)
{
if (gtk_toggle_button_get_active (toggle_button)) {
CamelSettings *settings;
CamelFetchHeadersType fetch_headers;
settings = page->priv->settings;
fetch_headers = CAMEL_FETCH_HEADERS_BASIC_AND_MAILING_LIST;
g_object_set (settings, "fetch-headers", fetch_headers, NULL);
}
}
static void
mail_config_imap_headers_page_set_account_source (EMailConfigImapHeadersPage *page,
ESource *account_source)
{
g_return_if_fail (E_IS_SOURCE (account_source));
g_return_if_fail (page->priv->account_source == NULL);
page->priv->account_source = g_object_ref (account_source);
}
static void
mail_config_imap_headers_page_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_ACCOUNT_SOURCE:
mail_config_imap_headers_page_set_account_source (
E_MAIL_CONFIG_IMAP_HEADERS_PAGE (object),
g_value_get_object (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
mail_config_imap_headers_page_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_ACCOUNT_SOURCE:
g_value_set_object (
value,
e_mail_config_imap_headers_page_get_account_source (
E_MAIL_CONFIG_IMAP_HEADERS_PAGE (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
mail_config_imap_headers_page_dispose (GObject *object)
{
EMailConfigImapHeadersPagePrivate *priv;
priv = E_MAIL_CONFIG_IMAP_HEADERS_PAGE_GET_PRIVATE (object);
if (priv->account_source != NULL) {
g_object_unref (priv->account_source);
priv->account_source = NULL;
}
if (priv->settings != NULL) {
g_object_unref (priv->settings);
priv->settings = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_mail_config_imap_headers_page_parent_class)->
dispose (object);
}
static void
mail_config_imap_headers_page_constructed (GObject *object)
{
EMailConfigImapHeadersPage *page;
ESource *source;
ESourceCamel *camel_ext;
ESourceBackend *backend_ext;
CamelSettings *settings;
CamelFetchHeadersType fetch_headers;
GtkWidget *widget;
GtkWidget *container;
GtkToggleButton *toggle_button;
GSList *group = NULL;
const gchar *backend_name;
const gchar *extension_name;
const gchar *text;
gchar *markup;
page = E_MAIL_CONFIG_IMAP_HEADERS_PAGE (object);
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_mail_config_imap_headers_page_parent_class)->
constructed (object);
source = e_mail_config_imap_headers_page_get_account_source (page);
extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
backend_ext = e_source_get_extension (source, extension_name);
backend_name = e_source_backend_get_backend_name (backend_ext);
extension_name = e_source_camel_get_extension_name (backend_name);
camel_ext = e_source_get_extension (source, extension_name);
settings = e_source_camel_get_settings (camel_ext);
page->priv->settings = g_object_ref (settings);
gtk_orientable_set_orientation (
GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);
gtk_box_set_spacing (GTK_BOX (page), 12);
/*** IMAP Headers ***/
/* Use row-spacing=0 so we can pack the "Basic Headers" hint
* label closer to its radio button. Unfortunately this means
* we have to remember to set a top margin on all the children. */
widget = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (widget), 0);
gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
gtk_widget_show (widget);
container = widget;
text = _("IMAP Headers");
markup = g_markup_printf_escaped ("<b>%s</b>", text);
widget = gtk_label_new (markup);
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
gtk_widget_show (widget);
text = _("Select a predefined set of IMAP headers to fetch.\n"
"Note, larger sets of headers take longer to download.");
widget = gtk_label_new (text);
gtk_widget_set_margin_top (widget, 6);
gtk_widget_set_margin_left (widget, 12);
gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
gtk_widget_show (widget);
text = _("_Fetch All Headers");
widget = gtk_radio_button_new_with_mnemonic (group, text);
gtk_widget_set_margin_top (widget, 6);
gtk_widget_set_margin_left (widget, 12);
gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
page->priv->fetch_all_headers = GTK_TOGGLE_BUTTON (widget);
gtk_widget_show (widget);
g_signal_connect (
widget, "toggled",
G_CALLBACK (mail_config_imap_headers_page_all_toggled), page);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
text = _("_Basic Headers (fastest)");
widget = gtk_radio_button_new_with_mnemonic (group, text);
gtk_widget_set_margin_top (widget, 6);
gtk_widget_set_margin_left (widget, 12);
gtk_grid_attach (GTK_GRID (container), widget, 0, 3, 1, 1);
page->priv->fetch_bas_headers = GTK_TOGGLE_BUTTON (widget);
gtk_widget_show (widget);
g_signal_connect (
widget, "toggled",
G_CALLBACK (mail_config_imap_headers_page_bas_toggled), page);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget));
text = _("Use this if you are not filtering any mailing lists.");
markup = g_markup_printf_escaped ("<small>%s</small>", text);
widget = gtk_label_new (markup);
gtk_widget_set_margin_left (widget, 36);
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_grid_attach (GTK_GRID (container), widget, 0, 4, 1, 1);
gtk_widget_show (widget);
g_free (markup);
text = _("Basic and _Mailing List Headers (default)");
widget = gtk_radio_button_new_with_mnemonic (group, text);
gtk_widget_set_margin_top (widget, 6);
gtk_widget_set_margin_left (widget, 12);
gtk_grid_attach (GTK_GRID (container), widget, 0, 5, 1, 1);
page->priv->fetch_bml_headers = GTK_TOGGLE_BUTTON (widget);
gtk_widget_show (widget);
g_signal_connect (
widget, "toggled",
G_CALLBACK (mail_config_imap_headers_page_bml_toggled), page);
/* Pick an initial radio button. */
g_object_get (settings, "fetch-headers", &fetch_headers, NULL);
switch (fetch_headers) {
case CAMEL_FETCH_HEADERS_ALL:
toggle_button = page->priv->fetch_all_headers;
break;
case CAMEL_FETCH_HEADERS_BASIC:
toggle_button = page->priv->fetch_bas_headers;
break;
case CAMEL_FETCH_HEADERS_BASIC_AND_MAILING_LIST:
default:
toggle_button = page->priv->fetch_bml_headers;
break;
}
gtk_toggle_button_set_active (toggle_button, TRUE);
/*** Custom Headers ***/
widget = gtk_grid_new ();
gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
gtk_box_pack_start (GTK_BOX (page), widget, TRUE, TRUE, 0);
gtk_widget_show (widget);
g_object_bind_property (
page->priv->fetch_all_headers, "active",
widget, "sensitive",
G_BINDING_SYNC_CREATE |
G_BINDING_INVERT_BOOLEAN);
container = widget;
text = _("Custom Headers");
markup = g_markup_printf_escaped ("<b>%s</b>", text);
widget = gtk_label_new (markup);
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
gtk_widget_show (widget);
text = _("Specify any extra headers to fetch in addition "
"to the predefined set of headers selected above.");
widget = gtk_label_new (text);
gtk_widget_set_margin_left (widget, 12);
gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
gtk_widget_show (widget);
widget = e_mail_config_header_manager_new ();
gtk_widget_set_hexpand (widget, TRUE);
gtk_widget_set_vexpand (widget, TRUE);
gtk_widget_set_margin_left (widget, 12);
gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
gtk_widget_show (widget);
g_object_bind_property (
settings, "fetch-headers-extra",
widget, "headers",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
}
static void
e_mail_config_imap_headers_page_class_init (EMailConfigImapHeadersPageClass *class)
{
GObjectClass *object_class;
g_type_class_add_private (
class, sizeof (EMailConfigImapHeadersPagePrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = mail_config_imap_headers_page_set_property;
object_class->get_property = mail_config_imap_headers_page_get_property;
object_class->dispose = mail_config_imap_headers_page_dispose;
object_class->constructed = mail_config_imap_headers_page_constructed;
g_object_class_install_property (
object_class,
PROP_ACCOUNT_SOURCE,
g_param_spec_object (
"account-source",
"Account Source",
"Mail account source being edited",
E_TYPE_SOURCE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
e_mail_config_imap_headers_page_class_finalize (EMailConfigImapHeadersPageClass *class)
{
}
static void
e_mail_config_imap_headers_page_interface_init (EMailConfigPageInterface *interface)
{
interface->title = _("IMAP Headers");
interface->sort_order = E_MAIL_CONFIG_IMAP_HEADERS_PAGE_SORT_ORDER;
}
static void
e_mail_config_imap_headers_page_init (EMailConfigImapHeadersPage *page)
{
page->priv = E_MAIL_CONFIG_IMAP_HEADERS_PAGE_GET_PRIVATE (page);
}
void
e_mail_config_imap_headers_page_type_register (GTypeModule *type_module)
{
/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
* function, so we have to wrap it with a public function in
* order to register types from a separate compilation unit. */
e_mail_config_imap_headers_page_register_type (type_module);
}
EMailConfigPage *
e_mail_config_imap_headers_page_new (ESource *account_source)
{
g_return_val_if_fail (E_IS_SOURCE (account_source), NULL);
return g_object_new (
E_TYPE_MAIL_CONFIG_IMAP_HEADERS_PAGE,
"account-source", account_source, NULL);
}
ESource *
e_mail_config_imap_headers_page_get_account_source (EMailConfigImapHeadersPage *page)
{
g_return_val_if_fail (E_IS_MAIL_CONFIG_IMAP_HEADERS_PAGE (page), NULL);
return page->priv->account_source;
}
|