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_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);
539 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
540 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
541 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
542 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
543 gtk_widget_show (label);
545 /* Create a size group to be used by all captions.
546 * Note that HildonCaption does not create a default size group if we do not specify one.
547 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
548 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
549 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
551 /* The country widgets: */
552 priv->account_country_selector = modest_toolkit_factory_create_country_selector (modest_runtime_get_toolkit_factory ());
553 if (GTK_IS_COMBO_BOX (priv->account_country_selector)) {
554 GtkWidget *captioned;
555 g_signal_connect (G_OBJECT (priv->account_country_selector), "changed",
556 G_CALLBACK (on_picker_button_value_changed), self);
557 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
558 _("mcen_fi_country"), FALSE,
559 priv->account_country_selector);
561 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
562 gtk_widget_show (captioned);
564 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
565 _("mcen_fi_country"), priv->account_country_selector);
566 g_signal_connect (G_OBJECT (priv->account_country_selector), "value-changed",
567 G_CALLBACK (on_picker_button_value_changed), self);
568 gtk_box_pack_start (GTK_BOX (box), priv->account_country_selector, FALSE, FALSE, MODEST_MARGIN_HALF);
570 gtk_widget_show (priv->account_country_selector);
572 /* The service provider widgets: */
573 priv->account_serviceprovider_selector = modest_toolkit_factory_create_provider_selector (modest_runtime_get_toolkit_factory ());
574 if (GTK_IS_COMBO_BOX (priv->account_serviceprovider_selector)) {
575 GtkWidget *captioned;
576 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "changed",
577 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
578 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
579 _("mcen_fi_serviceprovider"), FALSE,
580 priv->account_serviceprovider_selector);
582 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "changed",
583 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
584 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
585 gtk_widget_show (captioned);
587 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
588 _("mcen_fi_serviceprovider"),
589 priv->account_serviceprovider_selector);
590 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "value-changed",
591 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
592 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_selector, FALSE, FALSE, 0);
594 gtk_widget_show (priv->account_serviceprovider_selector);
596 /* The description widgets: */
597 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
599 /* Do use auto-capitalization: */
601 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
602 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
605 /* Set a default account title, choosing one that does not already exist: */
606 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
607 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
608 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
609 priv->account_manager, default_account_name_start);
610 g_free (default_account_name_start);
611 default_account_name_start = NULL;
613 modest_entry_set_text (priv->entry_account_title, default_account_name);
614 g_free (default_account_name);
615 default_account_name = NULL;
617 /* Connect signal after changing the text in the entry */
618 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
619 G_CALLBACK(on_easysetup_changed), self);
621 tmp_str = g_strconcat (_("mcen_fi_account_title"), "*", NULL);
622 priv->caption_account_title = create_captioned (self, title_sizegroup, value_sizegroup,
624 priv->entry_account_title);
626 gtk_widget_show (priv->entry_account_title);
627 gtk_box_pack_start (GTK_BOX (box), priv->caption_account_title, FALSE, FALSE, 0);
628 gtk_widget_show (priv->caption_account_title);
629 gtk_widget_set_no_show_all (priv->caption_account_title, TRUE);
631 /* Prevent the use of some characters in the account title,
632 * as required by our UI specification: */
633 GList *list_prevent = NULL;
634 list_prevent = g_list_append (list_prevent, "\\");
635 list_prevent = g_list_append (list_prevent, "/");
636 list_prevent = g_list_append (list_prevent, ":");
637 list_prevent = g_list_append (list_prevent, "*");
638 list_prevent = g_list_append (list_prevent, "?");
639 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
640 list_prevent = g_list_append (list_prevent, "“");
641 list_prevent = g_list_append (list_prevent, "<");
642 list_prevent = g_list_append (list_prevent, ">");
643 list_prevent = g_list_append (list_prevent, "|");
644 list_prevent = g_list_append (list_prevent, "^");
645 modest_validating_entry_set_unallowed_characters (
646 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
647 g_list_free (list_prevent);
649 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
650 modest_utils_on_entry_invalid_character, self);
652 /* Set max length as in the UI spec:
653 * The UI spec seems to want us to show a dialog if we hit the maximum. */
654 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
655 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
658 gtk_widget_show (GTK_WIDGET (box));
660 g_object_unref (title_sizegroup);
661 g_object_unref (value_sizegroup);
663 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
664 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
665 gtk_widget_show (align);
666 gtk_container_add (GTK_CONTAINER (align), box);
668 return GTK_WIDGET (align);
672 on_user_username_changed(GtkWidget* widget, ModestEasysetupWizardDialog *self)
674 ModestEasysetupWizardDialogPrivate* priv;
675 gchar* provider_id = NULL;
677 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
679 /* Work out the user email address */
680 provider_id = modest_provider_selector_get_active_provider_id (
681 priv->account_serviceprovider_selector);
684 const gchar *current_username;
685 gchar *email_address;
686 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
688 current_username = modest_entry_get_text (priv->entry_user_username);
690 if (current_username && strstr (current_username, "@")) {
691 email_address = g_strdup (current_username);
693 email_address = g_strdup_printf ("%s@%s",
698 /* Update the email address */
699 modest_entry_set_text (priv->entry_user_email, email_address);
701 g_free (email_address);
702 g_free (domain_name);
703 g_free (provider_id);
707 on_easysetup_changed(widget, self);
712 create_page_user_details (ModestEasysetupWizardDialog *self)
714 GtkSizeGroup* title_sizegroup;
715 GtkSizeGroup* value_sizegroup;
717 ModestEasysetupWizardDialogPrivate *priv;
719 const gchar *my_name;
722 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
724 /* Create a size group to be used by all captions.
725 * Note that HildonCaption does not create a default size group if we do not specify one.
726 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
727 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
728 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
729 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
731 /* The name widgets: (use auto cap) */
732 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
734 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
735 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
738 /* Set max length as in the UI spec:
739 * The UI spec seems to want us to show a dialog if we hit the maximum. */
740 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
741 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
743 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
744 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
746 /* Try to initialize the user name with my own contact */
747 my_name = modest_address_book_get_my_name ();
749 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_name), my_name);
751 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
752 G_CALLBACK(on_easysetup_changed), self);
753 gtk_widget_show (priv->entry_user_name);
754 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
755 gtk_widget_show (caption);
757 /* Prevent the use of some characters in the name,
758 * as required by our UI specification: */
759 GList *list_prevent = NULL;
760 list_prevent = g_list_append (list_prevent, "<");
761 list_prevent = g_list_append (list_prevent, ">");
762 modest_validating_entry_set_unallowed_characters (
763 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
764 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
765 modest_utils_on_entry_invalid_character, self);
766 g_list_free (list_prevent);
768 /* The username widgets: */
769 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
770 /* Auto-capitalization is the default, so let's turn it off: */
772 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
773 HILDON_GTK_INPUT_MODE_FULL);
775 tmp_str = g_strconcat (_("mail_fi_username"), "*", NULL);
776 caption = create_captioned (self, title_sizegroup, value_sizegroup,
778 priv->entry_user_username);
780 gtk_widget_show (priv->entry_user_username);
781 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
782 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
783 G_CALLBACK(on_user_username_changed), self);
784 gtk_widget_show (caption);
786 /* Prevent the use of some characters in the username,
787 * as required by our UI specification: */
788 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
789 modest_utils_on_entry_invalid_character, self);
791 /* Set max length as in the UI spec:
792 * The UI spec seems to want us to show a dialog if we hit the maximum. */
793 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
794 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
797 /* The password widgets: */
798 priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
799 /* Auto-capitalization is the default, so let's turn it off: */
801 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
802 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
804 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
805 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
806 caption = create_captioned (self, title_sizegroup, value_sizegroup,
807 _("mail_fi_password"), FALSE, priv->entry_user_password);
808 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
809 G_CALLBACK(on_easysetup_changed), self);
810 gtk_widget_show (priv->entry_user_password);
811 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
812 gtk_widget_show (caption);
814 /* The email address widgets: */
815 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
816 /* Auto-capitalization is the default, so let's turn it off: */
818 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
820 tmp_str = g_strconcat (_("mcen_li_emailsetup_email_address"), "*", NULL);
821 caption = create_captioned (self, title_sizegroup, value_sizegroup,
822 tmp_str, FALSE, priv->entry_user_email);
824 update_user_email_from_provider (self);
825 gtk_widget_show (priv->entry_user_email);
826 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
827 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
828 G_CALLBACK(on_easysetup_changed), self);
829 gtk_widget_show (caption);
831 /* Set max length as in the UI spec:
832 * The UI spec seems to want us to show a dialog if we hit the maximum. */
833 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
834 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
838 gtk_widget_show (GTK_WIDGET (box));
839 g_object_unref (title_sizegroup);
840 g_object_unref (value_sizegroup);
842 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
843 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
844 gtk_widget_show (align);
845 gtk_container_add (GTK_CONTAINER (align), box);
847 return GTK_WIDGET (align);
851 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
854 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
856 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
857 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
858 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
859 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
860 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
862 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
863 gtk_widget_show (label);
865 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
866 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
867 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
869 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
870 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
871 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
872 gtk_widget_show (label);
874 gtk_widget_show (GTK_WIDGET (box));
876 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
877 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
878 gtk_widget_show (align);
879 gtk_container_add (GTK_CONTAINER (align), box);
881 return GTK_WIDGET (align);
884 /** Change the caption title for the incoming server,
885 * as specified in the UI spec:
888 update_incoming_server_title (ModestEasysetupWizardDialog *self)
890 ModestEasysetupWizardDialogPrivate* priv;
891 ModestProtocolType protocol_type;
892 ModestProtocolRegistry *protocol_registry;
894 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
895 protocol_registry = modest_runtime_get_protocol_registry ();
897 protocol_type = modest_servertype_selector_get_active_servertype (
898 priv->incoming_servertype_selector);
900 /* This could happen when the combo box has still no active iter */
901 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
902 gchar* incomingserver_title;
903 const gchar *protocol_display_name;
904 ModestProtocol *protocol;
906 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
908 protocol_display_name = modest_protocol_get_display_name (protocol);
910 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "*\n<small>(",
911 protocol_display_name, ")</small>", NULL);
913 modest_toolkit_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
915 g_free(incomingserver_title);
919 /** Change the caption title for the incoming server,
920 * as specified in the UI spec:
923 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
925 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
926 GtkWidget *server_type_selector;
927 ModestProtocolType protocol_type;
928 ModestSecurityOptionsView *view;
930 server_type_selector = priv->incoming_servertype_selector;
931 protocol_type = modest_servertype_selector_get_active_servertype (server_type_selector);
933 /* Fill the combo with appropriately titled choices for all
935 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
936 modest_security_options_view_set_server_type (view, protocol_type);
939 #ifdef HILDON_PICKER_BUTTON
941 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
943 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
944 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
949 update_incoming_server_title (self);
951 /* Update security options if needed */
952 update_incoming_server_security_choices (self);
953 gtk_widget_show (priv->incoming_security);
955 set_default_custom_servernames (self);
960 on_servertype_combo_changed(GtkWidget *selector, gpointer user_data)
962 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
963 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
968 update_incoming_server_title (self);
970 /* Update security options if needed */
971 update_incoming_server_security_choices (self);
972 gtk_widget_show (priv->incoming_security);
974 set_default_custom_servernames (self);
978 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
980 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
981 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
983 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
987 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
989 ModestProtocolRegistry *protocol_registry;
990 ModestEasysetupWizardDialogPrivate* priv;
993 GtkWidget *scrollable;
995 GtkSizeGroup *title_sizegroup;
996 GtkSizeGroup *value_sizegroup;
998 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
999 protocol_registry = modest_runtime_get_protocol_registry ();
1001 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1002 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1004 /* Show note that account type cannot be changed in future: */
1005 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
1006 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1007 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1008 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1009 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1010 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1011 gtk_widget_show (label);
1013 /* Create a size group to be used by all captions.
1014 * Note that HildonCaption does not create a default size group if we do not specify one.
1015 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1016 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1017 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1019 /* The incoming server widgets: */
1020 priv->incoming_servertype_selector =
1021 modest_toolkit_factory_create_servertype_selector (modest_runtime_get_toolkit_factory (),
1023 if (GTK_IS_COMBO_BOX (priv->incoming_servertype_selector)) {
1024 GtkWidget *captioned;
1025 g_signal_connect (G_OBJECT (priv->incoming_servertype_selector), "changed",
1026 G_CALLBACK (on_picker_button_value_changed), self);
1027 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
1028 _("mcen_fi_country"), FALSE,
1029 priv->incoming_servertype_selector);
1031 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
1032 gtk_widget_show (captioned);
1034 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
1035 _("mcen_li_emailsetup_type"),
1036 priv->incoming_servertype_selector);
1037 g_signal_connect (G_OBJECT (priv->incoming_servertype_selector), "value-changed",
1038 G_CALLBACK (on_picker_button_value_changed), self);
1039 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_selector, FALSE, FALSE, 0);
1041 gtk_widget_show (priv->incoming_servertype_selector);
1043 priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
1045 /* Auto-capitalization is the default, so let's turn it off: */
1046 #ifdef MAEMO_CHANGES
1047 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
1049 set_default_custom_servernames (self);
1051 /* The caption title will be updated in update_incoming_server_title().
1052 * so this default text will never be seen: */
1053 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
1054 "This will be removed",
1055 FALSE, priv->entry_incomingserver);
1056 update_incoming_server_title (self);
1057 gtk_widget_show (priv->entry_incomingserver);
1058 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
1059 gtk_widget_show (priv->caption_incoming);
1061 /* Remember when the servername was changed manually: */
1062 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
1063 G_CALLBACK (on_entry_incoming_servername_changed), self);
1065 /* The secure connection widgets. These are only valid for
1066 protocols with security */
1067 priv->incoming_security = modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
1068 MODEST_SECURITY_OPTIONS_INCOMING,
1069 FALSE, title_sizegroup, value_sizegroup);
1070 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
1072 gtk_widget_show (priv->incoming_security);
1074 /* Set default selection */
1075 modest_servertype_selector_set_active_servertype (priv->incoming_servertype_selector,
1076 MODEST_PROTOCOLS_STORE_POP);
1077 update_incoming_server_title (self);
1078 update_incoming_server_security_choices (self);
1079 set_default_custom_servernames (self);
1081 /* Change the caption title when the servertype changes,
1082 * as in the UI spec: */
1083 if (GTK_IS_COMBO_BOX (priv->incoming_servertype_selector)) {
1084 g_signal_connect (priv->incoming_servertype_selector,
1086 G_CALLBACK (on_servertype_combo_changed), self);
1088 #ifdef HILDON_PICKER_BUTTON
1089 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_selector))),
1091 G_CALLBACK (on_servertype_selector_changed), self);
1095 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1096 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1097 gtk_widget_show (align);
1098 gtk_container_add (GTK_CONTAINER (align), box);
1100 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1101 gtk_widget_show (GTK_WIDGET (box));
1102 gtk_widget_show (scrollable);
1104 g_object_unref (title_sizegroup);
1105 g_object_unref (value_sizegroup);
1107 /* Connect changed signals. We do it here after initializing everything */
1108 g_signal_connect (G_OBJECT(priv->entry_incomingserver), "changed",
1109 G_CALLBACK(on_easysetup_changed), self);
1112 return GTK_WIDGET (scrollable);
1116 on_check_button_changed (GtkWidget *button, gpointer user_data)
1118 GtkWidget *widget = GTK_WIDGET (user_data);
1120 /* Enable the widget only if the check button is active: */
1121 const gboolean enable = modest_togglable_get_active (button);
1122 gtk_widget_set_sensitive (widget, enable);
1125 /* Make the sensitivity of a widget depend on a check button.
1128 enable_widget_for_checkbutton (GtkWidget *widget, GtkWidget* button)
1130 g_signal_connect (G_OBJECT (button), "toggled",
1131 G_CALLBACK (on_check_button_changed), widget);
1133 /* Set the starting sensitivity: */
1134 on_check_button_changed (button, widget);
1138 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
1140 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1141 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1142 GtkWidget *specific_window;
1144 /* We set dirty here because setting it depending on the connection specific dialog
1148 /* Create the window, if necessary: */
1149 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
1150 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
1152 /* Show the window */
1153 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
1154 gtk_widget_show (specific_window);
1158 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
1160 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1161 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1162 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
1166 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
1168 ModestEasysetupWizardDialogPrivate *priv;
1169 gchar *smtp_caption_label;
1170 GtkWidget *scrollable;
1172 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1174 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1176 /* Create a size group to be used by all captions.
1177 * Note that HildonCaption does not create a default size group if we do not specify one.
1178 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1179 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1180 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1182 /* The outgoing server widgets: */
1183 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1184 priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
1186 /* Auto-capitalization is the default, so let's turn it off: */
1187 #ifdef MAEMO_CHANGES
1188 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
1190 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "*\n<small>(SMTP)</small>", NULL);
1192 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
1193 smtp_caption_label, TRUE, priv->entry_outgoingserver);
1194 g_free (smtp_caption_label);
1195 gtk_widget_show (priv->entry_outgoingserver);
1196 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
1197 gtk_widget_show (caption);
1198 set_default_custom_servernames (self);
1200 /* The secure connection widgets. These are only valid for
1201 protocols with security */
1202 priv->outgoing_security =
1203 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
1204 MODEST_SECURITY_OPTIONS_OUTGOING,
1205 FALSE, title_sizegroup, value_sizegroup);
1206 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
1208 gtk_widget_show (priv->outgoing_security);
1210 GtkWidget *separator = gtk_hseparator_new ();
1211 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
1212 gtk_widget_show (separator);
1214 /* connection-specific checkbox: */
1215 priv->checkbox_outgoing_smtp_specific = modest_toolkit_factory_create_check_button
1216 (modest_runtime_get_toolkit_factory (),
1217 _("mcen_fi_advsetup_connection_smtp"));
1218 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
1221 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1222 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
1225 /* Connection-specific SMTP-Severs Edit button: */
1226 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
1227 #ifdef MAEMO_CHANGES
1228 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
1229 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1231 gtk_widget_show (priv->button_outgoing_smtp_servers);
1232 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
1235 /* Only enable the button when the checkbox is checked: */
1236 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
1237 priv->checkbox_outgoing_smtp_specific);
1239 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1240 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1242 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1243 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1246 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1247 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1248 gtk_widget_show (align);
1249 gtk_container_add (GTK_CONTAINER (align), box);
1251 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1252 gtk_widget_show (GTK_WIDGET (box));
1253 gtk_widget_show (scrollable);
1255 g_object_unref (title_sizegroup);
1256 g_object_unref (value_sizegroup);
1258 /* Connect changed signals. We do it here after initializing everything */
1259 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1260 G_CALLBACK (on_easysetup_changed), self);
1261 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1262 G_CALLBACK (on_easysetup_changed), self);
1264 return GTK_WIDGET (scrollable);
1268 show_advanced_edit(gpointer user_data)
1270 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1271 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1274 /* Show the Account Settings window: */
1275 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
1276 if (priv->pending_load_settings) {
1277 save_to_settings (self);
1278 priv->pending_load_settings = FALSE;
1280 modest_account_settings_dialog_load_settings (dialog, priv->settings);
1282 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
1284 response = gtk_dialog_run (GTK_DIALOG (dialog));
1286 gtk_widget_destroy (GTK_WIDGET (dialog));
1288 return FALSE; /* Do not call this timeout callback again. */
1292 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1294 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1296 /* Show the Account Settings window: */
1297 show_advanced_edit(self);
1300 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1302 gchar *complete_string;
1306 GtkWidget *button_edit;
1308 box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1309 complete_string = g_strconcat (_("mcen_ia_emailsetup_setup_complete"), " ",
1310 _("mcen_ia_customsetup_complete"), NULL);
1311 label = gtk_label_new(complete_string);
1312 g_free (complete_string);
1313 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1314 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1315 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1316 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1317 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1318 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1319 gtk_widget_show (label);
1321 button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1322 #ifdef MAEMO_CHANGES
1323 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1325 gtk_widget_show (button_edit);
1326 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, 0);
1328 g_signal_connect (G_OBJECT (button_edit), "clicked",
1329 G_CALLBACK (on_button_edit_advanced_settings), self);
1331 gtk_widget_show (GTK_WIDGET (box));
1333 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1334 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
1335 gtk_widget_show (align);
1336 gtk_container_add (GTK_CONTAINER (align), box);
1338 return GTK_WIDGET (align);
1345 on_response (ModestWizardDialog *wizard_dialog,
1349 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1351 invoke_enable_buttons_vfunc (self);
1355 on_response_before (ModestWizardDialog *wizard_dialog,
1359 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1360 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1361 if (response_id == GTK_RESPONSE_CANCEL) {
1362 /* This is mostly copied from
1363 * src/maemo/modest-account-settings-dialog.c */
1365 gint dialog_response;
1367 dialog_response = modest_platform_run_confirmation_dialog ((GtkWindow *) self,
1368 _("imum_nc_wizard_confirm_lose_changes"));
1370 if (dialog_response != GTK_RESPONSE_OK) {
1371 /* Don't let the dialog close */
1372 g_signal_stop_emission_by_name (wizard_dialog, "response");
1379 fill_providers (ModestEasysetupWizardDialog *self)
1381 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1383 if (priv->account_country_selector) {
1384 /* gint mcc = get_default_country_code(); */
1386 /* Fill the combo in an idle call, as it takes a lot of time */
1387 modest_country_selector_load_data(priv->account_country_selector);
1388 /* connect to country picker's changed signal, so we can fill the provider picker: */
1389 if (GTK_IS_COMBO_BOX (priv->account_country_selector)) {
1390 g_signal_connect ((GObject *) priv->account_country_selector,
1392 G_CALLBACK (on_account_country_selector_changed), self);
1394 g_signal_connect ((GObject *) priv->account_country_selector,
1396 G_CALLBACK (on_account_country_selector_changed), self);
1399 modest_country_selector_set_active_country_locale (priv->account_country_selector);
1400 mcc = modest_country_selector_get_active_country_mcc (priv->account_country_selector);
1401 modest_provider_selector_fill (
1402 priv->account_serviceprovider_selector,
1403 priv->presets, mcc);
1404 /* connect to providers picker's changed signal, so we can fill the email address: */
1405 if (GTK_IS_COMBO_BOX (priv->account_serviceprovider_selector)) {
1406 g_signal_connect (priv->account_serviceprovider_selector,
1408 G_CALLBACK (on_account_serviceprovider_selector_combo_box_changed), self);
1410 #ifdef HILDON_PICKER_BUTTON
1411 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1412 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_selector))),
1414 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1417 modest_provider_selector_set_others_provider (priv->account_serviceprovider_selector);
1420 priv->dirty = FALSE;
1424 typedef struct IdleData {
1425 ModestEasysetupWizardDialog *dialog;
1426 ModestPresets *presets;
1430 presets_idle (gpointer userdata)
1432 IdleData *idle_data = (IdleData *) userdata;
1433 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1434 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1436 g_assert (idle_data->presets);
1438 gdk_threads_enter ();
1440 priv->presets = idle_data->presets;
1442 if (priv->check_support_done)
1443 fill_providers (self);
1445 g_object_unref (idle_data->dialog);
1448 gdk_threads_leave ();
1454 presets_loader (gpointer userdata)
1456 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1457 ModestPresets *presets = NULL;
1458 IdleData *idle_data;
1460 const gchar* path = NULL;
1461 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1462 const gchar* path2 = MODEST_FALLBACK_PROVIDER_DATA_FILE;
1464 if (access(path1, R_OK) == 0)
1466 else if (access(path2, R_OK) == 0)
1469 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1470 __FUNCTION__, path1, path2);
1474 presets = modest_presets_new (path);
1476 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1480 idle_data = g_new0 (IdleData, 1);
1481 idle_data->dialog = self;
1482 idle_data->presets = presets;
1484 g_idle_add (presets_idle, idle_data);
1490 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1496 /* Append page and set attributes */
1497 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1498 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1499 "tab-expand", TRUE, "tab-fill", TRUE,
1502 /* Give focus to page and show it */
1503 gtk_container_set_focus_child (GTK_CONTAINER (notebook), page);
1504 gtk_widget_show (page);
1508 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1510 priv->page_user_details = NULL;
1511 priv->entry_user_name = NULL;
1512 priv->entry_user_username = NULL;
1513 priv->entry_user_password = NULL;
1514 priv->entry_user_email = NULL;
1518 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1520 priv->page_custom_incoming = NULL;
1521 priv->incoming_servertype_selector = NULL;
1522 priv->caption_incoming = NULL;
1523 priv->entry_incomingserver = NULL;
1524 priv->entry_user_email = NULL;
1525 priv->incoming_security = NULL;
1529 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1531 priv->page_custom_outgoing = NULL;
1532 priv->entry_outgoingserver = NULL;
1533 priv->checkbox_outgoing_smtp_specific = NULL;
1534 priv->button_outgoing_smtp_servers = NULL;
1535 priv->outgoing_security = NULL;
1539 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1541 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1543 /* Create the notebook to be used by the ModestWizardDialog base class:
1544 * Each page of the notebook will be a page of the wizard: */
1545 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1546 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1548 /* Set the notebook used by the ModestWizardDialog base class: */
1549 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1551 /* Set the wizard title:
1552 * The actual window title will be a combination of this and the page's tab label title. */
1553 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1555 /* Read in the information about known service providers: */
1556 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1558 /* The server fields did not have been manually changed yet */
1559 priv->server_changes = 0;
1560 priv->pending_load_settings = TRUE;
1562 /* Get the account manager object,
1563 * so we can check for existing accounts,
1564 * and create new accounts: */
1565 priv->account_manager = modest_runtime_get_account_mgr ();
1566 g_object_ref (priv->account_manager);
1568 /* Initialize fields */
1569 priv->check_support_done = FALSE;
1570 priv->check_support_show_progress_id = 0;
1571 priv->check_support_progress_pulse_id = 0;
1572 priv->check_support_cancel_note = NULL;
1573 priv->check_support_progress = NULL;
1574 priv->pending_check_support = 0;
1575 priv->destroyed = FALSE;
1576 priv->page_welcome = create_page_welcome (self);
1577 gtk_widget_show (priv->page_welcome);
1578 priv->page_account_details = create_page_account_details (self);
1580 init_user_page (priv);
1581 init_incoming_page (priv);
1582 init_outgoing_page (priv);
1584 priv->page_complete_easysetup = NULL;
1585 priv->page_complete_customsetup = NULL;
1586 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1587 priv->missing_data_signals = NULL;
1589 /* Add the common pages */
1590 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1591 _("mcen_ti_emailsetup_welcome"));
1592 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1593 _("mcen_ti_accountdetails"));
1595 /* Connect to the dialog's response signal so we can enable/disable buttons
1596 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1597 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1598 * so that we can be enable/disable after ModestWizardDialog has done its own
1599 * enabling/disabling of buttons.
1601 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1602 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1604 * It's not enough to connect to the notebook's switch-page signal, because
1605 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1606 * _after_ switching the page (understandably).
1607 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1608 * then gtk_notebook_get_current_page() would return an incorrect value.)
1610 g_signal_connect_after (G_OBJECT (self), "response",
1611 G_CALLBACK (on_response), self);
1613 /* This is to show a confirmation dialog when the user hits cancel */
1614 g_signal_connect (G_OBJECT (self), "response",
1615 G_CALLBACK (on_response_before), self);
1617 g_signal_connect (G_OBJECT (self), "delete-event",
1618 G_CALLBACK (on_delete_event), self);
1620 /* Reset dirty, because there was no user input until now */
1621 priv->dirty = FALSE;
1623 /* When this window is shown, hibernation should not be possible,
1624 * because there is no sensible way to save the state: */
1625 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1626 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1628 /* Load provider presets */
1629 g_object_ref (self);
1630 g_thread_create (presets_loader, self, FALSE, NULL);
1632 priv->settings = modest_account_settings_new ();
1636 ModestEasysetupWizardDialog*
1637 modest_easysetup_wizard_dialog_new (void)
1640 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1644 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1646 ModestEasysetupWizardDialogPrivate *priv;
1647 GtkNotebook *notebook = NULL;
1649 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1652 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1654 if (!priv->page_user_details) {
1655 priv->page_user_details = create_page_user_details (self);
1658 /* Create the custom pages: */
1659 if(!(priv->page_custom_incoming)) {
1660 priv->page_custom_incoming = create_page_custom_incoming (self);
1663 /* TODO: only if needed */
1664 if(!(priv->page_custom_outgoing)) {
1665 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1668 if(!(priv->page_complete_customsetup)) {
1669 priv->page_complete_customsetup = create_page_complete_custom (self);
1672 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1673 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1674 _("mcen_ti_emailsetup_userdetails"));
1676 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1677 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1678 _("mcen_ti_emailsetup_incomingdetails"));
1680 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1681 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1682 _("mcen_ti_emailsetup_outgoingdetails"));
1684 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1685 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1686 _("mcen_ti_emailsetup_complete"));
1688 /* This is unnecessary with GTK+ 2.10: */
1689 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1693 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1695 ModestEasysetupWizardDialogPrivate *priv;
1696 GtkNotebook *notebook = NULL;
1698 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1701 /* Create the easysetup-specific pages: */
1702 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1703 if(!priv->page_complete_easysetup)
1704 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1706 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1707 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1708 _("mcen_ti_emailsetup_complete"));
1710 /* This is unnecessary with GTK+ 2.10: */
1711 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1716 remove_non_common_tabs (ModestEasysetupWizardDialog *self,
1717 gboolean remove_user_details)
1720 GtkNotebook *notebook;
1721 ModestEasysetupWizardDialogPrivate *priv;
1723 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1724 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1726 /* The first 2 tabs are the common ones (welcome tab and the
1727 providers tab), so we always remove starting from the
1729 starting_tab = (remove_user_details) ? 2 : 3;
1730 while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
1731 /* Disconnect signal */
1732 GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
1733 if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
1734 priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
1736 "missing-mandatory-data");
1738 /* Remove page from notebook */
1739 gtk_notebook_remove_page (notebook, -1);
1744 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1748 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1751 /* After the user details page,
1752 * the following pages depend on whether "Other" was chosen
1753 * in the provider combobox on the account page
1756 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1758 ModestEasysetupWizardDialogPrivate *priv;
1760 ModestProviderSelectorIdType id_type;
1761 GtkNotebook *notebook;
1763 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1764 picker = priv->account_serviceprovider_selector;
1765 id_type = modest_provider_selector_get_active_id_type (picker);
1766 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1768 /* Remove the response override handler for non-plugin
1769 protocols. For plugins it'll be overriden later */
1770 if (id_type != MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL)
1771 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1775 if (id_type == MODEST_PROVIDER_SELECTOR_ID_OTHER) {
1776 /* "Other..." was selected: */
1778 /* If we come from a rollbacked easysetup */
1779 if (priv->page_complete_easysetup) {
1780 remove_non_common_tabs (self, FALSE);
1781 priv->page_complete_easysetup = NULL;
1784 /* If we come from a rollbacked plugin protocol setup */
1785 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1786 remove_non_common_tabs (self, TRUE);
1787 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1788 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1789 priv->missing_data_signals = NULL;
1792 create_subsequent_customsetup_pages (self);
1794 /* If we come from a rollbacked custom setup */
1795 if (priv->page_custom_incoming) {
1796 remove_non_common_tabs (self, TRUE);
1797 init_user_page (priv);
1798 init_incoming_page (priv);
1799 init_outgoing_page (priv);
1800 init_user_page (priv);
1801 priv->page_complete_customsetup = NULL;
1804 /* It's a pluggable protocol and not a provider with presets */
1805 if (id_type == MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL) {
1806 ModestProtocol *protocol;
1808 ModestProtocolType proto_type;
1809 ModestWizardDialogResponseOverrideFunc response_override;
1811 /* Get protocol data */
1812 proto_name = modest_provider_selector_get_active_provider_id (picker);
1813 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1814 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1816 proto_type = modest_protocol_get_type_id (protocol);
1819 /* If we come from a rollbacked easy setup */
1820 if (priv->last_plugin_protocol_selected != proto_type &&
1821 priv->page_complete_easysetup) {
1822 remove_non_common_tabs (self, TRUE);
1823 init_user_page (priv);
1824 priv->page_complete_easysetup = NULL;
1827 /* Ensure that the response override handler
1828 is set. It might happen that plugins clear
1830 response_override = modest_account_protocol_get_wizard_response_override
1831 (MODEST_ACCOUNT_PROTOCOL (protocol));
1832 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1835 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1836 proto_type != priv->last_plugin_protocol_selected) {
1837 ModestPairList *tabs;
1839 gboolean first_page = TRUE;
1841 /* Remember the last selected plugin protocol */
1842 priv->last_plugin_protocol_selected = proto_type;
1845 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1846 tmp = (GSList *) tabs;
1848 ModestPair *pair = (ModestPair *) tmp->data;
1849 modest_easysetup_wizard_dialog_append_page (notebook,
1850 GTK_WIDGET (pair->second),
1851 (const gchar *) pair->first);
1853 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1854 GTK_WIDGET (pair->second));
1858 /* Connect signals */
1859 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1860 priv->missing_data_signals =
1861 modest_signal_mgr_connect (priv->missing_data_signals,
1862 G_OBJECT (pair->second),
1863 "missing-mandatory-data",
1864 G_CALLBACK (on_missing_mandatory_data),
1868 g_free (pair->first);
1869 tmp = g_slist_next (tmp);
1870 /* Critical: if you don't show the page then the dialog will ignore it */
1871 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1873 modest_pair_list_free (tabs);
1875 g_free (proto_name);
1877 if (priv->last_plugin_protocol_selected !=
1878 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1879 remove_non_common_tabs (self, TRUE);
1880 init_user_page (priv);
1881 priv->page_complete_easysetup = NULL;
1882 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1883 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1884 priv->missing_data_signals = NULL;
1886 if (!priv->page_user_details) {
1887 priv->page_user_details = create_page_user_details (self);
1888 modest_easysetup_wizard_dialog_append_page (notebook,
1889 priv->page_user_details,
1890 _("mcen_ti_emailsetup_userdetails"));
1894 /* Create the easysetup pages: */
1895 create_subsequent_easysetup_pages (self);
1901 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1903 const gchar* hostname = NULL;
1906 ModestProtocolRegistry *protocol_registry;
1907 ModestProtocol *protocol;
1912 at = g_utf8_strchr (email_address, -1, '@');
1913 if (!at || (g_utf8_strlen (at, -1) < 2))
1916 domain = g_utf8_next_char (at);
1920 protocol_registry = modest_runtime_get_protocol_registry ();
1921 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1923 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1924 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1925 hostname = modest_protocol_get_name (protocol);
1931 return g_strdup_printf ("%s.%s", hostname, domain);
1935 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1937 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1939 if (!priv->entry_incomingserver)
1942 /* Set a default domain for the server, based on the email address,
1943 * if no server name was already specified.
1945 if (priv->entry_user_email
1946 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1947 const ModestProtocolType protocol_type = modest_servertype_selector_get_active_servertype (
1948 priv->incoming_servertype_selector);
1950 /* This could happen when the combo box has still no active iter */
1951 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1952 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1953 gchar* servername = util_get_default_servername_from_email_address (email_address,
1956 /* Do not set the INCOMING_CHANGED flag because of this edit */
1957 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1958 modest_entry_set_text (priv->entry_incomingserver, servername);
1959 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1961 g_free (servername);
1965 /* Set a default domain for the server, based on the email address,
1966 * if no server name was already specified.
1968 if (!priv->entry_outgoingserver)
1971 if (priv->entry_user_email
1972 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1973 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1975 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1977 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1978 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1979 modest_entry_set_text (priv->entry_outgoingserver, servername);
1980 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1982 g_free (servername);
1987 get_entered_account_title (ModestEasysetupWizardDialog *self)
1989 ModestEasysetupWizardDialogPrivate *priv;
1990 const gchar* account_title;
1992 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1993 account_title = modest_entry_get_text (priv->entry_account_title);
1995 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1998 /* Strip it of whitespace at the start and end: */
1999 gchar *result = g_strdup (account_title);
2000 result = g_strstrip (result);
2005 if (g_utf8_strlen (result, -1) == 0) {
2015 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
2017 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2018 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2019 ModestProtocolRegistry *protocol_registry;
2021 protocol_registry = modest_runtime_get_protocol_registry ();
2023 /* if are browsing pages previous to the last one, then we have pending settings in
2025 if (next_page != NULL)
2026 priv->pending_load_settings = TRUE;
2028 /* Do extra validation that couldn't be done for every key press,
2029 * either because it was too slow,
2030 * or because it requires interaction:
2032 if (current_page == priv->page_welcome) {
2033 if (!priv->check_support_done) {
2034 check_support_of_protocols (self);
2035 return priv->check_support_done;
2037 } else if (current_page == priv->page_account_details) {
2038 /* Check that the title is not already in use: */
2039 gchar* account_title = get_entered_account_title (self);
2043 /* Aavoid a clash with an existing display name: */
2044 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
2045 priv->account_manager, account_title);
2046 g_free (account_title);
2049 /* Warn the user via a dialog: */
2050 modest_platform_system_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
2055 /* Make sure that the subsequent pages are appropriate for the provider choice. */
2056 create_subsequent_pages (self);
2058 } else if (current_page == priv->page_user_details) {
2059 /* Check that the email address is valud: */
2060 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
2061 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
2064 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
2065 /* Warn the user via a dialog: */
2066 modest_platform_system_banner (NULL, NULL, _("mcen_ib_invalid_email"));
2068 /* Return focus to the email address entry: */
2069 gtk_widget_grab_focus (priv->entry_user_email);
2070 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
2074 } else if (current_page == priv->page_custom_incoming ||
2075 current_page == priv->page_custom_outgoing) {
2077 const gchar *hostname;
2078 GtkWidget *entry = (current_page == priv->page_custom_incoming) ?
2079 priv->entry_incomingserver :
2080 priv->entry_outgoingserver;
2082 hostname = gtk_entry_get_text (GTK_ENTRY (entry));
2083 if (!modest_text_utils_validate_domain_name (hostname)) {
2085 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
2087 /* Return focus to the email address entry: */
2088 gtk_widget_grab_focus (entry);
2089 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
2095 if (next_page == priv->page_custom_incoming) {
2096 set_default_custom_servernames (self);
2097 } else if (next_page == priv->page_custom_outgoing) {
2098 set_default_custom_servernames (self);
2100 /* Check if the server supports secure authentication */
2101 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
2102 if (!check_has_supported_auth_methods (self))
2104 gtk_widget_show (priv->outgoing_security);
2107 /* If this is the last page, and this is a click on Finish,
2108 * then attempt to create the dialog.
2111 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
2113 if (priv->pending_load_settings) {
2114 save_to_settings (self);
2117 /* We check if there's already another account with the same configuration */
2118 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2119 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2123 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2130 static gboolean entry_is_empty (GtkWidget *entry)
2135 const gchar* text = modest_entry_get_text (entry);
2136 if ((!text) || (g_utf8_strlen (text, -1) == 0))
2139 /* Strip it of whitespace at the start and end: */
2140 gchar *stripped = g_strdup (text);
2141 stripped = g_strstrip (stripped);
2146 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
2154 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
2156 GtkNotebook *notebook = NULL;
2157 gboolean is_finish_tab;
2159 ModestEasysetupWizardDialogPrivate *priv;
2162 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
2163 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
2165 /* Disable the Finish button until we are on the last page,
2166 * because HildonWizardDialog enables this for all but the
2168 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
2169 is_finish_tab = ((current == priv->page_complete_easysetup) ||
2170 (current == priv->page_complete_customsetup));
2172 if (is_finish_tab) {
2173 /* Disable Next on the last page no matter what the
2175 enable_next = FALSE;
2177 /* Not the last one */
2178 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2179 MODEST_WIZARD_DIALOG_FINISH,
2182 /* If the check support is not done then do not enable
2183 the wizard to continue */
2184 enable_next = enable_next && priv->pending_check_support == 0;
2187 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2188 MODEST_WIZARD_DIALOG_NEXT,
2193 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
2195 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2196 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2198 gboolean enable_next = TRUE;
2199 if (current_page == priv->page_welcome) {
2201 } else if (current_page == priv->page_account_details) {
2202 /* The account details title is mandatory: */
2203 if (entry_is_empty(priv->entry_account_title))
2204 enable_next = FALSE;
2205 } else if (current_page == priv->page_user_details) {
2206 /* The user details username is mandatory: */
2207 if (entry_is_empty(priv->entry_user_username))
2208 enable_next = FALSE;
2210 /* The user details email address is mandatory: */
2211 if (enable_next && entry_is_empty (priv->entry_user_email))
2212 enable_next = FALSE;
2213 } else if (current_page == priv->page_custom_incoming) {
2214 /* The custom incoming server is mandatory: */
2215 if (entry_is_empty(priv->entry_incomingserver))
2216 enable_next = FALSE;
2217 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
2218 enable_next = !modest_easysetup_wizard_page_validate (
2219 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
2222 /* Enable/disable buttons */
2223 real_enable_buttons (dialog, enable_next);
2227 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
2229 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2230 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
2233 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
2234 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
2236 /* Provide a vfunc implementation so we can decide
2237 * when to enable/disable the prev/next buttons.
2239 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
2240 base_klass->before_next = on_before_next;
2241 base_klass->enable_buttons = on_enable_buttons;
2242 base_klass->update_model = on_update_model;
2243 base_klass->save = on_save;
2247 check_username_for_provider (const gchar *provider_id,
2248 const gchar *domain,
2251 gchar *providers_to_check[] = { "ovi.com", "yahoomailplus.com", "hotmail.com" };
2253 gboolean found = FALSE;
2256 /* Check if the username contains the @hostname, if not then add it */
2257 if (strchr (*username, '@'))
2260 /* Check if it's one of the providers to check */
2261 for (i = 0; i < G_N_ELEMENTS (providers_to_check) && !found; i++) {
2262 if (!g_ascii_strncasecmp (providers_to_check[i], provider_id, strlen (providers_to_check[i])))
2269 /* Replace the username */
2271 *username = g_strconcat (*username, "@", domain, NULL);
2277 * @self: a #ModestEasysetupWizardDialog
2279 * takes information from all the wizard and stores it in settings
2282 save_to_settings (ModestEasysetupWizardDialog *self)
2284 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2286 gchar *provider_id = NULL;
2287 gchar *alternate_username = NULL;
2288 gchar *display_name;
2289 const gchar *username, *password;
2290 gchar *store_hostname, *transport_hostname;
2291 guint store_port, transport_port;
2292 ModestProtocolRegistry *protocol_registry;
2293 ModestProtocolType store_protocol, transport_protocol;
2294 ModestProtocolType store_security, transport_security;
2295 ModestProtocolType store_auth_protocol, transport_auth_protocol;
2296 ModestServerAccountSettings *store_settings, *transport_settings;
2297 const gchar *fullname, *email_address;
2299 ModestProviderSelectorIdType id_type;
2301 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2302 picker = priv->account_serviceprovider_selector;
2303 protocol_registry = modest_runtime_get_protocol_registry ();
2305 /* Get details from the specified presets: */
2306 id_type = modest_provider_selector_get_active_id_type (picker);
2307 provider_id = modest_provider_selector_get_active_provider_id (picker);
2309 /* Let the plugin save the settings. We do a return in order
2310 to save an indentation level */
2311 if (id_type == MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL) {
2312 ModestProtocol *protocol;
2314 protocol = modest_protocol_registry_get_protocol_by_name (
2315 modest_runtime_get_protocol_registry (),
2316 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
2319 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
2320 gint n_pages, i = 0;
2321 GtkNotebook *notebook;
2322 GList *wizard_pages = NULL;
2324 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
2325 n_pages = gtk_notebook_get_n_pages (notebook);
2326 for (i = 0; i < n_pages; i++) {
2327 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
2328 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
2329 wizard_pages = g_list_append (wizard_pages, page);
2331 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
2334 g_list_free (wizard_pages);
2336 g_debug ("The selected protocol is a plugin protocol "//
2337 "but it's not a ModestAccountProtocol");
2340 g_free (provider_id);
2344 /* username and password (for both incoming and outgoing): */
2345 username = modest_entry_get_text (priv->entry_user_username);
2346 password = modest_entry_get_text (priv->entry_user_password);
2348 store_settings = modest_account_settings_get_store_settings (priv->settings);
2349 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
2351 /* Incoming server: */
2352 /* Note: We need something as default for the transport store protocol values,
2353 * or modest_account_mgr_add_server_account will fail. */
2355 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2356 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2357 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2360 ModestProtocolType store_provider_server_type;
2361 gboolean store_provider_use_alternate_port;
2362 gchar *domain = NULL;
2365 store_hostname = modest_presets_get_server (priv->presets, provider_id,
2368 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2371 store_security = modest_presets_get_info_server_security (priv->presets,
2374 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
2377 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
2382 /* This is HORRIBLE, but it seems that somehow it helps users
2383 that do not like to read the user instructions for their
2385 domain = modest_presets_get_domain (priv->presets, provider_id);
2387 alternate_username = g_strdup (username);
2388 check_username_for_provider (provider_id, domain, &alternate_username);
2392 /* We don't check for SMTP here as that is impossible for an incoming server. */
2393 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
2394 store_protocol = MODEST_PROTOCOLS_STORE_POP;
2396 store_protocol = store_provider_server_type;
2398 /* we check if there is a *special* port */
2399 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
2400 if (special_port != 0) {
2401 store_port = special_port;
2403 gboolean use_alternate_port = FALSE;
2404 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2406 use_alternate_port = TRUE;
2407 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
2410 modest_server_account_settings_set_security_protocol (store_settings,
2412 modest_server_account_settings_set_auth_protocol (store_settings,
2413 store_auth_protocol);
2414 if (store_port != 0)
2415 modest_server_account_settings_set_port (store_settings, store_port);
2417 /* Use custom pages because no preset was specified: */
2418 store_hostname = g_strdup (modest_entry_get_text (priv->entry_incomingserver ));
2419 store_protocol = modest_servertype_selector_get_active_servertype (
2420 priv->incoming_servertype_selector);
2422 modest_security_options_view_save_settings (
2423 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2427 /* now we store the common store account settings */
2428 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2429 modest_server_account_settings_set_username (store_settings, (alternate_username) ? alternate_username : username);
2430 modest_server_account_settings_set_password (store_settings, password);
2431 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2433 g_object_unref (store_settings);
2434 g_free (store_hostname);
2436 /* Outgoing server: */
2437 transport_hostname = NULL;
2438 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2439 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2440 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2444 ModestProtocolType transport_provider_server_type;
2445 ModestProtocolType transport_provider_security;
2449 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2450 FALSE /* transport */);
2452 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2454 FALSE /* transport */);
2455 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2457 FALSE /* transport */);
2459 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2460 transport_protocol = transport_provider_server_type;
2461 transport_security = transport_provider_security;
2462 is_secure = modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2463 transport_security);
2465 /* we check if there is a *special* port */
2466 special_port = modest_presets_get_port (priv->presets, provider_id,
2467 FALSE /* transport */);
2468 if (special_port != 0) {
2469 transport_port = special_port;
2471 gboolean use_alternate_port = FALSE;
2472 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL)
2473 use_alternate_port = TRUE;
2474 transport_port = get_port_from_protocol(transport_provider_server_type, use_alternate_port);
2478 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2480 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2482 modest_server_account_settings_set_security_protocol (transport_settings,
2483 transport_security);
2484 modest_server_account_settings_set_auth_protocol (transport_settings,
2485 transport_auth_protocol);
2486 if (transport_port != 0)
2487 modest_server_account_settings_set_port (transport_settings,
2490 ModestProtocolRegistry *registry;
2491 ModestProtocol *store_proto;
2493 registry = modest_runtime_get_protocol_registry ();
2494 /* Use custom pages because no preset was specified: */
2495 transport_hostname = g_strdup (modest_entry_get_text (priv->entry_outgoingserver ));
2497 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2500 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2501 /* fallback to SMTP if none was specified */
2502 g_warning ("No transport protocol was specified for store %d (%s)",
2503 modest_protocol_get_type_id (store_proto),
2504 modest_protocol_get_display_name (store_proto));
2505 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2508 modest_security_options_view_save_settings (
2509 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2513 /* now we store the common transport account settings */
2514 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2515 modest_server_account_settings_set_username (transport_settings, (alternate_username) ? alternate_username : username);
2516 modest_server_account_settings_set_password (transport_settings, password);
2517 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2519 g_object_unref (transport_settings);
2520 g_free (transport_hostname);
2521 if (alternate_username)
2522 g_free (alternate_username);
2524 fullname = modest_entry_get_text (priv->entry_user_name);
2525 email_address = modest_entry_get_text (priv->entry_user_email);
2526 modest_account_settings_set_fullname (priv->settings, fullname);
2527 modest_account_settings_set_email_address (priv->settings, email_address);
2528 /* we don't set retrieve type to preserve advanced settings if
2529 any. By default account settings are set to headers only */
2531 /* Save the connection-specific SMTP server accounts. */
2532 if (priv->checkbox_outgoing_smtp_specific) {
2533 modest_account_settings_set_use_connection_specific_smtp
2535 modest_togglable_get_active(priv->checkbox_outgoing_smtp_specific));
2538 display_name = get_entered_account_title (self);
2539 modest_account_settings_set_display_name (priv->settings, display_name);
2540 g_free (display_name);
2541 g_free (provider_id);
2543 /* This values are hardcoded for Fremantle */
2544 modest_account_settings_set_retrieve_type (priv->settings,
2545 MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS);
2546 modest_account_settings_set_retrieve_limit (priv->settings, 20);
2551 on_update_model (ModestWizardDialog *dialog)
2553 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2554 save_to_settings (self);
2559 on_save (ModestWizardDialog *dialog)
2561 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2562 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2564 save_to_settings (self);
2566 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2567 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2571 return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2577 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2579 GError *error = NULL;
2580 ModestProtocolType protocol_type;
2581 const gchar* hostname;
2582 const gchar* username;
2583 ModestProtocolType security_protocol_incoming_type;
2584 ModestProtocolRegistry *registry;
2586 GList *list_auth_methods;
2587 ModestEasysetupWizardDialogPrivate *priv;
2589 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2590 registry = modest_runtime_get_protocol_registry ();
2591 protocol_type = modest_servertype_selector_get_active_servertype (
2592 priv->incoming_servertype_selector);
2593 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2594 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2595 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2596 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2597 port_num = get_port_from_protocol(protocol_type, FALSE);
2598 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2599 username, GTK_WINDOW (self), &error);
2601 if (list_auth_methods) {
2602 /* TODO: Select the correct method */
2605 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2606 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2607 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2608 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2609 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2613 g_list_free(list_auth_methods);
2619 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2620 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2622 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2623 _("mcen_ib_unableto_discover_auth_methods"));
2627 g_error_free(error);
2633 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2635 GList* methods = check_for_supported_auth_methods(self);
2641 g_list_free(methods);
2646 check_support_show_progress (gpointer userdata)
2648 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2649 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2651 priv->check_support_show_progress_id = 0;
2653 if (priv->destroyed)
2656 #ifdef MODEST_TOOLKIT_HILDON2
2657 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
2664 check_support_progress_pulse (gpointer userdata)
2666 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2667 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2669 if (priv->destroyed || priv->check_support_progress == NULL) {
2670 priv->check_support_progress_pulse_id = 0;
2674 gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->check_support_progress));
2680 check_support_callback (ModestAccountProtocol *protocol,
2684 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2685 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2687 priv->pending_check_support --;
2689 if (priv->check_support_show_progress_id > 0) {
2690 g_source_remove (priv->check_support_show_progress_id);
2691 priv->check_support_show_progress_id = 0;
2694 if (priv->pending_check_support == 0) {
2695 priv->check_support_done = TRUE;
2697 if (priv->check_support_cancel_note) {
2698 gtk_widget_destroy (priv->check_support_cancel_note);
2699 priv->check_support_cancel_note = NULL;
2700 priv->check_support_progress = NULL;
2703 if (!priv->destroyed) {
2705 fill_providers (self);
2706 #ifdef MODEST_TOOLKIT_HILDON2
2707 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
2709 invoke_enable_buttons_vfunc (self);
2710 gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
2713 g_object_unref (self);
2716 #ifdef MODEST_TOOLKIT_HILDON2
2718 on_check_support_cancel (GtkDialog *cancel_note,
2720 ModestEasysetupWizardDialog *self)
2722 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2723 ModestProtocolRegistry *registry;
2724 GSList *provider_protos, *node;
2726 registry = modest_runtime_get_protocol_registry ();
2727 provider_protos = modest_protocol_registry_get_by_tag (registry,
2728 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2730 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2731 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2733 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2734 modest_protocol_get_type_id (proto),
2735 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2738 if (modest_protocol_registry_protocol_type_has_tag
2740 modest_protocol_get_type_id (proto),
2741 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2742 /* Check if there's already an account configured with this account type */
2743 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2744 modest_protocol_get_type_id (proto)))
2748 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2749 modest_account_protocol_cancel_check_support (MODEST_ACCOUNT_PROTOCOL (proto));
2752 g_slist_free (provider_protos);
2754 gtk_widget_destroy (GTK_WIDGET (cancel_note));
2755 priv->check_support_cancel_note = NULL;
2756 priv->check_support_progress = NULL;
2761 check_support_of_protocols (ModestEasysetupWizardDialog *self)
2763 ModestProtocolRegistry *registry;
2764 GSList *provider_protos, *node, *check_support_providers;
2765 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2767 registry = modest_runtime_get_protocol_registry ();
2768 provider_protos = modest_protocol_registry_get_by_tag (registry,
2769 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2771 check_support_providers = NULL;
2772 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2773 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2775 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2776 modest_protocol_get_type_id (proto),
2777 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2780 if (modest_protocol_registry_protocol_type_has_tag
2782 modest_protocol_get_type_id (proto),
2783 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2784 /* Check if there's already an account configured with this account type */
2785 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2786 modest_protocol_get_type_id (proto)))
2790 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2791 priv->pending_check_support ++;
2792 check_support_providers = g_slist_prepend (check_support_providers, proto);
2795 g_slist_free (provider_protos);
2797 for (node = check_support_providers; node != NULL; node = g_slist_next (node)) {
2798 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2800 modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
2801 check_support_callback,
2802 g_object_ref (self));
2804 g_slist_free (check_support_providers);
2806 if (priv->pending_check_support > 0) {
2807 priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
2808 check_support_show_progress,
2809 g_object_ref (self), g_object_unref);
2810 priv->check_support_progress_pulse_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 200,
2811 check_support_progress_pulse,
2812 g_object_ref (self), g_object_unref);
2813 priv->check_support_progress = gtk_progress_bar_new ();
2814 #ifdef MODEST_TOOLKIT_HILDON2
2815 priv->check_support_cancel_note = hildon_note_new_cancel_with_progress_bar (GTK_WINDOW (self),
2816 _("mcen_cn_availability_check"),
2817 GTK_PROGRESS_BAR (priv->check_support_progress));
2818 gtk_widget_show (priv->check_support_cancel_note);
2819 g_signal_connect (priv->check_support_cancel_note, "response", G_CALLBACK (on_check_support_cancel), self);
2822 priv->check_support_done = TRUE;
2824 fill_providers (self);
2826 invoke_enable_buttons_vfunc (self);