~ubuntu-branches/ubuntu/precise/evolution/precise

« back to all changes in this revision

Viewing changes to .pc/evo_fbee43e_to_f4505a2.patch/mail/em-account-editor.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-08-18 11:10:01 UTC
  • mfrom: (1.1.83 upstream)
  • Revision ID: james.westby@ubuntu.com-20110818111001-559uzyuqsoyj7xjg
Tags: 3.1.5-0ubuntu1
* New upstream release.
* debian/control: bump e-d-s Build-Depends to 3.1.5.
* debian/patches/03_lpi.patch: refreshed.
* debian/patches/11_remove_upstream_submit_bugreport.patch: refreshed.
* debian/patches/bogofilter_init_903b8e6.patch,
  debian/patches/evo_fbee43e_to_f4505a2.patch,
  debian/patches/spamassassin_init_4fc04af.patch: dropped, included upstream.
* debian/patches/spamd_sbin_path.patch: correct the path to spamd as
  /usr/sbin/spamd, which is the correct path in Ubuntu. (LP: #828693)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This program is free software; you can redistribute it and/or
3
 
 * modify it under the terms of the GNU Lesser General Public
4
 
 * License as published by the Free Software Foundation; either
5
 
 * version 2 of the License, or (at your option) version 3.
6
 
 *
7
 
 * This program is distributed in the hope that it will be useful,
8
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10
 
 * Lesser General Public License for more details.
11
 
 *
12
 
 * You should have received a copy of the GNU Lesser General Public
13
 
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
14
 
 *
15
 
 *
16
 
 * Authors:
17
 
 *              Dan Winship <danw@ximian.com>
18
 
 *              Jeffrey Stedfast <fejj@ximian.com>
19
 
 *              Michael Zucchi <notzed@ximian.com>
20
 
 *
21
 
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22
 
 *
23
 
 */
24
 
 
25
 
/*
26
 
  work before merge can occur:
27
 
 
28
 
  verify behaviour.
29
 
  work out what to do with the startup assistant.
30
 
 
31
 
  also need to work out:
32
 
  how to remove unecessary items from a service url once
33
 
   configured (removing settings from other types).
34
 
 
35
 
*/
36
 
 
37
 
#ifdef HAVE_CONFIG_H
38
 
#include <config.h>
39
 
#endif
40
 
 
41
 
#include <glib/gi18n.h>
42
 
#include <glib/gstdio.h>
43
 
 
44
 
#include <string.h>
45
 
#include <stdarg.h>
46
 
 
47
 
#include <gconf/gconf-client.h>
48
 
#include <libedataserverui/e-passwords.h>
49
 
 
50
 
#include "shell/e-shell.h"
51
 
#include "e-util/e-util.h"
52
 
#include "e-util/e-alert-dialog.h"
53
 
#include "e-util/e-account-utils.h"
54
 
#include "e-util/e-dialog-utils.h"
55
 
#include "e-util/e-signature-list.h"
56
 
#include "e-util/e-signature-utils.h"
57
 
#include "e-util/e-util-private.h"
58
 
#include "widgets/misc/e-signature-editor.h"
59
 
#include "widgets/misc/e-port-entry.h"
60
 
 
61
 
#include "e-mail-backend.h"
62
 
#include "e-mail-folder-utils.h"
63
 
#include "e-mail-local.h"
64
 
#include "e-mail-store.h"
65
 
#include "em-config.h"
66
 
#include "em-folder-selection-button.h"
67
 
#include "em-account-editor.h"
68
 
#include "mail-send-recv.h"
69
 
#include "em-utils.h"
70
 
#include "mail-ops.h"
71
 
#include "mail-mt.h"
72
 
 
73
 
#if defined (HAVE_NSS) && defined (ENABLE_SMIME)
74
 
#include "smime/gui/e-cert-selector.h"
75
 
#endif
76
 
 
77
 
#define d(x)
78
 
 
79
 
static ServerData mail_servers[] = {
80
 
        {"gmail", "imap.gmail.com", "smtp.gmail.com", "imap", "always"},
81
 
        {"googlemail", "imap.gmail.com", "smtp.gmail.com", "imap", "always"},
82
 
        {"yahoo", "pop3.yahoo.com", "smtp.yahoo.com", "pop", "never"},
83
 
        {"aol", "imap.aol.com", "smtp.aol.com", "imap", "never"},
84
 
        {"msn", "pop3.email.msn.com", "smtp.email.msn.com", "pop", "never", "@", "@"},
85
 
        {"hotmail", "pop3.live.com", "smtp.live.com", "pop", "always", "@", "@"},
86
 
        {"live.com", "pop3.live.com", "smtp.live.com", "pop", "always", "@", "@"},
87
 
 
88
 
};
89
 
 
90
 
/* econfig item for the extra config hings */
91
 
struct _receive_options_item {
92
 
        EMConfigItem item;
93
 
 
94
 
        /* Only CAMEL_PROVIDER_CONF_ENTRYs GtkEntrys are stored here.
95
 
           The auto-detect camel provider code will probably be removed */
96
 
        GHashTable *extra_table;
97
 
};
98
 
 
99
 
typedef struct _EMAccountEditorService {
100
 
        EMAccountEditor *emae;  /* parent pointer, for callbacks */
101
 
 
102
 
        /* NOTE: keep all widgets together, first frame last check_dialog */
103
 
        GtkWidget *frame;
104
 
        GtkWidget *container;
105
 
 
106
 
        GtkComboBox *providers;
107
 
 
108
 
        GtkLabel *description;
109
 
        GtkLabel *hostlabel;
110
 
        GtkEntry *hostname;
111
 
        GtkLabel *portlabel;
112
 
        EPortEntry *port;
113
 
        GtkLabel *userlabel;
114
 
        GtkEntry *username;
115
 
        GtkEntry *path;
116
 
        GtkLabel *pathlabel;
117
 
        GtkWidget *pathentry;
118
 
 
119
 
        GtkWidget *ssl_frame;
120
 
        GtkComboBox *use_ssl;
121
 
        GtkWidget *ssl_hbox;
122
 
        GtkWidget *no_ssl;
123
 
 
124
 
        GtkWidget *auth_frame;
125
 
        GtkComboBox *authtype;
126
 
 
127
 
        GtkWidget *authitem;
128
 
        GtkToggleButton *remember;
129
 
        GtkButton *check_supported;
130
 
        GtkToggleButton *needs_auth;
131
 
 
132
 
        GCancellable *checking;
133
 
        GtkWidget *check_dialog;
134
 
 
135
 
        GList *auth_types;      /* if "Check supported" */
136
 
        CamelProvider *provider;
137
 
        CamelProviderType type;
138
 
 
139
 
        gint auth_changed_id;
140
 
} EMAccountEditorService;
141
 
 
142
 
struct _EMAccountEditorPrivate {
143
 
 
144
 
        EMailBackend *backend;
145
 
        EAccount *modified_account;
146
 
        EAccount *original_account;
147
 
        gboolean new_account;
148
 
 
149
 
        struct _EMConfig *config;
150
 
        GList *providers;
151
 
 
152
 
        /* signatures */
153
 
        GtkComboBox *signatures_dropdown;
154
 
        guint sig_added_id;
155
 
        guint sig_removed_id;
156
 
        guint sig_changed_id;
157
 
        const gchar *sig_uid;
158
 
 
159
 
        /* incoming mail */
160
 
        EMAccountEditorService source;
161
 
 
162
 
        /* extra incoming config */
163
 
        CamelProvider *extra_provider;
164
 
        GSList *extra_items;    /* this is freed by the econfig automatically */
165
 
 
166
 
        /* outgoing mail */
167
 
        EMAccountEditorService transport;
168
 
 
169
 
        /* account management */
170
 
        GtkEntry *identity_entries[5];
171
 
        GtkToggleButton *default_account;
172
 
        GtkWidget *management_frame;
173
 
 
174
 
        /* special folders */
175
 
        GtkButton *drafts_folder_button;
176
 
        GtkButton *sent_folder_button;
177
 
        GtkToggleButton *trash_folder_check;
178
 
        GtkButton *trash_folder_button;
179
 
        GtkToggleButton *junk_folder_check;
180
 
        GtkButton *junk_folder_button;
181
 
        GtkButton *restore_folders_button;
182
 
 
183
 
        /* Security */
184
 
        GtkEntry *pgp_key;
185
 
        GtkToggleButton *pgp_encrypt_to_self;
186
 
        GtkToggleButton *pgp_always_sign;
187
 
        GtkToggleButton *pgp_no_imip_sign;
188
 
        GtkToggleButton *pgp_always_trust;
189
 
 
190
 
        GtkToggleButton *smime_sign_default;
191
 
        GtkEntry *smime_sign_key;
192
 
        GtkButton *smime_sign_key_select;
193
 
        GtkButton *smime_sign_key_clear;
194
 
        GtkButton *smime_sign_select;
195
 
        GtkToggleButton *smime_encrypt_default;
196
 
        GtkToggleButton *smime_encrypt_to_self;
197
 
        GtkEntry *smime_encrypt_key;
198
 
        GtkButton *smime_encrypt_key_select;
199
 
        GtkButton *smime_encrypt_key_clear;
200
 
 
201
 
        /* for e-config callbacks, each page sets up its widgets, then they are dealed out by the get_widget callback in order*/
202
 
        GHashTable *widgets;
203
 
 
204
 
        /* for assistant page preparation */
205
 
        guint identity_set:1;
206
 
        guint receive_set:1;
207
 
        guint send_set:1;
208
 
        guint management_set:1;
209
 
 
210
 
        ServerData *selected_server;
211
 
};
212
 
 
213
 
enum {
214
 
        PROP_0,
215
 
        PROP_BACKEND,
216
 
        PROP_MODIFIED_ACCOUNT,
217
 
        PROP_ORIGINAL_ACCOUNT
218
 
};
219
 
 
220
 
static void emae_refresh_authtype (EMAccountEditor *emae, EMAccountEditorService *service);
221
 
static void em_account_editor_construct (EMAccountEditor *emae, EMAccountEditorType type, const gchar *id);
222
 
static void emae_account_folder_changed (EMFolderSelectionButton *folder, EMAccountEditor *emae);
223
 
static ServerData * emae_check_servers (const gchar *email);
224
 
static void set_provider_defaults_on_url (EMAccountEditor *emae, CamelProvider *provider, CamelURL *url);
225
 
 
226
 
static gpointer parent_class;
227
 
 
228
 
static void
229
 
emae_set_original_account (EMAccountEditor *emae,
230
 
                           EAccount *original_account)
231
 
{
232
 
        EAccount *modified_account;
233
 
 
234
 
        g_return_if_fail (emae->priv->original_account == NULL);
235
 
 
236
 
        /* Editing an existing account. */
237
 
        if (original_account != NULL) {
238
 
                gchar *xml;
239
 
 
240
 
                xml = e_account_to_xml (original_account);
241
 
                modified_account = e_account_new_from_xml (xml);
242
 
                g_free (xml);
243
 
 
244
 
                g_object_ref (original_account);
245
 
                if (emae->type != EMAE_PAGES)
246
 
                        emae->do_signature = TRUE;
247
 
 
248
 
        /* Creating a new account. */
249
 
        } else {
250
 
                modified_account = e_account_new ();
251
 
                modified_account->enabled = TRUE;
252
 
                emae->priv->new_account = TRUE;
253
 
 
254
 
                e_account_set_string (
255
 
                        modified_account, E_ACCOUNT_DRAFTS_FOLDER_URI,
256
 
                        e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_DRAFTS));
257
 
 
258
 
                e_account_set_string (
259
 
                        modified_account, E_ACCOUNT_SENT_FOLDER_URI,
260
 
                        e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_SENT));
261
 
 
262
 
                /* encrypt to self by default */
263
 
                e_account_set_bool (modified_account, E_ACCOUNT_PGP_ENCRYPT_TO_SELF, TRUE);
264
 
                e_account_set_bool (modified_account, E_ACCOUNT_SMIME_ENCRYPT_TO_SELF, TRUE);
265
 
        }
266
 
 
267
 
        emae->priv->original_account = original_account;
268
 
        emae->priv->modified_account = modified_account;
269
 
}
270
 
 
271
 
static void
272
 
emae_set_backend (EMAccountEditor *emae,
273
 
                  EMailBackend *backend)
274
 
{
275
 
        g_return_if_fail (E_IS_MAIL_BACKEND (backend));
276
 
        g_return_if_fail (emae->priv->backend == NULL);
277
 
 
278
 
        emae->priv->backend = g_object_ref (backend);
279
 
}
280
 
 
281
 
static void
282
 
emae_set_property (GObject *object,
283
 
                   guint property_id,
284
 
                   const GValue *value,
285
 
                   GParamSpec *pspec)
286
 
{
287
 
        switch (property_id) {
288
 
                case PROP_BACKEND:
289
 
                        emae_set_backend (
290
 
                                EM_ACCOUNT_EDITOR (object),
291
 
                                g_value_get_object (value));
292
 
                        return;
293
 
 
294
 
                case PROP_ORIGINAL_ACCOUNT:
295
 
                        emae_set_original_account (
296
 
                                EM_ACCOUNT_EDITOR (object),
297
 
                                g_value_get_object (value));
298
 
                        return;
299
 
        }
300
 
 
301
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
302
 
}
303
 
 
304
 
static void
305
 
emae_get_property (GObject *object,
306
 
                   guint property_id,
307
 
                   GValue *value,
308
 
                   GParamSpec *pspec)
309
 
{
310
 
        switch (property_id) {
311
 
                case PROP_BACKEND:
312
 
                        g_value_set_object (
313
 
                                value,
314
 
                                em_account_editor_get_backend (
315
 
                                EM_ACCOUNT_EDITOR (object)));
316
 
                        return;
317
 
 
318
 
                case PROP_MODIFIED_ACCOUNT:
319
 
                        g_value_set_object (
320
 
                                value,
321
 
                                em_account_editor_get_modified_account (
322
 
                                EM_ACCOUNT_EDITOR (object)));
323
 
                        return;
324
 
 
325
 
                case PROP_ORIGINAL_ACCOUNT:
326
 
                        g_value_set_object (
327
 
                                value,
328
 
                                em_account_editor_get_original_account (
329
 
                                EM_ACCOUNT_EDITOR (object)));
330
 
                        return;
331
 
        }
332
 
 
333
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
334
 
}
335
 
 
336
 
static void
337
 
emae_dispose (GObject *object)
338
 
{
339
 
        EMAccountEditorPrivate *priv;
340
 
 
341
 
        priv = EM_ACCOUNT_EDITOR (object)->priv;
342
 
 
343
 
        if (priv->backend != NULL) {
344
 
                g_object_unref (priv->backend);
345
 
                priv->backend = NULL;
346
 
        }
347
 
 
348
 
        if (priv->modified_account != NULL) {
349
 
                g_object_unref (priv->modified_account);
350
 
                priv->modified_account = NULL;
351
 
        }
352
 
 
353
 
        if (priv->original_account != NULL) {
354
 
                g_object_unref (priv->original_account);
355
 
                priv->original_account = NULL;
356
 
        }
357
 
 
358
 
        /* Chain up to parent's dispose() method. */
359
 
        G_OBJECT_CLASS (parent_class)->dispose (object);
360
 
}
361
 
 
362
 
static void
363
 
emae_finalize (GObject *object)
364
 
{
365
 
        EMAccountEditor *emae = EM_ACCOUNT_EDITOR (object);
366
 
        EMAccountEditorPrivate *priv = emae->priv;
367
 
 
368
 
        if (priv->sig_added_id) {
369
 
                ESignatureList *signatures;
370
 
 
371
 
                signatures = e_get_signature_list ();
372
 
                g_signal_handler_disconnect (signatures, priv->sig_added_id);
373
 
                g_signal_handler_disconnect (signatures, priv->sig_removed_id);
374
 
                g_signal_handler_disconnect (signatures, priv->sig_changed_id);
375
 
        }
376
 
 
377
 
        g_list_free (priv->source.auth_types);
378
 
        g_list_free (priv->transport.auth_types);
379
 
 
380
 
        g_list_free (priv->providers);
381
 
 
382
 
        /* Chain up to parent's finalize() method. */
383
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
384
 
}
385
 
 
386
 
static void
387
 
emae_class_init (GObjectClass *class)
388
 
{
389
 
        GObjectClass *object_class;
390
 
 
391
 
        parent_class = g_type_class_peek_parent (class);
392
 
        g_type_class_add_private (class, sizeof (EMAccountEditorPrivate));
393
 
 
394
 
        object_class = G_OBJECT_CLASS (class);
395
 
        object_class->set_property = emae_set_property;
396
 
        object_class->get_property = emae_get_property;
397
 
        object_class->dispose = emae_dispose;
398
 
        object_class->finalize = emae_finalize;
399
 
 
400
 
        g_object_class_install_property (
401
 
                object_class,
402
 
                PROP_BACKEND,
403
 
                g_param_spec_object (
404
 
                        "backend",
405
 
                        "Mail Backend",
406
 
                        NULL,
407
 
                        E_TYPE_MAIL_BACKEND,
408
 
                        G_PARAM_READWRITE |
409
 
                        G_PARAM_CONSTRUCT_ONLY));
410
 
 
411
 
        g_object_class_install_property (
412
 
                object_class,
413
 
                PROP_MODIFIED_ACCOUNT,
414
 
                g_param_spec_object (
415
 
                        "modified-account",
416
 
                        "Modified Account",
417
 
                        NULL,
418
 
                        E_TYPE_ACCOUNT,
419
 
                        G_PARAM_READABLE));
420
 
 
421
 
        g_object_class_install_property (
422
 
                object_class,
423
 
                PROP_ORIGINAL_ACCOUNT,
424
 
                g_param_spec_object (
425
 
                        "original-account",
426
 
                        "Original Account",
427
 
                        NULL,
428
 
                        E_TYPE_ACCOUNT,
429
 
                        G_PARAM_READWRITE |
430
 
                        G_PARAM_CONSTRUCT_ONLY));
431
 
}
432
 
 
433
 
static void
434
 
emae_init (EMAccountEditor *emae)
435
 
{
436
 
        emae->priv = G_TYPE_INSTANCE_GET_PRIVATE (
437
 
                emae, EM_TYPE_ACCOUNT_EDITOR, EMAccountEditorPrivate);
438
 
 
439
 
        emae->priv->selected_server = NULL;
440
 
        emae->emae_check_servers = emae_check_servers;
441
 
        emae->priv->source.emae = emae;
442
 
        emae->priv->transport.emae = emae;
443
 
        emae->priv->widgets = g_hash_table_new (g_str_hash, g_str_equal);
444
 
}
445
 
 
446
 
GType
447
 
em_account_editor_get_type (void)
448
 
{
449
 
        static GType type = 0;
450
 
 
451
 
        if (G_UNLIKELY (type == 0)) {
452
 
                static const GTypeInfo type_info = {
453
 
                        sizeof (EMAccountEditorClass),
454
 
                        (GBaseInitFunc) NULL,
455
 
                        (GBaseFinalizeFunc) NULL,
456
 
                        (GClassInitFunc) emae_class_init,
457
 
                        (GClassFinalizeFunc) NULL,
458
 
                        NULL,  /* class_data */
459
 
                        sizeof (EMAccountEditor),
460
 
                        0,     /* n_preallocs */
461
 
                        (GInstanceInitFunc) emae_init,
462
 
                        NULL   /* value_table */
463
 
                };
464
 
 
465
 
                type = g_type_register_static (
466
 
                        G_TYPE_OBJECT, "EMAccountEditor", &type_info, 0);
467
 
        }
468
 
 
469
 
        return type;
470
 
}
471
 
 
472
 
/**
473
 
 * em_account_editor_new:
474
 
 * @account:
475
 
 * @type:
476
 
 *
477
 
 * Create a new account editor.  If @account is NULL then this is to
478
 
 * create a new account, else @account is copied to a working
479
 
 * structure and is for editing an existing account.
480
 
 *
481
 
 * Return value:
482
 
 **/
483
 
EMAccountEditor *
484
 
em_account_editor_new (EAccount *account,
485
 
                       EMAccountEditorType type,
486
 
                       EMailBackend *backend,
487
 
                       const gchar *id)
488
 
{
489
 
        EMAccountEditor *emae;
490
 
 
491
 
        g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
492
 
 
493
 
        emae = g_object_new (
494
 
                EM_TYPE_ACCOUNT_EDITOR,
495
 
                "original-account", account,
496
 
                "backend", backend, NULL);
497
 
 
498
 
        em_account_editor_construct (emae, type, id);
499
 
 
500
 
        return emae;
501
 
}
502
 
 
503
 
/**
504
 
 * em_account_editor_new_for_pages:
505
 
 * @account:
506
 
 * @type:
507
 
 *
508
 
 * Create a new account editor.  If @account is NULL then this is to
509
 
 * create a new account, else @account is copied to a working
510
 
 * structure and is for editing an existing account.
511
 
 *
512
 
 * Return value:
513
 
 **/
514
 
EMAccountEditor *
515
 
em_account_editor_new_for_pages (EAccount *account,
516
 
                                 EMAccountEditorType type,
517
 
                                 EMailBackend *backend,
518
 
                                 const gchar *id,
519
 
                                 GtkWidget **pages)
520
 
{
521
 
        EMAccountEditor *emae;
522
 
 
523
 
        g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
524
 
 
525
 
        emae = g_object_new (
526
 
                EM_TYPE_ACCOUNT_EDITOR,
527
 
                "original-account", account,
528
 
                "backend", backend, NULL);
529
 
 
530
 
        emae->pages = pages;
531
 
        em_account_editor_construct (emae, type, id);
532
 
 
533
 
        return emae;
534
 
}
535
 
 
536
 
EMailBackend *
537
 
em_account_editor_get_backend (EMAccountEditor *emae)
538
 
{
539
 
        g_return_val_if_fail (EM_IS_ACCOUNT_EDITOR (emae), NULL);
540
 
 
541
 
        return emae->priv->backend;
542
 
}
543
 
 
544
 
EAccount *
545
 
em_account_editor_get_modified_account (EMAccountEditor *emae)
546
 
{
547
 
        g_return_val_if_fail (EM_IS_ACCOUNT_EDITOR (emae), NULL);
548
 
 
549
 
        return emae->priv->modified_account;
550
 
}
551
 
 
552
 
EAccount *
553
 
em_account_editor_get_original_account (EMAccountEditor *emae)
554
 
{
555
 
        g_return_val_if_fail (EM_IS_ACCOUNT_EDITOR (emae), NULL);
556
 
 
557
 
        return emae->priv->original_account;
558
 
}
559
 
 
560
 
/* ********************************************************************** */
561
 
 
562
 
static struct {
563
 
        const gchar *label;
564
 
        const gchar *value;
565
 
} ssl_options[] = {
566
 
        /* Translators: This string is a "Use secure connection" option for
567
 
           the Mailer. It will not use an encrypted connection. */
568
 
        { N_("No encryption"), "never" },
569
 
        /* Translators: This string is a "Use secure connection" option for
570
 
           the Mailer. TLS (Transport Layer Security) is commonly known by
571
 
           this abbreviation. */
572
 
        { N_("TLS encryption"), "when-possible" },
573
 
        /* Translators: This string is a "Use secure connection" option for
574
 
           the Mailer. SSL (Secure Sockets Layer) is commonly known by this
575
 
           abbreviation. */
576
 
        { N_("SSL encryption"), "always" }
577
 
};
578
 
 
579
 
static gboolean
580
 
is_email (const gchar *address)
581
 
{
582
 
        /* This is supposed to check if the address's domain could be
583
 
           an FQDN but alas, it's not worth the pain and suffering. */
584
 
        const gchar *at;
585
 
 
586
 
        at = strchr (address, '@');
587
 
        /* make sure we have an '@' and that it's not the first or last gchar */
588
 
        if (!at || at == address || *(at + 1) == '\0')
589
 
                return FALSE;
590
 
 
591
 
        return TRUE;
592
 
}
593
 
 
594
 
static CamelURL *
595
 
emae_account_url (EMAccountEditor *emae, gint urlid)
596
 
{
597
 
        EAccount *account;
598
 
        CamelURL *url = NULL;
599
 
        const gchar *uri;
600
 
 
601
 
        account = em_account_editor_get_modified_account (emae);
602
 
        uri = e_account_get_string (account, urlid);
603
 
 
604
 
        if (uri && uri[0])
605
 
                url = camel_url_new (uri, NULL);
606
 
 
607
 
        if (url == NULL) {
608
 
                url = camel_url_new ("dummy:", NULL);
609
 
                camel_url_set_protocol (url, NULL);
610
 
        }
611
 
 
612
 
        return url;
613
 
}
614
 
 
615
 
