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

« back to all changes in this revision

Viewing changes to mail/em-account-editor.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-09-08 09:38:57 UTC
  • mfrom: (1.1.84 upstream)
  • Revision ID: package-import@ubuntu.com-20110908093857-6lfl04ke2ns3kx2o
Tags: 3.1.91-0ubuntu1
* New upstream release. (LP: #843769)
* debian/control: bump e-d-s Build-Depends to 3.1.91. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
 
25
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
 
*/
 
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
 */
36
35
 
37
36
#ifdef HAVE_CONFIG_H
38
37
#include <config.h>
75
74
#include "smime/gui/e-cert-selector.h"
76
75
#endif
77
76
 
 
77
/* Option widgets whose sensitivity depends on another widget, such
 
78
 * as a checkbox being active, are indented to the right slightly for
 
79
 * better visual clarity.  This specifies how far to the right. */
 
80
#define INDENT_MARGIN 24
 
81
 
78
82
#define d(x)
79
83
 
80
84
static ServerData mail_servers[] = {
81
 
        {"gmail", "imap.gmail.com", "smtp.gmail.com", "imap", "always"},
82
 
        {"googlemail", "imap.gmail.com", "smtp.gmail.com", "imap", "always"},
83
 
        {"yahoo", "pop3.yahoo.com", "smtp.yahoo.com", "pop", "never"},
84
 
        {"aol", "imap.aol.com", "smtp.aol.com", "imap", "never"},
85
 
        {"msn", "pop3.email.msn.com", "smtp.email.msn.com", "pop", "never", "@", "@"},
86
 
        {"hotmail", "pop3.live.com", "smtp.live.com", "pop", "always", "@", "@"},
87
 
        {"live.com", "pop3.live.com", "smtp.live.com", "pop", "always", "@", "@"},
 
85
        { "gmail", "imap.gmail.com", "smtp.gmail.com", "imap",
 
86
          CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT },
 
87
        { "googlemail", "imap.gmail.com", "smtp.gmail.com", "imap",
 
88
          CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT },
 
89
        { "yahoo", "pop3.yahoo.com", "smtp.yahoo.com", "pop",
 
90
          CAMEL_NETWORK_SECURITY_METHOD_NONE },
 
91
        { "aol", "imap.aol.com", "smtp.aol.com", "imap",
 
92
          CAMEL_NETWORK_SECURITY_METHOD_NONE },
 
93
        { "msn", "pop3.email.msn.com", "smtp.email.msn.com", "pop",
 
94
          CAMEL_NETWORK_SECURITY_METHOD_NONE, "@", "@"},
 
95
        { "hotmail", "pop3.live.com", "smtp.live.com", "pop",
 
96
          CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT, "@", "@"},
 
97
        { "live.com", "pop3.live.com", "smtp.live.com", "pop",
 
98
          CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT, "@", "@"},
88
99
 
89
100
};
90
101
 
93
104
        EMConfigItem item;
94
105
 
95
106
        /* Only CAMEL_PROVIDER_CONF_ENTRYs GtkEntrys are stored here.
96
 
           The auto-detect camel provider code will probably be removed */
 
107
         * The auto-detect camel provider code will probably be removed */
97
108
        GHashTable *extra_table;
98
109
};
99
110
 
136
147
        GList *auth_types;      /* if "Check supported" */
137
148
        CamelProvider *provider;
138
149
        CamelProviderType type;
 
150
        CamelSettings *settings;
139
151
 
140
152
        gint auth_changed_id;
141
153
} EMAccountEditorService;
203
215
        GHashTable *widgets;
204
216
 
205
217
        /* for assistant page preparation */
206
 
        guint identity_set:1;
207
 
        guint receive_set:1;
208
 
        guint send_set:1;
209
 
        guint management_set:1;
 
218
        guint identity_set : 1;
 
219
        guint receive_set : 1;
 
220
        guint send_set : 1;
 
221
        guint management_set : 1;
210
222
 
211
223
        ServerData *selected_server;
212
224
};
222
234
static void em_account_editor_construct (EMAccountEditor *emae, EMAccountEditorType type, const gchar *id);
223
235
static void emae_account_folder_changed (EMFolderSelectionButton *folder, EMAccountEditor *emae);
224
236
static ServerData * emae_check_servers (const gchar *email);
225
 
static void set_provider_defaults_on_url (EMAccountEditor *emae, CamelProvider *provider, CamelURL *url);
226
237
 
227
238
static gpointer parent_class;
228
239
 
356
367
                priv->original_account = NULL;
357
368
        }
358
369
 
 
370
        if (priv->source.settings != NULL) {
 
371
                g_object_unref (priv->source.settings);
 
372
                priv->source.settings = NULL;
 
373
        }
 
374
 
 
375
        if (priv->transport.settings != NULL) {
 
376
                g_object_unref (priv->transport.settings);
 
377
                priv->transport.settings = NULL;
 
378
        }
 
379
 
359
380
        /* Chain up to parent's dispose() method. */
360
381
        G_OBJECT_CLASS (parent_class)->dispose (object);
361
382
}
560
581
 
561
582
/* ********************************************************************** */
562
583
 
563
 
static struct {
564
 
        const gchar *label;
565
 
        const gchar *value;
566
 
} ssl_options[] = {
567
 
        /* Translators: This string is a "Use secure connection" option for
568
 
           the Mailer. It will not use an encrypted connection. */
569
 
        { N_("No encryption"), "never" },
570
 
        /* Translators: This string is a "Use secure connection" option for
571
 
           the Mailer. TLS (Transport Layer Security) is commonly known by
572
 
           this abbreviation. */
573
 
        { N_("TLS encryption"), "when-possible" },
574
 
        /* Translators: This string is a "Use secure connection" option for
575
 
           the Mailer. SSL (Secure Sockets Layer) is commonly known by this
576
 
           abbreviation. */
577
 
        { N_("SSL encryption"), "always" }
578
 
};
579
 
 
580
584
static gboolean
581
585
is_email (const gchar *address)
582
586
{
583
587
        /* This is supposed to check if the address's domain could be
584
 
           an FQDN but alas, it's not worth the pain and suffering. */
 
588
         * an FQDN but alas, it's not worth the pain and suffering. */
585
589
        const gchar *at;
586
590
 
587
591
        at = strchr (address, '@');
593
597
}
594
598
 
595
599
static CamelURL *
596
 
emae_account_url (EMAccountEditor *emae, gint urlid)
 
600
emae_account_url (EMAccountEditor *emae,
 
601
                  gint urlid)
