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 GList* check_for_supported_auth_methods (ModestEasysetupWizardDialog* self);
143 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self);
146 on_delete_event (GtkWidget *widget,
148 ModestEasysetupWizardDialog *wizard)
150 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
155 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
157 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
158 g_return_if_fail (priv != NULL);
163 modest_easysetup_wizard_dialog_dispose (GObject *object)
165 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
166 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
170 modest_easysetup_wizard_dialog_finalize (GObject *object)
172 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
173 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
175 if (priv->account_manager)
176 g_object_unref (G_OBJECT (priv->account_manager));
179 modest_presets_destroy (priv->presets);
182 g_object_unref (priv->settings);
184 if (priv->missing_data_signals) {
185 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
186 priv->missing_data_signals = NULL;
189 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
193 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
196 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
198 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
201 get_port_from_protocol (ModestProtocolType server_type,
202 gboolean alternate_port)
205 ModestProtocol *protocol;
206 ModestProtocolRegistry *protocol_registry;
208 protocol_registry = modest_runtime_get_protocol_registry ();
209 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
211 if (alternate_port) {
212 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
214 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
220 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
222 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
224 /* Call the vfunc, which may be overridden by derived classes: */
225 if (klass->enable_buttons) {
226 GtkNotebook *notebook = NULL;
227 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
229 const gint current_page_num = gtk_notebook_get_current_page (notebook);
230 if (current_page_num == -1)
233 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
234 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
239 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
241 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
243 invoke_enable_buttons_vfunc(self);
247 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
249 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
251 invoke_enable_buttons_vfunc(self);
255 on_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
257 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
259 invoke_enable_buttons_vfunc(self);
263 on_serviceprovider_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
265 gchar* default_account_name_start;
266 gchar* default_account_name;
267 ModestEasysetupWizardDialog *self;
268 ModestEasysetupWizardDialogPrivate *priv;
269 ModestProviderPickerIdType provider_id_type;
271 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
272 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
274 on_picker_button_value_changed (widget, user_data);
276 provider_id_type = modest_provider_picker_get_active_id_type (
277 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
278 if (provider_id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
279 default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
283 selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (widget)));
284 default_account_name_start =
285 g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
288 default_account_name = modest_account_mgr_get_unused_account_display_name (
289 priv->account_manager, default_account_name_start);
290 g_free (default_account_name_start);
291 default_account_name_start = NULL;
293 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
294 g_free (default_account_name);
297 /** This is a convenience function to create a caption containing a mandatory widget.
298 * When the widget is edited, the enable_buttons() vfunc will be called.
301 create_captioned (ModestEasysetupWizardDialog *self,
302 GtkSizeGroup *title_size_group,
303 GtkSizeGroup *value_size_group,
310 result = modest_maemo_utils_create_captioned (title_size_group, value_size_group,
311 value, use_markup, control);
313 /* Connect to the appropriate changed signal for the widget,
314 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
316 if (GTK_IS_ENTRY (control)) {
317 g_signal_connect (G_OBJECT (control), "changed",
318 G_CALLBACK (on_caption_entry_changed), self);
321 else if (GTK_IS_COMBO_BOX (control)) {
322 g_signal_connect (G_OBJECT (control), "changed",
323 G_CALLBACK (on_caption_combobox_changed), self);
330 create_page_welcome (ModestEasysetupWizardDialog *self)
332 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
333 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
334 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
335 /* So that it is not truncated: */
336 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
337 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
338 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
339 gtk_widget_show (label);
340 gtk_widget_show (GTK_WIDGET (box));
341 return GTK_WIDGET (box);
345 on_account_country_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
347 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
349 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
353 /* Fill the providers picker, based on the selected country: */
354 if (priv->presets != NULL) {
355 gint mcc = modest_country_picker_get_active_country_mcc (
356 MODEST_COUNTRY_PICKER (priv->account_country_picker));
357 modest_provider_picker_fill (
358 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
363 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
365 ModestEasysetupWizardDialogPrivate *priv;
367 gchar* domain_name = NULL;
370 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
372 /* Fill the providers combo, based on the selected country: */
373 provider_id = modest_provider_picker_get_active_provider_id (
374 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
377 domain_name = modest_presets_get_domain (priv->presets, provider_id);
380 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
382 if (priv->entry_user_email)
383 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), domain_name);
385 g_free (domain_name);
387 g_free (provider_id);
391 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
393 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
395 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
399 update_user_email_from_provider (self);
403 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
405 modest_platform_information_banner (GTK_WIDGET (self), NULL,
406 _CS("ckdg_ib_maximum_characters_reached"));
410 create_page_account_details (ModestEasysetupWizardDialog *self)
413 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
414 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
415 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
417 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
418 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
419 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
420 gtk_widget_show (label);
422 /* Create a size group to be used by all captions.
423 * Note that HildonCaption does not create a default size group if we do not specify one.
424 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
425 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
426 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
428 /* The country widgets: */
429 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
430 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
431 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
432 _("mcen_fi_country"), priv->account_country_picker);
433 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
434 G_CALLBACK (on_picker_button_value_changed), self);
435 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
436 gtk_widget_show (priv->account_country_picker);
438 GtkWidget *separator = gtk_hseparator_new ();
439 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
440 gtk_widget_show (separator);
442 /* The service provider widgets: */
443 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
444 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
445 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
446 _("mcen_fi_serviceprovider"),
447 priv->account_serviceprovider_picker);
448 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
449 G_CALLBACK (on_serviceprovider_picker_button_value_changed), self);
450 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
451 gtk_widget_show (priv->account_serviceprovider_picker);
453 /* The description widgets: */
454 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
455 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
456 G_CALLBACK(on_easysetup_changed), self);
457 /* Do use auto-capitalization: */
458 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
459 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
461 /* Set a default account title, choosing one that does not already exist: */
462 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
463 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
464 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
465 priv->account_manager, default_account_name_start);
466 g_free (default_account_name_start);
467 default_account_name_start = NULL;
469 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
470 g_free (default_account_name);
471 default_account_name = NULL;
473 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mcen_fi_account_title"), FALSE,
474 priv->entry_account_title);
475 gtk_widget_show (priv->entry_account_title);
476 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
477 gtk_widget_show (caption);
479 /* Prevent the use of some characters in the account title,
480 * as required by our UI specification: */
481 GList *list_prevent = NULL;
482 list_prevent = g_list_append (list_prevent, "\\");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
488 list_prevent = g_list_append (list_prevent, "“");
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 modest_validating_entry_set_unallowed_characters (
494 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
495 g_list_free (list_prevent);
497 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
498 modest_utils_on_entry_invalid_character, self);
500 /* Set max length as in the UI spec:
501 * The UI spec seems to want us to show a dialog if we hit the maximum. */
502 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
503 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
506 gtk_widget_show (GTK_WIDGET (box));
508 g_object_unref (title_sizegroup);
509 g_object_unref (value_sizegroup);
511 return GTK_WIDGET (box);
515 create_page_user_details (ModestEasysetupWizardDialog *self)
517 GtkSizeGroup* title_sizegroup;
518 GtkSizeGroup* value_sizegroup;
520 ModestEasysetupWizardDialogPrivate *priv;
522 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
524 /* Create a size group to be used by all captions.
525 * Note that HildonCaption does not create a default size group if we do not specify one.
526 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
527 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
528 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
529 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
531 /* The name widgets: (use auto cap) */
532 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
533 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
534 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
536 /* Set max length as in the UI spec:
537 * The UI spec seems to want us to show a dialog if we hit the maximum. */
538 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
539 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
541 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
542 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
543 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
544 G_CALLBACK(on_easysetup_changed), self);
545 gtk_widget_show (priv->entry_user_name);
546 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
547 gtk_widget_show (caption);
549 /* Prevent the use of some characters in the name,
550 * as required by our UI specification: */
551 GList *list_prevent = NULL;
552 list_prevent = g_list_append (list_prevent, "<");
553 list_prevent = g_list_append (list_prevent, ">");
554 modest_validating_entry_set_unallowed_characters (
555 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
556 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
557 modest_utils_on_entry_invalid_character, self);
558 g_list_free (list_prevent);
560 /* The username widgets: */
561 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
562 /* Auto-capitalization is the default, so let's turn it off: */
563 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
564 HILDON_GTK_INPUT_MODE_FULL);
565 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
566 priv->entry_user_username);
567 gtk_widget_show (priv->entry_user_username);
568 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
569 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
570 G_CALLBACK(on_easysetup_changed), self);
571 gtk_widget_show (caption);
573 /* Prevent the use of some characters in the username,
574 * as required by our UI specification: */
575 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
576 modest_utils_on_entry_invalid_character, self);
578 /* Set max length as in the UI spec:
579 * The UI spec seems to want us to show a dialog if we hit the maximum. */
580 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
581 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
584 /* The password widgets: */
585 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
586 /* Auto-capitalization is the default, so let's turn it off: */
587 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
588 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
589 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
590 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
591 caption = create_captioned (self, title_sizegroup, value_sizegroup,
592 _("mail_fi_password"), FALSE, priv->entry_user_password);
593 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
594 G_CALLBACK(on_easysetup_changed), self);
595 gtk_widget_show (priv->entry_user_password);
596 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
597 gtk_widget_show (caption);
599 /* The email address widgets: */
600 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
601 /* Auto-capitalization is the default, so let's turn it off: */
602 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
603 caption = create_captioned (self, title_sizegroup, value_sizegroup,
604 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
605 update_user_email_from_provider (self);
606 gtk_widget_show (priv->entry_user_email);
607 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
608 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
609 G_CALLBACK(on_easysetup_changed), self);
610 gtk_widget_show (caption);
612 /* Set max length as in the UI spec:
613 * The UI spec seems to want us to show a dialog if we hit the maximum. */
614 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
615 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
619 gtk_widget_show (GTK_WIDGET (box));
620 g_object_unref (title_sizegroup);
621 g_object_unref (value_sizegroup);
623 return GTK_WIDGET (box);
627 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
629 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
631 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
632 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
633 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
634 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
635 /* The documentation for gtk_label_set_line_wrap() says that we must
636 * call gtk_widget_set_size_request() with a hard-coded width,
637 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
638 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
639 gtk_widget_show (label);
641 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
642 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
643 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
645 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
646 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
647 gtk_widget_show (label);
649 gtk_widget_show (GTK_WIDGET (box));
650 return GTK_WIDGET (box);
653 /** Change the caption title for the incoming server,
654 * as specified in the UI spec:
657 update_incoming_server_title (ModestEasysetupWizardDialog *self)
659 ModestEasysetupWizardDialogPrivate* priv;
660 ModestProtocolType protocol_type;
661 ModestProtocolRegistry *protocol_registry;
663 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
664 protocol_registry = modest_runtime_get_protocol_registry ();
666 protocol_type = modest_servertype_picker_get_active_servertype (
667 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
669 /* This could happen when the combo box has still no active iter */
670 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
671 gchar* incomingserver_title;
672 const gchar *protocol_display_name;
673 ModestProtocol *protocol;
675 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
677 protocol_display_name = modest_protocol_get_display_name (protocol);
679 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
680 protocol_display_name, ")</small>", NULL);
682 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
684 g_free(incomingserver_title);
688 /** Change the caption title for the incoming server,
689 * as specified in the UI spec:
692 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
694 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
695 ModestServertypePicker *server_type_picker;
696 ModestProtocolType protocol_type;
697 ModestSecurityOptionsView *view;
700 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
702 modest_servertype_picker_get_active_servertype (server_type_picker);
704 /* Fill the combo with appropriately titled choices for all
706 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
707 modest_security_options_view_set_server_type (view, protocol_type);
711 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
713 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
714 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
715 ModestServertypePicker *picker;
716 ModestProtocolType protocol_type;
721 update_incoming_server_title (self);
723 /* Update security options if needed */
724 picker = MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
725 protocol_type = modest_servertype_picker_get_active_servertype (picker);
726 update_incoming_server_security_choices (self);
727 gtk_widget_show (priv->incoming_security);
729 set_default_custom_servernames (self);
733 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
735 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
736 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
738 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
742 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
744 ModestProtocolRegistry *protocol_registry;
745 ModestEasysetupWizardDialogPrivate* priv;
749 GtkSizeGroup *title_sizegroup;
750 GtkSizeGroup *value_sizegroup;
752 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
753 protocol_registry = modest_runtime_get_protocol_registry ();
755 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
756 pannable = hildon_pannable_area_new ();
758 /* Show note that account type cannot be changed in future: */
759 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
760 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
761 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
762 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
763 gtk_widget_show (label);
765 /* Create a size group to be used by all captions.
766 * Note that HildonCaption does not create a default size group if we do not specify one.
767 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
768 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
769 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
771 /* The incoming server widgets: */
772 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
773 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
775 hildon_button_set_title (HILDON_BUTTON (priv->incoming_servertype_picker), _("mcen_li_emailsetup_type"));
776 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
777 G_CALLBACK (on_picker_button_value_changed), self);
778 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
779 gtk_widget_show (priv->incoming_servertype_picker);
781 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
782 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
783 /* Auto-capitalization is the default, so let's turn it off: */
784 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
785 set_default_custom_servernames (self);
787 /* The caption title will be updated in update_incoming_server_title().
788 * so this default text will never be seen: */
789 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
790 "This will be removed",
791 FALSE, priv->entry_incomingserver);
792 update_incoming_server_title (self);
793 gtk_widget_show (priv->entry_incomingserver);
794 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
795 gtk_widget_show (priv->caption_incoming);
797 /* Change the caption title when the servertype changes,
798 * as in the UI spec: */
799 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
801 G_CALLBACK (on_servertype_selector_changed), self);
803 /* Remember when the servername was changed manually: */
804 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
805 G_CALLBACK (on_entry_incoming_servername_changed), self);
807 /* The secure connection widgets. These are only valid for
808 protocols with security */
809 priv->incoming_security =
810 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
811 FALSE, title_sizegroup, value_sizegroup);
812 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
813 FALSE, FALSE, MODEST_MARGIN_HALF);
814 gtk_widget_show_all (priv->incoming_security);
816 /* Set default selection */
817 modest_servertype_picker_set_active_servertype (
818 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
819 MODEST_PROTOCOLS_STORE_POP);
821 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), box);
822 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
823 hildon_pannable_area_get_vadjustment (HILDON_PANNABLE_AREA (pannable)));
824 gtk_widget_show (GTK_WIDGET (box));
825 gtk_widget_show (pannable);
827 g_object_unref (title_sizegroup);
828 g_object_unref (value_sizegroup);
830 return GTK_WIDGET (pannable);
834 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
836 GtkWidget *widget = GTK_WIDGET (user_data);
838 /* Enable the widget only if the check button is active: */
839 const gboolean enable = hildon_check_button_get_active (button);
840 gtk_widget_set_sensitive (widget, enable);
843 /* Make the sensitivity of a widget depend on a check button.
846 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
848 g_signal_connect (G_OBJECT (button), "toggled",
849 G_CALLBACK (on_check_button_changed), widget);
851 /* Set the starting sensitivity: */
852 on_check_button_changed (button, widget);
856 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
858 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
859 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
860 GtkWidget *specific_window;
862 /* We set dirty here because setting it depending on the connection specific dialog
866 /* Create the window, if necessary: */
867 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
868 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
870 /* Show the window */
871 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
872 gtk_widget_show (specific_window);
876 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
878 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
879 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
880 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
884 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
886 ModestEasysetupWizardDialogPrivate *priv;
887 gchar *smtp_caption_label;
889 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
891 pannable = hildon_pannable_area_new ();
893 /* Create a size group to be used by all captions.
894 * Note that HildonCaption does not create a default size group if we do not specify one.
895 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
896 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
897 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
899 /* The outgoing server widgets: */
900 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
901 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
902 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
903 G_CALLBACK (on_easysetup_changed), self);
904 /* Auto-capitalization is the default, so let's turn it off: */
905 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
906 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
907 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
908 smtp_caption_label, TRUE, priv->entry_outgoingserver);
909 g_free (smtp_caption_label);
910 gtk_widget_show (priv->entry_outgoingserver);
911 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
912 gtk_widget_show (caption);
913 set_default_custom_servernames (self);
915 /* The secure connection widgets. These are only valid for
916 protocols with security */
917 priv->outgoing_security =
918 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
919 FALSE, title_sizegroup, value_sizegroup);
920 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
921 FALSE, FALSE, MODEST_MARGIN_HALF);
922 gtk_widget_show (priv->outgoing_security);
924 GtkWidget *separator = gtk_hseparator_new ();
925 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
926 gtk_widget_show (separator);
928 /* connection-specific checkbox: */
929 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
930 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
932 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
933 _("mcen_fi_advsetup_connection_smtp"));
934 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
936 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
937 G_CALLBACK (on_easysetup_changed), self);
939 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
940 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
941 FALSE, FALSE, MODEST_MARGIN_HALF);
943 /* Connection-specific SMTP-Severs Edit button: */
944 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
945 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
946 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
947 gtk_widget_show (priv->button_outgoing_smtp_servers);
948 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
949 FALSE, FALSE, MODEST_MARGIN_HALF);
951 /* Only enable the button when the checkbox is checked: */
952 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
953 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
955 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
956 G_CALLBACK (on_button_outgoing_smtp_servers), self);
958 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
959 G_CALLBACK (on_entry_outgoing_servername_changed), self);
962 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), box);
963 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
964 hildon_pannable_area_get_vadjustment (HILDON_PANNABLE_AREA (pannable)));
965 gtk_widget_show (GTK_WIDGET (box));
966 gtk_widget_show (pannable);
968 g_object_unref (title_sizegroup);
969 g_object_unref (value_sizegroup);
971 return GTK_WIDGET (pannable);
975 show_advanced_edit(gpointer user_data)
977 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
978 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
981 /* Show the Account Settings window: */
982 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
983 if (priv->pending_load_settings) {
984 save_to_settings (self);
985 priv->pending_load_settings = FALSE;
987 modest_account_settings_dialog_load_settings (dialog, priv->settings);
989 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
991 response = gtk_dialog_run (GTK_DIALOG (dialog));
993 gtk_widget_destroy (GTK_WIDGET (dialog));
995 return FALSE; /* Do not call this timeout callback again. */
999 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1001 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1003 /* Show the Account Settings window: */
1004 show_advanced_edit(self);
1007 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1009 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1010 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1011 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1012 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1013 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1014 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1015 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1016 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1017 gtk_widget_show (label);
1019 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1020 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1021 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1022 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1023 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1024 gtk_widget_show (label);
1026 gtk_widget_show (button_edit);
1027 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, MODEST_MARGIN_HALF);
1029 g_signal_connect (G_OBJECT (button_edit), "clicked",
1030 G_CALLBACK (on_button_edit_advanced_settings), self);
1032 gtk_widget_show (GTK_WIDGET (box));
1033 return GTK_WIDGET (box);
1040 on_response (ModestWizardDialog *wizard_dialog,
1044 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1046 invoke_enable_buttons_vfunc (self);
1050 on_response_before (ModestWizardDialog *wizard_dialog,
1054 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1055 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1056 if (response_id == GTK_RESPONSE_CANCEL) {
1057 /* This is mostly copied from
1058 * src/maemo/modest-account-settings-dialog.c */
1060 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1061 _("imum_nc_wizard_confirm_lose_changes")));
1062 /* TODO: These button names will be ambiguous, and not
1063 * specified in the UI specification. */
1065 const gint dialog_response = gtk_dialog_run (dialog);
1066 gtk_widget_destroy (GTK_WIDGET (dialog));
1068 if (dialog_response != GTK_RESPONSE_OK) {
1069 /* Don't let the dialog close */
1070 g_signal_stop_emission_by_name (wizard_dialog, "response");
1076 typedef struct IdleData {
1077 ModestEasysetupWizardDialog *dialog;
1078 ModestPresets *presets;
1082 presets_idle (gpointer userdata)
1084 IdleData *idle_data = (IdleData *) userdata;
1085 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1086 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1088 g_assert (idle_data->presets);
1090 gdk_threads_enter ();
1092 priv->presets = idle_data->presets;
1094 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1095 /* gint mcc = get_default_country_code(); */
1097 /* Fill the combo in an idle call, as it takes a lot of time */
1098 modest_country_picker_load_data(
1099 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1100 /* connect to country picker's changed signal, so we can fill the provider picker: */
1101 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1102 (HILDON_PICKER_BUTTON (priv->account_country_picker))),
1104 G_CALLBACK (on_account_country_selector_changed), self);
1106 modest_country_picker_set_active_country_locale (
1107 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1108 mcc = modest_country_picker_get_active_country_mcc (
1109 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1110 modest_provider_picker_fill (
1111 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1112 priv->presets, mcc);
1113 /* connect to providers picker's changed signal, so we can fill the email address: */
1114 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1115 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1117 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1119 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1122 priv->dirty = FALSE;
1124 g_object_unref (idle_data->dialog);
1127 gdk_threads_leave ();
1133 presets_loader (gpointer userdata)
1135 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1136 ModestPresets *presets = NULL;
1137 IdleData *idle_data;
1139 const gchar* path = NULL;
1140 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1141 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1143 if (access(path1, R_OK) == 0)
1145 else if (access(path2, R_OK) == 0)
1148 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1149 __FUNCTION__, path1, path2);
1153 presets = modest_presets_new (path);
1155 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1159 idle_data = g_new0 (IdleData, 1);
1160 idle_data->dialog = self;
1161 idle_data->presets = presets;
1163 g_idle_add (presets_idle, idle_data);
1169 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1174 /* Append page and set attributes */
1175 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1176 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1177 "tab-expand", TRUE, "tab-fill", TRUE,
1179 gtk_widget_show (page);
1183 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1185 priv->page_user_details = NULL;
1186 priv->entry_user_name = NULL;
1187 priv->entry_user_username = NULL;
1188 priv->entry_user_password = NULL;
1189 priv->entry_user_email = NULL;
1193 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1195 priv->page_custom_incoming = NULL;
1196 priv->incoming_servertype_picker = NULL;
1197 priv->caption_incoming = NULL;
1198 priv->entry_incomingserver = NULL;
1199 priv->entry_user_email = NULL;
1200 priv->incoming_security = NULL;
1204 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1206 priv->page_custom_outgoing = NULL;
1207 priv->entry_outgoingserver = NULL;
1208 priv->checkbox_outgoing_smtp_specific = NULL;
1209 priv->button_outgoing_smtp_servers = NULL;
1210 priv->outgoing_security = NULL;
1214 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1216 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1218 /* Create the notebook to be used by the ModestWizardDialog base class:
1219 * Each page of the notebook will be a page of the wizard: */
1220 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1221 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1223 /* Set the notebook used by the ModestWizardDialog base class: */
1224 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1226 /* Set the wizard title:
1227 * The actual window title will be a combination of this and the page's tab label title. */
1228 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1230 /* Read in the information about known service providers: */
1231 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1233 /* The server fields did not have been manually changed yet */
1234 priv->server_changes = 0;
1235 priv->pending_load_settings = TRUE;
1237 /* Get the account manager object,
1238 * so we can check for existing accounts,
1239 * and create new accounts: */
1240 priv->account_manager = modest_runtime_get_account_mgr ();
1241 g_object_ref (priv->account_manager);
1243 /* Initialize fields */
1244 priv->page_welcome = create_page_welcome (self);
1245 priv->page_account_details = create_page_account_details (self);
1247 init_user_page (priv);
1248 init_incoming_page (priv);
1249 init_outgoing_page (priv);
1251 priv->page_complete_easysetup = NULL;
1252 priv->page_complete_customsetup = NULL;
1253 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1254 priv->missing_data_signals = NULL;
1256 /* Add the common pages */
1257 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1258 _("mcen_ti_emailsetup_welcome"));
1259 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1260 _("mcen_ti_accountdetails"));
1262 /* Connect to the dialog's response signal so we can enable/disable buttons
1263 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1264 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1265 * so that we can be enable/disable after ModestWizardDialog has done its own
1266 * enabling/disabling of buttons.
1268 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1269 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1271 * It's not enough to connect to the notebook's switch-page signal, because
1272 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1273 * _after_ switching the page (understandably).
1274 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1275 * then gtk_notebook_get_current_page() would return an incorrect value.)
1277 g_signal_connect_after (G_OBJECT (self), "response",
1278 G_CALLBACK (on_response), self);
1280 /* This is to show a confirmation dialog when the user hits cancel */
1281 g_signal_connect (G_OBJECT (self), "response",
1282 G_CALLBACK (on_response_before), self);
1284 g_signal_connect (G_OBJECT (self), "delete-event",
1285 G_CALLBACK (on_delete_event), self);
1287 /* Reset dirty, because there was no user input until now */
1288 priv->dirty = FALSE;
1290 /* When this window is shown, hibernation should not be possible,
1291 * because there is no sensible way to save the state: */
1292 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1293 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1295 /* Load provider presets */
1296 g_object_ref (self);
1297 g_thread_create (presets_loader, self, FALSE, NULL);
1299 priv->settings = modest_account_settings_new ();
1302 ModestEasysetupWizardDialog*
1303 modest_easysetup_wizard_dialog_new (void)
1306 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1310 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1312 ModestEasysetupWizardDialogPrivate *priv;
1313 GtkNotebook *notebook = NULL;
1315 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1318 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1320 if (!priv->page_user_details) {
1321 priv->page_user_details = create_page_user_details (self);
1324 /* Create the custom pages: */
1325 if(!(priv->page_custom_incoming)) {
1326 priv->page_custom_incoming = create_page_custom_incoming (self);
1329 /* TODO: only if needed */
1330 if(!(priv->page_custom_outgoing)) {
1331 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1334 if(!(priv->page_complete_customsetup)) {
1335 priv->page_complete_customsetup = create_page_complete_custom (self);
1338 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1339 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1340 _("mcen_ti_emailsetup_userdetails"));
1342 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1343 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1344 _("mcen_ti_emailsetup_incomingdetails"));
1346 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1347 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1348 _("mcen_ti_emailsetup_outgoingdetails"));
1350 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1351 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1352 _("mcen_ti_emailsetup_complete"));
1354 /* This is unnecessary with GTK+ 2.10: */
1355 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1359 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1361 ModestEasysetupWizardDialogPrivate *priv;
1362 GtkNotebook *notebook = NULL;
1364 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1367 /* Create the easysetup-specific pages: */
1368 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1369 if(!priv->page_complete_easysetup)
1370 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1372 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1373 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1374 _("mcen_ti_emailsetup_complete"));
1376 /* This is unnecessary with GTK+ 2.10: */
1377 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1382 remove_non_common_tabs (GtkNotebook *notebook,
1383 gboolean remove_user_details)
1386 /* The first 2 tabs are the common ones (welcome tab and the
1387 providers tab), so we always remove starting from the
1390 starting_tab = (remove_user_details) ? 2 : 3;
1391 while (gtk_notebook_get_n_pages (notebook) > starting_tab)
1392 gtk_notebook_remove_page (notebook, -1);
1396 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1400 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1403 /* After the user details page,
1404 * the following pages depend on whether "Other" was chosen
1405 * in the provider combobox on the account page
1408 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1410 ModestEasysetupWizardDialogPrivate *priv;
1411 ModestProviderPicker *picker;
1412 ModestProviderPickerIdType id_type;
1413 GtkNotebook *notebook;
1415 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1416 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1417 id_type = modest_provider_picker_get_active_id_type (picker);
1418 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1420 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1421 /* "Other..." was selected: */
1423 /* If we come from a rollbacked easysetup */
1424 if (priv->page_complete_easysetup) {
1425 remove_non_common_tabs (notebook, FALSE);
1426 priv->page_complete_easysetup = NULL;
1429 /* If we come from a rollbacked plugin protocol setup */
1430 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1431 remove_non_common_tabs (notebook, TRUE);
1432 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1433 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1434 priv->missing_data_signals = NULL;
1437 create_subsequent_customsetup_pages (self);
1439 /* If we come from a rollbacked custom setup */
1440 if (priv->page_custom_incoming) {
1441 remove_non_common_tabs (notebook, TRUE);
1442 init_user_page (priv);
1443 init_incoming_page (priv);
1444 init_outgoing_page (priv);
1445 init_user_page (priv);
1446 priv->page_complete_customsetup = NULL;
1449 /* It's a pluggable protocol and not a provider with presets */
1450 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1451 ModestProtocol *protocol;
1453 ModestProtocolType proto_type;
1456 /* If we come from a rollbacked easy setup */
1457 if (priv->last_plugin_protocol_selected ==
1458 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1459 priv->page_complete_easysetup) {
1460 remove_non_common_tabs (notebook, TRUE);
1461 init_user_page (priv);
1462 priv->page_complete_easysetup = NULL;
1465 proto_name = modest_provider_picker_get_active_provider_id (picker);
1466 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1467 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1469 proto_type = modest_protocol_get_type_id (protocol);
1471 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1472 proto_type != priv->last_plugin_protocol_selected) {
1473 ModestPairList *tabs;
1475 gboolean first_page = TRUE;
1477 /* Remember the last selected plugin protocol */
1478 priv->last_plugin_protocol_selected = proto_type;
1481 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1482 tmp = (GSList *) tabs;
1484 ModestPair *pair = (ModestPair *) tmp->data;
1485 modest_easysetup_wizard_dialog_append_page (notebook,
1486 GTK_WIDGET (pair->second),
1487 (const gchar *) pair->first);
1489 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1490 GTK_WIDGET (pair->second));
1494 /* Connect signals */
1495 priv->missing_data_signals =
1496 modest_signal_mgr_connect (priv->missing_data_signals,
1497 G_OBJECT (pair->second),
1498 "missing-mandatory-data",
1499 G_CALLBACK (on_missing_mandatory_data),
1502 g_free (pair->first);
1503 tmp = g_slist_next (tmp);
1504 /* Critical: if you don't show the page then the dialog will ignore it */
1505 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1507 modest_pair_list_free (tabs);
1509 g_free (proto_name);
1511 if (priv->last_plugin_protocol_selected !=
1512 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1513 remove_non_common_tabs (notebook, TRUE);
1514 init_user_page (priv);
1515 priv->page_complete_easysetup = NULL;
1516 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1517 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1518 priv->missing_data_signals = NULL;
1520 if (!priv->page_user_details) {
1521 priv->page_user_details = create_page_user_details (self);
1522 modest_easysetup_wizard_dialog_append_page (notebook,
1523 priv->page_user_details,
1524 _("mcen_ti_emailsetup_userdetails"));
1528 /* Create the easysetup pages: */
1529 create_subsequent_easysetup_pages (self);
1535 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1537 const gchar* hostname = NULL;
1540 ModestProtocolRegistry *protocol_registry;
1541 ModestProtocol *protocol;
1546 at = g_utf8_strchr (email_address, -1, '@');
1547 if (!at || (g_utf8_strlen (at, -1) < 2))
1550 domain = g_utf8_next_char (at);
1554 protocol_registry = modest_runtime_get_protocol_registry ();
1555 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1557 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1558 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1559 hostname = modest_protocol_get_name (protocol);
1565 return g_strdup_printf ("%s.%s", hostname, domain);
1569 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1571 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1573 if (!priv->entry_incomingserver)
1576 /* Set a default domain for the server, based on the email address,
1577 * if no server name was already specified.
1579 if (priv->entry_user_email
1580 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1581 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1582 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1584 /* This could happen when the combo box has still no active iter */
1585 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1586 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1587 gchar* servername = util_get_default_servername_from_email_address (email_address,
1590 /* Do not set the INCOMING_CHANGED flag because of this edit */
1591 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1592 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1593 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1595 g_free (servername);
1599 /* Set a default domain for the server, based on the email address,
1600 * if no server name was already specified.
1602 if (!priv->entry_outgoingserver)
1605 if (priv->entry_user_email
1606 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1607 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1609 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1611 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1612 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1613 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1614 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1616 g_free (servername);
1621 get_entered_account_title (ModestEasysetupWizardDialog *self)
1623 ModestEasysetupWizardDialogPrivate *priv;
1624 const gchar* account_title;
1626 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1627 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1629 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1632 /* Strip it of whitespace at the start and end: */
1633 gchar *result = g_strdup (account_title);
1634 result = g_strstrip (result);
1639 if (g_utf8_strlen (result, -1) == 0) {
1649 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1651 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1652 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1653 ModestProtocolRegistry *protocol_registry;
1655 protocol_registry = modest_runtime_get_protocol_registry ();
1657 /* if are browsing pages previous to the last one, then we have pending settings in
1659 if (next_page != NULL)
1660 priv->pending_load_settings = TRUE;
1662 /* Do extra validation that couldn't be done for every key press,
1663 * either because it was too slow,
1664 * or because it requires interaction:
1666 if (current_page == priv->page_account_details) {
1667 /* Check that the title is not already in use: */
1668 gchar* account_title = get_entered_account_title (self);
1672 /* Aavoid a clash with an existing display name: */
1673 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1674 priv->account_manager, account_title);
1675 g_free (account_title);
1678 /* Warn the user via a dialog: */
1679 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1684 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1685 create_subsequent_pages (self);
1687 } else if (current_page == priv->page_user_details) {
1688 /* Check that the email address is valud: */
1689 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1690 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1693 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1694 /* Warn the user via a dialog: */
1695 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1697 /* Return focus to the email address entry: */
1698 gtk_widget_grab_focus (priv->entry_user_email);
1699 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1705 if (next_page == priv->page_custom_incoming) {
1706 set_default_custom_servernames (self);
1707 } else if (next_page == priv->page_custom_outgoing) {
1708 set_default_custom_servernames (self);
1710 /* Check if the server supports secure authentication */
1711 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
1712 if (!check_has_supported_auth_methods (self))
1714 gtk_widget_show (priv->outgoing_security);
1717 /* If this is the last page, and this is a click on Finish,
1718 * then attempt to create the dialog.
1721 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1723 if (priv->pending_load_settings) {
1724 save_to_settings (self);
1727 /* We check if there's already another account with the same configuration */
1728 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1729 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1733 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1740 static gboolean entry_is_empty (GtkWidget *entry)
1745 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1746 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1749 /* Strip it of whitespace at the start and end: */
1750 gchar *stripped = g_strdup (text);
1751 stripped = g_strstrip (stripped);
1756 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1764 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1766 GtkNotebook *notebook = NULL;
1767 gboolean is_finish_tab;
1769 ModestEasysetupWizardDialogPrivate *priv;
1772 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1773 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
1775 /* Disable the Finish button until we are on the last page,
1776 * because HildonWizardDialog enables this for all but the
1778 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1779 is_finish_tab = ((current == priv->page_complete_easysetup) ||
1780 (current == priv->page_complete_customsetup));
1782 if (is_finish_tab) {
1783 /* Disable Next on the last page no matter what the
1785 enable_next = FALSE;
1787 /* Not the last one */
1788 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1789 MODEST_WIZARD_DIALOG_FINISH,
1793 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1794 MODEST_WIZARD_DIALOG_NEXT,
1799 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1801 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1802 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1804 gboolean enable_next = TRUE;
1805 if (current_page == priv->page_welcome) {
1807 } else if (current_page == priv->page_account_details) {
1808 /* The account details title is mandatory: */
1809 if (entry_is_empty(priv->entry_account_title))
1810 enable_next = FALSE;
1811 } else if (current_page == priv->page_user_details) {
1812 /* The user details username is mandatory: */
1813 if (entry_is_empty(priv->entry_user_username))
1814 enable_next = FALSE;
1816 /* The user details email address is mandatory: */
1817 if (enable_next && entry_is_empty (priv->entry_user_email))
1818 enable_next = FALSE;
1819 } else if (current_page == priv->page_custom_incoming) {
1820 /* The custom incoming server is mandatory: */
1821 if (entry_is_empty(priv->entry_incomingserver))
1822 enable_next = FALSE;
1823 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1824 enable_next = !modest_easysetup_wizard_page_validate (
1825 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1828 /* Enable/disable buttons */
1829 real_enable_buttons (dialog, enable_next);
1833 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1835 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1836 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1839 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1840 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1842 /* Provide a vfunc implementation so we can decide
1843 * when to enable/disable the prev/next buttons.
1845 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1846 base_klass->before_next = on_before_next;
1847 base_klass->enable_buttons = on_enable_buttons;
1852 * @self: a #ModestEasysetupWizardDialog
1854 * takes information from all the wizard and stores it in settings
1857 save_to_settings (ModestEasysetupWizardDialog *self)
1859 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1861 gchar *provider_id = NULL;
1862 gchar* display_name;
1863 const gchar *username, *password;
1864 gchar *store_hostname, *transport_hostname;
1865 guint store_port, transport_port;
1866 ModestProtocolRegistry *protocol_registry;
1867 ModestProtocolType store_protocol, transport_protocol;
1868 ModestProtocolType store_security, transport_security;
1869 ModestProtocolType store_auth_protocol, transport_auth_protocol;
1870 ModestServerAccountSettings *store_settings, *transport_settings;
1871 const gchar *fullname, *email_address;
1872 ModestProviderPicker *picker;
1873 ModestProviderPickerIdType id_type;
1875 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1876 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1877 protocol_registry = modest_runtime_get_protocol_registry ();
1879 /* Get details from the specified presets: */
1880 id_type = modest_provider_picker_get_active_id_type (picker);
1881 provider_id = modest_provider_picker_get_active_provider_id (picker);
1883 /* Let the plugin save the settings. We do a return in order
1884 to save an indentation level */
1885 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1886 ModestProtocol *protocol;
1888 protocol = modest_protocol_registry_get_protocol_by_name (
1889 modest_runtime_get_protocol_registry (),
1890 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1893 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1894 gint n_pages, i = 0;
1895 GtkNotebook *notebook;
1896 GList *wizard_pages = NULL;
1898 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1899 n_pages = gtk_notebook_get_n_pages (notebook);
1900 for (i = 0; i < n_pages; i++) {
1901 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1902 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1903 wizard_pages = g_list_append (wizard_pages, page);
1905 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1908 g_list_free (wizard_pages);
1910 g_warning ("The selected protocol is a plugin protocol "//
1911 "but it's not a ModestAccountProtocol");
1914 g_free (provider_id);
1918 /* username and password (for both incoming and outgoing): */
1919 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
1920 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
1922 store_settings = modest_account_settings_get_store_settings (priv->settings);
1923 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1925 /* Incoming server: */
1926 /* Note: We need something as default for the transport store protocol values,
1927 * or modest_account_mgr_add_server_account will fail. */
1929 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1930 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1931 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1934 ModestProtocolType store_provider_server_type;
1935 gboolean store_provider_use_alternate_port;
1937 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1940 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1943 store_security = modest_presets_get_info_server_security (priv->presets,
1946 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
1949 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
1953 /* We don't check for SMTP here as that is impossible for an incoming server. */
1954 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1955 store_protocol = MODEST_PROTOCOLS_STORE_POP;
1957 store_protocol = store_provider_server_type;
1959 /* we check if there is a *special* port */
1960 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1961 if (special_port != 0) {
1962 store_port = special_port;
1964 gboolean use_alternate_port = FALSE;
1965 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
1967 use_alternate_port = TRUE;
1968 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
1971 modest_server_account_settings_set_security_protocol (store_settings,
1973 modest_server_account_settings_set_auth_protocol (store_settings,
1974 store_auth_protocol);
1975 if (store_port != 0)
1976 modest_server_account_settings_set_port (store_settings, store_port);
1978 /* Use custom pages because no preset was specified: */
1979 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
1980 store_protocol = modest_servertype_picker_get_active_servertype (
1981 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1983 modest_security_options_view_save_settings (
1984 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1988 /* now we store the common store account settings */
1989 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1990 modest_server_account_settings_set_username (store_settings, username);
1991 modest_server_account_settings_set_password (store_settings, password);
1992 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1994 g_object_unref (store_settings);
1995 g_free (store_hostname);
1997 /* Outgoing server: */
1998 transport_hostname = NULL;
1999 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2000 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2001 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2005 ModestProtocolType transport_provider_server_type;
2006 ModestProtocolType transport_provider_security;
2009 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2010 FALSE /* transport */);
2012 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2014 FALSE /* transport */);
2015 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2017 FALSE /* transport */);
2019 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2020 transport_protocol = transport_provider_server_type;
2021 transport_security = transport_provider_security;
2022 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
2023 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
2024 /* we check if there is a *special* port */
2025 special_port = modest_presets_get_port (priv->presets, provider_id,
2026 FALSE /* transport */);
2027 if (special_port != 0)
2028 transport_port = special_port;
2030 transport_port = 465;
2031 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2033 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
2034 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2037 modest_server_account_settings_set_security_protocol (transport_settings,
2038 transport_security);
2039 modest_server_account_settings_set_auth_protocol (transport_settings,
2040 transport_auth_protocol);
2041 if (transport_port != 0)
2042 modest_server_account_settings_set_port (transport_settings,
2045 ModestProtocolRegistry *registry;
2046 ModestProtocol *store_proto;
2048 registry = modest_runtime_get_protocol_registry ();
2049 /* Use custom pages because no preset was specified: */
2050 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2052 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2055 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2056 /* fallback to SMTP if none was specified */
2057 g_warning ("No transport protocol was specified for store %d (%s)",
2058 modest_protocol_get_type_id (store_proto),
2059 modest_protocol_get_display_name (store_proto));
2060 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2063 modest_security_options_view_save_settings (
2064 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2068 /* now we store the common transport account settings */
2069 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2070 modest_server_account_settings_set_username (transport_settings, username);
2071 modest_server_account_settings_set_password (transport_settings, password);
2072 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2074 g_object_unref (transport_settings);
2075 g_free (transport_hostname);
2077 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2078 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2079 modest_account_settings_set_fullname (priv->settings, fullname);
2080 modest_account_settings_set_email_address (priv->settings, email_address);
2081 /* we don't set retrieve type to preserve advanced settings if
2082 any. By default account settings are set to headers only */
2084 /* Save the connection-specific SMTP server accounts. */
2085 modest_account_settings_set_use_connection_specific_smtp
2087 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2089 display_name = get_entered_account_title (self);
2090 modest_account_settings_set_display_name (priv->settings, display_name);
2091 g_free (display_name);
2092 g_free (provider_id);
2096 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2098 GError *error = NULL;
2099 ModestProtocolType protocol_type;
2100 const gchar* hostname;
2101 const gchar* username;
2102 ModestProtocolType security_protocol_incoming_type;
2103 ModestProtocolRegistry *registry;
2105 GList *list_auth_methods;
2106 ModestEasysetupWizardDialogPrivate *priv;
2108 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2109 registry = modest_runtime_get_protocol_registry ();
2110 protocol_type = modest_servertype_picker_get_active_servertype (
2111 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2112 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2113 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2114 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2115 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2116 port_num = get_port_from_protocol(protocol_type, FALSE);
2117 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2118 username, GTK_WINDOW (self), &error);
2120 if (list_auth_methods) {
2121 /* TODO: Select the correct method */
2124 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2125 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2126 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2127 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2128 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2132 g_list_free(list_auth_methods);
2138 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2139 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2141 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2142 _("mcen_ib_unableto_discover_auth_methods"));
2146 g_error_free(error);
2152 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2154 GList* methods = check_for_supported_auth_methods(self);
2160 g_list_free(methods);