/* ********************************************************************** */
616
 
 
617
 
static void
618
 
default_folders_clicked (GtkButton *button, gpointer user_data)
619
 
{
620
 
        EMAccountEditor *emae = user_data;
621
 
        const gchar *uri;
622
 
 
623
 
        uri = e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_DRAFTS);
624
 
        em_folder_selection_button_set_selection ((EMFolderSelectionButton *) emae->priv->drafts_folder_button, uri);
625
 
        emae_account_folder_changed ((EMFolderSelectionButton *) emae->priv->drafts_folder_button, emae);
626
 
 
627
 
        uri = e_mail_local_get_folder_uri (E_MAIL_LOCAL_FOLDER_SENT);
628
 
        em_folder_selection_button_set_selection ((EMFolderSelectionButton *) emae->priv->sent_folder_button, uri);
629
 
        emae_account_folder_changed ((EMFolderSelectionButton *) emae->priv->sent_folder_button, emae);
630
 
 
631
 
        gtk_toggle_button_set_active (emae->priv->trash_folder_check, FALSE);
632
 
        gtk_toggle_button_set_active (emae->priv->junk_folder_check, FALSE);
633
 
}
634
 
 
635
 
/* The camel provider auto-detect interface should be deprecated.
636
 
   But it still needs to be replaced with something of similar functionality.
637
 
   Just using the normal econfig plugin mechanism should be adequate. */
638
 
static void
639
 
emae_auto_detect_free (gpointer key, gpointer value, gpointer user_data)
640
 
{
641
 
        g_free (key);
642
 
        g_free (value);
643
 
}
644
 
 
645
 
static void
646
 
emae_auto_detect (EMAccountEditor *emae)
647
 
{
648
 
        EMAccountEditorPrivate *priv = emae->priv;
649
 
        EMAccountEditorService *service = &priv->source;
650
 
        GHashTable *auto_detected;
651
 
        GSList *l;
652
 
        CamelProviderConfEntry *entries;
653
 
        gchar *value;
654
 
        gint i;
655
 
        CamelURL *url;
656
 
 
657
 
        if (service->provider == NULL
658
 
            || (entries = service->provider->extra_conf) == NULL)
659
 
                return;
660
 
 
661
 
        d (printf ("Running auto-detect\n"));
662
 
 
663
 
        url = emae_account_url (emae, E_ACCOUNT_SOURCE_URL);
664
 
        camel_provider_auto_detect (service->provider, url, &auto_detected, NULL);
665
 
        camel_url_free (url);
666
 
        if (auto_detected == NULL) {
667
 
                d (printf (" no values detected\n"));
668
 
                return;
669
 
        }
670
 
 
671
 
        for (i = 0; entries[i].type != CAMEL_PROVIDER_CONF_END; i++) {
672
 
                struct _receive_options_item *item;
673
 
                GtkWidget *w;
674
 
 
675
 
                if (entries[i].name == NULL
676
 
                    || (value = g_hash_table_lookup (auto_detected, entries[i].name)) == NULL)
677
 
                        continue;
678
 
 
679
 
                /* only 2 providers use this, and they only do it for 3 entries only */
680
 
                g_return_if_fail (entries[i].type == CAMEL_PROVIDER_CONF_ENTRY);
681
 
 
682
 
                w = NULL;
683
 
                for (l = emae->priv->extra_items;l;l=g_slist_next (l)) {
684
 
                        item = l->data;
685
 
                        if (item->extra_table && (w = g_hash_table_lookup (item->extra_table, entries[i].name)))
686
 
                                break;
687
 
                }
688
 
 
689
 
                gtk_entry_set_text ((GtkEntry *)w, value?value:"");
690
 
        }
691
 
 
692
 
        g_hash_table_foreach (auto_detected, emae_auto_detect_free, NULL);
693
 
        g_hash_table_destroy (auto_detected);
694
 
}
695
 
 
696
 
static gint
697
 
provider_compare (const CamelProvider *p1, const CamelProvider *p2)
698
 
{
699
 
        /* sort providers based on "location" (ie. local or remote) */
700
 
        if (p1->flags & CAMEL_PROVIDER_IS_REMOTE) {
701
 
                if (p2->flags & CAMEL_PROVIDER_IS_REMOTE)
702
 
                        return 0;
703
 
                return -1;
704
 
        } else {
705
 
                if (p2->flags & CAMEL_PROVIDER_IS_REMOTE)
706
 
                        return 1;
707
 
                return 0;
708
 
        }
709
 
}
710
 
 
711
 
static void
712
 
emae_signature_added (ESignatureList *signatures, ESignature *sig, EMAccountEditor *emae)
713
 
{
714
 
        GtkTreeModel *model;
715
 
        GtkTreeIter iter;
716
 
        const gchar *name;
717
 
        const gchar *uid;
718
 
 
719
 
        name = e_signature_get_name (sig);
720
 
        uid = e_signature_get_uid (sig);
721
 
 
722
 
        model = gtk_combo_box_get_model (emae->priv->signatures_dropdown);
723
 
 
724
 
        gtk_list_store_append ((GtkListStore *) model, &iter);
725
 
        gtk_list_store_set ((GtkListStore *) model, &iter, 0, name, 1, uid, -1);
726
 
 
727
 
        gtk_combo_box_set_active (emae->priv->signatures_dropdown, gtk_tree_model_iter_n_children (model, NULL)-1);
728
 
}
729
 
 
730
 
static gint
731
 
emae_signature_get_iter (EMAccountEditor *emae, ESignature *sig, GtkTreeModel **modelp, GtkTreeIter *iter)
732
 
{
733
 
        GtkTreeModel *model;
734
 
        gint found = 0;
735
 
 
736
 
        model = gtk_combo_box_get_model (emae->priv->signatures_dropdown);
737
 
        *modelp = model;
738
 
        if (!gtk_tree_model_get_iter_first (model, iter))
739
 
                return FALSE;
740
 
 
741
 
        do {
742
 
                const gchar *signature_uid;
743
 
                gchar *uid;
744
 
 
745
 
                signature_uid = e_signature_get_uid (sig);
746
 
 
747
 
                gtk_tree_model_get (model, iter, 1, &uid, -1);
748
 
                if (uid && !strcmp (uid, signature_uid))
749
 
                        found = TRUE;
750
 
                g_free (uid);
751
 
        } while (!found && gtk_tree_model_iter_next (model, iter));
752
 
 
753
 
        return found;
754
 
}
755
 
 
756
 
static void
757
 
emae_signature_removed (ESignatureList *signatures, ESignature *sig, EMAccountEditor *emae)
758
 
{
759
 
        GtkTreeIter iter;
760
 
        GtkTreeModel *model;
761
 
 
762
 
        if (emae_signature_get_iter (emae, sig, &model, &iter))
763
 
                gtk_list_store_remove ((GtkListStore *) model, &iter);
764
 
}
765
 
 
766
 
static void
767
 
emae_signature_changed (ESignatureList *signatures, ESignature *sig, EMAccountEditor *emae)
768
 
{
769
 
        GtkTreeIter iter;
770
 
        GtkTreeModel *model;
771
 
        const gchar *name;
772
 
 
773
 
        name = e_signature_get_name (sig);
774
 
 
775
 
        if (emae_signature_get_iter (emae, sig, &model, &iter))
776
 
                gtk_list_store_set ((GtkListStore *) model, &iter, 0, name, -1);
777
 
}
778
 
 
779
 
static void
780
 
emae_signaturetype_changed (GtkComboBox *dropdown, EMAccountEditor *emae)
781
 
{
782
 
        EAccount *account;
783
 
        gint id = gtk_combo_box_get_active (dropdown);
784
 
        GtkTreeModel *model;
785
 
        GtkTreeIter iter;
786
 
        gchar *uid = NULL;
787
 
 
788
 
        account = em_account_editor_get_modified_account (emae);
789
 
 
790
 
        if (id != -1) {
791
 
                model = gtk_combo_box_get_model (dropdown);
792
 
                if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id))
793
 
                        gtk_tree_model_get (model, &iter, 1, &uid, -1);
794
 
        }
795
 
 
796
 
        e_account_set_string (account, E_ACCOUNT_ID_SIGNATURE, uid);
797
 
        g_free (uid);
798
 
}
799
 
 
800
 
static void
801
 
emae_signature_new (GtkWidget *widget, EMAccountEditor *emae)
802
 
{
803
 
        GtkWidget *editor;
804
 
        gpointer parent;
805
 
 
806
 
        parent = gtk_widget_get_toplevel (widget);
807
 
        parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
808
 
 
809
 
        editor = e_signature_editor_new ();
810
 
        gtk_window_set_transient_for (GTK_WINDOW (editor), parent);
811
 
        gtk_widget_show (editor);
812
 
}
813
 
 
814
 
static GtkWidget *
815
 
emae_setup_signatures (EMAccountEditor *emae, GtkBuilder *builder)
816
 
{
817
 
        EMAccountEditorPrivate *p = emae->priv;
818
 
        EAccount *account;
819
 
        GtkComboBox *dropdown = (GtkComboBox *)e_builder_get_widget (builder, "signature_dropdown");
820
 
        GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
821
 
        GtkListStore *store;
822
 
        gint i, active=0;
823
 
        GtkTreeIter iter;
824
 
        ESignatureList *signatures;
825
 
        EIterator *it;
826
 
        const gchar *current;
827
 
        GtkWidget *button;
828
 
 
829
 
        account = em_account_editor_get_modified_account (emae);
830
 
        current = e_account_get_string (account, E_ACCOUNT_ID_SIGNATURE);
831
 
 
832
 
        emae->priv->signatures_dropdown = dropdown;
833
 
        gtk_widget_show ((GtkWidget *) dropdown);
834
 
 
835
 
        store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
836
 
 
837
 
        gtk_list_store_append (store, &iter);
838
 
        /* Translators: "None" as an option for a default signature of an account, part of "Signature: None" */
839
 
        gtk_list_store_set (store, &iter, 0, C_("mail-signature", "None"), 1, NULL, -1);
840
 
 
841
 
        signatures = e_get_signature_list ();
842
 
 
843
 
        if (p->sig_added_id == 0) {
844
 
                p->sig_added_id = g_signal_connect (signatures, "signature-added", G_CALLBACK(emae_signature_added), emae);
845
 
                p->sig_removed_id = g_signal_connect (signatures, "signature-removed", G_CALLBACK(emae_signature_removed), emae);
846
 
                p->sig_changed_id = g_signal_connect (signatures, "signature-changed", G_CALLBACK(emae_signature_changed), emae);
847
 
        }
848
 
 
849
 
        /* we need to count the 'none' entry before using the index */
850
 
        i = 1;
851
 
        it = e_list_get_iterator ((EList *) signatures);
852
 
        while (e_iterator_is_valid (it)) {
853
 
                ESignature *sig = (ESignature *) e_iterator_get (it);
854
 
                const gchar *name;
855
 
                const gchar *uid;
856
 
 
857
 
                name = e_signature_get_name (sig);
858
 
                uid = e_signature_get_uid (sig);
859
 
 
860
 
                gtk_list_store_append (store, &iter);
861
 
                gtk_list_store_set (store, &iter, 0, name, 1, uid, -1);
862
 
 
863
 
                if (current && !strcmp (current, uid))
864
 
                        active = i;
865
 
 
866
 
                e_iterator_next (it);
867
 
                i++;
868
 
        }
869
 
        g_object_unref (it);
870
 
 
871
 
        gtk_cell_layout_pack_start ((GtkCellLayout *) dropdown, cell, TRUE);
872
 
        gtk_cell_layout_set_attributes ((GtkCellLayout *)dropdown, cell, "text", 0, NULL);
873
 
 
874
 
        gtk_combo_box_set_model (dropdown, (GtkTreeModel *) store);
875
 
        gtk_combo_box_set_active (dropdown, active);
876
 
 
877
 
        g_signal_connect (dropdown, "changed", G_CALLBACK(emae_signaturetype_changed), emae);
878
 
        gtk_widget_set_sensitive ((GtkWidget *) dropdown, e_account_writable (account, E_ACCOUNT_ID_SIGNATURE));
879
 
 
880
 
        button = e_builder_get_widget (builder, "sigAddNew");
881
 
        g_signal_connect (button, "clicked", G_CALLBACK(emae_signature_new), emae);
882
 
 
883
 
        return (GtkWidget *) dropdown;
884
 
}
885
 
 
886
 
static void
887
 
emae_receipt_policy_changed (GtkComboBox *dropdown, EMAccountEditor *emae)
888
 
{
889
 
        EAccount *account;
890
 
        gint id = gtk_combo_box_get_active (dropdown);
891
 
        GtkTreeModel *model;
892
 
        GtkTreeIter iter;
893
 
        EAccountReceiptPolicy policy;
894
 
 
895
 
        account = em_account_editor_get_modified_account (emae);
896
 
 
897
 
        if (id != -1) {
898
 
                model = gtk_combo_box_get_model (dropdown);
899
 
                if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) {
900
 
                        gtk_tree_model_get (model, &iter, 1, &policy, -1);
901
 
                        e_account_set_int (account, E_ACCOUNT_RECEIPT_POLICY, policy);
902
 
                }
903
 
        }
904
 
}
905
 
 
906
 
static GtkWidget *
907
 
emae_setup_receipt_policy (EMAccountEditor *emae, GtkBuilder *builder)
908
 
{
909
 
        EAccount *account;
910
 
        GtkComboBox *dropdown = (GtkComboBox *)e_builder_get_widget (builder, "receipt_policy_dropdown");
911
 
        GtkListStore *store;
912
 
        GtkCellRenderer *cell;
913
 
        gint i = 0, active = 0;
914
 
        GtkTreeIter iter;
915
 
        EAccountReceiptPolicy current;
916
 
        static struct {
917
 
                EAccountReceiptPolicy policy;
918
 
                const gchar *label;
919
 
        } receipt_policies[] = {
920
 
                { E_ACCOUNT_RECEIPT_NEVER,  N_("Never") },
921
 
                { E_ACCOUNT_RECEIPT_ALWAYS, N_("Always") },
922
 
                { E_ACCOUNT_RECEIPT_ASK,    N_("Ask for each message") }
923
 
        };
924
 
 
925
 
        account = em_account_editor_get_modified_account (emae);
926
 
        current = account->receipt_policy;
927
 
 
928
 
        gtk_widget_show ((GtkWidget *) dropdown);
929
 
 
930
 
        store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
931
 
 
932
 
        for (i = 0; i < 3; ++i) {
933
 
                gtk_list_store_append (store, &iter);
934
 
                gtk_list_store_set (store, &iter,
935
 
                                    0, _(receipt_policies[i].label),
936
 
                                    1, receipt_policies[i].policy,
937
 
                                    -1);
938
 
                if (current == receipt_policies[i].policy)
939
 
                        active = i;
940
 
        }
941
 
 
942
 
        gtk_combo_box_set_model (dropdown, (GtkTreeModel *) store);
943
 
 
944
 
        cell = gtk_cell_renderer_text_new ();
945
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (dropdown), cell, TRUE);
946
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (dropdown), cell, "text", 0, NULL);
947
 
 
948
 
        gtk_combo_box_set_active (dropdown, active);
949
 
 
950
 
        g_signal_connect (dropdown, "changed", G_CALLBACK(emae_receipt_policy_changed), emae);
951
 
        gtk_widget_set_sensitive ((GtkWidget *) dropdown, e_account_writable (account, E_ACCOUNT_RECEIPT_POLICY));
952
 
 
953
 
        return (GtkWidget *) dropdown;
954
 
}
955
 
 
956
 
static void
957
 
emae_account_entry_changed (GtkEntry *entry, EMAccountEditor *emae)
958
 
{
959
 
        EAccount *account;
960
 
        gchar *text;
961
 
        gpointer data;
962
 
 
963
 
        account = em_account_editor_get_modified_account (emae);
964
 
        data = g_object_get_data (G_OBJECT (entry), "account-item");
965
 
        text = g_strdup (gtk_entry_get_text (entry));
966
 
 
967
 
        g_strstrip (text);
968
 
 
969
 
        e_account_set_string (account, GPOINTER_TO_INT (data), text);
970
 
 
971
 
        g_free (text);
972
 
}
973
 
 
974
 
static GtkEntry *
975
 
emae_account_entry (EMAccountEditor *emae, const gchar *name, gint item, GtkBuilder *builder)
976
 
{
977
 
        EAccount *account;
978
 
        GtkEntry *entry;
979
 
        const gchar *text;
980
 
 
981
 
        account = em_account_editor_get_modified_account (emae);
982
 
        entry = (GtkEntry *) e_builder_get_widget (builder, name);
983
 
        text = e_account_get_string (account, item);
984
 
        if (text)
985
 
                gtk_entry_set_text (entry, text);
986
 
        g_object_set_data ((GObject *)entry, "account-item", GINT_TO_POINTER(item));
987
 
        g_signal_connect (entry, "changed", G_CALLBACK(emae_account_entry_changed), emae);
988
 
        gtk_widget_set_sensitive ((GtkWidget *) entry, e_account_writable (account, item));
989
 
 
990
 
        return entry;
991
 
}
992
 
 
993
 
static void
994
 
emae_account_toggle_changed (GtkToggleButton *toggle, EMAccountEditor *emae)
995
 
{
996
 
        EAccount *account;
997
 
        gboolean active;
998
 
        gpointer data;
999
 
 
1000
 
        account = em_account_editor_get_modified_account (emae);
1001
 
        data = g_object_get_data (G_OBJECT (toggle), "account-item");
1002
 
        active = gtk_toggle_button_get_active (toggle);
1003
 
 
1004
 
        e_account_set_bool (account, GPOINTER_TO_INT (data), active);
1005
 
}
1006
 
 
1007
 
static void
1008
 
emae_account_toggle_widget (EMAccountEditor *emae, GtkToggleButton *toggle, gint item)
1009
 
{
1010
 
        EAccount *account;
1011
 
        gboolean active;
1012
 
        gboolean writable;
1013
 
 
1014
 
        account = em_account_editor_get_modified_account (emae);
1015
 
 
1016
 
        active = e_account_get_bool (account, item);
1017
 
        gtk_toggle_button_set_active (toggle, active);
1018
 
 
1019
 
        writable = e_account_writable (account, item);
1020
 
        gtk_widget_set_sensitive (GTK_WIDGET (toggle), writable);
1021
 
 
1022
 
        g_object_set_data (
1023
 
                G_OBJECT (toggle), "account-item",
1024
 
                GINT_TO_POINTER (item));
1025
 
 
1026
 
        g_signal_connect (
1027
 
                toggle, "toggled",
1028
 
                G_CALLBACK (emae_account_toggle_changed), emae);
1029
 
}
1030
 
 
1031
 
static GtkToggleButton *
1032
 
emae_account_toggle (EMAccountEditor *emae, const gchar *name, gint item, GtkBuilder *builder)
1033
 
{
1034
 
        GtkToggleButton *toggle;
1035
 
 
1036
 
        toggle = (GtkToggleButton *) e_builder_get_widget (builder, name);
1037
 
        emae_account_toggle_widget (emae, toggle, item);
1038
 
 
1039
 
        return toggle;
1040
 
}
1041
 
 
1042
 
static void
1043
 
emae_account_spinint_changed (GtkSpinButton *spin, EMAccountEditor *emae)
1044
 
{
1045
 
        EAccount *account;
1046
 
        gpointer data;
1047
 
        gint value;
1048
 
 
1049
 
        account = em_account_editor_get_modified_account (emae);
1050
 
        data = g_object_get_data (G_OBJECT (spin), "account-item");
1051
 
        value = gtk_spin_button_get_value (spin);
1052
 
 
1053
 
        e_account_set_int (account, GPOINTER_TO_INT (data), value);
1054
 
}
1055
 
 
1056
 
static void
1057
 
emae_account_spinint_widget (EMAccountEditor *emae, GtkSpinButton *spin, gint item)
1058
 
{
1059
 
        EAccount *account;
1060
 
        gboolean writable;
1061
 
        gint v_int;
1062
 
 
1063
 
        account = em_account_editor_get_modified_account (emae);
1064
 
 
1065
 
        v_int = e_account_get_int (account, item);
1066
 
        gtk_spin_button_set_value (spin, v_int);
1067
 
 
1068
 
        writable = e_account_writable (account, item);
1069
 
        gtk_widget_set_sensitive (GTK_WIDGET (spin), writable);
1070
 
 
1071
 
        g_object_set_data (
1072
 
                G_OBJECT (spin), "account-item",
1073
 
                GINT_TO_POINTER (item));
1074
 
 
1075
 
        g_signal_connect (
1076
 
                spin, "value-changed",
1077
 
                G_CALLBACK (emae_account_spinint_changed), emae);
1078
 
}
1079
 
 
1080
 
#if 0
1081
 
static GtkSpinButton *
1082
 
emae_account_spinint (EMAccountEditor *emae, const gchar *name, gint item)
1083
 
{
1084
 
        GtkSpinButton *spin;
1085
 
 
1086
 
        spin = (GtkSpinButton *) e_builder_get_widget (emae->priv->xml, name);
1087
 
        emae_account_spinint_widget (emae, spin, item);
1088
 
 
1089
 
        return spin;
1090
 
}
1091
 
#endif
1092
 
 
1093
 
static void
1094
 
emae_account_folder_changed (EMFolderSelectionButton *folder, EMAccountEditor *emae)
1095
 
{
1096
 
        EAccount *account;
1097
 
        gpointer data;
1098
 
        const gchar *selection;
1099
 
 
1100
 
        account = em_account_editor_get_modified_account (emae);
1101
 
        data = g_object_get_data (G_OBJECT (folder), "account-item");
1102
 
        selection = em_folder_selection_button_get_selection (folder);
1103
 
 
1104
 
        e_account_set_string (account, GPOINTER_TO_INT (data), selection);
1105
 
}
1106
 
 
1107
 
static EMFolderSelectionButton *
1108
 
emae_account_folder (EMAccountEditor *emae, const gchar *name, gint item, gint deffolder, GtkBuilder *builder)
1109
 
{
1110
 
        EAccount *account;
1111
 
        EMFolderSelectionButton *folder;
1112
 
        EMailBackend *backend;
1113
 
        const gchar *uri;
1114
 
 
1115
 
        account = em_account_editor_get_modified_account (emae);
1116
 
        backend = em_account_editor_get_backend (emae);
1117
 
 
1118
 
        folder = (EMFolderSelectionButton *) e_builder_get_widget (builder, name);
1119
 
        em_folder_selection_button_set_backend (folder, backend);
1120
 
 
1121
 
        uri = e_account_get_string (account, item);
1122
 
        if (uri != NULL) {
1123
 
                em_folder_selection_button_set_selection (folder, uri);
1124
 
        } else {
1125
 
                uri = e_mail_local_get_folder_uri (deffolder);
1126
 
                em_folder_selection_button_set_selection (folder, uri);
1127
 
        }
1128
 
 
1129
 
        g_object_set_data ((GObject *)folder, "account-item", GINT_TO_POINTER(item));
1130
 
        g_object_set_data ((GObject *)folder, "folder-default", GINT_TO_POINTER(deffolder));
1131
 
        g_signal_connect (folder, "selected", G_CALLBACK(emae_account_folder_changed), emae);
1132
 
        gtk_widget_show ((GtkWidget *) folder);
1133
 
 
1134
 
        gtk_widget_set_sensitive ((GtkWidget *) folder, e_account_writable (account, item));
1135
 
 
1136
 
        return folder;
1137
 
}
1138
 
 
1139
 
#if defined (HAVE_NSS) && defined (ENABLE_SMIME)
1140
 
static void
1141
 
smime_changed (EMAccountEditor *emae)
1142
 
