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/gtkmessagedialog.h>
40 #include <gtk/gtkseparator.h>
41 #include "widgets/modest-validating-entry.h"
42 #include "modest-text-utils.h"
43 #include "modest-conf.h"
44 #include "modest-defs.h"
45 #include "modest-account-mgr.h"
46 #include "modest-signal-mgr.h"
47 #include "modest-account-mgr-helpers.h"
48 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
49 #include "modest-connection-specific-smtp-window.h"
50 #include "widgets/modest-ui-constants.h"
51 #include "widgets/modest-default-account-settings-dialog.h"
52 #include "widgets/modest-easysetup-wizard-page.h"
53 #include "modest-utils.h"
54 #include "modest-account-protocol.h"
55 #include "modest-address-book.h"
56 #include <modest-scrollable.h>
57 #include <modest-toolkit-factory.h>
58 #include <modest-toolkit-utils.h>
59 #ifdef MODEST_TOOLKIT_HILDON2
60 #include <hildon/hildon.h>
63 /* Include config.h so that _() works: */
68 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
70 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
71 MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
72 ModestEasysetupWizardDialogPrivate))
74 #define LABELS_WIDTH 520
75 #define DIALOG_WIDTH LABELS_WIDTH + MODEST_MARGIN_DOUBLE
77 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
81 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
82 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
83 } ModestEasysetupWizardDialogServerChanges;
85 struct _ModestEasysetupWizardDialogPrivate
87 ModestPresets *presets;
89 /* Remember what fields the user edited manually to not prefill them
91 ModestEasysetupWizardDialogServerChanges server_changes;
93 /* Check if the user changes a field to show a confirmation dialog */
96 /* If we have a pending load of settings or not. */
97 gboolean pending_load_settings;
99 /* Used by derived widgets to query existing accounts,
100 * and to create new accounts: */
101 ModestAccountMgr *account_manager;
102 ModestAccountSettings *settings;
104 /* notebook pages: */
105 GtkWidget *page_welcome;
106 gboolean check_support_done;
107 guint check_support_show_progress_id;
108 guint check_support_progress_pulse_id;
109 GtkWidget *check_support_cancel_note;
110 GtkWidget *check_support_progress;
111 gint pending_check_support;
114 GtkWidget *page_account_details;
115 GtkWidget *account_country_selector;
116 GtkWidget *account_serviceprovider_selector;
117 GtkWidget *entry_account_title;
118 GtkWidget *caption_account_title;
120 GtkWidget *page_user_details;
121 GtkWidget *entry_user_name;
122 GtkWidget *entry_user_username;
123 GtkWidget *entry_user_password;
124 GtkWidget *entry_user_email;
126 GtkWidget *page_complete_easysetup;
128 GtkWidget *page_custom_incoming;
129 GtkWidget *incoming_servertype_selector;
130 GtkWidget *caption_incoming;
131 GtkWidget *entry_incomingserver;
133 /* Security widgets */
134 GtkWidget *incoming_security;
135 GtkWidget *outgoing_security;
137 GtkWidget *page_custom_outgoing;
138 GtkWidget *entry_outgoingserver;
139 GtkWidget *checkbox_outgoing_smtp_specific;
140 GtkWidget *button_outgoing_smtp_servers;
142 GtkWidget *page_complete_customsetup;
144 ModestProtocolType last_plugin_protocol_selected;
145 GSList *missing_data_signals;
148 static void save_to_settings (ModestEasysetupWizardDialog *self);
149 static void real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next);
150 static void on_update_model (ModestWizardDialog *dialog);
151 static gboolean on_save (ModestWizardDialog *dialog);
152 static GList* check_for_supported_auth_methods (ModestEasysetupWizardDialog* self);
153 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self);
154 static void check_support_callback (ModestAccountProtocol *protocol,
157 static void check_support_of_protocols (ModestEasysetupWizardDialog *self);
158 static gboolean check_support_show_progress (gpointer userdata);
159 static gboolean check_support_progress_pulse (gpointer userdata);
162 on_delete_event (GtkWidget *widget,
164 ModestEasysetupWizardDialog *wizard)
166 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
171 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
173 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
174 g_return_if_fail (priv != NULL);
179 modest_easysetup_wizard_dialog_dispose (GObject *object)
181 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (object);
182 priv->destroyed = TRUE;
184 if (priv->check_support_show_progress_id > 0) {
185 g_source_remove (priv->check_support_show_progress_id);
186 priv->check_support_show_progress_id = 0;
189 if (priv->check_support_progress_pulse_id > 0) {
190 g_source_remove (priv->check_support_progress_pulse_id);
191 priv->check_support_progress_pulse_id = 0;
194 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
195 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
199 modest_easysetup_wizard_dialog_finalize (GObject *object)
201 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
202 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
203 ModestProtocolRegistry *registry;
204 GSList *provider_protos, *node;
206 registry = modest_runtime_get_protocol_registry ();
207 provider_protos = modest_protocol_registry_get_by_tag (registry,
208 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
210 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
211 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
213 if (!modest_protocol_registry_protocol_type_has_tag (registry,
214 modest_protocol_get_type_id (proto),
215 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
218 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
219 modest_account_protocol_wizard_finished (MODEST_ACCOUNT_PROTOCOL (proto));
222 g_slist_free (provider_protos);
224 if (priv->account_manager)
225 g_object_unref (G_OBJECT (priv->account_manager));
228 modest_presets_destroy (priv->presets);
231 g_object_unref (priv->settings);
233 if (priv->missing_data_signals) {
234 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
235 priv->missing_data_signals = NULL;
238 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
242 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
245 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
247 #ifdef HILDON_PICKER_BUTTON
248 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
252 get_port_from_protocol (ModestProtocolType server_type,
253 gboolean alternate_port)
256 ModestProtocol *protocol;
257 ModestProtocolRegistry *protocol_registry;
259 protocol_registry = modest_runtime_get_protocol_registry ();
260 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
262 if (alternate_port) {
263 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
265 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
271 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
273 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
275 /* Call the vfunc, which may be overridden by derived classes: */
276 if (klass->enable_buttons) {
277 GtkNotebook *notebook = NULL;
278 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
280 const gint current_page_num = gtk_notebook_get_current_page (notebook);
281 if (current_page_num == -1)
284 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
285 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
290 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
292 ModestEasysetupWizardDialog *self;
294 g_return_if_fail (user_data);
296 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
298 invoke_enable_buttons_vfunc(self);
302 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
304 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
306 invoke_enable_buttons_vfunc(self);
310 on_picker_button_value_changed (GtkWidget *widget, gpointer user_data)
312 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
314 invoke_enable_buttons_vfunc(self);
318 on_serviceprovider_selector_value_changed (GtkWidget *widget, gpointer user_data)
320 gchar* default_account_name_start;
321 gchar* default_account_name;
322 ModestEasysetupWizardDialog *self;
323 ModestEasysetupWizardDialogPrivate *priv;
324 ModestProviderSelectorIdType provider_id_type;
325 ModestProtocol *protocol;
327 ModestProtocolType proto_type;
328 gboolean hide_account_title;
330 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
331 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
333 on_picker_button_value_changed (GTK_WIDGET (widget), user_data);
335 provider_id_type = modest_provider_selector_get_active_id_type (
336 priv->account_serviceprovider_selector);
337 if (provider_id_type == MODEST_PROVIDER_SELECTOR_ID_OTHER) {
338 default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
340 /* obtain properly the account name! */
341 default_account_name_start = modest_provider_selector_get_active_provider_label (widget);
343 default_account_name = modest_account_mgr_get_unused_account_display_name (
344 priv->account_manager, default_account_name_start);
345 g_free (default_account_name_start);
346 default_account_name_start = NULL;
348 hide_account_title = FALSE;
349 proto_name = modest_provider_selector_get_active_provider_id (priv->account_serviceprovider_selector);
350 if (proto_name != NULL) {
351 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
352 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
354 if (protocol != NULL) {
355 proto_type = modest_protocol_get_type_id (protocol);
357 hide_account_title = (modest_protocol_registry_protocol_type_has_tag
358 (modest_runtime_get_protocol_registry (),
360 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS) ||
361 modest_protocol_registry_protocol_type_has_tag
362 (modest_runtime_get_protocol_registry (),
364 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS));
368 if (hide_account_title)
369 gtk_widget_hide (priv->caption_account_title);
371 gtk_widget_show (priv->caption_account_title);
373 modest_entry_set_text (priv->entry_account_title, default_account_name);
374 g_free (default_account_name);
377 /** This is a convenience function to create a caption containing a mandatory widget.
378 * When the widget is edited, the enable_buttons() vfunc will be called.
381 create_captioned (ModestEasysetupWizardDialog *self,
382 GtkSizeGroup *title_size_group,
383 GtkSizeGroup *value_size_group,
390 result = modest_toolkit_utils_create_captioned_with_size_type (title_size_group, value_size_group,
391 value, use_markup, control,
392 MODEST_EDITABLE_SIZE);
394 /* Connect to the appropriate changed signal for the widget,
395 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
397 if (GTK_IS_ENTRY (control)) {
398 g_signal_connect (G_OBJECT (control), "changed",
399 G_CALLBACK (on_caption_entry_changed), self);
402 else if (GTK_IS_COMBO_BOX (control)) {
403 g_signal_connect (G_OBJECT (control), "changed",
404 G_CALLBACK (on_caption_combobox_changed), self);
411 create_page_welcome (ModestEasysetupWizardDialog *self)
416 GtkWidget *privacy_note;
417 GtkWidget *scrollable;
418 ModestEasysetupWizardDialogPrivate *priv;
420 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
421 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
422 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
423 label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
424 privacy_note = gtk_label_new (_("mcen_ia_privacy_notice"));
425 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
426 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
427 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
428 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
429 gtk_widget_set_size_request (privacy_note, LABELS_WIDTH, -1);
430 gtk_label_set_line_wrap (GTK_LABEL (privacy_note), TRUE);
431 #ifdef MODEST_TOOLKIT_HILDON2
432 hildon_helper_set_logical_font (privacy_note, "SmallSystemFont");
434 /* So that it is not truncated: */
435 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
436 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
437 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
438 gtk_box_pack_start (GTK_BOX (box), privacy_note, FALSE, FALSE, 0);
439 gtk_container_add (GTK_CONTAINER (align), box);
440 gtk_widget_show (label);
441 gtk_widget_show (privacy_note);
443 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
444 gtk_widget_show (GTK_WIDGET (box));
445 gtk_widget_show (GTK_WIDGET (align));
446 gtk_widget_show (scrollable);
448 return GTK_WIDGET (scrollable);
452 on_account_country_selector_changed (GtkWidget *widget, gpointer user_data)
454 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
456 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
460 /* Fill the providers selector, based on the selected country: */
461 if (priv->presets != NULL) {
462 gint mcc = modest_country_selector_get_active_country_mcc (priv->account_country_selector);
463 modest_provider_selector_fill (priv->account_serviceprovider_selector, priv->presets, mcc);
468 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
470 ModestEasysetupWizardDialogPrivate *priv;
471 gchar* provider_id = NULL, *with_at = NULL;
474 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
476 /* Fill the providers combo, based on the selected country: */
477 provider_id = modest_provider_selector_get_active_provider_id (
478 priv->account_serviceprovider_selector);
481 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
482 with_at = g_strdup_printf ("%c%s", '@', domain_name);
483 g_free (domain_name);
486 /* The sample address already contains the '@' */
488 with_at = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
490 if (priv->entry_user_email)
491 modest_entry_set_text (priv->entry_user_email, with_at);
494 g_free (provider_id);
497 #ifdef HILDON_PICKER_BUTTON
499 on_account_serviceprovider_selector_changed (GtkWidget *widget, gint column, gpointer user_data)
501 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
503 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
507 update_user_email_from_provider (self);
512 on_account_serviceprovider_selector_combo_box_changed (GtkWidget *widget, gpointer user_data)
514 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
516 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
520 update_user_email_from_provider (self);
524 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
526 modest_platform_information_banner (GTK_WIDGET (self), NULL,
527 _CS("ckdg_ib_maximum_characters_reached"));
531 create_page_account_details (ModestEasysetupWizardDialog *self)
534 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
535 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
536 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
538 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
539 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
540 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
541 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
542 gtk_widget_show (label);
544 /* Create a size group to be used by all captions.
545 * Note that HildonCaption does not create a default size group if we do not specify one.
546 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
547 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
548 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
550 /* The country widgets: */
551 priv->account_country_selector = modest_toolkit_factory_create_country_selector (modest_runtime_get_toolkit_factory ());
552 if (GTK_IS_COMBO_BOX (priv->account_country_selector)) {
553 GtkWidget *captioned;
554 g_signal_connect (G_OBJECT (priv->account_country_selector), "changed",
555 G_CALLBACK (on_picker_button_value_changed), self);
556 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
557 _("mcen_fi_country"), FALSE,
558 priv->account_country_selector);
560 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
561 gtk_widget_show (captioned);
563 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
564 _("mcen_fi_country"), priv->account_country_selector);
565 g_signal_connect (G_OBJECT (priv->account_country_selector), "value-changed",
566 G_CALLBACK (on_picker_button_value_changed), self);
567 gtk_box_pack_start (GTK_BOX (box), priv->account_country_selector, FALSE, FALSE, MODEST_MARGIN_HALF);
569 gtk_widget_show (priv->account_country_selector);
571 /* The service provider widgets: */
572 priv->account_serviceprovider_selector = modest_toolkit_factory_create_provider_selector (modest_runtime_get_toolkit_factory ());
573 if (GTK_IS_COMBO_BOX (priv->account_serviceprovider_selector)) {
574 GtkWidget *captioned;
575 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "changed",
576 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
577 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
578 _("mcen_fi_serviceprovider"), FALSE,
579 priv->account_serviceprovider_selector);
581 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "changed",
582 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
583 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
584 gtk_widget_show (captioned);
586 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
587 _("mcen_fi_serviceprovider"),
588 priv->account_serviceprovider_selector);
589 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "value-changed",
590 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
591 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_selector, FALSE, FALSE, 0);
593 gtk_widget_show (priv->account_serviceprovider_selector);
595 /* The description widgets: */
596 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
598 /* Do use auto-capitalization: */
600 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
601 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
604 /* Set a default account title, choosing one that does not already exist: */
605 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
606 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
607 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
608 priv->account_manager, default_account_name_start);
609 g_free (default_account_name_start);
610 default_account_name_start = NULL;
612 modest_entry_set_text (priv->entry_account_title, default_account_name);
613 g_free (default_account_name);
614 default_account_name = NULL;
616 /* Connect signal after changing the text in the entry */
617 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
618 G_CALLBACK(on_easysetup_changed), self);
620 priv->caption_account_title = create_captioned (self, title_sizegroup, value_sizegroup,
621 _("mcen_fi_account_title"), FALSE,
622 priv->entry_account_title);
623 gtk_widget_show (priv->entry_account_title);
624 gtk_box_pack_start (GTK_BOX (box), priv->caption_account_title, FALSE, FALSE, 0);
625 gtk_widget_show (priv->caption_account_title);
626 gtk_widget_set_no_show_all (priv->caption_account_title, TRUE);
628 /* Prevent the use of some characters in the account title,
629 * as required by our UI specification: */
630 GList *list_prevent = NULL;
631 list_prevent = g_list_append (list_prevent, "\\");
632 list_prevent = g_list_append (list_prevent, "/");
633 list_prevent = g_list_append (list_prevent, ":");
634 list_prevent = g_list_append (list_prevent, "*");
635 list_prevent = g_list_append (list_prevent, "?");
636 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
637 list_prevent = g_list_append (list_prevent, "“");
638 list_prevent = g_list_append (list_prevent, "<");
639 list_prevent = g_list_append (list_prevent, ">");
640 list_prevent = g_list_append (list_prevent, "|");
641 list_prevent = g_list_append (list_prevent, "^");
642 modest_validating_entry_set_unallowed_characters (
643 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
644 g_list_free (list_prevent);
646 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
647 modest_utils_on_entry_invalid_character, self);
649 /* Set max length as in the UI spec:
650 * The UI spec seems to want us to show a dialog if we hit the maximum. */
651 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
652 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
655 gtk_widget_show (GTK_WIDGET (box));
657 g_object_unref (title_sizegroup);
658 g_object_unref (value_sizegroup);
660 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
661 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
662 gtk_widget_show (align);
663 gtk_container_add (GTK_CONTAINER (align), box);
665 return GTK_WIDGET (align);
669 on_user_username_changed(GtkWidget* widget, ModestEasysetupWizardDialog *self)
671 ModestEasysetupWizardDialogPrivate* priv;
672 gchar* provider_id = NULL;
674 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
676 /* Work out the user email address */
677 provider_id = modest_provider_selector_get_active_provider_id (
678 priv->account_serviceprovider_selector);
681 const gchar *current_username;
682 gchar *email_address;
683 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
685 current_username = modest_entry_get_text (priv->entry_user_username);
687 if (current_username && strstr (current_username, "@")) {
688 email_address = g_strdup (current_username);
690 email_address = g_strdup_printf ("%s@%s",
695 /* Update the email address */
696 modest_entry_set_text (priv->entry_user_email, email_address);
698 g_free (email_address);
699 g_free (domain_name);
700 g_free (provider_id);
704 on_easysetup_changed(widget, self);
709 create_page_user_details (ModestEasysetupWizardDialog *self)
711 GtkSizeGroup* title_sizegroup;
712 GtkSizeGroup* value_sizegroup;
714 ModestEasysetupWizardDialogPrivate *priv;
716 const gchar *my_name;
718 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
720 /* Create a size group to be used by all captions.
721 * Note that HildonCaption does not create a default size group if we do not specify one.
722 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
723 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
724 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
725 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
727 /* The name widgets: (use auto cap) */
728 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
730 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
731 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
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_name), 64);
737 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
739 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
740 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
742 /* Try to initialize the user name with my own contact */
743 my_name = modest_address_book_get_my_name ();
745 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_name), my_name);
747 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
748 G_CALLBACK(on_easysetup_changed), self);
749 gtk_widget_show (priv->entry_user_name);
750 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
751 gtk_widget_show (caption);
753 /* Prevent the use of some characters in the name,
754 * as required by our UI specification: */
755 GList *list_prevent = NULL;
756 list_prevent = g_list_append (list_prevent, "<");
757 list_prevent = g_list_append (list_prevent, ">");
758 modest_validating_entry_set_unallowed_characters (
759 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
760 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
761 modest_utils_on_entry_invalid_character, self);
762 g_list_free (list_prevent);
764 /* The username widgets: */
765 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
766 /* Auto-capitalization is the default, so let's turn it off: */
768 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
769 HILDON_GTK_INPUT_MODE_FULL);
771 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
772 priv->entry_user_username);
773 gtk_widget_show (priv->entry_user_username);
774 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
775 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
776 G_CALLBACK(on_user_username_changed), self);
777 gtk_widget_show (caption);
779 /* Prevent the use of some characters in the username,
780 * as required by our UI specification: */
781 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
782 modest_utils_on_entry_invalid_character, self);
784 /* Set max length as in the UI spec:
785 * The UI spec seems to want us to show a dialog if we hit the maximum. */
786 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
787 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
790 /* The password widgets: */
791 priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
792 /* Auto-capitalization is the default, so let's turn it off: */
794 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
795 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
797 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
798 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
799 caption = create_captioned (self, title_sizegroup, value_sizegroup,
800 _("mail_fi_password"), FALSE, priv->entry_user_password);
801 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
802 G_CALLBACK(on_easysetup_changed), self);
803 gtk_widget_show (priv->entry_user_password);
804 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
805 gtk_widget_show (caption);
807 /* The email address widgets: */
808 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
809 /* Auto-capitalization is the default, so let's turn it off: */
811 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
813 caption = create_captioned (self, title_sizegroup, value_sizegroup,
814 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
815 update_user_email_from_provider (self);
816 gtk_widget_show (priv->entry_user_email);
817 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
818 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
819 G_CALLBACK(on_easysetup_changed), self);
820 gtk_widget_show (caption);
822 /* Set max length as in the UI spec:
823 * The UI spec seems to want us to show a dialog if we hit the maximum. */
824 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
825 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
829 gtk_widget_show (GTK_WIDGET (box));
830 g_object_unref (title_sizegroup);
831 g_object_unref (value_sizegroup);
833 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
834 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
835 gtk_widget_show (align);
836 gtk_container_add (GTK_CONTAINER (align), box);
838 return GTK_WIDGET (align);
842 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
845 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
847 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
848 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
849 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
850 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
851 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
853 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
854 gtk_widget_show (label);
856 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
857 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
858 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
860 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
861 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
862 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
863 gtk_widget_show (label);
865 gtk_widget_show (GTK_WIDGET (box));
867 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
868 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
869 gtk_widget_show (align);
870 gtk_container_add (GTK_CONTAINER (align), box);
872 return GTK_WIDGET (align);
875 /** Change the caption title for the incoming server,
876 * as specified in the UI spec:
879 update_incoming_server_title (ModestEasysetupWizardDialog *self)
881 ModestEasysetupWizardDialogPrivate* priv;
882 ModestProtocolType protocol_type;
883 ModestProtocolRegistry *protocol_registry;
885 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
886 protocol_registry = modest_runtime_get_protocol_registry ();
888 protocol_type = modest_servertype_selector_get_active_servertype (
889 priv->incoming_servertype_selector);
891 /* This could happen when the combo box has still no active iter */
892 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
893 gchar* incomingserver_title;
894 const gchar *protocol_display_name;
895 ModestProtocol *protocol;
897 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
899 protocol_display_name = modest_protocol_get_display_name (protocol);
901 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
902 protocol_display_name, ")</small>", NULL);
904 modest_toolkit_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
906 g_free(incomingserver_title);
910 /** Change the caption title for the incoming server,
911 * as specified in the UI spec:
914 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
916 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
917 GtkWidget *server_type_selector;
918 ModestProtocolType protocol_type;
919 ModestSecurityOptionsView *view;
921 server_type_selector = priv->incoming_servertype_selector;
922 protocol_type = modest_servertype_selector_get_active_servertype (server_type_selector);
924 /* Fill the combo with appropriately titled choices for all
926 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
927 modest_security_options_view_set_server_type (view, protocol_type);
930 #ifdef HILDON_PICKER_BUTTON
932 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
934 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
935 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
940 update_incoming_server_title (self);
942 /* Update security options if needed */
943 update_incoming_server_security_choices (self);
944 gtk_widget_show (priv->incoming_security);
946 set_default_custom_servernames (self);
951 on_servertype_combo_changed(GtkWidget *selector, gpointer user_data)
953 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
954 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
959 update_incoming_server_title (self);
961 /* Update security options if needed */
962 update_incoming_server_security_choices (self);
963 gtk_widget_show (priv->incoming_security);
965 set_default_custom_servernames (self);
969 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
971 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
972 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
974 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
978 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
980 ModestProtocolRegistry *protocol_registry;
981 ModestEasysetupWizardDialogPrivate* priv;
984 GtkWidget *scrollable;
986 GtkSizeGroup *title_sizegroup;
987 GtkSizeGroup *value_sizegroup;
989 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
990 protocol_registry = modest_runtime_get_protocol_registry ();
992 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
993 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
995 /* Show note that account type cannot be changed in future: */
996 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
997 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
998 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
999 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1000 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1001 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1002 gtk_widget_show (label);
1004 /* Create a size group to be used by all captions.
1005 * Note that HildonCaption does not create a default size group if we do not specify one.
1006 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1007 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1008 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1010 /* The incoming server widgets: */
1011 priv->incoming_servertype_selector =
1012 modest_toolkit_factory_create_servertype_selector (modest_runtime_get_toolkit_factory (),
1014 if (GTK_IS_COMBO_BOX (priv->incoming_servertype_selector)) {
1015 GtkWidget *captioned;
1016 g_signal_connect (G_OBJECT (priv->incoming_servertype_selector), "changed",
1017 G_CALLBACK (on_picker_button_value_changed), self);
1018 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
1019 _("mcen_fi_country"), FALSE,
1020 priv->incoming_servertype_selector);
1022 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
1023 gtk_widget_show (captioned);
1025 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
1026 _("mcen_li_emailsetup_type"),
1027 priv->incoming_servertype_selector);
1028 g_signal_connect (G_OBJECT (priv->incoming_servertype_selector), "value-changed",
1029 G_CALLBACK (on_picker_button_value_changed), self);
1030 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_selector, FALSE, FALSE, 0);
1032 gtk_widget_show (priv->incoming_servertype_selector);
1034 priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
1036 /* Auto-capitalization is the default, so let's turn it off: */
1037 #ifdef MAEMO_CHANGES
1038 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
1040 set_default_custom_servernames (self);
1042 /* The caption title will be updated in update_incoming_server_title().
1043 * so this default text will never be seen: */
1044 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
1045 "This will be removed",
1046 FALSE, priv->entry_incomingserver);
1047 update_incoming_server_title (self);
1048 gtk_widget_show (priv->entry_incomingserver);
1049 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
1050 gtk_widget_show (priv->caption_incoming);
1052 /* Remember when the servername was changed manually: */
1053 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
1054 G_CALLBACK (on_entry_incoming_servername_changed), self);
1056 /* The secure connection widgets. These are only valid for
1057 protocols with security */
1058 priv->incoming_security = modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
1059 MODEST_SECURITY_OPTIONS_INCOMING,
1060 FALSE, title_sizegroup, value_sizegroup);
1061 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
1063 gtk_widget_show (priv->incoming_security);
1065 /* Set default selection */
1066 modest_servertype_selector_set_active_servertype (priv->incoming_servertype_selector,
1067 MODEST_PROTOCOLS_STORE_POP);
1068 update_incoming_server_title (self);
1069 update_incoming_server_security_choices (self);
1070 set_default_custom_servernames (self);
1072 /* Change the caption title when the servertype changes,
1073 * as in the UI spec: */
1074 if (GTK_IS_COMBO_BOX (priv->incoming_servertype_selector)) {
1075 g_signal_connect (priv->incoming_servertype_selector,
1077 G_CALLBACK (on_servertype_combo_changed), self);
1079 #ifdef HILDON_PICKER_BUTTON
1080 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_selector))),
1082 G_CALLBACK (on_servertype_selector_changed), self);
1086 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1087 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1088 gtk_widget_show (align);
1089 gtk_container_add (GTK_CONTAINER (align), box);
1091 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1092 gtk_widget_show (GTK_WIDGET (box));
1093 gtk_widget_show (scrollable);
1095 g_object_unref (title_sizegroup);
1096 g_object_unref (value_sizegroup);
1098 /* Connect changed signals. We do it here after initializing everything */
1099 g_signal_connect (G_OBJECT(priv->entry_incomingserver), "changed",
1100 G_CALLBACK(on_easysetup_changed), self);
1103 return GTK_WIDGET (scrollable);
1107 on_check_button_changed (GtkWidget *button, gpointer user_data)
1109 GtkWidget *widget = GTK_WIDGET (user_data);
1111 /* Enable the widget only if the check button is active: */
1112 const gboolean enable = modest_togglable_get_active (button);
1113 gtk_widget_set_sensitive (widget, enable);
1116 /* Make the sensitivity of a widget depend on a check button.
1119 enable_widget_for_checkbutton (GtkWidget *widget, GtkWidget* button)
1121 g_signal_connect (G_OBJECT (button), "toggled",
1122 G_CALLBACK (on_check_button_changed), widget);
1124 /* Set the starting sensitivity: */
1125 on_check_button_changed (button, widget);
1129 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
1131 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1132 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1133 GtkWidget *specific_window;
1135 /* We set dirty here because setting it depending on the connection specific dialog
1139 /* Create the window, if necessary: */
1140 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
1141 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
1143 /* Show the window */
1144 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
1145 gtk_widget_show (specific_window);
1149 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
1151 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1152 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1153 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
1157 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
1159 ModestEasysetupWizardDialogPrivate *priv;
1160 gchar *smtp_caption_label;
1161 GtkWidget *scrollable;
1163 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1165 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1167 /* Create a size group to be used by all captions.
1168 * Note that HildonCaption does not create a default size group if we do not specify one.
1169 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1170 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1171 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1173 /* The outgoing server widgets: */
1174 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1175 priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
1177 /* Auto-capitalization is the default, so let's turn it off: */
1178 #ifdef MAEMO_CHANGES
1179 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
1181 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
1182 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
1183 smtp_caption_label, TRUE, priv->entry_outgoingserver);
1184 g_free (smtp_caption_label);
1185 gtk_widget_show (priv->entry_outgoingserver);
1186 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
1187 gtk_widget_show (caption);
1188 set_default_custom_servernames (self);
1190 /* The secure connection widgets. These are only valid for
1191 protocols with security */
1192 priv->outgoing_security =
1193 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
1194 MODEST_SECURITY_OPTIONS_OUTGOING,
1195 FALSE, title_sizegroup, value_sizegroup);
1196 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
1198 gtk_widget_show (priv->outgoing_security);
1200 GtkWidget *separator = gtk_hseparator_new ();
1201 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
1202 gtk_widget_show (separator);
1204 /* connection-specific checkbox: */
1205 priv->checkbox_outgoing_smtp_specific = modest_toolkit_factory_create_check_button
1206 (modest_runtime_get_toolkit_factory (),
1207 _("mcen_fi_advsetup_connection_smtp"));
1208 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
1211 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1212 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
1215 /* Connection-specific SMTP-Severs Edit button: */
1216 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
1217 #ifdef MAEMO_CHANGES
1218 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
1219 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1221 gtk_widget_show (priv->button_outgoing_smtp_servers);
1222 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
1225 /* Only enable the button when the checkbox is checked: */
1226 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
1227 priv->checkbox_outgoing_smtp_specific);
1229 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1230 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1232 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1233 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1236 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1237 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1238 gtk_widget_show (align);
1239 gtk_container_add (GTK_CONTAINER (align), box);
1241 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1242 gtk_widget_show (GTK_WIDGET (box));
1243 gtk_widget_show (scrollable);
1245 g_object_unref (title_sizegroup);
1246 g_object_unref (value_sizegroup);
1248 /* Connect changed signals. We do it here after initializing everything */
1249 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1250 G_CALLBACK (on_easysetup_changed), self);
1251 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1252 G_CALLBACK (on_easysetup_changed), self);
1254 return GTK_WIDGET (scrollable);
1258 show_advanced_edit(gpointer user_data)
1260 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1261 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1264 /* Show the Account Settings window: */
1265 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
1266 if (priv->pending_load_settings) {
1267 save_to_settings (self);
1268 priv->pending_load_settings = FALSE;
1270 modest_account_settings_dialog_load_settings (dialog, priv->settings);
1272 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
1274 response = gtk_dialog_run (GTK_DIALOG (dialog));
1276 gtk_widget_destroy (GTK_WIDGET (dialog));
1278 return FALSE; /* Do not call this timeout callback again. */
1282 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1284 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1286 /* Show the Account Settings window: */
1287 show_advanced_edit(self);
1290 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1292 gchar *complete_string;
1296 GtkWidget *button_edit;
1298 box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1299 complete_string = g_strconcat (_("mcen_ia_emailsetup_setup_complete"), " ",
1300 _("mcen_ia_customsetup_complete"), NULL);
1301 label = gtk_label_new(complete_string);
1302 g_free (complete_string);
1303 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1304 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1305 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1306 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1307 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1308 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1309 gtk_widget_show (label);
1311 button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1312 #ifdef MAEMO_CHANGES
1313 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1315 gtk_widget_show (button_edit);
1316 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, 0);
1318 g_signal_connect (G_OBJECT (button_edit), "clicked",
1319 G_CALLBACK (on_button_edit_advanced_settings), self);
1321 gtk_widget_show (GTK_WIDGET (box));
1323 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1324 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
1325 gtk_widget_show (align);
1326 gtk_container_add (GTK_CONTAINER (align), box);
1328 return GTK_WIDGET (align);
1335 on_response (ModestWizardDialog *wizard_dialog,
1339 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1341 invoke_enable_buttons_vfunc (self);
1345 on_response_before (ModestWizardDialog *wizard_dialog,
1349 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1350 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1351 if (response_id == GTK_RESPONSE_CANCEL) {
1352 /* This is mostly copied from
1353 * src/maemo/modest-account-settings-dialog.c */
1355 gint dialog_response;
1357 dialog_response = modest_platform_run_confirmation_dialog ((GtkWindow *) self,
1358 _("imum_nc_wizard_confirm_lose_changes"));
1360 if (dialog_response != GTK_RESPONSE_OK) {
1361 /* Don't let the dialog close */
1362 g_signal_stop_emission_by_name (wizard_dialog, "response");
1369 fill_providers (ModestEasysetupWizardDialog *self)
1371 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1373 if (priv->account_country_selector) {
1374 /* gint mcc = get_default_country_code(); */
1376 /* Fill the combo in an idle call, as it takes a lot of time */
1377 modest_country_selector_load_data(priv->account_country_selector);
1378 /* connect to country picker's changed signal, so we can fill the provider picker: */
1379 if (GTK_IS_COMBO_BOX (priv->account_country_selector)) {
1380 g_signal_connect ((GObject *) priv->account_country_selector,
1382 G_CALLBACK (on_account_country_selector_changed), self);
1384 g_signal_connect ((GObject *) priv->account_country_selector,
1386 G_CALLBACK (on_account_country_selector_changed), self);
1389 modest_country_selector_set_active_country_locale (priv->account_country_selector);
1390 mcc = modest_country_selector_get_active_country_mcc (priv->account_country_selector);
1391 modest_provider_selector_fill (
1392 priv->account_serviceprovider_selector,
1393 priv->presets, mcc);
1394 /* connect to providers picker's changed signal, so we can fill the email address: */
1395 if (GTK_IS_COMBO_BOX (priv->account_serviceprovider_selector)) {
1396 g_signal_connect (priv->account_serviceprovider_selector,
1398 G_CALLBACK (on_account_serviceprovider_selector_combo_box_changed), self);
1400 #ifdef HILDON_PICKER_BUTTON
1401 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1402 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_selector))),
1404 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1407 modest_provider_selector_set_others_provider (priv->account_serviceprovider_selector);
1410 priv->dirty = FALSE;
1414 typedef struct IdleData {
1415 ModestEasysetupWizardDialog *dialog;
1416 ModestPresets *presets;
1420 presets_idle (gpointer userdata)
1422 IdleData *idle_data = (IdleData *) userdata;
1423 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1424 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1426 g_assert (idle_data->presets);
1428 gdk_threads_enter ();
1430 priv->presets = idle_data->presets;
1432 if (priv->check_support_done)
1433 fill_providers (self);
1435 g_object_unref (idle_data->dialog);
1438 gdk_threads_leave ();
1444 presets_loader (gpointer userdata)
1446 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1447 ModestPresets *presets = NULL;
1448 IdleData *idle_data;
1450 const gchar* path = NULL;
1451 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1452 const gchar* path2 = MODEST_FALLBACK_PROVIDER_DATA_FILE;
1454 if (access(path1, R_OK) == 0)
1456 else if (access(path2, R_OK) == 0)
1459 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1460 __FUNCTION__, path1, path2);
1464 presets = modest_presets_new (path);
1466 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1470 idle_data = g_new0 (IdleData, 1);
1471 idle_data->dialog = self;
1472 idle_data->presets = presets;
1474 g_idle_add (presets_idle, idle_data);
1480 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1486 /* Append page and set attributes */
1487 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1488 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1489 "tab-expand", TRUE, "tab-fill", TRUE,
1492 /* Give focus to page and show it */
1493 gtk_container_set_focus_child (GTK_CONTAINER (notebook), page);
1494 gtk_widget_show (page);
1498 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1500 priv->page_user_details = NULL;
1501 priv->entry_user_name = NULL;
1502 priv->entry_user_username = NULL;
1503 priv->entry_user_password = NULL;
1504 priv->entry_user_email = NULL;
1508 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1510 priv->page_custom_incoming = NULL;
1511 priv->incoming_servertype_selector = NULL;
1512 priv->caption_incoming = NULL;
1513 priv->entry_incomingserver = NULL;
1514 priv->entry_user_email = NULL;
1515 priv->incoming_security = NULL;
1519 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1521 priv->page_custom_outgoing = NULL;
1522 priv->entry_outgoingserver = NULL;
1523 priv->checkbox_outgoing_smtp_specific = NULL;
1524 priv->button_outgoing_smtp_servers = NULL;
1525 priv->outgoing_security = NULL;
1529 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1531 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1533 /* Create the notebook to be used by the ModestWizardDialog base class:
1534 * Each page of the notebook will be a page of the wizard: */
1535 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1536 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1538 /* Set the notebook used by the ModestWizardDialog base class: */
1539 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1541 /* Set the wizard title:
1542 * The actual window title will be a combination of this and the page's tab label title. */
1543 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1545 /* Read in the information about known service providers: */
1546 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1548 /* The server fields did not have been manually changed yet */
1549 priv->server_changes = 0;
1550 priv->pending_load_settings = TRUE;
1552 /* Get the account manager object,
1553 * so we can check for existing accounts,
1554 * and create new accounts: */
1555 priv->account_manager = modest_runtime_get_account_mgr ();
1556 g_object_ref (priv->account_manager);
1558 /* Initialize fields */
1559 priv->check_support_done = FALSE;
1560 priv->check_support_show_progress_id = 0;
1561 priv->check_support_progress_pulse_id = 0;
1562 priv->check_support_cancel_note = NULL;
1563 priv->check_support_progress = NULL;
1564 priv->pending_check_support = 0;
1565 priv->destroyed = FALSE;
1566 priv->page_welcome = create_page_welcome (self);
1567 gtk_widget_show (priv->page_welcome);
1568 priv->page_account_details = create_page_account_details (self);
1570 init_user_page (priv);
1571 init_incoming_page (priv);
1572 init_outgoing_page (priv);
1574 priv->page_complete_easysetup = NULL;
1575 priv->page_complete_customsetup = NULL;
1576 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1577 priv->missing_data_signals = NULL;
1579 /* Add the common pages */
1580 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1581 _("mcen_ti_emailsetup_welcome"));
1582 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1583 _("mcen_ti_accountdetails"));
1585 /* Connect to the dialog's response signal so we can enable/disable buttons
1586 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1587 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1588 * so that we can be enable/disable after ModestWizardDialog has done its own
1589 * enabling/disabling of buttons.
1591 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1592 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1594 * It's not enough to connect to the notebook's switch-page signal, because
1595 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1596 * _after_ switching the page (understandably).
1597 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1598 * then gtk_notebook_get_current_page() would return an incorrect value.)
1600 g_signal_connect_after (G_OBJECT (self), "response",
1601 G_CALLBACK (on_response), self);
1603 /* This is to show a confirmation dialog when the user hits cancel */
1604 g_signal_connect (G_OBJECT (self), "response",
1605 G_CALLBACK (on_response_before), self);
1607 g_signal_connect (G_OBJECT (self), "delete-event",
1608 G_CALLBACK (on_delete_event), self);
1610 /* Reset dirty, because there was no user input until now */
1611 priv->dirty = FALSE;
1613 /* When this window is shown, hibernation should not be possible,
1614 * because there is no sensible way to save the state: */
1615 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1616 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1618 /* Load provider presets */
1619 g_object_ref (self);
1620 g_thread_create (presets_loader, self, FALSE, NULL);
1622 priv->settings = modest_account_settings_new ();
1626 ModestEasysetupWizardDialog*
1627 modest_easysetup_wizard_dialog_new (void)
1630 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1634 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1636 ModestEasysetupWizardDialogPrivate *priv;
1637 GtkNotebook *notebook = NULL;
1639 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1642 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1644 if (!priv->page_user_details) {
1645 priv->page_user_details = create_page_user_details (self);
1648 /* Create the custom pages: */
1649 if(!(priv->page_custom_incoming)) {
1650 priv->page_custom_incoming = create_page_custom_incoming (self);
1653 /* TODO: only if needed */
1654 if(!(priv->page_custom_outgoing)) {
1655 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1658 if(!(priv->page_complete_customsetup)) {
1659 priv->page_complete_customsetup = create_page_complete_custom (self);
1662 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1663 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1664 _("mcen_ti_emailsetup_userdetails"));
1666 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1667 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1668 _("mcen_ti_emailsetup_incomingdetails"));
1670 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1671 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1672 _("mcen_ti_emailsetup_outgoingdetails"));
1674 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1675 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1676 _("mcen_ti_emailsetup_complete"));
1678 /* This is unnecessary with GTK+ 2.10: */
1679 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1683 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1685 ModestEasysetupWizardDialogPrivate *priv;
1686 GtkNotebook *notebook = NULL;
1688 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1691 /* Create the easysetup-specific pages: */
1692 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1693 if(!priv->page_complete_easysetup)
1694 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1696 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1697 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1698 _("mcen_ti_emailsetup_complete"));
1700 /* This is unnecessary with GTK+ 2.10: */
1701 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1706 remove_non_common_tabs (ModestEasysetupWizardDialog *self,
1707 gboolean remove_user_details)
1710 GtkNotebook *notebook;
1711 ModestEasysetupWizardDialogPrivate *priv;
1713 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1714 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1716 /* The first 2 tabs are the common ones (welcome tab and the
1717 providers tab), so we always remove starting from the
1719 starting_tab = (remove_user_details) ? 2 : 3;
1720 while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
1721 /* Disconnect signal */
1722 GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
1723 if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
1724 priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
1726 "missing-mandatory-data");
1728 /* Remove page from notebook */
1729 gtk_notebook_remove_page (notebook, -1);
1734 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1738 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1741 /* After the user details page,
1742 * the following pages depend on whether "Other" was chosen
1743 * in the provider combobox on the account page
1746 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1748 ModestEasysetupWizardDialogPrivate *priv;
1750 ModestProviderSelectorIdType id_type;
1751 GtkNotebook *notebook;
1753 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1754 picker = priv->account_serviceprovider_selector;
1755 id_type = modest_provider_selector_get_active_id_type (picker);
1756 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1758 /* Remove the response override handler for non-plugin
1759 protocols. For plugins it'll be overriden later */
1760 if (id_type != MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL)
1761 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1765 if (id_type == MODEST_PROVIDER_SELECTOR_ID_OTHER) {
1766 /* "Other..." was selected: */
1768 /* If we come from a rollbacked easysetup */
1769 if (priv->page_complete_easysetup) {
1770 remove_non_common_tabs (self, FALSE);
1771 priv->page_complete_easysetup = NULL;
1774 /* If we come from a rollbacked plugin protocol setup */
1775 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1776 remove_non_common_tabs (self, TRUE);
1777 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1778 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1779 priv->missing_data_signals = NULL;
1782 create_subsequent_customsetup_pages (self);
1784 /* If we come from a rollbacked custom setup */
1785 if (priv->page_custom_incoming) {
1786 remove_non_common_tabs (self, TRUE);
1787 init_user_page (priv);
1788 init_incoming_page (priv);
1789 init_outgoing_page (priv);
1790 init_user_page (priv);
1791 priv->page_complete_customsetup = NULL;
1794 /* It's a pluggable protocol and not a provider with presets */
1795 if (id_type == MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL) {
1796 ModestProtocol *protocol;
1798 ModestProtocolType proto_type;
1799 ModestWizardDialogResponseOverrideFunc response_override;
1801 /* Get protocol data */
1802 proto_name = modest_provider_selector_get_active_provider_id (picker);
1803 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1804 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1806 proto_type = modest_protocol_get_type_id (protocol);
1809 /* If we come from a rollbacked easy setup */
1810 if (priv->last_plugin_protocol_selected != proto_type &&
1811 priv->page_complete_easysetup) {
1812 remove_non_common_tabs (self, TRUE);
1813 init_user_page (priv);
1814 priv->page_complete_easysetup = NULL;
1817 /* Ensure that the response override handler
1818 is set. It might happen that plugins clear
1820 response_override = modest_account_protocol_get_wizard_response_override
1821 (MODEST_ACCOUNT_PROTOCOL (protocol));
1822 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1825 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1826 proto_type != priv->last_plugin_protocol_selected) {
1827 ModestPairList *tabs;
1829 gboolean first_page = TRUE;
1831 /* Remember the last selected plugin protocol */
1832 priv->last_plugin_protocol_selected = proto_type;
1835 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1836 tmp = (GSList *) tabs;
1838 ModestPair *pair = (ModestPair *) tmp->data;
1839 modest_easysetup_wizard_dialog_append_page (notebook,
1840 GTK_WIDGET (pair->second),
1841 (const gchar *) pair->first);
1843 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1844 GTK_WIDGET (pair->second));
1848 /* Connect signals */
1849 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1850 priv->missing_data_signals =
1851 modest_signal_mgr_connect (priv->missing_data_signals,
1852 G_OBJECT (pair->second),
1853 "missing-mandatory-data",
1854 G_CALLBACK (on_missing_mandatory_data),
1858 g_free (pair->first);
1859 tmp = g_slist_next (tmp);
1860 /* Critical: if you don't show the page then the dialog will ignore it */
1861 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1863 modest_pair_list_free (tabs);
1865 g_free (proto_name);
1867 if (priv->last_plugin_protocol_selected !=
1868 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1869 remove_non_common_tabs (self, TRUE);
1870 init_user_page (priv);
1871 priv->page_complete_easysetup = NULL;
1872 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1873 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1874 priv->missing_data_signals = NULL;
1876 if (!priv->page_user_details) {
1877 priv->page_user_details = create_page_user_details (self);
1878 modest_easysetup_wizard_dialog_append_page (notebook,
1879 priv->page_user_details,
1880 _("mcen_ti_emailsetup_userdetails"));
1884 /* Create the easysetup pages: */
1885 create_subsequent_easysetup_pages (self);
1891 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1893 const gchar* hostname = NULL;
1896 ModestProtocolRegistry *protocol_registry;
1897 ModestProtocol *protocol;
1902 at = g_utf8_strchr (email_address, -1, '@');
1903 if (!at || (g_utf8_strlen (at, -1) < 2))
1906 domain = g_utf8_next_char (at);
1910 protocol_registry = modest_runtime_get_protocol_registry ();
1911 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1913 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1914 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1915 hostname = modest_protocol_get_name (protocol);
1921 return g_strdup_printf ("%s.%s", hostname, domain);
1925 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1927 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1929 if (!priv->entry_incomingserver)
1932 /* Set a default domain for the server, based on the email address,
1933 * if no server name was already specified.
1935 if (priv->entry_user_email
1936 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1937 const ModestProtocolType protocol_type = modest_servertype_selector_get_active_servertype (
1938 priv->incoming_servertype_selector);
1940 /* This could happen when the combo box has still no active iter */
1941 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1942 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1943 gchar* servername = util_get_default_servername_from_email_address (email_address,
1946 /* Do not set the INCOMING_CHANGED flag because of this edit */
1947 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1948 modest_entry_set_text (priv->entry_incomingserver, servername);
1949 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1951 g_free (servername);
1955 /* Set a default domain for the server, based on the email address,
1956 * if no server name was already specified.
1958 if (!priv->entry_outgoingserver)
1961 if (priv->entry_user_email
1962 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1963 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1965 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1967 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1968 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1969 modest_entry_set_text (priv->entry_outgoingserver, servername);
1970 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1972 g_free (servername);
1977 get_entered_account_title (ModestEasysetupWizardDialog *self)
1979 ModestEasysetupWizardDialogPrivate *priv;
1980 const gchar* account_title;
1982 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1983 account_title = modest_entry_get_text (priv->entry_account_title);
1985 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1988 /* Strip it of whitespace at the start and end: */
1989 gchar *result = g_strdup (account_title);
1990 result = g_strstrip (result);
1995 if (g_utf8_strlen (result, -1) == 0) {
2005 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
2007 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2008 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2009 ModestProtocolRegistry *protocol_registry;
2011 protocol_registry = modest_runtime_get_protocol_registry ();
2013 /* if are browsing pages previous to the last one, then we have pending settings in
2015 if (next_page != NULL)
2016 priv->pending_load_settings = TRUE;
2018 /* Do extra validation that couldn't be done for every key press,
2019 * either because it was too slow,
2020 * or because it requires interaction:
2022 if (current_page == priv->page_welcome) {
2023 if (!priv->check_support_done) {
2024 check_support_of_protocols (self);
2025 return priv->check_support_done;
2027 } else if (current_page == priv->page_account_details) {
2028 /* Check that the title is not already in use: */
2029 gchar* account_title = get_entered_account_title (self);
2033 /* Aavoid a clash with an existing display name: */
2034 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
2035 priv->account_manager, account_title);
2036 g_free (account_title);
2039 /* Warn the user via a dialog: */
2040 modest_platform_system_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
2045 /* Make sure that the subsequent pages are appropriate for the provider choice. */
2046 create_subsequent_pages (self);
2048 } else if (current_page == priv->page_user_details) {
2049 /* Check that the email address is valud: */
2050 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
2051 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
2054 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
2055 /* Warn the user via a dialog: */
2056 modest_platform_system_banner (NULL, NULL, _("mcen_ib_invalid_email"));
2058 /* Return focus to the email address entry: */
2059 gtk_widget_grab_focus (priv->entry_user_email);
2060 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
2064 } else if (current_page == priv->page_custom_incoming ||
2065 current_page == priv->page_custom_outgoing) {
2067 const gchar *hostname;
2068 GtkWidget *entry = (current_page == priv->page_custom_incoming) ?
2069 priv->entry_incomingserver :
2070 priv->entry_outgoingserver;
2072 hostname = gtk_entry_get_text (GTK_ENTRY (entry));
2073 if (!modest_text_utils_validate_domain_name (hostname)) {
2075 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
2077 /* Return focus to the email address entry: */
2078 gtk_widget_grab_focus (entry);
2079 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
2085 if (next_page == priv->page_custom_incoming) {
2086 set_default_custom_servernames (self);
2087 } else if (next_page == priv->page_custom_outgoing) {
2088 set_default_custom_servernames (self);
2090 /* Check if the server supports secure authentication */
2091 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
2092 if (!check_has_supported_auth_methods (self))
2094 gtk_widget_show (priv->outgoing_security);
2097 /* If this is the last page, and this is a click on Finish,
2098 * then attempt to create the dialog.
2101 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
2103 if (priv->pending_load_settings) {
2104 save_to_settings (self);
2107 /* We check if there's already another account with the same configuration */
2108 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2109 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2113 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2120 static gboolean entry_is_empty (GtkWidget *entry)
2125 const gchar* text = modest_entry_get_text (entry);
2126 if ((!text) || (g_utf8_strlen (text, -1) == 0))
2129 /* Strip it of whitespace at the start and end: */
2130 gchar *stripped = g_strdup (text);
2131 stripped = g_strstrip (stripped);
2136 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
2144 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
2146 GtkNotebook *notebook = NULL;
2147 gboolean is_finish_tab;
2149 ModestEasysetupWizardDialogPrivate *priv;
2152 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
2153 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
2155 /* Disable the Finish button until we are on the last page,
2156 * because HildonWizardDialog enables this for all but the
2158 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
2159 is_finish_tab = ((current == priv->page_complete_easysetup) ||
2160 (current == priv->page_complete_customsetup));
2162 if (is_finish_tab) {
2163 /* Disable Next on the last page no matter what the
2165 enable_next = FALSE;
2167 /* Not the last one */
2168 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2169 MODEST_WIZARD_DIALOG_FINISH,
2172 /* If the check support is not done then do not enable
2173 the wizard to continue */
2174 enable_next = enable_next && priv->pending_check_support == 0;
2177 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2178 MODEST_WIZARD_DIALOG_NEXT,
2183 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
2185 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2186 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2188 gboolean enable_next = TRUE;
2189 if (current_page == priv->page_welcome) {
2191 } else if (current_page == priv->page_account_details) {
2192 /* The account details title is mandatory: */
2193 if (entry_is_empty(priv->entry_account_title))
2194 enable_next = FALSE;
2195 } else if (current_page == priv->page_user_details) {
2196 /* The user details username is mandatory: */
2197 if (entry_is_empty(priv->entry_user_username))
2198 enable_next = FALSE;
2200 /* The user details email address is mandatory: */
2201 if (enable_next && entry_is_empty (priv->entry_user_email))
2202 enable_next = FALSE;
2203 } else if (current_page == priv->page_custom_incoming) {
2204 /* The custom incoming server is mandatory: */
2205 if (entry_is_empty(priv->entry_incomingserver))
2206 enable_next = FALSE;
2207 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
2208 enable_next = !modest_easysetup_wizard_page_validate (
2209 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
2212 /* Enable/disable buttons */
2213 real_enable_buttons (dialog, enable_next);
2217 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
2219 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2220 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
2223 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
2224 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
2226 /* Provide a vfunc implementation so we can decide
2227 * when to enable/disable the prev/next buttons.
2229 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
2230 base_klass->before_next = on_before_next;
2231 base_klass->enable_buttons = on_enable_buttons;
2232 base_klass->update_model = on_update_model;
2233 base_klass->save = on_save;
2237 check_username_for_provider (const gchar *provider_id,
2238 const gchar *domain,
2241 gchar *providers_to_check[] = { "ovi.com", "yahoomailplus.com", "hotmail.com" };
2243 gboolean found = FALSE;
2246 /* Check if the username contains the @hostname, if not then add it */
2247 if (strchr (*username, '@'))
2250 /* Check if it's one of the providers to check */
2251 for (i = 0; i < G_N_ELEMENTS (providers_to_check) && !found; i++) {
2252 if (!g_ascii_strncasecmp (providers_to_check[i], provider_id, strlen (providers_to_check[i])))
2259 /* Replace the username */
2261 *username = g_strconcat (*username, "@", domain, NULL);
2267 * @self: a #ModestEasysetupWizardDialog
2269 * takes information from all the wizard and stores it in settings
2272 save_to_settings (ModestEasysetupWizardDialog *self)
2274 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2276 gchar *provider_id = NULL;
2277 gchar *alternate_username = NULL;
2278 gchar *display_name;
2279 const gchar *username, *password;
2280 gchar *store_hostname, *transport_hostname;
2281 guint store_port, transport_port;
2282 ModestProtocolRegistry *protocol_registry;
2283 ModestProtocolType store_protocol, transport_protocol;
2284 ModestProtocolType store_security, transport_security;
2285 ModestProtocolType store_auth_protocol, transport_auth_protocol;
2286 ModestServerAccountSettings *store_settings, *transport_settings;
2287 const gchar *fullname, *email_address;
2289 ModestProviderSelectorIdType id_type;
2291 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2292 picker = priv->account_serviceprovider_selector;
2293 protocol_registry = modest_runtime_get_protocol_registry ();
2295 /* Get details from the specified presets: */
2296 id_type = modest_provider_selector_get_active_id_type (picker);
2297 provider_id = modest_provider_selector_get_active_provider_id (picker);
2299 /* Let the plugin save the settings. We do a return in order
2300 to save an indentation level */
2301 if (id_type == MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL) {
2302 ModestProtocol *protocol;
2304 protocol = modest_protocol_registry_get_protocol_by_name (
2305 modest_runtime_get_protocol_registry (),
2306 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
2309 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
2310 gint n_pages, i = 0;
2311 GtkNotebook *notebook;
2312 GList *wizard_pages = NULL;
2314 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
2315 n_pages = gtk_notebook_get_n_pages (notebook);
2316 for (i = 0; i < n_pages; i++) {
2317 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
2318 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
2319 wizard_pages = g_list_append (wizard_pages, page);
2321 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
2324 g_list_free (wizard_pages);
2326 g_debug ("The selected protocol is a plugin protocol "//
2327 "but it's not a ModestAccountProtocol");
2330 g_free (provider_id);
2334 /* username and password (for both incoming and outgoing): */
2335 username = modest_entry_get_text (priv->entry_user_username);
2336 password = modest_entry_get_text (priv->entry_user_password);
2338 store_settings = modest_account_settings_get_store_settings (priv->settings);
2339 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
2341 /* Incoming server: */
2342 /* Note: We need something as default for the transport store protocol values,
2343 * or modest_account_mgr_add_server_account will fail. */
2345 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2346 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2347 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2350 ModestProtocolType store_provider_server_type;
2351 gboolean store_provider_use_alternate_port;
2352 gchar *domain = NULL;
2355 store_hostname = modest_presets_get_server (priv->presets, provider_id,
2358 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2361 store_security = modest_presets_get_info_server_security (priv->presets,
2364 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
2367 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
2372 /* This is HORRIBLE, but it seems that somehow it helps users
2373 that do not like to read the user instructions for their
2375 domain = modest_presets_get_domain (priv->presets, provider_id);
2377 alternate_username = g_strdup (username);
2378 check_username_for_provider (provider_id, domain, &alternate_username);
2382 /* We don't check for SMTP here as that is impossible for an incoming server. */
2383 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
2384 store_protocol = MODEST_PROTOCOLS_STORE_POP;
2386 store_protocol = store_provider_server_type;
2388 /* we check if there is a *special* port */
2389 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
2390 if (special_port != 0) {
2391 store_port = special_port;
2393 gboolean use_alternate_port = FALSE;
2394 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2396 use_alternate_port = TRUE;
2397 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
2400 modest_server_account_settings_set_security_protocol (store_settings,
2402 modest_server_account_settings_set_auth_protocol (store_settings,
2403 store_auth_protocol);
2404 if (store_port != 0)
2405 modest_server_account_settings_set_port (store_settings, store_port);
2407 /* Use custom pages because no preset was specified: */
2408 store_hostname = g_strdup (modest_entry_get_text (priv->entry_incomingserver ));
2409 store_protocol = modest_servertype_selector_get_active_servertype (
2410 priv->incoming_servertype_selector);
2412 modest_security_options_view_save_settings (
2413 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2417 /* now we store the common store account settings */
2418 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2419 modest_server_account_settings_set_username (store_settings, (alternate_username) ? alternate_username : username);
2420 modest_server_account_settings_set_password (store_settings, password);
2421 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2423 g_object_unref (store_settings);
2424 g_free (store_hostname);
2426 /* Outgoing server: */
2427 transport_hostname = NULL;
2428 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2429 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2430 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2434 ModestProtocolType transport_provider_server_type;
2435 ModestProtocolType transport_provider_security;
2439 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2440 FALSE /* transport */);
2442 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2444 FALSE /* transport */);
2445 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2447 FALSE /* transport */);
2449 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2450 transport_protocol = transport_provider_server_type;
2451 transport_security = transport_provider_security;
2452 is_secure = modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2453 transport_security);
2455 /* we check if there is a *special* port */
2456 special_port = modest_presets_get_port (priv->presets, provider_id,
2457 FALSE /* transport */);
2458 if (special_port != 0) {
2459 transport_port = special_port;
2461 gboolean use_alternate_port = FALSE;
2462 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL)
2463 use_alternate_port = TRUE;
2464 transport_port = get_port_from_protocol(transport_provider_server_type, use_alternate_port);
2468 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2470 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2472 modest_server_account_settings_set_security_protocol (transport_settings,
2473 transport_security);
2474 modest_server_account_settings_set_auth_protocol (transport_settings,
2475 transport_auth_protocol);
2476 if (transport_port != 0)
2477 modest_server_account_settings_set_port (transport_settings,
2480 ModestProtocolRegistry *registry;
2481 ModestProtocol *store_proto;
2483 registry = modest_runtime_get_protocol_registry ();
2484 /* Use custom pages because no preset was specified: */
2485 transport_hostname = g_strdup (modest_entry_get_text (priv->entry_outgoingserver ));
2487 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2490 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2491 /* fallback to SMTP if none was specified */
2492 g_warning ("No transport protocol was specified for store %d (%s)",
2493 modest_protocol_get_type_id (store_proto),
2494 modest_protocol_get_display_name (store_proto));
2495 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2498 modest_security_options_view_save_settings (
2499 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2503 /* now we store the common transport account settings */
2504 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2505 modest_server_account_settings_set_username (transport_settings, (alternate_username) ? alternate_username : username);
2506 modest_server_account_settings_set_password (transport_settings, password);
2507 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2509 g_object_unref (transport_settings);
2510 g_free (transport_hostname);
2511 if (alternate_username)
2512 g_free (alternate_username);
2514 fullname = modest_entry_get_text (priv->entry_user_name);
2515 email_address = modest_entry_get_text (priv->entry_user_email);
2516 modest_account_settings_set_fullname (priv->settings, fullname);
2517 modest_account_settings_set_email_address (priv->settings, email_address);
2518 /* we don't set retrieve type to preserve advanced settings if
2519 any. By default account settings are set to headers only */
2521 /* Save the connection-specific SMTP server accounts. */
2522 if (priv->checkbox_outgoing_smtp_specific) {
2523 modest_account_settings_set_use_connection_specific_smtp
2525 modest_togglable_get_active(priv->checkbox_outgoing_smtp_specific));
2528 display_name = get_entered_account_title (self);
2529 modest_account_settings_set_display_name (priv->settings, display_name);
2530 g_free (display_name);
2531 g_free (provider_id);
2533 /* This values are hardcoded for Fremantle */
2534 modest_account_settings_set_retrieve_type (priv->settings,
2535 MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS);
2536 modest_account_settings_set_retrieve_limit (priv->settings, 20);
2541 on_update_model (ModestWizardDialog *dialog)
2543 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2544 save_to_settings (self);
2549 on_save (ModestWizardDialog *dialog)
2551 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2552 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2554 save_to_settings (self);
2556 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2557 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2561 return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2567 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2569 GError *error = NULL;
2570 ModestProtocolType protocol_type;
2571 const gchar* hostname;
2572 const gchar* username;
2573 ModestProtocolType security_protocol_incoming_type;
2574 ModestProtocolRegistry *registry;
2576 GList *list_auth_methods;
2577 ModestEasysetupWizardDialogPrivate *priv;
2579 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2580 registry = modest_runtime_get_protocol_registry ();
2581 protocol_type = modest_servertype_selector_get_active_servertype (
2582 priv->incoming_servertype_selector);
2583 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2584 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2585 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2586 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2587 port_num = get_port_from_protocol(protocol_type, FALSE);
2588 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2589 username, GTK_WINDOW (self), &error);
2591 if (list_auth_methods) {
2592 /* TODO: Select the correct method */
2595 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2596 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2597 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2598 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2599 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2603 g_list_free(list_auth_methods);
2609 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2610 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2612 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2613 _("mcen_ib_unableto_discover_auth_methods"));
2617 g_error_free(error);
2623 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2625 GList* methods = check_for_supported_auth_methods(self);
2631 g_list_free(methods);
2636 check_support_show_progress (gpointer userdata)
2638 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2639 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2641 priv->check_support_show_progress_id = 0;
2643 if (priv->destroyed)
2646 #ifdef MODEST_TOOLKIT_HILDON2
2647 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
2654 check_support_progress_pulse (gpointer userdata)
2656 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2657 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2659 if (priv->destroyed || priv->check_support_progress == NULL) {
2660 priv->check_support_progress_pulse_id = 0;
2664 gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->check_support_progress));
2670 check_support_callback (ModestAccountProtocol *protocol,
2674 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2675 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2677 priv->pending_check_support --;
2679 if (priv->check_support_show_progress_id > 0) {
2680 g_source_remove (priv->check_support_show_progress_id);
2681 priv->check_support_show_progress_id = 0;
2684 if (priv->pending_check_support == 0) {
2685 priv->check_support_done = TRUE;
2687 if (priv->check_support_cancel_note) {
2688 gtk_widget_destroy (priv->check_support_cancel_note);
2689 priv->check_support_cancel_note = NULL;
2690 priv->check_support_progress = NULL;
2693 if (!priv->destroyed) {
2695 fill_providers (self);
2696 #ifdef MODEST_TOOLKIT_HILDON2
2697 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
2699 invoke_enable_buttons_vfunc (self);
2700 gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
2703 g_object_unref (self);
2706 #ifdef MODEST_TOOLKIT_HILDON2
2708 on_check_support_cancel (GtkDialog *cancel_note,
2710 ModestEasysetupWizardDialog *self)
2712 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2713 ModestProtocolRegistry *registry;
2714 GSList *provider_protos, *node;
2716 registry = modest_runtime_get_protocol_registry ();
2717 provider_protos = modest_protocol_registry_get_by_tag (registry,
2718 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2720 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2721 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2723 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2724 modest_protocol_get_type_id (proto),
2725 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2728 if (modest_protocol_registry_protocol_type_has_tag
2730 modest_protocol_get_type_id (proto),
2731 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2732 /* Check if there's already an account configured with this account type */
2733 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2734 modest_protocol_get_type_id (proto)))
2738 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2739 modest_account_protocol_cancel_check_support (MODEST_ACCOUNT_PROTOCOL (proto));
2742 g_slist_free (provider_protos);
2744 gtk_widget_destroy (GTK_WIDGET (cancel_note));
2745 priv->check_support_cancel_note = NULL;
2746 priv->check_support_progress = NULL;
2751 check_support_of_protocols (ModestEasysetupWizardDialog *self)
2753 ModestProtocolRegistry *registry;
2754 GSList *provider_protos, *node, *check_support_providers;
2755 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2757 registry = modest_runtime_get_protocol_registry ();
2758 provider_protos = modest_protocol_registry_get_by_tag (registry,
2759 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2761 check_support_providers = NULL;
2762 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2763 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2765 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2766 modest_protocol_get_type_id (proto),
2767 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2770 if (modest_protocol_registry_protocol_type_has_tag
2772 modest_protocol_get_type_id (proto),
2773 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2774 /* Check if there's already an account configured with this account type */
2775 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2776 modest_protocol_get_type_id (proto)))
2780 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2781 priv->pending_check_support ++;
2782 check_support_providers = g_slist_prepend (check_support_providers, proto);
2785 g_slist_free (provider_protos);
2787 for (node = check_support_providers; node != NULL; node = g_slist_next (node)) {
2788 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2790 modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
2791 check_support_callback,
2792 g_object_ref (self));
2794 g_slist_free (check_support_providers);
2796 if (priv->pending_check_support > 0) {
2797 priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
2798 check_support_show_progress,
2799 g_object_ref (self), g_object_unref);
2800 priv->check_support_progress_pulse_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 200,
2801 check_support_progress_pulse,
2802 g_object_ref (self), g_object_unref);
2803 priv->check_support_progress = gtk_progress_bar_new ();
2804 #ifdef MODEST_TOOLKIT_HILDON2
2805 priv->check_support_cancel_note = hildon_note_new_cancel_with_progress_bar (GTK_WINDOW (self),
2806 _("mcen_cn_availability_check"),
2807 GTK_PROGRESS_BAR (priv->check_support_progress));
2808 gtk_widget_show (priv->check_support_cancel_note);
2809 g_signal_connect (priv->check_support_cancel_note, "response", G_CALLBACK (on_check_support_cancel), self);
2812 priv->check_support_done = TRUE;
2814 fill_providers (self);
2816 invoke_enable_buttons_vfunc (self);