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 hildon_helper_set_logical_font (privacy_note, "SmallSystemFont");
406 /* So that it is not truncated: */
407 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
408 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
409 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
410 gtk_box_pack_start (GTK_BOX (box), privacy_note, FALSE, FALSE, 0);
411 gtk_container_add (GTK_CONTAINER (align), box);
412 gtk_widget_show (label);
413 gtk_widget_show (privacy_note);
415 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
416 gtk_widget_show (GTK_WIDGET (box));
417 gtk_widget_show (GTK_WIDGET (align));
418 gtk_widget_show (pannable);
420 return GTK_WIDGET (pannable);
424 on_account_country_selector_changed (HildonTouchSelector *widget, gpointer user_data)
426 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
428 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
432 /* Fill the providers picker, based on the selected country: */
433 if (priv->presets != NULL) {
434 gint mcc = modest_country_picker_get_active_country_mcc (
435 MODEST_COUNTRY_PICKER (priv->account_country_picker));
436 modest_provider_picker_fill (
437 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
442 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
444 ModestEasysetupWizardDialogPrivate *priv;
445 gchar* provider_id = NULL, *with_at = NULL;
448 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
450 /* Fill the providers combo, based on the selected country: */
451 provider_id = modest_provider_picker_get_active_provider_id (
452 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
455 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
456 with_at = g_strdup_printf ("%c%s", '@', domain_name);
457 g_free (domain_name);
460 /* The sample address already contains the '@' */
462 with_at = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
464 if (priv->entry_user_email)
465 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), with_at);
468 g_free (provider_id);
472 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
474 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
476 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
480 update_user_email_from_provider (self);
484 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
486 modest_platform_information_banner (GTK_WIDGET (self), NULL,
487 _CS("ckdg_ib_maximum_characters_reached"));
491 create_page_account_details (ModestEasysetupWizardDialog *self)
494 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
495 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
496 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
498 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
499 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
500 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
501 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
502 gtk_widget_show (label);
504 /* Create a size group to be used by all captions.
505 * Note that HildonCaption does not create a default size group if we do not specify one.
506 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
507 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
508 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
510 /* The country widgets: */
511 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
512 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
513 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
514 _("mcen_fi_country"), priv->account_country_picker);
515 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
516 G_CALLBACK (on_picker_button_value_changed), self);
517 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
518 gtk_widget_show (priv->account_country_picker);
520 /* The service provider widgets: */
521 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
522 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
523 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
524 _("mcen_fi_serviceprovider"),
525 priv->account_serviceprovider_picker);
526 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
527 G_CALLBACK (on_serviceprovider_picker_button_value_changed), self);
528 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, 0);
529 gtk_widget_show (priv->account_serviceprovider_picker);
531 /* The description widgets: */
532 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
534 /* Do use auto-capitalization: */
535 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
536 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
538 /* Set a default account title, choosing one that does not already exist: */
539 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
540 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
541 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
542 priv->account_manager, default_account_name_start);
543 g_free (default_account_name_start);
544 default_account_name_start = NULL;
546 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
547 g_free (default_account_name);
548 default_account_name = NULL;
550 /* Connect signal after changing the text in the entry */
551 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
552 G_CALLBACK(on_easysetup_changed), self);
554 priv->caption_account_title = create_captioned (self, title_sizegroup, value_sizegroup,
555 _("mcen_fi_account_title"), FALSE,
556 priv->entry_account_title);
557 gtk_widget_show (priv->entry_account_title);
558 gtk_box_pack_start (GTK_BOX (box), priv->caption_account_title, FALSE, FALSE, 0);
559 gtk_widget_show (priv->caption_account_title);
560 gtk_widget_set_no_show_all (priv->caption_account_title, TRUE);
562 /* Prevent the use of some characters in the account title,
563 * as required by our UI specification: */
564 GList *list_prevent = NULL;
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, "?");
570 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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 list_prevent = g_list_append (list_prevent, "^");
576 modest_validating_entry_set_unallowed_characters (
577 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
578 g_list_free (list_prevent);
580 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
581 modest_utils_on_entry_invalid_character, self);
583 /* Set max length as in the UI spec:
584 * The UI spec seems to want us to show a dialog if we hit the maximum. */
585 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
586 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
589 gtk_widget_show (GTK_WIDGET (box));
591 g_object_unref (title_sizegroup);
592 g_object_unref (value_sizegroup);
594 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
595 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
596 gtk_widget_show (align);
597 gtk_container_add (GTK_CONTAINER (align), box);
599 return GTK_WIDGET (align);
603 on_user_username_changed(GtkWidget* widget, ModestEasysetupWizardDialog *self)
605 ModestEasysetupWizardDialogPrivate* priv;
606 gchar* provider_id = NULL;
608 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
610 /* Work out the user email address */
611 provider_id = modest_provider_picker_get_active_provider_id (
612 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
615 const gchar *current_username;
616 gchar *email_address;
617 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
619 current_username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
621 if (current_username && strstr (current_username, "@")) {
622 email_address = g_strdup (current_username);
624 email_address = g_strdup_printf ("%s@%s",
629 /* Update the email address */
630 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), email_address);
632 g_free (email_address);
633 g_free (domain_name);
634 g_free (provider_id);
638 on_easysetup_changed(widget, self);
643 create_page_user_details (ModestEasysetupWizardDialog *self)
645 GtkSizeGroup* title_sizegroup;
646 GtkSizeGroup* value_sizegroup;
648 ModestEasysetupWizardDialogPrivate *priv;
650 const gchar *my_name;
652 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
654 /* Create a size group to be used by all captions.
655 * Note that HildonCaption does not create a default size group if we do not specify one.
656 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
657 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
658 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
659 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
661 /* The name widgets: (use auto cap) */
662 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
663 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
664 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
666 /* Set max length as in the UI spec:
667 * The UI spec seems to want us to show a dialog if we hit the maximum. */
668 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
669 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
671 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
672 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
674 /* Try to initialize the user name with my own contact */
675 my_name = modest_address_book_get_my_name ();
677 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_name), my_name);
679 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
680 G_CALLBACK(on_easysetup_changed), self);
681 gtk_widget_show (priv->entry_user_name);
682 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
683 gtk_widget_show (caption);
685 /* Prevent the use of some characters in the name,
686 * as required by our UI specification: */
687 GList *list_prevent = NULL;
688 list_prevent = g_list_append (list_prevent, "<");
689 list_prevent = g_list_append (list_prevent, ">");
690 modest_validating_entry_set_unallowed_characters (
691 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
692 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
693 modest_utils_on_entry_invalid_character, self);
694 g_list_free (list_prevent);
696 /* The username widgets: */
697 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
698 /* Auto-capitalization is the default, so let's turn it off: */
699 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
700 HILDON_GTK_INPUT_MODE_FULL);
701 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
702 priv->entry_user_username);
703 gtk_widget_show (priv->entry_user_username);
704 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
705 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
706 G_CALLBACK(on_user_username_changed), self);
707 gtk_widget_show (caption);
709 /* Prevent the use of some characters in the username,
710 * as required by our UI specification: */
711 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
712 modest_utils_on_entry_invalid_character, self);
714 /* Set max length as in the UI spec:
715 * The UI spec seems to want us to show a dialog if we hit the maximum. */
716 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
717 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
720 /* The password widgets: */
721 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
722 /* Auto-capitalization is the default, so let's turn it off: */
723 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
724 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
725 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
726 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
727 caption = create_captioned (self, title_sizegroup, value_sizegroup,
728 _("mail_fi_password"), FALSE, priv->entry_user_password);
729 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
730 G_CALLBACK(on_easysetup_changed), self);
731 gtk_widget_show (priv->entry_user_password);
732 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
733 gtk_widget_show (caption);
735 /* The email address widgets: */
736 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
737 /* Auto-capitalization is the default, so let's turn it off: */
738 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
739 caption = create_captioned (self, title_sizegroup, value_sizegroup,
740 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
741 update_user_email_from_provider (self);
742 gtk_widget_show (priv->entry_user_email);
743 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
744 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
745 G_CALLBACK(on_easysetup_changed), self);
746 gtk_widget_show (caption);
748 /* Set max length as in the UI spec:
749 * The UI spec seems to want us to show a dialog if we hit the maximum. */
750 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
751 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
755 gtk_widget_show (GTK_WIDGET (box));
756 g_object_unref (title_sizegroup);
757 g_object_unref (value_sizegroup);
759 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
760 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
761 gtk_widget_show (align);
762 gtk_container_add (GTK_CONTAINER (align), box);
764 return GTK_WIDGET (align);
768 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
771 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
773 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
774 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
775 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
776 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
777 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
779 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
780 gtk_widget_show (label);
782 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
783 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
784 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
786 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
787 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
788 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
789 gtk_widget_show (label);
791 gtk_widget_show (GTK_WIDGET (box));
793 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
794 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
795 gtk_widget_show (align);
796 gtk_container_add (GTK_CONTAINER (align), box);
798 return GTK_WIDGET (align);
801 /** Change the caption title for the incoming server,
802 * as specified in the UI spec:
805 update_incoming_server_title (ModestEasysetupWizardDialog *self)
807 ModestEasysetupWizardDialogPrivate* priv;
808 ModestProtocolType protocol_type;
809 ModestProtocolRegistry *protocol_registry;
811 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
812 protocol_registry = modest_runtime_get_protocol_registry ();
814 protocol_type = modest_servertype_picker_get_active_servertype (
815 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
817 /* This could happen when the combo box has still no active iter */
818 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
819 gchar* incomingserver_title;
820 const gchar *protocol_display_name;
821 ModestProtocol *protocol;
823 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
825 protocol_display_name = modest_protocol_get_display_name (protocol);
827 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
828 protocol_display_name, ")</small>", NULL);
830 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
832 g_free(incomingserver_title);
836 /** Change the caption title for the incoming server,
837 * as specified in the UI spec:
840 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
842 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
843 ModestServertypePicker *server_type_picker;
844 ModestProtocolType protocol_type;
845 ModestSecurityOptionsView *view;
848 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
850 modest_servertype_picker_get_active_servertype (server_type_picker);
852 /* Fill the combo with appropriately titled choices for all
854 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
855 modest_security_options_view_set_server_type (view, protocol_type);
859 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
861 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
862 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
867 update_incoming_server_title (self);
869 /* Update security options if needed */
870 update_incoming_server_security_choices (self);
871 gtk_widget_show (priv->incoming_security);
873 set_default_custom_servernames (self);
877 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
879 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
880 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
882 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
886 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
888 ModestProtocolRegistry *protocol_registry;
889 ModestEasysetupWizardDialogPrivate* priv;
894 GtkSizeGroup *title_sizegroup;
895 GtkSizeGroup *value_sizegroup;
897 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
898 protocol_registry = modest_runtime_get_protocol_registry ();
900 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
901 pannable = hildon_pannable_area_new ();
903 /* Show note that account type cannot be changed in future: */
904 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
905 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
906 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
907 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
908 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
909 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
910 gtk_widget_show (label);
912 /* Create a size group to be used by all captions.
913 * Note that HildonCaption does not create a default size group if we do not specify one.
914 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
915 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
916 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
918 /* The incoming server widgets: */
919 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
920 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
922 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
923 _("mcen_li_emailsetup_type"),
924 priv->incoming_servertype_picker);
925 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
926 G_CALLBACK (on_picker_button_value_changed), self);
927 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, 0);
928 gtk_widget_show (priv->incoming_servertype_picker);
930 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
932 /* Auto-capitalization is the default, so let's turn it off: */
933 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
934 set_default_custom_servernames (self);
936 /* The caption title will be updated in update_incoming_server_title().
937 * so this default text will never be seen: */
938 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
939 "This will be removed",
940 FALSE, priv->entry_incomingserver);
941 update_incoming_server_title (self);
942 gtk_widget_show (priv->entry_incomingserver);
943 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
944 gtk_widget_show (priv->caption_incoming);
946 /* Remember when the servername was changed manually: */
947 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
948 G_CALLBACK (on_entry_incoming_servername_changed), self);
950 /* The secure connection widgets. These are only valid for
951 protocols with security */
952 priv->incoming_security =
953 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
954 FALSE, title_sizegroup, value_sizegroup);
955 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
957 gtk_widget_show (priv->incoming_security);
959 /* Set default selection */
960 modest_servertype_picker_set_active_servertype (
961 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
962 MODEST_PROTOCOLS_STORE_POP);
963 update_incoming_server_title (self);
964 update_incoming_server_security_choices (self);
965 set_default_custom_servernames (self);
967 /* Change the caption title when the servertype changes,
968 * as in the UI spec: */
969 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
971 G_CALLBACK (on_servertype_selector_changed), self);
973 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
974 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
975 gtk_widget_show (align);
976 gtk_container_add (GTK_CONTAINER (align), box);
978 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
979 gtk_widget_show (GTK_WIDGET (box));
980 gtk_widget_show (pannable);
982 g_object_unref (title_sizegroup);
983 g_object_unref (value_sizegroup);
985 /* Connect changed signals. We do it here after initializing everything */
986 g_signal_connect (G_OBJECT(priv->entry_incomingserver), "changed",
987 G_CALLBACK(on_easysetup_changed), self);
990 return GTK_WIDGET (pannable);
994 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
996 GtkWidget *widget = GTK_WIDGET (user_data);
998 /* Enable the widget only if the check button is active: */
999 const gboolean enable = hildon_check_button_get_active (button);
1000 gtk_widget_set_sensitive (widget, enable);
1003 /* Make the sensitivity of a widget depend on a check button.
1006 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
1008 g_signal_connect (G_OBJECT (button), "toggled",
1009 G_CALLBACK (on_check_button_changed), widget);
1011 /* Set the starting sensitivity: */
1012 on_check_button_changed (button, widget);
1016 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
1018 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1019 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1020 GtkWidget *specific_window;
1022 /* We set dirty here because setting it depending on the connection specific dialog
1026 /* Create the window, if necessary: */
1027 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
1028 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
1030 /* Show the window */
1031 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
1032 gtk_widget_show (specific_window);
1036 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
1038 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1039 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1040 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
1044 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
1046 ModestEasysetupWizardDialogPrivate *priv;
1047 gchar *smtp_caption_label;
1048 GtkWidget *pannable;
1050 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1052 pannable = hildon_pannable_area_new ();
1054 /* Create a size group to be used by all captions.
1055 * Note that HildonCaption does not create a default size group if we do not specify one.
1056 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1057 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1058 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1060 /* The outgoing server widgets: */
1061 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1062 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
1064 /* Auto-capitalization is the default, so let's turn it off: */
1065 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
1066 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
1067 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
1068 smtp_caption_label, TRUE, priv->entry_outgoingserver);
1069 g_free (smtp_caption_label);
1070 gtk_widget_show (priv->entry_outgoingserver);
1071 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
1072 gtk_widget_show (caption);
1073 set_default_custom_servernames (self);
1075 /* The secure connection widgets. These are only valid for
1076 protocols with security */
1077 priv->outgoing_security =
1078 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
1079 FALSE, title_sizegroup, value_sizegroup);
1080 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
1082 gtk_widget_show (priv->outgoing_security);
1084 GtkWidget *separator = gtk_hseparator_new ();
1085 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
1086 gtk_widget_show (separator);
1088 /* connection-specific checkbox: */
1089 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
1090 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1092 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1093 _("mcen_fi_advsetup_connection_smtp"));
1094 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1097 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1098 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
1101 /* Connection-specific SMTP-Severs Edit button: */
1102 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
1103 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
1104 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1105 gtk_widget_show (priv->button_outgoing_smtp_servers);
1106 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
1109 /* Only enable the button when the checkbox is checked: */
1110 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
1111 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
1113 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1114 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1116 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1117 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1120 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1121 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1122 gtk_widget_show (align);
1123 gtk_container_add (GTK_CONTAINER (align), box);
1125 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
1126 gtk_widget_show (GTK_WIDGET (box));
1127 gtk_widget_show (pannable);
1129 g_object_unref (title_sizegroup);
1130 g_object_unref (value_sizegroup);
1132 /* Connect changed signals. We do it here after initializing everything */
1133 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1134 G_CALLBACK (on_easysetup_changed), self);
1135 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1136 G_CALLBACK (on_easysetup_changed), self);
1138 return GTK_WIDGET (pannable);
1142 show_advanced_edit(gpointer user_data)
1144 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1145 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1148 /* Show the Account Settings window: */
1149 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
1150 if (priv->pending_load_settings) {
1151 save_to_settings (self);
1152 priv->pending_load_settings = FALSE;
1154 modest_account_settings_dialog_load_settings (dialog, priv->settings);
1156 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
1158 response = gtk_dialog_run (GTK_DIALOG (dialog));
1160 gtk_widget_destroy (GTK_WIDGET (dialog));
1162 return FALSE; /* Do not call this timeout callback again. */
1166 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1168 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1170 /* Show the Account Settings window: */
1171 show_advanced_edit(self);
1174 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1176 gchar *complete_string;
1180 GtkWidget *button_edit;
1182 box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1183 complete_string = g_strconcat (_("mcen_ia_emailsetup_setup_complete"), " ",
1184 _("mcen_ia_customsetup_complete"), NULL);
1185 label = gtk_label_new(complete_string);
1186 g_free (complete_string);
1187 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1188 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1189 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1190 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1191 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1192 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1193 gtk_widget_show (label);
1195 button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1196 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1197 gtk_widget_show (button_edit);
1198 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, 0);
1200 g_signal_connect (G_OBJECT (button_edit), "clicked",
1201 G_CALLBACK (on_button_edit_advanced_settings), self);
1203 gtk_widget_show (GTK_WIDGET (box));
1205 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1206 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
1207 gtk_widget_show (align);
1208 gtk_container_add (GTK_CONTAINER (align), box);
1210 return GTK_WIDGET (align);
1217 on_response (ModestWizardDialog *wizard_dialog,
1221 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1223 invoke_enable_buttons_vfunc (self);
1227 on_response_before (ModestWizardDialog *wizard_dialog,
1231 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1232 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1233 if (response_id == GTK_RESPONSE_CANCEL) {
1234 /* This is mostly copied from
1235 * src/maemo/modest-account-settings-dialog.c */
1237 gint dialog_response;
1240 dialog = hildon_note_new_confirmation ((GtkWindow *) self,
1241 _("imum_nc_wizard_confirm_lose_changes"));
1243 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
1244 (GtkWindow *) dialog,
1245 (GtkWindow *) wizard_dialog);
1247 dialog_response = gtk_dialog_run ((GtkDialog *) dialog);
1248 gtk_widget_destroy (GTK_WIDGET (dialog));
1250 if (dialog_response != GTK_RESPONSE_OK) {
1251 /* Don't let the dialog close */
1252 g_signal_stop_emission_by_name (wizard_dialog, "response");
1259 fill_providers (ModestEasysetupWizardDialog *self)
1261 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1263 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1264 /* gint mcc = get_default_country_code(); */
1266 /* Fill the combo in an idle call, as it takes a lot of time */
1267 modest_country_picker_load_data(
1268 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1269 /* connect to country picker's changed signal, so we can fill the provider picker: */
1270 g_signal_connect ((GObject *) priv->account_country_picker,
1272 G_CALLBACK (on_account_country_selector_changed), self);
1274 modest_country_picker_set_active_country_locale (
1275 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1276 mcc = modest_country_picker_get_active_country_mcc (
1277 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1278 modest_provider_picker_fill (
1279 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1280 priv->presets, mcc);
1281 /* connect to providers picker's changed signal, so we can fill the email address: */
1282 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1283 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1285 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1287 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1290 priv->dirty = FALSE;
1294 typedef struct IdleData {
1295 ModestEasysetupWizardDialog *dialog;
1296 ModestPresets *presets;
1300 presets_idle (gpointer userdata)
1302 IdleData *idle_data = (IdleData *) userdata;
1303 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1304 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1306 g_assert (idle_data->presets);
1308 gdk_threads_enter ();
1310 priv->presets = idle_data->presets;
1312 if (priv->check_support_done)
1313 fill_providers (self);
1315 g_object_unref (idle_data->dialog);
1318 gdk_threads_leave ();
1324 presets_loader (gpointer userdata)
1326 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1327 ModestPresets *presets = NULL;
1328 IdleData *idle_data;
1330 const gchar* path = NULL;
1331 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1332 const gchar* path2 = MODEST_FALLBACK_PROVIDER_DATA_FILE;
1334 if (access(path1, R_OK) == 0)
1336 else if (access(path2, R_OK) == 0)
1339 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1340 __FUNCTION__, path1, path2);
1344 presets = modest_presets_new (path);
1346 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1350 idle_data = g_new0 (IdleData, 1);
1351 idle_data->dialog = self;
1352 idle_data->presets = presets;
1354 g_idle_add (presets_idle, idle_data);
1360 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1366 /* Append page and set attributes */
1367 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1368 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1369 "tab-expand", TRUE, "tab-fill", TRUE,
1372 /* Give focus to page and show it */
1373 gtk_container_set_focus_child (GTK_CONTAINER (notebook), page);
1374 gtk_widget_show (page);
1378 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1380 priv->page_user_details = NULL;
1381 priv->entry_user_name = NULL;
1382 priv->entry_user_username = NULL;
1383 priv->entry_user_password = NULL;
1384 priv->entry_user_email = NULL;
1388 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1390 priv->page_custom_incoming = NULL;
1391 priv->incoming_servertype_picker = NULL;
1392 priv->caption_incoming = NULL;
1393 priv->entry_incomingserver = NULL;
1394 priv->entry_user_email = NULL;
1395 priv->incoming_security = NULL;
1399 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1401 priv->page_custom_outgoing = NULL;
1402 priv->entry_outgoingserver = NULL;
1403 priv->checkbox_outgoing_smtp_specific = NULL;
1404 priv->button_outgoing_smtp_servers = NULL;
1405 priv->outgoing_security = NULL;
1409 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1411 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1413 /* Create the notebook to be used by the ModestWizardDialog base class:
1414 * Each page of the notebook will be a page of the wizard: */
1415 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1416 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1418 /* Set the notebook used by the ModestWizardDialog base class: */
1419 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1421 /* Set the wizard title:
1422 * The actual window title will be a combination of this and the page's tab label title. */
1423 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1425 /* Read in the information about known service providers: */
1426 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1428 /* The server fields did not have been manually changed yet */
1429 priv->server_changes = 0;
1430 priv->pending_load_settings = TRUE;
1432 /* Get the account manager object,
1433 * so we can check for existing accounts,
1434 * and create new accounts: */
1435 priv->account_manager = modest_runtime_get_account_mgr ();
1436 g_object_ref (priv->account_manager);
1438 /* Initialize fields */
1439 priv->check_support_done = FALSE;
1440 priv->check_support_show_progress_id = 0;
1441 priv->pending_check_support = 0;
1442 priv->destroyed = FALSE;
1443 priv->page_welcome = create_page_welcome (self);
1444 gtk_widget_show (priv->page_welcome);
1445 priv->page_account_details = create_page_account_details (self);
1447 init_user_page (priv);
1448 init_incoming_page (priv);
1449 init_outgoing_page (priv);
1451 priv->page_complete_easysetup = NULL;
1452 priv->page_complete_customsetup = NULL;
1453 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1454 priv->missing_data_signals = NULL;
1456 /* Add the common pages */
1457 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1458 _("mcen_ti_emailsetup_welcome"));
1459 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1460 _("mcen_ti_accountdetails"));
1462 /* Connect to the dialog's response signal so we can enable/disable buttons
1463 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1464 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1465 * so that we can be enable/disable after ModestWizardDialog has done its own
1466 * enabling/disabling of buttons.
1468 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1469 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1471 * It's not enough to connect to the notebook's switch-page signal, because
1472 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1473 * _after_ switching the page (understandably).
1474 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1475 * then gtk_notebook_get_current_page() would return an incorrect value.)
1477 g_signal_connect_after (G_OBJECT (self), "response",
1478 G_CALLBACK (on_response), self);
1480 /* This is to show a confirmation dialog when the user hits cancel */
1481 g_signal_connect (G_OBJECT (self), "response",
1482 G_CALLBACK (on_response_before), self);
1484 g_signal_connect (G_OBJECT (self), "delete-event",
1485 G_CALLBACK (on_delete_event), self);
1487 /* Reset dirty, because there was no user input until now */
1488 priv->dirty = FALSE;
1490 /* When this window is shown, hibernation should not be possible,
1491 * because there is no sensible way to save the state: */
1492 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1493 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1495 /* Load provider presets */
1496 g_object_ref (self);
1497 g_thread_create (presets_loader, self, FALSE, NULL);
1499 priv->settings = modest_account_settings_new ();
1503 ModestEasysetupWizardDialog*
1504 modest_easysetup_wizard_dialog_new (void)
1507 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1511 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1513 ModestEasysetupWizardDialogPrivate *priv;
1514 GtkNotebook *notebook = NULL;
1516 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1519 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1521 if (!priv->page_user_details) {
1522 priv->page_user_details = create_page_user_details (self);
1525 /* Create the custom pages: */
1526 if(!(priv->page_custom_incoming)) {
1527 priv->page_custom_incoming = create_page_custom_incoming (self);
1530 /* TODO: only if needed */
1531 if(!(priv->page_custom_outgoing)) {
1532 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1535 if(!(priv->page_complete_customsetup)) {
1536 priv->page_complete_customsetup = create_page_complete_custom (self);
1539 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1540 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1541 _("mcen_ti_emailsetup_userdetails"));
1543 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1544 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1545 _("mcen_ti_emailsetup_incomingdetails"));
1547 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1548 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1549 _("mcen_ti_emailsetup_outgoingdetails"));
1551 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1552 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1553 _("mcen_ti_emailsetup_complete"));
1555 /* This is unnecessary with GTK+ 2.10: */
1556 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1560 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1562 ModestEasysetupWizardDialogPrivate *priv;
1563 GtkNotebook *notebook = NULL;
1565 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1568 /* Create the easysetup-specific pages: */
1569 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1570 if(!priv->page_complete_easysetup)
1571 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1573 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1574 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1575 _("mcen_ti_emailsetup_complete"));
1577 /* This is unnecessary with GTK+ 2.10: */
1578 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1583 remove_non_common_tabs (ModestEasysetupWizardDialog *self,
1584 gboolean remove_user_details)
1587 GtkNotebook *notebook;
1588 ModestEasysetupWizardDialogPrivate *priv;
1590 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1591 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1593 /* The first 2 tabs are the common ones (welcome tab and the
1594 providers tab), so we always remove starting from the
1596 starting_tab = (remove_user_details) ? 2 : 3;
1597 while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
1598 /* Disconnect signal */
1599 GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
1600 if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
1601 priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
1603 "missing-mandatory-data");
1605 /* Remove page from notebook */
1606 gtk_notebook_remove_page (notebook, -1);
1611 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1615 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1618 /* After the user details page,
1619 * the following pages depend on whether "Other" was chosen
1620 * in the provider combobox on the account page
1623 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1625 ModestEasysetupWizardDialogPrivate *priv;
1626 ModestProviderPicker *picker;
1627 ModestProviderPickerIdType id_type;
1628 GtkNotebook *notebook;
1630 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1631 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1632 id_type = modest_provider_picker_get_active_id_type (picker);
1633 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1635 /* Remove the response override handler for non-plugin
1636 protocols. For plugins it'll be overriden later */
1637 if (id_type != MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL)
1638 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1642 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1643 /* "Other..." was selected: */
1645 /* If we come from a rollbacked easysetup */
1646 if (priv->page_complete_easysetup) {
1647 remove_non_common_tabs (self, FALSE);
1648 priv->page_complete_easysetup = NULL;
1651 /* If we come from a rollbacked plugin protocol setup */
1652 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1653 remove_non_common_tabs (self, TRUE);
1654 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1655 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1656 priv->missing_data_signals = NULL;
1659 create_subsequent_customsetup_pages (self);
1661 /* If we come from a rollbacked custom setup */
1662 if (priv->page_custom_incoming) {
1663 remove_non_common_tabs (self, TRUE);
1664 init_user_page (priv);
1665 init_incoming_page (priv);
1666 init_outgoing_page (priv);
1667 init_user_page (priv);
1668 priv->page_complete_customsetup = NULL;
1671 /* It's a pluggable protocol and not a provider with presets */
1672 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1673 ModestProtocol *protocol;
1675 ModestProtocolType proto_type;
1676 ModestWizardDialogResponseOverrideFunc response_override;
1678 /* Get protocol data */
1679 proto_name = modest_provider_picker_get_active_provider_id (picker);
1680 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1681 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1683 proto_type = modest_protocol_get_type_id (protocol);
1686 /* If we come from a rollbacked easy setup */
1687 if (priv->last_plugin_protocol_selected != proto_type &&
1688 priv->page_complete_easysetup) {
1689 remove_non_common_tabs (self, TRUE);
1690 init_user_page (priv);
1691 priv->page_complete_easysetup = NULL;
1694 /* Ensure that the response override handler
1695 is set. It might happen that plugins clear
1697 response_override = modest_account_protocol_get_wizard_response_override
1698 (MODEST_ACCOUNT_PROTOCOL (protocol));
1699 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1702 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1703 proto_type != priv->last_plugin_protocol_selected) {
1704 ModestPairList *tabs;
1706 gboolean first_page = TRUE;
1708 /* Remember the last selected plugin protocol */
1709 priv->last_plugin_protocol_selected = proto_type;
1712 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1713 tmp = (GSList *) tabs;
1715 ModestPair *pair = (ModestPair *) tmp->data;
1716 modest_easysetup_wizard_dialog_append_page (notebook,
1717 GTK_WIDGET (pair->second),
1718 (const gchar *) pair->first);
1720 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1721 GTK_WIDGET (pair->second));
1725 /* Connect signals */
1726 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1727 priv->missing_data_signals =
1728 modest_signal_mgr_connect (priv->missing_data_signals,
1729 G_OBJECT (pair->second),
1730 "missing-mandatory-data",
1731 G_CALLBACK (on_missing_mandatory_data),
1735 g_free (pair->first);
1736 tmp = g_slist_next (tmp);
1737 /* Critical: if you don't show the page then the dialog will ignore it */
1738 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1740 modest_pair_list_free (tabs);
1742 g_free (proto_name);
1744 if (priv->last_plugin_protocol_selected !=
1745 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1746 remove_non_common_tabs (self, TRUE);
1747 init_user_page (priv);
1748 priv->page_complete_easysetup = NULL;
1749 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1750 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1751 priv->missing_data_signals = NULL;
1753 if (!priv->page_user_details) {
1754 priv->page_user_details = create_page_user_details (self);
1755 modest_easysetup_wizard_dialog_append_page (notebook,
1756 priv->page_user_details,
1757 _("mcen_ti_emailsetup_userdetails"));
1761 /* Create the easysetup pages: */
1762 create_subsequent_easysetup_pages (self);
1768 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1770 const gchar* hostname = NULL;
1773 ModestProtocolRegistry *protocol_registry;
1774 ModestProtocol *protocol;
1779 at = g_utf8_strchr (email_address, -1, '@');
1780 if (!at || (g_utf8_strlen (at, -1) < 2))
1783 domain = g_utf8_next_char (at);
1787 protocol_registry = modest_runtime_get_protocol_registry ();
1788 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1790 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1791 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1792 hostname = modest_protocol_get_name (protocol);
1798 return g_strdup_printf ("%s.%s", hostname, domain);
1802 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1804 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1806 if (!priv->entry_incomingserver)
1809 /* Set a default domain for the server, based on the email address,
1810 * if no server name was already specified.
1812 if (priv->entry_user_email
1813 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1814 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1815 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1817 /* This could happen when the combo box has still no active iter */
1818 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1819 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1820 gchar* servername = util_get_default_servername_from_email_address (email_address,
1823 /* Do not set the INCOMING_CHANGED flag because of this edit */
1824 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1825 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1826 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1828 g_free (servername);
1832 /* Set a default domain for the server, based on the email address,
1833 * if no server name was already specified.
1835 if (!priv->entry_outgoingserver)
1838 if (priv->entry_user_email
1839 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1840 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1842 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1844 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1845 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1846 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1847 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1849 g_free (servername);
1854 get_entered_account_title (ModestEasysetupWizardDialog *self)
1856 ModestEasysetupWizardDialogPrivate *priv;
1857 const gchar* account_title;
1859 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1860 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1862 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1865 /* Strip it of whitespace at the start and end: */
1866 gchar *result = g_strdup (account_title);
1867 result = g_strstrip (result);
1872 if (g_utf8_strlen (result, -1) == 0) {
1882 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1884 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1885 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1886 ModestProtocolRegistry *protocol_registry;
1888 protocol_registry = modest_runtime_get_protocol_registry ();
1890 /* if are browsing pages previous to the last one, then we have pending settings in
1892 if (next_page != NULL)
1893 priv->pending_load_settings = TRUE;
1895 /* Do extra validation that couldn't be done for every key press,
1896 * either because it was too slow,
1897 * or because it requires interaction:
1899 if (current_page == priv->page_welcome) {
1900 if (!priv->check_support_done) {
1901 check_support_of_protocols (self);
1902 return priv->check_support_done;
1904 } else if (current_page == priv->page_account_details) {
1905 /* Check that the title is not already in use: */
1906 gchar* account_title = get_entered_account_title (self);
1910 /* Aavoid a clash with an existing display name: */
1911 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1912 priv->account_manager, account_title);
1913 g_free (account_title);
1916 /* Warn the user via a dialog: */
1917 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1922 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1923 create_subsequent_pages (self);
1925 } else if (current_page == priv->page_user_details) {
1926 /* Check that the email address is valud: */
1927 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1928 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1931 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1932 /* Warn the user via a dialog: */
1933 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1935 /* Return focus to the email address entry: */
1936 gtk_widget_grab_focus (priv->entry_user_email);
1937 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1941 } else if (current_page == priv->page_custom_incoming ||
1942 current_page == priv->page_custom_outgoing) {
1944 const gchar *hostname;
1945 GtkWidget *entry = (current_page == priv->page_custom_incoming) ?
1946 priv->entry_incomingserver :
1947 priv->entry_outgoingserver;
1949 hostname = gtk_entry_get_text (GTK_ENTRY (entry));
1950 if (!modest_text_utils_validate_domain_name (hostname)) {
1952 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
1954 /* Return focus to the email address entry: */
1955 gtk_widget_grab_focus (entry);
1956 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
1962 if (next_page == priv->page_custom_incoming) {
1963 set_default_custom_servernames (self);
1964 } else if (next_page == priv->page_custom_outgoing) {
1965 set_default_custom_servernames (self);
1967 /* Check if the server supports secure authentication */
1968 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
1969 if (!check_has_supported_auth_methods (self))
1971 gtk_widget_show (priv->outgoing_security);
1974 /* If this is the last page, and this is a click on Finish,
1975 * then attempt to create the dialog.
1978 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1980 if (priv->pending_load_settings) {
1981 save_to_settings (self);
1984 /* We check if there's already another account with the same configuration */
1985 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1986 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1990 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1997 static gboolean entry_is_empty (GtkWidget *entry)
2002 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
2003 if ((!text) || (g_utf8_strlen (text, -1) == 0))
2006 /* Strip it of whitespace at the start and end: */
2007 gchar *stripped = g_strdup (text);
2008 stripped = g_strstrip (stripped);
2013 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
2021 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
2023 GtkNotebook *notebook = NULL;
2024 gboolean is_finish_tab;
2026 ModestEasysetupWizardDialogPrivate *priv;
2029 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
2030 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
2032 /* Disable the Finish button until we are on the last page,
2033 * because HildonWizardDialog enables this for all but the
2035 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
2036 is_finish_tab = ((current == priv->page_complete_easysetup) ||
2037 (current == priv->page_complete_customsetup));
2039 if (is_finish_tab) {
2040 /* Disable Next on the last page no matter what the
2042 enable_next = FALSE;
2044 /* Not the last one */
2045 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2046 MODEST_WIZARD_DIALOG_FINISH,
2049 /* If the check support is not done then do not enable
2050 the wizard to continue */
2051 enable_next = enable_next && priv->pending_check_support == 0;
2054 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2055 MODEST_WIZARD_DIALOG_NEXT,
2060 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
2062 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2063 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2065 gboolean enable_next = TRUE;
2066 if (current_page == priv->page_welcome) {
2068 } else if (current_page == priv->page_account_details) {
2069 /* The account details title is mandatory: */
2070 if (entry_is_empty(priv->entry_account_title))
2071 enable_next = FALSE;
2072 } else if (current_page == priv->page_user_details) {
2073 /* The user details username is mandatory: */
2074 if (entry_is_empty(priv->entry_user_username))
2075 enable_next = FALSE;
2077 /* The user details email address is mandatory: */
2078 if (enable_next && entry_is_empty (priv->entry_user_email))
2079 enable_next = FALSE;
2080 } else if (current_page == priv->page_custom_incoming) {
2081 /* The custom incoming server is mandatory: */
2082 if (entry_is_empty(priv->entry_incomingserver))
2083 enable_next = FALSE;
2084 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
2085 enable_next = !modest_easysetup_wizard_page_validate (
2086 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
2089 /* Enable/disable buttons */
2090 real_enable_buttons (dialog, enable_next);
2094 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
2096 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2097 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
2100 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
2101 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
2103 /* Provide a vfunc implementation so we can decide
2104 * when to enable/disable the prev/next buttons.
2106 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
2107 base_klass->before_next = on_before_next;
2108 base_klass->enable_buttons = on_enable_buttons;
2109 base_klass->update_model = on_update_model;
2110 base_klass->save = on_save;
2115 * @self: a #ModestEasysetupWizardDialog
2117 * takes information from all the wizard and stores it in settings
2120 save_to_settings (ModestEasysetupWizardDialog *self)
2122 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2124 gchar *provider_id = NULL;
2125 gchar* display_name;
2126 const gchar *username, *password;
2127 gchar *store_hostname, *transport_hostname;
2128 guint store_port, transport_port;
2129 ModestProtocolRegistry *protocol_registry;
2130 ModestProtocolType store_protocol, transport_protocol;
2131 ModestProtocolType store_security, transport_security;
2132 ModestProtocolType store_auth_protocol, transport_auth_protocol;
2133 ModestServerAccountSettings *store_settings, *transport_settings;
2134 const gchar *fullname, *email_address;
2135 ModestProviderPicker *picker;
2136 ModestProviderPickerIdType id_type;
2138 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2139 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
2140 protocol_registry = modest_runtime_get_protocol_registry ();
2142 /* Get details from the specified presets: */
2143 id_type = modest_provider_picker_get_active_id_type (picker);
2144 provider_id = modest_provider_picker_get_active_provider_id (picker);
2146 /* Let the plugin save the settings. We do a return in order
2147 to save an indentation level */
2148 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
2149 ModestProtocol *protocol;
2151 protocol = modest_protocol_registry_get_protocol_by_name (
2152 modest_runtime_get_protocol_registry (),
2153 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
2156 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
2157 gint n_pages, i = 0;
2158 GtkNotebook *notebook;
2159 GList *wizard_pages = NULL;
2161 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
2162 n_pages = gtk_notebook_get_n_pages (notebook);
2163 for (i = 0; i < n_pages; i++) {
2164 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
2165 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
2166 wizard_pages = g_list_append (wizard_pages, page);
2168 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
2171 g_list_free (wizard_pages);
2173 g_debug ("The selected protocol is a plugin protocol "//
2174 "but it's not a ModestAccountProtocol");
2177 g_free (provider_id);
2181 /* username and password (for both incoming and outgoing): */
2182 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
2183 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
2185 store_settings = modest_account_settings_get_store_settings (priv->settings);
2186 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
2188 /* Incoming server: */
2189 /* Note: We need something as default for the transport store protocol values,
2190 * or modest_account_mgr_add_server_account will fail. */
2192 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2193 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2194 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2197 ModestProtocolType store_provider_server_type;
2198 gboolean store_provider_use_alternate_port;
2200 store_hostname = modest_presets_get_server (priv->presets, provider_id,
2203 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2206 store_security = modest_presets_get_info_server_security (priv->presets,
2209 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
2212 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
2216 /* We don't check for SMTP here as that is impossible for an incoming server. */
2217 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
2218 store_protocol = MODEST_PROTOCOLS_STORE_POP;
2220 store_protocol = store_provider_server_type;
2222 /* we check if there is a *special* port */
2223 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
2224 if (special_port != 0) {
2225 store_port = special_port;
2227 gboolean use_alternate_port = FALSE;
2228 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2230 use_alternate_port = TRUE;
2231 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
2234 modest_server_account_settings_set_security_protocol (store_settings,
2236 modest_server_account_settings_set_auth_protocol (store_settings,
2237 store_auth_protocol);
2238 if (store_port != 0)
2239 modest_server_account_settings_set_port (store_settings, store_port);
2241 /* Use custom pages because no preset was specified: */
2242 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
2243 store_protocol = modest_servertype_picker_get_active_servertype (
2244 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2246 modest_security_options_view_save_settings (
2247 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2251 /* now we store the common store account settings */
2252 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2253 modest_server_account_settings_set_username (store_settings, username);
2254 modest_server_account_settings_set_password (store_settings, password);
2255 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2257 g_object_unref (store_settings);
2258 g_free (store_hostname);
2260 /* Outgoing server: */
2261 transport_hostname = NULL;
2262 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2263 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2264 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2268 ModestProtocolType transport_provider_server_type;
2269 ModestProtocolType transport_provider_security;
2273 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2274 FALSE /* transport */);
2276 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2278 FALSE /* transport */);
2279 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2281 FALSE /* transport */);
2283 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2284 transport_protocol = transport_provider_server_type;
2285 transport_security = transport_provider_security;
2286 is_secure = modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2287 transport_security);
2289 /* we check if there is a *special* port */
2290 special_port = modest_presets_get_port (priv->presets, provider_id,
2291 FALSE /* transport */);
2292 if (special_port != 0) {
2293 transport_port = special_port;
2295 gboolean use_alternate_port = FALSE;
2296 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL)
2297 use_alternate_port = TRUE;
2298 transport_port = get_port_from_protocol(transport_provider_server_type, use_alternate_port);
2302 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2304 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2306 modest_server_account_settings_set_security_protocol (transport_settings,
2307 transport_security);
2308 modest_server_account_settings_set_auth_protocol (transport_settings,
2309 transport_auth_protocol);
2310 if (transport_port != 0)
2311 modest_server_account_settings_set_port (transport_settings,
2314 ModestProtocolRegistry *registry;
2315 ModestProtocol *store_proto;
2317 registry = modest_runtime_get_protocol_registry ();
2318 /* Use custom pages because no preset was specified: */
2319 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2321 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2324 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2325 /* fallback to SMTP if none was specified */
2326 g_warning ("No transport protocol was specified for store %d (%s)",
2327 modest_protocol_get_type_id (store_proto),
2328 modest_protocol_get_display_name (store_proto));
2329 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2332 modest_security_options_view_save_settings (
2333 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2337 /* now we store the common transport account settings */
2338 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2339 modest_server_account_settings_set_username (transport_settings, username);
2340 modest_server_account_settings_set_password (transport_settings, password);
2341 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2343 g_object_unref (transport_settings);
2344 g_free (transport_hostname);
2346 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2347 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2348 modest_account_settings_set_fullname (priv->settings, fullname);
2349 modest_account_settings_set_email_address (priv->settings, email_address);
2350 /* we don't set retrieve type to preserve advanced settings if
2351 any. By default account settings are set to headers only */
2353 /* Save the connection-specific SMTP server accounts. */
2354 if (priv->checkbox_outgoing_smtp_specific) {
2355 modest_account_settings_set_use_connection_specific_smtp
2357 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2360 display_name = get_entered_account_title (self);
2361 modest_account_settings_set_display_name (priv->settings, display_name);
2362 g_free (display_name);
2363 g_free (provider_id);
2365 /* This values are hardcoded for Fremantle */
2366 modest_account_settings_set_retrieve_type (priv->settings,
2367 MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS);
2368 modest_account_settings_set_retrieve_limit (priv->settings, 20);
2373 on_update_model (ModestWizardDialog *dialog)
2375 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2376 save_to_settings (self);
2381 on_save (ModestWizardDialog *dialog)
2383 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2384 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2386 save_to_settings (self);
2388 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2389 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2393 return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2399 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2401 GError *error = NULL;
2402 ModestProtocolType protocol_type;
2403 const gchar* hostname;
2404 const gchar* username;
2405 ModestProtocolType security_protocol_incoming_type;
2406 ModestProtocolRegistry *registry;
2408 GList *list_auth_methods;
2409 ModestEasysetupWizardDialogPrivate *priv;
2411 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2412 registry = modest_runtime_get_protocol_registry ();
2413 protocol_type = modest_servertype_picker_get_active_servertype (
2414 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2415 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2416 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2417 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2418 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2419 port_num = get_port_from_protocol(protocol_type, FALSE);
2420 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2421 username, GTK_WINDOW (self), &error);
2423 if (list_auth_methods) {
2424 /* TODO: Select the correct method */
2427 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2428 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2429 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2430 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2431 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2435 g_list_free(list_auth_methods);
2441 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2442 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2444 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2445 _("mcen_ib_unableto_discover_auth_methods"));
2449 g_error_free(error);
2455 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2457 GList* methods = check_for_supported_auth_methods(self);
2463 g_list_free(methods);
2468 check_support_show_progress (gpointer userdata)
2470 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2471 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2473 priv->check_support_show_progress_id = 0;
2475 if (priv->destroyed)
2478 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
2484 check_support_callback (ModestAccountProtocol *protocol,
2488 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2489 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2491 priv->pending_check_support --;
2493 if (priv->check_support_show_progress_id > 0) {
2494 g_source_remove (priv->check_support_show_progress_id);
2495 priv->check_support_show_progress_id = 0;
2498 if (priv->pending_check_support == 0) {
2499 priv->check_support_done = TRUE;
2501 if (!priv->destroyed) {
2503 fill_providers (self);
2504 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
2505 invoke_enable_buttons_vfunc (self);
2506 gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
2509 g_object_unref (self);
2514 check_support_of_protocols (ModestEasysetupWizardDialog *self)
2516 ModestProtocolRegistry *registry;
2517 GSList *provider_protos, *node;
2518 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2520 registry = modest_runtime_get_protocol_registry ();
2521 provider_protos = modest_protocol_registry_get_by_tag (registry,
2522 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2524 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2525 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2527 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2528 modest_protocol_get_type_id (proto),
2529 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2532 if (modest_protocol_registry_protocol_type_has_tag
2534 modest_protocol_get_type_id (proto),
2535 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2536 /* Check if there's already an account configured with this account type */
2537 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2538 modest_protocol_get_type_id (proto)))
2542 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2543 priv->pending_check_support ++;
2544 modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
2545 check_support_callback,
2546 g_object_ref (self));
2549 g_slist_free (provider_protos);
2551 if (priv->pending_check_support > 0) {
2552 priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
2553 check_support_show_progress,
2554 g_object_ref (self), g_object_unref);
2556 priv->check_support_done = TRUE;
2558 invoke_enable_buttons_vfunc (self);