{
1143
 
        EMAccountEditorPrivate *priv = emae->priv;
1144
 
        gint act;
1145
 
        const gchar *tmp;
1146
 
 
1147
 
        tmp = gtk_entry_get_text (priv->smime_sign_key);
1148
 
        act = tmp && tmp[0];
1149
 
        gtk_widget_set_sensitive ((GtkWidget *) priv->smime_sign_key_clear, act);
1150
 
        gtk_widget_set_sensitive ((GtkWidget *) priv->smime_sign_default, act);
1151
 
        if (!act)
1152
 
                gtk_toggle_button_set_active (priv->smime_sign_default, FALSE);
1153
 
 
1154
 
        tmp = gtk_entry_get_text (priv->smime_encrypt_key);
1155
 
        act = tmp && tmp[0];
1156
 
        gtk_widget_set_sensitive ((GtkWidget *) priv->smime_encrypt_key_clear, act);
1157
 
        gtk_widget_set_sensitive ((GtkWidget *) priv->smime_encrypt_default, act);
1158
 
        gtk_widget_set_sensitive ((GtkWidget *) priv->smime_encrypt_to_self, act);
1159
 
        if (!act) {
1160
 
                gtk_toggle_button_set_active (priv->smime_encrypt_default, FALSE);
1161
 
        }
1162
 
}
1163
 
 
1164
 
static void
1165
 
smime_sign_key_selected (GtkWidget *dialog, const gchar *key, EMAccountEditor *emae)
1166
 
{
1167
 
        EMAccountEditorPrivate *priv = emae->priv;
1168
 
 
1169
 
        if (key != NULL) {
1170
 
                gtk_entry_set_text (priv->smime_sign_key, key);
1171
 
                smime_changed (emae);
1172
 
        }
1173
 
 
1174
 
        gtk_widget_destroy (dialog);
1175
 
}
1176
 
 
1177
 
static void
1178
 
smime_sign_key_select (GtkWidget *button, EMAccountEditor *emae)
1179
 
{
1180
 
        EMAccountEditorPrivate *priv = emae->priv;
1181
 
        GtkWidget *w;
1182
 
 
1183
 
        w = e_cert_selector_new (E_CERT_SELECTOR_SIGNER, gtk_entry_get_text (priv->smime_sign_key));
1184
 
        gtk_window_set_modal ((GtkWindow *) w, TRUE);
1185
 
        gtk_window_set_transient_for ((GtkWindow *) w, (GtkWindow *) gtk_widget_get_toplevel (button));
1186
 
        g_signal_connect (w, "selected", G_CALLBACK(smime_sign_key_selected), emae);
1187
 
        gtk_widget_show (w);
1188
 
}
1189
 
 
1190
 
static void
1191
 
smime_sign_key_clear (GtkWidget *w, EMAccountEditor *emae)
1192
 
{
1193
 
        EMAccountEditorPrivate *priv = emae->priv;
1194
 
 
1195
 
        gtk_entry_set_text (priv->smime_sign_key, "");
1196
 
        smime_changed (emae);
1197
 
}
1198
 
 
1199
 
static void
1200
 
smime_encrypt_key_selected (GtkWidget *dialog, const gchar *key, EMAccountEditor *emae)
1201
 
{
1202
 
        EMAccountEditorPrivate *priv = emae->priv;
1203
 
 
1204
 
        if (key != NULL) {
1205
 
                gtk_entry_set_text (priv->smime_encrypt_key, key);
1206
 
                smime_changed (emae);
1207
 
        }
1208
 
 
1209
 
        gtk_widget_destroy (dialog);
1210
 
}
1211
 
 
1212
 
static void
1213
 
smime_encrypt_key_select (GtkWidget *button, EMAccountEditor *emae)
1214
 
{
1215
 
        EMAccountEditorPrivate *priv = emae->priv;
1216
 
        GtkWidget *w;
1217
 
 
1218
 
        w = e_cert_selector_new (E_CERT_SELECTOR_RECIPIENT, gtk_entry_get_text (priv->smime_encrypt_key));
1219
 
        gtk_window_set_modal ((GtkWindow *) w, TRUE);
1220
 
        gtk_window_set_transient_for ((GtkWindow *) w, (GtkWindow *) gtk_widget_get_toplevel (button));
1221
 
        g_signal_connect (w, "selected", G_CALLBACK(smime_encrypt_key_selected), emae);
1222
 
        gtk_widget_show (w);
1223
 
}
1224
 
 
1225
 
static void
1226
 
smime_encrypt_key_clear (GtkWidget *w, EMAccountEditor *emae)
1227
 
{
1228
 
        EMAccountEditorPrivate *priv = emae->priv;
1229
 
 
1230
 
        gtk_entry_set_text (priv->smime_encrypt_key, "");
1231
 
        smime_changed (emae);
1232
 
}
1233
 
#endif
1234
 
 
1235
 
static void
1236
 
emae_url_set_host (CamelURL *url, const gchar *txt)
1237
 
{
1238
 
        gchar *host;
1239
 
 
1240
 
        if (txt && *txt) {
1241
 
                host = g_strdup (txt);
1242
 
                g_strstrip (host);
1243
 
                camel_url_set_host (url, host);
1244
 
                g_free (host);
1245
 
        }
1246
 
}
1247
 
 
1248
 
static void
1249
 
emae_url_set_port (CamelURL *url, const gchar *port)
1250
 
{
1251
 
        if (port && *port)
1252
 
                camel_url_set_port (url, atoi (port));
1253
 
}
1254
 
 
1255
 
/* This is used to map a funciton which will set on the url a string value.
1256
 
   if widgets[0] is set, it is the entry which will be called against setval ()
1257
 
   We need our own function for host:port decoding, as above */
1258
 
struct _provider_host_info {
1259
 
        guint32 flag;
1260
 
        void (*setval)(CamelURL *, const gchar *);
1261
 
        glong widgets[3];
1262
 
};
1263
 
 
1264
 
static struct _provider_host_info emae_source_host_info[] = {
1265
 
        { CAMEL_URL_PART_HOST, emae_url_set_host, { G_STRUCT_OFFSET (EMAccountEditorService, hostname), G_STRUCT_OFFSET (EMAccountEditorService, hostlabel), }, },
1266
 
        { CAMEL_URL_PART_PORT, emae_url_set_port,  { G_STRUCT_OFFSET (EMAccountEditorService, port), G_STRUCT_OFFSET (EMAccountEditorService, portlabel), }, },
1267
 
        { CAMEL_URL_PART_USER, camel_url_set_user, { G_STRUCT_OFFSET (EMAccountEditorService, username), G_STRUCT_OFFSET (EMAccountEditorService, userlabel), } },
1268
 
        { CAMEL_URL_PART_PATH, camel_url_set_path, { G_STRUCT_OFFSET (EMAccountEditorService, path), G_STRUCT_OFFSET (EMAccountEditorService, pathlabel), G_STRUCT_OFFSET (EMAccountEditorService, pathentry) }, },
1269
 
        { CAMEL_URL_PART_AUTH, NULL, { 0, G_STRUCT_OFFSET (EMAccountEditorService, auth_frame), }, },
1270
 
        { 0 },
1271
 
};
1272
 
 
1273
 
static struct _provider_host_info emae_transport_host_info[] = {
1274
 
        { CAMEL_URL_PART_HOST, emae_url_set_host, { G_STRUCT_OFFSET (EMAccountEditorService, hostname), G_STRUCT_OFFSET (EMAccountEditorService, hostlabel), }, },
1275
 
        { CAMEL_URL_PART_PORT, emae_url_set_port, { G_STRUCT_OFFSET (EMAccountEditorService, port), G_STRUCT_OFFSET (EMAccountEditorService, portlabel), }, },
1276
 
        { CAMEL_URL_PART_USER, camel_url_set_user, { G_STRUCT_OFFSET (EMAccountEditorService, username), G_STRUCT_OFFSET (EMAccountEditorService, userlabel), } },
1277
 
        { CAMEL_URL_PART_AUTH, NULL, { 0, G_STRUCT_OFFSET (EMAccountEditorService, auth_frame), }, },
1278
 
        { 0 },
1279
 
};
1280
 
 
1281
 
/* This is used to map each of the two services in a typical account to
1282
 
 * the widgets that represent each service.  i.e. the receiving (source)
1283
 
 * service, and the sending (transport) service.  It is used throughout
1284
 
 * the following code to drive each page. */
1285
 
static struct _service_info {
1286
 
        gint account_uri_key;
1287
 
        gint save_passwd_key;
1288
 
 
1289
 
        const gchar *frame;
1290
 
        const gchar *type_dropdown;
1291
 
 
1292
 
        const gchar *container;
1293
 
        const gchar *description;
1294
 
        const gchar *hostname;
1295
 
        const gchar *hostlabel;
1296
 
        const gchar *port;
1297
 
        const gchar *portlabel;
1298
 
        const gchar *username;
1299
 
        const gchar *userlabel;
1300
 
        const gchar *path;
1301
 
        const gchar *pathlabel;
1302
 
        const gchar *pathentry;
1303
 
 
1304
 
        const gchar *security_frame;
1305
 
        const gchar *ssl_hbox;
1306
 
        const gchar *use_ssl;
1307
 
        const gchar *ssl_disabled;
1308
 
 
1309
 
        const gchar *needs_auth;
1310
 
        const gchar *auth_frame;
1311
 
 
1312
 
        const gchar *authtype;
1313
 
        const gchar *authtype_check;
1314
 
 
1315
 
        const gchar *remember_password;
1316
 
 
1317
 
        struct _provider_host_info *host_info;
1318
 
 
1319
 
} emae_service_info[CAMEL_NUM_PROVIDER_TYPES] = {
1320
 
 
1321
 
        { E_ACCOUNT_SOURCE_URL,
1322
 
          E_ACCOUNT_SOURCE_SAVE_PASSWD,
1323
 
 
1324
 
          "source-config-section",
1325
 
          "source_type_dropdown",
1326
 
 
1327
 
          "vboxSourceBorder",
1328
 
          "source_description",
1329
 
          "source_host",
1330
 
          "source_host_label",
1331
 
          "source_port",
1332
 
          "source_port_label",
1333
 
          "source_user",
1334
 
          "source_user_label",
1335
 
          "source_path",
1336
 
          "source_path_label",
1337
 
          "source_path_entry",
1338
 
 
1339
 
          "source-security-section",
1340
 
          "source_ssl_hbox",
1341
 
          "source_use_ssl",
1342
 
          "source_ssl_disabled",
1343
 
 
1344
 
          NULL,
1345
 
          "source-auth-section",
1346
 
 
1347
 
          "source_auth_dropdown",
1348
 
          "source_check_supported",
1349
 
 
1350
 
          "source_remember_password",
1351
 
 
1352
 
          emae_source_host_info },
1353
 
 
1354
 
        { E_ACCOUNT_TRANSPORT_URL,
1355
 
          E_ACCOUNT_TRANSPORT_SAVE_PASSWD,
1356
 
 
1357
 
          "transport-server-section",
1358
 
          "transport_type_dropdown",
1359
 
 
1360
 
          "vboxTransportBorder",
1361
 
          "transport_description",
1362
 
          "transport_host",
1363
 
          "transport_host_label",
1364
 
          "transport_port",
1365
 
          "transport_port_label",
1366
 
          "transport_user",
1367
 
          "transport_user_label",
1368
 
          NULL,
1369
 
          NULL,
1370
 
          NULL,
1371
 
 
1372
 
          "transport-security-section",
1373
 
          "transport_ssl_hbox",
1374
 
          "transport_use_ssl",
1375
 
          "transport_ssl_disabled",
1376
 
 
1377
 
          "transport_needs_auth",
1378
 
          "transport-auth-section",
1379
 
 
1380
 
          "transport_auth_dropdown",
1381
 
          "transport_check_supported",
1382
 
 
1383
 
          "transport_remember_password",
1384
 
 
1385
 
          emae_transport_host_info,
1386
 
        },
1387
 
};
1388
 
 
1389
 
static void
1390
 
emae_uri_changed (EMAccountEditorService *service, CamelURL *url)
1391
 
{
1392
 
        EAccount *account;
1393
 
        gchar *uri;
1394
 
 
1395
 
        account = em_account_editor_get_modified_account (service->emae);
1396
 
        uri = camel_url_to_string (url, 0);
1397
 
 
1398
 
        e_account_set_string (account, emae_service_info[service->type].account_uri_key, uri);
1399
 
 
1400
 
        /* small hack for providers which are store and transport - copy settings across */
1401
 
        if (service->type == CAMEL_PROVIDER_STORE
1402
 
            && service->provider
1403
 
            && CAMEL_PROVIDER_IS_STORE_AND_TRANSPORT (service->provider))
1404
 
                e_account_set_string (account, E_ACCOUNT_TRANSPORT_URL, uri);
1405
 
 
1406
 
        g_free (uri);
1407
 
}
1408
 
 
1409
 
static void
1410
 
emae_service_url_changed (EMAccountEditorService *service, void (*setval)(CamelURL *, const gchar *), GtkWidget *entry)
1411
 
{
1412
 
        GtkComboBox *dropdown;
1413
 
        gint id;
1414
 
        GtkTreeModel *model;
1415
 
        GtkTreeIter iter;
1416
 
        CamelServiceAuthType *authtype;
1417
 
        gchar *text;
1418
 
 
1419
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
1420
 
 
1421
 
        if (GTK_IS_ENTRY (entry))
1422
 
                text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1423
 
        else if (E_IS_PORT_ENTRY (entry)) {
1424
 
                text = g_strdup_printf ("%i", e_port_entry_get_port (E_PORT_ENTRY (entry)));
1425
 
        } else
1426
 
                return;
1427
 
 
1428
 
        g_strstrip (text);
1429
 
 
1430
 
        setval (url, (text && text[0])?text:NULL);
1431
 
 
1432
 
        if (text && text[0] && setval == camel_url_set_user) {
1433
 
                dropdown = service->authtype;
1434
 
                if (dropdown) {
1435
 
                        id = gtk_combo_box_get_active (dropdown);
1436
 
                        if (id != -1) {
1437
 
                                model = gtk_combo_box_get_model (dropdown);
1438
 
                                        if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) {
1439
 
                                                gtk_tree_model_get (model, &iter, 1, &authtype, -1);
1440
 
                                                if (authtype)
1441
 
                                                        camel_url_set_authmech (url, authtype->authproto);
1442
 
                                        }
1443
 
                        }
1444
 
                }
1445
 
        }
1446
 
 
1447
 
        emae_uri_changed (service, url);
1448
 
        camel_url_free (url);
1449
 
        g_free (text);
1450
 
}
1451
 
 
1452
 
static void
1453
 
emae_service_url_path_changed (EMAccountEditorService *service, void (*setval)(CamelURL *, const gchar *), GtkWidget *widget)
1454
 
{
1455
 
        GtkComboBox *dropdown;
1456
 
        gint id;
1457
 
        GtkTreeModel *model;
1458
 
        GtkTreeIter iter;
1459
 
        CamelServiceAuthType *authtype;
1460
 
 
1461
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
1462
 
        const gchar *text = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
1463
 
 
1464
 
        setval (url, (text && text[0])?text:NULL);
1465
 
 
1466
 
        if (text && text[0] && setval == camel_url_set_user) {
1467
 
                dropdown = service->authtype;
1468
 
                if (dropdown) {
1469
 
                        id = gtk_combo_box_get_active (dropdown);
1470
 
                        if (id != -1) {
1471
 
                                model = gtk_combo_box_get_model (dropdown);
1472
 
                                        if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) {
1473
 
                                                gtk_tree_model_get (model, &iter, 1, &authtype, -1);
1474
 
                                                if (authtype)
1475
 
                                                        camel_url_set_authmech (url, authtype->authproto);
1476
 
                                        }
1477
 
                        }
1478
 
                }
1479
 
        }
1480
 
 
1481
 
        emae_uri_changed (service, url);
1482
 
        camel_url_free (url);
1483
 
}
1484
 
 
1485
 
static void
1486
 
emae_hostname_changed (GtkEntry *entry, EMAccountEditorService *service)
1487
 
{
1488
 
        emae_service_url_changed (service, emae_url_set_host, GTK_WIDGET (entry));
1489
 
}
1490
 
 
1491
 
static void
1492
 
emae_port_changed (EPortEntry *pentry, EMAccountEditorService *service)
1493
 
{
1494
 
        emae_service_url_changed (service, emae_url_set_port, GTK_WIDGET (pentry));
1495
 
}
1496
 
 
1497
 
static void
1498
 
emae_username_changed (GtkEntry *entry, EMAccountEditorService *service)
1499
 
{
1500
 
        emae_service_url_changed (service, camel_url_set_user, GTK_WIDGET (entry));
1501
 
}
1502
 
 
1503
 
static void
1504
 
emae_path_changed (GtkWidget *widget, EMAccountEditorService *service)
1505
 
{
1506
 
        emae_service_url_path_changed (service, camel_url_set_path, widget);
1507
 
}
1508
 
 
1509
 
static gint
1510
 
emae_ssl_update (EMAccountEditorService *service, CamelURL *url)
1511
 
{
1512
 
        gint id = gtk_combo_box_get_active (service->use_ssl);
1513
 
        GtkTreeModel *model;
1514
 
        GtkTreeIter iter;
1515
 
        gchar *ssl;
1516
 
 
1517
 
        if (id == -1)
1518
 
                return 0;
1519
 
 
1520
 
        model = gtk_combo_box_get_model (service->use_ssl);
1521
 
        if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) {
1522
 
                gtk_tree_model_get (model, &iter, 1, &ssl, -1);
1523
 
                if (!strcmp (ssl, "none"))
1524
 
                        ssl = NULL;
1525
 
 
1526
 
                e_port_entry_security_port_changed (service->port, ssl);
1527
 
 
1528
 
                camel_url_set_param (url, "use_ssl", ssl);
1529
 
                camel_url_set_port (url, e_port_entry_get_port (service->port));
1530
 
                return 1;
1531
 
        }
1532
 
 
1533
 
        return 0;
1534
 
}
1535
 
 
1536
 
static void
1537
 
emae_ssl_changed (GtkComboBox *dropdown, EMAccountEditorService *service)
1538
 
{
1539
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
1540
 
 
1541
 
        if (emae_ssl_update (service, url))
1542
 
                emae_uri_changed (service, url);
1543
 
        camel_url_free (url);
1544
 
}
1545
 
 
1546
 
static void
1547
 
emae_service_provider_changed (EMAccountEditorService *service)
1548
 
{
1549
 
        EAccount *account;
1550
 
        gint i, j;
1551
 
        gint old_port;
1552
 
        void (*show)(GtkWidget *);
1553
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
1554
 
 
1555
 
        account = em_account_editor_get_modified_account (service->emae);
1556
 
 
1557
 
        if (service->provider) {
1558
 
                gint enable;
1559
 
                GtkWidget *dwidget = NULL;
1560
 
 
1561
 
                set_provider_defaults_on_url (service->emae, service->provider, url);
1562
 
 
1563
 
                camel_url_set_protocol (url, service->provider->protocol);
1564
 
                gtk_label_set_text (service->description, service->provider->description);
1565
 
                gtk_widget_show (service->frame);
1566
 
 
1567
 
                enable = e_account_writable_option (account, service->provider->protocol, "auth");
1568
 
                gtk_widget_set_sensitive ((GtkWidget *) service->authtype, enable);
1569
 
                gtk_widget_set_sensitive ((GtkWidget *) service->check_supported, enable);
1570
 
 
1571
 
                enable = e_account_writable_option (account, service->provider->protocol, "use_ssl");
1572
 
                gtk_widget_set_sensitive ((GtkWidget *) service->use_ssl, enable);
1573
 
 
1574
 
                enable = e_account_writable (account, emae_service_info[service->type].save_passwd_key);
1575
 
                gtk_widget_set_sensitive ((GtkWidget *) service->remember, enable);
1576
 
 
1577
 
                if (service->port && service->provider->port_entries)
1578
 
                        e_port_entry_set_camel_entries (service->port, service->provider->port_entries);
1579
 
 
1580
 
                for (i=0;emae_service_info[service->type].host_info[i].flag;i++) {
1581
 
                        GtkWidget *w;
1582
 
                        gint hide;
1583
 
                        struct _provider_host_info *info = &emae_service_info[service->type].host_info[i];
1584
 
 
1585
 
                        enable = CAMEL_PROVIDER_ALLOWS (service->provider, info->flag);
1586
 
                        hide = CAMEL_PROVIDER_HIDDEN (service->provider, info->flag);
1587
 
                        show = (enable && !hide)?gtk_widget_show:gtk_widget_hide;
1588
 
 
1589
 
                        for (j=0; j < G_N_ELEMENTS (info->widgets); j++) {
1590
 
                                if (info->widgets[j] && (w = G_STRUCT_MEMBER (GtkWidget *, service, info->widgets[j]))) {
1591
 
                                        show (w);
1592
 
                                        if (j == 0) {
1593
 
                                                if (dwidget == NULL && enable)
1594
 
                                                        dwidget = w;
1595
 
 
1596
 
                                                if (info->setval && !hide) {
1597
 
                                                        if (GTK_IS_ENTRY (w))
1598
 
                                                                info->setval (url, enable?gtk_entry_get_text ((GtkEntry *) w):NULL);
1599
 
                                                        else if (E_IS_PORT_ENTRY (w))
1600
 
                                                                info->setval (url, enable?g_strdup_printf("%i",
1601
 
                                                                                        e_port_entry_get_port (E_PORT_ENTRY (w))):NULL);
1602
 
                                                }
1603
 
                                        }
1604
 
                                }
1605
 
                        }
1606
 
                }
1607
 
 
1608
 
                if (dwidget)
1609
 
                        gtk_widget_grab_focus (dwidget);
1610
 
 
1611
 
                if (CAMEL_PROVIDER_ALLOWS (service->provider, CAMEL_URL_PART_AUTH)) {
1612
 
                        GList *ll;
1613
 
 
1614
 
                        /* try to keep the authmech from the current url, or clear it */
1615
 
                        if (url->authmech) {
1616
 
                                if (service->provider->authtypes) {
1617
 
                                        for (ll = service->provider->authtypes;ll;ll = g_list_next (ll))
1618
 
                                                if (!strcmp (url->authmech, ((CamelServiceAuthType *) ll->data)->authproto))
1619
 
                                                        break;
1620
 
                                        if (ll == NULL)
1621
 
                                                camel_url_set_authmech (url, NULL);
1622
 
                                } else {
1623
 
                                        camel_url_set_authmech (url, NULL);
1624
 
                                }
1625
 
                        }
1626
 
 
1627
 
                        emae_refresh_authtype (service->emae, service);
1628
 
                        if (service->needs_auth && !CAMEL_PROVIDER_NEEDS (service->provider, CAMEL_URL_PART_AUTH))
1629
 
                                gtk_widget_show ((GtkWidget *) service->needs_auth);
1630
 
                } else {
1631
 
                        if (service->needs_auth)
1632
 
                                gtk_widget_hide ((GtkWidget *) service->needs_auth);
1633
 
                }
1634
 
#ifdef HAVE_SSL
1635
 
                old_port = url->port;
1636
 
                gtk_widget_hide (service->no_ssl);
1637
 
                if (service->provider->flags & CAMEL_PROVIDER_SUPPORTS_SSL) {
1638
 
                        emae_ssl_update (service, url);
1639
 
                        show = gtk_widget_show;
1640
 
                } else {
1641
 
                        camel_url_set_param (url, "use_ssl", NULL);
1642
 
                        show = gtk_widget_hide;
1643
 
                }
1644
 
                show (service->ssl_frame);
1645
 
                show (service->ssl_hbox);
1646
 
#else
1647
 
                gtk_widget_hide (service->ssl_hbox);
1648
 
                gtk_widget_show (service->no_ssl);
1649
 
                camel_url_set_param (url, "use_ssl", NULL);
1650
 
#endif
1651
 
 
1652
 
                /* This must be done AFTER use_ssl is set; changing use_ssl overwrites
1653
 
                   the old port, which could be SSL port, but also could be some special
1654
 
                   port and we would otherwise lost it */
1655
 
                if (url->port && service->provider->port_entries)
1656
 
                        e_port_entry_set_port (service->port, old_port);
1657
 
 
1658
 
        } else {
1659
 
                camel_url_set_protocol (url, NULL);
1660
 
                gtk_label_set_text (service->description, "");
1661
 
                gtk_widget_hide (service->frame);
1662
 
                gtk_widget_hide (service->auth_frame);
1663
 
                gtk_widget_hide (service->ssl_frame);
1664
 
        }
1665
 
 
1666
 
        /* FIXME: linked services? */
1667
 
        /* FIXME: permissions setup */
1668
 
 
1669
 
        emae_uri_changed (service, url);
1670
 
        camel_url_free (url);
1671
 
}
1672
 
 
1673
 
static void
1674
 
emae_provider_changed (GtkComboBox *dropdown, EMAccountEditorService *service)
1675
 
