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