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