{
1676
 
        gint id = gtk_combo_box_get_active (dropdown);
1677
 
        GtkTreeModel *model;
1678
 
        GtkTreeIter iter;
1679
 
 
1680
 
        if (id == -1)
1681
 
                return;
1682
 
 
1683
 
        model = gtk_combo_box_get_model (dropdown);
1684
 
        if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, id))
1685
 
                return;
1686
 
 
1687
 
        gtk_tree_model_get (model, &iter, 1, &service->provider, -1);
1688
 
 
1689
 
        g_list_free (service->auth_types);
1690
 
        service->auth_types = NULL;
1691
 
 
1692
 
        emae_service_provider_changed (service);
1693
 
 
1694
 
        e_config_target_changed ((EConfig *) service->emae->priv->config, E_CONFIG_TARGET_CHANGED_REBUILD);
1695
 
}
1696
 
 
1697
 
static void
1698
 
emae_refresh_providers (EMAccountEditor *emae, EMAccountEditorService *service)
1699
 
{
1700
 
        EAccount *account;
1701
 
        GtkListStore *store;
1702
 
        GtkTreeIter iter;
1703
 
        GList *l;
1704
 
        GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
1705
 
        GtkComboBox *dropdown;
1706
 
        gint active = 0, i;
1707
 
        struct _service_info *info = &emae_service_info[service->type];
1708
 
        const gchar *uri;
1709
 
        gchar *current = NULL;
1710
 
        const gchar *tmp;
1711
 
        CamelURL *url;
1712
 
 
1713
 
        account = em_account_editor_get_modified_account (emae);
1714
 
        uri = e_account_get_string (account, info->account_uri_key);
1715
 
 
1716
 
        dropdown = service->providers;
1717
 
        gtk_widget_show ((GtkWidget *) dropdown);
1718
 
 
1719
 
        if (uri) {
1720
 
                const gchar *colon = strchr (uri, ':');
1721
 
                gint len;
1722
 
 
1723
 
                if (colon) {
1724
 
                        len = colon-uri;
1725
 
                        current = g_alloca (len+1);
1726
 
                        memcpy (current, uri, len);
1727
 
                        current[len] = 0;
1728
 
                }
1729
 
        } else {
1730
 
                /* Promote the newer IMAP provider over the older one. */
1731
 
                current = (gchar *) "imapx";
1732
 
        }
1733
 
 
1734
 
        store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
1735
 
 
1736
 
        i = 0;
1737
 
 
1738
 
        /* We just special case each type here, its just easier */
1739
 
        if (service->type == CAMEL_PROVIDER_STORE) {
1740
 
                gtk_list_store_append (store, &iter);
1741
 
                /* Translators: "None" for receiving account type, beside of IMAP, POP3, ... */
1742
 
                gtk_list_store_set (store, &iter, 0, C_("mail-receiving", "None"), 1, NULL, -1);
1743
 
                i++;
1744
 
        }
1745
 
 
1746
 
        for (l=emae->priv->providers; l; l=l->next) {
1747
 
                CamelProvider *provider = l->data;
1748
 
 
1749
 
                if (!((strcmp (provider->domain, "mail") == 0
1750
 
                       || strcmp (provider->domain, "news") == 0)
1751
 
                      && provider->object_types[service->type]
1752
 
                      && (service->type != CAMEL_PROVIDER_STORE || (provider->flags & CAMEL_PROVIDER_IS_SOURCE) != 0))
1753
 
                    /* hardcode not showing providers who's transport is done in the store */
1754
 
                    || (service->type == CAMEL_PROVIDER_TRANSPORT
1755
 
                        && CAMEL_PROVIDER_IS_STORE_AND_TRANSPORT (provider)))
1756
 
                        continue;
1757
 
 
1758
 
                gtk_list_store_append (store, &iter);
1759
 
                gtk_list_store_set (store, &iter, 0, provider->name, 1, provider, -1);
1760
 
 
1761
 
                /* find the displayed and set default */
1762
 
                if (i == 0 || (current && strcmp (provider->protocol, current) == 0)) {
1763
 
                        CamelURL *url;
1764
 
 
1765
 
                        service->provider = provider;
1766
 
                        active = i;
1767
 
 
1768
 
                        url = emae_account_url (emae, info->account_uri_key);
1769
 
                        if (current == NULL) {
1770
 
                                /* we need to set this value on the uri too */
1771
 
                                camel_url_set_protocol (url, provider->protocol);
1772
 
                        }
1773
 
 
1774
 
                        set_provider_defaults_on_url (emae, provider, url);
1775
 
                        emae_uri_changed (service, url);
1776
 
                        uri = e_account_get_string (account, info->account_uri_key);
1777
 
                        camel_url_free (url);
1778
 
                }
1779
 
                i++;
1780
 
        }
1781
 
 
1782
 
        gtk_cell_layout_clear ((GtkCellLayout *) dropdown);
1783
 
        gtk_combo_box_set_model (dropdown, (GtkTreeModel *) store);
1784
 
        gtk_cell_layout_pack_start ((GtkCellLayout *) dropdown, cell, TRUE);
1785
 
        gtk_cell_layout_set_attributes ((GtkCellLayout *)dropdown, cell, "text", 0, NULL);
1786
 
 
1787
 
        g_signal_handlers_disconnect_by_func (dropdown, emae_provider_changed, service);
1788
 
        gtk_combo_box_set_active (dropdown, -1);        /* needed for gtkcombo bug (?) */
1789
 
        gtk_combo_box_set_active (dropdown, active);
1790
 
        g_signal_connect (dropdown, "changed", G_CALLBACK(emae_provider_changed), service);
1791
 
 
1792
 
        if (!uri  || (url = camel_url_new (uri, NULL)) == NULL) {
1793
 
                return;
1794
 
        }
1795
 
 
1796
 
        tmp = camel_url_get_param (url, "use_ssl");
1797
 
        if (tmp == NULL)
1798
 
                tmp = "never";
1799
 
        for (i=0;i<G_N_ELEMENTS (ssl_options);i++) {
1800
 
                if (!strcmp (ssl_options[i].value, tmp)) {
1801
 
                        gtk_combo_box_set_active (service->use_ssl, i);
1802
 
                        break;
1803
 
                }
1804
 
        }
1805
 
 
1806
 
        camel_url_free (url);
1807
 
}
1808
 
 
1809
 
static void
1810
 
emae_authtype_changed (GtkComboBox *dropdown, EMAccountEditorService *service)
1811
 
{
1812
 
        EAccount *account;
1813
 
        gint id = gtk_combo_box_get_active (dropdown);
1814
 
        GtkTreeModel *model;
1815
 
        GtkTreeIter iter;
1816
 
        CamelURL *url;
1817
 
        gboolean sensitive = FALSE;
1818
 
 
1819
 
        if (id == -1)
1820
 
                return;
1821
 
 
1822
 
        account = em_account_editor_get_modified_account (service->emae);
1823
 
 
1824
 
        url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
1825
 
        model = gtk_combo_box_get_model (dropdown);
1826
 
        if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) {
1827
 
                CamelServiceAuthType *authtype;
1828
 
 
1829
 
                gtk_tree_model_get (model, &iter, 1, &authtype, -1);
1830
 
                if (authtype)
1831
 
                        camel_url_set_authmech (url, authtype->authproto);
1832
 
                else
1833
 
                        camel_url_set_authmech (url, NULL);
1834
 
                emae_uri_changed (service, url);
1835
 
 
1836
 
                sensitive =
1837
 
                        authtype != NULL &&
1838
 
                        authtype->need_password &&
1839
 
                        e_account_writable (account,
1840
 
                        emae_service_info[service->type].save_passwd_key);
1841
 
        }
1842
 
        camel_url_free (url);
1843
 
 
1844
 
        gtk_widget_set_sensitive ((GtkWidget *) service->remember, sensitive);
1845
 
}
1846
 
 
1847
 
static void
1848
 
emae_needs_auth (GtkToggleButton *toggle, EMAccountEditorService *service)
1849
 
{
1850
 
        gint need = gtk_toggle_button_get_active (toggle);
1851
 
 
1852
 
        gtk_widget_set_sensitive (service->auth_frame, need);
1853
 
 
1854
 
        if (need)
1855
 
                emae_authtype_changed (service->authtype, service);
1856
 
        else {
1857
 
                CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
1858
 
 
1859
 
                camel_url_set_authmech (url, NULL);
1860
 
                emae_uri_changed (service, url);
1861
 
                camel_url_free (url);
1862
 
        }
1863
 
}
1864
 
 
1865
 
static void emae_check_authtype (GtkWidget *w, EMAccountEditorService *service);
1866
 
 
1867
 
static void
1868
 
emae_refresh_authtype (EMAccountEditor *emae, EMAccountEditorService *service)
1869
 
{
1870
 
        EAccount *account;
1871
 
        GtkListStore *store;
1872
 
        GtkTreeIter iter;
1873
 
        GtkComboBox *dropdown;
1874
 
        gint active = 0;
1875
 
        gint i;
1876
 
        struct _service_info *info = &emae_service_info[service->type];
1877
 
        const gchar *uri;
1878
 
        GList *l, *ll;
1879
 
        CamelURL *url = NULL;
1880
 
 
1881
 
        account = em_account_editor_get_modified_account (emae);
1882
 
        uri = e_account_get_string (account, info->account_uri_key);
1883
 
 
1884
 
        dropdown = service->authtype;
1885
 
        gtk_widget_show ((GtkWidget *) dropdown);
1886
 
 
1887
 
        store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
1888
 
 
1889
 
        if (uri)
1890
 
                url = camel_url_new (uri, NULL);
1891
 
 
1892
 
        if (service->provider) {
1893
 
                for (i=0, l=service->provider->authtypes; l; l=l->next, i++) {
1894
 
                        CamelServiceAuthType *authtype = l->data;
1895
 
                        gint avail;
1896
 
 
1897
 
                        /* if we have some already shown */
1898
 
                        if (service->auth_types) {
1899
 
                                for (ll = service->auth_types;ll;ll = g_list_next (ll))
1900
 
                                        if (!strcmp (authtype->authproto, ((CamelServiceAuthType *) ll->data)->authproto))
1901
 
                                                break;
1902
 
                                avail = ll != NULL;
1903
 
                        } else {
1904
 
                                avail = TRUE;
1905
 
                        }
1906
 
 
1907
 
                        gtk_list_store_append (store, &iter);
1908
 
                        gtk_list_store_set (store, &iter, 0, authtype->name, 1, authtype, 2, !avail, -1);
1909
 
 
1910
 
                        if (url && url->authmech && !strcmp (url->authmech, authtype->authproto))
1911
 
                                active = i;
1912
 
                }
1913
 
        }
1914
 
 
1915
 
        gtk_combo_box_set_model (dropdown, (GtkTreeModel *) store);
1916
 
        gtk_combo_box_set_active (dropdown, -1);
1917
 
 
1918
 
        if (service->auth_changed_id == 0) {
1919
 
                GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
1920
 
 
1921
 
                gtk_cell_layout_pack_start ((GtkCellLayout *) dropdown, cell, TRUE);
1922
 
                gtk_cell_layout_set_attributes ((GtkCellLayout *)dropdown, cell, "text", 0, "strikethrough", 2, NULL);
1923
 
 
1924
 
                service->auth_changed_id = g_signal_connect (dropdown, "changed", G_CALLBACK(emae_authtype_changed), service);
1925
 
                g_signal_connect (service->check_supported, "clicked", G_CALLBACK(emae_check_authtype), service);
1926
 
        }
1927
 
 
1928
 
        gtk_combo_box_set_active (dropdown, active);
1929
 
 
1930
 
        if (url)
1931
 
                camel_url_free (url);
1932
 
}
1933
 
 
1934
 
static void
1935
 
emae_check_authtype_done (CamelService *camel_service,
1936
 
                          GAsyncResult *result,
1937
 
                          EMAccountEditorService *service)
1938
 
{
1939
 
        GtkWidget *editor;
1940
 
        GList *auth_types;
1941
 
        GError *error = NULL;
1942
 
 
1943
 
        auth_types = camel_service_query_auth_types_finish (
1944
 
                camel_service, result, &error);
1945
 
 
1946
 
        if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
1947
 
                g_warn_if_fail (auth_types == NULL);
1948
 
                g_error_free (error);
1949
 
 
1950
 
        } else if (error != NULL) {
1951
 
                g_warn_if_fail (auth_types == NULL);
1952
 
                g_warning ("%s", error->message);
1953
 
                g_error_free (error);
1954
 
 
1955
 
        } else {
1956
 
                g_list_free (service->auth_types);
1957
 
                service->auth_types = auth_types;
1958
 
                emae_refresh_authtype (service->emae, service);
1959
 
        }
1960
 
 
1961
 
        gtk_widget_destroy (service->check_dialog);
1962
 
        service->check_dialog = NULL;
1963
 
 
1964
 
        editor = E_CONFIG (service->emae->config)->window;
1965
 
 
1966
 
        if (editor != NULL)
1967
 
                gtk_widget_set_sensitive (editor, TRUE);
1968
 
 
1969
 
        g_object_unref (service->emae);
1970
 
}
1971
 
 
1972
 
static void
1973
 
emae_check_authtype_response (GtkDialog *dialog,
1974
 
                              gint button,
1975
 
                              GCancellable *cancellable)
1976
 
{
1977
 
        g_cancellable_cancel (cancellable);
1978
 
}
1979
 
 
1980
 
static void
1981
 
emae_check_authtype (GtkWidget *w,
1982
 
                     EMAccountEditorService *service)
1983
 
{
1984
 
        CamelService *camel_service;
1985
 
        EMailBackend *backend;
1986
 
        EMailSession *session;
1987
 
        EAccount *account;
1988
 
        GtkWidget *editor;
1989
 
        gpointer parent;
1990
 
        gchar *uid;
1991
 
 
1992
 
        account = em_account_editor_get_modified_account (service->emae);
1993
 
        editor = E_CONFIG (service->emae->config)->window;
1994
 
 
1995
 
        backend = em_account_editor_get_backend (service->emae);
1996
 
        session = e_mail_backend_get_session (backend);
1997
 
 
1998
 
        if (service->type == CAMEL_PROVIDER_TRANSPORT)
1999
 
                uid = g_strconcat (account->uid, "-transport", NULL);
2000
 
        else
2001
 
                uid = g_strdup (account->uid);
2002
 
 
2003
 
        camel_service = camel_session_get_service (
2004
 
                CAMEL_SESSION (session), uid);
2005
 
 
2006
 
        g_free (uid);
2007
 
 
2008
 
        g_return_if_fail (CAMEL_IS_SERVICE (camel_service));
2009
 
 
2010
 
        if (service->checking != NULL) {
2011
 
                g_cancellable_cancel (service->checking);
2012
 
                g_object_unref (service->checking);
2013
 
        }
2014
 
 
2015
 
        service->checking = g_cancellable_new ();
2016
 
 
2017
 
        if (editor != NULL)
2018
 
                parent = gtk_widget_get_toplevel (editor);
2019
 
        else
2020
 
                parent = gtk_widget_get_toplevel (w);
2021
 
 
2022
 
        service->check_dialog = e_alert_dialog_new_for_args (
2023
 
                parent, "mail:checking-service", NULL);
2024
 
 
2025
 
        g_object_ref (service->emae);
2026
 
 
2027
 
        camel_service_query_auth_types (
2028
 
                camel_service, G_PRIORITY_DEFAULT,
2029
 
                service->checking, (GAsyncReadyCallback)
2030
 
                emae_check_authtype_done, service);
2031
 
 
2032
 
        g_signal_connect (
2033
 
                service->check_dialog, "response",
2034
 
                G_CALLBACK (emae_check_authtype_response),
2035
 
                service->checking);
2036
 
 
2037
 
        gtk_widget_show (service->check_dialog);
2038
 
 
2039
 
        if (editor != NULL)
2040
 
                gtk_widget_set_sensitive (editor, FALSE);
2041
 
}
2042
 
 
2043
 
static void
2044
 
emae_setup_service (EMAccountEditor *emae, EMAccountEditorService *service, GtkBuilder *builder)
2045
 
{
2046
 
        EAccount *account;
2047
 
        struct _service_info *info = &emae_service_info[service->type];
2048
 
        CamelURL *url = emae_account_url (emae, info->account_uri_key);
2049
 
        const gchar *uri;
2050
 
        const gchar *tmp;
2051
 
        gint i;
2052
 
 
2053
 
        account = em_account_editor_get_modified_account (emae);
2054
 
        uri = e_account_get_string (account, info->account_uri_key);
2055
 
 
2056
 
        service->provider = uri ? camel_provider_get (uri, NULL) : NULL;
2057
 
 
2058
 
        /* Extract all widgets we need from the builder file. */
2059
 
 
2060
 
        service->frame = e_builder_get_widget (builder, info->frame);
2061
 
        service->container = e_builder_get_widget (builder, info->container);
2062
 
        service->description = GTK_LABEL (e_builder_get_widget (builder, info->description));
2063
 
        service->hostname = GTK_ENTRY (e_builder_get_widget (builder, info->hostname));
2064
 
        service->hostlabel = (GtkLabel *) e_builder_get_widget (builder, info->hostlabel);
2065
 
        service->port = E_PORT_ENTRY (e_builder_get_widget (builder, info->port));
2066
 
        service->portlabel = (GtkLabel *) e_builder_get_widget (builder, info->portlabel);
2067
 
        service->username = GTK_ENTRY (e_builder_get_widget (builder, info->username));
2068
 
        service->userlabel = (GtkLabel *) e_builder_get_widget (builder, info->userlabel);
2069
 
        if (info->pathentry) {
2070
 
                service->pathlabel = (GtkLabel *) e_builder_get_widget (builder, info->pathlabel);
2071
 
                service->pathentry = e_builder_get_widget (builder, info->pathentry);
2072
 
        }
2073
 
 
2074
 
        service->ssl_frame = e_builder_get_widget (builder, info->security_frame);
2075
 
        gtk_widget_hide (service->ssl_frame);
2076
 
        service->ssl_hbox = e_builder_get_widget (builder, info->ssl_hbox);
2077
 
        service->use_ssl = (GtkComboBox *) e_builder_get_widget (builder, info->use_ssl);
2078
 
        service->no_ssl = e_builder_get_widget (builder, info->ssl_disabled);
2079
 
 
2080
 
        service->auth_frame = e_builder_get_widget (builder, info->auth_frame);
2081
 
        service->check_supported = (GtkButton *) e_builder_get_widget (builder, info->authtype_check);
2082
 
        service->authtype = (GtkComboBox *) e_builder_get_widget (builder, info->authtype);
2083
 
        service->providers = (GtkComboBox *) e_builder_get_widget (builder, info->type_dropdown);
2084
 
 
2085
 
        service->remember = emae_account_toggle (emae, info->remember_password, info->save_passwd_key, builder);
2086
 
 
2087
 
        if (info->needs_auth)
2088
 
                service->needs_auth = (GtkToggleButton *) e_builder_get_widget (builder, info->needs_auth);
2089
 
        else
2090
 
                service->needs_auth = NULL;
2091
 
 
2092
 
        service->auth_changed_id = 0;
2093
 
 
2094
 
        /* Do this first.  Otherwise subsequent changes get clobbered. */
2095
 
        emae_service_provider_changed (service);
2096
 
 
2097
 
        g_signal_connect (service->hostname, "changed", G_CALLBACK (emae_hostname_changed), service);
2098
 
        g_signal_connect (service->port, "changed", G_CALLBACK (emae_port_changed), service);
2099
 
        g_signal_connect (service->username, "changed", G_CALLBACK (emae_username_changed), service);
2100
 
        if (service->pathentry)
2101
 
                g_signal_connect (GTK_FILE_CHOOSER (service->pathentry), "selection-changed", G_CALLBACK (emae_path_changed), service);
2102
 
 
2103
 
        g_signal_connect (service->use_ssl, "changed", G_CALLBACK(emae_ssl_changed), service);
2104
 
 
2105
 
        /* configure ui for current settings */
2106
 
        if (url->host) {
2107
 
                gtk_entry_set_text (service->hostname, url->host);
2108
 
        }
2109
 
 
2110
 
        if (url->user && *url->user) {
2111
 
                gtk_entry_set_text (service->username, url->user);
2112
 
        }
2113
 
 
2114
 
        if (service->pathentry) {
2115
 
                GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
2116
 
 
2117
 
                if (service->provider && (service->provider->url_flags & CAMEL_URL_NEED_PATH_DIR) == 0)
2118
 
                        action = GTK_FILE_CHOOSER_ACTION_OPEN;
2119
 
 
2120
 
                if (action != gtk_file_chooser_get_action (GTK_FILE_CHOOSER (service->pathentry)))
2121
 
                        gtk_file_chooser_set_action (GTK_FILE_CHOOSER (service->pathentry), action);
2122
 
 
2123
 
                if (url->path)
2124
 
                        gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (service->pathentry), url->path);
2125
 
        }
2126
 
 
2127
 
        tmp = camel_url_get_param (url, "use_ssl");
2128
 
        if (tmp == NULL)
2129
 
                tmp = "never";
2130
 
 
2131
 
        for (i=0;i<G_N_ELEMENTS (ssl_options);i++) {
2132
 
                if (!strcmp (ssl_options[i].value, tmp)) {
2133
 
                        gtk_combo_box_set_active (service->use_ssl, i);
2134
 
                        break;
2135
 
                }
2136
 
        }
2137
 
 
2138
 
        /* Set the port after SSL is set, because it would overwrite the
2139
 
           port value (through emae_ssl_changed signal) */
2140
 
        if (url->port && service->provider->port_entries) {
2141
 
                e_port_entry_set_port (service->port, url->port);
2142
 
        }
2143
 
 
2144
 
        /* old authtype will be destroyed when we exit */
2145
 
        emae_refresh_providers (emae, service);
2146
 
        emae_refresh_authtype (emae, service);
2147
 
 
2148
 
        if (service->needs_auth != NULL) {
2149
 
                gtk_toggle_button_set_active (service->needs_auth, url->authmech != NULL);
2150
 
                g_signal_connect (service->needs_auth, "toggled", G_CALLBACK(emae_needs_auth), service);
2151
 
                emae_needs_auth (service->needs_auth, service);
2152
 
        }
2153
 
 
2154
 
        if (!e_account_writable (account, info->account_uri_key))
2155
 
                gtk_widget_set_sensitive (service->container, FALSE);
2156
 
        else
2157
 
                gtk_widget_set_sensitive (service->container, TRUE);
2158
 
 
2159
 
        camel_url_free (url);
2160
 
}
2161
 
 
2162
 
static GtkWidget *
2163
 
emae_create_basic_assistant_page (EMAccountEditor *emae,
2164
 
                                  GtkAssistant *assistant,
2165
 
                                  const gchar *page_id,
2166
 
                                  gint position)
2167
 
{
2168
 
        const gchar *title = NULL, *label = NULL;
2169
 
        GtkAssistantPageType page_type = GTK_ASSISTANT_PAGE_CONTENT;
2170
 
        GtkWidget *vbox, *lbl;
2171
 
        gboolean fill_space = FALSE;
2172
 
 
2173
 
        g_return_val_if_fail (page_id != NULL, NULL);
2174
 
 
2175
 
        if (g_ascii_strcasecmp (page_id, "start_page") == 0) {
2176
 
                page_type = GTK_ASSISTANT_PAGE_INTRO;
2177
 
                fill_space = TRUE;
2178
 
                title = _("Mail Configuration");
2179
 
                label = _("Welcome to the Evolution Mail Configuration Assistant.\n\nClick \"Forward\" to begin.");
2180
 
        } else if (g_ascii_strcasecmp (page_id, "identity_page") == 0) {
2181
 
                title = _("Identity");
2182
 
                label = _("Please enter your name and email address below. The \"optional\" fields below do not need to be filled in, unless you wish to include this information in email you send.");
2183
 
        } else if (g_ascii_strcasecmp (page_id, "source_page") == 0) {
2184
 
                title = _("Receiving Email");
2185
 
                label = _("Please configure the following account settings.");
2186
 
        } else if (g_ascii_strcasecmp (page_id, "transport_page") == 0) {
2187
 
                title = _("Sending Email");
2188
 
                label = _("Please enter information about the way you will send mail. If you are not sure, ask your system administrator or Internet Service Provider.");
2189
 
        } else if (g_ascii_strcasecmp (page_id, "management_page") == 0) {
2190
 
                title = _("Account Information");
2191
 
                label = _("Please enter a descriptive name for this account below.\nThis name will be used for display purposes only.");
2192
 
        } else if (g_ascii_strcasecmp (page_id, "finish_page") == 0) {
2193
 
                page_type = GTK_ASSISTANT_PAGE_CONFIRM;
2194
 
                fill_space = TRUE;
2195
 
                title = _("Done");
2196
 
                label = _("Congratulations, your mail configuration is complete.\n\nYou are now ready to send and receive email using Evolution.\n\nClick \"Apply\" to save your settings.");
2197
 
        } else {
2198
 
                g_return_val_if_reached (NULL);
2199
 
        }
2200
 
 
2201
 
        vbox = gtk_vbox_new (FALSE, 12);
2202
 
        gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
2203
 
        gtk_widget_show (vbox);
2204
 
 
2205
 
        lbl = gtk_label_new (label);
2206
 
        gtk_label_set_line_wrap (GTK_LABEL (lbl), TRUE);
2207
 
        gtk_misc_set_alignment (GTK_MISC (lbl), 0.0, 0.5);
2208
 
        gtk_box_pack_start (GTK_BOX (vbox), lbl, fill_space, fill_space, 0);
2209
 
        gtk_widget_show (lbl);
2210
 
 
2211
 
        if (g_ascii_strcasecmp (page_id, "start_page") == 0)
2212
 
                g_hash_table_insert (emae->priv->widgets, (gchar *)"start_page_label", lbl);
2213
 
 
2214
 
        gtk_assistant_insert_page (assistant, vbox, position);
2215
 
        gtk_assistant_set_page_title (assistant, vbox, title);
2216
 
        gtk_assistant_set_page_type (assistant, vbox, page_type);
2217
 
 
2218
 
        return vbox;
2219
 
}
2220
 
 
2221
 
