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 ModestEasysetupWizardDialogPrivate *priv;
392 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
393 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
394 label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
395 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
396 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
397 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
398 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
399 /* So that it is not truncated: */
400 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
401 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
402 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
403 gtk_container_add (GTK_CONTAINER (align), box);
404 gtk_widget_show (label);
405 gtk_widget_show (GTK_WIDGET (box));
406 return GTK_WIDGET (align);
410 on_account_country_selector_changed (HildonTouchSelector *widget, gpointer user_data)
412 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
414 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
418 /* Fill the providers picker, based on the selected country: */
419 if (priv->presets != NULL) {
420 gint mcc = modest_country_picker_get_active_country_mcc (
421 MODEST_COUNTRY_PICKER (priv->account_country_picker));
422 modest_provider_picker_fill (
423 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
428 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
430 ModestEasysetupWizardDialogPrivate *priv;
431 gchar* provider_id = NULL, *with_at = NULL;
434 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
436 /* Fill the providers combo, based on the selected country: */
437 provider_id = modest_provider_picker_get_active_provider_id (
438 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
441 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
442 with_at = g_strdup_printf ("%c%s", '@', domain_name);
443 g_free (domain_name);
446 /* The sample address already contains the '@' */
448 with_at = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
450 if (priv->entry_user_email)
451 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), with_at);
454 g_free (provider_id);
458 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
460 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
462 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
466 update_user_email_from_provider (self);
470 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
472 modest_platform_information_banner (GTK_WIDGET (self), NULL,
473 _CS("ckdg_ib_maximum_characters_reached"));
477 create_page_account_details (ModestEasysetupWizardDialog *self)
480 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
481 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
482 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
484 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
485 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
486 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
487 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
488 gtk_widget_show (label);
490 /* Create a size group to be used by all captions.
491 * Note that HildonCaption does not create a default size group if we do not specify one.
492 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
493 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
494 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
496 /* The country widgets: */
497 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
498 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
499 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
500 _("mcen_fi_country"), priv->account_country_picker);
501 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
502 G_CALLBACK (on_picker_button_value_changed), self);
503 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
504 gtk_widget_show (priv->account_country_picker);
506 /* The service provider widgets: */
507 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
508 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
509 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
510 _("mcen_fi_serviceprovider"),
511 priv->account_serviceprovider_picker);
512 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
513 G_CALLBACK (on_serviceprovider_picker_button_value_changed), self);
514 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, 0);
515 gtk_widget_show (priv->account_serviceprovider_picker);
517 /* The description widgets: */
518 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
520 /* Do use auto-capitalization: */
521 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
522 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
524 /* Set a default account title, choosing one that does not already exist: */
525 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
526 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
527 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
528 priv->account_manager, default_account_name_start);
529 g_free (default_account_name_start);
530 default_account_name_start = NULL;
532 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
533 g_free (default_account_name);
534 default_account_name = NULL;
536 /* Connect signal after changing the text in the entry */
537 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
538 G_CALLBACK(on_easysetup_changed), self);
540 priv->caption_account_title = create_captioned (self, title_sizegroup, value_sizegroup,
541 _("mcen_fi_account_title"), FALSE,
542 priv->entry_account_title);
543 gtk_widget_show (priv->entry_account_title);
544 gtk_box_pack_start (GTK_BOX (box), priv->caption_account_title, FALSE, FALSE, 0);
545 gtk_widget_show (priv->caption_account_title);
546 gtk_widget_set_no_show_all (priv->caption_account_title, TRUE);
548 /* Prevent the use of some characters in the account title,
549 * as required by our UI specification: */
550 GList *list_prevent = NULL;
551 list_prevent = g_list_append (list_prevent, "\\");
552 list_prevent = g_list_append (list_prevent, "/");
553 list_prevent = g_list_append (list_prevent, ":");
554 list_prevent = g_list_append (list_prevent, "*");
555 list_prevent = g_list_append (list_prevent, "?");
556 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
557 list_prevent = g_list_append (list_prevent, "“");
558 list_prevent = g_list_append (list_prevent, "<");
559 list_prevent = g_list_append (list_prevent, ">");
560 list_prevent = g_list_append (list_prevent, "|");
561 list_prevent = g_list_append (list_prevent, "^");
562 modest_validating_entry_set_unallowed_characters (
563 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
564 g_list_free (list_prevent);
566 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
567 modest_utils_on_entry_invalid_character, self);
569 /* Set max length as in the UI spec:
570 * The UI spec seems to want us to show a dialog if we hit the maximum. */
571 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
572 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
575 gtk_widget_show (GTK_WIDGET (box));
577 g_object_unref (title_sizegroup);
578 g_object_unref (value_sizegroup);
580 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
581 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
582 gtk_widget_show (align);
583 gtk_container_add (GTK_CONTAINER (align), box);
585 return GTK_WIDGET (align);
589 on_user_username_changed(GtkWidget* widget, ModestEasysetupWizardDialog *self)
591 ModestEasysetupWizardDialogPrivate* priv;
592 gchar* provider_id = NULL;
594 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
596 /* Work out the user email address */
597 provider_id = modest_provider_picker_get_active_provider_id (
598 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
601 const gchar *current_username;
602 gchar *email_address;
603 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
605 current_username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
607 if (current_username && strstr (current_username, "@")) {
608 email_address = g_strdup (current_username);
610 email_address = g_strdup_printf ("%s@%s",
615 /* Update the email address */
616 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), email_address);
618 g_free (email_address);
619 g_free (domain_name);
620 g_free (provider_id);
624 on_easysetup_changed(widget, self);
629 create_page_user_details (ModestEasysetupWizardDialog *self)
631 GtkSizeGroup* title_sizegroup;
632 GtkSizeGroup* value_sizegroup;
634 ModestEasysetupWizardDialogPrivate *priv;
636 const gchar *my_name;
638 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
640 /* Create a size group to be used by all captions.
641 * Note that HildonCaption does not create a default size group if we do not specify one.
642 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
643 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
644 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
645 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
647 /* The name widgets: (use auto cap) */
648 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
649 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
650 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
652 /* Set max length as in the UI spec:
653 * The UI spec seems to want us to show a dialog if we hit the maximum. */
654 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
655 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
657 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
658 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
660 /* Try to initialize the user name with my own contact */
661 my_name = modest_address_book_get_my_name ();
663 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_name), my_name);
665 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
666 G_CALLBACK(on_easysetup_changed), self);
667 gtk_widget_show (priv->entry_user_name);
668 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
669 gtk_widget_show (caption);
671 /* Prevent the use of some characters in the name,
672 * as required by our UI specification: */
673 GList *list_prevent = NULL;
674 list_prevent = g_list_append (list_prevent, "<");
675 list_prevent = g_list_append (list_prevent, ">");
676 modest_validating_entry_set_unallowed_characters (
677 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
678 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
679 modest_utils_on_entry_invalid_character, self);
680 g_list_free (list_prevent);
682 /* The username widgets: */
683 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
684 /* Auto-capitalization is the default, so let's turn it off: */
685 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
686 HILDON_GTK_INPUT_MODE_FULL);
687 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
688 priv->entry_user_username);
689 gtk_widget_show (priv->entry_user_username);
690 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
691 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
692 G_CALLBACK(on_user_username_changed), self);
693 gtk_widget_show (caption);
695 /* Prevent the use of some characters in the username,
696 * as required by our UI specification: */
697 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
698 modest_utils_on_entry_invalid_character, self);
700 /* Set max length as in the UI spec:
701 * The UI spec seems to want us to show a dialog if we hit the maximum. */
702 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
703 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
706 /* The password widgets: */
707 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
708 /* Auto-capitalization is the default, so let's turn it off: */
709 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
710 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
711 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
712 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
713 caption = create_captioned (self, title_sizegroup, value_sizegroup,
714 _("mail_fi_password"), FALSE, priv->entry_user_password);
715 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
716 G_CALLBACK(on_easysetup_changed), self);
717 gtk_widget_show (priv->entry_user_password);
718 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
719 gtk_widget_show (caption);
721 /* The email address widgets: */
722 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
723 /* Auto-capitalization is the default, so let's turn it off: */
724 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
725 caption = create_captioned (self, title_sizegroup, value_sizegroup,
726 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
727 update_user_email_from_provider (self);
728 gtk_widget_show (priv->entry_user_email);
729 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
730 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
731 G_CALLBACK(on_easysetup_changed), self);
732 gtk_widget_show (caption);
734 /* Set max length as in the UI spec:
735 * The UI spec seems to want us to show a dialog if we hit the maximum. */
736 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
737 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
741 gtk_widget_show (GTK_WIDGET (box));
742 g_object_unref (title_sizegroup);
743 g_object_unref (value_sizegroup);
745 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
746 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
747 gtk_widget_show (align);
748 gtk_container_add (GTK_CONTAINER (align), box);
750 return GTK_WIDGET (align);
754 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
757 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
759 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
760 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
761 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
762 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
763 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
765 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
766 gtk_widget_show (label);
768 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
769 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
770 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
772 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
773 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
774 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
775 gtk_widget_show (label);
777 gtk_widget_show (GTK_WIDGET (box));
779 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
780 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
781 gtk_widget_show (align);
782 gtk_container_add (GTK_CONTAINER (align), box);
784 return GTK_WIDGET (align);
787 /** Change the caption title for the incoming server,
788 * as specified in the UI spec:
791 update_incoming_server_title (ModestEasysetupWizardDialog *self)
793 ModestEasysetupWizardDialogPrivate* priv;
794 ModestProtocolType protocol_type;
795 ModestProtocolRegistry *protocol_registry;
797 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
798 protocol_registry = modest_runtime_get_protocol_registry ();
800 protocol_type = modest_servertype_picker_get_active_servertype (
801 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
803 /* This could happen when the combo box has still no active iter */
804 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
805 gchar* incomingserver_title;
806 const gchar *protocol_display_name;
807 ModestProtocol *protocol;
809 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
811 protocol_display_name = modest_protocol_get_display_name (protocol);
813 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
814 protocol_display_name, ")</small>", NULL);
816 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
818 g_free(incomingserver_title);
822 /** Change the caption title for the incoming server,
823 * as specified in the UI spec:
826 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
828 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
829 ModestServertypePicker *server_type_picker;
830 ModestProtocolType protocol_type;
831 ModestSecurityOptionsView *view;
834 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
836 modest_servertype_picker_get_active_servertype (server_type_picker);
838 /* Fill the combo with appropriately titled choices for all
840 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
841 modest_security_options_view_set_server_type (view, protocol_type);
845 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
847 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
848 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
853 update_incoming_server_title (self);
855 /* Update security options if needed */
856 update_incoming_server_security_choices (self);
857 gtk_widget_show (priv->incoming_security);
859 set_default_custom_servernames (self);
863 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
865 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
866 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
868 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
872 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
874 ModestProtocolRegistry *protocol_registry;
875 ModestEasysetupWizardDialogPrivate* priv;
880 GtkSizeGroup *title_sizegroup;
881 GtkSizeGroup *value_sizegroup;
883 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
884 protocol_registry = modest_runtime_get_protocol_registry ();
886 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
887 pannable = hildon_pannable_area_new ();
889 /* Show note that account type cannot be changed in future: */
890 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
891 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
892 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
893 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
894 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
895 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
896 gtk_widget_show (label);
898 /* Create a size group to be used by all captions.
899 * Note that HildonCaption does not create a default size group if we do not specify one.
900 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
901 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
902 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
904 /* The incoming server widgets: */
905 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
906 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
908 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
909 _("mcen_li_emailsetup_type"),
910 priv->incoming_servertype_picker);
911 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
912 G_CALLBACK (on_picker_button_value_changed), self);
913 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, 0);
914 gtk_widget_show (priv->incoming_servertype_picker);
916 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
918 /* Auto-capitalization is the default, so let's turn it off: */
919 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
920 set_default_custom_servernames (self);
922 /* The caption title will be updated in update_incoming_server_title().
923 * so this default text will never be seen: */
924 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
925 "This will be removed",
926 FALSE, priv->entry_incomingserver);
927 update_incoming_server_title (self);
928 gtk_widget_show (priv->entry_incomingserver);
929 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
930 gtk_widget_show (priv->caption_incoming);
932 /* Remember when the servername was changed manually: */
933 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
934 G_CALLBACK (on_entry_incoming_servername_changed), self);
936 /* The secure connection widgets. These are only valid for
937 protocols with security */
938 priv->incoming_security =
939 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
940 FALSE, title_sizegroup, value_sizegroup);
941 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
943 gtk_widget_show (priv->incoming_security);
945 /* Set default selection */
946 modest_servertype_picker_set_active_servertype (
947 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
948 MODEST_PROTOCOLS_STORE_POP);
949 update_incoming_server_title (self);
950 update_incoming_server_security_choices (self);
951 set_default_custom_servernames (self);
953 /* Change the caption title when the servertype changes,
954 * as in the UI spec: */
955 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
957 G_CALLBACK (on_servertype_selector_changed), self);
959 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
960 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
961 gtk_widget_show (align);
962 gtk_container_add (GTK_CONTAINER (align), box);
964 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
965 gtk_widget_show (GTK_WIDGET (box));
966 gtk_widget_show (pannable);
968 g_object_unref (title_sizegroup);
969 g_object_unref (value_sizegroup);
971 /* Connect changed signals. We do it here after initializing everything */
972 g_signal_connect (G_OBJECT(priv->entry_incomingserver), "changed",
973 G_CALLBACK(on_easysetup_changed), self);
976 return GTK_WIDGET (pannable);
980 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
982 GtkWidget *widget = GTK_WIDGET (user_data);
984 /* Enable the widget only if the check button is active: */
985 const gboolean enable = hildon_check_button_get_active (button);
986 gtk_widget_set_sensitive (widget, enable);
989 /* Make the sensitivity of a widget depend on a check button.
992 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
994 g_signal_connect (G_OBJECT (button), "toggled",
995 G_CALLBACK (on_check_button_changed), widget);
997 /* Set the starting sensitivity: */
998 on_check_button_changed (button, widget);
1002 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
1004 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1005 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1006 GtkWidget *specific_window;
1008 /* We set dirty here because setting it depending on the connection specific dialog
1012 /* Create the window, if necessary: */
1013 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
1014 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
1016 /* Show the window */
1017 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
1018 gtk_widget_show (specific_window);
1022 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
1024 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1025 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1026 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
1030 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
1032 ModestEasysetupWizardDialogPrivate *priv;
1033 gchar *smtp_caption_label;
1034 GtkWidget *pannable;
1036 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1038 pannable = hildon_pannable_area_new ();
1040 /* Create a size group to be used by all captions.
1041 * Note that HildonCaption does not create a default size group if we do not specify one.
1042 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1043 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1044 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1046 /* The outgoing server widgets: */
1047 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1048 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
1050 /* Auto-capitalization is the default, so let's turn it off: */
1051 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
1052 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
1053 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
1054 smtp_caption_label, TRUE, priv->entry_outgoingserver);
1055 g_free (smtp_caption_label);
1056 gtk_widget_show (priv->entry_outgoingserver);
1057 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
1058 gtk_widget_show (caption);
1059 set_default_custom_servernames (self);
1061 /* The secure connection widgets. These are only valid for
1062 protocols with security */
1063 priv->outgoing_security =
1064 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
1065 FALSE, title_sizegroup, value_sizegroup);
1066 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
1068 gtk_widget_show (priv->outgoing_security);
1070 GtkWidget *separator = gtk_hseparator_new ();
1071 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
1072 gtk_widget_show (separator);
1074 /* connection-specific checkbox: */
1075 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
1076 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1078 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1079 _("mcen_fi_advsetup_connection_smtp"));
1080 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1083 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1084 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
1087 /* Connection-specific SMTP-Severs Edit button: */
1088 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
1089 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
1090 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1091 gtk_widget_show (priv->button_outgoing_smtp_servers);
1092 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
1095 /* Only enable the button when the checkbox is checked: */
1096 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
1097 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
1099 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1100 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1102 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1103 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1106 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1107 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1108 gtk_widget_show (align);
1109 gtk_container_add (GTK_CONTAINER (align), box);
1111 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
1112 gtk_widget_show (GTK_WIDGET (box));
1113 gtk_widget_show (pannable);
1115 g_object_unref (title_sizegroup);
1116 g_object_unref (value_sizegroup);
1118 /* Connect changed signals. We do it here after initializing everything */
1119 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1120 G_CALLBACK (on_easysetup_changed), self);
1121 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1122 G_CALLBACK (on_easysetup_changed), self);
1124 return GTK_WIDGET (pannable);
1128 show_advanced_edit(gpointer user_data)
1130 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1131 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1134 /* Show the Account Settings window: */
1135 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
1136 if (priv->pending_load_settings) {
1137 save_to_settings (self);
1138 priv->pending_load_settings = FALSE;
1140 modest_account_settings_dialog_load_settings (dialog, priv->settings);
1142 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
1144 response = gtk_dialog_run (GTK_DIALOG (dialog));
1146 gtk_widget_destroy (GTK_WIDGET (dialog));
1148 return FALSE; /* Do not call this timeout callback again. */
1152 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1154 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1156 /* Show the Account Settings window: */
1157 show_advanced_edit(self);
1160 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1162 gchar *complete_string;
1166 GtkWidget *button_edit;
1168 box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1169 complete_string = g_strconcat (_("mcen_ia_emailsetup_setup_complete"), " ",
1170 _("mcen_ia_customsetup_complete"), NULL);
1171 label = gtk_label_new(complete_string);
1172 g_free (complete_string);
1173 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1174 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1175 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1176 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1177 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1178 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1179 gtk_widget_show (label);
1181 button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1182 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1183 gtk_widget_show (button_edit);
1184 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, 0);
1186 g_signal_connect (G_OBJECT (button_edit), "clicked",
1187 G_CALLBACK (on_button_edit_advanced_settings), self);
1189 gtk_widget_show (GTK_WIDGET (box));
1191 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1192 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
1193 gtk_widget_show (align);
1194 gtk_container_add (GTK_CONTAINER (align), box);
1196 return GTK_WIDGET (align);
1203 on_response (ModestWizardDialog *wizard_dialog,
1207 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1209 invoke_enable_buttons_vfunc (self);
1213 on_response_before (ModestWizardDialog *wizard_dialog,
1217 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1218 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1219 if (response_id == GTK_RESPONSE_CANCEL) {
1220 /* This is mostly copied from
1221 * src/maemo/modest-account-settings-dialog.c */
1223 gint dialog_response;
1226 dialog = hildon_note_new_confirmation ((GtkWindow *) self,
1227 _("imum_nc_wizard_confirm_lose_changes"));
1229 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
1230 (GtkWindow *) dialog,
1231 (GtkWindow *) wizard_dialog);
1233 dialog_response = gtk_dialog_run ((GtkDialog *) dialog);
1234 gtk_widget_destroy (GTK_WIDGET (dialog));
1236 if (dialog_response != GTK_RESPONSE_OK) {
1237 /* Don't let the dialog close */
1238 g_signal_stop_emission_by_name (wizard_dialog, "response");
1245 fill_providers (ModestEasysetupWizardDialog *self)
1247 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1249 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1250 /* gint mcc = get_default_country_code(); */
1252 /* Fill the combo in an idle call, as it takes a lot of time */
1253 modest_country_picker_load_data(
1254 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1255 /* connect to country picker's changed signal, so we can fill the provider picker: */
1256 g_signal_connect ((GObject *) priv->account_country_picker,
1258 G_CALLBACK (on_account_country_selector_changed), self);
1260 modest_country_picker_set_active_country_locale (
1261 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1262 mcc = modest_country_picker_get_active_country_mcc (
1263 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1264 modest_provider_picker_fill (
1265 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1266 priv->presets, mcc);
1267 /* connect to providers picker's changed signal, so we can fill the email address: */
1268 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1269 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1271 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1273 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1276 priv->dirty = FALSE;
1280 typedef struct IdleData {
1281 ModestEasysetupWizardDialog *dialog;
1282 ModestPresets *presets;
1286 presets_idle (gpointer userdata)
1288 IdleData *idle_data = (IdleData *) userdata;
1289 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1290 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1292 g_assert (idle_data->presets);
1294 gdk_threads_enter ();
1296 priv->presets = idle_data->presets;
1298 if (priv->check_support_done)
1299 fill_providers (self);
1301 g_object_unref (idle_data->dialog);
1304 gdk_threads_leave ();
1310 presets_loader (gpointer userdata)
1312 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1313 ModestPresets *presets = NULL;
1314 IdleData *idle_data;
1316 const gchar* path = NULL;
1317 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1318 const gchar* path2 = MODEST_FALLBACK_PROVIDER_DATA_FILE;
1320 if (access(path1, R_OK) == 0)
1322 else if (access(path2, R_OK) == 0)
1325 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1326 __FUNCTION__, path1, path2);
1330 presets = modest_presets_new (path);
1332 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1336 idle_data = g_new0 (IdleData, 1);
1337 idle_data->dialog = self;
1338 idle_data->presets = presets;
1340 g_idle_add (presets_idle, idle_data);
1346 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1352 /* Append page and set attributes */
1353 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1354 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1355 "tab-expand", TRUE, "tab-fill", TRUE,
1358 /* Give focus to page and show it */
1359 gtk_container_set_focus_child (GTK_CONTAINER (notebook), page);
1360 gtk_widget_show (page);
1364 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1366 priv->page_user_details = NULL;
1367 priv->entry_user_name = NULL;
1368 priv->entry_user_username = NULL;
1369 priv->entry_user_password = NULL;
1370 priv->entry_user_email = NULL;
1374 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1376 priv->page_custom_incoming = NULL;
1377 priv->incoming_servertype_picker = NULL;
1378 priv->caption_incoming = NULL;
1379 priv->entry_incomingserver = NULL;
1380 priv->entry_user_email = NULL;
1381 priv->incoming_security = NULL;
1385 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1387 priv->page_custom_outgoing = NULL;
1388 priv->entry_outgoingserver = NULL;
1389 priv->checkbox_outgoing_smtp_specific = NULL;
1390 priv->button_outgoing_smtp_servers = NULL;
1391 priv->outgoing_security = NULL;
1395 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1397 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1399 /* Create the notebook to be used by the ModestWizardDialog base class:
1400 * Each page of the notebook will be a page of the wizard: */
1401 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1402 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1404 /* Set the notebook used by the ModestWizardDialog base class: */
1405 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1407 /* Set the wizard title:
1408 * The actual window title will be a combination of this and the page's tab label title. */
1409 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1411 /* Read in the information about known service providers: */
1412 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1414 /* The server fields did not have been manually changed yet */
1415 priv->server_changes = 0;
1416 priv->pending_load_settings = TRUE;
1418 /* Get the account manager object,
1419 * so we can check for existing accounts,
1420 * and create new accounts: */
1421 priv->account_manager = modest_runtime_get_account_mgr ();
1422 g_object_ref (priv->account_manager);
1424 /* Initialize fields */
1425 priv->check_support_done = FALSE;
1426 priv->check_support_show_progress_id = 0;
1427 priv->pending_check_support = 0;
1428 priv->destroyed = FALSE;
1429 priv->page_welcome = create_page_welcome (self);
1430 gtk_widget_show (priv->page_welcome);
1431 priv->page_account_details = create_page_account_details (self);
1433 init_user_page (priv);
1434 init_incoming_page (priv);
1435 init_outgoing_page (priv);
1437 priv->page_complete_easysetup = NULL;
1438 priv->page_complete_customsetup = NULL;
1439 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1440 priv->missing_data_signals = NULL;
1442 /* Add the common pages */
1443 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1444 _("mcen_ti_emailsetup_welcome"));
1445 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1446 _("mcen_ti_accountdetails"));
1448 /* Connect to the dialog's response signal so we can enable/disable buttons
1449 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1450 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1451 * so that we can be enable/disable after ModestWizardDialog has done its own
1452 * enabling/disabling of buttons.
1454 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1455 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1457 * It's not enough to connect to the notebook's switch-page signal, because
1458 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1459 * _after_ switching the page (understandably).
1460 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1461 * then gtk_notebook_get_current_page() would return an incorrect value.)
1463 g_signal_connect_after (G_OBJECT (self), "response",
1464 G_CALLBACK (on_response), self);
1466 /* This is to show a confirmation dialog when the user hits cancel */
1467 g_signal_connect (G_OBJECT (self), "response",
1468 G_CALLBACK (on_response_before), self);
1470 g_signal_connect (G_OBJECT (self), "delete-event",
1471 G_CALLBACK (on_delete_event), self);
1473 /* Reset dirty, because there was no user input until now */
1474 priv->dirty = FALSE;
1476 /* When this window is shown, hibernation should not be possible,
1477 * because there is no sensible way to save the state: */
1478 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1479 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1481 /* Load provider presets */
1482 g_object_ref (self);
1483 g_thread_create (presets_loader, self, FALSE, NULL);
1485 priv->settings = modest_account_settings_new ();
1489 ModestEasysetupWizardDialog*
1490 modest_easysetup_wizard_dialog_new (void)
1493 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1497 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1499 ModestEasysetupWizardDialogPrivate *priv;
1500 GtkNotebook *notebook = NULL;
1502 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1505 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1507 if (!priv->page_user_details) {
1508 priv->page_user_details = create_page_user_details (self);
1511 /* Create the custom pages: */
1512 if(!(priv->page_custom_incoming)) {
1513 priv->page_custom_incoming = create_page_custom_incoming (self);
1516 /* TODO: only if needed */
1517 if(!(priv->page_custom_outgoing)) {
1518 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1521 if(!(priv->page_complete_customsetup)) {
1522 priv->page_complete_customsetup = create_page_complete_custom (self);
1525 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1526 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1527 _("mcen_ti_emailsetup_userdetails"));
1529 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1530 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1531 _("mcen_ti_emailsetup_incomingdetails"));
1533 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1534 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1535 _("mcen_ti_emailsetup_outgoingdetails"));
1537 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1538 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1539 _("mcen_ti_emailsetup_complete"));
1541 /* This is unnecessary with GTK+ 2.10: */
1542 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1546 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1548 ModestEasysetupWizardDialogPrivate *priv;
1549 GtkNotebook *notebook = NULL;
1551 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1554 /* Create the easysetup-specific pages: */
1555 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1556 if(!priv->page_complete_easysetup)
1557 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1559 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1560 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1561 _("mcen_ti_emailsetup_complete"));
1563 /* This is unnecessary with GTK+ 2.10: */
1564 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1569 remove_non_common_tabs (ModestEasysetupWizardDialog *self,
1570 gboolean remove_user_details)
1573 GtkNotebook *notebook;
1574 ModestEasysetupWizardDialogPrivate *priv;
1576 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1577 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1579 /* The first 2 tabs are the common ones (welcome tab and the
1580 providers tab), so we always remove starting from the
1582 starting_tab = (remove_user_details) ? 2 : 3;
1583 while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
1584 /* Disconnect signal */
1585 GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
1586 if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
1587 priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
1589 "missing-mandatory-data");
1591 /* Remove page from notebook */
1592 gtk_notebook_remove_page (notebook, -1);
1597 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1601 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1604 /* After the user details page,
1605 * the following pages depend on whether "Other" was chosen
1606 * in the provider combobox on the account page
1609 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1611 ModestEasysetupWizardDialogPrivate *priv;
1612 ModestProviderPicker *picker;
1613 ModestProviderPickerIdType id_type;
1614 GtkNotebook *notebook;
1616 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1617 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1618 id_type = modest_provider_picker_get_active_id_type (picker);
1619 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1621 /* Remove the response override handler for non-plugin
1622 protocols. For plugins it'll be overriden later */
1623 if (id_type != MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL)
1624 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1628 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1629 /* "Other..." was selected: */
1631 /* If we come from a rollbacked easysetup */
1632 if (priv->page_complete_easysetup) {
1633 remove_non_common_tabs (self, FALSE);
1634 priv->page_complete_easysetup = NULL;
1637 /* If we come from a rollbacked plugin protocol setup */
1638 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1639 remove_non_common_tabs (self, TRUE);
1640 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1641 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1642 priv->missing_data_signals = NULL;
1645 create_subsequent_customsetup_pages (self);
1647 /* If we come from a rollbacked custom setup */
1648 if (priv->page_custom_incoming) {
1649 remove_non_common_tabs (self, TRUE);
1650 init_user_page (priv);
1651 init_incoming_page (priv);
1652 init_outgoing_page (priv);
1653 init_user_page (priv);
1654 priv->page_complete_customsetup = NULL;
1657 /* It's a pluggable protocol and not a provider with presets */
1658 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1659 ModestProtocol *protocol;
1661 ModestProtocolType proto_type;
1662 ModestWizardDialogResponseOverrideFunc response_override;
1664 /* Get protocol data */
1665 proto_name = modest_provider_picker_get_active_provider_id (picker);
1666 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1667 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1669 proto_type = modest_protocol_get_type_id (protocol);
1672 /* If we come from a rollbacked easy setup */
1673 if (priv->last_plugin_protocol_selected != proto_type &&
1674 priv->page_complete_easysetup) {
1675 remove_non_common_tabs (self, TRUE);
1676 init_user_page (priv);
1677 priv->page_complete_easysetup = NULL;
1680 /* Ensure that the response override handler
1681 is set. It might happen that plugins clear
1683 response_override = modest_account_protocol_get_wizard_response_override
1684 (MODEST_ACCOUNT_PROTOCOL (protocol));
1685 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1688 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1689 proto_type != priv->last_plugin_protocol_selected) {
1690 ModestPairList *tabs;
1692 gboolean first_page = TRUE;
1694 /* Remember the last selected plugin protocol */
1695 priv->last_plugin_protocol_selected = proto_type;
1698 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1699 tmp = (GSList *) tabs;
1701 ModestPair *pair = (ModestPair *) tmp->data;
1702 modest_easysetup_wizard_dialog_append_page (notebook,
1703 GTK_WIDGET (pair->second),
1704 (const gchar *) pair->first);
1706 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1707 GTK_WIDGET (pair->second));
1711 /* Connect signals */
1712 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1713 priv->missing_data_signals =
1714 modest_signal_mgr_connect (priv->missing_data_signals,
1715 G_OBJECT (pair->second),
1716 "missing-mandatory-data",
1717 G_CALLBACK (on_missing_mandatory_data),
1721 g_free (pair->first);
1722 tmp = g_slist_next (tmp);
1723 /* Critical: if you don't show the page then the dialog will ignore it */
1724 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1726 modest_pair_list_free (tabs);
1728 g_free (proto_name);
1730 if (priv->last_plugin_protocol_selected !=
1731 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1732 remove_non_common_tabs (self, TRUE);
1733 init_user_page (priv);
1734 priv->page_complete_easysetup = NULL;
1735 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1736 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1737 priv->missing_data_signals = NULL;
1739 if (!priv->page_user_details) {
1740 priv->page_user_details = create_page_user_details (self);
1741 modest_easysetup_wizard_dialog_append_page (notebook,
1742 priv->page_user_details,
1743 _("mcen_ti_emailsetup_userdetails"));
1747 /* Create the easysetup pages: */
1748 create_subsequent_easysetup_pages (self);
1754 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1756 const gchar* hostname = NULL;
1759 ModestProtocolRegistry *protocol_registry;
1760 ModestProtocol *protocol;
1765 at = g_utf8_strchr (email_address, -1, '@');
1766 if (!at || (g_utf8_strlen (at, -1) < 2))
1769 domain = g_utf8_next_char (at);
1773 protocol_registry = modest_runtime_get_protocol_registry ();
1774 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1776 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1777 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1778 hostname = modest_protocol_get_name (protocol);
1784 return g_strdup_printf ("%s.%s", hostname, domain);
1788 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1790 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1792 if (!priv->entry_incomingserver)
1795 /* Set a default domain for the server, based on the email address,
1796 * if no server name was already specified.
1798 if (priv->entry_user_email
1799 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1800 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1801 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1803 /* This could happen when the combo box has still no active iter */
1804 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1805 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1806 gchar* servername = util_get_default_servername_from_email_address (email_address,
1809 /* Do not set the INCOMING_CHANGED flag because of this edit */
1810 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1811 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1812 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1814 g_free (servername);
1818 /* Set a default domain for the server, based on the email address,
1819 * if no server name was already specified.
1821 if (!priv->entry_outgoingserver)
1824 if (priv->entry_user_email
1825 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1826 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1828 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1830 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1831 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1832 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1833 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1835 g_free (servername);
1840 get_entered_account_title (ModestEasysetupWizardDialog *self)
1842 ModestEasysetupWizardDialogPrivate *priv;
1843 const gchar* account_title;
1845 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1846 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1848 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1851 /* Strip it of whitespace at the start and end: */
1852 gchar *result = g_strdup (account_title);
1853 result = g_strstrip (result);
1858 if (g_utf8_strlen (result, -1) == 0) {
1868 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1870 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1871 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1872 ModestProtocolRegistry *protocol_registry;
1874 protocol_registry = modest_runtime_get_protocol_registry ();
1876 /* if are browsing pages previous to the last one, then we have pending settings in
1878 if (next_page != NULL)
1879 priv->pending_load_settings = TRUE;
1881 /* Do extra validation that couldn't be done for every key press,
1882 * either because it was too slow,
1883 * or because it requires interaction:
1885 if (current_page == priv->page_welcome) {
1886 if (!priv->check_support_done) {
1887 check_support_of_protocols (self);
1888 return priv->check_support_done;
1890 } else if (current_page == priv->page_account_details) {
1891 /* Check that the title is not already in use: */
1892 gchar* account_title = get_entered_account_title (self);
1896 /* Aavoid a clash with an existing display name: */
1897 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1898 priv->account_manager, account_title);
1899 g_free (account_title);
1902 /* Warn the user via a dialog: */
1903 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1908 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1909 create_subsequent_pages (self);
1911 } else if (current_page == priv->page_user_details) {
1912 /* Check that the email address is valud: */
1913 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1914 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1917 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1918 /* Warn the user via a dialog: */
1919 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1921 /* Return focus to the email address entry: */
1922 gtk_widget_grab_focus (priv->entry_user_email);
1923 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1927 } else if (current_page == priv->page_custom_incoming ||
1928 current_page == priv->page_custom_outgoing) {
1930 const gchar *hostname;
1931 GtkWidget *entry = (current_page == priv->page_custom_incoming) ?
1932 priv->entry_incomingserver :
1933 priv->entry_outgoingserver;
1935 hostname = gtk_entry_get_text (GTK_ENTRY (entry));
1936 if (!modest_text_utils_validate_domain_name (hostname)) {
1938 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
1940 /* Return focus to the email address entry: */
1941 gtk_widget_grab_focus (entry);
1942 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
1948 if (next_page == priv->page_custom_incoming) {
1949 set_default_custom_servernames (self);
1950 } else if (next_page == priv->page_custom_outgoing) {
1951 set_default_custom_servernames (self);
1953 /* Check if the server supports secure authentication */
1954 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
1955 if (!check_has_supported_auth_methods (self))
1957 gtk_widget_show (priv->outgoing_security);
1960 /* If this is the last page, and this is a click on Finish,
1961 * then attempt to create the dialog.
1964 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1966 if (priv->pending_load_settings) {
1967 save_to_settings (self);
1970 /* We check if there's already another account with the same configuration */
1971 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1972 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1976 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1983 static gboolean entry_is_empty (GtkWidget *entry)
1988 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1989 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1992 /* Strip it of whitespace at the start and end: */
1993 gchar *stripped = g_strdup (text);
1994 stripped = g_strstrip (stripped);
1999 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
2007 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
2009 GtkNotebook *notebook = NULL;
2010 gboolean is_finish_tab;
2012 ModestEasysetupWizardDialogPrivate *priv;
2015 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
2016 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
2018 /* Disable the Finish button until we are on the last page,
2019 * because HildonWizardDialog enables this for all but the
2021 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
2022 is_finish_tab = ((current == priv->page_complete_easysetup) ||
2023 (current == priv->page_complete_customsetup));
2025 if (is_finish_tab) {
2026 /* Disable Next on the last page no matter what the
2028 enable_next = FALSE;
2030 /* Not the last one */
2031 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2032 MODEST_WIZARD_DIALOG_FINISH,
2035 /* If the check support is not done then do not enable
2036 the wizard to continue */
2037 enable_next = enable_next && priv->pending_check_support == 0;
2040 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2041 MODEST_WIZARD_DIALOG_NEXT,
2046 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
2048 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2049 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2051 gboolean enable_next = TRUE;
2052 if (current_page == priv->page_welcome) {
2054 } else if (current_page == priv->page_account_details) {
2055 /* The account details title is mandatory: */
2056 if (entry_is_empty(priv->entry_account_title))
2057 enable_next = FALSE;
2058 } else if (current_page == priv->page_user_details) {
2059 /* The user details username is mandatory: */
2060 if (entry_is_empty(priv->entry_user_username))
2061 enable_next = FALSE;
2063 /* The user details email address is mandatory: */
2064 if (enable_next && entry_is_empty (priv->entry_user_email))
2065 enable_next = FALSE;
2066 } else if (current_page == priv->page_custom_incoming) {
2067 /* The custom incoming server is mandatory: */
2068 if (entry_is_empty(priv->entry_incomingserver))
2069 enable_next = FALSE;
2070 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
2071 enable_next = !modest_easysetup_wizard_page_validate (
2072 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
2075 /* Enable/disable buttons */
2076 real_enable_buttons (dialog, enable_next);
2080 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
2082 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2083 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
2086 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
2087 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
2089 /* Provide a vfunc implementation so we can decide
2090 * when to enable/disable the prev/next buttons.
2092 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
2093 base_klass->before_next = on_before_next;
2094 base_klass->enable_buttons = on_enable_buttons;
2095 base_klass->update_model = on_update_model;
2096 base_klass->save = on_save;
2101 * @self: a #ModestEasysetupWizardDialog
2103 * takes information from all the wizard and stores it in settings
2106 save_to_settings (ModestEasysetupWizardDialog *self)
2108 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2110 gchar *provider_id = NULL;
2111 gchar* display_name;
2112 const gchar *username, *password;
2113 gchar *store_hostname, *transport_hostname;
2114 guint store_port, transport_port;
2115 ModestProtocolRegistry *protocol_registry;
2116 ModestProtocolType store_protocol, transport_protocol;
2117 ModestProtocolType store_security, transport_security;
2118 ModestProtocolType store_auth_protocol, transport_auth_protocol;
2119 ModestServerAccountSettings *store_settings, *transport_settings;
2120 const gchar *fullname, *email_address;
2121 ModestProviderPicker *picker;
2122 ModestProviderPickerIdType id_type;
2124 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2125 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
2126 protocol_registry = modest_runtime_get_protocol_registry ();
2128 /* Get details from the specified presets: */
2129 id_type = modest_provider_picker_get_active_id_type (picker);
2130 provider_id = modest_provider_picker_get_active_provider_id (picker);
2132 /* Let the plugin save the settings. We do a return in order
2133 to save an indentation level */
2134 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
2135 ModestProtocol *protocol;
2137 protocol = modest_protocol_registry_get_protocol_by_name (
2138 modest_runtime_get_protocol_registry (),
2139 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
2142 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
2143 gint n_pages, i = 0;
2144 GtkNotebook *notebook;
2145 GList *wizard_pages = NULL;
2147 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
2148 n_pages = gtk_notebook_get_n_pages (notebook);
2149 for (i = 0; i < n_pages; i++) {
2150 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
2151 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
2152 wizard_pages = g_list_append (wizard_pages, page);
2154 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
2157 g_list_free (wizard_pages);
2159 g_debug ("The selected protocol is a plugin protocol "//
2160 "but it's not a ModestAccountProtocol");
2163 g_free (provider_id);
2167 /* username and password (for both incoming and outgoing): */
2168 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
2169 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
2171 store_settings = modest_account_settings_get_store_settings (priv->settings);
2172 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
2174 /* Incoming server: */
2175 /* Note: We need something as default for the transport store protocol values,
2176 * or modest_account_mgr_add_server_account will fail. */
2178 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2179 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2180 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2183 ModestProtocolType store_provider_server_type;
2184 gboolean store_provider_use_alternate_port;
2186 store_hostname = modest_presets_get_server (priv->presets, provider_id,
2189 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2192 store_security = modest_presets_get_info_server_security (priv->presets,
2195 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
2198 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
2202 /* We don't check for SMTP here as that is impossible for an incoming server. */
2203 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
2204 store_protocol = MODEST_PROTOCOLS_STORE_POP;
2206 store_protocol = store_provider_server_type;
2208 /* we check if there is a *special* port */
2209 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
2210 if (special_port != 0) {
2211 store_port = special_port;
2213 gboolean use_alternate_port = FALSE;
2214 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2216 use_alternate_port = TRUE;
2217 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
2220 modest_server_account_settings_set_security_protocol (store_settings,
2222 modest_server_account_settings_set_auth_protocol (store_settings,
2223 store_auth_protocol);
2224 if (store_port != 0)
2225 modest_server_account_settings_set_port (store_settings, store_port);
2227 /* Use custom pages because no preset was specified: */
2228 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
2229 store_protocol = modest_servertype_picker_get_active_servertype (
2230 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2232 modest_security_options_view_save_settings (
2233 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2237 /* now we store the common store account settings */
2238 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2239 modest_server_account_settings_set_username (store_settings, username);
2240 modest_server_account_settings_set_password (store_settings, password);
2241 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2243 g_object_unref (store_settings);
2244 g_free (store_hostname);
2246 /* Outgoing server: */
2247 transport_hostname = NULL;
2248 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2249 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2250 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2254 ModestProtocolType transport_provider_server_type;
2255 ModestProtocolType transport_provider_security;
2259 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2260 FALSE /* transport */);
2262 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2264 FALSE /* transport */);
2265 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2267 FALSE /* transport */);
2269 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2270 transport_protocol = transport_provider_server_type;
2271 transport_security = transport_provider_security;
2272 is_secure = modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2273 transport_security);
2275 /* we check if there is a *special* port */
2276 special_port = modest_presets_get_port (priv->presets, provider_id,
2277 FALSE /* transport */);
2278 if (special_port != 0) {
2279 transport_port = special_port;
2281 gboolean use_alternate_port = FALSE;
2282 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL)
2283 use_alternate_port = TRUE;
2284 transport_port = get_port_from_protocol(transport_provider_server_type, use_alternate_port);
2288 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2290 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2292 modest_server_account_settings_set_security_protocol (transport_settings,
2293 transport_security);
2294 modest_server_account_settings_set_auth_protocol (transport_settings,
2295 transport_auth_protocol);
2296 if (transport_port != 0)
2297 modest_server_account_settings_set_port (transport_settings,
2300 ModestProtocolRegistry *registry;
2301 ModestProtocol *store_proto;
2303 registry = modest_runtime_get_protocol_registry ();
2304 /* Use custom pages because no preset was specified: */
2305 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2307 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2310 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2311 /* fallback to SMTP if none was specified */
2312 g_warning ("No transport protocol was specified for store %d (%s)",
2313 modest_protocol_get_type_id (store_proto),
2314 modest_protocol_get_display_name (store_proto));
2315 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2318 modest_security_options_view_save_settings (
2319 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2323 /* now we store the common transport account settings */
2324 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2325 modest_server_account_settings_set_username (transport_settings, username);
2326 modest_server_account_settings_set_password (transport_settings, password);
2327 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2329 g_object_unref (transport_settings);
2330 g_free (transport_hostname);
2332 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2333 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2334 modest_account_settings_set_fullname (priv->settings, fullname);
2335 modest_account_settings_set_email_address (priv->settings, email_address);
2336 /* we don't set retrieve type to preserve advanced settings if
2337 any. By default account settings are set to headers only */
2339 /* Save the connection-specific SMTP server accounts. */
2340 if (priv->checkbox_outgoing_smtp_specific) {
2341 modest_account_settings_set_use_connection_specific_smtp
2343 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2346 display_name = get_entered_account_title (self);
2347 modest_account_settings_set_display_name (priv->settings, display_name);
2348 g_free (display_name);
2349 g_free (provider_id);
2351 /* This values are hardcoded for Fremantle */
2352 modest_account_settings_set_retrieve_type (priv->settings,
2353 MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS);
2354 modest_account_settings_set_retrieve_limit (priv->settings, 20);
2359 on_update_model (ModestWizardDialog *dialog)
2361 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2362 save_to_settings (self);
2367 on_save (ModestWizardDialog *dialog)
2369 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2370 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2372 save_to_settings (self);
2374 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2375 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2379 return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2385 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2387 GError *error = NULL;
2388 ModestProtocolType protocol_type;
2389 const gchar* hostname;
2390 const gchar* username;
2391 ModestProtocolType security_protocol_incoming_type;
2392 ModestProtocolRegistry *registry;
2394 GList *list_auth_methods;
2395 ModestEasysetupWizardDialogPrivate *priv;
2397 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2398 registry = modest_runtime_get_protocol_registry ();
2399 protocol_type = modest_servertype_picker_get_active_servertype (
2400 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2401 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2402 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2403 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2404 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2405 port_num = get_port_from_protocol(protocol_type, FALSE);
2406 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2407 username, GTK_WINDOW (self), &error);
2409 if (list_auth_methods) {
2410 /* TODO: Select the correct method */
2413 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2414 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2415 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2416 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2417 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2421 g_list_free(list_auth_methods);
2427 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2428 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2430 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2431 _("mcen_ib_unableto_discover_auth_methods"));
2435 g_error_free(error);
2441 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2443 GList* methods = check_for_supported_auth_methods(self);
2449 g_list_free(methods);
2454 check_support_show_progress (gpointer userdata)
2456 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2457 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2459 priv->check_support_show_progress_id = 0;
2461 if (priv->destroyed)
2464 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
2470 check_support_callback (ModestAccountProtocol *protocol,
2474 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2475 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2477 priv->pending_check_support --;
2479 if (priv->check_support_show_progress_id > 0) {
2480 g_source_remove (priv->check_support_show_progress_id);
2481 priv->check_support_show_progress_id = 0;
2484 if (priv->pending_check_support == 0) {
2485 priv->check_support_done = TRUE;
2487 if (!priv->destroyed) {
2489 fill_providers (self);
2490 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
2491 invoke_enable_buttons_vfunc (self);
2492 gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
2495 g_object_unref (self);
2500 check_support_of_protocols (ModestEasysetupWizardDialog *self)
2502 ModestProtocolRegistry *registry;
2503 GSList *provider_protos, *node;
2504 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2506 registry = modest_runtime_get_protocol_registry ();
2507 provider_protos = modest_protocol_registry_get_by_tag (registry,
2508 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2510 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2511 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2513 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2514 modest_protocol_get_type_id (proto),
2515 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2518 if (modest_protocol_registry_protocol_type_has_tag
2520 modest_protocol_get_type_id (proto),
2521 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2522 /* Check if there's already an account configured with this account type */
2523 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2524 modest_protocol_get_type_id (proto)))
2528 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2529 priv->pending_check_support ++;
2530 modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
2531 check_support_callback,
2532 g_object_ref (self));
2535 g_slist_free (provider_protos);
2537 if (priv->pending_check_support > 0) {
2538 priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
2539 check_support_show_progress,
2540 g_object_ref (self), g_object_unref);
2542 priv->check_support_done = TRUE;
2544 invoke_enable_buttons_vfunc (self);