529de6b0c9717bd4b5bdb2f7dcf20b9d4710def9
[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                 ModestProtocol *protocol;
638                 GtkWidget *label;
639                 GList *children;
640
641                 /* Get the label and change it. This is ugly */
642                 children = gtk_container_get_children (GTK_CONTAINER (priv->caption_incoming));
643                 label = (GtkWidget *) children->data;
644
645                 if (!GTK_IS_LABEL (label))
646                         return;
647
648                 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, 
649                                                                           protocol_type);
650                 protocol_display_name = modest_protocol_get_display_name (protocol);
651
652                 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), 
653                                                        protocol_display_name);
654
655                 gtk_label_set_markup (GTK_LABEL (label), incomingserver_title);
656
657                 g_free(incomingserver_title);
658         }
659 }
660
661 /** Change the caption title for the incoming server, 
662  * as specified in the UI spec:
663  */
664 static void 
665 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
666 {
667         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
668         ModestServertypePicker *server_type_picker;
669         ModestProtocolType protocol_type;
670         ModestSecurityOptionsView *view;
671
672         server_type_picker = 
673                 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
674         protocol_type = 
675                 modest_servertype_picker_get_active_servertype (server_type_picker);
676         
677         /* Fill the combo with appropriately titled choices for all
678            those protocols */
679         view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
680         modest_security_options_view_set_server_type (view, protocol_type);
681 }
682
683 static void 
684 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
685 {
686         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
687         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
688         ModestServertypePicker *picker;
689         ModestProtocolType protocol_type;
690
691         priv->dirty = TRUE;
692         
693         /* Update title */
694         update_incoming_server_title (self);
695
696         /* Update security options if needed */
697         picker = MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
698         protocol_type = modest_servertype_picker_get_active_servertype (picker);
699         update_incoming_server_security_choices (self);
700         gtk_widget_show (priv->incoming_security);
701
702         set_default_custom_servernames (self);
703 }
704
705 static void 
706 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
707 {
708         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
709         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
710         priv->dirty = TRUE;
711         priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
712 }
713
714 static GtkWidget* 
715 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
716 {
717         ModestProtocolRegistry *protocol_registry;
718         ModestEasysetupWizardDialogPrivate* priv; 
719         GtkWidget *box; 
720         GtkWidget *scrolled_window;
721         GtkWidget *label;
722         GtkSizeGroup *title_sizegroup;
723         GtkSizeGroup *value_sizegroup;
724
725         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
726         protocol_registry = modest_runtime_get_protocol_registry ();
727
728         box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
729         scrolled_window = gtk_scrolled_window_new (NULL, NULL);
730
731         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
732                                         GTK_POLICY_NEVER,
733                                         GTK_POLICY_AUTOMATIC);
734
735         /* Show note that account type cannot be changed in future: */
736         label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
737         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
738         gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
739         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
740         gtk_widget_show (label);
741         
742         /* Create a size group to be used by all captions.
743          * Note that HildonCaption does not create a default size group if we do not specify one.
744          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
745         title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
746         value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
747          
748         /* The incoming server widgets: */
749         priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
750                                                                                      HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
751                                                                                      TRUE));
752         hildon_button_set_title (HILDON_BUTTON (priv->incoming_servertype_picker), _("mcen_li_emailsetup_type"));
753         g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
754                           G_CALLBACK (on_picker_button_value_changed), self);
755         gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
756         gtk_widget_show (priv->incoming_servertype_picker);
757         
758         priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
759         g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
760         /* Auto-capitalization is the default, so let's turn it off: */
761         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
762         set_default_custom_servernames (self);
763
764         /* The caption title will be updated in update_incoming_server_title().
765          * so this default text will never be seen: */
766         priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
767                                                    "This will be removed", 
768                                                    priv->entry_incomingserver);
769         update_incoming_server_title (self);
770         gtk_widget_show (priv->entry_incomingserver);
771         gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
772         gtk_widget_show (priv->caption_incoming);
773         
774         /* Change the caption title when the servertype changes, 
775          * as in the UI spec: */
776         g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))), 
777                           "changed",
778                           G_CALLBACK (on_servertype_selector_changed), self);
779
780         /* Remember when the servername was changed manually: */
781         g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
782                           G_CALLBACK (on_entry_incoming_servername_changed), self);
783
784         /* The secure connection widgets. These are only valid for
785            protocols with security */   
786         priv->incoming_security = 
787                 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
788                                                         FALSE, title_sizegroup, value_sizegroup);
789         gtk_box_pack_start (GTK_BOX (box), priv->incoming_security, 
790                             FALSE, FALSE, MODEST_MARGIN_HALF);
791         gtk_widget_show_all (priv->incoming_security);
792
793         /* Set default selection */
794         modest_servertype_picker_set_active_servertype (
795                 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker), 
796                 MODEST_PROTOCOLS_STORE_POP);
797
798         gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
799         gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
800                                              gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
801         gtk_widget_show (GTK_WIDGET (box));
802         gtk_widget_show (scrolled_window);
803
804         g_object_unref (title_sizegroup);
805         g_object_unref (value_sizegroup);
806
807         return GTK_WIDGET (scrolled_window);
808 }
809
810 static void
811 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
812 {
813         GtkWidget *widget = GTK_WIDGET (user_data);
814         
815         /* Enable the widget only if the check button is active: */
816         const gboolean enable = hildon_check_button_get_active (button);
817         gtk_widget_set_sensitive (widget, enable);
818 }
819
820 /* Make the sensitivity of a widget depend on a check button.
821  */
822 static void
823 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
824 {
825         g_signal_connect (G_OBJECT (button), "toggled",
826                           G_CALLBACK (on_check_button_changed), widget);
827         
828         /* Set the starting sensitivity: */
829         on_check_button_changed (button, widget);
830 }
831
832 static void
833 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
834 {
835         ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
836         ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
837         GtkWidget *specific_window;
838         
839         /* We set dirty here because setting it depending on the connection specific dialog
840         seems overkill */
841         priv->dirty = TRUE;
842         
843         /* Create the window, if necessary: */
844         specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
845         modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
846
847         /* Show the window */
848         modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
849         gtk_widget_show (specific_window);
850 }
851
852 static void 
853 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
854 {
855         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
856         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
857         priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
858 }
859
860 static GtkWidget* 
861 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
862 {
863         ModestEasysetupWizardDialogPrivate *priv;
864         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
865         
866         /* Create a size group to be used by all captions.
867          * Note that HildonCaption does not create a default size group if we do not specify one.
868          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
869         GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
870         GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
871          
872         /* The outgoing server widgets: */
873         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
874         priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
875         g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
876                   G_CALLBACK (on_easysetup_changed), self);
877         /* Auto-capitalization is the default, so let's turn it off: */
878         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
879         GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
880                                                _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver);
881         gtk_widget_show (priv->entry_outgoingserver);
882         gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
883         gtk_widget_show (caption);
884         set_default_custom_servernames (self);
885
886         /* The secure connection widgets. These are only valid for
887            protocols with security */   
888         priv->outgoing_security = 
889                 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
890                                                         FALSE, title_sizegroup, value_sizegroup);
891         gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security, 
892                             FALSE, FALSE, MODEST_MARGIN_HALF);
893         gtk_widget_show (priv->outgoing_security);
894
895         GtkWidget *separator = gtk_hseparator_new ();
896         gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
897         gtk_widget_show (separator);
898
899         /* connection-specific checkbox: */
900         priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
901         hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific), 
902                                         FALSE);
903         gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
904                               _("mcen_fi_advsetup_connection_smtp"));
905         gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
906                                   0.0, 0.5);
907         g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
908                   G_CALLBACK (on_easysetup_changed), self);
909
910         gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
911         gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
912                             FALSE, FALSE, MODEST_MARGIN_HALF);
913
914         /* Connection-specific SMTP-Severs Edit button: */
915         priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
916         hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers, 
917                                           HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);  
918         gtk_widget_show (priv->button_outgoing_smtp_servers);
919         gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers, 
920                             FALSE, FALSE, MODEST_MARGIN_HALF);
921
922         /* Only enable the button when the checkbox is checked: */
923         enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers, 
924                                        HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
925
926         g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
927                           G_CALLBACK (on_button_outgoing_smtp_servers), self);
928
929         g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
930                           G_CALLBACK (on_entry_outgoing_servername_changed), self);
931         gtk_widget_show (GTK_WIDGET (box));
932
933         g_object_unref (title_sizegroup);
934         g_object_unref (value_sizegroup);
935         
936         return GTK_WIDGET (box);
937 }
938
939 static gboolean
940 show_advanced_edit(gpointer user_data)
941 {
942         ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
943         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
944         gint response;
945         
946         /* Show the Account Settings window: */
947         ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
948         if (priv->pending_load_settings) {
949                 save_to_settings (self);
950                 priv->pending_load_settings = FALSE;
951         }
952         modest_account_settings_dialog_load_settings (dialog, priv->settings);
953         
954         modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
955         
956         response = gtk_dialog_run (GTK_DIALOG (dialog));
957
958         gtk_widget_destroy (GTK_WIDGET (dialog));
959         
960         return FALSE; /* Do not call this timeout callback again. */
961 }
962
963 static void
964 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
965 {
966         ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
967         
968         /* Show the Account Settings window: */
969         show_advanced_edit(self);
970 }
971 static GtkWidget* 
972 create_page_complete_custom (ModestEasysetupWizardDialog *self)
973 {
974         GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
975         GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
976         GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
977         hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
978         gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
979         gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
980         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
981         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
982         gtk_widget_show (label);
983         
984         label = gtk_label_new (_("mcen_ia_customsetup_complete"));
985         gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
986         gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
987         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
988         gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
989         gtk_widget_show (label);
990         
991         gtk_widget_show (button_edit);
992         gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, MODEST_MARGIN_HALF);
993         
994         g_signal_connect (G_OBJECT (button_edit), "clicked", 
995                           G_CALLBACK (on_button_edit_advanced_settings), self);
996         
997         gtk_widget_show (GTK_WIDGET (box));
998         return GTK_WIDGET (box);
999 }
1000
1001
1002 /*
1003  */
1004 static void 
1005 on_response (ModestWizardDialog *wizard_dialog,
1006              gint response_id,
1007              gpointer user_data)
1008 {
1009         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1010
1011         invoke_enable_buttons_vfunc (self);
1012 }
1013
1014 static void 
1015 on_response_before (ModestWizardDialog *wizard_dialog,
1016                     gint response_id,
1017                     gpointer user_data)
1018 {
1019         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1020         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1021         if (response_id == GTK_RESPONSE_CANCEL) {
1022                 /* This is mostly copied from
1023                  * src/maemo/modest-account-settings-dialog.c */
1024                 if (priv->dirty) {
1025                         GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self), 
1026                                 _("imum_nc_wizard_confirm_lose_changes")));
1027                         /* TODO: These button names will be ambiguous, and not
1028                          * specified in the UI specification. */
1029
1030                         const gint dialog_response = gtk_dialog_run (dialog);
1031                         gtk_widget_destroy (GTK_WIDGET (dialog));
1032
1033                         if (dialog_response != GTK_RESPONSE_OK) {
1034                                 /* Don't let the dialog close */
1035                                 g_signal_stop_emission_by_name (wizard_dialog, "response");
1036                         }
1037                 }
1038         }
1039 }
1040
1041 typedef struct IdleData {
1042         ModestEasysetupWizardDialog *dialog;
1043         ModestPresets *presets;
1044 } IdleData;
1045
1046 static gboolean
1047 presets_idle (gpointer userdata)
1048 {
1049         IdleData *idle_data = (IdleData *) userdata;
1050         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1051         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1052
1053         g_assert (idle_data->presets);
1054
1055         gdk_threads_enter ();
1056
1057         priv->presets = idle_data->presets;
1058
1059         if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1060 /*              gint mcc = get_default_country_code(); */
1061                 gint mcc;
1062                 /* Fill the combo in an idle call, as it takes a lot of time */
1063                 modest_country_picker_load_data(
1064                         MODEST_COUNTRY_PICKER (priv->account_country_picker));
1065                 /* connect to country picker's changed signal, so we can fill the provider picker: */
1066                 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector 
1067                                             (HILDON_PICKER_BUTTON (priv->account_country_picker))),
1068                                   "changed",
1069                                   G_CALLBACK (on_account_country_selector_changed), self);
1070             
1071                 modest_country_picker_set_active_country_locale (
1072                         MODEST_COUNTRY_PICKER (priv->account_country_picker));
1073                 mcc = modest_country_picker_get_active_country_mcc (
1074                         MODEST_COUNTRY_PICKER (priv->account_country_picker));
1075                 modest_provider_picker_fill (
1076                         MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1077                         priv->presets, mcc);
1078                 /* connect to providers picker's changed signal, so we can fill the email address: */
1079                 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector 
1080                                             (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1081                                   "changed",
1082                                   G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1083                 
1084                 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1085         }
1086
1087         priv->dirty = FALSE;
1088
1089         g_object_unref (idle_data->dialog);
1090         g_free (idle_data);
1091
1092         gdk_threads_leave ();
1093
1094         return FALSE;
1095 }
1096
1097 static gpointer
1098 presets_loader (gpointer userdata)
1099 {
1100         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1101         ModestPresets *presets = NULL;
1102         IdleData *idle_data;
1103
1104         const gchar* path  = NULL;
1105         const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1106         const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1107         
1108         if (access(path1, R_OK) == 0) 
1109                 path = path1;
1110         else if (access(path2, R_OK) == 0)
1111                 path = path2;
1112         else {
1113                 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1114                            __FUNCTION__, path1, path2);
1115                 return NULL;
1116         }
1117
1118         presets = modest_presets_new (path);
1119         if (!presets) {
1120                 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1121                 return NULL;
1122         }
1123         
1124         idle_data = g_new0 (IdleData, 1);
1125         idle_data->dialog = self;
1126         idle_data->presets = presets;
1127         
1128         g_idle_add (presets_idle, idle_data);   
1129
1130         return NULL;
1131 }
1132
1133 static void
1134 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1135                                             GtkWidget *page,
1136                                             const gchar *label)
1137 {
1138         gint index;
1139         /* Append page and set attributes */
1140         index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1141         gtk_container_child_set (GTK_CONTAINER (notebook), page,
1142                                  "tab-expand", TRUE, "tab-fill", TRUE,
1143                                  NULL);
1144         gtk_widget_show (page);
1145 }
1146
1147 static void
1148 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1149 {
1150         priv->page_user_details = NULL;
1151         priv->entry_user_name = NULL;
1152         priv->entry_user_username = NULL;
1153         priv->entry_user_password = NULL;
1154         priv->entry_user_email = NULL;
1155 }
1156
1157 static void
1158 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1159 {
1160         priv->page_custom_incoming = NULL;
1161         priv->incoming_servertype_picker = NULL;
1162         priv->caption_incoming = NULL;
1163         priv->entry_incomingserver = NULL;
1164         priv->entry_user_email = NULL;
1165         priv->incoming_security = NULL;
1166 }
1167
1168 static void
1169 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1170 {
1171         priv->page_custom_outgoing = NULL;
1172         priv->entry_outgoingserver = NULL;
1173         priv->checkbox_outgoing_smtp_specific = NULL;
1174         priv->button_outgoing_smtp_servers = NULL;
1175         priv->outgoing_security = NULL;
1176 }
1177
1178 static void
1179 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1180 {
1181         gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1182         
1183         /* Create the notebook to be used by the ModestWizardDialog base class:
1184          * Each page of the notebook will be a page of the wizard: */
1185         GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1186         gtk_widget_set_size_request (GTK_WIDGET (notebook), DIALOG_WIDTH, -1);
1187         
1188         /* Set the notebook used by the ModestWizardDialog base class: */
1189         g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1190     
1191         /* Set the wizard title:
1192          * The actual window title will be a combination of this and the page's tab label title. */
1193         g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1194
1195         /* Read in the information about known service providers: */
1196         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1197         
1198         /* The server fields did not have been manually changed yet */
1199         priv->server_changes = 0;
1200         priv->pending_load_settings = TRUE;
1201
1202         /* Get the account manager object, 
1203          * so we can check for existing accounts,
1204          * and create new accounts: */
1205         priv->account_manager = modest_runtime_get_account_mgr ();
1206         g_object_ref (priv->account_manager);
1207         
1208         /* Initialize fields */
1209         priv->page_welcome = create_page_welcome (self);
1210         priv->page_account_details = create_page_account_details (self);
1211
1212         init_user_page (priv);
1213         init_incoming_page (priv);
1214         init_outgoing_page (priv);
1215
1216         priv->page_complete_easysetup = NULL;       
1217         priv->page_complete_customsetup = NULL;
1218         priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1219         priv->missing_data_signals = NULL;
1220
1221         /* Add the common pages */
1222         modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome, 
1223                                                     _("mcen_ti_emailsetup_welcome"));
1224         modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details, 
1225                                                     _("mcen_ti_accountdetails"));
1226                 
1227         /* Connect to the dialog's response signal so we can enable/disable buttons 
1228          * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1229          * Note that we use g_signal_connect_after() instead of g_signal_connect()
1230          * so that we can be enable/disable after ModestWizardDialog has done its own 
1231          * enabling/disabling of buttons.
1232          * 
1233          * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler 
1234          * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1235          * 
1236          * It's not enough to connect to the notebook's switch-page signal, because 
1237          * ModestWizardDialog's "response" signal handler enables the buttons itself, 
1238          * _after_ switching the page (understandably).
1239          * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1240          * then gtk_notebook_get_current_page() would return an incorrect value.)
1241          */
1242         g_signal_connect_after (G_OBJECT (self), "response",
1243                                 G_CALLBACK (on_response), self);
1244
1245         /* This is to show a confirmation dialog when the user hits cancel */
1246         g_signal_connect (G_OBJECT (self), "response",
1247                           G_CALLBACK (on_response_before), self);
1248
1249         g_signal_connect (G_OBJECT (self), "delete-event",
1250                           G_CALLBACK (on_delete_event), self);
1251
1252         /* Reset dirty, because there was no user input until now */
1253         priv->dirty = FALSE;
1254         
1255         /* When this window is shown, hibernation should not be possible, 
1256          * because there is no sensible way to save the state: */
1257         modest_window_mgr_prevent_hibernation_while_window_is_shown (
1258                 modest_runtime_get_window_mgr (), GTK_WINDOW (self)); 
1259
1260         /* Load provider presets */
1261         g_object_ref (self);
1262         g_thread_create (presets_loader, self, FALSE, NULL);
1263
1264         priv->settings = modest_account_settings_new ();
1265 }
1266
1267 ModestEasysetupWizardDialog*
1268 modest_easysetup_wizard_dialog_new (void)
1269 {       
1270         
1271         return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1272 }
1273
1274 static void 
1275 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1276 {
1277         ModestEasysetupWizardDialogPrivate *priv;
1278         GtkNotebook *notebook = NULL;
1279
1280         g_object_get (self, "wizard-notebook", &notebook, NULL);
1281         g_assert(notebook);
1282
1283         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1284
1285         if (!priv->page_user_details) {
1286                 priv->page_user_details = create_page_user_details (self);
1287         }                       
1288
1289         /* Create the custom pages: */
1290         if(!(priv->page_custom_incoming)) {
1291                 priv->page_custom_incoming = create_page_custom_incoming (self);
1292         }
1293                 
1294         /* TODO: only if needed */
1295         if(!(priv->page_custom_outgoing)) {
1296                 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1297         }
1298         
1299         if(!(priv->page_complete_customsetup)) {
1300                 priv->page_complete_customsetup = create_page_complete_custom (self);
1301         }
1302
1303         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1304                 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1305                                                             _("mcen_ti_emailsetup_userdetails"));
1306
1307         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1308                 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming, 
1309                                                             _("mcen_ti_emailsetup_incomingdetails"));
1310         
1311         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))           
1312                 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing, 
1313                                                             _("mcen_ti_emailsetup_outgoingdetails"));
1314                 
1315         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1316                 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup, 
1317                                                             _("mcen_ti_emailsetup_complete"));
1318                         
1319         /* This is unnecessary with GTK+ 2.10: */
1320         modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1321 }
1322         
1323 static void 
1324 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1325 {
1326         ModestEasysetupWizardDialogPrivate *priv;
1327         GtkNotebook *notebook = NULL;
1328
1329         g_object_get (self, "wizard-notebook", &notebook, NULL);
1330         g_assert(notebook);
1331         
1332         /* Create the easysetup-specific pages: */
1333         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1334         if(!priv->page_complete_easysetup)
1335                 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1336
1337         if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1338                 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup, 
1339                                                             _("mcen_ti_emailsetup_complete"));
1340                         
1341         /* This is unnecessary with GTK+ 2.10: */
1342         modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1343 }
1344
1345 /* */
1346 static void
1347 remove_non_common_tabs (GtkNotebook *notebook, 
1348                         gboolean remove_user_details) 
1349 {
1350         gint starting_tab;
1351         /* The first 2 tabs are the common ones (welcome tab and the
1352            providers tab), so we always remove starting from the
1353            end */
1354
1355         starting_tab = (remove_user_details) ? 2 : 3;
1356         while (gtk_notebook_get_n_pages (notebook) > starting_tab) 
1357                 gtk_notebook_remove_page (notebook, -1); 
1358 }
1359
1360 static void
1361 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1362                            gboolean missing,
1363                            gpointer user_data)
1364 {
1365         real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1366 }
1367
1368 /* After the user details page,
1369  * the following pages depend on whether "Other" was chosen 
1370  * in the provider combobox on the account page
1371  */
1372 static void 
1373 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1374 {
1375         ModestEasysetupWizardDialogPrivate *priv;
1376         ModestProviderPicker *picker;
1377         ModestProviderPickerIdType id_type;
1378         GtkNotebook *notebook;
1379
1380         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1381         picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1382         id_type = modest_provider_picker_get_active_id_type (picker);
1383         g_object_get (self, "wizard-notebook", &notebook, NULL);
1384
1385         if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1386                 /* "Other..." was selected: */
1387
1388                 /* If we come from a rollbacked easysetup */
1389                 if (priv->page_complete_easysetup) {
1390                         remove_non_common_tabs (notebook, FALSE);
1391                         priv->page_complete_easysetup = NULL;
1392                 } 
1393                 
1394                 /* If we come from a rollbacked plugin protocol setup */
1395                 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1396                         remove_non_common_tabs (notebook, TRUE);
1397                         priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1398                         modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1399                         priv->missing_data_signals = NULL;
1400                 }
1401
1402                 create_subsequent_customsetup_pages (self);
1403         } else {
1404                 /* If we come from a rollbacked custom setup */
1405                 if (priv->page_custom_incoming) {
1406                         remove_non_common_tabs (notebook, TRUE);
1407                         init_user_page (priv);
1408                         init_incoming_page (priv);
1409                         init_outgoing_page (priv);
1410                         init_user_page (priv);
1411                         priv->page_complete_customsetup = NULL;
1412                 }
1413
1414                 /* It's a pluggable protocol and not a provider with presets */
1415                 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1416                         ModestProtocol *protocol;
1417                         gchar *proto_name;
1418                         ModestProtocolType proto_type;
1419
1420                         
1421                         /* If we come from a rollbacked easy setup */
1422                         if (priv->last_plugin_protocol_selected == 
1423                             MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1424                             priv->page_complete_easysetup) {
1425                                 remove_non_common_tabs (notebook, TRUE);
1426                                 init_user_page (priv);
1427                                 priv->page_complete_easysetup = NULL;
1428                         }
1429                         
1430                         proto_name = modest_provider_picker_get_active_provider_id (picker);
1431                         protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1432                                                                                   MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1433                                                                                   proto_name);
1434                         proto_type = modest_protocol_get_type_id (protocol);
1435
1436                         if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1437                             proto_type != priv->last_plugin_protocol_selected) {
1438                                 ModestPairList *tabs;
1439                                 GSList *tmp;
1440
1441                                 /* Remember the last selected plugin protocol */
1442                                 priv->last_plugin_protocol_selected = proto_type;
1443
1444                                 /* Get tabs */
1445                                 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1446                                 tmp = (GSList *) tabs;
1447                                 while (tmp) {
1448                                         ModestPair *pair = (ModestPair *) tmp->data;
1449                                         modest_easysetup_wizard_dialog_append_page (notebook,
1450                                                                                     GTK_WIDGET (pair->second),
1451                                                                                     (const gchar *) pair->first);
1452
1453                                         /* Connect signals */
1454                                         priv->missing_data_signals = 
1455                                                 modest_signal_mgr_connect (priv->missing_data_signals, 
1456                                                                            G_OBJECT (pair->second), 
1457                                                                            "missing-mandatory-data",
1458                                                                            G_CALLBACK (on_missing_mandatory_data), 
1459                                                                            self);
1460
1461                                         g_free (pair->first);
1462                                         tmp = g_slist_next (tmp);
1463                                         /* Critical: if you don't show the page then the dialog will ignore it */
1464 /*                                      gtk_widget_show (GTK_WIDGET (pair->second)); */
1465                                 }
1466                                 modest_pair_list_free (tabs);
1467                         }
1468                         g_free (proto_name);
1469                 } else {
1470                         if (priv->last_plugin_protocol_selected != 
1471                             MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1472                                 remove_non_common_tabs (notebook, TRUE);
1473                                 init_user_page (priv);
1474                                 priv->page_complete_easysetup = NULL;
1475                                 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1476                                 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1477                                 priv->missing_data_signals = NULL;
1478                         }
1479                         if (!priv->page_user_details) {
1480                                 priv->page_user_details = create_page_user_details (self);
1481                                 modest_easysetup_wizard_dialog_append_page (notebook, 
1482                                                                             priv->page_user_details,
1483                                                                             _("mcen_ti_emailsetup_userdetails"));
1484                         }
1485                 }
1486                 
1487                 /* Create the easysetup pages: */
1488                 create_subsequent_easysetup_pages (self);
1489         }
1490 }
1491
1492
1493 static gchar*
1494 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1495 {
1496         const gchar* hostname = NULL;
1497         gchar* at;
1498         gchar* domain;
1499         ModestProtocolRegistry *protocol_registry;
1500         ModestProtocol *protocol;
1501
1502         if (!email_address)
1503                 return NULL;
1504         
1505         at = g_utf8_strchr (email_address, -1, '@');
1506         if (!at || (g_utf8_strlen (at, -1) < 2))
1507                 return NULL;
1508                 
1509         domain = g_utf8_next_char (at);
1510         if(!domain)
1511                 return NULL;
1512
1513         protocol_registry = modest_runtime_get_protocol_registry ();
1514         protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1515                 
1516         if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1517             modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1518                 hostname = modest_protocol_get_name (protocol);
1519         }
1520         
1521         if (!hostname)
1522                 return NULL;
1523                 
1524         return g_strdup_printf ("%s.%s", hostname, domain);
1525 }
1526
1527 static void 
1528 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1529 {
1530         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1531
1532         if (!priv->entry_incomingserver)
1533                 return;
1534                 
1535         /* Set a default domain for the server, based on the email address,
1536          * if no server name was already specified.
1537          */
1538         if (priv->entry_user_email
1539             && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1540                 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1541                         MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1542
1543                 /* This could happen when the combo box has still no active iter */
1544                 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1545                         const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));      
1546                         gchar* servername = util_get_default_servername_from_email_address (email_address, 
1547                                                                                             protocol_type);
1548
1549                         /* Do not set the INCOMING_CHANGED flag because of this edit */
1550                         g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1551                         hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1552                         g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1553                         
1554                         g_free (servername);
1555                 }
1556         }
1557         
1558         /* Set a default domain for the server, based on the email address,
1559          * if no server name was already specified.
1560          */
1561         if (!priv->entry_outgoingserver)
1562                 return;
1563                 
1564         if (priv->entry_user_email
1565             && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1566                 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1567                 
1568                 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1569
1570                 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1571                 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1572                 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1573                 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1574
1575                 g_free (servername);
1576         }
1577 }
1578
1579 static gchar*
1580 get_entered_account_title (ModestEasysetupWizardDialog *self)
1581 {
1582         ModestEasysetupWizardDialogPrivate *priv;
1583         const gchar* account_title;
1584
1585         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1586         account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1587
1588         if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1589                 return NULL;
1590         } else {
1591                 /* Strip it of whitespace at the start and end: */
1592                 gchar *result = g_strdup (account_title);
1593                 result = g_strstrip (result);
1594                 
1595                 if (!result)
1596                         return NULL;
1597                         
1598                 if (g_utf8_strlen (result, -1) == 0) {
1599                         g_free (result);
1600                         return NULL;    
1601                 }
1602                 
1603                 return result;
1604         }
1605 }
1606
1607 static gboolean
1608 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1609 {
1610         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1611         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1612         ModestProtocolRegistry *protocol_registry;
1613
1614         protocol_registry = modest_runtime_get_protocol_registry ();
1615
1616         /* if are browsing pages previous to the last one, then we have pending settings in
1617          * this wizard */
1618         if (next_page != NULL)
1619                 priv->pending_load_settings = TRUE;
1620         
1621         /* Do extra validation that couldn't be done for every key press,
1622          * either because it was too slow,
1623          * or because it requires interaction:
1624          */
1625         if (current_page == priv->page_account_details) {       
1626                 /* Check that the title is not already in use: */
1627                 gchar* account_title = get_entered_account_title (self);
1628                 if (!account_title)
1629                         return FALSE;
1630                         
1631                 /* Aavoid a clash with an existing display name: */
1632                 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1633                         priv->account_manager, account_title);
1634                 g_free (account_title);
1635
1636                 if (name_in_use) {
1637                         /* Warn the user via a dialog: */
1638                         hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1639             
1640                         return FALSE;
1641                 }
1642
1643                 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1644                 create_subsequent_pages (self);
1645
1646         } else if (current_page == priv->page_user_details) {
1647                 /* Check that the email address is valud: */
1648                 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1649                 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1650                         return FALSE;
1651                         
1652                 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1653                         /* Warn the user via a dialog: */
1654                         hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1655                                              
1656                         /* Return focus to the email address entry: */
1657                         gtk_widget_grab_focus (priv->entry_user_email);
1658                         gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1659
1660                         return FALSE;
1661                 }
1662         }
1663           
1664         if (next_page == priv->page_custom_incoming) {
1665                 set_default_custom_servernames (self);
1666         } else if (next_page == priv->page_custom_outgoing) {
1667                 set_default_custom_servernames (self);
1668
1669                 /* Check if the server supports secure authentication */
1670 /*              if (modest_security_options_view_auth_check (security_options)) */
1671 /*                      if (!check_has_supported_auth_methods (self)) */
1672 /*                              return FALSE; */
1673                 gtk_widget_show (priv->outgoing_security);
1674         }
1675         
1676         /* If this is the last page, and this is a click on Finish, 
1677          * then attempt to create the dialog.
1678          */
1679         if(!next_page && 
1680            current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1681         {
1682                 if (priv->pending_load_settings) {
1683                         save_to_settings (self);
1684                 }
1685
1686                 /* We check if there's already another account with the same configuration */
1687                 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1688                         modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1689                         return FALSE;
1690                 }
1691
1692                 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1693         }
1694         
1695         
1696         return TRUE;
1697 }
1698
1699 static gboolean entry_is_empty (GtkWidget *entry)
1700 {
1701         if (!entry)
1702                 return FALSE;
1703                 
1704         const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1705         if ((!text) || (g_utf8_strlen (text, -1) == 0))
1706                 return TRUE;
1707         else {
1708                 /* Strip it of whitespace at the start and end: */
1709                 gchar *stripped = g_strdup (text);
1710                 stripped = g_strstrip (stripped);
1711                 
1712                 if (!stripped)
1713                         return TRUE;
1714                         
1715                 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1716                 
1717                 g_free (stripped);
1718                 return result;
1719         }
1720 }
1721
1722 static void
1723 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1724 {               
1725         GtkNotebook *notebook = NULL;
1726         gboolean is_finish_tab;
1727         GtkWidget *current;
1728         ModestEasysetupWizardDialogPrivate *priv;
1729
1730         /* Get data */
1731         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1732         g_object_get (dialog, "wizard-notebook", &notebook, NULL);
1733         
1734         /* Disable the Finish button until we are on the last page,
1735          * because HildonWizardDialog enables this for all but the
1736          * first page */
1737         current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1738         is_finish_tab = ((current == priv->page_complete_easysetup) ||
1739                          (current == priv->page_complete_customsetup));
1740
1741         if (is_finish_tab) {
1742                 /* Disable Next on the last page no matter what the
1743                    argument say */
1744                 enable_next = FALSE;
1745         } else {
1746                 /* Not the last one */
1747                 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1748                                                    MODEST_WIZARD_DIALOG_FINISH,
1749                                                    FALSE);
1750         }
1751         
1752         gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1753                                            MODEST_WIZARD_DIALOG_NEXT,
1754                                            enable_next);
1755 }
1756
1757 static void
1758 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1759 {
1760         ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1761         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1762         
1763         gboolean enable_next = TRUE;
1764         if (current_page == priv->page_welcome) {
1765                 enable_next = TRUE;
1766         } else if (current_page == priv->page_account_details) {
1767                 /* The account details title is mandatory: */
1768                 if (entry_is_empty(priv->entry_account_title))
1769                         enable_next = FALSE;
1770         } else if (current_page == priv->page_user_details) {   
1771                 /* The user details username is mandatory: */
1772                 if (entry_is_empty(priv->entry_user_username))
1773                         enable_next = FALSE;
1774                         
1775                 /* The user details email address is mandatory: */
1776                 if (enable_next && entry_is_empty (priv->entry_user_email))
1777                         enable_next = FALSE;
1778         } else if (current_page == priv->page_custom_incoming) {
1779                 /* The custom incoming server is mandatory: */
1780                 if (entry_is_empty(priv->entry_incomingserver))
1781                         enable_next = FALSE;
1782         } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1783                 enable_next = !modest_easysetup_wizard_page_validate (
1784                        MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1785         }
1786                         
1787         /* Enable/disable buttons */ 
1788         real_enable_buttons (dialog, enable_next);
1789 }
1790
1791 static void
1792 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1793 {
1794         GObjectClass *object_class = G_OBJECT_CLASS (klass);
1795         g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1796
1797
1798         object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1799         object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1800         
1801         /* Provide a vfunc implementation so we can decide 
1802          * when to enable/disable the prev/next buttons.
1803          */
1804         ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1805         base_klass->before_next = on_before_next;
1806         base_klass->enable_buttons = on_enable_buttons;
1807 }
1808
1809 /**
1810  * save_to_settings:
1811  * @self: a #ModestEasysetupWizardDialog
1812  *
1813  * takes information from all the wizard and stores it in settings
1814  */
1815 static void
1816 save_to_settings (ModestEasysetupWizardDialog *self)
1817 {
1818         ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1819         guint special_port;
1820         gchar *provider_id = NULL;
1821         gchar* display_name;
1822         const gchar *username, *password;
1823         gchar *store_hostname, *transport_hostname;
1824         guint store_port, transport_port;
1825         ModestProtocolRegistry *protocol_registry;
1826         ModestProtocolType store_protocol, transport_protocol;
1827         ModestProtocolType store_security, transport_security;
1828         ModestProtocolType store_auth_protocol, transport_auth_protocol;
1829         ModestServerAccountSettings *store_settings, *transport_settings;
1830         const gchar *fullname, *email_address;
1831         ModestProviderPicker *picker;
1832         ModestProviderPickerIdType id_type;
1833
1834         priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1835         picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1836         protocol_registry = modest_runtime_get_protocol_registry ();
1837
1838         /* Get details from the specified presets: */
1839         id_type = modest_provider_picker_get_active_id_type (picker);
1840         provider_id = modest_provider_picker_get_active_provider_id (picker);
1841                 
1842         /* Let the plugin save the settings. We do a return in order
1843            to save an indentation level */
1844         if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1845                 ModestProtocol *protocol;
1846
1847                 protocol = modest_protocol_registry_get_protocol_by_name (
1848                        modest_runtime_get_protocol_registry (),
1849                        MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1850                        provider_id);
1851
1852                 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1853                         gint n_pages, i = 0;
1854                         GtkNotebook *notebook;
1855                         GList *wizard_pages = NULL;
1856
1857                         g_object_get (self, "wizard-notebook", &notebook, NULL);
1858                         n_pages = gtk_notebook_get_n_pages (notebook);
1859                         for (i = 0; i < n_pages; i++) {
1860                                 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1861                                 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1862                                         wizard_pages  = g_list_append (wizard_pages, page);
1863                         }
1864                         modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1865                                                                       wizard_pages,
1866                                                                       priv->settings);
1867                         g_list_free (wizard_pages);
1868                 } else {
1869                         g_warning ("The selected protocol is a plugin protocol "//
1870                                    "but it's not a ModestAccountProtocol");
1871                 }
1872
1873                 g_free (provider_id);
1874                 return;
1875         }
1876
1877         /* username and password (for both incoming and outgoing): */
1878         username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
1879         password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
1880
1881         store_settings = modest_account_settings_get_store_settings (priv->settings);
1882         transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1883
1884         /* Incoming server: */
1885         /* Note: We need something as default for the transport store protocol values, 
1886          * or modest_account_mgr_add_server_account will fail. */
1887         store_port = 0;
1888         store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1889         store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1890         store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1891
1892         if (provider_id) {
1893                 ModestProtocolType store_provider_server_type;
1894                 gboolean store_provider_use_alternate_port;
1895                 /* Use presets: */
1896                 store_hostname = modest_presets_get_server (priv->presets, provider_id, 
1897                                                             TRUE /* store */);
1898                 
1899                 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1900                                                                          provider_id, 
1901                                                                          TRUE /* store */);
1902                 store_security  = modest_presets_get_info_server_security (priv->presets,
1903                                                                                     provider_id, 
1904                                                                                     TRUE /* store */);
1905                 store_auth_protocol  = modest_presets_get_info_server_auth (priv->presets,
1906                                                                                      provider_id, 
1907                                                                                      TRUE /* store */);
1908                 store_provider_use_alternate_port  = modest_presets_get_info_server_use_alternate_port (priv->presets,
1909                                                                                                         provider_id, 
1910                                                                                                         TRUE /* store */);
1911
1912                 /* We don't check for SMTP here as that is impossible for an incoming server. */
1913                 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1914                         store_protocol = MODEST_PROTOCOLS_STORE_POP;
1915                 else
1916                         store_protocol = store_provider_server_type;
1917
1918                 /* we check if there is a *special* port */
1919                 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1920                 if (special_port != 0) {
1921                         store_port = special_port;
1922                 } else {
1923                         gboolean use_alternate_port = FALSE;
1924                         if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
1925                                                                               store_security))
1926                                 use_alternate_port = TRUE;
1927                         store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
1928                 }
1929
1930                 modest_server_account_settings_set_security_protocol (store_settings, 
1931                                                                       store_security);
1932                 modest_server_account_settings_set_auth_protocol (store_settings, 
1933                                                                   store_auth_protocol);
1934                 if (store_port != 0)
1935                         modest_server_account_settings_set_port (store_settings, store_port);
1936         } else {
1937                 /* Use custom pages because no preset was specified: */
1938                 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));         
1939                 store_protocol = modest_servertype_picker_get_active_servertype (
1940                         MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));           
1941
1942                 modest_security_options_view_save_settings (
1943                                     MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1944                                     priv->settings);
1945         }
1946
1947         /* now we store the common store account settings */
1948         modest_server_account_settings_set_hostname (store_settings, store_hostname);
1949         modest_server_account_settings_set_username (store_settings, username);
1950         modest_server_account_settings_set_password (store_settings, password);
1951         modest_server_account_settings_set_protocol (store_settings, store_protocol);
1952
1953         g_object_unref (store_settings);
1954         g_free (store_hostname);
1955         
1956         /* Outgoing server: */
1957         transport_hostname = NULL;
1958         transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1959         transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1960         transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1961         transport_port = 0;
1962         
1963         if (provider_id) {
1964                 ModestProtocolType transport_provider_server_type;
1965                 ModestProtocolType transport_provider_security;
1966
1967                 /* Use presets */
1968                 transport_hostname = modest_presets_get_server (priv->presets, provider_id, 
1969                                                                 FALSE /* transport */);
1970                         
1971                 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1972                                                                                       provider_id, 
1973                                                                                       FALSE /* transport */);           
1974                 transport_provider_security = modest_presets_get_info_server_security (priv->presets, 
1975                                                                                        provider_id, 
1976                                                                                        FALSE /* transport */);
1977
1978                 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1979                 transport_protocol = transport_provider_server_type;
1980                 transport_security = transport_provider_security;
1981                 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
1982                         /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1983                         /* we check if there is a *special* port */
1984                         special_port = modest_presets_get_port (priv->presets, provider_id,
1985                                                                 FALSE /* transport */);
1986                         if (special_port != 0)
1987                                 transport_port = special_port;
1988                         else 
1989                                 transport_port = 465;
1990                         transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
1991                 } else {
1992                         /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1993                         transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1994                 }
1995
1996                 modest_server_account_settings_set_security_protocol (transport_settings, 
1997                                                                       transport_security);
1998                 modest_server_account_settings_set_auth_protocol (transport_settings, 
1999                                                                   transport_auth_protocol);
2000                 if (transport_port != 0)
2001                         modest_server_account_settings_set_port (transport_settings, 
2002                                                                  transport_port);
2003         } else {
2004                 ModestProtocolRegistry *registry;
2005                 ModestProtocol *store_proto;
2006
2007                 registry = modest_runtime_get_protocol_registry ();
2008                 /* Use custom pages because no preset was specified: */
2009                 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2010
2011                 store_proto = modest_protocol_registry_get_protocol_by_type (registry, 
2012                                                                              store_protocol);
2013
2014                 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2015                         /* fallback to SMTP if none was specified */
2016                         g_warning ("No transport protocol was specified for store %d (%s)",
2017                                    modest_protocol_get_type_id (store_proto),
2018                                    modest_protocol_get_display_name (store_proto));
2019                         transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2020                 }
2021
2022                 modest_security_options_view_save_settings (
2023                                     MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2024                                     priv->settings);
2025         }
2026
2027         /* now we store the common transport account settings */
2028         modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2029         modest_server_account_settings_set_username (transport_settings, username);
2030         modest_server_account_settings_set_password (transport_settings, password);
2031         modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2032
2033         g_object_unref (transport_settings);
2034         g_free (transport_hostname);
2035         
2036         fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2037         email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2038         modest_account_settings_set_fullname (priv->settings, fullname);
2039         modest_account_settings_set_email_address (priv->settings, email_address);
2040         /* we don't set retrieve type to preserve advanced settings if
2041            any. By default account settings are set to headers only */
2042         
2043         /* Save the connection-specific SMTP server accounts. */
2044         modest_account_settings_set_use_connection_specific_smtp 
2045                 (priv->settings, 
2046                  hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2047
2048         display_name = get_entered_account_title (self);
2049         modest_account_settings_set_display_name (priv->settings, display_name);
2050         g_free (display_name);
2051         g_free (provider_id);
2052 }
2053