/* do not re-order these, the order is used by various code to look up emae->priv->identity_entries[] */
2222
 
static struct {
2223
 
        const gchar *name;
2224
 
        gint item;
2225
 
} emae_identity_entries[] = {
2226
 
        { "management_name", E_ACCOUNT_NAME },
2227
 
        { "identity_full_name", E_ACCOUNT_ID_NAME },
2228
 
        { "identity_address", E_ACCOUNT_ID_ADDRESS },
2229
 
        { "identity_reply_to", E_ACCOUNT_ID_REPLY_TO },
2230
 
        { "identity_organization", E_ACCOUNT_ID_ORGANIZATION },
2231
 
};
2232
 
 
2233
 
static void
2234
 
emae_queue_widgets (EMAccountEditor *emae, GtkBuilder *builder, const gchar *first, ...)
2235
 
{
2236
 
        va_list ap;
2237
 
 
2238
 
        va_start (ap, first);
2239
 
        while (first) {
2240
 
                g_hash_table_insert (emae->priv->widgets, (gchar *) first, e_builder_get_widget (builder, first));
2241
 
                first = va_arg (ap, const gchar *);
2242
 
        }
2243
 
        va_end (ap);
2244
 
}
2245
 
 
2246
 
static GtkWidget *
2247
 
emae_identity_page (EConfig *ec,
2248
 
                    EConfigItem *item,
2249
 
                    GtkWidget *parent,
2250
 
                    GtkWidget *old,
2251
 
                    gint position,
2252
 
                    gpointer data)
2253
 
{
2254
 
        EMAccountEditor *emae = data;
2255
 
        EMAccountEditorPrivate *priv = emae->priv;
2256
 
        EAccount *account;
2257
 
        gint i;
2258
 
        GtkWidget *w;
2259
 
        GtkBuilder *builder;
2260
 
 
2261
 
        if (old && emae->type == EMAE_PAGES)
2262
 
          return old;
2263
 
 
2264
 
        account = em_account_editor_get_modified_account (emae);
2265
 
 
2266
 
        /* Make sure our custom widget classes are registered with
2267
 
         * GType before we load the GtkBuilder definition file. */
2268
 
        EM_TYPE_FOLDER_SELECTION_BUTTON;
2269
 
 
2270
 
        builder = gtk_builder_new ();
2271
 
        e_load_ui_builder_definition (builder, "mail-config.ui");
2272
 
 
2273
 
        /* Management & Identity fields, in the assistant the management frame is relocated to the last page later on */
2274
 
        for (i=0;i<G_N_ELEMENTS (emae_identity_entries);i++)
2275
 
                priv->identity_entries[i] = emae_account_entry (emae, emae_identity_entries[i].name, emae_identity_entries[i].item, builder);
2276
 
 
2277
 
        priv->management_frame = e_builder_get_widget (builder, "management-section");
2278
 
 
2279
 
        priv->default_account = GTK_TOGGLE_BUTTON (e_builder_get_widget (builder, "management_default"));
2280
 
        if (!e_get_default_account ()
2281
 
                || (account == e_get_default_account ())
2282
 
                || (GPOINTER_TO_INT(g_object_get_data (G_OBJECT (account), "default_flagged"))) )
2283
 
                        gtk_toggle_button_set_active (priv->default_account, TRUE);
2284
 
 
2285
 
        if (emae->do_signature) {
2286
 
                emae_setup_signatures (emae, builder);
2287
 
        } else {
2288
 
                /* TODO: this could/should probably be neater */
2289
 
                gtk_widget_hide (e_builder_get_widget (builder, "sigLabel"));
2290
 
#if 0
2291
 
                gtk_widget_hide (e_builder_get_widget (builder, "sigOption"));
2292
 
#endif
2293
 
                gtk_widget_hide (e_builder_get_widget (builder, "signature_dropdown"));
2294
 
                gtk_widget_hide (e_builder_get_widget (builder, "sigAddNew"));
2295
 
        }
2296
 
 
2297
 
        w = e_builder_get_widget (builder, item->label);
2298
 
        if (emae->type == EMAE_PAGES) {
2299
 
                gtk_box_pack_start ((GtkBox *) emae->pages[0], w, TRUE, TRUE, 0);
2300
 
        } else if (((EConfig *) priv->config)->type == E_CONFIG_ASSISTANT) {
2301
 
                GtkWidget *page;
2302
 
 
2303
 
                page = emae_create_basic_assistant_page (
2304
 
                        emae, GTK_ASSISTANT (parent),
2305
 
                        "identity_page", position);
2306
 
 
2307
 
                gtk_box_pack_start (GTK_BOX (page), w, TRUE, TRUE, 0);
2308
 
 
2309
 
                w = page;
2310
 
        } else {
2311
 
                gtk_notebook_insert_page (
2312
 
                        GTK_NOTEBOOK (parent), w,
2313
 
                        gtk_label_new (_("Identity")),
2314
 
                        position);
2315
 
                gtk_container_child_set (
2316
 
                        GTK_CONTAINER (parent), w,
2317
 
                        "tab-fill", FALSE, "tab-expand", FALSE, NULL);
2318
 
        }
2319
 
 
2320
 
        emae_queue_widgets (
2321
 
                emae, builder,
2322
 
                "account_vbox",
2323
 
                "identity-required-table",
2324
 
                "identity-optional-table",
2325
 
                "identity-optional-section",
2326
 
                "identity_address",
2327
 
                NULL);
2328
 
 
2329
 
        g_object_unref (builder);
2330
 
 
2331
 
        return w;
2332
 
}
2333
 
 
2334
 
static GtkWidget *
2335
 
emae_receive_page (EConfig *ec,
2336
 
                   EConfigItem *item,
2337
 
                   GtkWidget *parent,
2338
 
                   GtkWidget *old,
2339
 
                   gint position,
2340
 
                   gpointer data)
2341
 
{
2342
 
        EMAccountEditor *emae = data;
2343
 
        EMAccountEditorPrivate *priv = emae->priv;
2344
 
        GtkWidget *w;
2345
 
        GtkBuilder *builder;
2346
 
 
2347
 
        /*if (old)
2348
 
          return old;*/
2349
 
 
2350
 
        builder = gtk_builder_new ();
2351
 
        e_load_ui_builder_definition (builder, "mail-config.ui");
2352
 
 
2353
 
        priv->source.type = CAMEL_PROVIDER_STORE;
2354
 
        emae_setup_service (emae, &priv->source, builder);
2355
 
 
2356
 
        w = e_builder_get_widget (builder, item->label);
2357
 
        if (emae->type == EMAE_PAGES) {
2358
 
                gtk_box_pack_start ((GtkBox *) emae->pages[1], w, TRUE, TRUE, 0);
2359
 
        } else if (((EConfig *) priv->config)->type == E_CONFIG_ASSISTANT) {
2360
 
                GtkWidget *page;
2361
 
 
2362
 
                page = emae_create_basic_assistant_page (
2363
 
                        emae, GTK_ASSISTANT (parent),
2364
 
                        "source_page", position);
2365
 
 
2366
 
                gtk_box_pack_start (GTK_BOX (page), w, TRUE, TRUE, 0);
2367
 
 
2368
 
                w = page;
2369
 
        } else {
2370
 
                gtk_notebook_insert_page (
2371
 
                        GTK_NOTEBOOK (parent), w,
2372
 
                        gtk_label_new (_("Receiving Email")),
2373
 
                        position);
2374
 
                gtk_container_child_set (
2375
 
                        GTK_CONTAINER (parent), w,
2376
 
                        "tab-fill", FALSE, "tab-expand", FALSE, NULL);
2377
 
        }
2378
 
 
2379
 
        emae_queue_widgets (
2380
 
                emae, builder,
2381
 
                "source-type-table",
2382
 
                "source-config-table",
2383
 
                "source-security-vbox",
2384
 
                "source-auth-vbox",
2385
 
                NULL);
2386
 
 
2387
 
        g_object_unref (builder);
2388
 
 
2389
 
        return w;
2390
 
}
2391
 
 
2392
 
static void
2393
 
emae_option_toggle_changed (GtkToggleButton *toggle, EMAccountEditorService *service)
2394
 
{
2395
 
        const gchar *name = g_object_get_data ((GObject *)toggle, "option-name");
2396
 
        GSList *depl = g_object_get_data ((GObject *)toggle, "dependent-list");
2397
 
        gint active = gtk_toggle_button_get_active (toggle);
2398
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2399
 
 
2400
 
        for (;depl;depl = g_slist_next (depl))
2401
 
                gtk_widget_set_sensitive ((GtkWidget *) depl->data, active);
2402
 
 
2403
 
        camel_url_set_param (url, name, active?"":NULL);
2404
 
        emae_uri_changed (service, url);
2405
 
        camel_url_free (url);
2406
 
}
2407
 
 
2408
 
static GtkWidget *
2409
 
emae_option_toggle (EMAccountEditorService *service, CamelURL *url, const gchar *text, const gchar *name)
2410
 
{
2411
 
        GtkWidget *w;
2412
 
 
2413
 
        w = gtk_check_button_new_with_mnemonic (text);
2414
 
        g_object_set_data ((GObject *)w, "option-name", (gpointer)name);
2415
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), camel_url_get_param (url, name) != NULL);
2416
 
        g_signal_connect (w, "toggled", G_CALLBACK(emae_option_toggle_changed), service);
2417
 
        gtk_widget_show (w);
2418
 
 
2419
 
        return w;
2420
 
}
2421
 
 
2422
 
static void
2423
 
emae_option_entry_changed (GtkEntry *entry, EMAccountEditorService *service)
2424
 
{
2425
 
        const gchar *name = g_object_get_data ((GObject *)entry, "option-name");
2426
 
        const gchar *text = gtk_entry_get_text (entry);
2427
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2428
 
 
2429
 
        camel_url_set_param (url, name, text && text[0]?text:NULL);
2430
 
        emae_uri_changed (service, url);
2431
 
        camel_url_free (url);
2432
 
}
2433
 
 
2434
 
static GtkWidget *
2435
 
emae_option_entry (EMAccountEditorService *service, CamelURL *url, const gchar *name, GtkWidget *label_for_mnemonic)
2436
 
{
2437
 
        GtkWidget *w;
2438
 
        const gchar *val = camel_url_get_param (url, name);
2439
 
 
2440
 
        if (val == NULL)
2441
 
                val = "";
2442
 
 
2443
 
        w = g_object_new (gtk_entry_get_type (),
2444
 
                         "text", val,
2445
 
                         NULL);
2446
 
        gtk_label_set_mnemonic_widget ((GtkLabel*) label_for_mnemonic, w);
2447
 
        g_object_set_data ((GObject *)w, "option-name", (gpointer)name);
2448
 
        g_signal_connect (w, "changed", G_CALLBACK(emae_option_entry_changed), service);
2449
 
        gtk_widget_show (w);
2450
 
 
2451
 
        return w;
2452
 
}
2453
 
 
2454
 
static void
2455
 
emae_option_checkspin_changed (GtkSpinButton *spin, EMAccountEditorService *service)
2456
 
{
2457
 
        const gchar *name = g_object_get_data ((GObject *)spin, "option-name");
2458
 
        gchar value[16];
2459
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2460
 
 
2461
 
        sprintf (value, "%d", gtk_spin_button_get_value_as_int (spin));
2462
 
        camel_url_set_param (url, name, value);
2463
 
        emae_uri_changed (service, url);
2464
 
        camel_url_free (url);
2465
 
}
2466
 
 
2467
 
static void
2468
 
emae_option_checkspin_check_changed (GtkToggleButton *toggle, EMAccountEditorService *service)
2469
 
{
2470
 
        const gchar *name = g_object_get_data ((GObject *)toggle, "option-name");
2471
 
        GtkSpinButton *spin = g_object_get_data ((GObject *)toggle, "option-target");
2472
 
 
2473
 
        if (gtk_toggle_button_get_active (toggle)) {
2474
 
                gtk_widget_set_sensitive ((GtkWidget *) spin, TRUE);
2475
 
                emae_option_checkspin_changed (spin, service);
2476
 
        } else {
2477
 
                CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2478
 
 
2479
 
                camel_url_set_param (url, name, NULL);
2480
 
                gtk_widget_set_sensitive ((GtkWidget *) spin, FALSE);
2481
 
                emae_uri_changed (service, url);
2482
 
                camel_url_free (url);
2483
 
        }
2484
 
}
2485
 
 
2486
 
static void
2487
 
parse_checkspin_format (const gchar *str,
2488
 
                        gboolean *on_ret,
2489
 
                        gdouble *min_ret,
2490
 
                        gdouble *def_ret,
2491
 
                        gdouble *max_ret)
2492
 
{
2493
 
        gchar on;
2494
 
 
2495
 
        /* FIXME: this is a fugly api. */
2496
 
        if (str == NULL
2497
 
            || sscanf (str, "%c:%lf:%lf:%lf", &on, min_ret, def_ret, max_ret) != 4) {
2498
 
                *on_ret = FALSE; /* FIXME: we could do better error handling here... */
2499
 
                *min_ret = 0.0;
2500
 
                *def_ret = 0.0;
2501
 
                *max_ret = 1.0;
2502
 
                return;
2503
 
        }
2504
 
 
2505
 
        *on_ret = (on == 'y');
2506
 
}
2507
 
 
2508
 
static GtkWidget *
2509
 
emae_option_checkspin (EMAccountEditorService *service, CamelURL *url, const gchar *name, const gchar *fmt, const gchar *info)
2510
 
{
2511
 
        GtkWidget *hbox, *check, *spin, *label = NULL;
2512
 
        gdouble min, def, max;
2513
 
        gchar *pre, *post;
2514
 
        const gchar *val;
2515
 
        gboolean on;
2516
 
 
2517
 
        pre = g_alloca (strlen (fmt)+1);
2518
 
        strcpy (pre, fmt);
2519
 
        post = strstr (pre, "%s");
2520
 
        if (post) {
2521
 
                *post = 0;
2522
 
                post+=2;
2523
 
        }
2524
 
 
2525
 
        /* FIXME: the following sucks.  The CamelURL may contain a default value
2526
 
         * already (or if it doesn't, it means that the option is turned off).
2527
 
         * However, the URL doesn't have information about the range for the
2528
 
         * value (min, max).  So we need to parse that out of the original
2529
 
         * description for the option from the CamelProvider.
2530
 
         */
2531
 
 
2532
 
        parse_checkspin_format (info, &on, &min, &def, &max);
2533
 
 
2534
 
        val = camel_url_get_param (url, name);
2535
 
        if (val != NULL) {
2536
 
                on = TRUE;
2537
 
                def = strtod (val, NULL);
2538
 
        } else
2539
 
                on = FALSE;
2540
 
 
2541
 
        hbox = gtk_hbox_new (FALSE, 0);
2542
 
        check = g_object_new (gtk_check_button_get_type (), "label", pre, "use_underline", TRUE, "active", on, NULL);
2543
 
 
2544
 
        spin = gtk_spin_button_new ((GtkAdjustment *) gtk_adjustment_new (def, min, max, 1, 1, 0), 1, 0);
2545
 
        if (post) {
2546
 
                label = gtk_label_new_with_mnemonic (post);
2547
 
                gtk_label_set_mnemonic_widget (GTK_LABEL (label), check);
2548
 
        }
2549
 
        gtk_box_pack_start ((GtkBox *) hbox, check, FALSE, TRUE, 0);
2550
 
        gtk_box_pack_start ((GtkBox *) hbox, spin, FALSE, TRUE, 0);
2551
 
        if (label)
2552
 
                gtk_box_pack_start ((GtkBox *) hbox, label, FALSE, TRUE, 4);
2553
 
 
2554
 
        g_object_set_data ((GObject *)spin, "option-name", (gpointer)name);
2555
 
        g_object_set_data ((GObject *)check, "option-name", (gpointer)name);
2556
 
        g_object_set_data ((GObject *)check, "option-target", (gpointer)spin);
2557
 
 
2558
 
        g_signal_connect (spin, "value_changed", G_CALLBACK(emae_option_checkspin_changed), service);
2559
 
        g_signal_connect (check, "toggled", G_CALLBACK(emae_option_checkspin_check_changed), service);
2560
 
 
2561
 
        gtk_widget_show_all (hbox);
2562
 
 
2563
 
        return hbox;
2564
 
}
2565
 
 
2566
 
static void
2567
 
emae_option_options_changed (GtkComboBox *options, EMAccountEditorService *service)
2568
 
{
2569
 
        const gchar *name = g_object_get_data (G_OBJECT (options), "option-name");
2570
 
        gchar *value = NULL;
2571
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2572
 
        gint id = gtk_combo_box_get_active (options);
2573
 
 
2574
 
        if (id != -1) {
2575
 
                GtkTreeModel *model;
2576
 
                GtkTreeIter iter;
2577
 
 
2578
 
                model = gtk_combo_box_get_model (options);
2579
 
                if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) {
2580
 
                        gtk_tree_model_get (model, &iter, 0, &value, -1);
2581
 
                }
2582
 
        }
2583
 
 
2584
 
        camel_url_set_param (url, name, value);
2585
 
        emae_uri_changed (service, url);
2586
 
        camel_url_free (url);
2587
 
        g_free (value);
2588
 
}
2589
 
 
2590
 
/* 'values' is in format "value0:caption0:value2:caption2:...valueN:captionN" */
2591
 
static GtkWidget *
2592
 
emae_option_options (EMAccountEditorService *service, CamelURL *url, const gchar *name, const gchar *values, GtkWidget *l)
2593
 
{
2594
 
        GtkComboBox *w;
2595
 
        GtkListStore *store;
2596
 
        GtkTreeIter iter;
2597
 
        const gchar *p, *value, *caption;
2598
 
        GtkCellRenderer *cell;
2599
 
        gint active = 0; /* the first item entered is always a default item */
2600
 
        gint i;
2601
 
        const gchar *val = camel_url_get_param (url, name);
2602
 
 
2603
 
        w = GTK_COMBO_BOX (gtk_combo_box_new ());
2604
 
 
2605
 
        /* value and caption */
2606
 
        store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
2607
 
 
2608
 
        for (p = values, i = 0; p; i++) {
2609
 
                gchar *vl, *cp;
2610
 
 
2611
 
                value = p;
2612
 
                caption = strchr (p, ':');
2613
 
                if (caption) {
2614
 
                        caption++;
2615
 
                } else {
2616
 
                        g_warning (G_STRLOC ": expected ':' not found at '%s'", p);
2617
 
                        break;
2618
 
                }
2619
 
                p = strchr (caption, ':');
2620
 
 
2621
 
                vl = g_strndup (value, caption - value - 1);
2622
 
                if (p) {
2623
 
                        p++;
2624
 
                        cp = g_strndup (caption, p - caption - 1);
2625
 
                } else
2626
 
                        cp = g_strdup (caption);
2627
 
 
2628
 
                gtk_list_store_append (store, &iter);
2629
 
                gtk_list_store_set (store, &iter, 0, vl, 1, dgettext (service->provider->translation_domain, cp), -1);
2630
 
 
2631
 
                if (val && g_ascii_strcasecmp (val, vl) == 0)
2632
 
                        active = i;
2633
 
 
2634
 
                g_free (vl);
2635
 
                g_free (cp);
2636
 
        }
2637
 
 
2638
 
        gtk_combo_box_set_model (w, (GtkTreeModel *) store);
2639
 
        gtk_combo_box_set_active (w, i > 0 ? active : -1);
2640
 
 
2641
 
        cell = gtk_cell_renderer_text_new ();
2642
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (w), cell, TRUE);
2643
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (w), cell, "text", 1, NULL);
2644
 
 
2645
 
        gtk_widget_show (GTK_WIDGET (w));
2646
 
 
2647
 
        gtk_label_set_mnemonic_widget (GTK_LABEL (l), GTK_WIDGET (w));
2648
 
 
2649
 
        g_object_set_data (G_OBJECT (w), "option-name", (gpointer)name);
2650
 
        g_signal_connect (w, "changed", G_CALLBACK (emae_option_options_changed), service);
2651
 
 
2652
 
        return GTK_WIDGET (w);
2653
 
}
2654
 
 
2655
 
static GtkWidget *
2656
 
emae_receive_options_item (EConfig *ec,
2657
 
                           EConfigItem *item,
2658
 
                           GtkWidget *parent,
2659
 
                           GtkWidget *old,
2660
 
                           gint position,
2661
 
                           gpointer data)
2662
 
