2 /* Copyright (c) 2006, Nokia Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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.
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.
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"
63 /* Include config.h so that _() works: */
68 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
70 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
71 MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
72 ModestEasysetupWizardDialogPrivate))
74 #define LABELS_WIDTH 480
75 #define DIALOG_WIDTH LABELS_WIDTH + MODEST_MARGIN_DOUBLE
77 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
81 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
82 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
83 } ModestEasysetupWizardDialogServerChanges;
85 struct _ModestEasysetupWizardDialogPrivate
87 ModestPresets *presets;
89 /* Remember what fields the user edited manually to not prefill them
91 ModestEasysetupWizardDialogServerChanges server_changes;
93 /* Check if the user changes a field to show a confirmation dialog */
96 /* If we have a pending load of settings or not. */
97 gboolean pending_load_settings;
99 /* Used by derived widgets to query existing accounts,
100 * and to create new accounts: */
101 ModestAccountMgr *account_manager;
102 ModestAccountSettings *settings;
104 /* notebook pages: */
105 GtkWidget *page_welcome;
107 GtkWidget *page_account_details;
108 GtkWidget *account_country_picker;
109 GtkWidget *account_serviceprovider_picker;
110 GtkWidget *entry_account_title;
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;
118 GtkWidget *page_complete_easysetup;
120 GtkWidget *page_custom_incoming;
121 GtkWidget *incoming_servertype_picker;
122 GtkWidget *caption_incoming;
123 GtkWidget *entry_incomingserver;
125 /* Security widgets */
126 GtkWidget *incoming_security;
127 GtkWidget *outgoing_security;
129 GtkWidget *page_custom_outgoing;
130 GtkWidget *entry_outgoingserver;
131 GtkWidget *checkbox_outgoing_smtp_specific;
132 GtkWidget *button_outgoing_smtp_servers;
134 GtkWidget *page_complete_customsetup;
136 ModestProtocolType last_plugin_protocol_selected;
137 GSList *missing_data_signals;
140 static void save_to_settings (ModestEasysetupWizardDialog *self);
141 static void real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next);
142 static void on_save_settings (ModestWizardDialog *dialog);
143 static GList* check_for_supported_auth_methods (ModestEasysetupWizardDialog* self);
144 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self);
147 on_delete_event (GtkWidget *widget,
149 ModestEasysetupWizardDialog *wizard)
151 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
156 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
158 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
159 g_return_if_fail (priv != NULL);
164 modest_easysetup_wizard_dialog_dispose (GObject *object)
166 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
167 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
171 modest_easysetup_wizard_dialog_finalize (GObject *object)
173 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
174 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
176 if (priv->account_manager)
177 g_object_unref (G_OBJECT (priv->account_manager));
180 modest_presets_destroy (priv->presets);
183 g_object_unref (priv->settings);
185 if (priv->missing_data_signals) {
186 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
187 priv->missing_data_signals = NULL;
190 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
194 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
197 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
199 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
202 get_port_from_protocol (ModestProtocolType server_type,
203 gboolean alternate_port)
206 ModestProtocol *protocol;
207 ModestProtocolRegistry *protocol_registry;
209 protocol_registry = modest_runtime_get_protocol_registry ();
210 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
212 if (alternate_port) {
213 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
215 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
221 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
223 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
225 /* Call the vfunc, which may be overridden by derived classes: */
226 if (klass->enable_buttons) {
227 GtkNotebook *notebook = NULL;
228 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
230 const gint current_page_num = gtk_notebook_get_current_page (notebook);
231 if (current_page_num == -1)
234 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
235 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
240 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
242 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
244 invoke_enable_buttons_vfunc(self);
248 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
250 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
252 invoke_enable_buttons_vfunc(self);
256 on_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
258 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
260 invoke_enable_buttons_vfunc(self);
264 on_serviceprovider_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
266 gchar* default_account_name_start;
267 gchar* default_account_name;
268 ModestEasysetupWizardDialog *self;
269 ModestEasysetupWizardDialogPrivate *priv;
270 ModestProviderPickerIdType provider_id_type;
272 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
273 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
275 on_picker_button_value_changed (widget, user_data);
277 provider_id_type = modest_provider_picker_get_active_id_type (
278 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
279 if (provider_id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
280 default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
284 selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (widget)));
285 default_account_name_start =
286 g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
289 default_account_name = modest_account_mgr_get_unused_account_display_name (
290 priv->account_manager, default_account_name_start);
291 g_free (default_account_name_start);
292 default_account_name_start = NULL;
294 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
295 g_free (default_account_name);
298 /** This is a convenience function to create a caption containing a mandatory widget.
299 * When the widget is edited, the enable_buttons() vfunc will be called.
302 create_captioned (ModestEasysetupWizardDialog *self,
303 GtkSizeGroup *title_size_group,
304 GtkSizeGroup *value_size_group,
311 result = modest_maemo_utils_create_captioned (title_size_group, value_size_group,
312 value, use_markup, control);
314 /* Connect to the appropriate changed signal for the widget,
315 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
317 if (GTK_IS_ENTRY (control)) {
318 g_signal_connect (G_OBJECT (control), "changed",
319 G_CALLBACK (on_caption_entry_changed), self);
322 else if (GTK_IS_COMBO_BOX (control)) {
323 g_signal_connect (G_OBJECT (control), "changed",
324 G_CALLBACK (on_caption_combobox_changed), self);
331 create_page_welcome (ModestEasysetupWizardDialog *self)
333 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
334 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
335 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
336 /* So that it is not truncated: */
337 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
338 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
339 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
340 gtk_widget_show (label);
341 gtk_widget_show (GTK_WIDGET (box));
342 return GTK_WIDGET (box);
346 on_account_country_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
348 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
350 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
354 /* Fill the providers picker, based on the selected country: */
355 if (priv->presets != NULL) {
356 gint mcc = modest_country_picker_get_active_country_mcc (
357 MODEST_COUNTRY_PICKER (priv->account_country_picker));
358 modest_provider_picker_fill (
359 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
364 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
366 ModestEasysetupWizardDialogPrivate *priv;
368 gchar* domain_name = NULL;
371 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
373 /* Fill the providers combo, based on the selected country: */
374 provider_id = modest_provider_picker_get_active_provider_id (
375 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
378 domain_name = modest_presets_get_domain (priv->presets, provider_id);
381 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
383 if (priv->entry_user_email)
384 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), domain_name);
386 g_free (domain_name);
388 g_free (provider_id);
392 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
394 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
396 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
400 update_user_email_from_provider (self);
404 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
406 modest_platform_information_banner (GTK_WIDGET (self), NULL,
407 _CS("ckdg_ib_maximum_characters_reached"));
411 create_page_account_details (ModestEasysetupWizardDialog *self)
414 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
415 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
416 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
418 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
419 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
420 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
421 gtk_widget_show (label);
423 /* Create a size group to be used by all captions.
424 * Note that HildonCaption does not create a default size group if we do not specify one.
425 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
426 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
427 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
429 /* The country widgets: */
430 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
431 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
432 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
433 _("mcen_fi_country"), priv->account_country_picker);
434 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
435 G_CALLBACK (on_picker_button_value_changed), self);
436 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
437 gtk_widget_show (priv->account_country_picker);
439 GtkWidget *separator = gtk_hseparator_new ();
440 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
441 gtk_widget_show (separator);
443 /* The service provider widgets: */
444 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
445 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
446 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
447 _("mcen_fi_serviceprovider"),
448 priv->account_serviceprovider_picker);
449 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
450 G_CALLBACK (on_serviceprovider_picker_button_value_changed), self);
451 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
452 gtk_widget_show (priv->account_serviceprovider_picker);
454 /* The description widgets: */
455 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
456 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
457 G_CALLBACK(on_easysetup_changed), self);
458 /* Do use auto-capitalization: */
459 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
460 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
462 /* Set a default account title, choosing one that does not already exist: */
463 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
464 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
465 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
466 priv->account_manager, default_account_name_start);
467 g_free (default_account_name_start);
468 default_account_name_start = NULL;
470 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
471 g_free (default_account_name);
472 default_account_name = NULL;
474 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mcen_fi_account_title"), FALSE,
475 priv->entry_account_title);
476 gtk_widget_show (priv->entry_account_title);
477 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
478 gtk_widget_show (caption);
480 /* Prevent the use of some characters in the account title,
481 * as required by our UI specification: */
482 GList *list_prevent = NULL;
483 list_prevent = g_list_append (list_prevent, "\\");
484 list_prevent = g_list_append (list_prevent, "/");
485 list_prevent = g_list_append (list_prevent, ":");
486 list_prevent = g_list_append (list_prevent, "*");
487 list_prevent = g_list_append (list_prevent, "?");
488 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
489 list_prevent = g_list_append (list_prevent, "“");
490 list_prevent = g_list_append (list_prevent, "<");
491 list_prevent = g_list_append (list_prevent, ">");
492 list_prevent = g_list_append (list_prevent, "|");
493 list_prevent = g_list_append (list_prevent, "^");
494 modest_validating_entry_set_unallowed_characters (
495 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
496 g_list_free (list_prevent);
498 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
499 modest_utils_on_entry_invalid_character, self);
501 /* Set max length as in the UI spec:
502 * The UI spec seems to want us to show a dialog if we hit the maximum. */
503 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
504 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
507 gtk_widget_show (GTK_WIDGET (box));
509 g_object_unref (title_sizegroup);
510 g_object_unref (value_sizegroup);
512 return GTK_WIDGET (box);
516 create_page_user_details (ModestEasysetupWizardDialog *self)
518 GtkSizeGroup* title_sizegroup;
519 GtkSizeGroup* value_sizegroup;
521 ModestEasysetupWizardDialogPrivate *priv;
523 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
525 /* Create a size group to be used by all captions.
526 * Note that HildonCaption does not create a default size group if we do not specify one.
527 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
528 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
529 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
530 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
532 /* The name widgets: (use auto cap) */
533 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
534 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
535 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
537 /* Set max length as in the UI spec:
538 * The UI spec seems to want us to show a dialog if we hit the maximum. */
539 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
540 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
542 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
543 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
544 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
545 G_CALLBACK(on_easysetup_changed), self);
546 gtk_widget_show (priv->entry_user_name);
547 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
548 gtk_widget_show (caption);
550 /* Prevent the use of some characters in the name,
551 * as required by our UI specification: */
552 GList *list_prevent = NULL;
553 list_prevent = g_list_append (list_prevent, "<");
554 list_prevent = g_list_append (list_prevent, ">");
555 modest_validating_entry_set_unallowed_characters (
556 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
557 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
558 modest_utils_on_entry_invalid_character, self);
559 g_list_free (list_prevent);
561 /* The username widgets: */
562 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
563 /* Auto-capitalization is the default, so let's turn it off: */
564 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
565 HILDON_GTK_INPUT_MODE_FULL);
566 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
567 priv->entry_user_username);
568 gtk_widget_show (priv->entry_user_username);
569 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
570 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
571 G_CALLBACK(on_easysetup_changed), self);
572 gtk_widget_show (caption);
574 /* Prevent the use of some characters in the username,
575 * as required by our UI specification: */
576 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
577 modest_utils_on_entry_invalid_character, self);
579 /* Set max length as in the UI spec:
580 * The UI spec seems to want us to show a dialog if we hit the maximum. */
581 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
582 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
585 /* The password widgets: */
586 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
587 /* Auto-capitalization is the default, so let's turn it off: */
588 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
589 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
590 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
591 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
592 caption = create_captioned (self, title_sizegroup, value_sizegroup,
593 _("mail_fi_password"), FALSE, priv->entry_user_password);
594 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
595 G_CALLBACK(on_easysetup_changed), self);
596 gtk_widget_show (priv->entry_user_password);
597 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
598 gtk_widget_show (caption);
600 /* The email address widgets: */
601 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
602 /* Auto-capitalization is the default, so let's turn it off: */
603 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
604 caption = create_captioned (self, title_sizegroup, value_sizegroup,
605 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
606 update_user_email_from_provider (self);
607 gtk_widget_show (priv->entry_user_email);
608 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
609 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
610 G_CALLBACK(on_easysetup_changed), self);
611 gtk_widget_show (caption);
613 /* Set max length as in the UI spec:
614 * The UI spec seems to want us to show a dialog if we hit the maximum. */
615 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
616 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
620 gtk_widget_show (GTK_WIDGET (box));
621 g_object_unref (title_sizegroup);
622 g_object_unref (value_sizegroup);
624 return GTK_WIDGET (box);
628 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
630 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
632 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
633 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
634 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
635 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
637 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
638 gtk_widget_show (label);
640 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
641 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
642 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
644 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
645 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
646 gtk_widget_show (label);
648 gtk_widget_show (GTK_WIDGET (box));
649 return GTK_WIDGET (box);
652 /** Change the caption title for the incoming server,
653 * as specified in the UI spec:
656 update_incoming_server_title (ModestEasysetupWizardDialog *self)
658 ModestEasysetupWizardDialogPrivate* priv;
659 ModestProtocolType protocol_type;
660 ModestProtocolRegistry *protocol_registry;
662 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
663 protocol_registry = modest_runtime_get_protocol_registry ();
665 protocol_type = modest_servertype_picker_get_active_servertype (
666 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
668 /* This could happen when the combo box has still no active iter */
669 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
670 gchar* incomingserver_title;
671 const gchar *protocol_display_name;
672 ModestProtocol *protocol;
674 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
676 protocol_display_name = modest_protocol_get_display_name (protocol);
678 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
679 protocol_display_name, ")</small>", NULL);
681 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
683 g_free(incomingserver_title);
687 /** Change the caption title for the incoming server,
688 * as specified in the UI spec:
691 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
693 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
694 ModestServertypePicker *server_type_picker;
695 ModestProtocolType protocol_type;
696 ModestSecurityOptionsView *view;
699 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
701 modest_servertype_picker_get_active_servertype (server_type_picker);
703 /* Fill the combo with appropriately titled choices for all
705 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
706 modest_security_options_view_set_server_type (view, protocol_type);
710 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
712 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
713 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
714 ModestServertypePicker *picker;
715 ModestProtocolType protocol_type;
720 update_incoming_server_title (self);
722 /* Update security options if needed */
723 picker = MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
724 protocol_type = modest_servertype_picker_get_active_servertype (picker);
725 update_incoming_server_security_choices (self);
726 gtk_widget_show (priv->incoming_security);
728 set_default_custom_servernames (self);
732 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
734 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
735 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
737 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
741 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
743 ModestProtocolRegistry *protocol_registry;
744 ModestEasysetupWizardDialogPrivate* priv;
748 GtkSizeGroup *title_sizegroup;
749 GtkSizeGroup *value_sizegroup;
751 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
752 protocol_registry = modest_runtime_get_protocol_registry ();
754 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
755 pannable = hildon_pannable_area_new ();
757 /* Show note that account type cannot be changed in future: */
758 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
759 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
760 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
761 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
762 gtk_widget_show (label);
764 /* Create a size group to be used by all captions.
765 * Note that HildonCaption does not create a default size group if we do not specify one.
766 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
767 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
768 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
770 /* The incoming server widgets: */
771 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
772 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
774 hildon_button_set_title (HILDON_BUTTON (priv->incoming_servertype_picker), _("mcen_li_emailsetup_type"));
775 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
776 G_CALLBACK (on_picker_button_value_changed), self);
777 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
778 gtk_widget_show (priv->incoming_servertype_picker);
780 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
781 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
782 /* Auto-capitalization is the default, so let's turn it off: */
783 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
784 set_default_custom_servernames (self);
786 /* The caption title will be updated in update_incoming_server_title().
787 * so this default text will never be seen: */
788 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
789 "This will be removed",
790 FALSE, priv->entry_incomingserver);
791 update_incoming_server_title (self);
792 gtk_widget_show (priv->entry_incomingserver);
793 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
794 gtk_widget_show (priv->caption_incoming);
796 /* Change the caption title when the servertype changes,
797 * as in the UI spec: */
798 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
800 G_CALLBACK (on_servertype_selector_changed), self);
802 /* Remember when the servername was changed manually: */
803 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
804 G_CALLBACK (on_entry_incoming_servername_changed), self);
806 /* The secure connection widgets. These are only valid for
807 protocols with security */
808 priv->incoming_security =
809 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
810 FALSE, title_sizegroup, value_sizegroup);
811 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
812 FALSE, FALSE, MODEST_MARGIN_HALF);
813 gtk_widget_show_all (priv->incoming_security);
815 /* Set default selection */
816 modest_servertype_picker_set_active_servertype (
817 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
818 MODEST_PROTOCOLS_STORE_POP);
820 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), box);
821 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
822 hildon_pannable_area_get_vadjustment (HILDON_PANNABLE_AREA (pannable)));
823 gtk_widget_show (GTK_WIDGET (box));
824 gtk_widget_show (pannable);
826 g_object_unref (title_sizegroup);
827 g_object_unref (value_sizegroup);
829 return GTK_WIDGET (pannable);
833 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
835 GtkWidget *widget = GTK_WIDGET (user_data);
837 /* Enable the widget only if the check button is active: */
838 const gboolean enable = hildon_check_button_get_active (button);
839 gtk_widget_set_sensitive (widget, enable);
842 /* Make the sensitivity of a widget depend on a check button.
845 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
847 g_signal_connect (G_OBJECT (button), "toggled",
848 G_CALLBACK (on_check_button_changed), widget);
850 /* Set the starting sensitivity: */
851 on_check_button_changed (button, widget);
855 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
857 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
858 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
859 GtkWidget *specific_window;
861 /* We set dirty here because setting it depending on the connection specific dialog
865 /* Create the window, if necessary: */
866 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
867 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
869 /* Show the window */
870 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
871 gtk_widget_show (specific_window);
875 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
877 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
878 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
879 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
883 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
885 ModestEasysetupWizardDialogPrivate *priv;
886 gchar *smtp_caption_label;
888 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
890 pannable = hildon_pannable_area_new ();
892 /* Create a size group to be used by all captions.
893 * Note that HildonCaption does not create a default size group if we do not specify one.
894 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
895 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
896 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
898 /* The outgoing server widgets: */
899 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
900 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
901 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
902 G_CALLBACK (on_easysetup_changed), self);
903 /* Auto-capitalization is the default, so let's turn it off: */
904 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
905 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
906 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
907 smtp_caption_label, TRUE, priv->entry_outgoingserver);
908 g_free (smtp_caption_label);
909 gtk_widget_show (priv->entry_outgoingserver);
910 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
911 gtk_widget_show (caption);
912 set_default_custom_servernames (self);
914 /* The secure connection widgets. These are only valid for
915 protocols with security */
916 priv->outgoing_security =
917 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
918 FALSE, title_sizegroup, value_sizegroup);
919 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
920 FALSE, FALSE, MODEST_MARGIN_HALF);
921 gtk_widget_show (priv->outgoing_security);
923 GtkWidget *separator = gtk_hseparator_new ();
924 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
925 gtk_widget_show (separator);
927 /* connection-specific checkbox: */
928 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
929 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
931 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
932 _("mcen_fi_advsetup_connection_smtp"));
933 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
935 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
936 G_CALLBACK (on_easysetup_changed), self);
938 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
939 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
940 FALSE, FALSE, MODEST_MARGIN_HALF);
942 /* Connection-specific SMTP-Severs Edit button: */
943 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
944 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
945 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
946 gtk_widget_show (priv->button_outgoing_smtp_servers);
947 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
948 FALSE, FALSE, MODEST_MARGIN_HALF);
950 /* Only enable the button when the checkbox is checked: */
951 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
952 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
954 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
955 G_CALLBACK (on_button_outgoing_smtp_servers), self);
957 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
958 G_CALLBACK (on_entry_outgoing_servername_changed), self);
961 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), box);
962 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
963 hildon_pannable_area_get_vadjustment (HILDON_PANNABLE_AREA (pannable)));
964 gtk_widget_show (GTK_WIDGET (box));
965 gtk_widget_show (pannable);
967 g_object_unref (title_sizegroup);
968 g_object_unref (value_sizegroup);
970 return GTK_WIDGET (pannable);
974 show_advanced_edit(gpointer user_data)
976 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
977 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
980 /* Show the Account Settings window: */
981 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
982 if (priv->pending_load_settings) {
983 save_to_settings (self);
984 priv->pending_load_settings = FALSE;
986 modest_account_settings_dialog_load_settings (dialog, priv->settings);
988 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
990 response = gtk_dialog_run (GTK_DIALOG (dialog));
992 gtk_widget_destroy (GTK_WIDGET (dialog));
994 return FALSE; /* Do not call this timeout callback again. */
998 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1000 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1002 /* Show the Account Settings window: */
1003 show_advanced_edit(self);
1006 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1008 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1009 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1010 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1011 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1012 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1013 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1014 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1015 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1016 gtk_widget_show (label);
1018 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1019 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1020 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1021 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1022 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1023 gtk_widget_show (label);
1025 gtk_widget_show (button_edit);
1026 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, MODEST_MARGIN_HALF);
1028 g_signal_connect (G_OBJECT (button_edit), "clicked",
1029 G_CALLBACK (on_button_edit_advanced_settings), self);
1031 gtk_widget_show (GTK_WIDGET (box));
1032 return GTK_WIDGET (box);
1039 on_response (ModestWizardDialog *wizard_dialog,
1043 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1045 invoke_enable_buttons_vfunc (self);
1049 on_response_before (ModestWizardDialog *wizard_dialog,
1053 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1054 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1055 if (response_id == GTK_RESPONSE_CANCEL) {
1056 /* This is mostly copied from
1057 * src/maemo/modest-account-settings-dialog.c */
1059 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1060 _("imum_nc_wizard_confirm_lose_changes")));
1061 /* TODO: These button names will be ambiguous, and not
1062 * specified in the UI specification. */
1064 const gint dialog_response = gtk_dialog_run (dialog);
1065 gtk_widget_destroy (GTK_WIDGET (dialog));
1067 if (dialog_response != GTK_RESPONSE_OK) {
1068 /* Don't let the dialog close */
1069 g_signal_stop_emission_by_name (wizard_dialog, "response");
1075 typedef struct IdleData {
1076 ModestEasysetupWizardDialog *dialog;
1077 ModestPresets *presets;
1081 presets_idle (gpointer userdata)
1083 IdleData *idle_data = (IdleData *) userdata;
1084 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1085 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1087 g_assert (idle_data->presets);
1089 gdk_threads_enter ();
1091 priv->presets = idle_data->presets;
1093 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1094 /* gint mcc = get_default_country_code(); */
1096 /* Fill the combo in an idle call, as it takes a lot of time */
1097 modest_country_picker_load_data(
1098 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1099 /* connect to country picker's changed signal, so we can fill the provider picker: */
1100 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1101 (HILDON_PICKER_BUTTON (priv->account_country_picker))),
1103 G_CALLBACK (on_account_country_selector_changed), self);
1105 modest_country_picker_set_active_country_locale (
1106 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1107 mcc = modest_country_picker_get_active_country_mcc (
1108 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1109 modest_provider_picker_fill (
1110 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1111 priv->presets, mcc);
1112 /* connect to providers picker's changed signal, so we can fill the email address: */
1113 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1114 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1116 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1118 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1121 priv->dirty = FALSE;
1123 g_object_unref (idle_data->dialog);
1126 gdk_threads_leave ();
1132 presets_loader (gpointer userdata)
1134 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1135 ModestPresets *presets = NULL;
1136 IdleData *idle_data;
1138 const gchar* path = NULL;
1139 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1140 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1142 if (access(path1, R_OK) == 0)
1144 else if (access(path2, R_OK) == 0)
1147 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1148 __FUNCTION__, path1, path2);
1152 presets = modest_presets_new (path);
1154 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1158 idle_data = g_new0 (IdleData, 1);
1159 idle_data->dialog = self;
1160 idle_data->presets = presets;
1162 g_idle_add (presets_idle, idle_data);
1168 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1173 /* Append page and set attributes */
1174 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1175 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1176 "tab-expand", TRUE, "tab-fill", TRUE,
1178 gtk_widget_show (page);
1182 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1184 priv->page_user_details = NULL;
1185 priv->entry_user_name = NULL;
1186 priv->entry_user_username = NULL;
1187 priv->entry_user_password = NULL;
1188 priv->entry_user_email = NULL;
1192 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1194 priv->page_custom_incoming = NULL;
1195 priv->incoming_servertype_picker = NULL;
1196 priv->caption_incoming = NULL;
1197 priv->entry_incomingserver = NULL;
1198 priv->entry_user_email = NULL;
1199 priv->incoming_security = NULL;
1203 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1205 priv->page_custom_outgoing = NULL;
1206 priv->entry_outgoingserver = NULL;
1207 priv->checkbox_outgoing_smtp_specific = NULL;
1208 priv->button_outgoing_smtp_servers = NULL;
1209 priv->outgoing_security = NULL;
1213 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1215 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1217 /* Create the notebook to be used by the ModestWizardDialog base class:
1218 * Each page of the notebook will be a page of the wizard: */
1219 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1220 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1222 /* Set the notebook used by the ModestWizardDialog base class: */
1223 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1225 /* Set the wizard title:
1226 * The actual window title will be a combination of this and the page's tab label title. */
1227 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1229 /* Read in the information about known service providers: */
1230 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1232 /* The server fields did not have been manually changed yet */
1233 priv->server_changes = 0;
1234 priv->pending_load_settings = TRUE;
1236 /* Get the account manager object,
1237 * so we can check for existing accounts,
1238 * and create new accounts: */
1239 priv->account_manager = modest_runtime_get_account_mgr ();
1240 g_object_ref (priv->account_manager);
1242 /* Initialize fields */
1243 priv->page_welcome = create_page_welcome (self);
1244 priv->page_account_details = create_page_account_details (self);
1246 init_user_page (priv);
1247 init_incoming_page (priv);
1248 init_outgoing_page (priv);
1250 priv->page_complete_easysetup = NULL;
1251 priv->page_complete_customsetup = NULL;
1252 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1253 priv->missing_data_signals = NULL;
1255 /* Add the common pages */
1256 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1257 _("mcen_ti_emailsetup_welcome"));
1258 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1259 _("mcen_ti_accountdetails"));
1261 /* Connect to the dialog's response signal so we can enable/disable buttons
1262 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1263 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1264 * so that we can be enable/disable after ModestWizardDialog has done its own
1265 * enabling/disabling of buttons.
1267 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1268 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1270 * It's not enough to connect to the notebook's switch-page signal, because
1271 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1272 * _after_ switching the page (understandably).
1273 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1274 * then gtk_notebook_get_current_page() would return an incorrect value.)
1276 g_signal_connect_after (G_OBJECT (self), "response",
1277 G_CALLBACK (on_response), self);
1279 /* This is to show a confirmation dialog when the user hits cancel */
1280 g_signal_connect (G_OBJECT (self), "response",
1281 G_CALLBACK (on_response_before), self);
1283 g_signal_connect (G_OBJECT (self), "delete-event",
1284 G_CALLBACK (on_delete_event), self);
1286 /* Reset dirty, because there was no user input until now */
1287 priv->dirty = FALSE;
1289 /* When this window is shown, hibernation should not be possible,
1290 * because there is no sensible way to save the state: */
1291 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1292 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1294 /* Load provider presets */
1295 g_object_ref (self);
1296 g_thread_create (presets_loader, self, FALSE, NULL);
1298 priv->settings = modest_account_settings_new ();
1301 ModestEasysetupWizardDialog*
1302 modest_easysetup_wizard_dialog_new (void)
1305 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1309 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1311 ModestEasysetupWizardDialogPrivate *priv;
1312 GtkNotebook *notebook = NULL;
1314 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1317 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1319 if (!priv->page_user_details) {
1320 priv->page_user_details = create_page_user_details (self);
1323 /* Create the custom pages: */
1324 if(!(priv->page_custom_incoming)) {
1325 priv->page_custom_incoming = create_page_custom_incoming (self);
1328 /* TODO: only if needed */
1329 if(!(priv->page_custom_outgoing)) {
1330 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1333 if(!(priv->page_complete_customsetup)) {
1334 priv->page_complete_customsetup = create_page_complete_custom (self);
1337 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1338 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1339 _("mcen_ti_emailsetup_userdetails"));
1341 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1342 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1343 _("mcen_ti_emailsetup_incomingdetails"));
1345 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1346 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1347 _("mcen_ti_emailsetup_outgoingdetails"));
1349 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1350 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1351 _("mcen_ti_emailsetup_complete"));
1353 /* This is unnecessary with GTK+ 2.10: */
1354 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1358 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1360 ModestEasysetupWizardDialogPrivate *priv;
1361 GtkNotebook *notebook = NULL;
1363 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1366 /* Create the easysetup-specific pages: */
1367 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1368 if(!priv->page_complete_easysetup)
1369 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1371 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1372 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1373 _("mcen_ti_emailsetup_complete"));
1375 /* This is unnecessary with GTK+ 2.10: */
1376 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1381 remove_non_common_tabs (GtkNotebook *notebook,
1382 gboolean remove_user_details)
1385 /* The first 2 tabs are the common ones (welcome tab and the
1386 providers tab), so we always remove starting from the
1389 starting_tab = (remove_user_details) ? 2 : 3;
1390 while (gtk_notebook_get_n_pages (notebook) > starting_tab)
1391 gtk_notebook_remove_page (notebook, -1);
1395 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1399 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1402 /* After the user details page,
1403 * the following pages depend on whether "Other" was chosen
1404 * in the provider combobox on the account page
1407 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1409 ModestEasysetupWizardDialogPrivate *priv;
1410 ModestProviderPicker *picker;
1411 ModestProviderPickerIdType id_type;
1412 GtkNotebook *notebook;
1414 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1415 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1416 id_type = modest_provider_picker_get_active_id_type (picker);
1417 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1418 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1422 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1423 /* "Other..." was selected: */
1425 /* If we come from a rollbacked easysetup */
1426 if (priv->page_complete_easysetup) {
1427 remove_non_common_tabs (notebook, FALSE);
1428 priv->page_complete_easysetup = NULL;
1431 /* If we come from a rollbacked plugin protocol setup */
1432 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1433 remove_non_common_tabs (notebook, TRUE);
1434 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1435 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1436 priv->missing_data_signals = NULL;
1439 create_subsequent_customsetup_pages (self);
1441 /* If we come from a rollbacked custom setup */
1442 if (priv->page_custom_incoming) {
1443 remove_non_common_tabs (notebook, TRUE);
1444 init_user_page (priv);
1445 init_incoming_page (priv);
1446 init_outgoing_page (priv);
1447 init_user_page (priv);
1448 priv->page_complete_customsetup = NULL;
1451 /* It's a pluggable protocol and not a provider with presets */
1452 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1453 ModestProtocol *protocol;
1455 ModestProtocolType proto_type;
1458 /* If we come from a rollbacked easy setup */
1459 if (priv->last_plugin_protocol_selected ==
1460 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1461 priv->page_complete_easysetup) {
1462 remove_non_common_tabs (notebook, TRUE);
1463 init_user_page (priv);
1464 priv->page_complete_easysetup = NULL;
1467 proto_name = modest_provider_picker_get_active_provider_id (picker);
1468 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1469 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1471 proto_type = modest_protocol_get_type_id (protocol);
1473 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1474 proto_type != priv->last_plugin_protocol_selected) {
1475 ModestPairList *tabs;
1477 gboolean first_page = TRUE;
1478 ModestWizardDialogResponseOverrideFunc response_override;
1480 /* Remember the last selected plugin protocol */
1481 priv->last_plugin_protocol_selected = proto_type;
1484 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1485 response_override = modest_account_protocol_get_wizard_response_override
1486 (MODEST_ACCOUNT_PROTOCOL (protocol));
1487 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1489 tmp = (GSList *) tabs;
1491 ModestPair *pair = (ModestPair *) tmp->data;
1492 modest_easysetup_wizard_dialog_append_page (notebook,
1493 GTK_WIDGET (pair->second),
1494 (const gchar *) pair->first);
1496 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1497 GTK_WIDGET (pair->second));
1501 /* Connect signals */
1502 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1503 priv->missing_data_signals =
1504 modest_signal_mgr_connect (priv->missing_data_signals,
1505 G_OBJECT (pair->second),
1506 "missing-mandatory-data",
1507 G_CALLBACK (on_missing_mandatory_data),
1511 g_free (pair->first);
1512 tmp = g_slist_next (tmp);
1513 /* Critical: if you don't show the page then the dialog will ignore it */
1514 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1516 modest_pair_list_free (tabs);
1518 g_free (proto_name);
1520 if (priv->last_plugin_protocol_selected !=
1521 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1522 remove_non_common_tabs (notebook, TRUE);
1523 init_user_page (priv);
1524 priv->page_complete_easysetup = NULL;
1525 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1526 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1527 priv->missing_data_signals = NULL;
1529 if (!priv->page_user_details) {
1530 priv->page_user_details = create_page_user_details (self);
1531 modest_easysetup_wizard_dialog_append_page (notebook,
1532 priv->page_user_details,
1533 _("mcen_ti_emailsetup_userdetails"));
1537 /* Create the easysetup pages: */
1538 create_subsequent_easysetup_pages (self);
1544 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1546 const gchar* hostname = NULL;
1549 ModestProtocolRegistry *protocol_registry;
1550 ModestProtocol *protocol;
1555 at = g_utf8_strchr (email_address, -1, '@');
1556 if (!at || (g_utf8_strlen (at, -1) < 2))
1559 domain = g_utf8_next_char (at);
1563 protocol_registry = modest_runtime_get_protocol_registry ();
1564 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1566 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1567 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1568 hostname = modest_protocol_get_name (protocol);
1574 return g_strdup_printf ("%s.%s", hostname, domain);
1578 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1580 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1582 if (!priv->entry_incomingserver)
1585 /* Set a default domain for the server, based on the email address,
1586 * if no server name was already specified.
1588 if (priv->entry_user_email
1589 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1590 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1591 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1593 /* This could happen when the combo box has still no active iter */
1594 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1595 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1596 gchar* servername = util_get_default_servername_from_email_address (email_address,
1599 /* Do not set the INCOMING_CHANGED flag because of this edit */
1600 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1601 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1602 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1604 g_free (servername);
1608 /* Set a default domain for the server, based on the email address,
1609 * if no server name was already specified.
1611 if (!priv->entry_outgoingserver)
1614 if (priv->entry_user_email
1615 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1616 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1618 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1620 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1621 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1622 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1623 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1625 g_free (servername);
1630 get_entered_account_title (ModestEasysetupWizardDialog *self)
1632 ModestEasysetupWizardDialogPrivate *priv;
1633 const gchar* account_title;
1635 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1636 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1638 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1641 /* Strip it of whitespace at the start and end: */
1642 gchar *result = g_strdup (account_title);
1643 result = g_strstrip (result);
1648 if (g_utf8_strlen (result, -1) == 0) {
1658 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1660 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1661 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1662 ModestProtocolRegistry *protocol_registry;
1664 protocol_registry = modest_runtime_get_protocol_registry ();
1666 /* if are browsing pages previous to the last one, then we have pending settings in
1668 if (next_page != NULL)
1669 priv->pending_load_settings = TRUE;
1671 /* Do extra validation that couldn't be done for every key press,
1672 * either because it was too slow,
1673 * or because it requires interaction:
1675 if (current_page == priv->page_account_details) {
1676 /* Check that the title is not already in use: */
1677 gchar* account_title = get_entered_account_title (self);
1681 /* Aavoid a clash with an existing display name: */
1682 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1683 priv->account_manager, account_title);
1684 g_free (account_title);
1687 /* Warn the user via a dialog: */
1688 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1693 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1694 create_subsequent_pages (self);
1696 } else if (current_page == priv->page_user_details) {
1697 /* Check that the email address is valud: */
1698 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1699 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1702 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1703 /* Warn the user via a dialog: */
1704 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1706 /* Return focus to the email address entry: */
1707 gtk_widget_grab_focus (priv->entry_user_email);
1708 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1714 if (next_page == priv->page_custom_incoming) {
1715 set_default_custom_servernames (self);
1716 } else if (next_page == priv->page_custom_outgoing) {
1717 set_default_custom_servernames (self);
1719 /* Check if the server supports secure authentication */
1720 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
1721 if (!check_has_supported_auth_methods (self))
1723 gtk_widget_show (priv->outgoing_security);
1726 /* If this is the last page, and this is a click on Finish,
1727 * then attempt to create the dialog.
1730 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1732 if (priv->pending_load_settings) {
1733 save_to_settings (self);
1736 /* We check if there's already another account with the same configuration */
1737 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1738 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1742 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1749 static gboolean entry_is_empty (GtkWidget *entry)
1754 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1755 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1758 /* Strip it of whitespace at the start and end: */
1759 gchar *stripped = g_strdup (text);
1760 stripped = g_strstrip (stripped);
1765 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1773 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1775 GtkNotebook *notebook = NULL;
1776 gboolean is_finish_tab;
1778 ModestEasysetupWizardDialogPrivate *priv;
1781 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1782 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
1784 /* Disable the Finish button until we are on the last page,
1785 * because HildonWizardDialog enables this for all but the
1787 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1788 is_finish_tab = ((current == priv->page_complete_easysetup) ||
1789 (current == priv->page_complete_customsetup));
1791 if (is_finish_tab) {
1792 /* Disable Next on the last page no matter what the
1794 enable_next = FALSE;
1796 /* Not the last one */
1797 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1798 MODEST_WIZARD_DIALOG_FINISH,
1802 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1803 MODEST_WIZARD_DIALOG_NEXT,
1808 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1810 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1811 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1813 gboolean enable_next = TRUE;
1814 if (current_page == priv->page_welcome) {
1816 } else if (current_page == priv->page_account_details) {
1817 /* The account details title is mandatory: */
1818 if (entry_is_empty(priv->entry_account_title))
1819 enable_next = FALSE;
1820 } else if (current_page == priv->page_user_details) {
1821 /* The user details username is mandatory: */
1822 if (entry_is_empty(priv->entry_user_username))
1823 enable_next = FALSE;
1825 /* The user details email address is mandatory: */
1826 if (enable_next && entry_is_empty (priv->entry_user_email))
1827 enable_next = FALSE;
1828 } else if (current_page == priv->page_custom_incoming) {
1829 /* The custom incoming server is mandatory: */
1830 if (entry_is_empty(priv->entry_incomingserver))
1831 enable_next = FALSE;
1832 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1833 enable_next = !modest_easysetup_wizard_page_validate (
1834 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1837 /* Enable/disable buttons */
1838 real_enable_buttons (dialog, enable_next);
1842 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1844 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1845 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1848 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1849 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1851 /* Provide a vfunc implementation so we can decide
1852 * when to enable/disable the prev/next buttons.
1854 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1855 base_klass->before_next = on_before_next;
1856 base_klass->enable_buttons = on_enable_buttons;
1857 base_klass->save_settings = on_save_settings;
1862 * @self: a #ModestEasysetupWizardDialog
1864 * takes information from all the wizard and stores it in settings
1867 save_to_settings (ModestEasysetupWizardDialog *self)
1869 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1871 gchar *provider_id = NULL;
1872 gchar* display_name;
1873 const gchar *username, *password;
1874 gchar *store_hostname, *transport_hostname;
1875 guint store_port, transport_port;
1876 ModestProtocolRegistry *protocol_registry;
1877 ModestProtocolType store_protocol, transport_protocol;
1878 ModestProtocolType store_security, transport_security;
1879 ModestProtocolType store_auth_protocol, transport_auth_protocol;
1880 ModestServerAccountSettings *store_settings, *transport_settings;
1881 const gchar *fullname, *email_address;
1882 ModestProviderPicker *picker;
1883 ModestProviderPickerIdType id_type;
1885 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1886 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1887 protocol_registry = modest_runtime_get_protocol_registry ();
1889 /* Get details from the specified presets: */
1890 id_type = modest_provider_picker_get_active_id_type (picker);
1891 provider_id = modest_provider_picker_get_active_provider_id (picker);
1893 /* Let the plugin save the settings. We do a return in order
1894 to save an indentation level */
1895 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1896 ModestProtocol *protocol;
1898 protocol = modest_protocol_registry_get_protocol_by_name (
1899 modest_runtime_get_protocol_registry (),
1900 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1903 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1904 gint n_pages, i = 0;
1905 GtkNotebook *notebook;
1906 GList *wizard_pages = NULL;
1908 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1909 n_pages = gtk_notebook_get_n_pages (notebook);
1910 for (i = 0; i < n_pages; i++) {
1911 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1912 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1913 wizard_pages = g_list_append (wizard_pages, page);
1915 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1918 g_list_free (wizard_pages);
1920 g_warning ("The selected protocol is a plugin protocol "//
1921 "but it's not a ModestAccountProtocol");
1924 g_free (provider_id);
1928 /* username and password (for both incoming and outgoing): */
1929 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
1930 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
1932 store_settings = modest_account_settings_get_store_settings (priv->settings);
1933 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1935 /* Incoming server: */
1936 /* Note: We need something as default for the transport store protocol values,
1937 * or modest_account_mgr_add_server_account will fail. */
1939 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1940 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1941 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1944 ModestProtocolType store_provider_server_type;
1945 gboolean store_provider_use_alternate_port;
1947 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1950 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1953 store_security = modest_presets_get_info_server_security (priv->presets,
1956 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
1959 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
1963 /* We don't check for SMTP here as that is impossible for an incoming server. */
1964 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1965 store_protocol = MODEST_PROTOCOLS_STORE_POP;
1967 store_protocol = store_provider_server_type;
1969 /* we check if there is a *special* port */
1970 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1971 if (special_port != 0) {
1972 store_port = special_port;
1974 gboolean use_alternate_port = FALSE;
1975 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
1977 use_alternate_port = TRUE;
1978 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
1981 modest_server_account_settings_set_security_protocol (store_settings,
1983 modest_server_account_settings_set_auth_protocol (store_settings,
1984 store_auth_protocol);
1985 if (store_port != 0)
1986 modest_server_account_settings_set_port (store_settings, store_port);
1988 /* Use custom pages because no preset was specified: */
1989 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
1990 store_protocol = modest_servertype_picker_get_active_servertype (
1991 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1993 modest_security_options_view_save_settings (
1994 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1998 /* now we store the common store account settings */
1999 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2000 modest_server_account_settings_set_username (store_settings, username);
2001 modest_server_account_settings_set_password (store_settings, password);
2002 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2004 g_object_unref (store_settings);
2005 g_free (store_hostname);
2007 /* Outgoing server: */
2008 transport_hostname = NULL;
2009 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2010 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2011 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2015 ModestProtocolType transport_provider_server_type;
2016 ModestProtocolType transport_provider_security;
2019 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2020 FALSE /* transport */);
2022 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2024 FALSE /* transport */);
2025 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2027 FALSE /* transport */);
2029 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2030 transport_protocol = transport_provider_server_type;
2031 transport_security = transport_provider_security;
2032 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
2033 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
2034 /* we check if there is a *special* port */
2035 special_port = modest_presets_get_port (priv->presets, provider_id,
2036 FALSE /* transport */);
2037 if (special_port != 0)
2038 transport_port = special_port;
2040 transport_port = 465;
2041 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2043 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
2044 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2047 modest_server_account_settings_set_security_protocol (transport_settings,
2048 transport_security);
2049 modest_server_account_settings_set_auth_protocol (transport_settings,
2050 transport_auth_protocol);
2051 if (transport_port != 0)
2052 modest_server_account_settings_set_port (transport_settings,
2055 ModestProtocolRegistry *registry;
2056 ModestProtocol *store_proto;
2058 registry = modest_runtime_get_protocol_registry ();
2059 /* Use custom pages because no preset was specified: */
2060 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2062 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2065 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2066 /* fallback to SMTP if none was specified */
2067 g_warning ("No transport protocol was specified for store %d (%s)",
2068 modest_protocol_get_type_id (store_proto),
2069 modest_protocol_get_display_name (store_proto));
2070 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2073 modest_security_options_view_save_settings (
2074 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2078 /* now we store the common transport account settings */
2079 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2080 modest_server_account_settings_set_username (transport_settings, username);
2081 modest_server_account_settings_set_password (transport_settings, password);
2082 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2084 g_object_unref (transport_settings);
2085 g_free (transport_hostname);
2087 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2088 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2089 modest_account_settings_set_fullname (priv->settings, fullname);
2090 modest_account_settings_set_email_address (priv->settings, email_address);
2091 /* we don't set retrieve type to preserve advanced settings if
2092 any. By default account settings are set to headers only */
2094 /* Save the connection-specific SMTP server accounts. */
2095 if (priv->checkbox_outgoing_smtp_specific) {
2096 modest_account_settings_set_use_connection_specific_smtp
2098 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2101 display_name = get_entered_account_title (self);
2102 modest_account_settings_set_display_name (priv->settings, display_name);
2103 g_free (display_name);
2104 g_free (provider_id);
2109 on_save_settings (ModestWizardDialog *dialog)
2111 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2112 save_to_settings (self);
2118 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2120 GError *error = NULL;
2121 ModestProtocolType protocol_type;
2122 const gchar* hostname;
2123 const gchar* username;
2124 ModestProtocolType security_protocol_incoming_type;
2125 ModestProtocolRegistry *registry;
2127 GList *list_auth_methods;
2128 ModestEasysetupWizardDialogPrivate *priv;
2130 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2131 registry = modest_runtime_get_protocol_registry ();
2132 protocol_type = modest_servertype_picker_get_active_servertype (
2133 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2134 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2135 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2136 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2137 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2138 port_num = get_port_from_protocol(protocol_type, FALSE);
2139 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2140 username, GTK_WINDOW (self), &error);
2142 if (list_auth_methods) {
2143 /* TODO: Select the correct method */
2146 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2147 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2148 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2149 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2150 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2154 g_list_free(list_auth_methods);
2160 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2161 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2163 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2164 _("mcen_ib_unableto_discover_auth_methods"));
2168 g_error_free(error);
2174 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2176 GList* methods = check_for_supported_auth_methods(self);
2182 g_list_free(methods);