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"
62 #include "modest-address-book.h"
64 /* Include config.h so that _() works: */
69 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
71 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
72 MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
73 ModestEasysetupWizardDialogPrivate))
75 #define LABELS_WIDTH 520
76 #define DIALOG_WIDTH LABELS_WIDTH + MODEST_MARGIN_DOUBLE
78 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
82 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
83 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
84 } ModestEasysetupWizardDialogServerChanges;
86 struct _ModestEasysetupWizardDialogPrivate
88 ModestPresets *presets;
90 /* Remember what fields the user edited manually to not prefill them
92 ModestEasysetupWizardDialogServerChanges server_changes;
94 /* Check if the user changes a field to show a confirmation dialog */
97 /* If we have a pending load of settings or not. */
98 gboolean pending_load_settings;
100 /* Used by derived widgets to query existing accounts,
101 * and to create new accounts: */
102 ModestAccountMgr *account_manager;
103 ModestAccountSettings *settings;
105 /* notebook pages: */
106 GtkWidget *page_welcome;
107 gboolean check_support_done;
108 guint check_support_show_progress_id;
109 gint pending_check_support;
112 GtkWidget *page_account_details;
113 GtkWidget *account_country_picker;
114 GtkWidget *account_serviceprovider_picker;
115 GtkWidget *entry_account_title;
116 GtkWidget *caption_account_title;
118 GtkWidget *page_user_details;
119 GtkWidget *entry_user_name;
120 GtkWidget *entry_user_username;
121 GtkWidget *entry_user_password;
122 GtkWidget *entry_user_email;
124 GtkWidget *page_complete_easysetup;
126 GtkWidget *page_custom_incoming;
127 GtkWidget *incoming_servertype_picker;
128 GtkWidget *caption_incoming;
129 GtkWidget *entry_incomingserver;
131 /* Security widgets */
132 GtkWidget *incoming_security;
133 GtkWidget *outgoing_security;
135 GtkWidget *page_custom_outgoing;
136 GtkWidget *entry_outgoingserver;
137 GtkWidget *checkbox_outgoing_smtp_specific;
138 GtkWidget *button_outgoing_smtp_servers;
140 GtkWidget *page_complete_customsetup;
142 ModestProtocolType last_plugin_protocol_selected;
143 GSList *missing_data_signals;
146 static void save_to_settings (ModestEasysetupWizardDialog *self);
147 static void real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next);
148 static void on_update_model (ModestWizardDialog *dialog);
149 static gboolean on_save (ModestWizardDialog *dialog);
150 static GList* check_for_supported_auth_methods (ModestEasysetupWizardDialog* self);
151 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self);
152 static void check_support_callback (ModestAccountProtocol *protocol,
155 static void check_support_of_protocols (ModestEasysetupWizardDialog *self);
156 static gboolean check_support_show_progress (gpointer userdata);
159 on_delete_event (GtkWidget *widget,
161 ModestEasysetupWizardDialog *wizard)
163 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
168 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
170 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
171 g_return_if_fail (priv != NULL);
176 modest_easysetup_wizard_dialog_dispose (GObject *object)
178 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (object);
179 priv->destroyed = TRUE;
181 if (priv->check_support_show_progress_id > 0) {
182 g_source_remove (priv->check_support_show_progress_id);
183 priv->check_support_show_progress_id = 0;
186 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
187 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
191 modest_easysetup_wizard_dialog_finalize (GObject *object)
193 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
194 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
196 if (priv->account_manager)
197 g_object_unref (G_OBJECT (priv->account_manager));
200 modest_presets_destroy (priv->presets);
203 g_object_unref (priv->settings);
205 if (priv->missing_data_signals) {
206 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
207 priv->missing_data_signals = NULL;
210 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
214 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
217 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
219 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
222 get_port_from_protocol (ModestProtocolType server_type,
223 gboolean alternate_port)
226 ModestProtocol *protocol;
227 ModestProtocolRegistry *protocol_registry;
229 protocol_registry = modest_runtime_get_protocol_registry ();
230 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
232 if (alternate_port) {
233 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
235 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
241 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
243 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
245 /* Call the vfunc, which may be overridden by derived classes: */
246 if (klass->enable_buttons) {
247 GtkNotebook *notebook = NULL;
248 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
250 const gint current_page_num = gtk_notebook_get_current_page (notebook);
251 if (current_page_num == -1)
254 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
255 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
260 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
262 ModestEasysetupWizardDialog *self;
264 g_return_if_fail (user_data);
266 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
268 invoke_enable_buttons_vfunc(self);
272 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
274 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
276 invoke_enable_buttons_vfunc(self);
280 on_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
282 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
284 invoke_enable_buttons_vfunc(self);
288 on_serviceprovider_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
290 gchar* default_account_name_start;
291 gchar* default_account_name;
292 ModestEasysetupWizardDialog *self;
293 ModestEasysetupWizardDialogPrivate *priv;
294 ModestProviderPickerIdType provider_id_type;
295 ModestProtocol *protocol;
297 ModestProtocolType proto_type;
298 gboolean hide_account_title;
300 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
301 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
303 on_picker_button_value_changed (widget, user_data);
305 provider_id_type = modest_provider_picker_get_active_id_type (
306 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
307 if (provider_id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
308 default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
312 selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (widget)));
313 default_account_name_start =
314 g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
317 default_account_name = modest_account_mgr_get_unused_account_display_name (
318 priv->account_manager, default_account_name_start);
319 g_free (default_account_name_start);
320 default_account_name_start = NULL;
322 hide_account_title = FALSE;
323 proto_name = modest_provider_picker_get_active_provider_id (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
324 if (proto_name != NULL) {
325 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
326 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
328 if (protocol != NULL) {
329 proto_type = modest_protocol_get_type_id (protocol);
331 hide_account_title = (modest_protocol_registry_protocol_type_has_tag
332 (modest_runtime_get_protocol_registry (),
334 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS) ||
335 modest_protocol_registry_protocol_type_has_tag
336 (modest_runtime_get_protocol_registry (),
338 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS));
342 if (hide_account_title)
343 gtk_widget_hide (priv->caption_account_title);
345 gtk_widget_show (priv->caption_account_title);
347 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
348 g_free (default_account_name);
351 /** This is a convenience function to create a caption containing a mandatory widget.
352 * When the widget is edited, the enable_buttons() vfunc will be called.
355 create_captioned (ModestEasysetupWizardDialog *self,
356 GtkSizeGroup *title_size_group,
357 GtkSizeGroup *value_size_group,
364 result = modest_maemo_utils_create_captioned_with_size_type (title_size_group, value_size_group,
365 value, use_markup, control,
366 MODEST_EDITABLE_SIZE);
368 /* Connect to the appropriate changed signal for the widget,
369 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
371 if (GTK_IS_ENTRY (control)) {
372 g_signal_connect (G_OBJECT (control), "changed",
373 G_CALLBACK (on_caption_entry_changed), self);
376 else if (GTK_IS_COMBO_BOX (control)) {
377 g_signal_connect (G_OBJECT (control), "changed",
378 G_CALLBACK (on_caption_combobox_changed), self);
385 create_page_welcome (ModestEasysetupWizardDialog *self)
390 GtkWidget *privacy_note;
392 ModestEasysetupWizardDialogPrivate *priv;
394 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
395 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
396 pannable = hildon_pannable_area_new ();
397 label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
398 privacy_note = gtk_label_new (_("mcen_ia_privacy_notice"));
399 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
400 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
401 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
402 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
403 gtk_widget_set_size_request (privacy_note, LABELS_WIDTH, -1);
404 gtk_label_set_line_wrap (GTK_LABEL (privacy_note), TRUE);
405 /* So that it is not truncated: */
406 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
407 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
408 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
409 gtk_box_pack_start (GTK_BOX (box), privacy_note, FALSE, FALSE, 0);
410 gtk_container_add (GTK_CONTAINER (align), box);
411 gtk_widget_show (label);
412 gtk_widget_show (privacy_note);
414 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
415 gtk_widget_show (GTK_WIDGET (box));
416 gtk_widget_show (GTK_WIDGET (align));
417 gtk_widget_show (pannable);
419 return GTK_WIDGET (pannable);
423 on_account_country_selector_changed (HildonTouchSelector *widget, gpointer user_data)
425 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
427 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
431 /* Fill the providers picker, based on the selected country: */
432 if (priv->presets != NULL) {
433 gint mcc = modest_country_picker_get_active_country_mcc (
434 MODEST_COUNTRY_PICKER (priv->account_country_picker));
435 modest_provider_picker_fill (
436 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
441 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
443 ModestEasysetupWizardDialogPrivate *priv;
444 gchar* provider_id = NULL, *with_at = NULL;
447 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
449 /* Fill the providers combo, based on the selected country: */
450 provider_id = modest_provider_picker_get_active_provider_id (
451 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
454 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
455 with_at = g_strdup_printf ("%c%s", '@', domain_name);
456 g_free (domain_name);
459 /* The sample address already contains the '@' */
461 with_at = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
463 if (priv->entry_user_email)
464 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), with_at);
467 g_free (provider_id);
471 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
473 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
475 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
479 update_user_email_from_provider (self);
483 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
485 modest_platform_information_banner (GTK_WIDGET (self), NULL,
486 _CS("ckdg_ib_maximum_characters_reached"));
490 create_page_account_details (ModestEasysetupWizardDialog *self)
493 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
494 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
495 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
497 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
498 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
499 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
500 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
501 gtk_widget_show (label);
503 /* Create a size group to be used by all captions.
504 * Note that HildonCaption does not create a default size group if we do not specify one.
505 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
506 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
507 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
509 /* The country widgets: */
510 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
511 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
512 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
513 _("mcen_fi_country"), priv->account_country_picker);
514 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
515 G_CALLBACK (on_picker_button_value_changed), self);
516 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
517 gtk_widget_show (priv->account_country_picker);
519 /* The service provider widgets: */
520 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
521 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
522 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
523 _("mcen_fi_serviceprovider"),
524 priv->account_serviceprovider_picker);
525 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
526 G_CALLBACK (on_serviceprovider_picker_button_value_changed), self);
527 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, 0);
528 gtk_widget_show (priv->account_serviceprovider_picker);
530 /* The description widgets: */
531 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
533 /* Do use auto-capitalization: */
534 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
535 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
537 /* Set a default account title, choosing one that does not already exist: */
538 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
539 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
540 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
541 priv->account_manager, default_account_name_start);
542 g_free (default_account_name_start);
543 default_account_name_start = NULL;
545 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
546 g_free (default_account_name);
547 default_account_name = NULL;
549 /* Connect signal after changing the text in the entry */
550 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
551 G_CALLBACK(on_easysetup_changed), self);
553 priv->caption_account_title = create_captioned (self, title_sizegroup, value_sizegroup,
554 _("mcen_fi_account_title"), FALSE,
555 priv->entry_account_title);
556 gtk_widget_show (priv->entry_account_title);
557 gtk_box_pack_start (GTK_BOX (box), priv->caption_account_title, FALSE, FALSE, 0);
558 gtk_widget_show (priv->caption_account_title);
559 gtk_widget_set_no_show_all (priv->caption_account_title, TRUE);
561 /* Prevent the use of some characters in the account title,
562 * as required by our UI specification: */
563 GList *list_prevent = NULL;
564 list_prevent = g_list_append (list_prevent, "\\");
565 list_prevent = g_list_append (list_prevent, "/");
566 list_prevent = g_list_append (list_prevent, ":");
567 list_prevent = g_list_append (list_prevent, "*");
568 list_prevent = g_list_append (list_prevent, "?");
569 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
570 list_prevent = g_list_append (list_prevent, "“");
571 list_prevent = g_list_append (list_prevent, "<");
572 list_prevent = g_list_append (list_prevent, ">");
573 list_prevent = g_list_append (list_prevent, "|");
574 list_prevent = g_list_append (list_prevent, "^");
575 modest_validating_entry_set_unallowed_characters (
576 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
577 g_list_free (list_prevent);
579 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
580 modest_utils_on_entry_invalid_character, self);
582 /* Set max length as in the UI spec:
583 * The UI spec seems to want us to show a dialog if we hit the maximum. */
584 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
585 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
588 gtk_widget_show (GTK_WIDGET (box));
590 g_object_unref (title_sizegroup);
591 g_object_unref (value_sizegroup);
593 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
594 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
595 gtk_widget_show (align);
596 gtk_container_add (GTK_CONTAINER (align), box);
598 return GTK_WIDGET (align);
602 on_user_username_changed(GtkWidget* widget, ModestEasysetupWizardDialog *self)
604 ModestEasysetupWizardDialogPrivate* priv;
605 gchar* provider_id = NULL;
607 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
609 /* Work out the user email address */
610 provider_id = modest_provider_picker_get_active_provider_id (
611 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
614 const gchar *current_username;
615 gchar *email_address;
616 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
618 current_username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
620 if (current_username && strstr (current_username, "@")) {
621 email_address = g_strdup (current_username);
623 email_address = g_strdup_printf ("%s@%s",
628 /* Update the email address */
629 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), email_address);
631 g_free (email_address);
632 g_free (domain_name);
633 g_free (provider_id);
637 on_easysetup_changed(widget, self);
642 create_page_user_details (ModestEasysetupWizardDialog *self)
644 GtkSizeGroup* title_sizegroup;
645 GtkSizeGroup* value_sizegroup;
647 ModestEasysetupWizardDialogPrivate *priv;
649 const gchar *my_name;
651 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
653 /* Create a size group to be used by all captions.
654 * Note that HildonCaption does not create a default size group if we do not specify one.
655 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
656 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
657 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
658 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
660 /* The name widgets: (use auto cap) */
661 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
662 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
663 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
665 /* Set max length as in the UI spec:
666 * The UI spec seems to want us to show a dialog if we hit the maximum. */
667 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
668 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
670 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
671 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
673 /* Try to initialize the user name with my own contact */
674 my_name = modest_address_book_get_my_name ();
676 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_name), my_name);
678 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
679 G_CALLBACK(on_easysetup_changed), self);
680 gtk_widget_show (priv->entry_user_name);
681 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
682 gtk_widget_show (caption);
684 /* Prevent the use of some characters in the name,
685 * as required by our UI specification: */
686 GList *list_prevent = NULL;
687 list_prevent = g_list_append (list_prevent, "<");
688 list_prevent = g_list_append (list_prevent, ">");
689 modest_validating_entry_set_unallowed_characters (
690 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
691 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
692 modest_utils_on_entry_invalid_character, self);
693 g_list_free (list_prevent);
695 /* The username widgets: */
696 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
697 /* Auto-capitalization is the default, so let's turn it off: */
698 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
699 HILDON_GTK_INPUT_MODE_FULL);
700 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
701 priv->entry_user_username);
702 gtk_widget_show (priv->entry_user_username);
703 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
704 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
705 G_CALLBACK(on_user_username_changed), self);
706 gtk_widget_show (caption);
708 /* Prevent the use of some characters in the username,
709 * as required by our UI specification: */
710 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
711 modest_utils_on_entry_invalid_character, self);
713 /* Set max length as in the UI spec:
714 * The UI spec seems to want us to show a dialog if we hit the maximum. */
715 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
716 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
719 /* The password widgets: */
720 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
721 /* Auto-capitalization is the default, so let's turn it off: */
722 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
723 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
724 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
725 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
726 caption = create_captioned (self, title_sizegroup, value_sizegroup,
727 _("mail_fi_password"), FALSE, priv->entry_user_password);
728 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
729 G_CALLBACK(on_easysetup_changed), self);
730 gtk_widget_show (priv->entry_user_password);
731 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
732 gtk_widget_show (caption);
734 /* The email address widgets: */
735 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
736 /* Auto-capitalization is the default, so let's turn it off: */
737 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
738 caption = create_captioned (self, title_sizegroup, value_sizegroup,
739 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
740 update_user_email_from_provider (self);
741 gtk_widget_show (priv->entry_user_email);
742 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
743 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
744 G_CALLBACK(on_easysetup_changed), self);
745 gtk_widget_show (caption);
747 /* Set max length as in the UI spec:
748 * The UI spec seems to want us to show a dialog if we hit the maximum. */
749 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
750 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
754 gtk_widget_show (GTK_WIDGET (box));
755 g_object_unref (title_sizegroup);
756 g_object_unref (value_sizegroup);
758 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
759 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
760 gtk_widget_show (align);
761 gtk_container_add (GTK_CONTAINER (align), box);
763 return GTK_WIDGET (align);
767 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
770 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
772 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
773 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
774 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
775 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
776 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
778 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
779 gtk_widget_show (label);
781 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
782 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
783 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
785 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
786 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
787 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
788 gtk_widget_show (label);
790 gtk_widget_show (GTK_WIDGET (box));
792 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
793 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
794 gtk_widget_show (align);
795 gtk_container_add (GTK_CONTAINER (align), box);
797 return GTK_WIDGET (align);
800 /** Change the caption title for the incoming server,
801 * as specified in the UI spec:
804 update_incoming_server_title (ModestEasysetupWizardDialog *self)
806 ModestEasysetupWizardDialogPrivate* priv;
807 ModestProtocolType protocol_type;
808 ModestProtocolRegistry *protocol_registry;
810 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
811 protocol_registry = modest_runtime_get_protocol_registry ();
813 protocol_type = modest_servertype_picker_get_active_servertype (
814 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
816 /* This could happen when the combo box has still no active iter */
817 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
818 gchar* incomingserver_title;
819 const gchar *protocol_display_name;
820 ModestProtocol *protocol;
822 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
824 protocol_display_name = modest_protocol_get_display_name (protocol);
826 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
827 protocol_display_name, ")</small>", NULL);
829 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
831 g_free(incomingserver_title);
835 /** Change the caption title for the incoming server,
836 * as specified in the UI spec:
839 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
841 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
842 ModestServertypePicker *server_type_picker;
843 ModestProtocolType protocol_type;
844 ModestSecurityOptionsView *view;
847 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
849 modest_servertype_picker_get_active_servertype (server_type_picker);
851 /* Fill the combo with appropriately titled choices for all
853 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
854 modest_security_options_view_set_server_type (view, protocol_type);
858 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
860 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
861 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
866 update_incoming_server_title (self);
868 /* Update security options if needed */
869 update_incoming_server_security_choices (self);
870 gtk_widget_show (priv->incoming_security);
872 set_default_custom_servernames (self);
876 on_entry_incoming_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);
881 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
885 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
887 ModestProtocolRegistry *protocol_registry;
888 ModestEasysetupWizardDialogPrivate* priv;
893 GtkSizeGroup *title_sizegroup;
894 GtkSizeGroup *value_sizegroup;
896 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
897 protocol_registry = modest_runtime_get_protocol_registry ();
899 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
900 pannable = hildon_pannable_area_new ();
902 /* Show note that account type cannot be changed in future: */
903 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
904 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
905 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
906 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
907 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
908 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
909 gtk_widget_show (label);
911 /* Create a size group to be used by all captions.
912 * Note that HildonCaption does not create a default size group if we do not specify one.
913 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
914 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
915 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
917 /* The incoming server widgets: */
918 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
919 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
921 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
922 _("mcen_li_emailsetup_type"),
923 priv->incoming_servertype_picker);
924 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
925 G_CALLBACK (on_picker_button_value_changed), self);
926 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, 0);
927 gtk_widget_show (priv->incoming_servertype_picker);
929 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
931 /* Auto-capitalization is the default, so let's turn it off: */
932 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
933 set_default_custom_servernames (self);
935 /* The caption title will be updated in update_incoming_server_title().
936 * so this default text will never be seen: */
937 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
938 "This will be removed",
939 FALSE, priv->entry_incomingserver);
940 update_incoming_server_title (self);
941 gtk_widget_show (priv->entry_incomingserver);
942 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
943 gtk_widget_show (priv->caption_incoming);
945 /* Remember when the servername was changed manually: */
946 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
947 G_CALLBACK (on_entry_incoming_servername_changed), self);
949 /* The secure connection widgets. These are only valid for
950 protocols with security */
951 priv->incoming_security =
952 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
953 FALSE, title_sizegroup, value_sizegroup);
954 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
956 gtk_widget_show (priv->incoming_security);
958 /* Set default selection */
959 modest_servertype_picker_set_active_servertype (
960 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
961 MODEST_PROTOCOLS_STORE_POP);
962 update_incoming_server_title (self);
963 update_incoming_server_security_choices (self);
964 set_default_custom_servernames (self);
966 /* Change the caption title when the servertype changes,
967 * as in the UI spec: */
968 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
970 G_CALLBACK (on_servertype_selector_changed), self);
972 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
973 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
974 gtk_widget_show (align);
975 gtk_container_add (GTK_CONTAINER (align), box);
977 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
978 gtk_widget_show (GTK_WIDGET (box));
979 gtk_widget_show (pannable);
981 g_object_unref (title_sizegroup);
982 g_object_unref (value_sizegroup);
984 /* Connect changed signals. We do it here after initializing everything */
985 g_signal_connect (G_OBJECT(priv->entry_incomingserver), "changed",
986 G_CALLBACK(on_easysetup_changed), self);
989 return GTK_WIDGET (pannable);
993 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
995 GtkWidget *widget = GTK_WIDGET (user_data);
997 /* Enable the widget only if the check button is active: */
998 const gboolean enable = hildon_check_button_get_active (button);
999 gtk_widget_set_sensitive (widget, enable);
1002 /* Make the sensitivity of a widget depend on a check button.
1005 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
1007 g_signal_connect (G_OBJECT (button), "toggled",
1008 G_CALLBACK (on_check_button_changed), widget);
1010 /* Set the starting sensitivity: */
1011 on_check_button_changed (button, widget);
1015 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
1017 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1018 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1019 GtkWidget *specific_window;
1021 /* We set dirty here because setting it depending on the connection specific dialog
1025 /* Create the window, if necessary: */
1026 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
1027 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
1029 /* Show the window */
1030 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
1031 gtk_widget_show (specific_window);
1035 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
1037 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1038 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1039 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
1043 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
1045 ModestEasysetupWizardDialogPrivate *priv;
1046 gchar *smtp_caption_label;
1047 GtkWidget *pannable;
1049 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1051 pannable = hildon_pannable_area_new ();
1053 /* Create a size group to be used by all captions.
1054 * Note that HildonCaption does not create a default size group if we do not specify one.
1055 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1056 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1057 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1059 /* The outgoing server widgets: */
1060 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1061 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
1063 /* Auto-capitalization is the default, so let's turn it off: */
1064 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
1065 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
1066 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
1067 smtp_caption_label, TRUE, priv->entry_outgoingserver);
1068 g_free (smtp_caption_label);
1069 gtk_widget_show (priv->entry_outgoingserver);
1070 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
1071 gtk_widget_show (caption);
1072 set_default_custom_servernames (self);
1074 /* The secure connection widgets. These are only valid for
1075 protocols with security */
1076 priv->outgoing_security =
1077 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
1078 FALSE, title_sizegroup, value_sizegroup);
1079 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
1081 gtk_widget_show (priv->outgoing_security);
1083 GtkWidget *separator = gtk_hseparator_new ();
1084 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
1085 gtk_widget_show (separator);
1087 /* connection-specific checkbox: */
1088 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
1089 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1091 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1092 _("mcen_fi_advsetup_connection_smtp"));
1093 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1096 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1097 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
1100 /* Connection-specific SMTP-Severs Edit button: */
1101 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
1102 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
1103 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1104 gtk_widget_show (priv->button_outgoing_smtp_servers);
1105 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
1108 /* Only enable the button when the checkbox is checked: */
1109 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
1110 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
1112 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1113 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1115 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1116 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1119 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1120 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1121 gtk_widget_show (align);
1122 gtk_container_add (GTK_CONTAINER (align), box);
1124 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
1125 gtk_widget_show (GTK_WIDGET (box));
1126 gtk_widget_show (pannable);
1128 g_object_unref (title_sizegroup);
1129 g_object_unref (value_sizegroup);
1131 /* Connect changed signals. We do it here after initializing everything */
1132 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1133 G_CALLBACK (on_easysetup_changed), self);
1134 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1135 G_CALLBACK (on_easysetup_changed), self);
1137 return GTK_WIDGET (pannable);
1141 show_advanced_edit(gpointer user_data)
1143 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1144 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1147 /* Show the Account Settings window: */
1148 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
1149 if (priv->pending_load_settings) {
1150 save_to_settings (self);
1151 priv->pending_load_settings = FALSE;
1153 modest_account_settings_dialog_load_settings (dialog, priv->settings);
1155 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
1157 response = gtk_dialog_run (GTK_DIALOG (dialog));
1159 gtk_widget_destroy (GTK_WIDGET (dialog));
1161 return FALSE; /* Do not call this timeout callback again. */
1165 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1167 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1169 /* Show the Account Settings window: */
1170 show_advanced_edit(self);
1173 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1175 gchar *complete_string;
1179 GtkWidget *button_edit;
1181 box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1182 complete_string = g_strconcat (_("mcen_ia_emailsetup_setup_complete"), " ",
1183 _("mcen_ia_customsetup_complete"), NULL);
1184 label = gtk_label_new(complete_string);
1185 g_free (complete_string);
1186 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1187 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1188 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1189 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1190 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1191 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1192 gtk_widget_show (label);
1194 button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1195 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1196 gtk_widget_show (button_edit);
1197 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, 0);
1199 g_signal_connect (G_OBJECT (button_edit), "clicked",
1200 G_CALLBACK (on_button_edit_advanced_settings), self);
1202 gtk_widget_show (GTK_WIDGET (box));
1204 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1205 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
1206 gtk_widget_show (align);
1207 gtk_container_add (GTK_CONTAINER (align), box);
1209 return GTK_WIDGET (align);
1216 on_response (ModestWizardDialog *wizard_dialog,
1220 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1222 invoke_enable_buttons_vfunc (self);
1226 on_response_before (ModestWizardDialog *wizard_dialog,
1230 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1231 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1232 if (response_id == GTK_RESPONSE_CANCEL) {
1233 /* This is mostly copied from
1234 * src/maemo/modest-account-settings-dialog.c */
1236 gint dialog_response;
1239 dialog = hildon_note_new_confirmation ((GtkWindow *) self,
1240 _("imum_nc_wizard_confirm_lose_changes"));
1242 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
1243 (GtkWindow *) dialog,
1244 (GtkWindow *) wizard_dialog);
1246 dialog_response = gtk_dialog_run ((GtkDialog *) dialog);
1247 gtk_widget_destroy (GTK_WIDGET (dialog));
1249 if (dialog_response != GTK_RESPONSE_OK) {
1250 /* Don't let the dialog close */
1251 g_signal_stop_emission_by_name (wizard_dialog, "response");
1258 fill_providers (ModestEasysetupWizardDialog *self)
1260 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1262 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1263 /* gint mcc = get_default_country_code(); */
1265 /* Fill the combo in an idle call, as it takes a lot of time */
1266 modest_country_picker_load_data(
1267 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1268 /* connect to country picker's changed signal, so we can fill the provider picker: */
1269 g_signal_connect ((GObject *) priv->account_country_picker,
1271 G_CALLBACK (on_account_country_selector_changed), self);
1273 modest_country_picker_set_active_country_locale (
1274 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1275 mcc = modest_country_picker_get_active_country_mcc (
1276 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1277 modest_provider_picker_fill (
1278 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1279 priv->presets, mcc);
1280 /* connect to providers picker's changed signal, so we can fill the email address: */
1281 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1282 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1284 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1286 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1289 priv->dirty = FALSE;
1293 typedef struct IdleData {
1294 ModestEasysetupWizardDialog *dialog;
1295 ModestPresets *presets;
1299 presets_idle (gpointer userdata)
1301 IdleData *idle_data = (IdleData *) userdata;
1302 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1303 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1305 g_assert (idle_data->presets);
1307 gdk_threads_enter ();
1309 priv->presets = idle_data->presets;
1311 if (priv->check_support_done)
1312 fill_providers (self);
1314 g_object_unref (idle_data->dialog);
1317 gdk_threads_leave ();
1323 presets_loader (gpointer userdata)
1325 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1326 ModestPresets *presets = NULL;
1327 IdleData *idle_data;
1329 const gchar* path = NULL;
1330 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1331 const gchar* path2 = MODEST_FALLBACK_PROVIDER_DATA_FILE;
1333 if (access(path1, R_OK) == 0)
1335 else if (access(path2, R_OK) == 0)
1338 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1339 __FUNCTION__, path1, path2);
1343 presets = modest_presets_new (path);
1345 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1349 idle_data = g_new0 (IdleData, 1);
1350 idle_data->dialog = self;
1351 idle_data->presets = presets;
1353 g_idle_add (presets_idle, idle_data);
1359 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1365 /* Append page and set attributes */
1366 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1367 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1368 "tab-expand", TRUE, "tab-fill", TRUE,
1371 /* Give focus to page and show it */
1372 gtk_container_set_focus_child (GTK_CONTAINER (notebook), page);
1373 gtk_widget_show (page);
1377 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1379 priv->page_user_details = NULL;
1380 priv->entry_user_name = NULL;
1381 priv->entry_user_username = NULL;
1382 priv->entry_user_password = NULL;
1383 priv->entry_user_email = NULL;
1387 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1389 priv->page_custom_incoming = NULL;
1390 priv->incoming_servertype_picker = NULL;
1391 priv->caption_incoming = NULL;
1392 priv->entry_incomingserver = NULL;
1393 priv->entry_user_email = NULL;
1394 priv->incoming_security = NULL;
1398 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1400 priv->page_custom_outgoing = NULL;
1401 priv->entry_outgoingserver = NULL;
1402 priv->checkbox_outgoing_smtp_specific = NULL;
1403 priv->button_outgoing_smtp_servers = NULL;
1404 priv->outgoing_security = NULL;
1408 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1410 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1412 /* Create the notebook to be used by the ModestWizardDialog base class:
1413 * Each page of the notebook will be a page of the wizard: */
1414 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1415 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1417 /* Set the notebook used by the ModestWizardDialog base class: */
1418 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1420 /* Set the wizard title:
1421 * The actual window title will be a combination of this and the page's tab label title. */
1422 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1424 /* Read in the information about known service providers: */
1425 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1427 /* The server fields did not have been manually changed yet */
1428 priv->server_changes = 0;
1429 priv->pending_load_settings = TRUE;
1431 /* Get the account manager object,
1432 * so we can check for existing accounts,
1433 * and create new accounts: */
1434 priv->account_manager = modest_runtime_get_account_mgr ();
1435 g_object_ref (priv->account_manager);
1437 /* Initialize fields */
1438 priv->check_support_done = FALSE;
1439 priv->check_support_show_progress_id = 0;
1440 priv->pending_check_support = 0;
1441 priv->destroyed = FALSE;
1442 priv->page_welcome = create_page_welcome (self);
1443 gtk_widget_show (priv->page_welcome);
1444 priv->page_account_details = create_page_account_details (self);
1446 init_user_page (priv);
1447 init_incoming_page (priv);
1448 init_outgoing_page (priv);
1450 priv->page_complete_easysetup = NULL;
1451 priv->page_complete_customsetup = NULL;
1452 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1453 priv->missing_data_signals = NULL;
1455 /* Add the common pages */
1456 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1457 _("mcen_ti_emailsetup_welcome"));
1458 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1459 _("mcen_ti_accountdetails"));
1461 /* Connect to the dialog's response signal so we can enable/disable buttons
1462 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1463 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1464 * so that we can be enable/disable after ModestWizardDialog has done its own
1465 * enabling/disabling of buttons.
1467 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1468 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1470 * It's not enough to connect to the notebook's switch-page signal, because
1471 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1472 * _after_ switching the page (understandably).
1473 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1474 * then gtk_notebook_get_current_page() would return an incorrect value.)
1476 g_signal_connect_after (G_OBJECT (self), "response",
1477 G_CALLBACK (on_response), self);
1479 /* This is to show a confirmation dialog when the user hits cancel */
1480 g_signal_connect (G_OBJECT (self), "response",
1481 G_CALLBACK (on_response_before), self);
1483 g_signal_connect (G_OBJECT (self), "delete-event",
1484 G_CALLBACK (on_delete_event), self);
1486 /* Reset dirty, because there was no user input until now */
1487 priv->dirty = FALSE;
1489 /* When this window is shown, hibernation should not be possible,
1490 * because there is no sensible way to save the state: */
1491 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1492 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1494 /* Load provider presets */
1495 g_object_ref (self);
1496 g_thread_create (presets_loader, self, FALSE, NULL);
1498 priv->settings = modest_account_settings_new ();
1502 ModestEasysetupWizardDialog*
1503 modest_easysetup_wizard_dialog_new (void)
1506 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1510 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1512 ModestEasysetupWizardDialogPrivate *priv;
1513 GtkNotebook *notebook = NULL;
1515 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1518 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1520 if (!priv->page_user_details) {
1521 priv->page_user_details = create_page_user_details (self);
1524 /* Create the custom pages: */
1525 if(!(priv->page_custom_incoming)) {
1526 priv->page_custom_incoming = create_page_custom_incoming (self);
1529 /* TODO: only if needed */
1530 if(!(priv->page_custom_outgoing)) {
1531 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1534 if(!(priv->page_complete_customsetup)) {
1535 priv->page_complete_customsetup = create_page_complete_custom (self);
1538 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1539 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1540 _("mcen_ti_emailsetup_userdetails"));
1542 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1543 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1544 _("mcen_ti_emailsetup_incomingdetails"));
1546 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1547 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1548 _("mcen_ti_emailsetup_outgoingdetails"));
1550 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1551 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1552 _("mcen_ti_emailsetup_complete"));
1554 /* This is unnecessary with GTK+ 2.10: */
1555 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1559 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1561 ModestEasysetupWizardDialogPrivate *priv;
1562 GtkNotebook *notebook = NULL;
1564 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1567 /* Create the easysetup-specific pages: */
1568 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1569 if(!priv->page_complete_easysetup)
1570 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1572 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1573 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1574 _("mcen_ti_emailsetup_complete"));
1576 /* This is unnecessary with GTK+ 2.10: */
1577 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1582 remove_non_common_tabs (ModestEasysetupWizardDialog *self,
1583 gboolean remove_user_details)
1586 GtkNotebook *notebook;
1587 ModestEasysetupWizardDialogPrivate *priv;
1589 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1590 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1592 /* The first 2 tabs are the common ones (welcome tab and the
1593 providers tab), so we always remove starting from the
1595 starting_tab = (remove_user_details) ? 2 : 3;
1596 while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
1597 /* Disconnect signal */
1598 GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
1599 if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
1600 priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
1602 "missing-mandatory-data");
1604 /* Remove page from notebook */
1605 gtk_notebook_remove_page (notebook, -1);
1610 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1614 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1617 /* After the user details page,
1618 * the following pages depend on whether "Other" was chosen
1619 * in the provider combobox on the account page
1622 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1624 ModestEasysetupWizardDialogPrivate *priv;
1625 ModestProviderPicker *picker;
1626 ModestProviderPickerIdType id_type;
1627 GtkNotebook *notebook;
1629 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1630 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1631 id_type = modest_provider_picker_get_active_id_type (picker);
1632 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1634 /* Remove the response override handler for non-plugin
1635 protocols. For plugins it'll be overriden later */
1636 if (id_type != MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL)
1637 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1641 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1642 /* "Other..." was selected: */
1644 /* If we come from a rollbacked easysetup */
1645 if (priv->page_complete_easysetup) {
1646 remove_non_common_tabs (self, FALSE);
1647 priv->page_complete_easysetup = NULL;
1650 /* If we come from a rollbacked plugin protocol setup */
1651 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1652 remove_non_common_tabs (self, TRUE);
1653 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1654 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1655 priv->missing_data_signals = NULL;
1658 create_subsequent_customsetup_pages (self);
1660 /* If we come from a rollbacked custom setup */
1661 if (priv->page_custom_incoming) {
1662 remove_non_common_tabs (self, TRUE);
1663 init_user_page (priv);
1664 init_incoming_page (priv);
1665 init_outgoing_page (priv);
1666 init_user_page (priv);
1667 priv->page_complete_customsetup = NULL;
1670 /* It's a pluggable protocol and not a provider with presets */
1671 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1672 ModestProtocol *protocol;
1674 ModestProtocolType proto_type;
1675 ModestWizardDialogResponseOverrideFunc response_override;
1677 /* Get protocol data */
1678 proto_name = modest_provider_picker_get_active_provider_id (picker);
1679 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1680 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1682 proto_type = modest_protocol_get_type_id (protocol);
1685 /* If we come from a rollbacked easy setup */
1686 if (priv->last_plugin_protocol_selected != proto_type &&
1687 priv->page_complete_easysetup) {
1688 remove_non_common_tabs (self, TRUE);
1689 init_user_page (priv);
1690 priv->page_complete_easysetup = NULL;
1693 /* Ensure that the response override handler
1694 is set. It might happen that plugins clear
1696 response_override = modest_account_protocol_get_wizard_response_override
1697 (MODEST_ACCOUNT_PROTOCOL (protocol));
1698 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1701 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1702 proto_type != priv->last_plugin_protocol_selected) {
1703 ModestPairList *tabs;
1705 gboolean first_page = TRUE;
1707 /* Remember the last selected plugin protocol */
1708 priv->last_plugin_protocol_selected = proto_type;
1711 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1712 tmp = (GSList *) tabs;
1714 ModestPair *pair = (ModestPair *) tmp->data;
1715 modest_easysetup_wizard_dialog_append_page (notebook,
1716 GTK_WIDGET (pair->second),
1717 (const gchar *) pair->first);
1719 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1720 GTK_WIDGET (pair->second));
1724 /* Connect signals */
1725 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1726 priv->missing_data_signals =
1727 modest_signal_mgr_connect (priv->missing_data_signals,
1728 G_OBJECT (pair->second),
1729 "missing-mandatory-data",
1730 G_CALLBACK (on_missing_mandatory_data),
1734 g_free (pair->first);
1735 tmp = g_slist_next (tmp);
1736 /* Critical: if you don't show the page then the dialog will ignore it */
1737 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1739 modest_pair_list_free (tabs);
1741 g_free (proto_name);
1743 if (priv->last_plugin_protocol_selected !=
1744 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1745 remove_non_common_tabs (self, TRUE);
1746 init_user_page (priv);
1747 priv->page_complete_easysetup = NULL;
1748 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1749 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1750 priv->missing_data_signals = NULL;
1752 if (!priv->page_user_details) {
1753 priv->page_user_details = create_page_user_details (self);
1754 modest_easysetup_wizard_dialog_append_page (notebook,
1755 priv->page_user_details,
1756 _("mcen_ti_emailsetup_userdetails"));
1760 /* Create the easysetup pages: */
1761 create_subsequent_easysetup_pages (self);
1767 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1769 const gchar* hostname = NULL;
1772 ModestProtocolRegistry *protocol_registry;
1773 ModestProtocol *protocol;
1778 at = g_utf8_strchr (email_address, -1, '@');
1779 if (!at || (g_utf8_strlen (at, -1) < 2))
1782 domain = g_utf8_next_char (at);
1786 protocol_registry = modest_runtime_get_protocol_registry ();
1787 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1789 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1790 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1791 hostname = modest_protocol_get_name (protocol);
1797 return g_strdup_printf ("%s.%s", hostname, domain);
1801 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1803 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1805 if (!priv->entry_incomingserver)
1808 /* Set a default domain for the server, based on the email address,
1809 * if no server name was already specified.
1811 if (priv->entry_user_email
1812 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1813 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1814 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1816 /* This could happen when the combo box has still no active iter */
1817 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1818 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1819 gchar* servername = util_get_default_servername_from_email_address (email_address,
1822 /* Do not set the INCOMING_CHANGED flag because of this edit */
1823 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1824 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1825 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1827 g_free (servername);
1831 /* Set a default domain for the server, based on the email address,
1832 * if no server name was already specified.
1834 if (!priv->entry_outgoingserver)
1837 if (priv->entry_user_email
1838 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1839 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1841 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1843 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1844 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1845 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1846 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1848 g_free (servername);
1853 get_entered_account_title (ModestEasysetupWizardDialog *self)
1855 ModestEasysetupWizardDialogPrivate *priv;
1856 const gchar* account_title;
1858 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1859 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1861 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1864 /* Strip it of whitespace at the start and end: */
1865 gchar *result = g_strdup (account_title);
1866 result = g_strstrip (result);
1871 if (g_utf8_strlen (result, -1) == 0) {
1881 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1883 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1884 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1885 ModestProtocolRegistry *protocol_registry;
1887 protocol_registry = modest_runtime_get_protocol_registry ();
1889 /* if are browsing pages previous to the last one, then we have pending settings in
1891 if (next_page != NULL)
1892 priv->pending_load_settings = TRUE;
1894 /* Do extra validation that couldn't be done for every key press,
1895 * either because it was too slow,
1896 * or because it requires interaction:
1898 if (current_page == priv->page_welcome) {
1899 if (!priv->check_support_done) {
1900 check_support_of_protocols (self);
1901 return priv->check_support_done;
1903 } else if (current_page == priv->page_account_details) {
1904 /* Check that the title is not already in use: */
1905 gchar* account_title = get_entered_account_title (self);
1909 /* Aavoid a clash with an existing display name: */
1910 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1911 priv->account_manager, account_title);
1912 g_free (account_title);
1915 /* Warn the user via a dialog: */
1916 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1921 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1922 create_subsequent_pages (self);
1924 } else if (current_page == priv->page_user_details) {
1925 /* Check that the email address is valud: */
1926 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1927 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1930 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1931 /* Warn the user via a dialog: */
1932 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1934 /* Return focus to the email address entry: */
1935 gtk_widget_grab_focus (priv->entry_user_email);
1936 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1940 } else if (current_page == priv->page_custom_incoming ||
1941 current_page == priv->page_custom_outgoing) {
1943 const gchar *hostname;
1944 GtkWidget *entry = (current_page == priv->page_custom_incoming) ?
1945 priv->entry_incomingserver :
1946 priv->entry_outgoingserver;
1948 hostname = gtk_entry_get_text (GTK_ENTRY (entry));
1949 if (!modest_text_utils_validate_domain_name (hostname)) {
1951 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
1953 /* Return focus to the email address entry: */
1954 gtk_widget_grab_focus (entry);
1955 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
1961 if (next_page == priv->page_custom_incoming) {
1962 set_default_custom_servernames (self);
1963 } else if (next_page == priv->page_custom_outgoing) {
1964 set_default_custom_servernames (self);
1966 /* Check if the server supports secure authentication */
1967 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
1968 if (!check_has_supported_auth_methods (self))
1970 gtk_widget_show (priv->outgoing_security);
1973 /* If this is the last page, and this is a click on Finish,
1974 * then attempt to create the dialog.
1977 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1979 if (priv->pending_load_settings) {
1980 save_to_settings (self);
1983 /* We check if there's already another account with the same configuration */
1984 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1985 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1989 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1996 static gboolean entry_is_empty (GtkWidget *entry)
2001 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
2002 if ((!text) || (g_utf8_strlen (text, -1) == 0))
2005 /* Strip it of whitespace at the start and end: */
2006 gchar *stripped = g_strdup (text);
2007 stripped = g_strstrip (stripped);
2012 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
2020 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
2022 GtkNotebook *notebook = NULL;
2023 gboolean is_finish_tab;
2025 ModestEasysetupWizardDialogPrivate *priv;
2028 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
2029 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
2031 /* Disable the Finish button until we are on the last page,
2032 * because HildonWizardDialog enables this for all but the
2034 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
2035 is_finish_tab = ((current == priv->page_complete_easysetup) ||
2036 (current == priv->page_complete_customsetup));
2038 if (is_finish_tab) {
2039 /* Disable Next on the last page no matter what the
2041 enable_next = FALSE;
2043 /* Not the last one */
2044 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2045 MODEST_WIZARD_DIALOG_FINISH,
2048 /* If the check support is not done then do not enable
2049 the wizard to continue */
2050 enable_next = enable_next && priv->pending_check_support == 0;
2053 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2054 MODEST_WIZARD_DIALOG_NEXT,
2059 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
2061 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2062 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2064 gboolean enable_next = TRUE;
2065 if (current_page == priv->page_welcome) {
2067 } else if (current_page == priv->page_account_details) {
2068 /* The account details title is mandatory: */
2069 if (entry_is_empty(priv->entry_account_title))
2070 enable_next = FALSE;
2071 } else if (current_page == priv->page_user_details) {
2072 /* The user details username is mandatory: */
2073 if (entry_is_empty(priv->entry_user_username))
2074 enable_next = FALSE;
2076 /* The user details email address is mandatory: */
2077 if (enable_next && entry_is_empty (priv->entry_user_email))
2078 enable_next = FALSE;
2079 } else if (current_page == priv->page_custom_incoming) {
2080 /* The custom incoming server is mandatory: */
2081 if (entry_is_empty(priv->entry_incomingserver))
2082 enable_next = FALSE;
2083 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
2084 enable_next = !modest_easysetup_wizard_page_validate (
2085 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
2088 /* Enable/disable buttons */
2089 real_enable_buttons (dialog, enable_next);
2093 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
2095 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2096 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
2099 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
2100 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
2102 /* Provide a vfunc implementation so we can decide
2103 * when to enable/disable the prev/next buttons.
2105 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
2106 base_klass->before_next = on_before_next;
2107 base_klass->enable_buttons = on_enable_buttons;
2108 base_klass->update_model = on_update_model;
2109 base_klass->save = on_save;
2114 * @self: a #ModestEasysetupWizardDialog
2116 * takes information from all the wizard and stores it in settings
2119 save_to_settings (ModestEasysetupWizardDialog *self)
2121 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2123 gchar *provider_id = NULL;
2124 gchar* display_name;
2125 const gchar *username, *password;
2126 gchar *store_hostname, *transport_hostname;
2127 guint store_port, transport_port;
2128 ModestProtocolRegistry *protocol_registry;
2129 ModestProtocolType store_protocol, transport_protocol;
2130 ModestProtocolType store_security, transport_security;
2131 ModestProtocolType store_auth_protocol, transport_auth_protocol;
2132 ModestServerAccountSettings *store_settings, *transport_settings;
2133 const gchar *fullname, *email_address;
2134 ModestProviderPicker *picker;
2135 ModestProviderPickerIdType id_type;
2137 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2138 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
2139 protocol_registry = modest_runtime_get_protocol_registry ();
2141 /* Get details from the specified presets: */
2142 id_type = modest_provider_picker_get_active_id_type (picker);
2143 provider_id = modest_provider_picker_get_active_provider_id (picker);
2145 /* Let the plugin save the settings. We do a return in order
2146 to save an indentation level */
2147 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
2148 ModestProtocol *protocol;
2150 protocol = modest_protocol_registry_get_protocol_by_name (
2151 modest_runtime_get_protocol_registry (),
2152 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
2155 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
2156 gint n_pages, i = 0;
2157 GtkNotebook *notebook;
2158 GList *wizard_pages = NULL;
2160 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
2161 n_pages = gtk_notebook_get_n_pages (notebook);
2162 for (i = 0; i < n_pages; i++) {
2163 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
2164 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
2165 wizard_pages = g_list_append (wizard_pages, page);
2167 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
2170 g_list_free (wizard_pages);
2172 g_debug ("The selected protocol is a plugin protocol "//
2173 "but it's not a ModestAccountProtocol");
2176 g_free (provider_id);
2180 /* username and password (for both incoming and outgoing): */
2181 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
2182 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
2184 store_settings = modest_account_settings_get_store_settings (priv->settings);
2185 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
2187 /* Incoming server: */
2188 /* Note: We need something as default for the transport store protocol values,
2189 * or modest_account_mgr_add_server_account will fail. */
2191 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2192 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2193 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2196 ModestProtocolType store_provider_server_type;
2197 gboolean store_provider_use_alternate_port;
2199 store_hostname = modest_presets_get_server (priv->presets, provider_id,
2202 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2205 store_security = modest_presets_get_info_server_security (priv->presets,
2208 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
2211 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
2215 /* We don't check for SMTP here as that is impossible for an incoming server. */
2216 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
2217 store_protocol = MODEST_PROTOCOLS_STORE_POP;
2219 store_protocol = store_provider_server_type;
2221 /* we check if there is a *special* port */
2222 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
2223 if (special_port != 0) {
2224 store_port = special_port;
2226 gboolean use_alternate_port = FALSE;
2227 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2229 use_alternate_port = TRUE;
2230 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
2233 modest_server_account_settings_set_security_protocol (store_settings,
2235 modest_server_account_settings_set_auth_protocol (store_settings,
2236 store_auth_protocol);
2237 if (store_port != 0)
2238 modest_server_account_settings_set_port (store_settings, store_port);
2240 /* Use custom pages because no preset was specified: */
2241 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
2242 store_protocol = modest_servertype_picker_get_active_servertype (
2243 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2245 modest_security_options_view_save_settings (
2246 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2250 /* now we store the common store account settings */
2251 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2252 modest_server_account_settings_set_username (store_settings, username);
2253 modest_server_account_settings_set_password (store_settings, password);
2254 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2256 g_object_unref (store_settings);
2257 g_free (store_hostname);
2259 /* Outgoing server: */
2260 transport_hostname = NULL;
2261 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2262 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2263 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2267 ModestProtocolType transport_provider_server_type;
2268 ModestProtocolType transport_provider_security;
2272 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2273 FALSE /* transport */);
2275 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2277 FALSE /* transport */);
2278 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2280 FALSE /* transport */);
2282 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2283 transport_protocol = transport_provider_server_type;
2284 transport_security = transport_provider_security;
2285 is_secure = modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2286 transport_security);
2288 /* we check if there is a *special* port */
2289 special_port = modest_presets_get_port (priv->presets, provider_id,
2290 FALSE /* transport */);
2291 if (special_port != 0) {
2292 transport_port = special_port;
2294 gboolean use_alternate_port = FALSE;
2295 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL)
2296 use_alternate_port = TRUE;
2297 transport_port = get_port_from_protocol(transport_provider_server_type, use_alternate_port);
2301 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2303 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2305 modest_server_account_settings_set_security_protocol (transport_settings,
2306 transport_security);
2307 modest_server_account_settings_set_auth_protocol (transport_settings,
2308 transport_auth_protocol);
2309 if (transport_port != 0)
2310 modest_server_account_settings_set_port (transport_settings,
2313 ModestProtocolRegistry *registry;
2314 ModestProtocol *store_proto;
2316 registry = modest_runtime_get_protocol_registry ();
2317 /* Use custom pages because no preset was specified: */
2318 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2320 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2323 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2324 /* fallback to SMTP if none was specified */
2325 g_warning ("No transport protocol was specified for store %d (%s)",
2326 modest_protocol_get_type_id (store_proto),
2327 modest_protocol_get_display_name (store_proto));
2328 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2331 modest_security_options_view_save_settings (
2332 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2336 /* now we store the common transport account settings */
2337 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2338 modest_server_account_settings_set_username (transport_settings, username);
2339 modest_server_account_settings_set_password (transport_settings, password);
2340 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2342 g_object_unref (transport_settings);
2343 g_free (transport_hostname);
2345 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2346 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2347 modest_account_settings_set_fullname (priv->settings, fullname);
2348 modest_account_settings_set_email_address (priv->settings, email_address);
2349 /* we don't set retrieve type to preserve advanced settings if
2350 any. By default account settings are set to headers only */
2352 /* Save the connection-specific SMTP server accounts. */
2353 if (priv->checkbox_outgoing_smtp_specific) {
2354 modest_account_settings_set_use_connection_specific_smtp
2356 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2359 display_name = get_entered_account_title (self);
2360 modest_account_settings_set_display_name (priv->settings, display_name);
2361 g_free (display_name);
2362 g_free (provider_id);
2364 /* This values are hardcoded for Fremantle */
2365 modest_account_settings_set_retrieve_type (priv->settings,
2366 MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS);
2367 modest_account_settings_set_retrieve_limit (priv->settings, 20);
2372 on_update_model (ModestWizardDialog *dialog)
2374 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2375 save_to_settings (self);
2380 on_save (ModestWizardDialog *dialog)
2382 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2383 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2385 save_to_settings (self);
2387 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2388 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2392 return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2398 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2400 GError *error = NULL;
2401 ModestProtocolType protocol_type;
2402 const gchar* hostname;
2403 const gchar* username;
2404 ModestProtocolType security_protocol_incoming_type;
2405 ModestProtocolRegistry *registry;
2407 GList *list_auth_methods;
2408 ModestEasysetupWizardDialogPrivate *priv;
2410 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2411 registry = modest_runtime_get_protocol_registry ();
2412 protocol_type = modest_servertype_picker_get_active_servertype (
2413 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2414 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2415 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2416 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2417 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2418 port_num = get_port_from_protocol(protocol_type, FALSE);
2419 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2420 username, GTK_WINDOW (self), &error);
2422 if (list_auth_methods) {
2423 /* TODO: Select the correct method */
2426 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2427 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2428 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2429 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2430 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2434 g_list_free(list_auth_methods);
2440 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2441 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2443 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2444 _("mcen_ib_unableto_discover_auth_methods"));
2448 g_error_free(error);
2454 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2456 GList* methods = check_for_supported_auth_methods(self);
2462 g_list_free(methods);
2467 check_support_show_progress (gpointer userdata)
2469 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2470 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2472 priv->check_support_show_progress_id = 0;
2474 if (priv->destroyed)
2477 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
2483 check_support_callback (ModestAccountProtocol *protocol,
2487 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2488 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2490 priv->pending_check_support --;
2492 if (priv->check_support_show_progress_id > 0) {
2493 g_source_remove (priv->check_support_show_progress_id);
2494 priv->check_support_show_progress_id = 0;
2497 if (priv->pending_check_support == 0) {
2498 priv->check_support_done = TRUE;
2500 if (!priv->destroyed) {
2502 fill_providers (self);
2503 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
2504 invoke_enable_buttons_vfunc (self);
2505 gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
2508 g_object_unref (self);
2513 check_support_of_protocols (ModestEasysetupWizardDialog *self)
2515 ModestProtocolRegistry *registry;
2516 GSList *provider_protos, *node;
2517 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2519 registry = modest_runtime_get_protocol_registry ();
2520 provider_protos = modest_protocol_registry_get_by_tag (registry,
2521 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2523 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2524 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2526 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2527 modest_protocol_get_type_id (proto),
2528 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2531 if (modest_protocol_registry_protocol_type_has_tag
2533 modest_protocol_get_type_id (proto),
2534 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2535 /* Check if there's already an account configured with this account type */
2536 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2537 modest_protocol_get_type_id (proto)))
2541 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2542 priv->pending_check_support ++;
2543 modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
2544 check_support_callback,
2545 g_object_ref (self));
2548 g_slist_free (provider_protos);
2550 if (priv->pending_check_support > 0) {
2551 priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
2552 check_support_show_progress,
2553 g_object_ref (self), g_object_unref);
2555 priv->check_support_done = TRUE;
2557 invoke_enable_buttons_vfunc (self);