597
602
{
598
603
        EAccount *account;
599
604
        CamelURL *url = NULL;
616
621
/* ********************************************************************** */
617
622
 
618
623
static void
619
 
default_folders_clicked (GtkButton *button, gpointer user_data)
 
624
default_folders_clicked (GtkButton *button,
 
625
                         gpointer user_data)
620
626
{
621
627
        EMAccountEditor *emae = user_data;
622
628
        const gchar *uri;
634
640
}
635
641
 
636
642
/* The camel provider auto-detect interface should be deprecated.
637
 
   But it still needs to be replaced with something of similar functionality.
638
 
   Just using the normal econfig plugin mechanism should be adequate. */
 
643
 * But it still needs to be replaced with something of similar functionality.
 
644
 * Just using the normal econfig plugin mechanism should be adequate. */
639
645
static void
640
 
emae_auto_detect_free (gpointer key, gpointer value, gpointer user_data)
 
646
emae_auto_detect_free (gpointer key,
 
647
                       gpointer value,
 
648
                       gpointer user_data)
641
649
{
642
650
        g_free (key);
643
651
        g_free (value);
681
689
                g_return_if_fail (entries[i].type == CAMEL_PROVIDER_CONF_ENTRY);
682
690
 
683
691
                w = NULL;
684
 
                for (l = emae->priv->extra_items;l;l=g_slist_next (l)) {
 
692
                for (l = emae->priv->extra_items; l; l = g_slist_next (l)) {
685
693
                        item = l->data;
686
694
                        if (item->extra_table && (w = g_hash_table_lookup (item->extra_table, entries[i].name)))
687
695
                                break;
695
703
}
696
704
 
697
705
static gint
698
 
provider_compare (const CamelProvider *p1, const CamelProvider *p2)
 
706
provider_compare (const CamelProvider *p1,
 
707
                  const CamelProvider *p2)
699
708
{
700
709
        /* sort providers based on "location" (ie. local or remote) */
701
710
        if (p1->flags & CAMEL_PROVIDER_IS_REMOTE) {
710
719
}
711
720
 
712
721
static void
713
 
emae_signature_added (ESignatureList *signatures, ESignature *sig, EMAccountEditor *emae)
 
722
emae_signature_added (ESignatureList *signatures,
 
723
                      ESignature *sig,
 
724
                      EMAccountEditor *emae)
714
725
{
715
726
        GtkTreeModel *model;
716
727
        GtkTreeIter iter;
725
736
        gtk_list_store_append ((GtkListStore *) model, &iter);
726
737
        gtk_list_store_set ((GtkListStore *) model, &iter, 0, name, 1, uid, -1);
727
738
 
728
 
        gtk_combo_box_set_active (emae->priv->signatures_dropdown, gtk_tree_model_iter_n_children (model, NULL)-1);
 
739
        gtk_combo_box_set_active (
 
740
                emae->priv->signatures_dropdown,
 
741
                gtk_tree_model_iter_n_children (model, NULL) - 1);
729
742
}
730
743
 
731
744
static gint
732
 
emae_signature_get_iter (EMAccountEditor *emae, ESignature *sig, GtkTreeModel **modelp, GtkTreeIter *iter)
 
745
emae_signature_get_iter (EMAccountEditor *emae,
 
746
                         ESignature *sig,
 
747
                         GtkTreeModel **modelp,
 
748
                         GtkTreeIter *iter)
733
749
{
734
750
        GtkTreeModel *model;
735
751
        gint found = 0;
755
771
}
756
772
 
757
773
static void
758
 
emae_signature_removed (ESignatureList *signatures, ESignature *sig, EMAccountEditor *emae)
 
774
emae_signature_removed (ESignatureList *signatures,
 
775
                        ESignature *sig,
 
776
                        EMAccountEditor *emae)
759
777
{
760
778
        GtkTreeIter iter;
761
779
        GtkTreeModel *model;
765
783
}
766
784
 
767
785
static void
768
 
emae_signature_changed (ESignatureList *signatures, ESignature *sig, EMAccountEditor *emae)
 
786
emae_signature_changed (ESignatureList *signatures,
 
787
                        ESignature *sig,
 
788
                        EMAccountEditor *emae)
769
789
{
770
790
        GtkTreeIter iter;
771
791
        GtkTreeModel *model;
778
798
}
779
799
 
780
800
static void
781
 
emae_signaturetype_changed (GtkComboBox *dropdown, EMAccountEditor *emae)
 
801
emae_signaturetype_changed (GtkComboBox *dropdown,
 
802
                            EMAccountEditor *emae)
782
803
{
783
804
        EAccount *account;
784
805
        gint id = gtk_combo_box_get_active (dropdown);
799
820
}
800
821
 
801
822
static void
802
 
emae_signature_new (GtkWidget *widget, EMAccountEditor *emae)
 
823
emae_signature_new (GtkWidget *widget,
 
824
                    EMAccountEditor *emae)
803
825
{
804
826
        GtkWidget *editor;
805
827
        gpointer parent;
813
835
}
814
836
 
815
837
static GtkWidget *
816
 
emae_setup_signatures (EMAccountEditor *emae, GtkBuilder *builder)
 
838
emae_setup_signatures (EMAccountEditor *emae,
 
839
                       GtkBuilder *builder)
817
840
{
818
841
        EMAccountEditorPrivate *p = emae->priv;
819
842
        EAccount *account;
820
843
        GtkComboBox *dropdown = (GtkComboBox *)e_builder_get_widget (builder, "signature_dropdown");
821
844
        GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
822
845
        GtkListStore *store;
823
 
        gint i, active=0;
 
846
        gint i, active = 0;
824
847
        GtkTreeIter iter;
825
848
        ESignatureList *signatures;
826
849
        EIterator *it;
885
908
}
886
909
 
887
910
static void
888
 
emae_receipt_policy_changed (GtkComboBox *dropdown, EMAccountEditor *emae)
 
911
emae_receipt_policy_changed (GtkComboBox *dropdown,
 
912
                             EMAccountEditor *emae)
889
913
{
890
914
        EAccount *account;
891
915
        gint id = gtk_combo_box_get_active (dropdown);
905
929
}
906
930
 
907
931
static GtkWidget *
908
 
emae_setup_receipt_policy (EMAccountEditor *emae, GtkBuilder *builder)
 
932
emae_setup_receipt_policy (EMAccountEditor *emae,
 
933
                           GtkBuilder *builder)
909
934
{
910
935
        EAccount *account;
911
936
        GtkComboBox *dropdown = (GtkComboBox *)e_builder_get_widget (builder, "receipt_policy_dropdown");
955
980
}
956
981
 
957
982
static void
958
 
emae_account_entry_changed (GtkEntry *entry, EMAccountEditor *emae)
 
983
emae_account_entry_changed (GtkEntry *entry,
 
984
                            EMAccountEditor *emae)
959
985
{
960
986
        EAccount *account;
961
987
        gchar *text;
973
999
}
974
1000
 
975
1001
static GtkEntry *
976
 
emae_account_entry (EMAccountEditor *emae, const gchar *name, gint item, GtkBuilder *builder)
 
1002
emae_account_entry (EMAccountEditor *emae,
 
1003
                    const gchar *name,
 
1004
                    gint item,
 
1005
                    GtkBuilder *builder)
977
1006
{
978
1007
        EAccount *account;
979
1008
        GtkEntry *entry;
992
1021
}
993
1022
 
994
1023
static void
995
 
emae_account_toggle_changed (GtkToggleButton *toggle, EMAccountEditor *emae)
 
1024
emae_account_toggle_changed (GtkToggleButton *toggle,
 
1025
                             EMAccountEditor *emae)
996
1026
{
997
1027
        EAccount *account;
998
1028
        gboolean active;
1006
1036
}
1007
1037
 
1008
1038
static void
1009
 
emae_account_toggle_widget (EMAccountEditor *emae, GtkToggleButton *toggle, gint item)
 
1039
emae_account_toggle_widget (EMAccountEditor *emae,
 
1040
                            GtkToggleButton *toggle,
 
1041
                            gint item)
1010
1042
{
1011
1043
        EAccount *account;
1012
1044
        gboolean active;
1030
1062
}
1031
1063
 
1032
1064
static GtkToggleButton *
1033
 
emae_account_toggle (EMAccountEditor *emae, const gchar *name, gint item, GtkBuilder *builder)
 
1065
emae_account_toggle (EMAccountEditor *emae,
 
1066
                     const gchar *name,
 
1067
                     gint item,
 
1068
                     GtkBuilder *builder)
1034
1069
{
1035
1070
        GtkToggleButton *toggle;
1036
1071
 
1041
1076
}
1042
1077
 
1043
1078
static void
1044
 
emae_account_spinint_changed (GtkSpinButton *spin, EMAccountEditor *emae)
 
1079
emae_account_spinint_changed (GtkSpinButton *spin,
 
1080
                              EMAccountEditor *emae)
1045
1081
{
1046
1082
        EAccount *account;
1047
1083
        gpointer data;
1055
1091
}
1056
1092
 
1057
1093
static void
1058
 
emae_account_spinint_widget (EMAccountEditor *emae, GtkSpinButton *spin, gint item)
 
1094
emae_account_spinint_widget (EMAccountEditor *emae,
 
1095
                             GtkSpinButton *spin,
 
1096
                             gint item)
1059
1097
{
1060
1098
        EAccount *account;
1061
1099
        gboolean writable;
1078
1116
                G_CALLBACK (emae_account_spinint_changed), emae);
1079
1117
}
1080
1118
 
1081
 
#if 0
1082
 
static GtkSpinButton *
1083
 
emae_account_spinint (EMAccountEditor *emae, const gchar *name, gint item)
1084
 
{
1085
 
        GtkSpinButton *spin;
1086
 
 
1087
 
        spin = (GtkSpinButton *) e_builder_get_widget (emae->priv->xml, name);
1088
 
        emae_account_spinint_widget (emae, spin, item);
1089
 
 
1090
 
        return spin;
1091
 
}
1092
 
#endif
1093
 
 
1094
1119
static void
1095
 
emae_account_folder_changed (EMFolderSelectionButton *folder, EMAccountEditor *emae)
 
1120
emae_account_folder_changed (EMFolderSelectionButton *folder,
 
1121
                             EMAccountEditor *emae)
1096
1122
{
1097
1123
        EAccount *account;
1098
1124
        gpointer data;
1106
1132
}
1107
1133
 
1108
1134
static EMFolderSelectionButton *
1109
 
emae_account_folder (EMAccountEditor *emae, const gchar *name, gint item, gint deffolder, GtkBuilder *builder)
 
1135
emae_account_folder (EMAccountEditor *emae,
 
1136
                     const gchar *name,
 
1137
                     gint item,
 
1138
                     gint deffolder,
 
1139
                     GtkBuilder *builder)
1110
1140
{
1111
1141
        EAccount *account;
1112
1142
        EMFolderSelectionButton *folder;
1163
1193
}
1164
1194
 
1165
1195
static void
1166
 
smime_sign_key_selected (GtkWidget *dialog, const gchar *key, EMAccountEditor *emae)
 
1196
smime_sign_key_selected (GtkWidget *dialog,
 
1197
                         const gchar *key,
 
1198
                         EMAccountEditor *emae)
1167
1199
{
1168
1200
        EMAccountEditorPrivate *priv = emae->priv;
1169
1201
 
1176
1208
}
1177
1209
 
1178
1210
static void
1179
 
smime_sign_key_select (GtkWidget *button, EMAccountEditor *emae)
 
1211
smime_sign_key_select (GtkWidget *button,
 
1212
                       EMAccountEditor *emae)
1180
1213
{
1181
1214
        EMAccountEditorPrivate *priv = emae->priv;
1182
1215
        GtkWidget *w;
1189
1222
}
1190
1223
 
1191
1224
static void
1192
 
smime_sign_key_clear (GtkWidget *w, EMAccountEditor *emae)
 
1225
smime_sign_key_clear (GtkWidget *w,
 
1226
                      EMAccountEditor *emae)
1193
1227
{
1194
1228
        EMAccountEditorPrivate *priv = emae->priv;
1195
1229
 
1198
1232
}
1199
1233
 
1200
1234
static void
1201
 
smime_encrypt_key_selected (GtkWidget *dialog, const gchar *key, EMAccountEditor *emae)
 
1235
smime_encrypt_key_selected (GtkWidget *dialog,
 
1236
                            const gchar *key,
 
1237
                            EMAccountEditor *emae)
1202
1238
{
1203
1239
        EMAccountEditorPrivate *priv = emae->priv;
1204
1240
 
1211
1247
}
1212
1248
 
1213
1249
static void
1214
 
smime_encrypt_key_select (GtkWidget *button, EMAccountEditor *emae)
 
1250
smime_encrypt_key_select (GtkWidget *button,
 
1251
                          EMAccountEditor *emae)
1215
1252
{
1216
1253
        EMAccountEditorPrivate *priv = emae->priv;
1217
1254
        GtkWidget *w;
1224
1261
}
1225
1262
 
1226
1263
static void
1227
 
smime_encrypt_key_clear (GtkWidget *w, EMAccountEditor *emae)
 
1264
smime_encrypt_key_clear (GtkWidget *w,
 
1265
                         EMAccountEditor *emae)
1228
1266
{
1229
1267
        EMAccountEditorPrivate *priv = emae->priv;
1230
1268
 
1234
1272
#endif
1235
1273
 
1236
1274
static void
1237
 
emae_url_set_host (CamelURL *url, const gchar *txt)
 
1275
emae_url_set_host (CamelURL *url,
 
1276
                   const gchar *txt)
1238
1277
{
1239
1278
        gchar *host;
1240
1279
 
1247
1286
}
1248
1287
 
1249
1288
static void
1250
 
emae_url_set_port (CamelURL *url, const gchar *port)
 
1289
emae_url_set_port (CamelURL *url,
 
1290
                   const gchar *port)
1251
1291
{
1252
1292
        if (port && *port)
1253
1293
                camel_url_set_port (url, atoi (port));
1254
1294
}
1255
1295
 
1256
1296
/* This is used to map a funciton which will set on the url a string value.
1257
 
   if widgets[0] is set, it is the entry which will be called against setval ()
1258
 
   We need our own function for host:port decoding, as above */
 
1297
 * if widgets[0] is set, it is the entry which will be called against setval ()
 
1298
 * We need our own function for host:port decoding, as above */
1259
1299
struct _provider_host_info {
1260
1300
        guint32 flag;
1261
1301
        void (*setval)(CamelURL *, const gchar *);
1388
1428
};
1389
1429
 
1390
1430
static void
1391
 
emae_uri_changed (EMAccountEditorService *service, CamelURL *url)
 
1431
emae_uri_changed (EMAccountEditorService *service,
 
1432
                  CamelURL *url)
1392
1433
{
1393
1434
        EAccount *account;
1394
1435
        gchar *uri;
1408
1449
}
1409
1450
 
1410
1451
static void
1411
 
emae_service_url_changed (EMAccountEditorService *service, void (*setval)(CamelURL *, const gchar *), GtkWidget *entry)
 
1452
emae_service_url_changed (EMAccountEditorService *service,
 
1453
                          void (*setval)(CamelURL *, const gchar *),
 
1454
                          GtkWidget *entry)
1412
1455
{
1413
1456
        GtkComboBox *dropdown;
1414
1457
        gint id;
1428
1471
 
1429
1472
        g_strstrip (text);
1430
1473
 
1431
 
        setval (url, (text && text[0])?text:NULL);
 
1474
        setval (url, (text && text[0]) ? text : NULL);
1432
1475
 
1433
1476
        if (text && text[0] && setval == camel_url_set_user) {
1434
1477
                dropdown = service->authtype;
1451
1494
}
1452
1495
 
1453
1496
static void
1454
 
emae_service_url_path_changed (EMAccountEditorService *service, void (*setval)(CamelURL *, const gchar *), GtkWidget *widget)
 
1497
emae_service_url_path_changed (EMAccountEditorService *service,
 
1498
                               void (*setval)(CamelURL *, const gchar *),
 
1499
                               GtkWidget *widget)
1455
1500
{
1456
1501
        GtkComboBox *dropdown;
1457
1502
        gint id;
1462
1507
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
1463
1508
        const gchar *text = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
1464
1509
 
1465
 
        setval (url, (text && text[0])?text:NULL);
 
1510
        setval (url, (text && text[0]) ? text : NULL);
1466
1511
 
1467
1512
        if (text && text[0] && setval == camel_url_set_user) {
1468
1513
                dropdown = service->authtype;
1484
1529
}
1485
1530
 
1486
1531
static void
1487
 
emae_hostname_changed (GtkEntry *entry, EMAccountEditorService *service)
 
1532
emae_hostname_changed (GtkEntry *entry,
 
1533
                       EMAccountEditorService *service)
1488
1534
{
1489
1535
        emae_service_url_changed (service, emae_url_set_host, GTK_WIDGET (entry));
1490
1536
}
1491
1537
 
1492
1538
static void
1493
 
emae_port_changed (EPortEntry *pentry, EMAccountEditorService *service)
 
1539
emae_port_changed (EPortEntry *pentry,
 
1540
                   EMAccountEditorService *service)
1494
1541
{
1495
1542
        emae_service_url_changed (service, emae_url_set_port, GTK_WIDGET (pentry));
1496
1543
}
1497
1544
 
1498
1545
static void
1499
 
emae_username_changed (GtkEntry *entry, EMAccountEditorService *service)
 
1546
emae_username_changed (GtkEntry *entry,
 
1547
                       EMAccountEditorService *service)
1500
1548
{
1501
1549
        emae_service_url_changed (service, camel_url_set_user, GTK_WIDGET (entry));
1502
1550
}
1503
1551
 
1504
1552
static void
1505
 
emae_path_changed (GtkWidget *widget, EMAccountEditorService *service)
 
1553
emae_path_changed (GtkWidget *widget,
 
1554
                   EMAccountEditorService *service)
1506
1555
{
1507
1556
        emae_service_url_path_changed (service, camel_url_set_path, widget);
1508
1557
}
1509
1558
 
1510
 
static gint
1511
 
emae_ssl_update (EMAccountEditorService *service, CamelURL *url)
 
1559
static void
 
1560
emae_ssl_changed (GtkComboBox *dropdown,
 
1561
                  EMAccountEditorService *service)
1512
1562
{
1513
 
        gint id = gtk_combo_box_get_active (service->use_ssl);
1514
 
        GtkTreeModel *model;
1515
 
        GtkTreeIter iter;
1516
 
        gchar *ssl;
1517
 
 
1518
 
        if (id == -1)
1519
 
                return 0;
1520
 
 
1521
 
        model = gtk_combo_box_get_model (service->use_ssl);
1522
 
        if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) {
1523
 
                gtk_tree_model_get (model, &iter, 1, &ssl, -1);
1524
 
                if (!strcmp (ssl, "none"))
1525
 
                        ssl = NULL;
1526
 
 
1527
 
                e_port_entry_security_port_changed (service->port, ssl);
1528
 
 
1529
 
                camel_url_set_param (url, "use_ssl", ssl);
1530
 
                camel_url_set_port (url, e_port_entry_get_port (service->port));
1531
 
                return 1;
1532
 
        }
1533
 
 
1534
 
        return 0;
 
1563
        CamelURL *url;
 
1564
 
 
1565
        url = emae_account_url (
 
1566
                service->emae,
 
1567
                emae_service_info[service->type].account_uri_key);
 
1568
        camel_url_set_port (url, e_port_entry_get_port (service->port));
 
1569
        emae_uri_changed (service, url);
 
1570
        camel_url_free (url);
1535
1571
}
1536
1572
 
1537
1573
static void
1538
 
emae_ssl_changed (GtkComboBox *dropdown, EMAccountEditorService *service)
 
1574
emae_setup_settings (EMAccountEditorService *service)
1539
1575
{
1540
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
1541
 
 
1542
 
        if (emae_ssl_update (service, url))
1543
 
                emae_uri_changed (service, url);
 
1576
        EConfig *config;
 
1577
        EMConfigTargetAccount *target;
 
1578
        CamelServiceClass *class;
 
1579
        GType service_type;
 
1580
        CamelURL *url;
 
1581
 
 
1582
        url = emae_account_url (
 
1583
                service->emae,
 
1584
                emae_service_info[service->type].account_uri_key);
 
1585
 
 
1586
        /* Destroy any old CamelSettings instances.
 
1587
         * Changing CamelProviders invalidates them. */
 
1588
 
 
1589
        if (service->settings != NULL) {
 
1590
                camel_settings_save_to_url (service->settings, url);
 
1591
                g_object_unref (service->settings);
 
1592
                service->settings = NULL;
 
1593
        }
 
1594
 
 
1595
        g_return_if_fail (service->provider != NULL);
 
1596
 
 
1597
        service_type = service->provider->object_types[service->type];
 
1598
        g_return_if_fail (g_type_is_a (service_type, CAMEL_TYPE_SERVICE));
 
1599
 
 
1600
        class = g_type_class_ref (service_type);
 
1601
 
 
1602
        if (g_type_is_a (class->settings_type, CAMEL_TYPE_SETTINGS)) {
 
1603
                service->settings = g_object_new (class->settings_type, NULL);
 
1604
                camel_settings_load_from_url (service->settings, url);
 
1605
        }
 
1606
 
 
1607
        g_type_class_unref (class);
1544
1608
        camel_url_free (url);
 
1609
 
 
1610
        /* If settings implements CamelNetworkSettings, bind the
 
1611
         * "security-method" property to the security combo box
 
1612
         * and to the EPortEntry widget. */
 
1613
        if (CAMEL_IS_NETWORK_SETTINGS (service->settings)) {
 
1614
                g_object_bind_property_full (
 
1615
                        service->settings, "security-method",
 
1616
                        service->use_ssl, "active-id",
 
1617
                        G_BINDING_BIDIRECTIONAL |
 
1618
                        G_BINDING_SYNC_CREATE,
 
1619
                        e_binding_transform_enum_value_to_nick,
 
1620
                        e_binding_transform_enum_nick_to_value,
 
1621
                        NULL, (GDestroyNotify) NULL);
 
1622
 
 
1623
                g_object_bind_property (
 
1624
                        service->settings, "security-method",
 
1625
                        service->port, "security-method",
 
1626
                        G_BINDING_SYNC_CREATE);
 
1627
        }
 
1628
 
 
1629
        /* Update the EConfigTarget so it has the latest CamelSettings. */
 
1630
 
 
1631
        config = E_CONFIG (service->emae->priv->config);
 
1632
        target = (EMConfigTargetAccount *) config->target;
 
1633
 
 
1634
        em_config_target_new_account_update_settings (
 
1635
                config, target, service->emae->priv->source.settings);
1545
1636
}
1546
1637
 
1547
1638
static void
1559
1650
                gint enable;
1560
1651
                GtkWidget *dwidget = NULL;
1561
1652
 
1562
 
                set_provider_defaults_on_url (service->emae, service->provider, url);
 
1653
                emae_setup_settings (service);
1563
1654
 
1564
1655
                camel_url_set_protocol (url, service->provider->protocol);
1565
1656
                gtk_label_set_text (service->description, service->provider->description);
1578
1669
                if (service->port && service->provider->port_entries)
1579
1670
                        e_port_entry_set_camel_entries (service->port, service->provider->port_entries);
1580
1671
 
1581
 
                for (i=0;emae_service_info[service->type].host_info[i].flag;i++) {
 
1672
                for (i = 0; emae_service_info[service->type].host_info[i].flag; i++) {
1582
1673
                        GtkWidget *w;
1583
1674
                        gint hide;
1584
1675
                        struct _provider_host_info *info = &emae_service_info[service->type].host_info[i];
1585
1676
 
1586
1677
                        enable = CAMEL_PROVIDER_ALLOWS (service->provider, info->flag);
1587
1678
                        hide = CAMEL_PROVIDER_HIDDEN (service->provider, info->flag);
1588
 
                        show = (enable && !hide)?gtk_widget_show:gtk_widget_hide;
 
1679
                        show = (enable && !hide) ? gtk_widget_show : gtk_widget_hide;
1589
1680
 
1590
 
                        for (j=0; j < G_N_ELEMENTS (info->widgets); j++) {
 
1681
                        for (j = 0; j < G_N_ELEMENTS (info->widgets); j++) {
1591
1682
                                if (info->widgets[j] && (w = G_STRUCT_MEMBER (GtkWidget *, service, info->widgets[j]))) {
1592
1683
                                        show (w);
1593
1684
                                        if (j == 0) {
1596
1687
 
1597
1688
                                                if (info->setval && !hide) {
1598
1689
                                                        if (GTK_IS_ENTRY (w))
1599
 
                                                                info->setval (url, enable?gtk_entry_get_text ((GtkEntry *) w):NULL);
 
1690
                                                                info->setval (url, enable ? gtk_entry_get_text ((GtkEntry *) w) : NULL);
1600
1691
                                                        else if (E_IS_PORT_ENTRY (w))
1601
1692
                                                                info->setval (url, enable?g_strdup_printf("%i",
1602
 
                                                                                        e_port_entry_get_port (E_PORT_ENTRY (w))):NULL);
 
1693
                                                                                        e_port_entry_get_port (E_PORT_ENTRY (w))) : NULL);
1603
1694
                                                }
1604
1695
                                        }
1605
1696
                                }
1615
1706
                        /* try to keep the authmech from the current url, or clear it */
1616
1707
                        if (url->authmech) {
1617
1708
                                if (service->provider->authtypes) {
1618
 
                                        for (ll = service->provider->authtypes;ll;ll = g_list_next (ll))
 
1709
                                        for (ll = service->provider->authtypes; ll; ll = g_list_next (ll))
1619
1710
                                                if (!strcmp (url->authmech, ((CamelServiceAuthType *) ll->data)->authproto))
1620
1711
                                                        break;
1621
1712
                                        if (ll == NULL)
1636
1727
                old_port = url->port;
1637
1728
                gtk_widget_hide (service->no_ssl);
1638
1729
                if (service->provider->flags & CAMEL_PROVIDER_SUPPORTS_SSL) {
1639
 
                        emae_ssl_update (service, url);
 
1730
                        camel_url_set_port (url, e_port_entry_get_port (service->port));
1640
1731
                        show = gtk_widget_show;
1641
1732
                } else {
1642
 
                        camel_url_set_param (url, "use_ssl", NULL);
1643
1733
                        show = gtk_widget_hide;
1644
1734
                }
1645
1735
                show (service->ssl_frame);
1647
1737
#else
1648
1738
                gtk_widget_hide (service->ssl_hbox);
1649
1739
                gtk_widget_show (service->no_ssl);
1650
 
                camel_url_set_param (url, "use_ssl", NULL);
1651
1740
#endif
1652
1741
 
1653
1742
                /* This must be done AFTER use_ssl is set; changing use_ssl overwrites
1654
 
                   the old port, which could be SSL port, but also could be some special
1655
 
                   port and we would otherwise lost it */
 
1743
                 * the old port, which could be SSL port, but also could be some special
 
1744
                 * port and we would otherwise lost it */
1656
1745
                if (url->port && service->provider->port_entries)
1657
1746
                        e_port_entry_set_port (service->port, old_port);
1658
1747
 
1672
1761
}
1673
1762
 
1674
1763
static void
1675
 
emae_provider_changed (GtkComboBox *dropdown, EMAccountEditorService *service)
 
1764
emae_provider_changed (GtkComboBox *dropdown,
 
1765
                       EMAccountEditorService *service)
1676
1766
{
1677
1767
        gint id = gtk_combo_box_get_active (dropdown);
1678
1768
        GtkTreeModel *model;
1696
1786
}
1697
1787
 
1698
1788
static void
1699
 
emae_refresh_providers (EMAccountEditor *emae, EMAccountEditorService *service)
 
1789
emae_refresh_providers (EMAccountEditor *emae,
 
1790
                        EMAccountEditorService *service)
1700
1791
{
1701
1792
        EAccount *account;
1702
1793
        GtkListStore *store;
1708
1799
        struct _service_info *info = &emae_service_info[service->type];
1709
1800
        const gchar *uri;
1710
1801
        gchar *current = NULL;
1711
 
        const gchar *tmp;
1712
1802
        CamelURL *url;
1713
1803
 
1714
1804
        account = em_account_editor_get_modified_account (emae);
1722
1812
                gint len;
1723
1813
 
1724
1814
                if (colon) {
1725
 
                        len = colon-uri;
1726
 
                        current = g_alloca (len+1);
 
1815
                        len = colon - uri;
 
1816
                        current = g_alloca (len + 1);
1727
1817
                        memcpy (current, uri, len);
1728
1818
                        current[len] = 0;
1729
1819
                }
1744
1834
                i++;
1745
1835
        }
1746
1836
 
1747
 
        for (l=emae->priv->providers; l; l=l->next) {
 
1837
        for (l = emae->priv->providers; l; l = l->next) {
1748
1838
                CamelProvider *provider = l->data;
1749
1839
 
1750
1840
                if (!((strcmp (provider->domain, "mail") == 0
1764
1854
                        CamelURL *url;
1765
1855
 
1766
1856
                        service->provider = provider;
 
1857
                        emae_setup_settings (service);
1767
1858
                        active = i;
1768
1859
 
1769
1860
                        url = emae_account_url (emae, info->account_uri_key);
1772
1863
                                camel_url_set_protocol (url, provider->protocol);
1773
1864
                        }
1774
1865
 
1775
 
                        set_provider_defaults_on_url (emae, provider, url);
1776
1866
                        emae_uri_changed (service, url);
1777
1867
                        uri = e_account_get_string (account, info->account_uri_key);
1778
1868
                        camel_url_free (url);
1794
1884
                return;
1795
1885
        }
1796
1886
 
1797
 
        tmp = camel_url_get_param (url, "use_ssl");
1798
 
        if (tmp == NULL)
1799
 
                tmp = "never";
1800
 
        for (i=0;i<G_N_ELEMENTS (ssl_options);i++) {
1801
 
                if (!strcmp (ssl_options[i].value, tmp)) {
1802
 
                        gtk_combo_box_set_active (service->use_ssl, i);
1803
 
                        break;
1804
 
                }
1805
 
        }
1806
 
 
1807
1887
        camel_url_free (url);
1808
1888
}
1809
1889
 
1810
1890
static void
1811
 
emae_authtype_changed (GtkComboBox *dropdown, EMAccountEditorService *service)
 
1891
emae_authtype_changed (GtkComboBox *dropdown,
 
1892
                       EMAccountEditorService *service)
1812
1893
{
1813
1894
        EAccount *account;
1814
1895
        gint id = gtk_combo_box_get_active (dropdown);
1846
1927
}
1847
1928
 
1848
1929
static void
1849
 
emae_needs_auth (GtkToggleButton *toggle, EMAccountEditorService *service)
 
1930
emae_needs_auth (GtkToggleButton *toggle,
 
1931
                 EMAccountEditorService *service)
1850
1932
{
1851
1933
        gint need = gtk_toggle_button_get_active (toggle);
1852
1934
 
1866
1948
static void emae_check_authtype (GtkWidget *w, EMAccountEditorService *service);
1867
1949
 
1868
1950
static void
1869
 
emae_refresh_authtype (EMAccountEditor *emae, EMAccountEditorService *service)
 
1951
emae_refresh_authtype (EMAccountEditor *emae,
 
1952
                       EMAccountEditorService *service)
1870
1953
{
1871
1954
        EAccount *account;
1872
1955
        GtkListStore *store;
1891
1974
                url = camel_url_new (uri, NULL);
1892
1975
 
1893
1976
        if (service->provider) {
1894
 
                for (i=0, l=service->provider->authtypes; l; l=l->next, i++) {
 
1977
                for (i = 0, l = service->provider->authtypes; l; l = l->next, i++) {
1895
1978
                        CamelServiceAuthType *authtype = l->data;
1896
1979
                        gint avail;
1897
1980
 
1898
1981
                        /* if we have some already shown */
1899
1982
                        if (service->auth_types) {
1900
 
                                for (ll = service->auth_types;ll;ll = g_list_next (ll))
 
1983
                                for (ll = service->auth_types; ll; ll = g_list_next (ll))
1901
1984
                                        if (!strcmp (authtype->authproto, ((CamelServiceAuthType *) ll->data)->authproto))
1902
1985
                                                break;
1903
1986
                                avail = ll != NULL;
2002
2085
        GtkWidget *editor;
2003
2086
        gpointer parent;
2004
2087
        gchar *uid;
2005
 
        const gchar *url_string;
 
2088
        gchar *url_string;
 
2089
        CamelURL *url;
2006
2090
        GError *error = NULL;
2007
2091
 
2008
2092
        account = em_account_editor_get_modified_account (service->emae);
2012
2096
        session = e_mail_backend_get_session (backend);
2013
2097
 
2014
2098
        uid = g_strdup_printf ("emae-check-authtype-%p", service);
2015
 
        url_string = e_account_get_string (
 
2099
        url_string = (gchar *) e_account_get_string (
2016
2100
                account, emae_service_info[service->type].account_uri_key);
 
2101
        url = camel_url_new (url_string, NULL);
 
2102
        if (service->settings)
 
2103
                camel_settings_save_to_url (service->settings, url);
 
2104
        url_string = camel_url_to_string (url, 0);
 
2105
        camel_url_free (url);
2017
2106
 
2018
2107
        /* to test on actual data, not on previously used */
2019
2108
        camel_service = camel_session_add_service (
2021
2110
                url_string, service->type, &error);
2022
2111
 
2023
2112
        g_free (uid);
 
2113
        g_free (url_string);
2024
2114
 
2025
2115
        if (editor != NULL)
2026
2116
                parent = gtk_widget_get_toplevel (editor);
2074
2164
        struct _service_info *info = &emae_service_info[service->type];
2075
2165
        CamelURL *url = emae_account_url (emae, info->account_uri_key);
2076
2166
        const gchar *uri;
2077
 
        const gchar *tmp;
2078
 
        gint i;
2079
2167
 
2080
2168
        account = em_account_editor_get_modified_account (emae);
2081
2169
        uri = e_account_get_string (account, info->account_uri_key);
2144
2232
                if (service->provider && (service->provider->url_flags & CAMEL_URL_NEED_PATH_DIR) == 0)
2145
2233
                        action = GTK_FILE_CHOOSER_ACTION_OPEN;
2146
2234
 
 
2235
                if (service->pathlabel)
 
2236
                        gtk_label_set_text_with_mnemonic (GTK_LABEL (service->pathlabel),
 
2237
                                action == GTK_FILE_CHOOSER_ACTION_OPEN ? _("Fil_e:") : _("_Path:"));
 
2238
 
2147
2239
                if (action != gtk_file_chooser_get_action (GTK_FILE_CHOOSER (service->pathentry)))
2148
2240
                        gtk_file_chooser_set_action (GTK_FILE_CHOOSER (service->pathentry), action);
2149
2241
 
2151
2243
                        gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (service->pathentry), url->path);
2152
2244
        }
2153
2245
 
2154
 
        tmp = camel_url_get_param (url, "use_ssl");
2155
 
        if (tmp == NULL)
2156
 
                tmp = "never";
2157
 
 
2158
 
        for (i=0;i<G_N_ELEMENTS (ssl_options);i++) {
2159
 
                if (!strcmp (ssl_options[i].value, tmp)) {
2160
 
                        gtk_combo_box_set_active (service->use_ssl, i);
2161
 
                        break;
2162
 
                }
2163
 
        }
 
2246
        /* old authtype will be destroyed when we exit */
 
2247
        emae_refresh_providers (emae, service);
 
2248
        emae_refresh_authtype (emae, service);
2164
2249
 
2165
2250
        /* Set the port after SSL is set, because it would overwrite the
2166
 
           port value (through emae_ssl_changed signal) */
 
2251
         * port value (through emae_ssl_changed signal) */
2167
2252
        if (url->port && service->provider->port_entries) {
2168
2253
                e_port_entry_set_port (service->port, url->port);
2169
2254
        }
2170
2255
 
2171
 
        /* old authtype will be destroyed when we exit */
2172
 
        emae_refresh_providers (emae, service);
2173
 
        emae_refresh_authtype (emae, service);
2174
 
 
2175
2256
        if (service->needs_auth != NULL) {
2176
2257
                gtk_toggle_button_set_active (service->needs_auth, url->authmech != NULL);
2177
2258
                g_signal_connect (service->needs_auth, "toggled", G_CALLBACK(emae_needs_auth), service);
2258
2339
};
2259
2340
 
2260
2341
static void
2261
 
emae_queue_widgets (EMAccountEditor *emae, GtkBuilder *builder, const gchar *first, ...)
 
2342
emae_queue_widgets (EMAccountEditor *emae,
 
2343
                    GtkBuilder *builder,
 
2344
                    const gchar *first,
 
2345
                    ...)
2262
2346
{
2263
2347
        va_list ap;
2264
2348
 
2299
2383
        e_load_ui_builder_definition (builder, "mail-config.ui");
2300
2384
 
2301
2385
        /* Management & Identity fields, in the assistant the management frame is relocated to the last page later on */
2302
 
        for (i=0;i<G_N_ELEMENTS (emae_identity_entries);i++)
 
2386
        for (i = 0; i < G_N_ELEMENTS (emae_identity_entries); i++)
2303
2387
                priv->identity_entries[i] = emae_account_entry (emae, emae_identity_entries[i].name, emae_identity_entries[i].item, builder);
2304
2388
 
2305
2389
        priv->management_frame = e_builder_get_widget (builder, "management-section");
2417
2501
        return w;
2418
2502
}
2419
2503
 
2420
 
static void
2421
 
emae_option_toggle_changed (GtkToggleButton *toggle,
2422
 
                            EMAccountEditorService *service)
2423
 
{
2424
 
        const gchar *name = g_object_get_data ((GObject *)toggle, "option-name");
2425
 
        GSList *depl = g_object_get_data ((GObject *)toggle, "dependent-list");
2426
 
        gint active = gtk_toggle_button_get_active (toggle);
2427
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2428
 
 
2429
 
        for (;depl;depl = g_slist_next (depl))
2430
 
                gtk_widget_set_sensitive ((GtkWidget *) depl->data, active);
2431
 
 
2432
 
        camel_url_set_param (url, name, active?"":NULL);
2433
 
        emae_uri_changed (service, url);
2434
 
        camel_url_free (url);
2435
 
}
2436
 
 
2437
2504
static GtkWidget *
2438
2505
emae_option_toggle (EMAccountEditorService *service,
2439
 
                    CamelURL *url,
2440
 
                    const gchar *text,
2441
 
                    const gchar *name)
2442
 
{
2443
 
        GtkWidget *w;
2444
 
 
2445
 
        w = gtk_check_button_new_with_mnemonic (text);
2446
 
        g_object_set_data ((GObject *)w, "option-name", (gpointer)name);
2447
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), camel_url_get_param (url, name) != NULL);
2448
 
        g_signal_connect (w, "toggled", G_CALLBACK(emae_option_toggle_changed), service);
2449
 
        gtk_widget_show (w);
2450
 
 
2451
 
        return w;
2452
 
}
2453
 
 
2454
 
static void
2455
 
emae_option_entry_changed (GtkEntry *entry,
2456
 
                           EMAccountEditorService *service)
2457
 
{
2458
 
        const gchar *name = g_object_get_data ((GObject *)entry, "option-name");
2459
 
        const gchar *text = gtk_entry_get_text (entry);
2460
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2461
 
 
2462
 
        camel_url_set_param (url, name, text && text[0]?text:NULL);
2463
 
        emae_uri_changed (service, url);
2464
 
        camel_url_free (url);
 
2506
                    CamelProviderConfEntry *conf)
 
2507
{
 
2508
        GtkWidget *widget;
 
2509
 
 
2510
        widget = gtk_check_button_new_with_mnemonic (conf->text);
 
2511
 
 
2512
        g_object_bind_property (
 
2513
                service->settings, conf->name,
 
2514
                widget, "active",
 
2515
                G_BINDING_BIDIRECTIONAL |
 
2516
                G_BINDING_SYNC_CREATE);
 
2517
 
 
2518
        if (conf->depname != NULL) {
 
2519
                g_object_bind_property (
 
2520
                        service->settings, conf->depname,
 
2521
                        widget, "sensitive",
 
2522
                        G_BINDING_SYNC_CREATE);
 
2523
                gtk_widget_set_margin_left (widget, INDENT_MARGIN);
 
2524
        }
 
2525
 
 
2526
        return widget;
2465
2527
}
2466
2528
 
2467
2529
static GtkWidget *
2468
2530
emae_option_entry (EMAccountEditorService *service,
2469
 
                   CamelURL *url,
2470
 
                   const gchar *name,
 
2531
                   CamelProviderConfEntry *conf,
2471
2532
                   GtkLabel *label_for_mnemonic)
2472
2533
{
2473
2534
        GtkWidget *widget;
2474
 
        const gchar *val = camel_url_get_param (url, name);
2475
 
 
2476
 
        if (val == NULL)
2477
 
                val = "";
2478
 
 
2479
 
        widget = g_object_new (GTK_TYPE_ENTRY, "text", val, NULL);
 
2535
 
 
2536
        widget = gtk_entry_new ();
2480
2537
        gtk_label_set_mnemonic_widget (label_for_mnemonic, widget);
2481
 
        g_object_set_data (G_OBJECT (widget), "option-name", (gpointer) name);
2482
 
        g_signal_connect (
2483
 
                widget, "changed",
2484
 
                G_CALLBACK (emae_option_entry_changed), service);
2485
 
        gtk_widget_show (widget);
 
2538
 
 
2539
        g_object_bind_property (
 
2540
                service->settings, conf->name,
 
2541
                widget, "text",
 
2542
                G_BINDING_BIDIRECTIONAL |
 
2543
                G_BINDING_SYNC_CREATE);
 
2544
 
 
2545
        if (conf->depname != NULL) {
 
2546
                g_object_bind_property (
 
2547
                        service->settings, conf->depname,
 
2548
                        widget, "sensitive",
 
2549
                        G_BINDING_SYNC_CREATE);
 
2550
                gtk_widget_set_margin_left (
 
2551
                        GTK_WIDGET (label_for_mnemonic), INDENT_MARGIN);
 
2552
        }
 
2553
 
 
2554
        g_object_bind_property (
 
2555
                widget, "sensitive",
 
2556
                label_for_mnemonic, "sensitive",
 
2557
                G_BINDING_SYNC_CREATE);
2486
2558
 
2487
2559
        return widget;
2488
2560
}
2489
2561
 
2490
 
static void
2491
 
emae_option_checkspin_changed (GtkSpinButton *spin,
2492
 
                               EMAccountEditorService *service)
2493
 
{
2494
 
        const gchar *name = g_object_get_data ((GObject *)spin, "option-name");
2495
 
        gchar value[16];
2496
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2497
 
 
2498
 
        sprintf (value, "%d", gtk_spin_button_get_value_as_int (spin));
2499
 
        camel_url_set_param (url, name, value);
2500
 
        emae_uri_changed (service, url);
2501
 
        camel_url_free (url);
2502
 
}
2503
 
 
2504
 
static void
2505
 
emae_option_checkspin_check_changed (GtkToggleButton *toggle,
2506
 
                                     EMAccountEditorService *service)
2507
 
{
2508
 
        const gchar *name = g_object_get_data ((GObject *)toggle, "option-name");
2509
 
        GtkSpinButton *spin = g_object_get_data ((GObject *)toggle, "option-target");
2510
 
 
2511
 
        if (gtk_toggle_button_get_active (toggle)) {
2512
 
                gtk_widget_set_sensitive ((GtkWidget *) spin, TRUE);
2513
 
                emae_option_checkspin_changed (spin, service);
2514
 
        } else {
2515
 
                CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2516
 
 
2517
 
                camel_url_set_param (url, name, NULL);
2518
 
                gtk_widget_set_sensitive ((GtkWidget *) spin, FALSE);
2519
 
                emae_uri_changed (service, url);
2520
 
                camel_url_free (url);
2521
 
        }
2522
 
}
2523
 
 
2524
 
static void
2525
 
parse_checkspin_format (const gchar *str,
2526
 
                        gboolean *on_ret,
2527
 
                        gdouble *min_ret,
2528
 
                        gdouble *def_ret,
2529
 
                        gdouble *max_ret)
2530
 
{
2531
 
        gchar on;
2532
 
 
2533
 
        /* FIXME: this is a fugly api. */
2534
 
        if (str == NULL
2535
 
            || sscanf (str, "%c:%lf:%lf:%lf", &on, min_ret, def_ret, max_ret) != 4) {
2536
 
                *on_ret = FALSE; /* FIXME: we could do better error handling here... */
2537
 
                *min_ret = 0.0;
2538
 
                *def_ret = 0.0;
2539
 
                *max_ret = 1.0;
2540
 
                return;
2541
 
        }
2542
 
 
2543
 
        *on_ret = (on == 'y');
2544
 
}
2545
 
 
2546
2562
static GtkWidget *
2547
2563
emae_option_checkspin (EMAccountEditorService *service,
2548
 
                       CamelURL *url,
2549
 
                       const gchar *name,
2550
 
                       const gchar *fmt,
2551
 
                       const gchar *info)
 
2564
                       CamelProviderConfEntry *conf)
2552
2565
{
2553
 
        GtkWidget *hbox, *check, *spin, *label = NULL;
2554
 
        gdouble min, def, max;
 
2566
        GObjectClass *class;
 
2567
        GParamSpec *pspec;
 
2568
        GParamSpec *use_pspec;
 
2569
        GtkAdjustment *adjustment;
 
2570
        GtkWidget *hbox, *spin;
 
2571
        GtkWidget *prefix;
 
2572
        gchar *use_property_name;
2555
2573
        gchar *pre, *post;
2556
 
        const gchar *val;
2557
 
        gboolean on;
2558
 
 
2559
 
        pre = g_alloca (strlen (fmt)+1);
2560
 
        strcpy (pre, fmt);
 
2574
 
 
2575
        /* The conf->name property (e.g. "foo") should be numeric for the
 
2576
         * spin button.  If a "use" boolean property exists (e.g. "use-foo")
 
2577
         * then a checkbox is also shown. */
 
2578
 
 
2579
        g_return_val_if_fail (conf->name != NULL, NULL);
 
2580
 
 
2581
        class = G_OBJECT_GET_CLASS (service->settings);
 
2582
        pspec = g_object_class_find_property (class, conf->name);
 
2583
        g_return_val_if_fail (pspec != NULL, NULL);
 
2584
 
 
2585
        use_property_name = g_strconcat ("use-", conf->name, NULL);
 
2586
        use_pspec = g_object_class_find_property (class, use_property_name);
 
2587
        if (use_pspec != NULL && use_pspec->value_type != G_TYPE_BOOLEAN)
 
2588
                use_pspec = NULL;
 
2589
        g_free (use_property_name);
 
2590
 
 
2591
        /* Make sure we can convert to and from doubles. */
 
2592
        g_return_val_if_fail (
 
2593
                g_value_type_transformable (
 
2594
                pspec->value_type, G_TYPE_DOUBLE), NULL);
 
2595
        g_return_val_if_fail (
 
2596
                g_value_type_transformable (
 
2597
                G_TYPE_DOUBLE, pspec->value_type), NULL);
 
2598
 
 
2599
        if (G_IS_PARAM_SPEC_CHAR (pspec)) {
 
2600
                GParamSpecChar *pspec_char;
 
2601
                pspec_char = G_PARAM_SPEC_CHAR (pspec);
 
2602
                adjustment = gtk_adjustment_new (
 
2603
                        (gdouble) pspec_char->default_value,
 
2604
                        (gdouble) pspec_char->minimum,
 
2605
                        (gdouble) pspec_char->maximum,
 
2606
                        1.0, 1.0, 0.0);
 
2607
 
 
2608
        } else if (G_IS_PARAM_SPEC_UCHAR (pspec)) {
 
2609
                GParamSpecUChar *pspec_uchar;
 
2610
                pspec_uchar = G_PARAM_SPEC_UCHAR (pspec);
 
2611
                adjustment = gtk_adjustment_new (
 
2612
                        (gdouble) pspec_uchar->default_value,
 
2613
                        (gdouble) pspec_uchar->minimum,
 
2614
                        (gdouble) pspec_uchar->maximum,
 
2615
                        1.0, 1.0, 0.0);
 
2616
 
 
2617
        } else if (G_IS_PARAM_SPEC_INT (pspec)) {
 
2618
                GParamSpecInt *pspec_int;
 
2619
                pspec_int = G_PARAM_SPEC_INT (pspec);
 
2620
                adjustment = gtk_adjustment_new (
 
2621
                        (gdouble) pspec_int->default_value,
 
2622
                        (gdouble) pspec_int->minimum,
 
2623
                        (gdouble) pspec_int->maximum,
 
2624
                        1.0, 1.0, 0.0);
 
2625
 
 
2626
        } else if (G_IS_PARAM_SPEC_UINT (pspec)) {
 
2627
                GParamSpecUInt *pspec_uint;
 
2628
                pspec_uint = G_PARAM_SPEC_UINT (pspec);
 
2629
                adjustment = gtk_adjustment_new (
 
2630
                        (gdouble) pspec_uint->default_value,
 
2631
                        (gdouble) pspec_uint->minimum,
 
2632
                        (gdouble) pspec_uint->maximum,
 
2633
                        1.0, 1.0, 0.0);
 
2634
 
 
2635
        } else if (G_IS_PARAM_SPEC_LONG (pspec)) {
 
2636
                GParamSpecLong *pspec_long;
 
2637
                pspec_long = G_PARAM_SPEC_LONG (pspec);
 
2638
                adjustment = gtk_adjustment_new (
 
2639
                        (gdouble) pspec_long->default_value,
 
2640
                        (gdouble) pspec_long->minimum,
 
2641
                        (gdouble) pspec_long->maximum,
 
2642
                        1.0, 1.0, 0.0);
 
2643
 
 
2644
        } else if (G_IS_PARAM_SPEC_ULONG (pspec)) {
 
2645
                GParamSpecULong *pspec_ulong;
 
2646
                pspec_ulong = G_PARAM_SPEC_ULONG (pspec);
 
2647
                adjustment = gtk_adjustment_new (
 
2648
                        (gdouble) pspec_ulong->default_value,
 
2649
                        (gdouble) pspec_ulong->minimum,
 
2650
                        (gdouble) pspec_ulong->maximum,
 
2651
                        1.0, 1.0, 0.0);
 
2652
 
 
2653
        } else if (G_IS_PARAM_SPEC_FLOAT (pspec)) {
 
2654
                GParamSpecFloat *pspec_float;
 
2655
                pspec_float = G_PARAM_SPEC_FLOAT (pspec);
 
2656
                adjustment = gtk_adjustment_new (
 
2657
                        (gdouble) pspec_float->default_value,
 
2658
                        (gdouble) pspec_float->minimum,
 
2659
                        (gdouble) pspec_float->maximum,
 
2660
                        1.0, 1.0, 0.0);
 
2661
 
 
2662
        } else if (G_IS_PARAM_SPEC_DOUBLE (pspec)) {
 
2663
                GParamSpecDouble *pspec_double;
 
2664
                pspec_double = G_PARAM_SPEC_DOUBLE (pspec);
 
2665
                adjustment = gtk_adjustment_new (
 
2666
                        (gdouble) pspec_double->default_value,
 
2667
                        (gdouble) pspec_double->minimum,
 
2668
                        (gdouble) pspec_double->maximum,
 
2669
                        1.0, 1.0, 0.0);
 
2670
 
 
2671
        } else
 
2672
                g_return_val_if_reached (NULL);
 
2673
 
 
2674
        pre = g_alloca (strlen (conf->text) + 1);
 
2675
        strcpy (pre, conf->text);
2561
2676
        post = strstr (pre, "%s");
2562
 
        if (post) {
2563
 
                *post = 0;
2564
 
                post+=2;
2565
 
        }
2566
 
 
2567
 
        /* FIXME: the following sucks.  The CamelURL may contain a default value
2568
 
         * already (or if it doesn't, it means that the option is turned off).
2569
 
         * However, the URL doesn't have information about the range for the
2570
 
         * value (min, max).  So we need to parse that out of the original
2571
 
         * description for the option from the CamelProvider.
2572
 
         */
2573
 
 
2574
 
        parse_checkspin_format (info, &on, &min, &def, &max);
2575
 
 
2576
 
        val = camel_url_get_param (url, name);
2577
 
        if (val != NULL) {
2578
 
                on = TRUE;
2579
 
                def = strtod (val, NULL);
2580
 
        } else
2581
 
                on = FALSE;
2582
 
 
2583
 
        hbox = gtk_hbox_new (FALSE, 0);
2584
 
        check = g_object_new (gtk_check_button_get_type (), "label", pre, "use_underline", TRUE, "active", on, NULL);
2585
 
 
2586
 
        spin = gtk_spin_button_new ((GtkAdjustment *) gtk_adjustment_new (def, min, max, 1, 1, 0), 1, 0);
2587
 
        if (post) {
2588
 
                label = gtk_label_new_with_mnemonic (post);
2589
 
                gtk_label_set_mnemonic_widget (GTK_LABEL (label), check);
2590
 
        }
2591
 
        gtk_box_pack_start ((GtkBox *) hbox, check, FALSE, TRUE, 0);
2592
 
        gtk_box_pack_start ((GtkBox *) hbox, spin, FALSE, TRUE, 0);
2593
 
        if (label)
2594
 
                gtk_box_pack_start ((GtkBox *) hbox, label, FALSE, TRUE, 4);
2595
 
 
2596
 
        g_object_set_data ((GObject *)spin, "option-name", (gpointer)name);
2597
 
        g_object_set_data ((GObject *)check, "option-name", (gpointer)name);
2598
 
        g_object_set_data ((GObject *)check, "option-target", (gpointer)spin);
2599
 
 
2600
 
        g_signal_connect (spin, "value_changed", G_CALLBACK(emae_option_checkspin_changed), service);
2601
 
        g_signal_connect (check, "toggled", G_CALLBACK(emae_option_checkspin_check_changed), service);
2602
 
 
2603
 
        gtk_widget_show_all (hbox);
 
2677
        if (post != NULL) {
 
2678
                *post = '\0';
 
2679
                post += 2;
 
2680
        }
 
2681
 
 
2682
        hbox = gtk_hbox_new (FALSE, 3);
 
2683
 
 
2684
        if (use_pspec != NULL) {
 
2685
                prefix = gtk_check_button_new_with_mnemonic (pre);
 
2686
 
 
2687
                g_object_bind_property (
 
2688
                        service->settings, use_pspec->name,
 
2689
                        prefix, "active",
 
2690
                        G_BINDING_BIDIRECTIONAL |
 
2691
                        G_BINDING_SYNC_CREATE);
 
2692
        } else {
 
2693
                prefix = gtk_label_new_with_mnemonic (pre);
 
2694
        }
 
2695
        gtk_box_pack_start (GTK_BOX (hbox), prefix, FALSE, TRUE, 0);
 
2696
        gtk_widget_show (prefix);
 
2697
 
 
2698
        spin = gtk_spin_button_new (adjustment, 1.0, 0);
 
2699
        gtk_box_pack_start (GTK_BOX (hbox), spin, FALSE, TRUE, 0);
 
2700
        gtk_widget_show (spin);
 
2701
 
 
2702
        g_object_bind_property (
 
2703
                service->settings, conf->name,
 
2704
                spin, "value",
 
2705
                G_BINDING_BIDIRECTIONAL |
 
2706
                G_BINDING_SYNC_CREATE);
 
2707
 
 
2708
        if (use_pspec != NULL)
 
2709
                g_object_bind_property (
 
2710
                        prefix, "active",
 
2711
                        spin, "sensitive",
 
2712
                        G_BINDING_SYNC_CREATE);
 
2713
 
 
2714
        if (post != NULL) {
 
2715
                GtkWidget *label = gtk_label_new_with_mnemonic (post);
 
2716
                gtk_label_set_mnemonic_widget (GTK_LABEL (label), prefix);
 
2717
                gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
 
2718
                gtk_widget_show (label);
 
2719
        }
 
2720
 
 
2721
        if (conf->depname != NULL) {
 
2722
                g_object_bind_property (
 
2723
                        service->settings, conf->depname,
 
2724
                        hbox, "sensitive",
 
2725
                        G_BINDING_SYNC_CREATE);
 
2726
                gtk_widget_set_margin_left (hbox, INDENT_MARGIN);
 
2727
        }
2604
2728
 
2605
2729
        return hbox;
2606
2730
}
2607
2731
 
2608
 
static void
2609
 
emae_option_options_changed (GtkComboBox *options,
2610
 
                             EMAccountEditorService *service)
2611
 
{
2612
 
        const gchar *name = g_object_get_data (G_OBJECT (options), "option-name");
2613
 
        gchar *value = NULL;
2614
 
        CamelURL *url = emae_account_url (service->emae, emae_service_info[service->type].account_uri_key);
2615
 
        gint id = gtk_combo_box_get_active (options);
2616
 
 
2617
 
        if (id != -1) {
2618
 
                GtkTreeModel *model;
2619
 
                GtkTreeIter iter;
2620
 
 
2621
 
                model = gtk_combo_box_get_model (options);
2622
 
                if (gtk_tree_model_iter_nth_child (model, &iter, NULL, id)) {
2623
 
                        gtk_tree_model_get (model, &iter, 0, &value, -1);
2624
 
                }
2625
 
        }
2626
 
 
2627
 
        camel_url_set_param (url, name, value);
2628
 
        emae_uri_changed (service, url);
2629
 
        camel_url_free (url);
2630
 
        g_free (value);
2631
 
}
2632
 
 
2633
 
/* 'values' is in format "value0:caption0:value2:caption2:...valueN:captionN" */
 
2732
/* 'values' is in format "nick0:caption0:nick1:caption1:...nickN:captionN"
 
2733
 * where 'nick' is the nickname of a GEnumValue belonging to a GEnumClass
 
2734
 * determined by the type of the GObject property named "name". */
2634
2735
static GtkWidget *
2635
2736
emae_option_options (EMAccountEditorService *service,
2636
 
                     CamelURL *url,
2637
 
                     const gchar *name,
2638
 
                     const gchar *values,
 
2737
                     CamelProviderConfEntry *conf,
2639
2738
                     GtkLabel *label)
2640
2739
{
2641
 
        GtkComboBox *w;
 
2740
        GtkWidget *widget;
2642
2741
        GtkListStore *store;
2643
2742
        GtkTreeIter iter;
2644
 
        const gchar *p, *value, *caption;
2645
 
        GtkCellRenderer *cell;
2646
 
        gint active = 0; /* the first item entered is always a default item */
2647
 
        gint i;
2648
 
        const gchar *val = camel_url_get_param (url, name);
2649
 
 
2650
 
        w = GTK_COMBO_BOX (gtk_combo_box_new ());
2651
 
 
2652
 
        /* value and caption */
 
2743
        const gchar *p;
 
2744
        GtkCellRenderer *renderer;
 
2745
 
 
2746
        /* nick and caption */
2653
2747
        store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
2654
2748
 
2655
 
        for (p = values, i = 0; p; i++) {
 
2749
        p = conf->value;
 
2750
        while (p != NULL) {
 
2751
                const gchar *nick;
 
2752
                const gchar *caption;
2656
2753
                gchar *vl, *cp;
2657
2754
 
2658
 
                value = p;
 
2755
                nick = p;
2659
2756
                caption = strchr (p, ':');
2660
2757
                if (caption) {
2661
2758
                        caption++;
2665
2762
                }
2666
2763
                p = strchr (caption, ':');
2667
2764
 
2668
 
                vl = g_strndup (value, caption - value - 1);
 
2765
                vl = g_strndup (nick, caption - nick - 1);
2669
2766
                if (p) {
2670
2767
                        p++;
2671
2768
                        cp = g_strndup (caption, p - caption - 1);
2673
2770
                        cp = g_strdup (caption);
2674
2771
 
2675
2772
                gtk_list_store_append (store, &iter);
2676
 
                gtk_list_store_set (store, &iter, 0, vl, 1, dgettext (service->provider->translation_domain, cp), -1);
2677
 
 
2678
 
                if (val && g_ascii_strcasecmp (val, vl) == 0)
2679
 
                        active = i;
 
2773
                gtk_list_store_set (
 
2774
                        store, &iter, 0, vl, 1, dgettext (
 
2775
                        service->provider->translation_domain, cp), -1);
2680
2776
 
2681
2777
                g_free (vl);
2682
2778
                g_free (cp);
2683
2779
        }
2684
2780
 
2685
 
        gtk_combo_box_set_model (w, (GtkTreeModel *) store);
2686
 
        gtk_combo_box_set_active (w, i > 0 ? active : -1);
2687
 
 
2688
 
        cell = gtk_cell_renderer_text_new ();
2689
 
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (w), cell, TRUE);
2690
 
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (w), cell, "text", 1, NULL);
2691
 
 
2692
 
        gtk_widget_show (GTK_WIDGET (w));
2693
 
 
2694
 
        gtk_label_set_mnemonic_widget (label, GTK_WIDGET (w));
2695
 
 
2696
 
        g_object_set_data (G_OBJECT (w), "option-name", (gpointer)name);
2697
 
        g_signal_connect (w, "changed", G_CALLBACK (emae_option_options_changed), service);
2698
 
 
2699
 
        return GTK_WIDGET (w);
 
2781
        widget = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
 
2782
        gtk_combo_box_set_id_column (GTK_COMBO_BOX (widget), 0);
 
2783
        gtk_widget_show (widget);
 
2784
 
 
2785
        g_object_bind_property_full (
 
2786
                service->settings, conf->name,
 
2787
                widget, "active-id",
 
2788
                G_BINDING_BIDIRECTIONAL |
 
2789
                G_BINDING_SYNC_CREATE,
 
2790
                e_binding_transform_enum_value_to_nick,
 
2791
                e_binding_transform_enum_nick_to_value,
 
2792
                NULL, (GDestroyNotify) NULL);
 
2793
 
 
2794
        renderer = gtk_cell_renderer_text_new ();
 
2795
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, TRUE);
 
2796
        gtk_cell_layout_set_attributes (
 
2797
                GTK_CELL_LAYOUT (widget), renderer, "text", 1, NULL);
 
2798
 
 
2799
        gtk_label_set_mnemonic_widget (label, widget);
 
2800
 
 
2801
        return widget;
2700
2802
}
2701
2803
 
2702
2804
static GtkWidget *
2752
2854
 
2753
2855
        gtk_widget_show_all (box);
2754
2856
 
2755
 
        gtk_table_attach ((GtkTable *) parent, box, 0, 2, row, row+1, GTK_EXPAND|GTK_FILL, 0, 0, 0);
 
2857
        gtk_table_attach ((GtkTable *) parent, box, 0, 2, row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
2756
2858
 
2757
2859
        return box;
2758
2860
}
2768
2870
        EMAccountEditor *emae = data;
2769
2871
        EMAccountEditorService *service;
2770
2872
        struct _receive_options_item *item = (struct _receive_options_item *) eitem;
2771
 
        GtkWidget *widget, *h;
 
2873
        GtkWidget *box;
 
2874
        GtkWidget *widget;
2772
2875
        GtkLabel *label;
2773
2876
        GtkTable *table;
2774
2877
        CamelProviderConfEntry *entries;
2775
 
        GtkWidget *depw;
2776
 
        GSList *depl = NULL, *n;
2777
2878
        guint row;
2778
2879
        GHashTable *extra;
2779
2880
        CamelURL *url;
2821
2922
        table = GTK_TABLE (parent);
2822
2923
        g_object_get (table, "n-rows", &row, NULL);
2823
2924
 
2824
 
        for (;entries[ii].type != CAMEL_PROVIDER_CONF_END && entries[ii].type != CAMEL_PROVIDER_CONF_SECTION_END; ii++) {
2825
 
                if (entries[ii].depname) {
2826
 
                        depw = g_hash_table_lookup (extra, entries[ii].depname);
2827
 
                        if (depw)
2828
 
                                depl = g_object_steal_data ((GObject *)depw, "dependent-list");
2829
 
                } else
2830
 
                        depw = NULL;
2831
 
 
 
2925
        for (; entries[ii].type != CAMEL_PROVIDER_CONF_END && entries[ii].type != CAMEL_PROVIDER_CONF_SECTION_END; ii++) {
2832
2926
                switch (entries[ii].type) {
2833
2927
                case CAMEL_PROVIDER_CONF_SECTION_START:
2834
2928
                case CAMEL_PROVIDER_CONF_SECTION_END:
2835
2929
                        break;
2836
2930
 
2837
2931
                case CAMEL_PROVIDER_CONF_LABEL:
2838
 
                        /* FIXME: This is a hack for exchange connector, labels should be removed from confentry */
 
2932
                        /* FIXME This is a hack for exchange connector,
 
2933
                         *       labels should be removed from confentry. */
2839
2934
                        if (!strcmp (entries[ii].name, "hostname"))
2840
2935
                                label = emae->priv->source.hostlabel;
2841
2936
                        else if (!strcmp (entries[ii].name, "username"))
2843
2938
                        else
2844
2939
                                label = NULL;
2845
2940
 
2846
 
                        if (label != NULL) {
 
2941
                        if (label != NULL)
2847
2942
                                gtk_label_set_text_with_mnemonic (
2848
2943
                                        label, entries[ii].text);
2849
 
                                if (depw)
2850
 
                                        depl = g_slist_prepend (depl, label);
2851
 
                        }
2852
2944
                        break;
2853
2945
 
2854
2946
                case CAMEL_PROVIDER_CONF_CHECKBOX:
2855
 
                        widget = emae_option_toggle (
2856
 
                                service, url, entries[ii].text,
2857
 
                                entries[ii].name);
 
2947
                        widget = emae_option_toggle (service, &entries[ii]);
2858
2948
                        gtk_table_attach (
2859
2949
                                table, widget, 0, 2,
2860
2950
                                row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
 
2951
                        gtk_widget_show (widget);
 
2952
 
2861
2953
                        g_hash_table_insert (
2862
2954
                                extra, (gpointer) entries[ii].name, widget);
2863
 
                        if (depw)
2864
 
                                depl = g_slist_prepend (depl, widget);
 
2955
 
2865
2956
                        row++;
 
2957
 
2866
2958
                        /* HACK: keep_on_server is stored in the e-account,
2867
2959
                         * but is displayed as a properly on the uri, make
2868
2960
                         * sure they track/match here. */
2869
 
                        if (strcmp (entries[ii].name, "keep_on_server") == 0)
 
2961
                        if (strcmp (entries[ii].name, "keep-on-server") == 0)
2870
2962
                                emae_account_toggle_widget (
2871
2963
                                        emae, (GtkToggleButton *) widget,
2872
2964
                                        E_ACCOUNT_SOURCE_KEEP_ON_SERVER);
2873
2965
                        break;
2874
2966
 
2875
2967
                case CAMEL_PROVIDER_CONF_ENTRY:
2876
 
                        widget = g_object_new (
2877
 
                                GTK_TYPE_LABEL,
2878
 
                                "label", entries[ii].text,
2879
 
                                "use_underline", TRUE,
2880
 
                                "xalign", 0.0,
2881
 
                                NULL);
 
2968
                        widget = gtk_label_new_with_mnemonic (entries[ii].text);
 
2969
                        gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
2882
2970
                        gtk_table_attach (
2883
2971
                                table, widget, 0, 1,
2884
2972
                                row, row + 1, GTK_FILL, 0, 0, 0);
2887
2975
                        label = GTK_LABEL (widget);
2888
2976
 
2889
2977
                        widget = emae_option_entry (
2890
 
                                service, url, entries[ii].name, label);
 
2978
                                service, &entries[ii], label);
2891
2979
                        gtk_table_attach (
2892
2980
                                table, widget, 1, 2,
2893
2981
                                row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
 
2982
                        gtk_widget_show (widget);
2894
2983
 
2895
 
                        if (depw) {
2896
 
                                depl = g_slist_prepend (depl, widget);
2897
 
                                depl = g_slist_prepend (depl, label);
2898
 
                        }
2899
2984
                        row++;
 
2985
 
2900
2986
                        /* FIXME This is another hack for
2901
2987
                         *       exchange/groupwise connector. */
2902
2988
                        g_hash_table_insert (
2905
2991
                        break;
2906
2992
 
2907
2993
                case CAMEL_PROVIDER_CONF_CHECKSPIN:
2908
 
                        widget = emae_option_checkspin (
2909
 
                                service, url, entries[ii].name,
2910
 
                                entries[ii].text, entries[ii].value);
 
2994
                        widget = emae_option_checkspin (service, &entries[ii]);
2911
2995
                        gtk_table_attach (
2912
2996
                                table, widget, 0, 2,
2913
2997
                                row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
2914
 
                        if (depw)
2915
 
                                depl = g_slist_prepend (depl, widget);
 
2998
                        gtk_widget_show (widget);
2916
2999
                        row++;
2917
3000
                        break;
2918
3001
 
2919
3002
                case CAMEL_PROVIDER_CONF_OPTIONS:
2920
 
                        h = gtk_hbox_new (FALSE, 4);
 
3003
                        box = gtk_hbox_new (FALSE, 4);
2921
3004
                        gtk_table_attach (
2922
 
                                table, h, 0, 2,
 
3005
                                table, box, 0, 2,
2923
3006
                                row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);
2924
 
                        gtk_widget_show (h);
 
3007
                        gtk_widget_show (box);
2925
3008
 
2926
 
                        widget = g_object_new (
2927
 
                                GTK_TYPE_LABEL,
2928
 
                                "label", entries[ii].text,
2929
 
                                "use_underline", TRUE,
2930
 
                                "xalign", 0.0,
2931
 
                                NULL);
 
3009
                        widget = gtk_label_new_with_mnemonic (entries[ii].text);
 
3010
                        gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
2932
3011
                        gtk_box_pack_start (
2933
 
                                GTK_BOX (h), widget,
2934
 
                                FALSE, FALSE, 0);
 
3012
                                GTK_BOX (box), widget, FALSE, FALSE, 0);
2935
3013
                        gtk_widget_show (widget);
2936
3014
 
2937
3015
                        label = GTK_LABEL (widget);
2938
3016
 
2939
3017
                        widget = emae_option_options (
2940
 
                                service, url, entries[ii].name,
2941
 
                                entries[ii].value, label);
 
3018
                                service, &entries[ii], label);
2942
3019
                        gtk_box_pack_start (
2943
 
                                GTK_BOX (h), widget, FALSE, FALSE, 0);
2944
 
                        if (depw)
2945
 
                                depl = g_slist_prepend (depl, h);
 
3020
                                GTK_BOX (box), widget, FALSE, FALSE, 0);
 
3021
                        gtk_widget_show (widget);
 
3022
 
2946
3023
                        row++;
2947
3024
                        break;
2948
3025
 
2949
3026
                default:
2950
3027
                        break;
2951
3028
                }
2952
 
 
2953
 
                if (depw && depl) {
2954
 
                        gint act = gtk_toggle_button_get_active ((GtkToggleButton *) depw);
2955
 
 
2956
 
                        g_object_set_data_full ((GObject *)depw, "dependent-list", depl, (GDestroyNotify)g_slist_free);
2957
 
                        for (n=depl;n;n=g_slist_next (n))
2958
 
                                gtk_widget_set_sensitive ((GtkWidget *) n->data, act);
2959
 
                }
2960
3029
        }
2961
3030
 
2962
3031
        camel_url_free (url);
2982
3051
 
2983
3052
        /* no transport options page at all for these types of providers */
2984
3053
        if (priv->source.provider && CAMEL_PROVIDER_IS_STORE_AND_TRANSPORT (priv->source.provider)) {
2985
 
                memset (&priv->transport.frame, 0, ((gchar *)&priv->transport.check_dialog)-((gchar *)&priv->transport.frame));
 
3054
                memset (&priv->transport.frame, 0, ((gchar *) &priv->transport.check_dialog) - ((gchar *) &priv->transport.frame));
2986
3055
                return NULL;
2987
3056
        }
2988
3057
 
3030
3099
}
3031
3100
 
3032
3101
static void
3033
 
emae_get_checkable_folder_keys_widgets (EMAccountEditor *emae, guint32 flag, GtkWidget **check, GtkWidget **button, const gchar **param_key)
3034
 
{
3035
 
        g_return_if_fail (emae != NULL);
3036
 
        g_return_if_fail (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER || flag == CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER);
3037
 
 
3038
 
        if (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER) {
3039
 
                if (check) *check = (GtkWidget *) emae->priv->trash_folder_check;
3040
 
                if (button) *button = (GtkWidget *) emae->priv->trash_folder_button;
3041
 
                if (param_key) *param_key = "real_trash_path";
3042
 
        } else {
3043
 
                if (check) *check = (GtkWidget *) emae->priv->junk_folder_check;
3044
 
                if (button) *button = (GtkWidget *) emae->priv->junk_folder_button;
3045
 
                if (param_key) *param_key = "real_junk_path";
3046
 
        }
3047
 
}
3048
 
 
3049
 
static void
3050
 
emae_real_url_toggled (GtkToggleButton *check, EMAccountEditor *emae)
3051
 
{
3052
 
        guint32 flag;
3053
 
        GtkWidget *butt = NULL;
3054
 
        gboolean checked;
3055
 
        const gchar *param_key;
3056
 
 
3057
 
        g_return_if_fail (check != NULL);
3058
 
        g_return_if_fail (emae != NULL);
3059
 
 
3060
 
        if (!gtk_widget_is_sensitive (GTK_WIDGET (check)) || !gtk_widget_get_visible (GTK_WIDGET (check)))
3061
 
                return;
3062
 
 
3063
 
        flag = GPOINTER_TO_INT (g_object_get_data ((GObject *)check, "url-flag"));
3064
 
        g_return_if_fail (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER || flag == CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER);
3065
 
 
3066
 
        emae_get_checkable_folder_keys_widgets (emae, flag, NULL, &butt, &param_key);
3067
 
 
3068
 
        checked = gtk_toggle_button_get_active (check);
3069
 
        gtk_widget_set_sensitive (butt, checked);
3070
 
 
3071
 
        if (!checked) {
3072
 
                CamelURL *url;
3073
 
 
3074
 
                url = emae_account_url (emae, emae_service_info[emae->priv->source.type].account_uri_key);
3075
 
                camel_url_set_param (url, param_key, NULL);
3076
 
                emae_uri_changed (&emae->priv->source, url);
3077
 
                camel_url_free (url);
3078
 
 
3079
 
                /* clear the previous selection */
3080
 
                em_folder_selection_button_set_folder_uri ((EMFolderSelectionButton *)butt, "");
3081
 
        }
3082
 
}
3083
 
 
3084
 
static void
3085
 
emae_real_url_folder_changed (EMFolderSelectionButton *folder,
3086
 
                              EMAccountEditor *emae)
3087
 
{
3088
 
        CamelURL *url;
3089
 
        guint32 flag;
3090
 
        GtkWidget *check = NULL;
3091
 
        const gchar *param_key = NULL, *curi_selected;
3092
 
 
3093
 
        g_return_if_fail (folder != NULL);
3094
 
        g_return_if_fail (emae != NULL);
3095
 
 
3096
 
        if (!gtk_widget_is_sensitive (GTK_WIDGET (folder)) || !gtk_widget_get_visible (GTK_WIDGET (folder)))
3097
 
                return;
3098
 
 
3099
 
        flag = GPOINTER_TO_INT (g_object_get_data ((GObject *)folder, "url-flag"));
3100
 
        g_return_if_fail (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER || flag == CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER);
3101
 
 
3102
 
        emae_get_checkable_folder_keys_widgets (emae, flag, &check, NULL, &param_key);
3103
 
 
3104
 
        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)))
3105
 
                return;
3106
 
 
3107
 
        url = emae_account_url (emae, emae_service_info[emae->priv->source.type].account_uri_key);
3108
 
 
3109
 
        curi_selected = em_folder_selection_button_get_folder_uri (folder);
3110
 
        if (!curi_selected || !*curi_selected) {
3111
 
                camel_url_set_param (url, param_key, NULL);
3112
 
        } else {
3113
 
                gchar *selected_folder_name = NULL;
3114
 
                CamelStore *selected_store = NULL;
3115
 
                EMailBackend *backend;
 
3102
emae_real_url_toggled (GtkToggleButton *check,
 
3103
                       EMFolderSelectionButton *button)
 
3104
{
 
3105
        if (!gtk_toggle_button_get_active (check))
 
3106
                em_folder_selection_button_set_folder_uri (button, "");
 
3107
}
 
3108
 
 
3109
static void
 
3110
set_real_folder_path (GtkButton *folder_button,
 
3111
                      CamelSettings *settings,
 
3112
                      const gchar *settings_prop,
 
3113
                      EAccount *account)
 
3114
{
 
3115
        gchar *path = NULL, *uri;
 
3116
        gchar *encoded_name;
 
3117
        gchar *encoded_uid;
 
3118
        const gchar *folder_name;
 
3119
 
 
3120
        g_return_if_fail (folder_button != NULL);
 
3121
        g_return_if_fail (settings != NULL);
 
3122
        g_return_if_fail (settings_prop != NULL);
 
3123
        g_return_if_fail (account != NULL);
 
3124
 
 
3125
        g_object_get (G_OBJECT (settings), settings_prop, &path, NULL);
 
3126
 
 
3127
        if (!path || !*path) {
 
3128
                g_free (path);
 
3129
                return;
 
3130
        }
 
3131
 
 
3132
        folder_name = path;
 
3133
 
 
3134
        /* Skip the leading slash, if present. */
 
3135
        if (*folder_name == '/')
 
3136
                folder_name++;
 
3137
 
 
3138
        encoded_uid = camel_url_encode (account->uid, ":;@/");
 
3139
        encoded_name = camel_url_encode (folder_name, "#");
 
3140
 
 
3141
        uri = g_strdup_printf ("folder://%s/%s", encoded_uid, encoded_name);
 
3142
 
 
3143
        g_free (encoded_uid);
 
3144
        g_free (encoded_name);
 
3145
        g_free (path);
 
3146
 
 
3147
        em_folder_selection_button_set_folder_uri (EM_FOLDER_SELECTION_BUTTON (folder_button), uri);
 
3148
 
 
3149
        g_free (uri);
 
3150
}
 
3151
 
 
3152
static void
 
3153
update_real_folder_cb (GtkButton *folder_button,
 
3154
                       GParamSpec *par_spec,
 
3155
                       EMAccountEditor *emae)
 
3156
{
 
3157
        EMFolderSelectionButton *sel_button;
 
3158
        CamelSettings *settings;
 
3159
        const gchar *prop_name = NULL;
 
3160
        const gchar *folder_uri;
 
3161
        gchar *path = NULL;
 
3162
 
 
3163
        g_return_if_fail (folder_button != NULL);
 
3164
        g_return_if_fail (emae != NULL);
 
3165
        g_return_if_fail (emae->priv != NULL);
 
3166
 
 
3167
        settings = emae->priv->source.settings;
 
3168
        if (folder_button == emae->priv->trash_folder_button)
 
3169
                prop_name = "real-trash-path";
 
3170
        else if (folder_button == emae->priv->junk_folder_button)
 
3171
                prop_name = "real-junk-path";
 
3172
 
 
3173
        g_return_if_fail (prop_name != NULL);
 
3174
 
 
3175
        sel_button = EM_FOLDER_SELECTION_BUTTON (folder_button);
 
3176
        g_return_if_fail (sel_button != NULL);
 
3177
 
 
3178
        folder_uri = em_folder_selection_button_get_folder_uri (sel_button);
 
3179
        if (folder_uri && *folder_uri) {
3116
3180
                EMailSession *session;
3117
 
                gboolean valid;
3118
 
 
3119
 
                backend = em_account_editor_get_backend (emae);
3120
 
                session = e_mail_backend_get_session (backend);
3121
 
 
3122
 
                valid = e_mail_folder_uri_parse (
3123
 
                        CAMEL_SESSION (session), curi_selected,
3124
 
                        &selected_store, &selected_folder_name, NULL);
3125
 
                g_return_if_fail (valid);
3126
 
 
3127
 
                if (*selected_folder_name == '/')
3128
 
                        camel_url_set_param (
3129
 
                                url, param_key, selected_folder_name + 1);
3130
 
                else
3131
 
                        camel_url_set_param (
3132
 
                                url, param_key, selected_folder_name);
3133
 
 
3134
 
                g_free (selected_folder_name);
3135
 
                if (selected_store)
3136
 
                        g_object_unref (selected_store);
3137
 
        }
3138
 
 
3139
 
        emae_uri_changed (&emae->priv->source, url);
3140
 
        camel_url_free (url);
3141
 
}
3142
 
 
3143
 
static void
3144
 
setup_checkable_folder (EMAccountEditor *emae,
3145
 
                        guint32 flag,
3146
 
                        GtkWidget *check,
3147
 
                        GtkWidget *button)
3148
 
{
3149
 
        EAccount *account;
3150
 
        gboolean available;
3151
 
        EMFolderSelectionButton *folderbutt;
3152
 
        CamelURL *url;
3153
 
        const gchar *value, *param_key = NULL;
3154
 
 
3155
 
        g_return_if_fail (emae != NULL);
3156
 
        g_return_if_fail (check != NULL);
3157
 
        g_return_if_fail (button != NULL);
3158
 
        g_return_if_fail (flag == CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER || flag == CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER);
3159
 
 
3160
 
        account = em_account_editor_get_modified_account (emae);
3161
 
        g_return_if_fail (account != NULL);
3162
 
 
3163
 
        folderbutt = EM_FOLDER_SELECTION_BUTTON (button);
3164
 
        url = emae_account_url (emae, emae_service_info[emae->priv->source.type].account_uri_key);
3165
 
 
3166
 
        emae_get_checkable_folder_keys_widgets (emae, flag, NULL, NULL, &param_key);
3167
 
 
3168
 
        value = camel_url_get_param (url, param_key);
3169
 
        available = account->enabled;
3170
 
        gtk_widget_set_sensitive (check, available);
3171
 
 
3172
 
        if (value && *value) {
3173
 
                gchar *url_string = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
3174
 
                if (!url_string) {
3175
 
                        em_folder_selection_button_set_folder_uri (folderbutt, "");
3176
 
                } else {
3177
 
                        CamelURL *copy = camel_url_new (url_string, NULL);
3178
 
 
3179
 
                        if (copy->path)
3180
 
                                g_free (copy->path);
3181
 
                        copy->path = g_strconcat ("/", value, NULL);
3182
 
                        g_free (url_string);
3183
 
 
3184
 
                        url_string = camel_url_to_string (copy, CAMEL_URL_HIDE_ALL);
3185
 
                        em_folder_selection_button_set_folder_uri (folderbutt, url_string ? url_string : "");
3186
 
                        g_free (url_string);
3187
 
                }
3188
 
        } else {
3189
 
                em_folder_selection_button_set_folder_uri (folderbutt, "");
3190
 
        }
3191
 
 
3192
 
        value = em_folder_selection_button_get_folder_uri (folderbutt);
3193
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), value && *value);
3194
 
        gtk_widget_set_sensitive (button, available && value && *value);
3195
 
 
3196
 
        g_object_set_data ((GObject *)check, "url-flag", GINT_TO_POINTER(flag));
3197
 
        g_object_set_data ((GObject *)folderbutt, "url-flag", GINT_TO_POINTER(flag));
3198
 
 
3199
 
        g_signal_connect (check, "toggled", G_CALLBACK (emae_real_url_toggled), emae);
3200
 
        g_signal_connect (folderbutt, "selected", G_CALLBACK (emae_real_url_folder_changed), emae);
3201
 
 
3202
 
        available = emae->priv->source.provider && ((emae->priv->source.provider->flags & flag) == flag);
3203
 
        if (available) {
3204
 
                gtk_widget_show (check);
3205
 
                gtk_widget_show (button);
3206
 
        } else {
3207
 
                gtk_widget_hide (check);
3208
 
                gtk_widget_hide (button);
3209
 
        }
3210
 
 
3211
 
        camel_url_free (url);
 
3181
 
 
3182
                session = e_mail_backend_get_session (em_folder_selection_button_get_backend (sel_button));
 
3183
                if (!e_mail_folder_uri_parse (CAMEL_SESSION (session), folder_uri, NULL, &path, NULL))
 
3184
                        path = NULL;
 
3185
        }
 
3186
 
 
3187
        g_object_set (G_OBJECT (settings), prop_name, path, NULL);
 
3188
        g_free (path);
3212
3189
}
3213
3190
 
3214
3191
static GtkWidget *
3222
3199
        EMAccountEditor *emae = data;
3223
3200
        EMAccountEditorPrivate *priv = emae->priv;
3224
3201
        EMFolderSelectionButton *button;
 
3202
        CamelProviderFlags flags;
 
3203
        CamelSettings *settings;
 
3204
        CamelStore *store = NULL;
3225
3205
        EMailBackend *backend;
 
3206
        EMailSession *session;
3226
3207
        EAccount *account;
3227
3208
        GtkWidget *widget;
3228
3209
        GtkBuilder *builder;
 
3210
        GParamSpec *pspec;
 
3211
        gboolean visible;
3229
3212
 
3230
3213
        /*if (old)
3231
3214
          return old;*/
3235
3218
        account = em_account_editor_get_modified_account (emae);
3236
3219
        backend = em_account_editor_get_backend (emae);
3237
3220
 
 
3221
        session = e_mail_backend_get_session (backend);
 
3222
 
 
3223
        if (account != NULL) {
 
3224
                CamelService *service;
 
3225
 
 
3226
                service = camel_session_get_service (
 
3227
                        CAMEL_SESSION (session), account->uid);
 
3228
 
 
3229
                if (CAMEL_IS_STORE (service))
 
3230
                        store = CAMEL_STORE (service);
 
3231
        }
 
3232
 
 
3233
        settings = emae->priv->source.settings;
 
3234
 
3238
3235
        /* Make sure we have a valid EMailBackend. */
3239
3236
        g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
3240
3237
 
3259
3256
 
3260
3257
        widget = e_builder_get_widget (builder, "trash_folder_butt");
3261
3258
        button = EM_FOLDER_SELECTION_BUTTON (widget);
3262
 
        em_folder_selection_button_set_account (button, account);
3263
3259
        em_folder_selection_button_set_backend (button, backend);
 
3260
        em_folder_selection_button_set_store (button, store);
3264
3261
        priv->trash_folder_button = GTK_BUTTON (button);
3265
3262
 
3266
 
        setup_checkable_folder (
3267
 
                emae, CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER,
3268
 
                GTK_WIDGET (priv->trash_folder_check),
3269
 
                GTK_WIDGET (priv->trash_folder_button));
 
3263
        g_signal_connect (
 
3264
                priv->trash_folder_check, "toggled",
 
3265
                G_CALLBACK (emae_real_url_toggled),
 
3266
                priv->trash_folder_button);
 
3267
 
 
3268
        g_object_bind_property (
 
3269
                priv->trash_folder_check, "active",
 
3270
                priv->trash_folder_button, "sensitive",
 
3271
                G_BINDING_SYNC_CREATE);
 
3272
 
 
3273
        pspec = !settings ? NULL : g_object_class_find_property (
 
3274
                G_OBJECT_GET_CLASS (settings), "use-real-trash-path");
 
3275
 
 
3276
        if (pspec != NULL)
 
3277
                g_object_bind_property (
 
3278
                        settings, "use-real-trash-path",
 
3279
                        priv->trash_folder_check, "active",
 
3280
                        G_BINDING_BIDIRECTIONAL |
 
3281
                        G_BINDING_SYNC_CREATE);
 
3282
 
 
3283
        pspec = !settings ? NULL : g_object_class_find_property (
 
3284
                G_OBJECT_GET_CLASS (settings), "real-trash-path");
 
3285
 
 
3286
        if (pspec != NULL) {
 
3287
                set_real_folder_path (priv->trash_folder_button, settings, "real-trash-path", account);
 
3288
                g_signal_connect (priv->trash_folder_button, "notify::folder-uri", G_CALLBACK (update_real_folder_cb), emae);
 
3289
        }
 
3290
 
 
3291
        flags = CAMEL_PROVIDER_ALLOW_REAL_TRASH_FOLDER;
 
3292
        visible = (emae->priv->source.provider != NULL) &&
 
3293
                ((emae->priv->source.provider->flags & flags) != 0);
 
3294
        widget = GTK_WIDGET (priv->trash_folder_check);
 
3295
        gtk_widget_set_visible (widget, visible);
 
3296
        widget = GTK_WIDGET (priv->trash_folder_button);
 
3297
        gtk_widget_set_visible (widget, visible);
3270
3298
 
3271
3299
        widget = e_builder_get_widget (builder, "junk_folder_check");
3272
3300
        priv->junk_folder_check = GTK_TOGGLE_BUTTON (widget);
3273
3301
 
3274
3302
        widget = e_builder_get_widget (builder, "junk_folder_butt");
3275
3303
        button = EM_FOLDER_SELECTION_BUTTON (widget);
3276
 
        em_folder_selection_button_set_account (button, account);
3277
3304
        em_folder_selection_button_set_backend (button, backend);
 
3305
        em_folder_selection_button_set_store (button, store);
3278
3306
        priv->junk_folder_button = GTK_BUTTON (button);
3279
3307
 
3280
 
        setup_checkable_folder (
3281
 
                emae, CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER,
3282
 
                GTK_WIDGET (priv->junk_folder_check),
3283
 
                GTK_WIDGET (priv->junk_folder_button));
 
3308
        g_signal_connect (
 
3309
                priv->junk_folder_check, "toggled",
 
3310
                G_CALLBACK (emae_real_url_toggled),
 
3311
                priv->junk_folder_button);
 
3312
 
 
3313
        g_object_bind_property (
 
3314
                priv->junk_folder_check, "active",
 
3315
                priv->junk_folder_button, "sensitive",
 
3316
                G_BINDING_SYNC_CREATE);
 
3317
 
 
3318
        pspec = !settings ? NULL : g_object_class_find_property (
 
3319
                G_OBJECT_GET_CLASS (settings), "use-real-junk-path");
 
3320
 
 
3321
        if (pspec != NULL)
 
3322
                g_object_bind_property (
 
3323
                        settings, "use-real-junk-path",
 
3324
                        priv->junk_folder_check, "active",
 
3325
                        G_BINDING_BIDIRECTIONAL |
 
3326
                        G_BINDING_SYNC_CREATE);
 
3327
 
 
3328
        pspec = !settings ? NULL : g_object_class_find_property (
 
3329
                G_OBJECT_GET_CLASS (settings), "real-junk-path");
 
3330
 
 
3331
        if (pspec != NULL) {
 
3332
                set_real_folder_path (priv->junk_folder_button, settings, "real-junk-path", account);
 
3333
                g_signal_connect (priv->junk_folder_button, "notify::folder-uri", G_CALLBACK (update_real_folder_cb), emae);
 
3334
        }
 
3335
 
 
3336
        flags = CAMEL_PROVIDER_ALLOW_REAL_JUNK_FOLDER;
 
3337
        visible = (emae->priv->source.provider != NULL) &&
 
3338
                ((emae->priv->source.provider->flags & flags) != 0);
 
3339
        widget = GTK_WIDGET (priv->junk_folder_check);
 
3340
        gtk_widget_set_visible (widget, visible);
 
3341
        widget = GTK_WIDGET (priv->junk_folder_button);
 
3342
        gtk_widget_set_visible (widget, visible);
3284
3343
 
3285
3344
        /* Special Folders "Reset Defaults" button */
3286
3345
        priv->restore_folders_button = (GtkButton *)e_builder_get_widget (builder, "default_folders_button");
3334
3393
}
3335
3394
 
3336
3395
static void
3337
 
emae_account_hash_algo_combo_changed_cb (GtkComboBox *combobox, EMAccountEditor *emae)
 
3396
emae_account_hash_algo_combo_changed_cb (GtkComboBox *combobox,
 
3397
                                         EMAccountEditor *emae)
3338
3398
{
3339
3399
        EAccount *account;
3340
3400
        gpointer data;
3360
3420
}
3361
3421
 
3362
3422
static GtkComboBox *
3363
 
emae_account_hash_algo_combo (EMAccountEditor *emae, const gchar *name, gint item, GtkBuilder *builder)
 
3423
emae_account_hash_algo_combo (EMAccountEditor *emae,
 
3424
                              const gchar *name,
 
3425
                              gint item,
 
3426
                              GtkBuilder *builder)
3364
3427
{
3365
3428
        EAccount *account;
3366
3429
        GtkComboBox *combobox;
3469
3532
 * Allow some level of post creation customisation in plugins.
3470
3533
 */
3471
3534
GtkWidget *
3472
 
em_account_editor_get_widget (EMAccountEditor *emae, const gchar *name)
 
3535
em_account_editor_get_widget (EMAccountEditor *emae,
 
3536
                              const gchar *name)
3473
3537
{
3474
3538
        GtkWidget *wid;
3475
3539
 
3613
3677
static gboolean emae_assistant_items_translated = FALSE;
3614
3678
 
3615
3679
static void
3616
 
emae_free (EConfig *ec, GSList *items, gpointer data)
 
3680
emae_free (EConfig *ec,
 
3681
           GSList *items,
 
3682
           gpointer data)
3617
3683
{
3618
3684
        g_slist_free (items);
3619
3685
}
3620
3686
 
3621
3687
static void
3622
 
emae_free_auto (EConfig *ec, GSList *items, gpointer data)
 
3688
emae_free_auto (EConfig *ec,
 
3689
                GSList *items,
 
3690
                gpointer data)
3623
3691
{
3624
3692
        GSList *l, *n;
3625
3693
 
3626
 
        for (l=items;l;) {
 
3694
        for (l = items; l;) {
3627
3695
                struct _receive_options_item *item = l->data;
3628
3696
 
3629
3697
                n = g_slist_next (l);
3637
3705
}
3638
3706
 
3639
3707
static gboolean
3640
 
emae_service_complete (EMAccountEditor *emae, EMAccountEditorService *service)
 
3708
emae_service_complete (EMAccountEditor *emae,
 
3709
                       EMAccountEditorService *service)
3641
3710
{
3642
3711
        EAccount *account;
3643
3712
        CamelURL *url;
3684
3753
 
3685
3754
        server++;
3686
3755
 
3687
 
        for (i=0; i<len; i++) {
 
3756
        for (i = 0; i < len; i++) {
3688
3757
                if (strstr (server, mail_servers[i].key) != NULL)
3689
3758
                        return &mail_servers[i];
3690
3759
        }
3693
3762
}
3694
3763
 
3695
3764
static void
3696
 
emae_check_set_authtype (GtkComboBox *dropdown, const gchar *auth)
 
3765
emae_check_set_authtype (GtkComboBox *dropdown,
 
3766
                         const gchar *auth)
3697
3767
{
3698
3768
        GtkTreeModel *model;
3699
3769
        GtkTreeIter iter;
3716
3786
}
3717
3787
 
3718
3788
static gboolean
3719
 
emae_check_complete (EConfig *ec, const gchar *pageid, gpointer data)
 
3789
emae_check_complete (EConfig *ec,
 
3790
                     const gchar *pageid,
 
3791
                     gpointer data)
3720
3792
{
3721
3793
        EMAccountEditor *emae = data;
3722
3794
        EAccount *account;
3732
3804
        new_account = (original_account == NULL);
3733
3805
 
3734
3806
        /* We use the page-check of various pages to 'prepare' or
3735
 
           pre-load their values, only in the assistant */
 
3807
         * pre-load their values, only in the assistant */
3736
3808
        if (pageid
3737
3809
            && ((EConfig *) emae->priv->config)->type == E_CONFIG_ASSISTANT) {
3738
3810
                if (!strcmp (pageid, "00.identity")) {
3760
3832
                                emae->priv->receive_set = 1;
3761
3833
                                tmp = (gchar *) e_account_get_string (account, E_ACCOUNT_ID_ADDRESS);
3762
3834
                                at = strchr (tmp, '@');
3763
 
                                user = g_alloca (at-tmp+1);
3764
 
                                memcpy (user, tmp, at-tmp);
3765
 
                                user[at-tmp] = 0;
 
3835
                                user = g_alloca (at - tmp + 1);
 
3836
                                memcpy (user, tmp, at - tmp);
 
3837
                                user[at - tmp] = 0;
3766
3838
                                at++;
3767
3839
 
3768
3840
                                sdata = emae->priv->selected_server = emae->emae_check_servers (tmp);
3775
3847
                                        gtk_entry_set_text (emae->priv->source.username, use_user);
3776
3848
 
3777
3849
                                        if (sdata != NULL) {
 
3850
                                                CamelNetworkSecurityMethod method;
 
3851
                                                if (sdata->recv_security_method != CAMEL_NETWORK_SECURITY_METHOD_NONE)
 
3852
                                                        method = sdata->recv_security_method;
 
3853
                                                else
 
3854
                                                        method = sdata->security_method;
 
3855
                                                g_object_set (emae->priv->source.settings, "security-method", method, NULL);
 
3856
 
3778
3857
                                                camel_url_set_protocol (url, sdata->proto);
3779
 
                                                if (sdata->recv_sock && *sdata->recv_sock)
3780
 
                                                        camel_url_set_param (url, "use_ssl", sdata->recv_sock);
3781
 
                                                else
3782
 
                                                        camel_url_set_param (url, "use_ssl", sdata->ssl);
3783
3858
                                                camel_url_set_host (url, sdata->recv);
3784
3859
                                                if (sdata->recv_port && *sdata->recv_port)
3785
3860
                                                        camel_url_set_port (url, atoi (sdata->recv_port));
3810
3885
                                emae->priv->send_set = 1;
3811
3886
                                tmp = e_account_get_string (account, E_ACCOUNT_ID_ADDRESS);
3812
3887
                                at = strchr (tmp, '@');
3813
 
                                user = g_alloca (at-tmp+1);
3814
 
                                memcpy (user, tmp, at-tmp);
3815
 
                                user[at-tmp] = 0;
 
3888
                                user = g_alloca (at - tmp + 1);
 
3889
                                memcpy (user, tmp, at - tmp);
 
3890
                                user[at - tmp] = 0;
3816
3891
                                at++;
3817
3892
 
3818
3893
                                sdata = emae->priv->selected_server;
3819
3894
                                if (sdata != NULL && uri && (url = camel_url_new (uri, NULL)) != NULL) {
 
3895
                                        CamelNetworkSecurityMethod method;
3820
3896
                                        const gchar *use_user = user;
 
3897
 
3821
3898
                                        refresh = TRUE;
 
3899
 
 
3900
                                        if (sdata->send_security_method != CAMEL_NETWORK_SECURITY_METHOD_NONE)
 
3901
                                                method = sdata->send_security_method;
 
3902
                                        else
 
3903
                                                method = sdata->security_method;
 
3904
                                        g_object_set (emae->priv->transport.settings, "security-method", method, NULL);
 
3905
 
3822
3906
                                        camel_url_set_protocol (url, "smtp");
3823
 
                                        if (sdata->send_sock && *sdata->send_sock)
3824
 
                                                camel_url_set_param (url, "use_ssl", sdata->send_sock);
3825
 
                                        else
3826
 
                                                camel_url_set_param (url, "use_ssl", sdata->ssl);
3827
3907
                                        camel_url_set_host (url, sdata->send);
3828
3908
                                        if (sdata->send_port && *sdata->send_port)
3829
3909
                                                camel_url_set_port (url, atoi (sdata->send_port));
3872
3952
        }
3873
3953
 
3874
3954
        /*
3875
 
           Setting a flag on the Account if it is marked as default. It is done in this way instead of
3876
 
           using a temporary variable so as to keep track of which account is marked as default in case of
3877
 
           editing multiple accounts at a time
 
3955
         * Setting a flag on the Account if it is marked as default. It is done in this way instead of
 
3956
         * using a temporary variable so as to keep track of which account is marked as default in case of
 
3957
         * editing multiple accounts at a time
3878
3958
         */
3879
3959
        if (gtk_toggle_button_get_active (emae->priv->default_account))
3880
3960
                g_object_set_data (G_OBJECT (account), "default_flagged", GINT_TO_POINTER(1));
3929
4009
}
3930
4010
 
3931
4011
gboolean
3932
 
em_account_editor_check (EMAccountEditor *emae, const gchar *page)
 
4012
em_account_editor_check (EMAccountEditor *emae,
 
4013
                         const gchar *page)
3933
4014
{
3934
4015
        return emae_check_complete ((EConfig *) emae->config, page, emae);
3935
4016
}
3936
4017
 
3937
4018
static void
3938
 
forget_password_if_needed (EAccount *original_account, EAccount *modified_account, e_account_item_t save_pass_itm, e_account_item_t url_itm)
 
4019
forget_password_if_needed (EAccount *original_account,
 
4020
                           EAccount *modified_account,
 
4021
                           e_account_item_t save_pass_itm,
 
4022
                           e_account_item_t url_itm)
3939
4023
{
3940
4024
        const gchar *orig_url, *modif_url;
3941
4025
 
3978
4062
        EAccount *account;
3979
4063
        EAccount *modified_account;
3980
4064
        EAccount *original_account;
 
4065
        CamelURL *url;
3981
4066
 
3982
4067
        /* the mail-config*acconts* api needs a lot of work */
3983
4068
 
3984
4069
        modified_account = em_account_editor_get_modified_account (emae);
3985
4070
        original_account = em_account_editor_get_original_account (emae);
3986
4071
 
 
4072
        url = camel_url_new (modified_account->source->url, NULL);
 
4073
        if (url != NULL) {
 
4074
                if (emae->priv->source.settings != NULL)
 
4075
                        camel_settings_save_to_url (
 
4076
                                emae->priv->source.settings, url);
 
4077
                g_free (modified_account->source->url);
 
4078
                modified_account->source->url = camel_url_to_string (url, 0);
 
4079
                camel_url_free (url);
 
4080
        }
 
4081
 
 
4082
        url = camel_url_new (modified_account->transport->url, NULL);
 
4083
        if (url != NULL) {
 
4084
                if (emae->priv->transport.settings != NULL)
 
4085
                        camel_settings_save_to_url (
 
4086
                                emae->priv->transport.settings, url);
 
4087
                g_free (modified_account->transport->url);
 
4088
                modified_account->transport->url = camel_url_to_string (url, 0);
 
4089
                camel_url_free (url);
 
4090
        }
 
4091
 
3987
4092
        if (original_account != NULL) {
3988
4093
                d (printf ("Committing account '%s'\n", e_account_get_string (modified_account, E_ACCOUNT_NAME)));
3989
4094
                forget_password_if_needed (original_account, modified_account, E_ACCOUNT_SOURCE_SAVE_PASSWD, E_ACCOUNT_SOURCE_URL);
3998
4103
                account = modified_account;
3999
4104
 
4000
4105
                /* HACK: this will add the account to the folder tree.
4001
 
                   We should just be listening to the account list directly for changed events */
 
4106
                 * We should just be listening to the account list directly for changed events */
4002
4107
                if (account->enabled
4003
4108
                    && emae->priv->source.provider
4004
4109
                    && (emae->priv->source.provider->flags & CAMEL_PROVIDER_IS_STORAGE)) {
4024
4129
}
4025
4130
 
4026
4131
static void
4027
 
set_checkbox_default (CamelProviderConfEntry *entry, CamelURL *url)
4028
 
{
4029
 
        const gchar *value;
4030
 
 
4031
 
        g_assert (entry->type == CAMEL_PROVIDER_CONF_CHECKBOX);
4032
 
 
4033
 
        if (atoi (entry->value) != 0)
4034
 
                value = "";
4035
 
        else
4036
 
                value = NULL;
4037
 
 
4038
 
        camel_url_set_param (url, entry->name, value);
4039
 
 
4040
 
        /* FIXME: do we need to call emae_uri_changed()? */
4041
 
}
4042
 
 
4043
 
static void
4044
 
set_entry_default (CamelProviderConfEntry *entry, CamelURL *url)
4045
 
{
4046
 
        g_assert (entry->type == CAMEL_PROVIDER_CONF_ENTRY);
4047
 
 
4048
 
        camel_url_set_param (url, entry->name, entry->value);
4049
 
        /* FIXME: This comes from emae_option_entry().  That function calls
4050
 
         * emae_uri_changed(), but the corresponding emae_option_toggle() does
4051
 
         * not call emae_uri_changed() when it creates the checkbuttons - do
4052
 
         * we need to call that function at all?
4053
 
         */
4054
 
}
4055
 
 
4056
 
static void
4057
 
set_checkspin_default (CamelProviderConfEntry *entry, CamelURL *url)
4058
 
{
4059
 
        gboolean on;
4060
 
        gdouble min, def, max;
4061
 
 
4062
 
        g_assert (entry->type == CAMEL_PROVIDER_CONF_CHECKSPIN);
4063
 
 
4064
 
        parse_checkspin_format (entry->value, &on, &min, &def, &max);
4065
 
 
4066
 
        if (on) {
4067
 
                gchar value[16];
4068
 
 
4069
 
                sprintf (value, "%d", (gint) def);
4070
 
                camel_url_set_param (url, entry->name, value);
4071
 
        } else
4072
 
                camel_url_set_param (url, entry->name, NULL);
4073
 
 
4074
 
        /* FIXME: do we need to call emae_uri_changed()? */
4075
 
}
4076
 
 
4077
 
static void
4078
 
set_provider_defaults_on_url (EMAccountEditor *emae, CamelProvider *provider, CamelURL *url)
4079
 
{
4080
 
        CamelProviderConfEntry *entries;
4081
 
        gint i;
4082
 
 
4083
 
        if (!emae->priv->new_account)
4084
 
                return;
4085
 
 
4086
 
        entries = provider->extra_conf;
4087
 
 
4088
 
        for (i = 0; entries && entries[i].type != CAMEL_PROVIDER_CONF_END; i++) {
4089
 
                switch (entries[i].type) {
4090
 
                case CAMEL_PROVIDER_CONF_CHECKBOX:
4091
 
                        set_checkbox_default (entries + i, url);
4092
 
                        break;
4093
 
 
4094
 
                case CAMEL_PROVIDER_CONF_ENTRY:
4095
 
                        set_entry_default (entries + i, url);
4096
 
                        break;
4097
 
 
4098
 
                case CAMEL_PROVIDER_CONF_CHECKSPIN:
4099
 
                        set_checkspin_default (entries + i, url);
4100
 
                        break;
4101
 
 
4102
 
                default:
4103
 
                        /* Other entry types don't have defaults, or so can be
4104
 
                         * inferred from emae_option_*().  But see
4105
 
                         * emae_option_options() - that *may* need something,
4106
 
                         * but that function doesn't actually modify the
4107
 
                         * CamelURL. */
4108
 
                        break;
4109
 
                }
4110
 
        }
4111
 
}
4112
 
 
4113
 
static void
4114
4132
em_account_editor_construct (EMAccountEditor *emae,
4115
4133
                             EMAccountEditorType type,
4116
4134
                             const gchar *id)
4135
4153
                ec = em_config_new (E_CONFIG_BOOK, id);
4136
4154
                items = emae_editor_items;
4137
4155
                if (!emae_editor_items_translated) {
4138
 
                        for (i=0;items[i].path;i++) {
 
4156
                        for (i = 0; items[i].path; i++) {
4139
4157
                                if (items[i].label)
4140
4158
                                        items[i].label = gettext (items[i].label);
4141
4159
                        }
4145
4163
                ec = em_config_new (E_CONFIG_ASSISTANT, id);
4146
4164
                items = emae_assistant_items;
4147
4165
                if (!emae_assistant_items_translated) {
4148
 
                        for (i=0;items[i].path;i++) {
 
4166
                        for (i = 0; items[i].path; i++) {
4149
4167
                                if (items[i].label)
4150
4168
                                        items[i].label = _(items[i].label);
4151
4169
                        }
4160
4178
 
4161
4179
        emae->config = priv->config = ec;
4162
4180
        l = NULL;
4163
 
        for (i=0;items[i].path;i++)
 
4181
        for (i = 0; items[i].path; i++)
4164
4182
                l = g_slist_prepend (l, &items[i]);
4165
4183
        e_config_add_items ((EConfig *) ec, l, emae_free, emae);
4166
4184
 
4168
4186
        l = NULL;
4169
4187
        have = g_hash_table_new (g_str_hash, g_str_equal);
4170
4188
        index = 20;
4171
 
        for (prov=priv->providers;prov;prov=g_list_next (prov)) {
 
4189
        for (prov = priv->providers; prov; prov = g_list_next (prov)) {
4172
4190
                CamelProviderConfEntry *entries = ((CamelProvider *) prov->data)->extra_conf;
4173
4191
 
4174
 
                for (i=0;entries && entries[i].type != CAMEL_PROVIDER_CONF_END;i++) {
 
4192
                for (i = 0; entries && entries[i].type != CAMEL_PROVIDER_CONF_END; i++) {
4175
4193
                        struct _receive_options_item *item;
4176
4194
                        const gchar *name = entries[i].name;
4177
4195
                        gint myindex = index;
4213
4231
        original_account = em_account_editor_get_original_account (emae);
4214
4232
        modified_account = em_account_editor_get_modified_account (emae);
4215
4233
        target = em_config_target_new_account (
4216
 
                ec, original_account, modified_account);
 
4234
                ec, original_account, modified_account,
 
4235
                emae->priv->source.settings);
4217
4236
        e_config_set_target ((EConfig *) ec, (EConfigTarget *) target);
4218
4237
}
4219
4238