{
2663
 
        EMAccountEditor *emae = data;
2664
 
        GtkWidget *w, *box, *spin;
2665
 
        guint row;
2666
 
 
2667
 
        if (emae->priv->source.provider == NULL
2668
 
            || emae->priv->source.provider->extra_conf == NULL)
2669
 
                return NULL;
2670
 
 
2671
 
        if (old) {
2672
 
                if (emae->type == EMAE_PAGES) {
2673
 
                        GtkWidget *box = gtk_hbox_new (FALSE, 12);
2674
 
                        gtk_widget_reparent (old, box);
2675
 
                        gtk_widget_show (box);
2676
 
                        gtk_box_set_child_packing ((GtkBox *) box, old, TRUE, TRUE, 12, GTK_PACK_START);
2677
 
                        gtk_box_pack_end ((GtkBox *) emae->pages[2], box, FALSE, FALSE, 0);
2678
 
                }
2679
 
                return old;
2680
 
        }
2681
 
 
2682
 
        if (emae->type == EMAE_PAGES)  {
2683
 
                GtkWidget *box = gtk_hbox_new (FALSE, 12);
2684
 
                gtk_widget_reparent (parent, box);
2685
 
                gtk_widget_show (box);
2686
 
                gtk_box_set_child_packing ((GtkBox *) box, parent, TRUE, TRUE, 12, GTK_PACK_START);
2687
 
                gtk_box_pack_start ((GtkBox *) emae->pages[2], box, FALSE, FALSE, 0);
2688
 
        }
2689
 
 
2690
 
        /* We have to add the automatic mail check item with the rest of the receive options */
2691
 
        g_object_get (parent, "n-rows", &row, NULL);
2692
 
 
2693
 
        box = gtk_hbox_new (FALSE, 4);
2694
 
        w = gtk_check_button_new_with_mnemonic (_("Check for _new messages every"));
2695
 
        emae_account_toggle_widget (emae, (GtkToggleButton *) w, E_ACCOUNT_SOURCE_AUTO_CHECK);
2696
 
        gtk_box_pack_start ((GtkBox *) box, w, FALSE, FALSE, 0);
2697
 
 
2698
 
        spin = gtk_spin_button_new_with_range (1.0, 1440.0, 1.0);
2699
 
        emae_account_spinint_widget (emae, (GtkSpinButton *) spin, E_ACCOUNT_SOURCE_AUTO_CHECK_TIME);
2700
 
        gtk_box_pack_start ((GtkBox *) box, spin, FALSE, TRUE, 0);
2701
 
 
2702
 
        w = gtk_label_new_with_mnemonic (_("minu_tes"));
2703
 
        gtk_label_set_mnemonic_widget (GTK_LABEL (w), spin);
2704
 
        gtk_box_pack_start ((GtkBox *) box, w, FALSE, FALSE, 0);
2705
 
 
2706
 
        gtk_widget_show_all (box);
2707
 
 
2708
 
        gtk_table_attach ((GtkTable *) parent, box, 0, 2, row, row+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
2709
 
 
2710
 
        return box;
2711
 
}
2712
 
 
2713
 
static GtkWidget *
2714
 
emae_receive_options_extra_item (EConfig *ec,
2715
 
                                 EConfigItem *eitem,
2716
 
                                 GtkWidget *parent,
2717
 
                                 GtkWidget *old,
2718
 
                                 gint position,
2719
 
                                 gpointer data)
2720
 
{
2721
 
        EMAccountEditor *emae = data;
2722
 
        struct _receive_options_item *item = (struct _receive_options_item *) eitem;
2723
 
        GtkWidget *w, *l, *h;
2724
 
        CamelProviderConfEntry *entries;
2725
 
        GtkWidget *depw;
2726
 
        GSList *depl = NULL, *n;
2727
 
        EMAccountEditorService *service = &emae->priv->source;
2728
 
        gint i;
2729
 
        guint row;
2730
 
        GHashTable *extra;
2731
 
        CamelURL *url;
2732
 
 
2733
 
        if (emae->priv->source.provider == NULL
2734
 
            || emae->priv->source.provider->extra_conf == NULL)
2735
 
                return NULL;
2736
 
        if (emae->type == EMAE_PAGES) {
2737
 
                GtkWidget *box = gtk_hbox_new (FALSE, 12);
2738
 
                gtk_widget_reparent (parent, box);
2739
 
                gtk_widget_show (box);
2740
 
                gtk_box_set_child_packing ((GtkBox *) box, parent, TRUE, TRUE, 12, GTK_PACK_START);
2741
 
                gtk_box_pack_start ((GtkBox *) emae->pages[2], box, FALSE, FALSE, 0);
2742
 
        }
2743
 
 
2744
 
        entries = emae->priv->source.provider->extra_conf;
2745
 
        for (i=0;entries && entries[i].type != CAMEL_PROVIDER_CONF_END;i++)
2746
 
                if (entries[i].type == CAMEL_PROVIDER_CONF_SECTION_START
2747
 
                    && entries[i].name
2748
 
                    && strcmp (entries[i].name, eitem->user_data) == 0)
2749
 
                        goto section;
2750
 
 
2751
 
        return NULL;
2752
 
section:
2753
 
        d (printf ("Building extra section '%s'\n", eitem->path));
2754
 
        w = NULL;
2755
 
        url = emae_account_url (emae, emae_service_info[service->type].account_uri_key);
2756
 
        item->extra_table = g_hash_table_new (g_str_hash, g_str_equal);
2757
 
        extra = g_hash_table_new (g_str_hash, g_str_equal);
2758
 
        g_object_get (parent, "n-rows", &row, NULL);
2759
 
 
2760
 
        for (;entries[i].type != CAMEL_PROVIDER_CONF_END && entries[i].type != CAMEL_PROVIDER_CONF_SECTION_END;i++) {
2761
 
                if (entries[i].depname) {
2762
 
                        depw = g_hash_table_lookup (extra, entries[i].depname);
2763
 
                        if (depw)
2764
 
                                depl = g_object_steal_data ((GObject *)depw, "dependent-list");
2765
 
                } else
2766
 
                        depw = NULL;
2767
 
 
2768
 
                switch (entries[i].type) {
2769
 
                case CAMEL_PROVIDER_CONF_SECTION_START:
2770
 
                case CAMEL_PROVIDER_CONF_SECTION_END:
2771
 
                        break;
2772
 
                case CAMEL_PROVIDER_CONF_LABEL:
2773
 
                        /* FIXME: This is a hack for exchange connector, labels should be removed from confentry */
2774
 
                        if (!strcmp (entries[i].name, "hostname"))
2775
 
                                l = (GtkWidget *) emae->priv->source.hostlabel;
2776
 
                        else if (!strcmp (entries[i].name, "username"))
2777
 
                                l = (GtkWidget *) emae->priv->source.userlabel;
2778
 
                        else
2779
 
                                l = NULL;
2780
 
 
2781
 
                        if (l) {
2782
 
                                gtk_label_set_text_with_mnemonic ((GtkLabel *) l, entries[i].text);
2783
 
                                if (depw)
2784
 
                                        depl = g_slist_prepend (depl, l);
2785
 
                        }
2786
 
                        break;
2787
 
                case CAMEL_PROVIDER_CONF_CHECKBOX:
2788
 
                        w = emae_option_toggle (service, url, entries[i].text, entries[i].name);
2789
 
                        gtk_table_attach ((GtkTable *) parent, w, 0, 2, row, row+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
2790
 
                        g_hash_table_insert (extra, (gpointer) entries[i].name, w);
2791
 
                        if (depw)
2792
 
                                depl = g_slist_prepend (depl, w);
2793
 
                        row++;
2794
 
                        /* HACK: keep_on_server is stored in the e-account, but is displayed as a properly on the uri,
2795
 
                           make sure they track/match here */
2796
 
                        if (!strcmp (entries[i].name, "keep_on_server"))
2797
 
                                emae_account_toggle_widget (emae, (GtkToggleButton *) w, E_ACCOUNT_SOURCE_KEEP_ON_SERVER);
2798
 
                        break;
2799
 
                case CAMEL_PROVIDER_CONF_ENTRY:
2800
 
                        l = g_object_new (gtk_label_get_type (), "label", entries[i].text, "xalign", 0.0, "use_underline", TRUE, NULL);
2801
 
                        gtk_widget_show (l);
2802
 
                        w = emae_option_entry (service, url, entries[i].name, l);
2803
 
                        gtk_table_attach ((GtkTable *) parent, l, 0, 1, row, row+1, GTK_FILL, 0, 0, 0);
2804
 
                        gtk_table_attach ((GtkTable *) parent, w, 1, 2, row, row+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
2805
 
                        if (depw) {
2806
 
                                depl = g_slist_prepend (depl, w);
2807
 
                                depl = g_slist_prepend (depl, l);
2808
 
                        }
2809
 
                        row++;
2810
 
                        /* FIXME: this is another hack for exchange/groupwise connector */
2811
 
                        g_hash_table_insert (item->extra_table, (gpointer) entries[i].name, w);
2812
 
                        break;
2813
 
                case CAMEL_PROVIDER_CONF_CHECKSPIN:
2814
 
                        w = emae_option_checkspin (service, url, entries[i].name, entries[i].text, entries[i].value);
2815
 
                        gtk_table_attach ((GtkTable *) parent, w, 0, 2, row, row+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
2816
 
                        if (depw)
2817
 
                                depl = g_slist_prepend (depl, w);
2818
 
                        row++;
2819
 
                        break;
2820
 
                case CAMEL_PROVIDER_CONF_OPTIONS:
2821
 
                        h = gtk_hbox_new (FALSE, 4);
2822
 
                        gtk_widget_show (h);
2823
 
                        l = g_object_new (gtk_label_get_type (), "label", entries[i].text, "xalign", 0.0, "use_underline", TRUE, NULL);
2824
 
                        gtk_widget_show (l);
2825
 
                        w = emae_option_options (service, url, entries[i].name, entries[i].value, l);
2826
 
                        gtk_box_pack_start (GTK_BOX (h), l, FALSE, FALSE, 0);
2827
 
                        gtk_box_pack_start (GTK_BOX (h), w, FALSE, FALSE, 0);
2828
 
                        gtk_table_attach ((GtkTable *) parent, h, 0, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
2829
 
                        if (depw) {
2830
 
                                depl = g_slist_prepend (depl, h);
2831
 
                        }
2832
 
                        row++;
2833
 
                        break;
2834
 
                default:
2835
 
                        break;
2836
 
                }
2837
 
 
2838
 
                if (depw && depl) {
2839
 
                        gint act = gtk_toggle_button_get_active ((GtkToggleButton *) depw);
2840
 
 
2841
 
                        g_object_set_data_full ((GObject *)depw, "dependent-list", depl, (GDestroyNotify)g_slist_free);
2842
 
                        for (n=depl;n;n=g_slist_next (n))
2843
 
                                gtk_widget_set_sensitive ((GtkWidget *) n->data, act);
2844
 
                }
2845
 
        }
2846
 
 
2847
 
        camel_url_free (url);
2848
 
        if (w)
2849
 
                gtk_widget_show (w);
2850
 
 
2851
 
        return w;
2852
 
}
2853
 
 
2854
 
static GtkWidget *
2855
 
emae_send_page (EConfig *ec,
2856
 
                EConfigItem *item,
2857
 
                GtkWidget *parent,
2858
 
                GtkWidget *old,
2859
 
                gint position,
2860
 
                gpointer data)
2861
 
{
2862
 
        EMAccountEditor *emae = data;
2863
 
        EMAccountEditorPrivate *priv = emae->priv;
2864
 
        GtkWidget *w;
2865
 
        GtkBuilder *builder;
2866
 
 
2867
 
        /* no transport options page at all for these types of providers */
2868
 
        if (priv->source.provider && CAMEL_PROVIDER_IS_STORE_AND_TRANSPORT (priv->source.provider)) {
2869
 
                memset (&priv->transport.frame, 0, ((gchar *)&priv->transport.check_dialog)-((gchar *)&priv->transport.frame));
2870
 
                return NULL;
2871
 
        }
2872
 
 
2873
 
        builder = gtk_builder_new ();
2874
 
        e_load_ui_builder_definition (builder, "mail-config.ui");
2875
 
 
2876
 
        /* Transport */
2877
 
        priv->transport.type = CAMEL_PROVIDER_TRANSPORT;
2878
 
        emae_setup_service (emae, &priv->transport, builder);
2879
 
 
2880
 
        w = e_builder_get_widget (builder, item->label);
2881
 
        if (emae->type == EMAE_PAGES) {
2882
 
                gtk_box_pack_start ((GtkBox *) emae->pages[3], w, TRUE, TRUE, 0);
2883
 
        } else if (((EConfig *) priv->config)->type == E_CONFIG_ASSISTANT) {
2884
 
                GtkWidget *page;
2885
 
 
2886
 
                page = emae_create_basic_assistant_page (
2887
 
                        emae, GTK_ASSISTANT (parent),
2888
 
                        "transport_page", position);
2889
 
 
2890
 
                gtk_box_pack_start (GTK_BOX (page), w, TRUE, TRUE, 0);
2891
 
 
2892
 
                w = page;
2893
 
        } else {
2894
 
                gtk_notebook_insert_page (
2895
 
                        GTK_NOTEBOOK (parent), w,
2896
 
                        gtk_label_new (_("Sending Email")),
2897
 
                        position);
2898
 
                gtk_container_child_set (
2899
 
                        GTK_CONTAINER (parent), w,
2900
 
                        "tab-fill", FALSE, "tab-expand", FALSE, NULL);
2901
 
        }
2902
 
 
2903
 
        emae_queue_widgets (
2904
 
                emae, builder,
2905
 
                "transport-type-table",
2906
 
                "transport-server-table",
2907
 
                "transport-security-table",
2908
 
                "transport-auth-table",
2909
 
                NULL);
2910
 
 
2911
 
        g_object_unref (builder);
2912
 
 
2913
 
        return w;
2914
 
}
2915
 
 
2916
 
static void
2917
 
emae_get_checkable_folder_keys_widgets (EMAccountEditor *emae, guint32 flag, GtkWidget **check, GtkWidget **button, const gchar **param_key)
2918
 
{
2919
 
        g_return_if_fail (emae != NULL);
2920
 
        g_return_if_fail (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER || flag == CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER);
2921
 
 
2922
 
        if (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER) {
2923
 
                if (check) *check = (GtkWidget *) emae->priv->trash_folder_check;
2924
 
                if (button) *button = (GtkWidget *) emae->priv->trash_folder_button;
2925
 
                if (param_key) *param_key = "real_trash_path";
2926
 
        } else {
2927
 
                if (check) *check = (GtkWidget *) emae->priv->junk_folder_check;
2928
 
                if (button) *button = (GtkWidget *) emae->priv->junk_folder_button;
2929
 
                if (param_key) *param_key = "real_junk_path";
2930
 
        }
2931
 
}
2932
 
 
2933
 
static void
2934
 
emae_real_url_toggled (GtkToggleButton *check, EMAccountEditor *emae)
2935
 
{
2936
 
        guint32 flag;
2937
 
        GtkWidget *butt = NULL;
2938
 
        gboolean checked;
2939
 
        const gchar *param_key;
2940
 
 
2941
 
        g_return_if_fail (check != NULL);
2942
 
        g_return_if_fail (emae != NULL);
2943
 
 
2944
 
        if (!gtk_widget_is_sensitive (GTK_WIDGET (check)) || !gtk_widget_get_visible (GTK_WIDGET (check)))
2945
 
                return;
2946
 
 
2947
 
        flag = GPOINTER_TO_INT (g_object_get_data ((GObject *)check, "url-flag"));
2948
 
        g_return_if_fail (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER || flag == CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER);
2949
 
 
2950
 
        emae_get_checkable_folder_keys_widgets (emae, flag, NULL, &butt, &param_key);
2951
 
 
2952
 
        checked = gtk_toggle_button_get_active (check);
2953
 
        gtk_widget_set_sensitive (butt, checked);
2954
 
 
2955
 
        if (!checked) {
2956
 
                CamelURL *url;
2957
 
 
2958
 
                url = emae_account_url (emae, emae_service_info[emae->priv->source.type].account_uri_key);
2959
 
                camel_url_set_param (url, param_key, NULL);
2960
 
                emae_uri_changed (&emae->priv->source, url);
2961
 
                camel_url_free (url);
2962
 
 
2963
 
                /* clear the previous selection */
2964
 
                em_folder_selection_button_set_selection ((EMFolderSelectionButton *)butt, "");
2965
 
        }
2966
 
}
2967
 
 
2968
 
static void
2969
 
emae_real_url_folder_changed (EMFolderSelectionButton *folder, EMAccountEditor *emae)
2970
 
{
2971
 
        CamelURL *url;
2972
 
        guint32 flag;
2973
 
        GtkWidget *check = NULL;
2974
 
        gboolean changed = FALSE;
2975
 
        const gchar *param_key = NULL, *curi_selected;
2976
 
 
2977
 
        g_return_if_fail (folder != NULL);
2978
 
        g_return_if_fail (emae != NULL);
2979
 
 
2980
 
        if (!gtk_widget_is_sensitive (GTK_WIDGET (folder)) || !gtk_widget_get_visible (GTK_WIDGET (folder)))
2981
 
                return;
2982
 
 
2983
 
        flag = GPOINTER_TO_INT (g_object_get_data ((GObject *)folder, "url-flag"));
2984
 
        g_return_if_fail (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER || flag == CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER);
2985
 
 
2986
 
        emae_get_checkable_folder_keys_widgets (emae, flag, &check, NULL, &param_key);
2987
 
 
2988
 
        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)))
2989
 
                return;
2990
 
 
2991
 
        url = emae_account_url (emae, emae_service_info[emae->priv->source.type].account_uri_key);
2992
 
 
2993
 
        curi_selected = em_folder_selection_button_get_selection (folder);
2994
 
        if (!curi_selected || !*curi_selected) {
2995
 
                camel_url_set_param (url, param_key, NULL);
2996
 
                changed = TRUE;
2997
 
        } else {
2998
 
                gboolean passed;
2999
 
                gchar *selected_folder_name = NULL;
3000
 
                CamelStore *selected_store = NULL;
3001
 
                CamelSession *session = CAMEL_SESSION (e_mail_backend_get_session (em_account_editor_get_backend (emae)));
3002
 
 
3003
 
                passed = e_mail_folder_uri_parse (session, curi_selected, &selected_store, &selected_folder_name, NULL);
3004
 
                if (passed) {
3005
 
                        passed = selected_store && emae->priv->modified_account && emae->priv->modified_account->uid
3006
 
                                && g_strcmp0 (camel_service_get_uid (CAMEL_SERVICE (selected_store)), emae->priv->modified_account->uid) == 0;
3007
 
                }
3008
 
 
3009
 
                if (passed && selected_folder_name && *selected_folder_name) {
3010
 
                        camel_url_set_param (url, param_key, (*selected_folder_name) == '/' ? selected_folder_name + 1 : selected_folder_name);
3011
 
                        changed = TRUE;
3012
 
                } else {
3013
 
                        e_notice (NULL, GTK_MESSAGE_ERROR, "%s", _("Please select a folder from the current account."));
3014
 
                        em_folder_selection_button_set_selection (folder, "");
3015
 
                }
3016
 
 
3017
 
                g_free (selected_folder_name);
3018
 
                if (selected_store)
3019
 
                        g_object_unref (selected_store);
3020
 
        }
3021
 
 
3022
 
        if (changed)
3023
 
                emae_uri_changed (&emae->priv->source, url);
3024
 
        camel_url_free (url);
3025
 
}
3026
 
 
3027
 
static void
3028
 
setup_checkable_folder (EMAccountEditor *emae,
3029
 
                        guint32 flag,
3030
 
                        GtkWidget *check,
3031
 
                        GtkWidget *button)
3032
 
{
3033
 
        EAccount *account;
3034
 
        gboolean available;
3035
 
        EMFolderSelectionButton *folderbutt;
3036
 
        CamelURL *url;
3037
 
        const gchar *value, *param_key = NULL;
3038
 
 
3039
 
        g_return_if_fail (emae != NULL);
3040
 
        g_return_if_fail (check != NULL);
3041
 
        g_return_if_fail (button != NULL);
3042
 
        g_return_if_fail (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER || flag == CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER);
3043
 
 
3044
 
        account = em_account_editor_get_modified_account (emae);
3045
 
        g_return_if_fail (account != NULL);
3046
 
 
3047
 
        folderbutt = EM_FOLDER_SELECTION_BUTTON (button);
3048
 
        url = emae_account_url (emae, emae_service_info[emae->priv->source.type].account_uri_key);
3049
 
 
3050
 
        emae_get_checkable_folder_keys_widgets (emae, flag, NULL, NULL, &param_key);
3051
 
 
3052
 
        value = camel_url_get_param (url, param_key);
3053
 
        available = account->enabled;
3054
 
        gtk_widget_set_sensitive (check, available);
3055
 
 
3056
 
        if (value && *value) {
3057
 
                gchar *url_string = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
3058
 
                if (!url_string) {
3059
 
                        em_folder_selection_button_set_selection (folderbutt, "");
3060
 
                } else {
3061
 
                        CamelURL *copy = camel_url_new (url_string, NULL);
3062
 
 
3063
 
                        if (copy->path)
3064
 
                                g_free (copy->path);
3065
 
                        copy->path = g_strconcat ("/", value, NULL);
3066
 
                        g_free (url_string);
3067
 
 
3068
 
                        url_string = camel_url_to_string (copy, CAMEL_URL_HIDE_ALL);
3069
 
                        em_folder_selection_button_set_selection (folderbutt, url_string ? url_string : "");
3070
 
                        g_free (url_string);
3071
 
                }
3072
 
        } else {
3073
 
                em_folder_selection_button_set_selection (folderbutt, "");
3074
 
        }
3075
 
 
3076
 
        value = em_folder_selection_button_get_selection (folderbutt);
3077
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), value && *value);
3078
 
        gtk_widget_set_sensitive (button, available && value && *value);
3079
 
 
3080
 
        g_object_set_data ((GObject *)check, "url-flag", GINT_TO_POINTER(flag));
3081
 
        g_object_set_data ((GObject *)folderbutt, "url-flag", GINT_TO_POINTER(flag));
3082
 
 
3083
 
        g_signal_connect (check, "toggled", G_CALLBACK (emae_real_url_toggled), emae);
3084
 
        g_signal_connect (folderbutt, "selected", G_CALLBACK (emae_real_url_folder_changed), emae);
3085
 
 
3086
 
        available = emae->priv->source.provider && ((emae->priv->source.provider->flags & flag) == flag);
3087
 
        if (available) {
3088
 
                gtk_widget_show (check);
3089
 
                gtk_widget_show (button);
3090
 
        } else {
3091
 
                gtk_widget_hide (check);
3092
 
                gtk_widget_hide (button);
3093
 
        }
3094
 
 
3095
 
        camel_url_free (url);
3096
 
}
3097
 
 
3098
 
static GtkWidget *
3099
 
emae_defaults_page (EConfig *ec,
3100
 
                    EConfigItem *item,
3101
 
                    GtkWidget *parent,
3102
 
                    GtkWidget *old,
3103
 
                    gint position,
3104
 
                    gpointer data)
3105
 
{
3106
 
        EMAccountEditor *emae = data;
3107
 
        EMAccountEditorPrivate *priv = emae->priv;
3108
 
        EMFolderSelectionButton *button;
3109
 
        EMailBackend *backend;
3110
 
        EAccount *account;
3111
 
        GtkWidget *widget;
3112
 
        GtkBuilder *builder;
3113
 
 
3114
 
        /*if (old)
3115
 
          return old;*/
3116
 
        if (((EConfig *) priv->config)->type == E_CONFIG_ASSISTANT && emae->type != EMAE_PAGES)
3117
 
                return NULL;
3118
 
 
3119
 
        account = em_account_editor_get_modified_account (emae);
3120
 
        backend = em_account_editor_get_backend (emae);
3121
 
 
3122
 
        /* Make sure we have a valid EMailBackend. */
3123
 
        g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
3124
 
 
3125
 
        builder = gtk_builder_new ();
3126
 
        e_load_ui_builder_definition (builder, "mail-config.ui");
3127
 
 
3128
 
        /* Special folders */
3129
 
        button = emae_account_folder (
3130
 
                emae, "drafts_button",
3131
 
                E_ACCOUNT_DRAFTS_FOLDER_URI,
3132
 
                E_MAIL_LOCAL_FOLDER_DRAFTS, builder);
3133
 
        priv->drafts_folder_button = GTK_BUTTON (button);
3134
 
 
3135
 
        button = emae_account_folder (
3136
 
                emae, "sent_button",
3137
 
                E_ACCOUNT_SENT_FOLDER_URI,
3138
 
                E_MAIL_LOCAL_FOLDER_SENT, builder);
3139
 
        priv->sent_folder_button = GTK_BUTTON (button);
3140
 
 
3141
 
        widget = e_builder_get_widget (builder, "trash_folder_check");
3142
 
        priv->trash_folder_check = GTK_TOGGLE_BUTTON (widget);
3143
 
 
3144
 
        widget = e_builder_get_widget (builder, "trash_folder_butt");
3145
 
        button = EM_FOLDER_SELECTION_BUTTON (widget);
3146
 
        em_folder_selection_button_set_backend (button, backend);
3147
 
        priv->trash_folder_button = GTK_BUTTON (button);
3148
 
 
3149
 
        setup_checkable_folder (
3150
 
                emae, CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER,
3151
 
                GTK_WIDGET (priv->trash_folder_check),
3152
 
                GTK_WIDGET (priv->trash_folder_button));
3153
 
 
3154
 
        widget = e_builder_get_widget (builder, "junk_folder_check");
3155
 
        priv->junk_folder_check = GTK_TOGGLE_BUTTON (widget);
3156
 
 
3157
 
        widget = e_builder_get_widget (builder, "junk_folder_butt");
3158
 
        button = EM_FOLDER_SELECTION_BUTTON (widget);
3159
 
        em_folder_selection_button_set_backend (button, backend);
3160
 
        priv->junk_folder_button = GTK_BUTTON (button);
3161
 
 
3162
 
        setup_checkable_folder (
3163
 
                emae, CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER,
3164
 
                GTK_WIDGET (priv->junk_folder_check),
3165
 
                GTK_WIDGET (priv->junk_folder_button));
3166
 
 
3167
 
        /* Special Folders "Reset Defaults" button */
3168
 
        priv->restore_folders_button = (GtkButton *)e_builder_get_widget (builder, "default_folders_button");
3169
 
        g_signal_connect (priv->restore_folders_button, "clicked", G_CALLBACK (default_folders_clicked), emae);
3170
 
 
3171
 
        /* Always Cc/Bcc */
3172
 
        emae_account_toggle (emae, "always_cc", E_ACCOUNT_CC_ALWAYS, builder);
3173
 
        emae_account_entry (emae, "cc_addrs", E_ACCOUNT_CC_ADDRS, builder);
3174
 
        emae_account_toggle (emae, "always_bcc", E_ACCOUNT_BCC_ALWAYS, builder);
3175
 
        emae_account_entry (emae, "bcc_addrs", E_ACCOUNT_BCC_ADDRS, builder);
3176
 
 
3177
 
        gtk_widget_set_sensitive ((GtkWidget *) priv->drafts_folder_button, e_account_writable (account, E_ACCOUNT_DRAFTS_FOLDER_URI));
3178
 
 
3179
 
        gtk_widget_set_sensitive ( (GtkWidget *) priv->sent_folder_button,
3180
 
                                  e_account_writable (account, E_ACCOUNT_SENT_FOLDER_URI)
3181
 
                                  &&
3182
 
                                  (emae->priv->source.provider ? !(emae->priv->source.provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER): TRUE)
3183
 
                                );
3184
 
 
3185
 
        gtk_widget_set_sensitive ((GtkWidget *) priv->restore_folders_button,
3186
 
                                 (e_account_writable (account, E_ACCOUNT_SENT_FOLDER_URI)
3187
 
                                  && ((emae->priv->source.provider  && !( emae->priv->source.provider->flags & CAMEL_PROVIDER_DISABLE_SENT_FOLDER))
3188
 
                                      || e_account_writable (account, E_ACCOUNT_DRAFTS_FOLDER_URI))));
3189
 
 
3190
 
        /* Receipt policy */
3191
 
        emae_setup_receipt_policy (emae, builder);
3192
 
 
3193
 
        widget = e_builder_get_widget (builder, item->label);
3194
 
        if (emae->type == EMAE_PAGES) {
3195
 
                gtk_box_pack_start ((GtkBox *) emae->pages[4], widget, TRUE, TRUE, 0);
3196
 
                gtk_widget_show  (widget);
3197
 
        } else {
3198
 
                gtk_notebook_insert_page (
3199
 
                        GTK_NOTEBOOK (parent), widget,
3200
 
                        gtk_label_new (_("Defaults")),
3201
 
                        position);
3202
 
                gtk_container_child_set (
3203
 
                        GTK_CONTAINER (parent), widget,
3204
 
                        "tab-fill", FALSE, "tab-expand", FALSE, NULL);
3205
 
        }
3206
 
 
3207
 
        emae_queue_widgets (
3208
 
                emae, builder,
3209
 
                "special-folders-table",
3210
 
                "composing-messages-table",
3211
 
                NULL);
3212
 
 
3213
 
        g_object_unref (builder);
3214
 
 
3215
 
        return widget;
3216
 
}
3217
 
 
3218
 
