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_update_model (ModestWizardDialog *dialog);
143 static gboolean on_save (ModestWizardDialog *dialog);
144 static GList* check_for_supported_auth_methods (ModestEasysetupWizardDialog* self);
145 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self);
148 on_delete_event (GtkWidget *widget,
150 ModestEasysetupWizardDialog *wizard)
152 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
157 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
159 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
160 g_return_if_fail (priv != NULL);
165 modest_easysetup_wizard_dialog_dispose (GObject *object)
167 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
168 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
172 modest_easysetup_wizard_dialog_finalize (GObject *object)
174 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
175 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
177 if (priv->account_manager)
178 g_object_unref (G_OBJECT (priv->account_manager));
181 modest_presets_destroy (priv->presets);
184 g_object_unref (priv->settings);
186 if (priv->missing_data_signals) {
187 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
188 priv->missing_data_signals = NULL;
191 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
195 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
198 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
200 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
203 get_port_from_protocol (ModestProtocolType server_type,
204 gboolean alternate_port)
207 ModestProtocol *protocol;
208 ModestProtocolRegistry *protocol_registry;
210 protocol_registry = modest_runtime_get_protocol_registry ();
211 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
213 if (alternate_port) {
214 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
216 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
222 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
224 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
226 /* Call the vfunc, which may be overridden by derived classes: */
227 if (klass->enable_buttons) {
228 GtkNotebook *notebook = NULL;
229 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
231 const gint current_page_num = gtk_notebook_get_current_page (notebook);
232 if (current_page_num == -1)
235 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
236 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
241 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
243 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
245 invoke_enable_buttons_vfunc(self);
249 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
251 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
253 invoke_enable_buttons_vfunc(self);
257 on_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
259 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
261 invoke_enable_buttons_vfunc(self);
265 on_serviceprovider_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
267 gchar* default_account_name_start;
268 gchar* default_account_name;
269 ModestEasysetupWizardDialog *self;
270 ModestEasysetupWizardDialogPrivate *priv;
271 ModestProviderPickerIdType provider_id_type;
273 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
274 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
276 on_picker_button_value_changed (widget, user_data);
278 provider_id_type = modest_provider_picker_get_active_id_type (
279 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
280 if (provider_id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
281 default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
285 selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (widget)));
286 default_account_name_start =
287 g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
290 default_account_name = modest_account_mgr_get_unused_account_display_name (
291 priv->account_manager, default_account_name_start);
292 g_free (default_account_name_start);
293 default_account_name_start = NULL;
295 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
296 g_free (default_account_name);
299 /** This is a convenience function to create a caption containing a mandatory widget.
300 * When the widget is edited, the enable_buttons() vfunc will be called.
303 create_captioned (ModestEasysetupWizardDialog *self,
304 GtkSizeGroup *title_size_group,
305 GtkSizeGroup *value_size_group,
312 result = modest_maemo_utils_create_captioned (title_size_group, value_size_group,
313 value, use_markup, control);
315 /* Connect to the appropriate changed signal for the widget,
316 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
318 if (GTK_IS_ENTRY (control)) {
319 g_signal_connect (G_OBJECT (control), "changed",
320 G_CALLBACK (on_caption_entry_changed), self);
323 else if (GTK_IS_COMBO_BOX (control)) {
324 g_signal_connect (G_OBJECT (control), "changed",
325 G_CALLBACK (on_caption_combobox_changed), self);
332 create_page_welcome (ModestEasysetupWizardDialog *self)
334 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
335 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
336 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
337 /* So that it is not truncated: */
338 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
339 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
340 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
341 gtk_widget_show (label);
342 gtk_widget_show (GTK_WIDGET (box));
343 return GTK_WIDGET (box);
347 on_account_country_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
349 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
351 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
355 /* Fill the providers picker, based on the selected country: */
356 if (priv->presets != NULL) {
357 gint mcc = modest_country_picker_get_active_country_mcc (
358 MODEST_COUNTRY_PICKER (priv->account_country_picker));
359 modest_provider_picker_fill (
360 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
365 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
367 ModestEasysetupWizardDialogPrivate *priv;
369 gchar* domain_name = NULL;
372 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
374 /* Fill the providers combo, based on the selected country: */
375 provider_id = modest_provider_picker_get_active_provider_id (
376 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
379 domain_name = modest_presets_get_domain (priv->presets, provider_id);
382 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
384 if (priv->entry_user_email)
385 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), domain_name);
387 g_free (domain_name);
389 g_free (provider_id);
393 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
395 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
397 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
401 update_user_email_from_provider (self);
405 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
407 modest_platform_information_banner (GTK_WIDGET (self), NULL,
408 _CS("ckdg_ib_maximum_characters_reached"));
412 create_page_account_details (ModestEasysetupWizardDialog *self)
415 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
416 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
417 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
419 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
420 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
421 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
422 gtk_widget_show (label);
424 /* Create a size group to be used by all captions.
425 * Note that HildonCaption does not create a default size group if we do not specify one.
426 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
427 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
428 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
430 /* The country widgets: */
431 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
432 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
433 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
434 _("mcen_fi_country"), priv->account_country_picker);
435 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
436 G_CALLBACK (on_picker_button_value_changed), self);
437 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
438 gtk_widget_show (priv->account_country_picker);
440 GtkWidget *separator = gtk_hseparator_new ();
441 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
442 gtk_widget_show (separator);
444 /* The service provider widgets: */
445 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
446 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
447 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
448 _("mcen_fi_serviceprovider"),
449 priv->account_serviceprovider_picker);
450 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
451 G_CALLBACK (on_serviceprovider_picker_button_value_changed), self);
452 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
453 gtk_widget_show (priv->account_serviceprovider_picker);
455 /* The description widgets: */
456 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
457 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
458 G_CALLBACK(on_easysetup_changed), self);
459 /* Do use auto-capitalization: */
460 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
461 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
463 /* Set a default account title, choosing one that does not already exist: */
464 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
465 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
466 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
467 priv->account_manager, default_account_name_start);
468 g_free (default_account_name_start);
469 default_account_name_start = NULL;
471 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
472 g_free (default_account_name);
473 default_account_name = NULL;
475 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mcen_fi_account_title"), FALSE,
476 priv->entry_account_title);
477 gtk_widget_show (priv->entry_account_title);
478 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
479 gtk_widget_show (caption);
481 /* Prevent the use of some characters in the account title,
482 * as required by our UI specification: */
483 GList *list_prevent = NULL;
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, "?");
489 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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 list_prevent = g_list_append (list_prevent, "^");
495 modest_validating_entry_set_unallowed_characters (
496 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
497 g_list_free (list_prevent);
499 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
500 modest_utils_on_entry_invalid_character, self);
502 /* Set max length as in the UI spec:
503 * The UI spec seems to want us to show a dialog if we hit the maximum. */
504 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
505 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
508 gtk_widget_show (GTK_WIDGET (box));
510 g_object_unref (title_sizegroup);
511 g_object_unref (value_sizegroup);
513 return GTK_WIDGET (box);
517 create_page_user_details (ModestEasysetupWizardDialog *self)
519 GtkSizeGroup* title_sizegroup;
520 GtkSizeGroup* value_sizegroup;
522 ModestEasysetupWizardDialogPrivate *priv;
524 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
526 /* Create a size group to be used by all captions.
527 * Note that HildonCaption does not create a default size group if we do not specify one.
528 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
529 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
530 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
531 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
533 /* The name widgets: (use auto cap) */
534 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
535 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
536 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
538 /* Set max length as in the UI spec:
539 * The UI spec seems to want us to show a dialog if we hit the maximum. */
540 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
541 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
543 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
544 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
545 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
546 G_CALLBACK(on_easysetup_changed), self);
547 gtk_widget_show (priv->entry_user_name);
548 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
549 gtk_widget_show (caption);
551 /* Prevent the use of some characters in the name,
552 * as required by our UI specification: */
553 GList *list_prevent = NULL;
554 list_prevent = g_list_append (list_prevent, "<");
555 list_prevent = g_list_append (list_prevent, ">");
556 modest_validating_entry_set_unallowed_characters (
557 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
558 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
559 modest_utils_on_entry_invalid_character, self);
560 g_list_free (list_prevent);
562 /* The username widgets: */
563 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
564 /* Auto-capitalization is the default, so let's turn it off: */
565 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
566 HILDON_GTK_INPUT_MODE_FULL);
567 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
568 priv->entry_user_username);
569 gtk_widget_show (priv->entry_user_username);
570 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
571 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
572 G_CALLBACK(on_easysetup_changed), self);
573 gtk_widget_show (caption);
575 /* Prevent the use of some characters in the username,
576 * as required by our UI specification: */
577 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
578 modest_utils_on_entry_invalid_character, self);
580 /* Set max length as in the UI spec:
581 * The UI spec seems to want us to show a dialog if we hit the maximum. */
582 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
583 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
586 /* The password widgets: */
587 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
588 /* Auto-capitalization is the default, so let's turn it off: */
589 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
590 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
591 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
592 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
593 caption = create_captioned (self, title_sizegroup, value_sizegroup,
594 _("mail_fi_password"), FALSE, priv->entry_user_password);
595 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
596 G_CALLBACK(on_easysetup_changed), self);
597 gtk_widget_show (priv->entry_user_password);
598 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
599 gtk_widget_show (caption);
601 /* The email address widgets: */
602 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
603 /* Auto-capitalization is the default, so let's turn it off: */
604 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
605 caption = create_captioned (self, title_sizegroup, value_sizegroup,
606 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
607 update_user_email_from_provider (self);
608 gtk_widget_show (priv->entry_user_email);
609 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
610 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
611 G_CALLBACK(on_easysetup_changed), self);
612 gtk_widget_show (caption);
614 /* Set max length as in the UI spec:
615 * The UI spec seems to want us to show a dialog if we hit the maximum. */
616 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
617 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
621 gtk_widget_show (GTK_WIDGET (box));
622 g_object_unref (title_sizegroup);
623 g_object_unref (value_sizegroup);
625 return GTK_WIDGET (box);
629 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
631 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
633 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
634 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
635 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
636 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
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);
1419 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1423 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1424 /* "Other..." was selected: */
1426 /* If we come from a rollbacked easysetup */
1427 if (priv->page_complete_easysetup) {
1428 remove_non_common_tabs (notebook, FALSE);
1429 priv->page_complete_easysetup = NULL;
1432 /* If we come from a rollbacked plugin protocol setup */
1433 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1434 remove_non_common_tabs (notebook, TRUE);
1435 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1436 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1437 priv->missing_data_signals = NULL;
1440 create_subsequent_customsetup_pages (self);
1442 /* If we come from a rollbacked custom setup */
1443 if (priv->page_custom_incoming) {
1444 remove_non_common_tabs (notebook, TRUE);
1445 init_user_page (priv);
1446 init_incoming_page (priv);
1447 init_outgoing_page (priv);
1448 init_user_page (priv);
1449 priv->page_complete_customsetup = NULL;
1452 /* It's a pluggable protocol and not a provider with presets */
1453 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1454 ModestProtocol *protocol;
1456 ModestProtocolType proto_type;
1459 /* If we come from a rollbacked easy setup */
1460 if (priv->last_plugin_protocol_selected ==
1461 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1462 priv->page_complete_easysetup) {
1463 remove_non_common_tabs (notebook, TRUE);
1464 init_user_page (priv);
1465 priv->page_complete_easysetup = NULL;
1468 proto_name = modest_provider_picker_get_active_provider_id (picker);
1469 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1470 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1472 proto_type = modest_protocol_get_type_id (protocol);
1474 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1475 proto_type != priv->last_plugin_protocol_selected) {
1476 ModestPairList *tabs;
1478 gboolean first_page = TRUE;
1479 ModestWizardDialogResponseOverrideFunc response_override;
1481 /* Remember the last selected plugin protocol */
1482 priv->last_plugin_protocol_selected = proto_type;
1485 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1486 response_override = modest_account_protocol_get_wizard_response_override
1487 (MODEST_ACCOUNT_PROTOCOL (protocol));
1488 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1490 tmp = (GSList *) tabs;
1492 ModestPair *pair = (ModestPair *) tmp->data;
1493 modest_easysetup_wizard_dialog_append_page (notebook,
1494 GTK_WIDGET (pair->second),
1495 (const gchar *) pair->first);
1497 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1498 GTK_WIDGET (pair->second));
1502 /* Connect signals */
1503 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1504 priv->missing_data_signals =
1505 modest_signal_mgr_connect (priv->missing_data_signals,
1506 G_OBJECT (pair->second),
1507 "missing-mandatory-data",
1508 G_CALLBACK (on_missing_mandatory_data),
1512 g_free (pair->first);
1513 tmp = g_slist_next (tmp);
1514 /* Critical: if you don't show the page then the dialog will ignore it */
1515 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1517 modest_pair_list_free (tabs);
1519 g_free (proto_name);
1521 if (priv->last_plugin_protocol_selected !=
1522 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1523 remove_non_common_tabs (notebook, TRUE);
1524 init_user_page (priv);
1525 priv->page_complete_easysetup = NULL;
1526 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1527 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1528 priv->missing_data_signals = NULL;
1530 if (!priv->page_user_details) {
1531 priv->page_user_details = create_page_user_details (self);
1532 modest_easysetup_wizard_dialog_append_page (notebook,
1533 priv->page_user_details,
1534 _("mcen_ti_emailsetup_userdetails"));
1538 /* Create the easysetup pages: */
1539 create_subsequent_easysetup_pages (self);
1545 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1547 const gchar* hostname = NULL;
1550 ModestProtocolRegistry *protocol_registry;
1551 ModestProtocol *protocol;
1556 at = g_utf8_strchr (email_address, -1, '@');
1557 if (!at || (g_utf8_strlen (at, -1) < 2))
1560 domain = g_utf8_next_char (at);
1564 protocol_registry = modest_runtime_get_protocol_registry ();
1565 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1567 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1568 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1569 hostname = modest_protocol_get_name (protocol);
1575 return g_strdup_printf ("%s.%s", hostname, domain);
1579 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1581 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1583 if (!priv->entry_incomingserver)
1586 /* Set a default domain for the server, based on the email address,
1587 * if no server name was already specified.
1589 if (priv->entry_user_email
1590 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1591 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1592 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1594 /* This could happen when the combo box has still no active iter */
1595 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1596 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1597 gchar* servername = util_get_default_servername_from_email_address (email_address,
1600 /* Do not set the INCOMING_CHANGED flag because of this edit */
1601 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1602 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1603 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1605 g_free (servername);
1609 /* Set a default domain for the server, based on the email address,
1610 * if no server name was already specified.
1612 if (!priv->entry_outgoingserver)
1615 if (priv->entry_user_email
1616 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1617 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1619 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1621 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1622 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1623 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1624 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1626 g_free (servername);
1631 get_entered_account_title (ModestEasysetupWizardDialog *self)
1633 ModestEasysetupWizardDialogPrivate *priv;
1634 const gchar* account_title;
1636 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1637 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1639 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1642 /* Strip it of whitespace at the start and end: */
1643 gchar *result = g_strdup (account_title);
1644 result = g_strstrip (result);
1649 if (g_utf8_strlen (result, -1) == 0) {
1659 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1661 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1662 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1663 ModestProtocolRegistry *protocol_registry;
1665 protocol_registry = modest_runtime_get_protocol_registry ();
1667 /* if are browsing pages previous to the last one, then we have pending settings in
1669 if (next_page != NULL)
1670 priv->pending_load_settings = TRUE;
1672 /* Do extra validation that couldn't be done for every key press,
1673 * either because it was too slow,
1674 * or because it requires interaction:
1676 if (current_page == priv->page_account_details) {
1677 /* Check that the title is not already in use: */
1678 gchar* account_title = get_entered_account_title (self);
1682 /* Aavoid a clash with an existing display name: */
1683 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1684 priv->account_manager, account_title);
1685 g_free (account_title);
1688 /* Warn the user via a dialog: */
1689 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1694 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1695 create_subsequent_pages (self);
1697 } else if (current_page == priv->page_user_details) {
1698 /* Check that the email address is valud: */
1699 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1700 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1703 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1704 /* Warn the user via a dialog: */
1705 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1707 /* Return focus to the email address entry: */
1708 gtk_widget_grab_focus (priv->entry_user_email);
1709 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1715 if (next_page == priv->page_custom_incoming) {
1716 set_default_custom_servernames (self);
1717 } else if (next_page == priv->page_custom_outgoing) {
1718 set_default_custom_servernames (self);
1720 /* Check if the server supports secure authentication */
1721 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
1722 if (!check_has_supported_auth_methods (self))
1724 gtk_widget_show (priv->outgoing_security);
1727 /* If this is the last page, and this is a click on Finish,
1728 * then attempt to create the dialog.
1731 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1733 if (priv->pending_load_settings) {
1734 save_to_settings (self);
1737 /* We check if there's already another account with the same configuration */
1738 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1739 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1743 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1750 static gboolean entry_is_empty (GtkWidget *entry)
1755 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1756 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1759 /* Strip it of whitespace at the start and end: */
1760 gchar *stripped = g_strdup (text);
1761 stripped = g_strstrip (stripped);
1766 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1774 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1776 GtkNotebook *notebook = NULL;
1777 gboolean is_finish_tab;
1779 ModestEasysetupWizardDialogPrivate *priv;
1782 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1783 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
1785 /* Disable the Finish button until we are on the last page,
1786 * because HildonWizardDialog enables this for all but the
1788 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1789 is_finish_tab = ((current == priv->page_complete_easysetup) ||
1790 (current == priv->page_complete_customsetup));
1792 if (is_finish_tab) {
1793 /* Disable Next on the last page no matter what the
1795 enable_next = FALSE;
1797 /* Not the last one */
1798 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1799 MODEST_WIZARD_DIALOG_FINISH,
1803 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1804 MODEST_WIZARD_DIALOG_NEXT,
1809 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1811 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1812 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1814 gboolean enable_next = TRUE;
1815 if (current_page == priv->page_welcome) {
1817 } else if (current_page == priv->page_account_details) {
1818 /* The account details title is mandatory: */
1819 if (entry_is_empty(priv->entry_account_title))
1820 enable_next = FALSE;
1821 } else if (current_page == priv->page_user_details) {
1822 /* The user details username is mandatory: */
1823 if (entry_is_empty(priv->entry_user_username))
1824 enable_next = FALSE;
1826 /* The user details email address is mandatory: */
1827 if (enable_next && entry_is_empty (priv->entry_user_email))
1828 enable_next = FALSE;
1829 } else if (current_page == priv->page_custom_incoming) {
1830 /* The custom incoming server is mandatory: */
1831 if (entry_is_empty(priv->entry_incomingserver))
1832 enable_next = FALSE;
1833 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1834 enable_next = !modest_easysetup_wizard_page_validate (
1835 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1838 /* Enable/disable buttons */
1839 real_enable_buttons (dialog, enable_next);
1843 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1845 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1846 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1849 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1850 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1852 /* Provide a vfunc implementation so we can decide
1853 * when to enable/disable the prev/next buttons.
1855 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1856 base_klass->before_next = on_before_next;
1857 base_klass->enable_buttons = on_enable_buttons;
1858 base_klass->update_model = on_update_model;
1859 base_klass->save = on_save;
1864 * @self: a #ModestEasysetupWizardDialog
1866 * takes information from all the wizard and stores it in settings
1869 save_to_settings (ModestEasysetupWizardDialog *self)
1871 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1873 gchar *provider_id = NULL;
1874 gchar* display_name;
1875 const gchar *username, *password;
1876 gchar *store_hostname, *transport_hostname;
1877 guint store_port, transport_port;
1878 ModestProtocolRegistry *protocol_registry;
1879 ModestProtocolType store_protocol, transport_protocol;
1880 ModestProtocolType store_security, transport_security;
1881 ModestProtocolType store_auth_protocol, transport_auth_protocol;
1882 ModestServerAccountSettings *store_settings, *transport_settings;
1883 const gchar *fullname, *email_address;
1884 ModestProviderPicker *picker;
1885 ModestProviderPickerIdType id_type;
1887 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1888 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1889 protocol_registry = modest_runtime_get_protocol_registry ();
1891 /* Get details from the specified presets: */
1892 id_type = modest_provider_picker_get_active_id_type (picker);
1893 provider_id = modest_provider_picker_get_active_provider_id (picker);
1895 /* Let the plugin save the settings. We do a return in order
1896 to save an indentation level */
1897 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1898 ModestProtocol *protocol;
1900 protocol = modest_protocol_registry_get_protocol_by_name (
1901 modest_runtime_get_protocol_registry (),
1902 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1905 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1906 gint n_pages, i = 0;
1907 GtkNotebook *notebook;
1908 GList *wizard_pages = NULL;
1910 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1911 n_pages = gtk_notebook_get_n_pages (notebook);
1912 for (i = 0; i < n_pages; i++) {
1913 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1914 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1915 wizard_pages = g_list_append (wizard_pages, page);
1917 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1920 g_list_free (wizard_pages);
1922 g_warning ("The selected protocol is a plugin protocol "//
1923 "but it's not a ModestAccountProtocol");
1926 g_free (provider_id);
1930 /* username and password (for both incoming and outgoing): */
1931 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
1932 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
1934 store_settings = modest_account_settings_get_store_settings (priv->settings);
1935 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1937 /* Incoming server: */
1938 /* Note: We need something as default for the transport store protocol values,
1939 * or modest_account_mgr_add_server_account will fail. */
1941 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1942 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1943 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1946 ModestProtocolType store_provider_server_type;
1947 gboolean store_provider_use_alternate_port;
1949 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1952 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1955 store_security = modest_presets_get_info_server_security (priv->presets,
1958 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
1961 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
1965 /* We don't check for SMTP here as that is impossible for an incoming server. */
1966 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1967 store_protocol = MODEST_PROTOCOLS_STORE_POP;
1969 store_protocol = store_provider_server_type;
1971 /* we check if there is a *special* port */
1972 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1973 if (special_port != 0) {
1974 store_port = special_port;
1976 gboolean use_alternate_port = FALSE;
1977 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
1979 use_alternate_port = TRUE;
1980 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
1983 modest_server_account_settings_set_security_protocol (store_settings,
1985 modest_server_account_settings_set_auth_protocol (store_settings,
1986 store_auth_protocol);
1987 if (store_port != 0)
1988 modest_server_account_settings_set_port (store_settings, store_port);
1990 /* Use custom pages because no preset was specified: */
1991 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
1992 store_protocol = modest_servertype_picker_get_active_servertype (
1993 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1995 modest_security_options_view_save_settings (
1996 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2000 /* now we store the common store account settings */
2001 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2002 modest_server_account_settings_set_username (store_settings, username);
2003 modest_server_account_settings_set_password (store_settings, password);
2004 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2006 g_object_unref (store_settings);
2007 g_free (store_hostname);
2009 /* Outgoing server: */
2010 transport_hostname = NULL;
2011 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2012 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2013 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2017 ModestProtocolType transport_provider_server_type;
2018 ModestProtocolType transport_provider_security;
2021 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2022 FALSE /* transport */);
2024 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2026 FALSE /* transport */);
2027 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2029 FALSE /* transport */);
2031 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2032 transport_protocol = transport_provider_server_type;
2033 transport_security = transport_provider_security;
2034 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
2035 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
2036 /* we check if there is a *special* port */
2037 special_port = modest_presets_get_port (priv->presets, provider_id,
2038 FALSE /* transport */);
2039 if (special_port != 0)
2040 transport_port = special_port;
2042 transport_port = 465;
2043 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2045 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
2046 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2049 modest_server_account_settings_set_security_protocol (transport_settings,
2050 transport_security);
2051 modest_server_account_settings_set_auth_protocol (transport_settings,
2052 transport_auth_protocol);
2053 if (transport_port != 0)
2054 modest_server_account_settings_set_port (transport_settings,
2057 ModestProtocolRegistry *registry;
2058 ModestProtocol *store_proto;
2060 registry = modest_runtime_get_protocol_registry ();
2061 /* Use custom pages because no preset was specified: */
2062 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2064 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2067 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2068 /* fallback to SMTP if none was specified */
2069 g_warning ("No transport protocol was specified for store %d (%s)",
2070 modest_protocol_get_type_id (store_proto),
2071 modest_protocol_get_display_name (store_proto));
2072 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2075 modest_security_options_view_save_settings (
2076 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2080 /* now we store the common transport account settings */
2081 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2082 modest_server_account_settings_set_username (transport_settings, username);
2083 modest_server_account_settings_set_password (transport_settings, password);
2084 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2086 g_object_unref (transport_settings);
2087 g_free (transport_hostname);
2089 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2090 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2091 modest_account_settings_set_fullname (priv->settings, fullname);
2092 modest_account_settings_set_email_address (priv->settings, email_address);
2093 /* we don't set retrieve type to preserve advanced settings if
2094 any. By default account settings are set to headers only */
2096 /* Save the connection-specific SMTP server accounts. */
2097 if (priv->checkbox_outgoing_smtp_specific) {
2098 modest_account_settings_set_use_connection_specific_smtp
2100 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2103 display_name = get_entered_account_title (self);
2104 modest_account_settings_set_display_name (priv->settings, display_name);
2105 g_free (display_name);
2106 g_free (provider_id);
2111 on_update_model (ModestWizardDialog *dialog)
2113 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2114 save_to_settings (self);
2119 on_save (ModestWizardDialog *dialog)
2121 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2122 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2124 save_to_settings (self);
2126 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2127 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2131 return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2137 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2139 GError *error = NULL;
2140 ModestProtocolType protocol_type;
2141 const gchar* hostname;
2142 const gchar* username;
2143 ModestProtocolType security_protocol_incoming_type;
2144 ModestProtocolRegistry *registry;
2146 GList *list_auth_methods;
2147 ModestEasysetupWizardDialogPrivate *priv;
2149 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2150 registry = modest_runtime_get_protocol_registry ();
2151 protocol_type = modest_servertype_picker_get_active_servertype (
2152 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2153 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2154 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2155 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2156 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2157 port_num = get_port_from_protocol(protocol_type, FALSE);
2158 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2159 username, GTK_WINDOW (self), &error);
2161 if (list_auth_methods) {
2162 /* TODO: Select the correct method */
2165 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2166 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2167 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2168 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2169 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2173 g_list_free(list_auth_methods);
2179 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2180 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2182 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2183 _("mcen_ib_unableto_discover_auth_methods"));
2187 g_error_free(error);
2193 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2195 GList* methods = check_for_supported_auth_methods(self);
2201 g_list_free(methods);