* src/maemo/modest-account-settings-dialog.c,
[modest] / src / maemo / easysetup / modest-easysetup-wizard-dialog.c
1
2 /* Copyright (c) 2006, Nokia Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  *   notice, this list of conditions and the following disclaimer in the
13  *   documentation and/or other materials provided with the distribution.
14  * * Neither the name of the Nokia Corporation nor the names of its
15  *   contributors may be used to endorse or promote products derived from
16  *   this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30  
31
32 #include "modest-easysetup-wizard-dialog.h"
33 #include <glib/gi18n.h>
34 #include <gtk/gtknotebook.h>
35 #include <gtk/gtkvbox.h>
36 #include <gtk/gtklabel.h>
37 #include <gtk/gtkcombobox.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkbutton.h>
40 #include <gtk/gtkcheckbutton.h>
41 #include <gtk/gtkmessagedialog.h>
42 #include <gtk/gtkseparator.h>
43 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
44 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
45 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
46 #include "widgets/modest-serversecurity-combo-box.h"
47 #include "widgets/modest-secureauth-combo-box.h"
48 #include "widgets/modest-validating-entry.h"
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-account-mgr-helpers.h"
52 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "maemo/modest-connection-specific-smtp-window.h"
54 #include "widgets/modest-ui-constants.h"
55 #include "widgets/modest-account-settings-dialog.h"
56 #include "maemo/modest-maemo-utils.h"
57 #include "modest-utils.h"
58 #include <gconf/gconf-client.h>
59 #include <string.h> /* For strlen(). */
60 #include "maemo/modest-hildon-includes.h"
61
62 /* Include config.h so that _() works: */
63 #ifdef HAVE_CONFIG_H
64 #include <config.h>
65 #endif
66
67 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
68
69 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
70                                                     MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
71                                                     ModestEasysetupWizardDialogPrivate))
72
73 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
74
75
76 typedef enum {
77         MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
78         MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
79 } ModestEasysetupWizardDialogServerChanges;
80
81 struct _ModestEasysetupWizardDialogPrivate
82 {
83         ModestPresets *presets;
84
85         /* Remember what fields the user edited manually to not prefill them
86          * again. */
87         ModestEasysetupWizardDialogServerChanges server_changes;
88         
89         /* Check if the user changes a field to show a confirmation dialog */
90         gboolean dirty;
91
92         /* If we have a pending load of settings or not. */
93         gboolean pending_load_settings;
94         
95         /* Used by derived widgets to query existing accounts,
96          * and to create new accounts: */
97         ModestAccountMgr *account_manager;
98         ModestAccountSettings *settings;
99         
100         /* notebook pages: */
101         GtkWidget *page_welcome;
102         
103         GtkWidget *page_account_details;
104         GtkWidget *combo_account_country;
105         GtkWidget *combo_account_serviceprovider;
106         GtkWidget *entry_account_title;
107         
108         GtkWidget *page_user_details;
109         GtkWidget *entry_user_name;
110         GtkWidget *entry_user_username;
111         GtkWidget *entry_user_password;
112         GtkWidget *entry_user_email;
113         
114         GtkWidget *page_complete_easysetup;
115         
116         GtkWidget *page_custom_incoming;
117         GtkWidget *combo_incoming_servertype;
118         GtkWidget *caption_incoming;
119         GtkWidget *entry_incomingserver;
120         GtkWidget *combo_incoming_security;
121         GtkWidget *checkbox_incoming_auth;
122
123         GtkWidget *page_custom_outgoing;
124         GtkWidget *entry_outgoingserver;
125         GtkWidget *combo_outgoing_security;
126         GtkWidget *combo_outgoing_auth;
127         GtkWidget *checkbox_outgoing_smtp_specific;
128         GtkWidget *button_outgoing_smtp_servers;
129         
130         GtkWidget *page_complete_customsetup;
131         
132         GtkWidget *specific_window;
133 };
134
135 static void save_to_settings (ModestEasysetupWizardDialog *self);
136
137
138 static gboolean
139 on_delete_event (GtkWidget *widget,
140                  GdkEvent *event,
141                  ModestEasysetupWizardDialog *wizard)
142 {
143         gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
144         return TRUE;
145 }
146
147 static void
148 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
149 {
150         ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
151         g_return_if_fail (priv != NULL);
152         priv->dirty = TRUE;
153 }
154
155 static void
156 on_incoming_security_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
157 {
158         ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
159         ModestConnectionProtocol protocol_security_incoming;
160
161         g_return_if_fail (priv != NULL);
162         protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
163                 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
164
165         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth), modest_protocol_info_is_secure (protocol_security_incoming));
166         gtk_widget_set_sensitive (priv->checkbox_incoming_auth, !modest_protocol_info_is_secure (protocol_security_incoming));
167         
168         on_easysetup_changed (widget, wizard);
169 }
170
171 static void
172 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
173                                              GValue *value, GParamSpec *pspec)
174 {
175         switch (property_id) {
176         default:
177                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
178         }
179 }
180
181 static void
182 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
183                                              const GValue *value, GParamSpec *pspec)
184 {
185         switch (property_id) {
186         default:
187                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
188         }
189 }
190
191 static void
192 modest_easysetup_wizard_dialog_dispose (GObject *object)
193 {
194         if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
195                 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
196 }
197
198 static void
199 modest_easysetup_wizard_dialog_finalize (GObject *object)
200 {
201         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
202         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
203         
204         if (priv->account_manager)
205                 g_object_unref (G_OBJECT (priv->account_manager));
206                 
207         if (priv->presets)
208                 modest_presets_destroy (priv->presets);
209                 
210         if (priv->specific_window)
211                 gtk_widget_destroy (priv->specific_window);
212
213         if (priv->settings)
214                 g_object_unref (priv->settings);
215                 
216         G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
217 }
218
219 static void
220 show_error (GtkWidget *parent_widget, const gchar* text);
221
222 static void
223 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
224
225 static void
226 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
227
228 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
229
230 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
231                                     ModestPresetsSecurity security_incoming)
232 {
233         int serverport_incoming = 0;
234                 /* We don't check for SMTP here as that is impossible for an incoming server. */
235                 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
236                         serverport_incoming =
237                                 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143; 
238                 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
239                         serverport_incoming =
240                                 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110; 
241                 }
242         return serverport_incoming;
243 }
244
245 static GList* 
246 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
247 {
248         GError *error = NULL;
249         ModestTransportStoreProtocol protocol;
250         const gchar* hostname;
251         const gchar* username;
252         ModestConnectionProtocol protocol_security_incoming;
253         int port_num; 
254         GList *list_auth_methods;
255         ModestEasysetupWizardDialogPrivate *priv;
256         
257         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
258         protocol = easysetup_servertype_combo_box_get_active_servertype (
259                  EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
260         hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
261         username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
262         protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
263                 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
264         port_num = get_serverport_incoming(protocol, protocol_security_incoming); 
265         list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol, hostname, port_num, 
266                                                                                       username, GTK_WINDOW (self), &error);
267
268         if (list_auth_methods) {
269                 /* TODO: Select the correct method */
270                 GList* list = NULL;
271                 GList* method;
272                 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
273                         ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
274                         if (modest_protocol_info_auth_is_secure(auth)) {
275                                 list = g_list_append(list, GINT_TO_POINTER(auth));
276                         }
277                 }
278
279                 g_list_free(list_auth_methods);
280
281                 if (list)
282                         return list;
283         }
284
285         if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
286                         error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
287         {
288                 show_error (GTK_WIDGET(self), _("mcen_ib_unableto_discover_auth_methods"));
289         }
290
291         if(error != NULL)
292                 g_error_free(error);
293
294         return NULL;
295 }
296
297 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
298 {
299         GList* methods = check_for_supported_auth_methods(self);
300         if (!methods)
301         {
302                 return FALSE;
303         }
304
305         g_list_free(methods);
306         return TRUE;
307 }
308
309 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* self)
310 {
311         ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
312
313         GList* methods = check_for_supported_auth_methods(self);
314         if (methods)
315         {
316                 /* Use the first one: */
317                 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
318                 g_list_free(methods);
319         }
320
321         return result;
322 }
323
324 static void
325 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
326 {
327         ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
328         
329         /* Call the vfunc, which may be overridden by derived classes: */
330         if (klass->enable_buttons) {
331                 GtkNotebook *notebook = NULL;
332                 g_object_get (wizard_dialog, "wizard-notebook", &notebook, NULL);
333                 
334                 const gint current_page_num = gtk_notebook_get_current_page (notebook);
335                 if (current_page_num == -1)
336                         return;
337                         
338                 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
339                 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
340         }
341 }
342
343 static void
344 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
345 {
346         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
347         g_assert(self);
348         invoke_enable_buttons_vfunc(self);
349 }
350
351 static void
352 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
353 {
354         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
355         g_assert(self);
356         invoke_enable_buttons_vfunc(self);
357 }
358
359 /** This is a convenience function to create a caption containing a mandatory widget.
360  * When the widget is edited, the enable_buttons() vfunc will be called.
361  */
362 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
363                                                   GtkSizeGroup *group,
364                                                   const gchar *value,
365                                                   GtkWidget *control,
366                                                   GtkWidget *icon,
367                                                   HildonCaptionStatus flag)
368 {
369         GtkWidget *caption = NULL;
370   
371         /* Note: Previously, the translated strings already contained the "*",
372          * Comment out this code if they do again.
373          */
374         /* Add a * character to indicate mandatory fields,
375          * as specified in our "Email UI Specification": */
376         if (flag == HILDON_CAPTION_MANDATORY) {
377                 gchar* title = g_strdup_printf("%s*", value);
378                 caption = hildon_caption_new (group, title, control, icon, flag);       
379                 g_free(title);
380         }       
381         else
382                 caption = hildon_caption_new (group, value, control, icon, flag);
383
384         /* Connect to the appropriate changed signal for the widget, 
385          * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
386          */
387         if (GTK_IS_ENTRY (control)) {
388                 g_signal_connect (G_OBJECT (control), "changed",
389                                   G_CALLBACK (on_caption_entry_changed), self);
390                 
391         }
392         else if (GTK_IS_COMBO_BOX (control)) {
393                 g_signal_connect (G_OBJECT (control), "changed",
394                                   G_CALLBACK (on_caption_combobox_changed), self);
395         }
396          
397         return caption;
398 }
399            
400 static GtkWidget*
401 create_page_welcome (ModestEasysetupWizardDialog *self)
402 {
403         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
404         GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
405         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
406         /* So that it is not truncated: */
407         gtk_widget_set_size_request (label, 600, -1);
408         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
409         gtk_widget_show (label);
410         gtk_widget_show (GTK_WIDGET (box));
411         return GTK_WIDGET (box);
412 }
413
414 static void
415 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
416 {
417         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
418         g_assert(self);
419         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
420         
421         priv->dirty = TRUE;
422         
423         /* Fill the providers combo, based on the selected country: */
424         if (priv->presets != NULL) {
425                 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
426                         MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
427                 easysetup_provider_combo_box_fill (
428                         EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider), priv->presets, mcc);
429         }
430 }
431
432 static void
433 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
434 {
435         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
436         g_assert(self);
437         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
438         
439         priv->dirty = TRUE;
440         
441         /* Fill the providers combo, based on the selected country: */
442         gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
443                 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
444         
445         gchar* domain_name = NULL;
446         if(provider_id)
447                 domain_name = modest_presets_get_domain (priv->presets, provider_id);
448         
449         if(!domain_name)
450                 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
451                 
452         if (priv->entry_user_email)
453                 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), domain_name);
454                 
455         g_free (domain_name);
456         
457         g_free (provider_id);
458 }
459
460 static void
461 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
462 {
463         /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
464         show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
465 }
466
467 static void
468 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
469 {
470         /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
471         
472         const gchar *show_char = NULL;
473         if (character)
474           show_char = character;
475         else {
476           /* TODO: We need a logical ID for this: */
477           show_char = _("whitespace");
478         }
479         
480         /* TODO: Should this show just this one bad character or all the not-allowed characters? */
481         gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
482         show_error (GTK_WIDGET (self), message);
483 }
484
485 static gint
486 get_default_country_code(void)
487 {
488         /* TODO: Default to the current country somehow.
489          * But I don't know how to get the information that is specified in the
490          * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
491          *
492          * This is probably not the best choice of gconf key:
493          * This is the  "mcc used in the last pairing", ie. the last connection you made.
494          * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
495          *
496          */
497         GError *error = NULL;
498         const gchar* key = "/apps/osso/operator-wizard/last_mcc";
499         gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
500
501         if(mcc_id < 0)
502                 mcc_id = 0;
503
504         if (error) {
505                 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
506                 g_error_free (error);
507                 error = NULL;
508
509                 mcc_id = 0;
510         }
511
512         /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
513          * This might just be a Maemo bug.
514          */
515         if (mcc_id == 0)
516         {
517                 /* For now, we default to Finland when there is nothing better: */
518                 mcc_id = 244;
519         }
520         return mcc_id;
521 }
522
523 static GtkWidget*
524 create_page_account_details (ModestEasysetupWizardDialog *self)
525 {
526         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
527         GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
528         ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
529
530         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
531         gtk_widget_set_size_request (label, 600, -1);
532         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
533         gtk_widget_show (label);
534
535         /* Create a size group to be used by all captions.
536          * Note that HildonCaption does not create a default size group if we do not specify one.
537          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
538         GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
539
540         /* The country widgets: */
541         priv->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
542         GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"), 
543                                                               priv->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
544         gtk_widget_show (priv->combo_account_country);
545         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
546         gtk_widget_show (caption);
547         
548         /* connect to country combo's changed signal, so we can fill the provider combo: */
549         g_signal_connect (G_OBJECT (priv->combo_account_country), "changed",
550                           G_CALLBACK (on_combo_account_country), self);
551             
552         GtkWidget *separator = gtk_hseparator_new ();
553         gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
554         gtk_widget_show (separator);
555             
556         /* The service provider widgets: */     
557         priv->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
558         gtk_widget_set_size_request (priv->combo_account_serviceprovider, 320, -1);
559         
560         caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"), 
561                                                    priv->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
562         gtk_widget_show (priv->combo_account_serviceprovider);
563         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
564         gtk_widget_show (caption);
565         
566         /* connect to providers combo's changed signal, so we can fill the email address: */
567         g_signal_connect (G_OBJECT (priv->combo_account_serviceprovider), "changed",
568                           G_CALLBACK (on_combo_account_serviceprovider), self);
569         
570         /* The description widgets: */  
571         priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
572         g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
573                          G_CALLBACK(on_easysetup_changed), self);
574         /* Do use auto-capitalization: */
575         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title), 
576                                          HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
577         
578         /* Set a default account title, choosing one that does not already exist: */
579         /* Note that this is irrelevant to the non-user visible name, which we will create later. */
580         gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
581         gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
582                 priv->account_manager, default_account_name_start);
583         g_free (default_account_name_start);
584         default_account_name_start = NULL;
585         
586         gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title), default_account_name);
587         g_free (default_account_name);
588         default_account_name = NULL;
589
590         caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"), 
591                                                    priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
592         gtk_widget_show (priv->entry_account_title);
593         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
594         gtk_widget_show (caption);
595         
596         /* Prevent the use of some characters in the account title, 
597          * as required by our UI specification: */
598         GList *list_prevent = NULL;
599         list_prevent = g_list_append (list_prevent, "\\");
600         list_prevent = g_list_append (list_prevent, "/");
601         list_prevent = g_list_append (list_prevent, ":");
602         list_prevent = g_list_append (list_prevent, "*");
603         list_prevent = g_list_append (list_prevent, "?");
604         list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions â€œ, but maybe means ", maybe both. */
605         list_prevent = g_list_append (list_prevent, "“");
606         list_prevent = g_list_append (list_prevent, "<"); 
607         list_prevent = g_list_append (list_prevent, ">"); 
608         list_prevent = g_list_append (list_prevent, "|");
609         list_prevent = g_list_append (list_prevent, "^");       
610         modest_validating_entry_set_unallowed_characters (
611                 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
612         g_list_free (list_prevent);
613         list_prevent = NULL;
614         modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
615                                                                                                                                          on_entry_invalid_character, self);
616         
617         /* Set max length as in the UI spec:
618          * The UI spec seems to want us to show a dialog if we hit the maximum. */
619         gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
620         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title), 
621                                               on_entry_max, self);
622         
623         gtk_widget_show (GTK_WIDGET (box));
624         
625         return GTK_WIDGET (box);
626 }
627
628 static GtkWidget*
629 create_page_user_details (ModestEasysetupWizardDialog *self)
630 {
631         GtkSizeGroup* sizegroup;
632         GtkWidget *box;
633         ModestEasysetupWizardDialogPrivate *priv;
634
635         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
636         
637         /* Create a size group to be used by all captions.
638          * Note that HildonCaption does not create a default size group if we do not specify one.
639          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
640         box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
641         sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
642          
643         /* The name widgets: (use auto cap) */
644         priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
645         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), 
646                                          HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
647         
648         /* Set max length as in the UI spec:
649          * The UI spec seems to want us to show a dialog if we hit the maximum. */
650         gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
651         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name), 
652                                               on_entry_max, self);
653         GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
654                                                               _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
655         g_signal_connect(G_OBJECT(priv->entry_user_name), "changed", 
656                                                                          G_CALLBACK(on_easysetup_changed), self);
657         gtk_widget_show (priv->entry_user_name);
658         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
659         gtk_widget_show (caption);
660         
661         /* Prevent the use of some characters in the name, 
662          * as required by our UI specification: */
663         GList *list_prevent = NULL;
664         list_prevent = g_list_append (list_prevent, "<");
665         list_prevent = g_list_append (list_prevent, ">");
666         modest_validating_entry_set_unallowed_characters (
667                 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
668         modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
669                 on_entry_invalid_character, self);
670         g_list_free (list_prevent);
671         
672         /* The username widgets: */     
673         priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
674         /* Auto-capitalization is the default, so let's turn it off: */
675         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
676         caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"), 
677                                                    priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
678         gtk_widget_show (priv->entry_user_username);
679         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
680         g_signal_connect(G_OBJECT(priv->entry_user_username), "changed", 
681                                                                          G_CALLBACK(on_easysetup_changed), self);
682         gtk_widget_show (caption);
683         
684         /* Prevent the use of some characters in the username, 
685          * as required by our UI specification: */
686         modest_validating_entry_set_unallowed_characters_whitespace (
687                 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
688         modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
689                 on_entry_invalid_character, self);
690         
691         /* Set max length as in the UI spec:
692          * The UI spec seems to want us to show a dialog if we hit the maximum. */
693         gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
694         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username), 
695                                               on_entry_max, self);
696         
697         /* The password widgets: */     
698         priv->entry_user_password = gtk_entry_new ();
699         /* Auto-capitalization is the default, so let's turn it off: */
700         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password), 
701                                          HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
702         gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
703         /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
704         caption = create_caption_new_with_asterisk (self, sizegroup, 
705                                                    _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
706         g_signal_connect(G_OBJECT(priv->entry_user_password), "changed", 
707                                                                          G_CALLBACK(on_easysetup_changed), self);
708         gtk_widget_show (priv->entry_user_password);
709         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
710         gtk_widget_show (caption);
711         
712         /* The email address widgets: */        
713         priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
714         /* Auto-capitalization is the default, so let's turn it off: */
715         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
716         caption = create_caption_new_with_asterisk (self, sizegroup, 
717                                                    _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
718         gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
719         gtk_widget_show (priv->entry_user_email);
720         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
721         g_signal_connect(G_OBJECT(priv->entry_user_email), "changed", 
722                                                                          G_CALLBACK(on_easysetup_changed), self);
723         gtk_widget_show (caption);
724         
725         /* Set max length as in the UI spec:
726          * The UI spec seems to want us to show a dialog if we hit the maximum. */
727         gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
728         modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email), 
729                                               on_entry_max, self);
730         
731         
732         gtk_widget_show (GTK_WIDGET (box));
733         
734         return GTK_WIDGET (box);
735 }
736
737 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
738 {
739         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
740         
741         GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
742         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
743         gtk_widget_set_size_request (label, 600, -1);
744         gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
745         /* The documentation for gtk_label_set_line_wrap() says that we must 
746          * call gtk_widget_set_size_request() with a hard-coded width, 
747          * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
748         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
749         gtk_widget_show (label);
750         
751         label = gtk_label_new (_("mcen_ia_easysetup_complete"));
752         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
753         gtk_widget_set_size_request (label, 600, -1);
754         
755         gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
756         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
757         gtk_widget_show (label);
758         
759         gtk_widget_show (GTK_WIDGET (box));
760         return GTK_WIDGET (box);
761 }
762
763 /** Change the caption title for the incoming server, 
764  * as specified in the UI spec:
765  */
766 static void 
767 update_incoming_server_title (ModestEasysetupWizardDialog *self)
768 {
769         ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
770         const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
771                 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
772         const gchar* type = 
773                 (protocol == MODEST_PROTOCOL_STORE_POP ? 
774                  _("mail_fi_emailtype_pop3") : 
775                  _("mail_fi_emailtype_imap") );
776                         
777                 
778         /* Note that this produces a compiler warning, 
779          * because the compiler does not know that the translated string will have a %s in it.
780          * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
781         gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
782         g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
783         g_free(incomingserver_title);
784 }
785
786 /** Change the caption title for the incoming server, 
787  * as specified in the UI spec:
788  */
789 static void 
790 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
791 {
792         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
793         const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
794                 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
795         
796         /* Fill the combo with appropriately titled choices for POP or IMAP. */
797         /* The choices are the same, but the titles are different, as in the UI spec. */
798         modest_serversecurity_combo_box_fill (
799                 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol);
800 }
801
802 static void 
803 on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
804 {
805         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
806         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
807         
808         priv->dirty = TRUE;
809         
810         update_incoming_server_title (self);
811         update_incoming_server_security_choices (self);
812
813         set_default_custom_servernames (self);
814 }
815
816 static void 
817 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
818 {
819         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
820         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
821         priv->dirty = TRUE;
822         priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
823 }
824
825 static GtkWidget* 
826 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
827 {
828         ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
829         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
830         GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
831
832         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
833                                         GTK_POLICY_NEVER,
834                                         GTK_POLICY_AUTOMATIC);
835
836         /* Show note that account type cannot be changed in future: */
837         GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
838         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
839         gtk_widget_set_size_request (label, 600, -1);
840         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
841         gtk_widget_show (label);
842         
843         /* Create a size group to be used by all captions.
844          * Note that HildonCaption does not create a default size group if we do not specify one.
845          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
846         GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
847          
848         /* The incoming server widgets: */
849         priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
850         easysetup_servertype_combo_box_set_active_servertype (
851                 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
852         GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
853                                                               _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
854         gtk_widget_show (priv->combo_incoming_servertype);
855         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
856         gtk_widget_show (caption);
857         
858         priv->entry_incomingserver = gtk_entry_new ();
859         g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
860         /* Auto-capitalization is the default, so let's turn it off: */
861         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
862         set_default_custom_servernames (self);
863
864         /* The caption title will be updated in update_incoming_server_title().
865          * so this default text will never be seen: */
866         /* (Note: Changing the title seems pointless. murrayc) */
867         priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup, 
868                                                                   "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
869         update_incoming_server_title (self);
870         gtk_widget_show (priv->entry_incomingserver);
871         gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
872         gtk_widget_show (priv->caption_incoming);
873         
874         /* Change the caption title when the servertype changes, 
875          * as in the UI spec: */
876         g_signal_connect (G_OBJECT (priv->combo_incoming_servertype), "changed",
877                           G_CALLBACK (on_combo_servertype_changed), self);
878
879         /* Remember when the servername was changed manually: */
880         g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
881                           G_CALLBACK (on_entry_incoming_servername_changed), self);
882
883         /* The secure connection widgets: */    
884         priv->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
885         update_incoming_server_security_choices (self);
886         modest_serversecurity_combo_box_set_active_serversecurity (
887                 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
888         caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
889                                       priv->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
890         g_signal_connect (G_OBJECT (priv->combo_incoming_security), "changed",
891                           G_CALLBACK (on_incoming_security_changed), self);
892         gtk_widget_show (priv->combo_incoming_security);
893         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
894         gtk_widget_show (caption);
895         
896         priv->checkbox_incoming_auth = gtk_check_button_new ();
897         g_signal_connect (G_OBJECT (priv->checkbox_incoming_auth), "toggled",
898                           G_CALLBACK (on_easysetup_changed), self);
899         caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"), 
900                                       priv->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
901         
902         gtk_widget_show (priv->checkbox_incoming_auth);
903         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
904         gtk_widget_show (caption);
905         
906         gtk_widget_show (GTK_WIDGET (box));
907
908         gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
909         gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
910                                              gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
911         gtk_widget_show (scrolled_window);
912         
913         return GTK_WIDGET (scrolled_window);
914 }
915
916 static void
917 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
918 {
919         GtkWidget *widget = GTK_WIDGET (user_data);
920         
921         /* Enable the widget only if the toggle button is active: */
922         const gboolean enable = gtk_toggle_button_get_active (togglebutton);
923         gtk_widget_set_sensitive (widget, enable);
924 }
925
926 /* Make the sensitivity of a widget depend on a toggle button.
927  */
928 static void
929 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
930 {
931         g_signal_connect (G_OBJECT (button), "toggled",
932                           G_CALLBACK (on_toggle_button_changed), widget);
933         
934         /* Set the starting sensitivity: */
935         on_toggle_button_changed (button, widget);
936 }
937
938 static void
939 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
940 {
941         ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
942         ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
943         
944         /* We set dirty here because setting it depending on the connection specific dialog
945         seems overkill */
946         priv->dirty = TRUE;
947         
948         /* Create the window, if necessary: */
949         if (!(priv->specific_window)) {
950                 priv->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
951                 modest_connection_specific_smtp_window_fill_with_connections (
952                         MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window), priv->account_manager);
953         }
954
955         /* Show the window: */
956         gtk_window_set_transient_for (GTK_WINDOW (priv->specific_window), GTK_WINDOW (self));
957         gtk_window_set_modal (GTK_WINDOW (priv->specific_window), TRUE);
958         gtk_widget_show (priv->specific_window);
959 }
960
961 static void 
962 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
963 {
964         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
965         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
966         priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
967 }
968
969 static GtkWidget* 
970 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
971 {
972         ModestEasysetupWizardDialogPrivate *priv;
973         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
974         
975         /* Create a size group to be used by all captions.
976          * Note that HildonCaption does not create a default size group if we do not specify one.
977          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
978         GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
979          
980         /* The outgoing server widgets: */
981         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
982         priv->entry_outgoingserver = gtk_entry_new ();
983         g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
984                   G_CALLBACK (on_easysetup_changed), self);
985         /* Auto-capitalization is the default, so let's turn it off: */
986         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
987         GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, 
988                                                               _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
989         gtk_widget_show (priv->entry_outgoingserver);
990         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
991         gtk_widget_show (caption);
992         set_default_custom_servernames (self);
993         
994         /* The secure connection widgets: */    
995         priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
996         g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed",
997                           G_CALLBACK (on_easysetup_changed), self);
998         modest_serversecurity_combo_box_fill (
999                 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
1000         modest_serversecurity_combo_box_set_active_serversecurity (
1001                 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
1002         caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"), 
1003                                       priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
1004         gtk_widget_show (priv->combo_outgoing_security);
1005         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1006         gtk_widget_show (caption);
1007         
1008         /* The secure authentication widgets: */
1009         priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
1010                         g_signal_connect (G_OBJECT (priv->combo_outgoing_auth), "changed",
1011                           G_CALLBACK (on_easysetup_changed), self);
1012         caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"), 
1013                                       priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
1014         gtk_widget_show (priv->combo_outgoing_auth);
1015         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1016         gtk_widget_show (caption);
1017         
1018         GtkWidget *separator = gtk_hseparator_new ();
1019         gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
1020         gtk_widget_show (separator);
1021         
1022         /* connection-specific checkbox: */
1023         priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
1024         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific), 
1025                                       FALSE);
1026         g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1027                   G_CALLBACK (on_easysetup_changed), self);
1028
1029         caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"), 
1030                                       priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
1031         gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1032         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1033         gtk_widget_show (caption);
1034         
1035         /* Connection-specific SMTP-Severs Edit button: */
1036         priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
1037         caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"), 
1038                                       priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
1039         hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1040         gtk_widget_show (priv->button_outgoing_smtp_servers);
1041         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1042         gtk_widget_show (caption);
1043         
1044         /* Only enable the button when the checkbox is checked: */
1045         enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers, 
1046                                         GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
1047                 
1048         g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1049                           G_CALLBACK (on_button_outgoing_smtp_servers), self);
1050
1051         g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1052                           G_CALLBACK (on_entry_outgoing_servername_changed), self);
1053         
1054         
1055         gtk_widget_show (GTK_WIDGET (box));
1056         
1057         return GTK_WIDGET (box);
1058 }
1059
1060 static gboolean
1061 show_advanced_edit(gpointer user_data)
1062 {
1063         ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1064         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1065         gint response;
1066         
1067         /* Show the Account Settings window: */
1068         ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
1069         if (priv->pending_load_settings) {
1070                 save_to_settings (self);
1071                 priv->pending_load_settings = FALSE;
1072         }
1073         modest_account_settings_dialog_set_account (dialog, priv->settings);
1074         
1075         modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
1076         
1077         response = gtk_dialog_run (GTK_DIALOG (dialog));
1078
1079         gtk_widget_destroy (GTK_WIDGET (dialog));
1080         
1081         return FALSE; /* Do not call this timeout callback again. */
1082 }
1083
1084 static void
1085 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1086 {
1087         ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1088         
1089         /* Show the Account Settings window: */
1090         show_advanced_edit(self);
1091 }
1092 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1093 {
1094         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1095         GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1096         GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1097         gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1098         gtk_widget_set_size_request (label, 600, -1);
1099         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1100         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1101         gtk_widget_show (label);
1102         
1103         label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1104         gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1105         gtk_widget_set_size_request (label, 600, -1);
1106         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1107         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1108         gtk_widget_show (label);
1109         
1110         GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"), 
1111                                                  button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1112         hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1113         gtk_widget_show (button_edit);
1114         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1115         gtk_widget_show (caption);
1116         
1117         g_signal_connect (G_OBJECT (button_edit), "clicked", 
1118                           G_CALLBACK (on_button_edit_advanced_settings), self);
1119         
1120         gtk_widget_show (GTK_WIDGET (box));
1121         return GTK_WIDGET (box);
1122 }
1123
1124
1125 /*
1126  */
1127 static void 
1128 on_response (ModestWizardDialog *wizard_dialog,
1129              gint response_id,
1130              gpointer user_data)
1131 {
1132         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1133
1134         invoke_enable_buttons_vfunc (self);
1135 }
1136
1137 static void 
1138 on_response_before (ModestWizardDialog *wizard_dialog,
1139                     gint response_id,
1140                     gpointer user_data)
1141 {
1142         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1143         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1144         if (response_id == GTK_RESPONSE_CANCEL) {
1145                 /* This is mostly copied from
1146                  * src/maemo/modest-account-settings-dialog.c */
1147                 if (priv->dirty) {
1148                         GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self), 
1149                                 _("imum_nc_wizard_confirm_lose_changes")));
1150                         /* TODO: These button names will be ambiguous, and not
1151                          * specified in the UI specification. */
1152
1153                         const gint dialog_response = gtk_dialog_run (dialog);
1154                         gtk_widget_destroy (GTK_WIDGET (dialog));
1155
1156                         if (dialog_response != GTK_RESPONSE_OK) {
1157                                 /* Don't let the dialog close */
1158                                 g_signal_stop_emission_by_name (wizard_dialog, "response");
1159                         }
1160                 }
1161         }
1162 }
1163
1164 typedef struct IdleData {
1165         ModestEasysetupWizardDialog *dialog;
1166         ModestPresets *presets;
1167 } IdleData;
1168
1169 static gboolean
1170 presets_idle (gpointer userdata)
1171 {
1172         IdleData *idle_data = (IdleData *) userdata;
1173         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1174         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1175
1176         g_assert (idle_data->presets);
1177
1178         gdk_threads_enter ();
1179
1180         priv->presets = idle_data->presets;
1181
1182         if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) {
1183                 gint mcc = get_default_country_code();
1184                 /* Fill the combo in an idle call, as it takes a lot of time */
1185                 easysetup_country_combo_box_load_data(
1186                         MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
1187                 easysetup_country_combo_box_set_active_country_mcc (
1188                         MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc);
1189                 easysetup_provider_combo_box_fill (
1190                         EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider),
1191                         priv->presets, mcc);
1192         }
1193
1194         priv->dirty = FALSE;
1195
1196         g_object_unref (idle_data->dialog);
1197         g_free (idle_data);
1198
1199         gdk_threads_leave ();
1200
1201         return FALSE;
1202 }
1203
1204 static gpointer
1205 presets_loader (gpointer userdata)
1206 {
1207         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1208         ModestPresets *presets = NULL;
1209         IdleData *idle_data;
1210
1211         const gchar* path  = NULL;
1212         const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1213         const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1214         
1215         if (access(path1, R_OK) == 0) 
1216                 path = path1;
1217         else if (access(path2, R_OK) == 0)
1218                 path = path2;
1219         else {
1220                 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1221                            __FUNCTION__, path1, path2);
1222                 return NULL;
1223         }
1224
1225         presets = modest_presets_new (path);
1226         if (!presets) {
1227                 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1228                 return NULL;
1229         }
1230         
1231         idle_data = g_new0 (IdleData, 1);
1232         idle_data->dialog = self;
1233         idle_data->presets = presets;
1234         
1235         g_idle_add (presets_idle, idle_data);   
1236
1237         return NULL;
1238 }
1239
1240 static void
1241 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1242 {
1243         gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1244         
1245         /* Create the notebook to be used by the ModestWizardDialog base class:
1246          * Each page of the notebook will be a page of the wizard: */
1247         GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1248         
1249         /* Set the notebook used by the ModestWizardDialog base class: */
1250         g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1251     
1252         /* Set the wizard title:
1253          * The actual window title will be a combination of this and the page's tab label title. */
1254         g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1255
1256         /* Read in the information about known service providers: */
1257         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1258         
1259         /* The server fields did not have been manually changed yet */
1260         priv->server_changes = 0;
1261         priv->pending_load_settings = TRUE;
1262
1263         /* Get the account manager object, 
1264          * so we can check for existing accounts,
1265          * and create new accounts: */
1266         priv->account_manager = modest_runtime_get_account_mgr ();
1267         g_object_ref (priv->account_manager);
1268         
1269         /* Initialize fields */
1270         priv->page_welcome = create_page_welcome (self);
1271         priv->page_account_details = create_page_account_details (self);
1272         priv->page_user_details = create_page_user_details (self);
1273         priv->page_complete_easysetup = NULL;       
1274         priv->page_custom_incoming = NULL;
1275         priv->combo_incoming_servertype = NULL;
1276         priv->caption_incoming = NULL;
1277         priv->entry_incomingserver = NULL;
1278         priv->combo_incoming_security = NULL;
1279         priv->checkbox_incoming_auth = NULL;
1280         priv->page_custom_outgoing = NULL;
1281         priv->entry_outgoingserver = NULL;
1282         priv->combo_outgoing_security = NULL;
1283         priv->combo_outgoing_auth = NULL;
1284         priv->checkbox_outgoing_smtp_specific = NULL;
1285         priv->button_outgoing_smtp_servers = NULL;
1286         priv->page_complete_customsetup = NULL;
1287         priv->specific_window = NULL;
1288
1289         /* Add the common pages: */
1290         gtk_notebook_append_page (notebook, priv->page_welcome, 
1291                                   gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1292         gtk_container_child_set (GTK_CONTAINER (notebook), 
1293                                  priv->page_welcome,
1294                                  "tab-expand", TRUE,
1295                                  "tab-fill", TRUE,
1296                                  NULL);
1297
1298         gtk_notebook_append_page (notebook, priv->page_account_details, 
1299                                   gtk_label_new (_("mcen_ti_accountdetails")));
1300         gtk_container_child_set (GTK_CONTAINER (notebook), 
1301                                  priv->page_account_details,
1302                                  "tab-expand", TRUE,
1303                                  "tab-fill", TRUE,
1304                                  NULL);
1305
1306         gtk_notebook_append_page (notebook, priv->page_user_details, 
1307                                   gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1308         gtk_container_child_set (GTK_CONTAINER (notebook), 
1309                                  priv->page_user_details,
1310                                  "tab-expand", TRUE,
1311                                  "tab-fill", TRUE,
1312                                  NULL);
1313                 
1314         /* Create and add the easysetup-specific pages,
1315          * because we need _some_ final page to enable the Next and Finish buttons: */
1316         create_subsequent_easysetup_pages (self);
1317
1318         /* Connect to the dialog's response signal so we can enable/disable buttons 
1319          * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1320          * Note that we use g_signal_connect_after() instead of g_signal_connect()
1321          * so that we can be enable/disable after ModestWizardDialog has done its own 
1322          * enabling/disabling of buttons.
1323          * 
1324          * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler 
1325          * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1326          * 
1327          * It's not enough to connect to the notebook's switch-page signal, because 
1328          * ModestWizardDialog's "response" signal handler enables the buttons itself, 
1329          * _after_ switching the page (understandably).
1330          * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1331          * then gtk_notebook_get_current_page() would return an incorrect value.)
1332          */
1333         g_signal_connect_after (G_OBJECT (self), "response",
1334                                 G_CALLBACK (on_response), self);
1335
1336         /* This is to show a confirmation dialog when the user hits cancel */
1337         g_signal_connect (G_OBJECT (self), "response",
1338                           G_CALLBACK (on_response_before), self);
1339
1340         g_signal_connect (G_OBJECT (self), "delete-event",
1341                           G_CALLBACK (on_delete_event), self);
1342
1343         /* Reset dirty, because there was no user input until now */
1344         priv->dirty = FALSE;
1345         
1346         /* When this window is shown, hibernation should not be possible, 
1347          * because there is no sensible way to save the state: */
1348         modest_window_mgr_prevent_hibernation_while_window_is_shown (
1349                 modest_runtime_get_window_mgr (), GTK_WINDOW (self)); 
1350
1351         /* Load provider presets */
1352         g_object_ref (self);
1353         g_thread_create (presets_loader, self, FALSE, NULL);
1354
1355         hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1356                                         modest_maemo_utils_get_osso_context()); 
1357
1358         priv->settings = modest_account_settings_new ();
1359 }
1360
1361 ModestEasysetupWizardDialog*
1362 modest_easysetup_wizard_dialog_new (void)
1363 {       
1364         
1365         return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1366 }
1367
1368 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1369 {
1370         ModestEasysetupWizardDialogPrivate *priv;
1371         GtkNotebook *notebook = NULL;
1372
1373         g_object_get (self, "wizard-notebook", &notebook, NULL);
1374         g_assert(notebook);
1375
1376         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1377         
1378         /* Create the custom pages: */
1379         if(!(priv->page_custom_incoming)) {
1380                 priv->page_custom_incoming = create_page_custom_incoming (self);
1381         }
1382                 
1383         if(!(priv->page_custom_outgoing)) {
1384                 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1385         }
1386         
1387         if(!(priv->page_complete_customsetup)) {
1388                 priv->page_complete_customsetup = create_page_complete_custom (self);
1389         }
1390         
1391         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1392                 gtk_notebook_append_page (notebook, priv->page_custom_incoming,
1393                                           gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1394         
1395         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))           
1396                 gtk_notebook_append_page (notebook, priv->page_custom_outgoing,
1397                                           gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1398                 
1399         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup))) {
1400                 gtk_notebook_append_page (notebook, priv->page_complete_customsetup,
1401                                           gtk_label_new (_("mcen_ti_emailsetup_complete")));
1402                 gtk_container_child_set (GTK_CONTAINER (notebook), 
1403                                          priv->page_complete_customsetup,
1404                                          "tab-expand", TRUE,
1405                                          "tab-fill", TRUE,
1406                                          NULL);
1407         }
1408                         
1409         /* This is unnecessary with GTK+ 2.10: */
1410         modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1411 }
1412         
1413 static void 
1414 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1415 {
1416         ModestEasysetupWizardDialogPrivate *priv;
1417         GtkNotebook *notebook = NULL;
1418
1419         g_object_get (self, "wizard-notebook", &notebook, NULL);
1420         g_assert(notebook);
1421         
1422         /* Create the easysetup-specific pages: */
1423         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1424         if(!priv->page_complete_easysetup)
1425                 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1426
1427         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup))) {
1428                 gtk_notebook_append_page (notebook, priv->page_complete_easysetup, 
1429                                           gtk_label_new (_("mcen_ti_emailsetup_complete")));
1430                 gtk_container_child_set (GTK_CONTAINER (notebook),
1431                                          priv->page_complete_easysetup,
1432                                          "tab-expand", TRUE,
1433                                          "tab-fill", TRUE,
1434                                          NULL);
1435         }
1436                         
1437         /* This is unnecessary with GTK+ 2.10: */
1438         modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1439 }
1440 /* After the user details page,
1441  * the following pages depend on whether "Other" was chosen 
1442  * in the provider combobox on the account page
1443  */
1444 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1445 {
1446         ModestEasysetupWizardDialogPrivate *priv;
1447
1448         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1449
1450         if (easysetup_provider_combo_box_get_active_provider_id (
1451                     EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider)) == 0) {
1452                 /* "Other..." was selected: */
1453                 
1454                 /* Make sure that the easysetup pages do not exist: */
1455                 if(priv->page_complete_easysetup) {
1456                         gtk_widget_destroy (priv->page_complete_easysetup);
1457                         priv->page_complete_easysetup = NULL;
1458                 }
1459                 
1460                 create_subsequent_customsetup_pages (self);
1461         }       
1462         else {
1463                 /* A specific provider was selected: */
1464                 {
1465                         /* Make sure that the custom pages do not exist:
1466                          * Because they will be used if they exist, when creating the account. */
1467                         if(priv->page_custom_incoming) {
1468                                 gtk_widget_destroy (priv->page_custom_incoming);
1469                                 priv->page_custom_incoming = NULL;
1470                                 priv->combo_incoming_servertype = NULL;
1471                                 priv->caption_incoming = NULL;
1472                                 priv->entry_incomingserver = NULL;
1473                                 priv->combo_incoming_security = NULL;
1474                                 priv->checkbox_incoming_auth = NULL;
1475                         }
1476                         
1477                         if(priv->page_custom_outgoing) {
1478                                 gtk_widget_destroy (priv->page_custom_outgoing);
1479                                 priv->page_custom_outgoing = NULL;
1480                                 priv->entry_outgoingserver = NULL;
1481                                 priv->combo_outgoing_security = NULL;
1482                                 priv->combo_outgoing_auth = NULL;
1483                                 priv->checkbox_outgoing_smtp_specific = NULL;
1484                                 priv->button_outgoing_smtp_servers = NULL;
1485                         }
1486                         
1487                         if(priv->page_complete_customsetup) {
1488                                 gtk_widget_destroy (priv->page_complete_customsetup);
1489                                 priv->page_complete_customsetup = NULL;
1490                         }
1491                 }
1492                 
1493                 /* Create the easysetup pages: */
1494                 create_subsequent_easysetup_pages (self);
1495         }
1496 }
1497
1498
1499 static gchar*
1500 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1501 {
1502         if (!email_address)
1503                 return NULL;
1504         
1505         gchar* at = g_utf8_strchr (email_address, -1, '@');
1506         if (!at || (g_utf8_strlen (at, -1) < 2))
1507                 return NULL;
1508                 
1509         gchar* domain = g_utf8_next_char (at);
1510         if(!domain)
1511                 return NULL;
1512                 
1513         const gchar* hostname = NULL;
1514         if (servertype == MODEST_PROTOCOL_STORE_POP)
1515                 hostname = "pop";
1516         else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1517                 hostname = "imap";
1518         else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1519                 hostname = "smtp";
1520         
1521         if (!hostname)
1522                 return NULL;
1523                 
1524         return g_strdup_printf ("%s.%s", hostname, domain);
1525 }
1526
1527 static void 
1528 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1529 {
1530         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1531
1532         if (!priv->entry_incomingserver)
1533                 return;
1534                 
1535         /* Set a default domain for the server, based on the email address,
1536          * if no server name was already specified.
1537          */
1538         if (priv->entry_user_email
1539             && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1540                 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1541                         EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1542                 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1543                 
1544                 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1545
1546                 /* Do not set the INCOMING_CHANGED flag because of this edit */
1547                 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1548                 gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
1549                 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1550
1551                 g_free (servername);
1552         }
1553         
1554         /* Set a default domain for the server, based on the email address,
1555          * if no server name was already specified.
1556          */
1557         if (!priv->entry_outgoingserver)
1558                 return;
1559                 
1560         if (priv->entry_user_email
1561             && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1562                 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1563                 
1564                 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1565
1566                 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1567                 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1568                 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), servername);
1569                 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1570
1571                 g_free (servername);
1572         }
1573 }
1574
1575 static gchar*
1576 get_entered_account_title (ModestEasysetupWizardDialog *self)
1577 {
1578         ModestEasysetupWizardDialogPrivate *priv;
1579         const gchar* account_title;
1580
1581         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1582         account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
1583
1584         if (!account_title || (strlen (account_title) == 0)) {
1585                 return NULL;
1586         } else {
1587                 /* Strip it of whitespace at the start and end: */
1588                 gchar *result = g_strdup (account_title);
1589                 result = g_strstrip (result);
1590                 
1591                 if (!result)
1592                         return NULL;
1593                         
1594                 if (strlen (result) == 0) {
1595                         g_free (result);
1596                         return NULL;    
1597                 }
1598                 
1599                 return result;
1600         }
1601 }
1602
1603 static gboolean
1604 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1605 {
1606         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1607         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1608
1609         /* if are browsing pages previous to the last one, then we have pending settings in
1610          * this wizard */
1611         if (next_page != NULL)
1612                 priv->pending_load_settings = TRUE;
1613         
1614         /* Do extra validation that couldn't be done for every key press,
1615          * either because it was too slow,
1616          * or because it requires interaction:
1617          */
1618         if (current_page == priv->page_account_details) {       
1619                 /* Check that the title is not already in use: */
1620                 gchar* account_title = get_entered_account_title (self);
1621                 if (!account_title)
1622                         return FALSE;
1623                         
1624                 /* Aavoid a clash with an existing display name: */
1625                 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1626                         priv->account_manager, account_title);
1627
1628                 if (name_in_use) {
1629                         /* Warn the user via a dialog: */
1630                         hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1631             
1632                         return FALSE;
1633                 }
1634         }
1635         else if (current_page == priv->page_user_details) {
1636                 /* Check that the email address is valud: */
1637                 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1638                 if ((!email_address) || (strlen(email_address) == 0))
1639                         return FALSE;
1640                         
1641                 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1642                         /* Warn the user via a dialog: */
1643                         hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1644                                              
1645                         /* Return focus to the email address entry: */
1646                         gtk_widget_grab_focus (priv->entry_user_email);
1647                         gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1648
1649                         return FALSE;
1650                 }
1651                 
1652                 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1653                 create_subsequent_pages (self);
1654         }
1655         
1656         /* TODO: The UI Spec wants us to check that the servernames are valid, 
1657          * but does not specify how.
1658          */
1659           
1660         if(next_page == priv->page_custom_incoming) {
1661                 set_default_custom_servernames (self);
1662         }
1663         else if (next_page == priv->page_custom_outgoing) {
1664                 set_default_custom_servernames (self);
1665
1666                 /* Check if the server supports secure authentication */
1667                 const ModestConnectionProtocol security_incoming = 
1668                         modest_serversecurity_combo_box_get_active_serversecurity (
1669                                 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1670                 if (gtk_toggle_button_get_active (
1671                         GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))
1672                                 && !modest_protocol_info_is_secure(security_incoming))
1673                 {
1674                                 if (!check_has_supported_auth_methods (self))
1675                                         return FALSE;
1676                 }
1677         }
1678         
1679         /* If this is the last page, and this is a click on Finish, 
1680          * then attempt to create the dialog.
1681          */
1682         if(!next_page) /* This is NULL when this is a click on Finish. */
1683         {
1684                 if (priv->pending_load_settings) {
1685                         save_to_settings (self);
1686                 }
1687                 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1688         }
1689         
1690         
1691         return TRUE;
1692 }
1693
1694 static gboolean entry_is_empty (GtkWidget *entry)
1695 {
1696         if (!entry)
1697                 return FALSE;
1698                 
1699         const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1700         if ((!text) || (strlen(text) == 0))
1701                 return TRUE;
1702         else {
1703                 /* Strip it of whitespace at the start and end: */
1704                 gchar *stripped = g_strdup (text);
1705                 stripped = g_strstrip (stripped);
1706                 
1707                 if (!stripped)
1708                         return TRUE;
1709                         
1710                 const gboolean result = (strlen (stripped) == 0);
1711                 
1712                 g_free (stripped);
1713                 return result;
1714         }
1715 }
1716
1717 static void
1718 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1719 {
1720         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1721         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1722         
1723         gboolean enable_next = TRUE;
1724         if (current_page == priv->page_welcome) {
1725                 enable_next = TRUE;
1726         }
1727         else if (current_page == priv->page_account_details) {
1728                 /* The account details title is mandatory: */
1729                 if (entry_is_empty(priv->entry_account_title))
1730                         enable_next = FALSE;
1731         }
1732         else if (current_page == priv->page_user_details) {     
1733                 /* The user details username is mandatory: */
1734                 if (entry_is_empty(priv->entry_user_username))
1735                         enable_next = FALSE;
1736                         
1737                 /* The user details email address is mandatory: */
1738                 if (enable_next && entry_is_empty (priv->entry_user_email))
1739                         enable_next = FALSE;
1740         }
1741         else if (current_page == priv->page_custom_incoming) {
1742                 /* The custom incoming server is mandatory: */
1743                 if (entry_is_empty(priv->entry_incomingserver))
1744                         enable_next = FALSE;
1745         }
1746                         
1747         /* Enable the buttons, 
1748          * identifying them via their associated response codes: */
1749                                    
1750         /* Disable the Finish button until we are on the last page,
1751          * because HildonWizardDialog enables this for all but the first page: */
1752         GtkNotebook *notebook = NULL;
1753         GtkDialog *dialog_base = GTK_DIALOG (dialog);
1754         g_object_get (dialog_base, "wizard-notebook", &notebook, NULL);
1755         
1756         gint current = gtk_notebook_get_current_page (notebook);
1757         gint last = gtk_notebook_get_n_pages (notebook) - 1;
1758         const gboolean is_last = (current == last);
1759     
1760         if(!is_last) {
1761                 gtk_dialog_set_response_sensitive (dialog_base,
1762                                                    MODEST_WIZARD_DIALOG_FINISH,
1763                                                    FALSE);
1764         } else
1765         {
1766                 /* Disable Next on the last page: */
1767                 enable_next = FALSE;
1768         }
1769         
1770         gtk_dialog_set_response_sensitive (dialog_base,
1771                                            MODEST_WIZARD_DIALOG_NEXT,
1772                                            enable_next);
1773 }
1774
1775 static void
1776 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1777 {
1778         GObjectClass *object_class = G_OBJECT_CLASS (klass);
1779         g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1780
1781
1782         object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1783         object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1784         object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1785         object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1786         
1787         /* Provide a vfunc implementation so we can decide 
1788          * when to enable/disable the prev/next buttons.
1789          */
1790         ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1791         base_klass->before_next = on_before_next;
1792         base_klass->enable_buttons = on_enable_buttons;
1793 }
1794  
1795 static void
1796 show_error (GtkWidget *parent_widget, const gchar* text)
1797 {
1798         //TODO: Apparently this doesn't show anything in Maemo Bora:
1799         hildon_banner_show_information(parent_widget, NULL, text);      
1800 }
1801
1802
1803 /**
1804  * save_to_settings:
1805  * @self: a #ModestEasysetupWizardDialog
1806  *
1807  * takes information from all the wizard and stores it in settings
1808  */
1809 static void
1810 save_to_settings (ModestEasysetupWizardDialog *self)
1811 {
1812         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1813         guint special_port;
1814         gchar *provider_id;
1815         gchar* display_name;
1816         const gchar *username, *password;
1817         gchar *store_hostname, *transport_hostname;
1818         guint store_port, transport_port;
1819         ModestTransportStoreProtocol store_protocol, transport_protocol;
1820         ModestConnectionProtocol store_security, transport_security;
1821         ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
1822         ModestServerAccountSettings *store_settings, *transport_settings;
1823         const gchar *fullname, *email_address;
1824
1825         /* Get details from the specified presets: */
1826         provider_id = easysetup_provider_combo_box_get_active_provider_id (
1827                 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
1828                 
1829         /* username and password (for both incoming and outgoing): */
1830         username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1831         password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1832
1833         /* Incoming server: */
1834         /* Note: We need something as default for the ModestTransportStoreProtocol* values, 
1835          * or modest_account_mgr_add_server_account will fail. */
1836         store_port = 0;
1837         store_protocol = MODEST_PROTOCOL_STORE_POP;
1838         store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1839         store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1840
1841         if (provider_id) {
1842                 ModestPresetsServerType store_provider_server_type;
1843                 ModestPresetsSecurity store_provider_security;
1844                 /* Use presets: */
1845                 store_hostname = modest_presets_get_server (priv->presets, provider_id, 
1846                                                             TRUE /* store */);
1847                 
1848                 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1849                                                                          provider_id, 
1850                                                                          TRUE /* store */);
1851                 store_provider_security  = modest_presets_get_info_server_security (priv->presets,
1852                                                                                     provider_id, 
1853                                                                                     TRUE /* store */);
1854
1855                 /* We don't check for SMTP here as that is impossible for an incoming server. */
1856                 if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
1857                         store_protocol = MODEST_PROTOCOL_STORE_IMAP;
1858                 else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
1859                         store_protocol = MODEST_PROTOCOL_STORE_POP;
1860                 else /* fallback */
1861                         store_protocol = MODEST_PROTOCOL_STORE_POP;
1862
1863                 /* we check if there is a *special* port */
1864                 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1865                 if (special_port != 0)
1866                         store_port = special_port;
1867                 else 
1868                         store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
1869                 
1870                 if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1871                         store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1872                 
1873                 if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
1874                         store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1875         } else {
1876                 /* Use custom pages because no preset was specified: */
1877                 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));               
1878                 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1879                         EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));              
1880                 store_security = modest_serversecurity_combo_box_get_active_serversecurity (
1881                         MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1882                 
1883                 /* The UI spec says: 
1884                  * If secure authentication is unchecked, allow sending username and password also as plain text.
1885                  * If secure authentication is checked, require one of the secure methods during 
1886                  * connection: SSL, TLS, CRAM-MD5 etc. */
1887                 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth)) &&
1888                     !modest_protocol_info_is_secure(store_security)) {
1889                         store_auth_protocol = check_first_supported_auth_method (self);
1890                 } else {
1891                         store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1892                 }
1893         }
1894
1895         /* now we store the store account settings */
1896         store_settings = modest_account_settings_get_store_settings (priv->settings);
1897         modest_server_account_settings_set_hostname (store_settings, store_hostname);
1898         modest_server_account_settings_set_username (store_settings, username);
1899         modest_server_account_settings_set_password (store_settings, password);
1900         modest_server_account_settings_set_protocol (store_settings, store_protocol);
1901         modest_server_account_settings_set_security (store_settings, store_security);
1902         modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1903         if (store_port != 0)
1904                 modest_server_account_settings_set_port (store_settings, store_port);
1905
1906         g_object_unref (store_settings);
1907         g_free (store_hostname);
1908         
1909         /* Outgoing server: */
1910         transport_hostname = NULL;
1911         transport_protocol = MODEST_PROTOCOL_STORE_POP;
1912         transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1913         transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1914         transport_port = 0;
1915         
1916         if (provider_id) {
1917                 ModestPresetsServerType transport_provider_server_type;
1918                 ModestPresetsSecurity transport_provider_security;
1919
1920                 /* Use presets: */
1921                 transport_hostname = modest_presets_get_server (priv->presets, provider_id, 
1922                                                                 FALSE /* transport */);
1923                         
1924                 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1925                                                                                       provider_id, 
1926                                                                                       FALSE /* transport */);           
1927                 transport_provider_security = modest_presets_get_info_server_security (priv->presets, 
1928                                                                                        provider_id, 
1929                                                                                        FALSE /* transport */);
1930
1931                 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1932                 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL; 
1933                 if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
1934                         transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
1935
1936                 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1937                 if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1938                         /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1939                         transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1940                         /* we check if there is a *special* port */
1941                         special_port = modest_presets_get_port (priv->presets, provider_id,
1942                                                                 FALSE /* transport */);
1943                         if (special_port != 0)
1944                                 transport_port = special_port;
1945                         else 
1946                                 transport_port = 465;
1947                         transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1948                 } else {
1949                         /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1950                         transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1951                 }
1952         } else {
1953                 /* Use custom pages because no preset was specified: */
1954                 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
1955                 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1956                 transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
1957                         MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));               
1958                 transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
1959                         MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
1960         }
1961             
1962         /* now we transport the transport account settings */
1963         transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1964         modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1965         modest_server_account_settings_set_username (transport_settings, username);
1966         modest_server_account_settings_set_password (transport_settings, password);
1967         modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1968         modest_server_account_settings_set_security (transport_settings, transport_security);
1969         modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1970         if (transport_port != 0)
1971                 modest_server_account_settings_set_port (transport_settings, transport_port);
1972
1973         g_object_unref (transport_settings);
1974         g_free (transport_hostname);
1975         
1976         fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1977         email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1978         modest_account_settings_set_fullname (priv->settings, fullname);
1979         modest_account_settings_set_email_address (priv->settings, email_address);
1980         /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1981            are set to headers only */
1982         
1983         /* Save the connection-specific SMTP server accounts. */
1984         modest_account_settings_set_use_connection_specific_smtp 
1985                 (priv->settings, 
1986                  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1987
1988         display_name = get_entered_account_title (self);
1989         modest_account_settings_set_display_name (priv->settings, display_name);
1990         g_free (display_name);
1991
1992         if (priv->specific_window)
1993                 modest_connection_specific_smtp_window_save_server_accounts (
1994                         MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window));
1995 }
1996