static void
3219
 
emae_account_hash_algo_combo_changed_cb (GtkComboBox *combobox, EMAccountEditor *emae)
3220
 
{
3221
 
        EAccount *account;
3222
 
        gpointer data;
3223
 
        const gchar *text = NULL;
3224
 
 
3225
 
        account = em_account_editor_get_modified_account (emae);
3226
 
        data = g_object_get_data (G_OBJECT (combobox), "account-item");
3227
 
 
3228
 
        switch (gtk_combo_box_get_active (combobox)) {
3229
 
        case 1: text = "sha1";
3230
 
                break;
3231
 
        case 2: text = "sha256";
3232
 
                break;
3233
 
        case 3:
3234
 
                text = "sha384";
3235
 
                break;
3236
 
        case 4:
3237
 
                text = "sha512";
3238
 
                break;
3239
 
        }
3240
 
 
3241
 
        e_account_set_string (account, GPOINTER_TO_INT (data), text);
3242
 
}
3243
 
 
3244
 
static GtkComboBox *
3245
 
emae_account_hash_algo_combo (EMAccountEditor *emae, const gchar *name, gint item, GtkBuilder *builder)
3246
 
{
3247
 
        EAccount *account;
3248
 
        GtkComboBox *combobox;
3249
 
        const gchar *text;
3250
 
        gint index = 0;
3251
 
 
3252
 
        account = em_account_editor_get_modified_account (emae);
3253
 
        combobox = GTK_COMBO_BOX (e_builder_get_widget (builder, name));
3254
 
        g_return_val_if_fail (combobox != NULL, NULL);
3255
 
 
3256
 
        text = e_account_get_string (account, item);
3257
 
        if (text) {
3258
 
                if (g_ascii_strcasecmp (text, "sha1") == 0)
3259
 
                        index = 1;
3260
 
                else if (g_ascii_strcasecmp (text, "sha256") == 0)
3261
 
                        index = 2;
3262
 
                else if (g_ascii_strcasecmp (text, "sha384") == 0)
3263
 
                        index = 3;
3264
 
                else if (g_ascii_strcasecmp (text, "sha512") == 0)
3265
 
                        index = 4;
3266
 
        }
3267
 
 
3268
 
        gtk_combo_box_set_active (combobox, index);
3269
 
 
3270
 
        g_object_set_data (G_OBJECT (combobox), "account-item", GINT_TO_POINTER (item));
3271
 
        g_signal_connect (combobox, "changed", G_CALLBACK (emae_account_hash_algo_combo_changed_cb), emae);
3272
 
        gtk_widget_set_sensitive (GTK_WIDGET (combobox), e_account_writable (account, item));
3273
 
 
3274
 
        return combobox;
3275
 
}
3276
 
 
3277
 
static GtkWidget *
3278
 
emae_security_page (EConfig *ec,
3279
 
                    EConfigItem *item,
3280
 
                    GtkWidget *parent,
3281
 
                    GtkWidget *old,
3282
 
                    gint position,
3283
 
                    gpointer data)
3284
 
{
3285
 
        EMAccountEditor *emae = data;
3286
 
#if defined (HAVE_NSS) && defined (ENABLE_SMIME)
3287
 
        EMAccountEditorPrivate *priv = emae->priv;
3288
 
#endif
3289
 
        GtkWidget *w;
3290
 
        GtkBuilder *builder;
3291
 
 
3292
 
        /*if (old)
3293
 
          return old;*/
3294
 
 
3295
 
        builder = gtk_builder_new ();
3296
 
        e_load_ui_builder_definition (builder, "mail-config.ui");
3297
 
 
3298
 
        /* Security */
3299
 
        emae_account_entry (emae, "pgp_key", E_ACCOUNT_PGP_KEY, builder);
3300
 
        emae_account_hash_algo_combo (emae, "pgp_hash_algo", E_ACCOUNT_PGP_HASH_ALGORITHM, builder);
3301
 
        emae_account_toggle (emae, "pgp_encrypt_to_self", E_ACCOUNT_PGP_ENCRYPT_TO_SELF, builder);
3302
 
        emae_account_toggle (emae, "pgp_always_sign", E_ACCOUNT_PGP_ALWAYS_SIGN, builder);
3303
 
        emae_account_toggle (emae, "pgp_no_imip_sign", E_ACCOUNT_PGP_NO_IMIP_SIGN, builder);
3304
 
        emae_account_toggle (emae, "pgp_always_trust", E_ACCOUNT_PGP_ALWAYS_TRUST, builder);
3305
 
 
3306
 
#if defined (HAVE_NSS) && defined (ENABLE_SMIME)
3307
 
        /* TODO: this should handle its entry separately? */
3308
 
        priv->smime_sign_key = emae_account_entry (emae, "smime_sign_key", E_ACCOUNT_SMIME_SIGN_KEY, builder);
3309
 
        priv->smime_sign_key_select = (GtkButton *)e_builder_get_widget (builder, "smime_sign_key_select");
3310
 
        priv->smime_sign_key_clear = (GtkButton *)e_builder_get_widget (builder, "smime_sign_key_clear");
3311
 
        g_signal_connect (priv->smime_sign_key_select, "clicked", G_CALLBACK(smime_sign_key_select), emae);
3312
 
        g_signal_connect (priv->smime_sign_key_clear, "clicked", G_CALLBACK(smime_sign_key_clear), emae);
3313
 
 
3314
 
        emae_account_hash_algo_combo (emae, "smime_hash_algo", E_ACCOUNT_SMIME_HASH_ALGORITHM, builder);
3315
 
        priv->smime_sign_default = emae_account_toggle (emae, "smime_sign_default", E_ACCOUNT_SMIME_SIGN_DEFAULT, builder);
3316
 
 
3317
 
        priv->smime_encrypt_key = emae_account_entry (emae, "smime_encrypt_key", E_ACCOUNT_SMIME_ENCRYPT_KEY, builder);
3318
 
        priv->smime_encrypt_key_select = (GtkButton *)e_builder_get_widget (builder, "smime_encrypt_key_select");
3319
 
        priv->smime_encrypt_key_clear = (GtkButton *)e_builder_get_widget (builder, "smime_encrypt_key_clear");
3320
 
        g_signal_connect (priv->smime_encrypt_key_select, "clicked", G_CALLBACK(smime_encrypt_key_select), emae);
3321
 
        g_signal_connect (priv->smime_encrypt_key_clear, "clicked", G_CALLBACK(smime_encrypt_key_clear), emae);
3322
 
 
3323
 
        priv->smime_encrypt_default = emae_account_toggle (emae, "smime_encrypt_default", E_ACCOUNT_SMIME_ENCRYPT_DEFAULT, builder);
3324
 
        priv->smime_encrypt_to_self = emae_account_toggle (emae, "smime_encrypt_to_self", E_ACCOUNT_SMIME_ENCRYPT_TO_SELF, builder);
3325
 
        smime_changed (emae);
3326
 
#else
3327
 
        {
3328
 
                /* Since we don't have NSS, hide the S/MIME config options */
3329
 
                GtkWidget *frame;
3330
 
 
3331
 
                frame = e_builder_get_widget (builder, "smime_vbox");
3332
 
                gtk_widget_destroy (frame);
3333
 
        }
3334
 
#endif /* HAVE_NSS */
3335
 
 
3336
 
        w = e_builder_get_widget (builder, item->label);
3337
 
        gtk_notebook_insert_page (
3338
 
                GTK_NOTEBOOK (parent), w,
3339
 
                gtk_label_new (_("Security")),
3340
 
                position);
3341
 
        gtk_container_child_set (
3342
 
                GTK_CONTAINER (parent), w,
3343
 
                "tab-fill", FALSE, "tab-expand", FALSE, NULL);
3344
 
 
3345
 
        g_object_unref (builder);
3346
 
 
3347
 
        return w;
3348
 
}
3349
 
 
3350
 
/*
3351
 
 * Allow some level of post creation customisation in plugins.
3352
 
 */
3353
 
GtkWidget *
3354
 
em_account_editor_get_widget (EMAccountEditor *emae, const gchar *name)
3355
 
{
3356
 
        GtkWidget *wid;
3357
 
 
3358
 
        wid = g_hash_table_lookup (emae->priv->widgets, name);
3359
 
        if (wid)
3360
 
                return wid;
3361
 
 
3362
 
        g_warning ("Mail account widget '%s' not found", name);
3363
 
 
3364
 
        return NULL;
3365
 
}
3366
 
 
3367
 
static GtkWidget *
3368
 
emae_widget_glade (EConfig *ec,
3369
 
                   EConfigItem *item,
3370
 
                   GtkWidget *parent,
3371
 
                   GtkWidget *old,
3372
 
                   gint position,
3373
 
                   gpointer data)
3374
 
{
3375
 
        return em_account_editor_get_widget (data, item->label);
3376
 
}
3377
 
 
3378
 
/* plugin meta-data for "org.gnome.evolution.mail.config.accountEditor" */
3379
 
static EMConfigItem emae_editor_items[] = {
3380
 
        { E_CONFIG_BOOK, (gchar *) "" },
3381
 
        { E_CONFIG_PAGE, (gchar *) "00.identity", (gchar *) "vboxIdentityBorder", emae_identity_page },
3382
 
        { E_CONFIG_SECTION, (gchar *) "00.identity/00.name", (gchar *) "account_vbox", emae_widget_glade },
3383
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "00.identity/10.required", (gchar *) "identity-required-table", emae_widget_glade },
3384
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "00.identity/20.info", (gchar *) "identity-optional-table", emae_widget_glade },
3385
 
 
3386
 
        { E_CONFIG_PAGE, (gchar *) "10.receive", (gchar *) "vboxSourceBorder", emae_receive_page },
3387
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "10.receive/00.type", (gchar *) "source-type-table", emae_widget_glade },
3388
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "10.receive/10.config", (gchar *) "source-config-table", emae_widget_glade },
3389
 
        { E_CONFIG_SECTION, (gchar *) "10.receive/20.security", (gchar *) "source-security-vbox", emae_widget_glade },
3390
 
        { E_CONFIG_SECTION, (gchar *) "10.receive/30.auth", (gchar *) "source-auth-vbox", emae_widget_glade },
3391
 
 
3392
 
        /* Most sections for this is auto-generated from the camel config */
3393
 
        { E_CONFIG_PAGE, (gchar *) "20.receive_options", (gchar *) N_("Receiving Options"), },
3394
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "20.receive_options/10.mailcheck", (gchar *) N_("Checking for New Messages"), },
3395
 
        { E_CONFIG_ITEM_TABLE, (gchar *) "20.receive_options/10.mailcheck/00.autocheck", NULL, emae_receive_options_item, },
3396
 
 
3397
 
        { E_CONFIG_PAGE, (gchar *) "30.send", (gchar *) "vboxTransportBorder", emae_send_page },
3398
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "30.send/00.type", (gchar *) "transport-type-table", emae_widget_glade },
3399
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "30.send/10.config", (gchar *) "transport-server-table", emae_widget_glade },
3400
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "30.send/20.security", (gchar *) "transport-security-table", emae_widget_glade },
3401
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "30.send/30.auth", (gchar *) "transport-auth-table", emae_widget_glade },
3402
 
 
3403
 
        { E_CONFIG_PAGE, (gchar *) "40.defaults", (gchar *) "vboxFoldersBorder", emae_defaults_page },
3404
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "40.defaults/00.folders", (gchar *) "special-folders-table", emae_widget_glade },
3405
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "40.defaults/10.composing", (gchar *) "composing-messages-table", emae_widget_glade },
3406
 
 
3407
 
        { E_CONFIG_PAGE, (gchar *) "50.security", (gchar *) "vboxSecurityBorder", emae_security_page },
3408
 
        /* 1x1 table (!) not vbox: { E_CONFIG_SECTION, "50.security/00.gpg", "table19", emae_widget_glade }, */
3409
 
        /* table not vbox: { E_CONFIG_SECTION, "50.security/10.smime", "smime_table", emae_widget_glade }, */
3410
 
        { 0 },
3411
 
};
3412
 
static gboolean emae_editor_items_translated = FALSE;
3413
 
 
3414
 
static GtkWidget *
3415
 
emae_management_page (EConfig *ec,
3416
 
                      EConfigItem *item,
3417
 
                      GtkWidget *parent,
3418
 
                      GtkWidget *old,
3419
 
                      gint position,
3420
 
                      gpointer data)
3421
 
{
3422
 
        EMAccountEditor *emae = data;
3423
 
        EMAccountEditorPrivate *priv = emae->priv;
3424
 
        GtkWidget *w;
3425
 
 
3426
 
        w = priv->management_frame;
3427
 
        if (((EConfig *) priv->config)->type == E_CONFIG_ASSISTANT) {
3428
 
                GtkWidget *page;
3429
 
 
3430
 
                page = emae_create_basic_assistant_page (
3431
 
                        emae, GTK_ASSISTANT (parent),
3432
 
                        "management_page", position);
3433
 
 
3434
 
                gtk_widget_reparent (w, page);
3435
 
 
3436
 
                w = page;
3437
 
        }
3438
 
 
3439
 
        return w;
3440
 
}
3441
 
 
3442
 
static GtkWidget *
3443
 
emae_widget_assistant_page (EConfig *ec,
3444
 
                            EConfigItem *item,
3445
 
                            GtkWidget *parent,
3446
 
                            GtkWidget *old,
3447
 
                            gint position,
3448
 
                            gpointer data)
3449
 
{
3450
 
        EMAccountEditor *emae = (EMAccountEditor *) data;
3451
 
 
3452
 
        if (emae->type == EMAE_PAGES)
3453
 
                return NULL;
3454
 
 
3455
 
        return emae_create_basic_assistant_page (
3456
 
                emae, GTK_ASSISTANT (parent), item->label, position);
3457
 
}
3458
 
 
3459
 
/* plugin meta-data for "org.gnome.evolution.mail.config.accountAssistant" */
3460
 
static EMConfigItem emae_assistant_items[] = {
3461
 
        { E_CONFIG_ASSISTANT, (gchar *) "" },
3462
 
        { E_CONFIG_PAGE_START, (gchar *) "0.start", (gchar *) "start_page", emae_widget_assistant_page },
3463
 
 
3464
 
        { E_CONFIG_PAGE, (gchar *) "00.identity", (gchar *) "vboxIdentityBorder", emae_identity_page },
3465
 
        { E_CONFIG_SECTION, (gchar *) "00.identity/00.name", (gchar *) "account_vbox", emae_widget_glade },
3466
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "00.identity/10.required", (gchar *) "identity-required-table", emae_widget_glade },
3467
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "00.identity/20.info", (gchar *) "identity-optional-table", emae_widget_glade },
3468
 
 
3469
 
        { E_CONFIG_PAGE, (gchar *) "10.receive", (gchar *) "vboxSourceBorder", emae_receive_page },
3470
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "10.receive/00.type", (gchar *) "source-type-table", emae_widget_glade },
3471
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "10.receive/10.config", (gchar *) "source-config-table", emae_widget_glade },
3472
 
        { E_CONFIG_SECTION, (gchar *) "10.receive/20.security", (gchar *) "source-security-vbox", emae_widget_glade },
3473
 
        { E_CONFIG_SECTION, (gchar *) "10.receive/30.auth", (gchar *) "source-auth-vbox", emae_widget_glade },
3474
 
 
3475
 
        /* Most sections for this is auto-generated fromt the camel config */
3476
 
        { E_CONFIG_PAGE, (gchar *) "20.receive_options", (gchar *) N_("Receiving Options"), },
3477
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "20.receive_options/10.mailcheck", (gchar *) N_("Checking for New Messages"), },
3478
 
        { E_CONFIG_ITEM_TABLE, (gchar *) "20.receive_options/10.mailcheck/00.autocheck", NULL, emae_receive_options_item, },
3479
 
 
3480
 
        { E_CONFIG_PAGE, (gchar *) "30.send", (gchar *) "vboxTransportBorder", emae_send_page },
3481
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "30.send/00.type", (gchar *) "transport-type-table", emae_widget_glade },
3482
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "30.send/10.config", (gchar *) "transport-server-table", emae_widget_glade },
3483
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "30.send/20.security", (gchar *) "transport-security-table", emae_widget_glade },
3484
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "30.send/30.auth", (gchar *) "transport-auth-table", emae_widget_glade },
3485
 
 
3486
 
        { E_CONFIG_PAGE, (gchar *) "40.defaults", (gchar *) "vboxFoldersBorder", emae_defaults_page },
3487
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "40.defaults/00.folders", (gchar *) "special-folders-table", emae_widget_glade },
3488
 
        { E_CONFIG_SECTION_TABLE, (gchar *) "40.defaults/10.composing", (gchar *) "composing-messages-table", emae_widget_glade },
3489
 
 
3490
 
        { E_CONFIG_PAGE, (gchar *) "40.management", (gchar *) "management_frame", emae_management_page },
3491
 
 
3492
 
        { E_CONFIG_PAGE_FINISH, (gchar *) "999.end", (gchar *) "finish_page", emae_widget_assistant_page },
3493
 
        { 0 },
3494
 
};
3495
 
static gboolean emae_assistant_items_translated = FALSE;
3496
 
 
3497
 
static void
3498
 
emae_free (EConfig *ec, GSList *items, gpointer data)
3499
 
{
3500
 
        g_slist_free (items);
3501
 
}
3502
 
 
3503
 
static void
3504
 
emae_free_auto (EConfig *ec, GSList *items, gpointer data)
3505
 
{
3506
 
        GSList *l, *n;
3507
 
 
3508
 
        for (l=items;l;) {
3509
 
                struct _receive_options_item *item = l->data;
3510
 
 
3511
 
                n = g_slist_next (l);
3512
 
                g_free (item->item.path);
3513
 
                if (item->extra_table)
3514
 
                        g_hash_table_destroy (item->extra_table);
3515
 
                g_free (item);
3516
 
                g_slist_free_1 (l);
3517
 
                l = n;
3518
 
        }
3519
 
}
3520
 
 
3521
 
static gboolean
3522
 
emae_service_complete (EMAccountEditor *emae, EMAccountEditorService *service)
3523
 
{
3524
 
        EAccount *account;
3525
 
        CamelURL *url;
3526
 
        gint ok = TRUE;
3527
 
        const gchar *uri;
3528
 
 
3529
 
        if (service->provider == NULL)
3530
 
                return TRUE;
3531
 
 
3532
 
        account = em_account_editor_get_modified_account (emae);
3533
 
 
3534
 
        uri = e_account_get_string (account, emae_service_info[service->type].account_uri_key);
3535
 
        if (uri == NULL || (url = camel_url_new (uri, NULL)) == NULL)
3536
 
                return FALSE;
3537
 
 
3538
 
        if (CAMEL_PROVIDER_NEEDS (service->provider, CAMEL_URL_PART_HOST)) {
3539
 
                if (url->host == NULL || url->host[0] == 0 || (!e_port_entry_is_valid (service->port) && service->provider->port_entries))
3540
 
                        ok = FALSE;
3541
 
        }
3542
 
        /* We only need the user if the service needs auth as well, i think */
3543
 
        if (ok
3544
 
            && (service->needs_auth == NULL
3545
 
                || CAMEL_PROVIDER_NEEDS (service->provider, CAMEL_URL_PART_AUTH)
3546
 
                || gtk_toggle_button_get_active (service->needs_auth))
3547
 
            && CAMEL_PROVIDER_NEEDS (service->provider, CAMEL_URL_PART_USER)
3548
 
            && (url->user == NULL || url->user[0] == 0))
3549
 
                ok = FALSE;
3550
 
 
3551
 
        if (ok
3552
 
            && CAMEL_PROVIDER_NEEDS (service->provider, CAMEL_URL_PART_PATH)
3553
 
            && (url->path == NULL || url->path[0] == 0))
3554
 
                ok = FALSE;
3555
 
 
3556
 
        camel_url_free (url);
3557
 
 
3558
 
        return ok;
3559
 
}
3560
 
 
3561
 
static ServerData *
3562
 
emae_check_servers (const gchar *email)
3563
 
{
3564
 
        gint len = G_N_ELEMENTS (mail_servers), i;
3565
 
        gchar *server = strchr (email, '@');
3566
 
 
3567
 
        server++;
3568
 
 
3569
 
        for (i=0; i<len; i++) {
3570
 
                if (strstr (server, mail_servers[i].key) != NULL)
3571
 
                        return &mail_servers[i];
3572
 
        }
3573
 
 
3574
 
        return NULL;
3575
 
}
3576
 
 
3577
 
static void
3578
 
emae_check_set_authtype (GtkComboBox *dropdown, const gchar *auth)
3579
 
{
3580
 
        GtkTreeModel *model;
3581
 
        GtkTreeIter iter;
3582
 
        gint id;
3583
 
        gint children;
3584
 
 
3585
 
        model = gtk_combo_box_get_model (dropdown);
3586
 
        children = gtk_tree_model_iter_n_children (model, NULL);
3587
 
        for (id = 0; id < children; id++)  {
3588
 
                CamelServiceAuthType *authtype;
3589
 
 
3590
 
                gtk_tree_model_iter_nth_child (model, &iter, NULL, id);
3591
 
                gtk_tree_model_get (model, &iter, 1, &authtype, -1);
3592
 
                if (g_ascii_strcasecmp (authtype->authproto, auth) == 0)
3593
 
                        break;
3594
 
        }
3595
 
 
3596
 
        if (id < children)
3597
 
                gtk_combo_box_set_active (dropdown, id);
3598
 
}
3599
 
 
3600
 
static gboolean
3601
 
emae_check_complete (EConfig *ec, const gchar *pageid, gpointer data)
3602
 
{
3603
 
        EMAccountEditor *emae = data;
3604
 
        EAccount *account;
3605
 
        EAccount *original_account;
3606
 
        gint ok = TRUE;
3607
 
        const gchar *tmp;
3608
 
        EAccount *ea;
3609
 
        gboolean refresh = FALSE;
3610
 
        gboolean new_account;
3611
 
 
3612
 
        account = em_account_editor_get_modified_account (emae);
3613
 
        original_account = em_account_editor_get_original_account (emae);
3614
 
        new_account = (original_account == NULL);
3615
 
 
3616
 
        /* We use the page-check of various pages to 'prepare' or
3617
 
           pre-load their values, only in the assistant */
3618
 
        if (pageid
3619
 
            && ((EConfig *) emae->priv->config)->type == E_CONFIG_ASSISTANT) {
3620
 
                if (!strcmp (pageid, "00.identity")) {
3621
 
                        if (!emae->priv->identity_set) {
3622
 
                                gchar *uname;
3623
 
 
3624
 
                                emae->priv->identity_set = 1;
3625
 
#ifndef G_OS_WIN32
3626
 
                                uname = g_locale_to_utf8 (g_get_real_name (), -1, NULL, NULL, NULL);
3627
 
#else
3628
 
                                uname = g_strdup (g_get_real_name ());
3629
 
#endif
3630
 
                                if (uname) {
3631
 
                                        gtk_entry_set_text (emae->priv->identity_entries[1], uname);
3632
 
                                        g_free (uname);
3633
 
                                }
3634
 
                        }
3635
 
                } else if (!strcmp (pageid, "10.receive")) {
3636
 
                        if (!emae->priv->receive_set) {
3637
 
                                ServerData *sdata;
3638
 
                                gchar *user, *at;
3639
 
                                gchar *uri = g_strdup (e_account_get_string (account, E_ACCOUNT_SOURCE_URL));
3640
 
                                CamelURL *url;
3641
 
 
3642
 
                                emae->priv->receive_set = 1;
3643
 
                                tmp = (gchar *) e_account_get_string (account, E_ACCOUNT_ID_ADDRESS);
3644
 
                                at = strchr (tmp, '@');
3645
 
                                user = g_alloca (at-tmp+1);
3646
 
                                memcpy (user, tmp, at-tmp);
3647
 
                                user[at-tmp] = 0;
3648
 
                                at++;
3649
 
 
3650
 
                                sdata = emae->priv->selected_server = emae->emae_check_servers (tmp);
3651
 
                                if (new_account && uri && (url = camel_url_new (uri, NULL)) != NULL) {
3652
 
                                        const gchar *use_user = user;
3653
 
                                        refresh = TRUE;
3654
 
                                        if (sdata && sdata->recv_user && *sdata->recv_user)
3655
 
                                                use_user = g_str_equal (sdata->recv_user, "@") ? tmp : sdata->recv_user;
3656
 
                                        camel_url_set_user (url, use_user);
3657
 
                                        gtk_entry_set_text (emae->priv->source.username, use_user);
3658
 
 
3659
 
                                        if (sdata != NULL) {
3660
 
                                                camel_url_set_protocol (url, sdata->proto);
3661
 
                                                if (sdata->recv_sock && *sdata->recv_sock)
3662
 
                                                        camel_url_set_param (url, "use_ssl", sdata->recv_sock);
3663
 
                                                else
3664
 
                                                        camel_url_set_param (url, "use_ssl", sdata->ssl);
3665
 
                                                camel_url_set_host (url, sdata->recv);
3666
 
                                                if (sdata->recv_port && *sdata->recv_port)
3667
 
                                                        camel_url_set_port (url, atoi (sdata->recv_port));
3668
 
                                                gtk_entry_set_text (emae->priv->source.hostname, sdata->recv);
3669
 
                                                gtk_entry_set_text (emae->priv->transport.hostname, sdata->send);
3670
 
                                        } else {
3671
 
                                                camel_url_set_host (url, "");
3672
 
                                        }
3673
 
                                        g_free (uri);
3674
 
                                        uri = camel_url_to_string (url, 0);
3675
 
                                        e_account_set_string (account, E_ACCOUNT_SOURCE_URL, uri);
3676
 
                                        if (sdata != NULL && sdata->recv_auth && *sdata->recv_auth)
3677
 
                                                emae_check_set_authtype (emae->priv->source.authtype, sdata->recv_auth);
3678
 
 
3679
 
                                        camel_url_free (url);
3680
 
                                } else
3681
 
                                        gtk_entry_set_text (emae->priv->source.username, user);
3682
 
                                g_free (uri);
3683
 
 
3684
 
                        }
3685
 
                } else if (!strcmp (pageid, "30.send")) {
3686
 
                        if (!emae->priv->send_set) {
3687
 
                                CamelURL *url;
3688
 
                                gchar *at, *user;
3689
 
                                gchar *uri = (gchar *) e_account_get_string (account, E_ACCOUNT_TRANSPORT_URL);
3690
 
                                ServerData *sdata;
3691
 
 
3692
 
                                emae->priv->send_set = 1;
3693
 
                                tmp = e_account_get_string (account, E_ACCOUNT_ID_ADDRESS);
3694
 
                                at = strchr (tmp, '@');
3695
 
                                user = g_alloca (at-tmp+1);
3696
 
                                memcpy (user, tmp, at-tmp);
3697
 
                                user[at-tmp] = 0;
3698
 
                                at++;
3699
 
 
3700
 
                                sdata = emae->priv->selected_server;
3701
 
                                if (sdata != NULL && uri && (url = camel_url_new (uri, NULL)) != NULL) {
3702
 
                                        const gchar *use_user = user;
3703
 
                                        refresh = TRUE;
3704
 
                                        camel_url_set_protocol (url, "smtp");
3705
 
                                        if (sdata->send_sock && *sdata->send_sock)
3706
 
                                                camel_url_set_param (url, "use_ssl", sdata->send_sock);
3707
 
                                        else
3708
 
                                                camel_url_set_param (url, "use_ssl", sdata->ssl);
3709
 
                                        camel_url_set_host (url, sdata->send);
3710
 
                                        if (sdata->send_port && *sdata->send_port)
3711
 
                                                camel_url_set_port (url, atoi (sdata->send_port));
3712
 
 
3713
 
                                        if (sdata->send_user && *sdata->send_user)
3714
 
                                                use_user = g_str_equal (sdata->send_user, "@") ? tmp : sdata->send_user;
3715
 
                                        camel_url_set_user (url, use_user);
3716
 
                                        gtk_entry_set_text (emae->priv->transport.username, use_user);
3717
 
 
3718
 
                                        uri = camel_url_to_string (url, 0);
3719
 
                                        e_account_set_string (account, E_ACCOUNT_TRANSPORT_URL, uri);
3720
 
                                        g_free (uri);
3721
 
                                        camel_url_free (url);
3722
 
                                        gtk_toggle_button_set_active (emae->priv->transport.needs_auth, TRUE);
3723
 
                                        if (sdata->send_auth && *sdata->send_auth)
3724
 
                                                emae_check_set_authtype (emae->priv->transport.authtype, sdata->send_auth);
3725
 
                                        else
3726
 
                                                emae_authtype_changed (emae->priv->transport.authtype, &emae->priv->transport);
3727
 
                                        uri = (gchar *) e_account_get_string (account, E_ACCOUNT_TRANSPORT_URL);
3728
 
                                } else
3729
 
                                        gtk_entry_set_text (emae->priv->transport.username, user);
3730
 
                        }
3731
 
 
3732
 
                } else if (!strcmp (pageid, "20.receive_options")) {
3733
 
                        if (emae->priv->source.provider
3734
 
                            && emae->priv->extra_provider != emae->priv->source.provider) {
3735
 
                                emae->priv->extra_provider = emae->priv->source.provider;
3736
 
                                emae_auto_detect (emae);
3737
 
                        }
3738
 
                } else if (!strcmp (pageid, "40.management")) {
3739
 
                        if (!emae->priv->management_set) {
3740
 
                                gchar *template;
3741
 
                                guint i = 0, len;
3742
 
 
3743
 
                                emae->priv->management_set = 1;
3744
 
                                tmp = e_account_get_string (account, E_ACCOUNT_ID_ADDRESS);
3745
 
                                len = strlen (tmp);
3746
 
                                template = g_alloca (len + 14);
3747
 
                                strcpy (template, tmp);
3748
 
                                while (e_get_account_by_name (template))
3749
 
                                        sprintf (template + len, " (%d)", i++);
3750
 
 
3751
 
                                gtk_entry_set_text (emae->priv->identity_entries[0], template);
3752
 
                        }
3753
 
                }
3754
 
        }
3755
 
 
3756
 
        /*
3757
 
           Setting a flag on the Account if it is marked as default. It is done in this way instead of
3758
 
           using a temporary variable so as to keep track of which account is marked as default in case of
3759
 
           editing multiple accounts at a time
3760
 
         */
3761
 
        if (gtk_toggle_button_get_active (emae->priv->default_account))
3762
 
                g_object_set_data (G_OBJECT (account), "default_flagged", GINT_TO_POINTER(1));
3763
 
 
3764
 
        if (pageid == NULL || !strcmp (pageid, "00.identity")) {
3765
 
                /* TODO: check the account name is set, and unique in the account list */
3766
 
                ok = (tmp = e_account_get_string (account, E_ACCOUNT_ID_NAME))
3767
 
                        && tmp[0]
3768
 
                        && (tmp = e_account_get_string (account, E_ACCOUNT_ID_ADDRESS))
3769
 
                        && is_email (tmp)
3770
 
                        && ((tmp = e_account_get_string (account, E_ACCOUNT_ID_REPLY_TO)) == NULL
3771
 
                            || tmp[0] == 0
3772
 
                            || is_email (tmp));
3773
 
                if (!ok) {
3774
 
                        d (printf ("identity incomplete\n"));
3775
 
                }
3776
 
        }
3777
 
 
3778
 
        if (ok && (pageid == NULL || !strcmp (pageid, "10.receive"))) {
3779
 
                if (emae->type != EMAE_NOTEBOOK && refresh) {
3780
 
                        emae_refresh_providers (emae, &emae->priv->source);
3781
 
                        emae_provider_changed (emae->priv->source.providers, &emae->priv->source);
3782
 
                }
3783
 
                ok = emae_service_complete (emae, &emae->priv->source);
3784
 
                if (!ok) {
3785
 
                        d (printf ("receive page incomplete\n"));
3786
 
                }
3787
 
        }
3788
 
 
3789
 
        if (ok && (pageid == NULL || !strcmp (pageid, "30.send"))) {
3790
 
                if (emae->type != EMAE_NOTEBOOK && refresh) {
3791
 
                        emae_refresh_providers (emae, &emae->priv->transport);
3792
 
                        emae_provider_changed (emae->priv->transport.providers, &emae->priv->transport);
3793
 
                }
3794
 
                ok = emae_service_complete (emae, &emae->priv->transport);
3795
 
                if (!ok) {
3796
 
                        d (printf ("send page incomplete\n"));
3797
 
                }
3798
 
        }
3799
 
 
3800
 
        if (ok && (pageid == NULL || !strcmp (pageid, "40.management"))) {
3801
 
                ok = (tmp = e_account_get_string (account, E_ACCOUNT_NAME))
3802
 
                        && tmp[0]
3803
 
                        && ((ea = e_get_account_by_name (tmp)) == NULL
3804
 
                            || ea == original_account);
3805
 
                if (!ok) {
3806
 
                        d (printf ("management page incomplete\n"));
3807
 
                }
3808
 
        }
3809
 
 
3810
 
        return ok;
3811
 
}
3812
 
 
3813
 
gboolean
3814
 
em_account_editor_check (EMAccountEditor *emae, const gchar *page)
3815
 
{
3816
 
        return emae_check_complete ((EConfig *) emae->config, page, emae);
3817
 
}
3818
 
 
3819
 
static void
3820
 
forget_password_if_needed (EAccount *original_account, EAccount *modified_account, e_account_item_t save_pass_itm, e_account_item_t url_itm)
3821
 
{
3822
 
        const gchar *orig_url, *modif_url;
3823
 
 
3824
 
        g_return_if_fail (original_account != NULL);
3825
 
        g_return_if_fail (modified_account != NULL);
3826
 
 
3827
 
        orig_url = e_account_get_string (original_account, url_itm);
3828
 
        modif_url = e_account_get_string (modified_account, url_itm);
3829
 
 
3830
 
        if (orig_url && !*orig_url)
3831
 
                orig_url = NULL;
3832
 
 
3833
 
        if (modif_url && !*modif_url)
3834
 
                modif_url = NULL;
3835
 
 
3836
 
        if ((e_account_get_bool (original_account, save_pass_itm) != e_account_get_bool (modified_account, save_pass_itm)
3837
 
            && !e_account_get_bool (modified_account, save_pass_itm) && orig_url) ||
3838
 
            (orig_url && !modif_url)) {
3839
 
                CamelURL *url;
3840
 
                gchar *url_str;
3841
 
 
3842
 
                url = camel_url_new (orig_url, NULL);
3843
 
                if (!url)
3844
 
                        return;
3845
 
 
3846
 
                url_str = camel_url_to_string (url, CAMEL_URL_HIDE_PASSWORD | CAMEL_URL_HIDE_PARAMS);
3847
 
                if (url_str)
3848
 
                        e_passwords_forget_password (NULL, url_str);
3849
 
 
3850
 
                g_free (url_str);
3851
 
                camel_url_free (url);
3852
 
        }
3853
 
}
3854
 
 
3855
 
static void
3856
 
emae_commit (EConfig *ec, GSList *items, gpointer data)
3857
 
{
3858
 
        EMAccountEditor *emae = data;
3859
 
        EAccountList *accounts = e_get_account_list ();
3860
 
        EAccount *account;
3861
 
        EAccount *modified_account;
3862
 
        EAccount *original_account;
3863
 
 
3864
 
        /* the mail-config*acconts* api needs a lot of work */
3865
 
 
3866
 
        modified_account = em_account_editor_get_modified_account (emae);
3867
 
        original_account = em_account_editor_get_original_account (emae);
3868
 
 
3869
 
        if (original_account != NULL) {
3870
 
                d (printf ("Committing account '%s'\n", e_account_get_string (modified_account, E_ACCOUNT_NAME)));
3871
 
                forget_password_if_needed (original_account, modified_account, E_ACCOUNT_SOURCE_SAVE_PASSWD, E_ACCOUNT_SOURCE_URL);
3872
 
                forget_password_if_needed (original_account, modified_account, E_ACCOUNT_TRANSPORT_SAVE_PASSWD, E_ACCOUNT_TRANSPORT_URL);
3873
 
 
3874
 
                e_account_import (original_account, modified_account);
3875
 
                account = original_account;
3876
 
                e_account_list_change (accounts, account);
3877
 
        } else {
3878
 
                d (printf ("Adding new account '%s'\n", e_account_get_string (account, E_ACCOUNT_NAME)));
3879
 
                e_account_list_add (accounts, modified_account);
3880
 
                account = modified_account;
3881
 
 
3882
 
                /* HACK: this will add the account to the folder tree.
3883
 
                   We should just be listening to the account list directly for changed events */
3884
 
                if (account->enabled
3885
 
                    && emae->priv->source.provider
3886
 
                    && (emae->priv->source.provider->flags & CAMEL_PROVIDER_IS_STORAGE)) {
3887
 
                        EMailBackend *backend;
3888
 
                        EMailSession *session;
3889
 
 
3890
 
                        backend = em_account_editor_get_backend (emae);
3891
 
                        session = e_mail_backend_get_session (backend);
3892
 
                        e_mail_store_add_by_account (session, account);
3893
 
                }
3894
 
        }
3895
 
 
3896
 
        if (gtk_toggle_button_get_active (emae->priv->default_account))
3897
 
                e_account_list_set_default (accounts, account);
3898
 
 
3899
 
        e_account_list_save (accounts);
3900
 
}
3901
 
 
3902
 
void
3903
 
em_account_editor_commit (EMAccountEditor *emae)
3904
 
{
3905
 
        emae_commit ((EConfig *) emae->config, NULL, emae);
3906
 
}
3907
 
 
3908
 
static void
3909
 
set_checkbox_default (CamelProviderConfEntry *entry, CamelURL *url)
3910
 
{
3911
 
        const gchar *value;
3912
 
 
3913
 
        g_assert (entry->type == CAMEL_PROVIDER_CONF_CHECKBOX);
3914
 
 
3915
 
        if (atoi (entry->value) != 0)
3916
 
                value = "";
3917
 
        else
3918
 
                value = NULL;
3919
 
 
3920
 
        camel_url_set_param (url, entry->name, value);
3921
 
 
3922
 
        /* FIXME: do we need to call emae_uri_changed()? */
3923
 
}
3924
 
 
3925
 
static void
3926
 
set_entry_default (CamelProviderConfEntry *entry, CamelURL *url)
3927
 
{
3928
 
        g_assert (entry->type == CAMEL_PROVIDER_CONF_ENTRY);
3929
 
 
3930
 
        camel_url_set_param (url, entry->name, entry->value);
3931
 
        /* FIXME: This comes from emae_option_entry().  That function calls
3932
 
         * emae_uri_changed(), but the corresponding emae_option_toggle() does
3933
 
         * not call emae_uri_changed() when it creates the checkbuttons - do
3934
 
         * we need to call that function at all?
3935
 
         */
3936
 
}
3937
 
 
3938
 
static void
3939
 
set_checkspin_default (CamelProviderConfEntry *entry, CamelURL *url)
3940
 
{
3941
 
        gboolean on;
3942
 
        gdouble min, def, max;
3943
 
 
3944
 
        g_assert (entry->type == CAMEL_PROVIDER_CONF_CHECKSPIN);
3945
 
 
3946
 
        parse_checkspin_format (entry->value, &on, &min, &def, &max);
3947
 
 
3948
 
        if (on) {
3949
 
                gchar value[16];
3950
 
 
3951
 
                sprintf (value, "%d", (gint) def);
3952
 
                camel_url_set_param (url, entry->name, value);
3953
 
        } else
3954
 
                camel_url_set_param (url, entry->name, NULL);
3955
 
 
3956
 
        /* FIXME: do we need to call emae_uri_changed()? */
3957
 
}
3958
 
 
3959
 
static void
3960
 
set_provider_defaults_on_url (EMAccountEditor *emae, CamelProvider *provider, CamelURL *url)
3961
 
{
3962
 
        CamelProviderConfEntry *entries;
3963
 
        gint i;
3964
 
 
3965
 
        if (!emae->priv->new_account)
3966
 
                return;
3967
 
 
3968
 
        entries = provider->extra_conf;
3969
 
 
3970
 
        for (i = 0; entries && entries[i].type != CAMEL_PROVIDER_CONF_END; i++) {
3971
 
                switch (entries[i].type) {
3972
 
                case CAMEL_PROVIDER_CONF_CHECKBOX:
3973
 
                        set_checkbox_default (entries + i, url);
3974
 
                        break;
3975
 
 
3976
 
                case CAMEL_PROVIDER_CONF_ENTRY:
3977
 
                        set_entry_default (entries + i, url);
3978
 
                        break;
3979
 
 
3980
 
                case CAMEL_PROVIDER_CONF_CHECKSPIN:
3981
 
                        set_checkspin_default (entries + i, url);
3982
 
                        break;
3983
 
 
3984
 
                default:
3985
 
                        /* Other entry types don't have defaults, or so can be
3986
 
                         * inferred from emae_option_*().  But see
3987
 
                         * emae_option_options() - that *may* need something,
3988
 
                         * but that function doesn't actually modify the
3989
 
                         * CamelURL. */
3990
 
                        break;
3991
 
                }
3992
 
        }
3993
 
}
3994
 
 
3995
 
static void
3996
 
em_account_editor_construct (EMAccountEditor *emae,
3997
 
                             EMAccountEditorType type,
3998
 
                             const gchar *id)
3999
 
{
4000
 
        EMAccountEditorPrivate *priv = emae->priv;
4001
 
        EAccount *original_account;
4002
 
        EAccount *modified_account;
4003
 
        gint i, index;
4004
 
        GSList *l;
4005
 
        GList *prov;
4006
 
        EMConfig *ec;
4007
 
        EMConfigTargetAccount *target;
4008
 
        GHashTable *have;
4009
 
        EConfigItem *items;
4010
 
 
4011
 
        emae->type = type;
4012
 
 
4013
 
        /* sort the providers, remote first */
4014
 
        priv->providers = g_list_sort (camel_provider_list (TRUE), (GCompareFunc) provider_compare);
4015
 
 
4016
 
        if (type == EMAE_NOTEBOOK) {
4017
 
                ec = em_config_new (E_CONFIG_BOOK, id);
4018
 
                items = emae_editor_items;
4019
 
                if (!emae_editor_items_translated) {
4020
 
                        for (i=0;items[i].path;i++) {
4021
 
                                if (items[i].label)
4022
 
                                        items[i].label = gettext (items[i].label);
4023
 
                        }
4024
 
                        emae_editor_items_translated = TRUE;
4025
 
                }
4026
 
        } else {
4027
 
                ec = em_config_new (E_CONFIG_ASSISTANT, id);
4028
 
                items = emae_assistant_items;
4029
 
                if (!emae_assistant_items_translated) {
4030
 
                        for (i=0;items[i].path;i++) {
4031
 
                                if (items[i].label)
4032
 
                                        items[i].label = _(items[i].label);
4033
 
                        }
4034
 
                        emae_assistant_items_translated = TRUE;
4035
 
                }
4036
 
        }
4037
 
 
4038
 
        emae->config = priv->config = ec;
4039
 
        l = NULL;
4040
 
        for (i=0;items[i].path;i++)
4041
 
                l = g_slist_prepend (l, &items[i]);
4042
 
        e_config_add_items ((EConfig *) ec, l, emae_commit, NULL, emae_free, emae);
4043
 
 
4044
 
        /* This is kinda yuck, we're dynamically mapping from the 'old style' extensibility api to the new one */
4045
 
        l = NULL;
4046
 
        have = g_hash_table_new (g_str_hash, g_str_equal);
4047
 
        index = 20;
4048
 
        for (prov=priv->providers;prov;prov=g_list_next (prov)) {
4049
 
                CamelProviderConfEntry *entries = ((CamelProvider *) prov->data)->extra_conf;
4050
 
 
4051
 
                for (i=0;entries && entries[i].type != CAMEL_PROVIDER_CONF_END;i++) {
4052
 
                        struct _receive_options_item *item;
4053
 
                        const gchar *name = entries[i].name;
4054
 
                        gint myindex = index;
4055
 
 
4056
 
                        if (entries[i].type != CAMEL_PROVIDER_CONF_SECTION_START
4057
 
                            || name == NULL
4058
 
                            || g_hash_table_lookup (have, name))
4059
 
                                continue;
4060
 
 
4061
 
                        /* override mailcheck since we also insert our own mailcheck item at this index */
4062
 
                        if (name && !strcmp (name, "mailcheck"))
4063
 
                                myindex = 10;
4064
 
 
4065
 
                        item = g_malloc0 (sizeof (*item));
4066
 
                        item->item.type = E_CONFIG_SECTION_TABLE;
4067
 
                        item->item.path = g_strdup_printf ("20.receive_options/%02d.%s", myindex, name?name:"unnamed");
4068
 
                        item->item.label = g_strdup (entries[i].text);
4069
 
 
4070
 
                        l = g_slist_prepend (l, item);
4071
 
 
4072
 
                        item = g_malloc0 (sizeof (*item));
4073
 
                        item->item.type = E_CONFIG_ITEM_TABLE;
4074
 
                        item->item.path = g_strdup_printf ("20.receive_options/%02d.%s/80.camelitem", myindex, name?name:"unnamed");
4075
 
                        item->item.factory = emae_receive_options_extra_item;
4076
 
                        item->item.user_data = g_strdup (entries[i].name);
4077
 
 
4078
 
                        l = g_slist_prepend (l, item);
4079
 
 
4080
 
                        index += 10;
4081
 
                        g_hash_table_insert (have, (gpointer) entries[i].name, have);
4082
 
                }
4083
 
        }
4084
 
        g_hash_table_destroy (have);
4085
 
        e_config_add_items ((EConfig *) ec, l, NULL, NULL, emae_free_auto, emae);
4086
 
        priv->extra_items = l;
4087
 
 
4088
 
        e_config_add_page_check ((EConfig *) ec, NULL, emae_check_complete, emae);
4089
 
 
4090
 
        original_account = em_account_editor_get_original_account (emae);
4091
 
        modified_account = em_account_editor_get_modified_account (emae);
4092
 
        target = em_config_target_new_account (
4093
 
                ec, original_account, modified_account);
4094
 
        e_config_set_target ((EConfig *) ec, (EConfigTarget *) target);
4095
 
}
4096