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 "modest-servertype-picker.h"
42 #include "widgets/modest-validating-entry.h"
43 #include "modest-text-utils.h"
44 #include "modest-conf.h"
45 #include "modest-defs.h"
46 #include "modest-account-mgr.h"
47 #include "modest-signal-mgr.h"
48 #include "modest-account-mgr-helpers.h"
49 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
50 #include "modest-connection-specific-smtp-window.h"
51 #include "widgets/modest-ui-constants.h"
52 #include "widgets/modest-default-account-settings-dialog.h"
53 #include "widgets/modest-easysetup-wizard-page.h"
54 #include "modest-maemo-utils.h"
55 #include "modest-utils.h"
56 #include "modest-hildon-includes.h"
57 #include "modest-maemo-security-options-view.h"
58 #include "modest-account-protocol.h"
59 #include "modest-address-book.h"
60 #include <modest-scrollable.h>
61 #include <modest-toolkit-factory.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_picker;
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 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
250 get_port_from_protocol (ModestProtocolType server_type,
251 gboolean alternate_port)
254 ModestProtocol *protocol;
255 ModestProtocolRegistry *protocol_registry;
257 protocol_registry = modest_runtime_get_protocol_registry ();
258 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
260 if (alternate_port) {
261 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
263 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
269 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
271 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
273 /* Call the vfunc, which may be overridden by derived classes: */
274 if (klass->enable_buttons) {
275 GtkNotebook *notebook = NULL;
276 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
278 const gint current_page_num = gtk_notebook_get_current_page (notebook);
279 if (current_page_num == -1)
282 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
283 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
288 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
290 ModestEasysetupWizardDialog *self;
292 g_return_if_fail (user_data);
294 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
296 invoke_enable_buttons_vfunc(self);
300 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
302 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
304 invoke_enable_buttons_vfunc(self);
308 on_picker_button_value_changed (GtkWidget *widget, gpointer user_data)
310 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
312 invoke_enable_buttons_vfunc(self);
316 on_serviceprovider_selector_value_changed (GtkWidget *widget, gpointer user_data)
318 gchar* default_account_name_start;
319 gchar* default_account_name;
320 ModestEasysetupWizardDialog *self;
321 ModestEasysetupWizardDialogPrivate *priv;
322 ModestProviderSelectorIdType provider_id_type;
323 ModestProtocol *protocol;
325 ModestProtocolType proto_type;
326 gboolean hide_account_title;
328 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
329 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
331 on_picker_button_value_changed (GTK_WIDGET (widget), user_data);
333 provider_id_type = modest_provider_selector_get_active_id_type (
334 priv->account_serviceprovider_selector);
335 if (provider_id_type == MODEST_PROVIDER_SELECTOR_ID_OTHER) {
336 default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
338 /* obtain properly the account name! */
339 default_account_name_start = modest_provider_selector_get_active_provider_label (widget);
341 default_account_name = modest_account_mgr_get_unused_account_display_name (
342 priv->account_manager, default_account_name_start);
343 g_free (default_account_name_start);
344 default_account_name_start = NULL;
346 hide_account_title = FALSE;
347 proto_name = modest_provider_selector_get_active_provider_id (priv->account_serviceprovider_selector);
348 if (proto_name != NULL) {
349 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
350 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
352 if (protocol != NULL) {
353 proto_type = modest_protocol_get_type_id (protocol);
355 hide_account_title = (modest_protocol_registry_protocol_type_has_tag
356 (modest_runtime_get_protocol_registry (),
358 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS) ||
359 modest_protocol_registry_protocol_type_has_tag
360 (modest_runtime_get_protocol_registry (),
362 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS));
366 if (hide_account_title)
367 gtk_widget_hide (priv->caption_account_title);
369 gtk_widget_show (priv->caption_account_title);
371 modest_entry_set_text (priv->entry_account_title, default_account_name);
372 g_free (default_account_name);
375 /** This is a convenience function to create a caption containing a mandatory widget.
376 * When the widget is edited, the enable_buttons() vfunc will be called.
379 create_captioned (ModestEasysetupWizardDialog *self,
380 GtkSizeGroup *title_size_group,
381 GtkSizeGroup *value_size_group,
388 result = modest_maemo_utils_create_captioned_with_size_type (title_size_group, value_size_group,
389 value, use_markup, control,
390 MODEST_EDITABLE_SIZE);
392 /* Connect to the appropriate changed signal for the widget,
393 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
395 if (GTK_IS_ENTRY (control)) {
396 g_signal_connect (G_OBJECT (control), "changed",
397 G_CALLBACK (on_caption_entry_changed), self);
400 else if (GTK_IS_COMBO_BOX (control)) {
401 g_signal_connect (G_OBJECT (control), "changed",
402 G_CALLBACK (on_caption_combobox_changed), self);
409 create_page_welcome (ModestEasysetupWizardDialog *self)
414 GtkWidget *privacy_note;
415 GtkWidget *scrollable;
416 ModestEasysetupWizardDialogPrivate *priv;
418 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
419 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
420 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
421 label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
422 privacy_note = gtk_label_new (_("mcen_ia_privacy_notice"));
423 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
424 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
425 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
426 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
427 gtk_widget_set_size_request (privacy_note, LABELS_WIDTH, -1);
428 gtk_label_set_line_wrap (GTK_LABEL (privacy_note), TRUE);
429 hildon_helper_set_logical_font (privacy_note, "SmallSystemFont");
430 /* So that it is not truncated: */
431 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
432 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
433 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
434 gtk_box_pack_start (GTK_BOX (box), privacy_note, FALSE, FALSE, 0);
435 gtk_container_add (GTK_CONTAINER (align), box);
436 gtk_widget_show (label);
437 gtk_widget_show (privacy_note);
439 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
440 gtk_widget_show (GTK_WIDGET (box));
441 gtk_widget_show (GTK_WIDGET (align));
442 gtk_widget_show (scrollable);
444 return GTK_WIDGET (scrollable);
448 on_account_country_selector_changed (GtkWidget *widget, gpointer user_data)
450 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
452 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
456 /* Fill the providers selector, based on the selected country: */
457 if (priv->presets != NULL) {
458 gint mcc = modest_country_selector_get_active_country_mcc (priv->account_country_selector);
459 modest_provider_selector_fill (priv->account_serviceprovider_selector, priv->presets, mcc);
464 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
466 ModestEasysetupWizardDialogPrivate *priv;
467 gchar* provider_id = NULL, *with_at = NULL;
470 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
472 /* Fill the providers combo, based on the selected country: */
473 provider_id = modest_provider_selector_get_active_provider_id (
474 priv->account_serviceprovider_selector);
477 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
478 with_at = g_strdup_printf ("%c%s", '@', domain_name);
479 g_free (domain_name);
482 /* The sample address already contains the '@' */
484 with_at = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
486 if (priv->entry_user_email)
487 modest_entry_set_text (priv->entry_user_email, with_at);
490 g_free (provider_id);
494 on_account_serviceprovider_selector_changed (GtkWidget *widget, gint column, gpointer user_data)
496 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
498 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
502 update_user_email_from_provider (self);
506 on_account_serviceprovider_selector_combo_box_changed (GtkWidget *widget, gpointer user_data)
508 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
510 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
514 update_user_email_from_provider (self);
518 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
520 modest_platform_information_banner (GTK_WIDGET (self), NULL,
521 _CS("ckdg_ib_maximum_characters_reached"));
525 create_page_account_details (ModestEasysetupWizardDialog *self)
528 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
529 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
530 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
532 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
533 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
534 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
535 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
536 gtk_widget_show (label);
538 /* Create a size group to be used by all captions.
539 * Note that HildonCaption does not create a default size group if we do not specify one.
540 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
541 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
542 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
544 /* The country widgets: */
545 priv->account_country_selector = modest_toolkit_factory_create_country_selector (modest_runtime_get_toolkit_factory ());
546 if (GTK_IS_COMBO_BOX (priv->account_country_selector)) {
547 GtkWidget *captioned;
548 g_signal_connect (G_OBJECT (priv->account_country_selector), "changed",
549 G_CALLBACK (on_picker_button_value_changed), self);
550 captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
551 _("mcen_fi_country"), FALSE,
552 priv->account_country_selector);
554 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
555 gtk_widget_show (captioned);
557 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
558 _("mcen_fi_country"), priv->account_country_selector);
559 g_signal_connect (G_OBJECT (priv->account_country_selector), "value-changed",
560 G_CALLBACK (on_picker_button_value_changed), self);
561 gtk_box_pack_start (GTK_BOX (box), priv->account_country_selector, FALSE, FALSE, MODEST_MARGIN_HALF);
563 gtk_widget_show (priv->account_country_selector);
565 /* The service provider widgets: */
566 priv->account_serviceprovider_selector = modest_toolkit_factory_create_provider_selector (modest_runtime_get_toolkit_factory ());
567 if (GTK_IS_COMBO_BOX (priv->account_serviceprovider_selector)) {
568 GtkWidget *captioned;
569 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "changed",
570 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
571 captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
572 _("mcen_fi_serviceprovider"), FALSE,
573 priv->account_serviceprovider_selector);
575 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
576 gtk_widget_show (captioned);
578 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
579 _("mcen_fi_serviceprovider"),
580 priv->account_serviceprovider_selector);
581 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "value-changed",
582 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
583 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_selector, FALSE, FALSE, 0);
585 gtk_widget_show (priv->account_serviceprovider_selector);
587 /* The description widgets: */
588 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
590 /* Do use auto-capitalization: */
591 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
592 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
594 /* Set a default account title, choosing one that does not already exist: */
595 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
596 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
597 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
598 priv->account_manager, default_account_name_start);
599 g_free (default_account_name_start);
600 default_account_name_start = NULL;
602 modest_entry_set_text (priv->entry_account_title, default_account_name);
603 g_free (default_account_name);
604 default_account_name = NULL;
606 /* Connect signal after changing the text in the entry */
607 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
608 G_CALLBACK(on_easysetup_changed), self);
610 priv->caption_account_title = create_captioned (self, title_sizegroup, value_sizegroup,
611 _("mcen_fi_account_title"), FALSE,
612 priv->entry_account_title);
613 gtk_widget_show (priv->entry_account_title);
614 gtk_box_pack_start (GTK_BOX (box), priv->caption_account_title, FALSE, FALSE, 0);
615 gtk_widget_show (priv->caption_account_title);
616 gtk_widget_set_no_show_all (priv->caption_account_title, TRUE);
618 /* Prevent the use of some characters in the account title,
619 * as required by our UI specification: */
620 GList *list_prevent = NULL;
621 list_prevent = g_list_append (list_prevent, "\\");
622 list_prevent = g_list_append (list_prevent, "/");
623 list_prevent = g_list_append (list_prevent, ":");
624 list_prevent = g_list_append (list_prevent, "*");
625 list_prevent = g_list_append (list_prevent, "?");
626 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
627 list_prevent = g_list_append (list_prevent, "“");
628 list_prevent = g_list_append (list_prevent, "<");
629 list_prevent = g_list_append (list_prevent, ">");
630 list_prevent = g_list_append (list_prevent, "|");
631 list_prevent = g_list_append (list_prevent, "^");
632 modest_validating_entry_set_unallowed_characters (
633 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
634 g_list_free (list_prevent);
636 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
637 modest_utils_on_entry_invalid_character, self);
639 /* Set max length as in the UI spec:
640 * The UI spec seems to want us to show a dialog if we hit the maximum. */
641 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
642 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
645 gtk_widget_show (GTK_WIDGET (box));
647 g_object_unref (title_sizegroup);
648 g_object_unref (value_sizegroup);
650 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
651 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
652 gtk_widget_show (align);
653 gtk_container_add (GTK_CONTAINER (align), box);
655 return GTK_WIDGET (align);
659 on_user_username_changed(GtkWidget* widget, ModestEasysetupWizardDialog *self)
661 ModestEasysetupWizardDialogPrivate* priv;
662 gchar* provider_id = NULL;
664 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
666 /* Work out the user email address */
667 provider_id = modest_provider_selector_get_active_provider_id (
668 priv->account_serviceprovider_selector);
671 const gchar *current_username;
672 gchar *email_address;
673 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
675 current_username = modest_entry_get_text (priv->entry_user_username);
677 if (current_username && strstr (current_username, "@")) {
678 email_address = g_strdup (current_username);
680 email_address = g_strdup_printf ("%s@%s",
685 /* Update the email address */
686 modest_entry_set_text (priv->entry_user_email, email_address);
688 g_free (email_address);
689 g_free (domain_name);
690 g_free (provider_id);
694 on_easysetup_changed(widget, self);
699 create_page_user_details (ModestEasysetupWizardDialog *self)
701 GtkSizeGroup* title_sizegroup;
702 GtkSizeGroup* value_sizegroup;
704 ModestEasysetupWizardDialogPrivate *priv;
706 const gchar *my_name;
708 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
710 /* Create a size group to be used by all captions.
711 * Note that HildonCaption does not create a default size group if we do not specify one.
712 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
713 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
714 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
715 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
717 /* The name widgets: (use auto cap) */
718 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
719 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
720 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
722 /* Set max length as in the UI spec:
723 * The UI spec seems to want us to show a dialog if we hit the maximum. */
724 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
725 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
727 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
728 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
730 /* Try to initialize the user name with my own contact */
731 my_name = modest_address_book_get_my_name ();
733 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_name), my_name);
735 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
736 G_CALLBACK(on_easysetup_changed), self);
737 gtk_widget_show (priv->entry_user_name);
738 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
739 gtk_widget_show (caption);
741 /* Prevent the use of some characters in the name,
742 * as required by our UI specification: */
743 GList *list_prevent = NULL;
744 list_prevent = g_list_append (list_prevent, "<");
745 list_prevent = g_list_append (list_prevent, ">");
746 modest_validating_entry_set_unallowed_characters (
747 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
748 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
749 modest_utils_on_entry_invalid_character, self);
750 g_list_free (list_prevent);
752 /* The username widgets: */
753 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
754 /* Auto-capitalization is the default, so let's turn it off: */
755 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
756 HILDON_GTK_INPUT_MODE_FULL);
757 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
758 priv->entry_user_username);
759 gtk_widget_show (priv->entry_user_username);
760 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
761 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
762 G_CALLBACK(on_user_username_changed), self);
763 gtk_widget_show (caption);
765 /* Prevent the use of some characters in the username,
766 * as required by our UI specification: */
767 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
768 modest_utils_on_entry_invalid_character, self);
770 /* Set max length as in the UI spec:
771 * The UI spec seems to want us to show a dialog if we hit the maximum. */
772 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
773 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
776 /* The password widgets: */
777 priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
778 /* Auto-capitalization is the default, so let's turn it off: */
779 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
780 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
781 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
782 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
783 caption = create_captioned (self, title_sizegroup, value_sizegroup,
784 _("mail_fi_password"), FALSE, priv->entry_user_password);
785 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
786 G_CALLBACK(on_easysetup_changed), self);
787 gtk_widget_show (priv->entry_user_password);
788 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
789 gtk_widget_show (caption);
791 /* The email address widgets: */
792 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
793 /* Auto-capitalization is the default, so let's turn it off: */
794 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
795 caption = create_captioned (self, title_sizegroup, value_sizegroup,
796 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
797 update_user_email_from_provider (self);
798 gtk_widget_show (priv->entry_user_email);
799 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
800 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
801 G_CALLBACK(on_easysetup_changed), self);
802 gtk_widget_show (caption);
804 /* Set max length as in the UI spec:
805 * The UI spec seems to want us to show a dialog if we hit the maximum. */
806 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
807 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
811 gtk_widget_show (GTK_WIDGET (box));
812 g_object_unref (title_sizegroup);
813 g_object_unref (value_sizegroup);
815 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
816 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
817 gtk_widget_show (align);
818 gtk_container_add (GTK_CONTAINER (align), box);
820 return GTK_WIDGET (align);
824 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
827 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
829 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
830 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
831 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
832 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
833 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
835 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
836 gtk_widget_show (label);
838 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
839 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
840 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
842 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
843 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
844 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
845 gtk_widget_show (label);
847 gtk_widget_show (GTK_WIDGET (box));
849 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
850 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
851 gtk_widget_show (align);
852 gtk_container_add (GTK_CONTAINER (align), box);
854 return GTK_WIDGET (align);
857 /** Change the caption title for the incoming server,
858 * as specified in the UI spec:
861 update_incoming_server_title (ModestEasysetupWizardDialog *self)
863 ModestEasysetupWizardDialogPrivate* priv;
864 ModestProtocolType protocol_type;
865 ModestProtocolRegistry *protocol_registry;
867 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
868 protocol_registry = modest_runtime_get_protocol_registry ();
870 protocol_type = modest_servertype_picker_get_active_servertype (
871 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
873 /* This could happen when the combo box has still no active iter */
874 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
875 gchar* incomingserver_title;
876 const gchar *protocol_display_name;
877 ModestProtocol *protocol;
879 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
881 protocol_display_name = modest_protocol_get_display_name (protocol);
883 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
884 protocol_display_name, ")</small>", NULL);
886 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
888 g_free(incomingserver_title);
892 /** Change the caption title for the incoming server,
893 * as specified in the UI spec:
896 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
898 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
899 ModestServertypePicker *server_type_picker;
900 ModestProtocolType protocol_type;
901 ModestSecurityOptionsView *view;
904 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
906 modest_servertype_picker_get_active_servertype (server_type_picker);
908 /* Fill the combo with appropriately titled choices for all
910 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
911 modest_security_options_view_set_server_type (view, protocol_type);
915 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
917 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
918 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
923 update_incoming_server_title (self);
925 /* Update security options if needed */
926 update_incoming_server_security_choices (self);
927 gtk_widget_show (priv->incoming_security);
929 set_default_custom_servernames (self);
933 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
935 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
936 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
938 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
942 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
944 ModestProtocolRegistry *protocol_registry;
945 ModestEasysetupWizardDialogPrivate* priv;
948 GtkWidget *scrollable;
950 GtkSizeGroup *title_sizegroup;
951 GtkSizeGroup *value_sizegroup;
953 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
954 protocol_registry = modest_runtime_get_protocol_registry ();
956 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
957 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
959 /* Show note that account type cannot be changed in future: */
960 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
961 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
962 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
963 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
964 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
965 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
966 gtk_widget_show (label);
968 /* Create a size group to be used by all captions.
969 * Note that HildonCaption does not create a default size group if we do not specify one.
970 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
971 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
972 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
974 /* The incoming server widgets: */
975 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
976 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
978 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
979 _("mcen_li_emailsetup_type"),
980 priv->incoming_servertype_picker);
981 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
982 G_CALLBACK (on_picker_button_value_changed), self);
983 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, 0);
984 gtk_widget_show (priv->incoming_servertype_picker);
986 priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
988 /* Auto-capitalization is the default, so let's turn it off: */
989 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
990 set_default_custom_servernames (self);
992 /* The caption title will be updated in update_incoming_server_title().
993 * so this default text will never be seen: */
994 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
995 "This will be removed",
996 FALSE, priv->entry_incomingserver);
997 update_incoming_server_title (self);
998 gtk_widget_show (priv->entry_incomingserver);
999 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
1000 gtk_widget_show (priv->caption_incoming);
1002 /* Remember when the servername was changed manually: */
1003 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
1004 G_CALLBACK (on_entry_incoming_servername_changed), self);
1006 /* The secure connection widgets. These are only valid for
1007 protocols with security */
1008 priv->incoming_security =
1009 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
1010 FALSE, title_sizegroup, value_sizegroup);
1011 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
1013 gtk_widget_show (priv->incoming_security);
1015 /* Set default selection */
1016 modest_servertype_picker_set_active_servertype (
1017 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
1018 MODEST_PROTOCOLS_STORE_POP);
1019 update_incoming_server_title (self);
1020 update_incoming_server_security_choices (self);
1021 set_default_custom_servernames (self);
1023 /* Change the caption title when the servertype changes,
1024 * as in the UI spec: */
1025 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
1027 G_CALLBACK (on_servertype_selector_changed), self);
1029 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1030 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1031 gtk_widget_show (align);
1032 gtk_container_add (GTK_CONTAINER (align), box);
1034 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1035 gtk_widget_show (GTK_WIDGET (box));
1036 gtk_widget_show (scrollable);
1038 g_object_unref (title_sizegroup);
1039 g_object_unref (value_sizegroup);
1041 /* Connect changed signals. We do it here after initializing everything */
1042 g_signal_connect (G_OBJECT(priv->entry_incomingserver), "changed",
1043 G_CALLBACK(on_easysetup_changed), self);
1046 return GTK_WIDGET (scrollable);
1050 on_check_button_changed (GtkWidget *button, gpointer user_data)
1052 GtkWidget *widget = GTK_WIDGET (user_data);
1054 /* Enable the widget only if the check button is active: */
1055 const gboolean enable = modest_togglable_get_active (button);
1056 gtk_widget_set_sensitive (widget, enable);
1059 /* Make the sensitivity of a widget depend on a check button.
1062 enable_widget_for_checkbutton (GtkWidget *widget, GtkWidget* button)
1064 g_signal_connect (G_OBJECT (button), "toggled",
1065 G_CALLBACK (on_check_button_changed), widget);
1067 /* Set the starting sensitivity: */
1068 on_check_button_changed (button, widget);
1072 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
1074 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1075 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1076 GtkWidget *specific_window;
1078 /* We set dirty here because setting it depending on the connection specific dialog
1082 /* Create the window, if necessary: */
1083 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
1084 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
1086 /* Show the window */
1087 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
1088 gtk_widget_show (specific_window);
1092 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
1094 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1095 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1096 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
1100 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
1102 ModestEasysetupWizardDialogPrivate *priv;
1103 gchar *smtp_caption_label;
1104 GtkWidget *scrollable;
1106 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1108 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1110 /* Create a size group to be used by all captions.
1111 * Note that HildonCaption does not create a default size group if we do not specify one.
1112 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1113 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1114 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1116 /* The outgoing server widgets: */
1117 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1118 priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
1120 /* Auto-capitalization is the default, so let's turn it off: */
1121 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
1122 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
1123 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
1124 smtp_caption_label, TRUE, priv->entry_outgoingserver);
1125 g_free (smtp_caption_label);
1126 gtk_widget_show (priv->entry_outgoingserver);
1127 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
1128 gtk_widget_show (caption);
1129 set_default_custom_servernames (self);
1131 /* The secure connection widgets. These are only valid for
1132 protocols with security */
1133 priv->outgoing_security =
1134 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
1135 FALSE, title_sizegroup, value_sizegroup);
1136 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
1138 gtk_widget_show (priv->outgoing_security);
1140 GtkWidget *separator = gtk_hseparator_new ();
1141 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
1142 gtk_widget_show (separator);
1144 /* connection-specific checkbox: */
1145 priv->checkbox_outgoing_smtp_specific = modest_toolkit_factory_create_check_button
1146 (modest_runtime_get_toolkit_factory (),
1147 _("mcen_fi_advsetup_connection_smtp"));
1148 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
1151 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1152 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
1155 /* Connection-specific SMTP-Severs Edit button: */
1156 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
1157 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
1158 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1159 gtk_widget_show (priv->button_outgoing_smtp_servers);
1160 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
1163 /* Only enable the button when the checkbox is checked: */
1164 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
1165 priv->checkbox_outgoing_smtp_specific);
1167 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1168 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1170 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1171 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1174 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1175 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1176 gtk_widget_show (align);
1177 gtk_container_add (GTK_CONTAINER (align), box);
1179 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1180 gtk_widget_show (GTK_WIDGET (box));
1181 gtk_widget_show (scrollable);
1183 g_object_unref (title_sizegroup);
1184 g_object_unref (value_sizegroup);
1186 /* Connect changed signals. We do it here after initializing everything */
1187 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1188 G_CALLBACK (on_easysetup_changed), self);
1189 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1190 G_CALLBACK (on_easysetup_changed), self);
1192 return GTK_WIDGET (scrollable);
1196 show_advanced_edit(gpointer user_data)
1198 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1199 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1202 /* Show the Account Settings window: */
1203 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
1204 if (priv->pending_load_settings) {
1205 save_to_settings (self);
1206 priv->pending_load_settings = FALSE;
1208 modest_account_settings_dialog_load_settings (dialog, priv->settings);
1210 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
1212 response = gtk_dialog_run (GTK_DIALOG (dialog));
1214 gtk_widget_destroy (GTK_WIDGET (dialog));
1216 return FALSE; /* Do not call this timeout callback again. */
1220 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1222 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1224 /* Show the Account Settings window: */
1225 show_advanced_edit(self);
1228 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1230 gchar *complete_string;
1234 GtkWidget *button_edit;
1236 box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1237 complete_string = g_strconcat (_("mcen_ia_emailsetup_setup_complete"), " ",
1238 _("mcen_ia_customsetup_complete"), NULL);
1239 label = gtk_label_new(complete_string);
1240 g_free (complete_string);
1241 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1242 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1243 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1244 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1245 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1246 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1247 gtk_widget_show (label);
1249 button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1250 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1251 gtk_widget_show (button_edit);
1252 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, 0);
1254 g_signal_connect (G_OBJECT (button_edit), "clicked",
1255 G_CALLBACK (on_button_edit_advanced_settings), self);
1257 gtk_widget_show (GTK_WIDGET (box));
1259 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1260 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
1261 gtk_widget_show (align);
1262 gtk_container_add (GTK_CONTAINER (align), box);
1264 return GTK_WIDGET (align);
1271 on_response (ModestWizardDialog *wizard_dialog,
1275 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1277 invoke_enable_buttons_vfunc (self);
1281 on_response_before (ModestWizardDialog *wizard_dialog,
1285 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1286 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1287 if (response_id == GTK_RESPONSE_CANCEL) {
1288 /* This is mostly copied from
1289 * src/maemo/modest-account-settings-dialog.c */
1291 gint dialog_response;
1294 dialog = hildon_note_new_confirmation ((GtkWindow *) self,
1295 _("imum_nc_wizard_confirm_lose_changes"));
1297 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
1298 (GtkWindow *) dialog,
1299 (GtkWindow *) wizard_dialog);
1301 dialog_response = gtk_dialog_run ((GtkDialog *) dialog);
1302 gtk_widget_destroy (GTK_WIDGET (dialog));
1304 if (dialog_response != GTK_RESPONSE_OK) {
1305 /* Don't let the dialog close */
1306 g_signal_stop_emission_by_name (wizard_dialog, "response");
1313 fill_providers (ModestEasysetupWizardDialog *self)
1315 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1317 if (priv->account_country_selector) {
1318 /* gint mcc = get_default_country_code(); */
1320 /* Fill the combo in an idle call, as it takes a lot of time */
1321 modest_country_selector_load_data(priv->account_country_selector);
1322 /* connect to country picker's changed signal, so we can fill the provider picker: */
1323 if (GTK_IS_COMBO_BOX (priv->account_country_selector)) {
1324 g_signal_connect ((GObject *) priv->account_country_selector,
1326 G_CALLBACK (on_account_country_selector_changed), self);
1328 g_signal_connect ((GObject *) priv->account_country_selector,
1330 G_CALLBACK (on_account_country_selector_changed), self);
1333 modest_country_selector_set_active_country_locale (priv->account_country_selector);
1334 mcc = modest_country_selector_get_active_country_mcc (priv->account_country_selector);
1335 modest_provider_selector_fill (
1336 priv->account_serviceprovider_selector,
1337 priv->presets, mcc);
1338 /* connect to providers picker's changed signal, so we can fill the email address: */
1339 if (GTK_IS_COMBO_BOX (priv->account_serviceprovider_selector)) {
1340 g_signal_connect (priv->account_serviceprovider_selector,
1342 G_CALLBACK (on_account_serviceprovider_selector_combo_box_changed), self);
1344 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1345 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_selector))),
1347 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1349 modest_provider_selector_set_others_provider (priv->account_serviceprovider_selector);
1352 priv->dirty = FALSE;
1356 typedef struct IdleData {
1357 ModestEasysetupWizardDialog *dialog;
1358 ModestPresets *presets;
1362 presets_idle (gpointer userdata)
1364 IdleData *idle_data = (IdleData *) userdata;
1365 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1366 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1368 g_assert (idle_data->presets);
1370 gdk_threads_enter ();
1372 priv->presets = idle_data->presets;
1374 if (priv->check_support_done)
1375 fill_providers (self);
1377 g_object_unref (idle_data->dialog);
1380 gdk_threads_leave ();
1386 presets_loader (gpointer userdata)
1388 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1389 ModestPresets *presets = NULL;
1390 IdleData *idle_data;
1392 const gchar* path = NULL;
1393 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1394 const gchar* path2 = MODEST_FALLBACK_PROVIDER_DATA_FILE;
1396 if (access(path1, R_OK) == 0)
1398 else if (access(path2, R_OK) == 0)
1401 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1402 __FUNCTION__, path1, path2);
1406 presets = modest_presets_new (path);
1408 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1412 idle_data = g_new0 (IdleData, 1);
1413 idle_data->dialog = self;
1414 idle_data->presets = presets;
1416 g_idle_add (presets_idle, idle_data);
1422 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1428 /* Append page and set attributes */
1429 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1430 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1431 "tab-expand", TRUE, "tab-fill", TRUE,
1434 /* Give focus to page and show it */
1435 gtk_container_set_focus_child (GTK_CONTAINER (notebook), page);
1436 gtk_widget_show (page);
1440 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1442 priv->page_user_details = NULL;
1443 priv->entry_user_name = NULL;
1444 priv->entry_user_username = NULL;
1445 priv->entry_user_password = NULL;
1446 priv->entry_user_email = NULL;
1450 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1452 priv->page_custom_incoming = NULL;
1453 priv->incoming_servertype_picker = NULL;
1454 priv->caption_incoming = NULL;
1455 priv->entry_incomingserver = NULL;
1456 priv->entry_user_email = NULL;
1457 priv->incoming_security = NULL;
1461 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1463 priv->page_custom_outgoing = NULL;
1464 priv->entry_outgoingserver = NULL;
1465 priv->checkbox_outgoing_smtp_specific = NULL;
1466 priv->button_outgoing_smtp_servers = NULL;
1467 priv->outgoing_security = NULL;
1471 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1473 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1475 /* Create the notebook to be used by the ModestWizardDialog base class:
1476 * Each page of the notebook will be a page of the wizard: */
1477 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1478 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1480 /* Set the notebook used by the ModestWizardDialog base class: */
1481 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1483 /* Set the wizard title:
1484 * The actual window title will be a combination of this and the page's tab label title. */
1485 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1487 /* Read in the information about known service providers: */
1488 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1490 /* The server fields did not have been manually changed yet */
1491 priv->server_changes = 0;
1492 priv->pending_load_settings = TRUE;
1494 /* Get the account manager object,
1495 * so we can check for existing accounts,
1496 * and create new accounts: */
1497 priv->account_manager = modest_runtime_get_account_mgr ();
1498 g_object_ref (priv->account_manager);
1500 /* Initialize fields */
1501 priv->check_support_done = FALSE;
1502 priv->check_support_show_progress_id = 0;
1503 priv->check_support_progress_pulse_id = 0;
1504 priv->check_support_cancel_note = NULL;
1505 priv->check_support_progress = NULL;
1506 priv->pending_check_support = 0;
1507 priv->destroyed = FALSE;
1508 priv->page_welcome = create_page_welcome (self);
1509 gtk_widget_show (priv->page_welcome);
1510 priv->page_account_details = create_page_account_details (self);
1512 init_user_page (priv);
1513 init_incoming_page (priv);
1514 init_outgoing_page (priv);
1516 priv->page_complete_easysetup = NULL;
1517 priv->page_complete_customsetup = NULL;
1518 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1519 priv->missing_data_signals = NULL;
1521 /* Add the common pages */
1522 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1523 _("mcen_ti_emailsetup_welcome"));
1524 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1525 _("mcen_ti_accountdetails"));
1527 /* Connect to the dialog's response signal so we can enable/disable buttons
1528 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1529 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1530 * so that we can be enable/disable after ModestWizardDialog has done its own
1531 * enabling/disabling of buttons.
1533 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1534 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1536 * It's not enough to connect to the notebook's switch-page signal, because
1537 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1538 * _after_ switching the page (understandably).
1539 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1540 * then gtk_notebook_get_current_page() would return an incorrect value.)
1542 g_signal_connect_after (G_OBJECT (self), "response",
1543 G_CALLBACK (on_response), self);
1545 /* This is to show a confirmation dialog when the user hits cancel */
1546 g_signal_connect (G_OBJECT (self), "response",
1547 G_CALLBACK (on_response_before), self);
1549 g_signal_connect (G_OBJECT (self), "delete-event",
1550 G_CALLBACK (on_delete_event), self);
1552 /* Reset dirty, because there was no user input until now */
1553 priv->dirty = FALSE;
1555 /* When this window is shown, hibernation should not be possible,
1556 * because there is no sensible way to save the state: */
1557 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1558 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1560 /* Load provider presets */
1561 g_object_ref (self);
1562 g_thread_create (presets_loader, self, FALSE, NULL);
1564 priv->settings = modest_account_settings_new ();
1568 ModestEasysetupWizardDialog*
1569 modest_easysetup_wizard_dialog_new (void)
1572 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1576 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1578 ModestEasysetupWizardDialogPrivate *priv;
1579 GtkNotebook *notebook = NULL;
1581 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1584 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1586 if (!priv->page_user_details) {
1587 priv->page_user_details = create_page_user_details (self);
1590 /* Create the custom pages: */
1591 if(!(priv->page_custom_incoming)) {
1592 priv->page_custom_incoming = create_page_custom_incoming (self);
1595 /* TODO: only if needed */
1596 if(!(priv->page_custom_outgoing)) {
1597 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1600 if(!(priv->page_complete_customsetup)) {
1601 priv->page_complete_customsetup = create_page_complete_custom (self);
1604 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1605 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1606 _("mcen_ti_emailsetup_userdetails"));
1608 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1609 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1610 _("mcen_ti_emailsetup_incomingdetails"));
1612 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1613 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1614 _("mcen_ti_emailsetup_outgoingdetails"));
1616 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1617 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1618 _("mcen_ti_emailsetup_complete"));
1620 /* This is unnecessary with GTK+ 2.10: */
1621 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1625 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1627 ModestEasysetupWizardDialogPrivate *priv;
1628 GtkNotebook *notebook = NULL;
1630 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1633 /* Create the easysetup-specific pages: */
1634 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1635 if(!priv->page_complete_easysetup)
1636 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1638 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1639 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1640 _("mcen_ti_emailsetup_complete"));
1642 /* This is unnecessary with GTK+ 2.10: */
1643 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1648 remove_non_common_tabs (ModestEasysetupWizardDialog *self,
1649 gboolean remove_user_details)
1652 GtkNotebook *notebook;
1653 ModestEasysetupWizardDialogPrivate *priv;
1655 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1656 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1658 /* The first 2 tabs are the common ones (welcome tab and the
1659 providers tab), so we always remove starting from the
1661 starting_tab = (remove_user_details) ? 2 : 3;
1662 while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
1663 /* Disconnect signal */
1664 GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
1665 if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
1666 priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
1668 "missing-mandatory-data");
1670 /* Remove page from notebook */
1671 gtk_notebook_remove_page (notebook, -1);
1676 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1680 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1683 /* After the user details page,
1684 * the following pages depend on whether "Other" was chosen
1685 * in the provider combobox on the account page
1688 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1690 ModestEasysetupWizardDialogPrivate *priv;
1692 ModestProviderSelectorIdType id_type;
1693 GtkNotebook *notebook;
1695 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1696 picker = priv->account_serviceprovider_selector;
1697 id_type = modest_provider_selector_get_active_id_type (picker);
1698 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1700 /* Remove the response override handler for non-plugin
1701 protocols. For plugins it'll be overriden later */
1702 if (id_type != MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL)
1703 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1707 if (id_type == MODEST_PROVIDER_SELECTOR_ID_OTHER) {
1708 /* "Other..." was selected: */
1710 /* If we come from a rollbacked easysetup */
1711 if (priv->page_complete_easysetup) {
1712 remove_non_common_tabs (self, FALSE);
1713 priv->page_complete_easysetup = NULL;
1716 /* If we come from a rollbacked plugin protocol setup */
1717 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1718 remove_non_common_tabs (self, TRUE);
1719 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1720 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1721 priv->missing_data_signals = NULL;
1724 create_subsequent_customsetup_pages (self);
1726 /* If we come from a rollbacked custom setup */
1727 if (priv->page_custom_incoming) {
1728 remove_non_common_tabs (self, TRUE);
1729 init_user_page (priv);
1730 init_incoming_page (priv);
1731 init_outgoing_page (priv);
1732 init_user_page (priv);
1733 priv->page_complete_customsetup = NULL;
1736 /* It's a pluggable protocol and not a provider with presets */
1737 if (id_type == MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL) {
1738 ModestProtocol *protocol;
1740 ModestProtocolType proto_type;
1741 ModestWizardDialogResponseOverrideFunc response_override;
1743 /* Get protocol data */
1744 proto_name = modest_provider_selector_get_active_provider_id (picker);
1745 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1746 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1748 proto_type = modest_protocol_get_type_id (protocol);
1751 /* If we come from a rollbacked easy setup */
1752 if (priv->last_plugin_protocol_selected != proto_type &&
1753 priv->page_complete_easysetup) {
1754 remove_non_common_tabs (self, TRUE);
1755 init_user_page (priv);
1756 priv->page_complete_easysetup = NULL;
1759 /* Ensure that the response override handler
1760 is set. It might happen that plugins clear
1762 response_override = modest_account_protocol_get_wizard_response_override
1763 (MODEST_ACCOUNT_PROTOCOL (protocol));
1764 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1767 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1768 proto_type != priv->last_plugin_protocol_selected) {
1769 ModestPairList *tabs;
1771 gboolean first_page = TRUE;
1773 /* Remember the last selected plugin protocol */
1774 priv->last_plugin_protocol_selected = proto_type;
1777 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1778 tmp = (GSList *) tabs;
1780 ModestPair *pair = (ModestPair *) tmp->data;
1781 modest_easysetup_wizard_dialog_append_page (notebook,
1782 GTK_WIDGET (pair->second),
1783 (const gchar *) pair->first);
1785 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1786 GTK_WIDGET (pair->second));
1790 /* Connect signals */
1791 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1792 priv->missing_data_signals =
1793 modest_signal_mgr_connect (priv->missing_data_signals,
1794 G_OBJECT (pair->second),
1795 "missing-mandatory-data",
1796 G_CALLBACK (on_missing_mandatory_data),
1800 g_free (pair->first);
1801 tmp = g_slist_next (tmp);
1802 /* Critical: if you don't show the page then the dialog will ignore it */
1803 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1805 modest_pair_list_free (tabs);
1807 g_free (proto_name);
1809 if (priv->last_plugin_protocol_selected !=
1810 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1811 remove_non_common_tabs (self, TRUE);
1812 init_user_page (priv);
1813 priv->page_complete_easysetup = NULL;
1814 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1815 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1816 priv->missing_data_signals = NULL;
1818 if (!priv->page_user_details) {
1819 priv->page_user_details = create_page_user_details (self);
1820 modest_easysetup_wizard_dialog_append_page (notebook,
1821 priv->page_user_details,
1822 _("mcen_ti_emailsetup_userdetails"));
1826 /* Create the easysetup pages: */
1827 create_subsequent_easysetup_pages (self);
1833 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1835 const gchar* hostname = NULL;
1838 ModestProtocolRegistry *protocol_registry;
1839 ModestProtocol *protocol;
1844 at = g_utf8_strchr (email_address, -1, '@');
1845 if (!at || (g_utf8_strlen (at, -1) < 2))
1848 domain = g_utf8_next_char (at);
1852 protocol_registry = modest_runtime_get_protocol_registry ();
1853 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1855 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1856 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1857 hostname = modest_protocol_get_name (protocol);
1863 return g_strdup_printf ("%s.%s", hostname, domain);
1867 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1869 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1871 if (!priv->entry_incomingserver)
1874 /* Set a default domain for the server, based on the email address,
1875 * if no server name was already specified.
1877 if (priv->entry_user_email
1878 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1879 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1880 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1882 /* This could happen when the combo box has still no active iter */
1883 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1884 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1885 gchar* servername = util_get_default_servername_from_email_address (email_address,
1888 /* Do not set the INCOMING_CHANGED flag because of this edit */
1889 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1890 modest_entry_set_text (priv->entry_incomingserver, servername);
1891 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1893 g_free (servername);
1897 /* Set a default domain for the server, based on the email address,
1898 * if no server name was already specified.
1900 if (!priv->entry_outgoingserver)
1903 if (priv->entry_user_email
1904 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1905 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1907 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1909 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1910 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1911 modest_entry_set_text (priv->entry_outgoingserver, servername);
1912 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1914 g_free (servername);
1919 get_entered_account_title (ModestEasysetupWizardDialog *self)
1921 ModestEasysetupWizardDialogPrivate *priv;
1922 const gchar* account_title;
1924 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1925 account_title = modest_entry_get_text (priv->entry_account_title);
1927 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1930 /* Strip it of whitespace at the start and end: */
1931 gchar *result = g_strdup (account_title);
1932 result = g_strstrip (result);
1937 if (g_utf8_strlen (result, -1) == 0) {
1947 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1949 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1950 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1951 ModestProtocolRegistry *protocol_registry;
1953 protocol_registry = modest_runtime_get_protocol_registry ();
1955 /* if are browsing pages previous to the last one, then we have pending settings in
1957 if (next_page != NULL)
1958 priv->pending_load_settings = TRUE;
1960 /* Do extra validation that couldn't be done for every key press,
1961 * either because it was too slow,
1962 * or because it requires interaction:
1964 if (current_page == priv->page_welcome) {
1965 if (!priv->check_support_done) {
1966 check_support_of_protocols (self);
1967 return priv->check_support_done;
1969 } else if (current_page == priv->page_account_details) {
1970 /* Check that the title is not already in use: */
1971 gchar* account_title = get_entered_account_title (self);
1975 /* Aavoid a clash with an existing display name: */
1976 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1977 priv->account_manager, account_title);
1978 g_free (account_title);
1981 /* Warn the user via a dialog: */
1982 modest_platform_system_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
1987 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1988 create_subsequent_pages (self);
1990 } else if (current_page == priv->page_user_details) {
1991 /* Check that the email address is valud: */
1992 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1993 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1996 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1997 /* Warn the user via a dialog: */
1998 modest_platform_system_banner (NULL, NULL, _("mcen_ib_invalid_email"));
2000 /* Return focus to the email address entry: */
2001 gtk_widget_grab_focus (priv->entry_user_email);
2002 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
2006 } else if (current_page == priv->page_custom_incoming ||
2007 current_page == priv->page_custom_outgoing) {
2009 const gchar *hostname;
2010 GtkWidget *entry = (current_page == priv->page_custom_incoming) ?
2011 priv->entry_incomingserver :
2012 priv->entry_outgoingserver;
2014 hostname = gtk_entry_get_text (GTK_ENTRY (entry));
2015 if (!modest_text_utils_validate_domain_name (hostname)) {
2017 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
2019 /* Return focus to the email address entry: */
2020 gtk_widget_grab_focus (entry);
2021 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
2027 if (next_page == priv->page_custom_incoming) {
2028 set_default_custom_servernames (self);
2029 } else if (next_page == priv->page_custom_outgoing) {
2030 set_default_custom_servernames (self);
2032 /* Check if the server supports secure authentication */
2033 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
2034 if (!check_has_supported_auth_methods (self))
2036 gtk_widget_show (priv->outgoing_security);
2039 /* If this is the last page, and this is a click on Finish,
2040 * then attempt to create the dialog.
2043 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
2045 if (priv->pending_load_settings) {
2046 save_to_settings (self);
2049 /* We check if there's already another account with the same configuration */
2050 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2051 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2055 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2062 static gboolean entry_is_empty (GtkWidget *entry)
2067 const gchar* text = modest_entry_get_text (entry);
2068 if ((!text) || (g_utf8_strlen (text, -1) == 0))
2071 /* Strip it of whitespace at the start and end: */
2072 gchar *stripped = g_strdup (text);
2073 stripped = g_strstrip (stripped);
2078 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
2086 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
2088 GtkNotebook *notebook = NULL;
2089 gboolean is_finish_tab;
2091 ModestEasysetupWizardDialogPrivate *priv;
2094 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
2095 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
2097 /* Disable the Finish button until we are on the last page,
2098 * because HildonWizardDialog enables this for all but the
2100 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
2101 is_finish_tab = ((current == priv->page_complete_easysetup) ||
2102 (current == priv->page_complete_customsetup));
2104 if (is_finish_tab) {
2105 /* Disable Next on the last page no matter what the
2107 enable_next = FALSE;
2109 /* Not the last one */
2110 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2111 MODEST_WIZARD_DIALOG_FINISH,
2114 /* If the check support is not done then do not enable
2115 the wizard to continue */
2116 enable_next = enable_next && priv->pending_check_support == 0;
2119 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2120 MODEST_WIZARD_DIALOG_NEXT,
2125 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
2127 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2128 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2130 gboolean enable_next = TRUE;
2131 if (current_page == priv->page_welcome) {
2133 } else if (current_page == priv->page_account_details) {
2134 /* The account details title is mandatory: */
2135 if (entry_is_empty(priv->entry_account_title))
2136 enable_next = FALSE;
2137 } else if (current_page == priv->page_user_details) {
2138 /* The user details username is mandatory: */
2139 if (entry_is_empty(priv->entry_user_username))
2140 enable_next = FALSE;
2142 /* The user details email address is mandatory: */
2143 if (enable_next && entry_is_empty (priv->entry_user_email))
2144 enable_next = FALSE;
2145 } else if (current_page == priv->page_custom_incoming) {
2146 /* The custom incoming server is mandatory: */
2147 if (entry_is_empty(priv->entry_incomingserver))
2148 enable_next = FALSE;
2149 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
2150 enable_next = !modest_easysetup_wizard_page_validate (
2151 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
2154 /* Enable/disable buttons */
2155 real_enable_buttons (dialog, enable_next);
2159 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
2161 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2162 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
2165 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
2166 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
2168 /* Provide a vfunc implementation so we can decide
2169 * when to enable/disable the prev/next buttons.
2171 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
2172 base_klass->before_next = on_before_next;
2173 base_klass->enable_buttons = on_enable_buttons;
2174 base_klass->update_model = on_update_model;
2175 base_klass->save = on_save;
2179 check_username_for_provider (const gchar *provider_id,
2180 const gchar *domain,
2183 gchar *providers_to_check[] = { "ovi.com", "yahoomailplus.com", "hotmail.com" };
2185 gboolean found = FALSE;
2188 /* Check if the username contains the @hostname, if not then add it */
2189 if (strchr (*username, '@'))
2192 /* Check if it's one of the providers to check */
2193 for (i = 0; i < G_N_ELEMENTS (providers_to_check) && !found; i++) {
2194 if (!g_ascii_strncasecmp (providers_to_check[i], provider_id, strlen (providers_to_check[i])))
2201 /* Replace the username */
2203 *username = g_strconcat (*username, "@", domain, NULL);
2209 * @self: a #ModestEasysetupWizardDialog
2211 * takes information from all the wizard and stores it in settings
2214 save_to_settings (ModestEasysetupWizardDialog *self)
2216 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2218 gchar *provider_id = NULL;
2219 gchar *alternate_username = NULL;
2220 gchar *display_name;
2221 const gchar *username, *password;
2222 gchar *store_hostname, *transport_hostname;
2223 guint store_port, transport_port;
2224 ModestProtocolRegistry *protocol_registry;
2225 ModestProtocolType store_protocol, transport_protocol;
2226 ModestProtocolType store_security, transport_security;
2227 ModestProtocolType store_auth_protocol, transport_auth_protocol;
2228 ModestServerAccountSettings *store_settings, *transport_settings;
2229 const gchar *fullname, *email_address;
2231 ModestProviderSelectorIdType id_type;
2233 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2234 picker = priv->account_serviceprovider_selector;
2235 protocol_registry = modest_runtime_get_protocol_registry ();
2237 /* Get details from the specified presets: */
2238 id_type = modest_provider_selector_get_active_id_type (picker);
2239 provider_id = modest_provider_selector_get_active_provider_id (picker);
2241 /* Let the plugin save the settings. We do a return in order
2242 to save an indentation level */
2243 if (id_type == MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL) {
2244 ModestProtocol *protocol;
2246 protocol = modest_protocol_registry_get_protocol_by_name (
2247 modest_runtime_get_protocol_registry (),
2248 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
2251 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
2252 gint n_pages, i = 0;
2253 GtkNotebook *notebook;
2254 GList *wizard_pages = NULL;
2256 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
2257 n_pages = gtk_notebook_get_n_pages (notebook);
2258 for (i = 0; i < n_pages; i++) {
2259 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
2260 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
2261 wizard_pages = g_list_append (wizard_pages, page);
2263 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
2266 g_list_free (wizard_pages);
2268 g_debug ("The selected protocol is a plugin protocol "//
2269 "but it's not a ModestAccountProtocol");
2272 g_free (provider_id);
2276 /* username and password (for both incoming and outgoing): */
2277 username = modest_entry_get_text (priv->entry_user_username);
2278 password = modest_entry_get_text (priv->entry_user_password);
2280 store_settings = modest_account_settings_get_store_settings (priv->settings);
2281 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
2283 /* Incoming server: */
2284 /* Note: We need something as default for the transport store protocol values,
2285 * or modest_account_mgr_add_server_account will fail. */
2287 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2288 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2289 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2292 ModestProtocolType store_provider_server_type;
2293 gboolean store_provider_use_alternate_port;
2294 gchar *domain = NULL;
2297 store_hostname = modest_presets_get_server (priv->presets, provider_id,
2300 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2303 store_security = modest_presets_get_info_server_security (priv->presets,
2306 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
2309 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
2314 /* This is HORRIBLE, but it seems that somehow it helps users
2315 that do not like to read the user instructions for their
2317 domain = modest_presets_get_domain (priv->presets, provider_id);
2319 alternate_username = g_strdup (username);
2320 check_username_for_provider (provider_id, domain, &alternate_username);
2324 /* We don't check for SMTP here as that is impossible for an incoming server. */
2325 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
2326 store_protocol = MODEST_PROTOCOLS_STORE_POP;
2328 store_protocol = store_provider_server_type;
2330 /* we check if there is a *special* port */
2331 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
2332 if (special_port != 0) {
2333 store_port = special_port;
2335 gboolean use_alternate_port = FALSE;
2336 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2338 use_alternate_port = TRUE;
2339 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
2342 modest_server_account_settings_set_security_protocol (store_settings,
2344 modest_server_account_settings_set_auth_protocol (store_settings,
2345 store_auth_protocol);
2346 if (store_port != 0)
2347 modest_server_account_settings_set_port (store_settings, store_port);
2349 /* Use custom pages because no preset was specified: */
2350 store_hostname = g_strdup (modest_entry_get_text (priv->entry_incomingserver ));
2351 store_protocol = modest_servertype_picker_get_active_servertype (
2352 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2354 modest_security_options_view_save_settings (
2355 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2359 /* now we store the common store account settings */
2360 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2361 modest_server_account_settings_set_username (store_settings, (alternate_username) ? alternate_username : username);
2362 modest_server_account_settings_set_password (store_settings, password);
2363 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2365 g_object_unref (store_settings);
2366 g_free (store_hostname);
2368 /* Outgoing server: */
2369 transport_hostname = NULL;
2370 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2371 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2372 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2376 ModestProtocolType transport_provider_server_type;
2377 ModestProtocolType transport_provider_security;
2381 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2382 FALSE /* transport */);
2384 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2386 FALSE /* transport */);
2387 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2389 FALSE /* transport */);
2391 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2392 transport_protocol = transport_provider_server_type;
2393 transport_security = transport_provider_security;
2394 is_secure = modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2395 transport_security);
2397 /* we check if there is a *special* port */
2398 special_port = modest_presets_get_port (priv->presets, provider_id,
2399 FALSE /* transport */);
2400 if (special_port != 0) {
2401 transport_port = special_port;
2403 gboolean use_alternate_port = FALSE;
2404 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL)
2405 use_alternate_port = TRUE;
2406 transport_port = get_port_from_protocol(transport_provider_server_type, use_alternate_port);
2410 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2412 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2414 modest_server_account_settings_set_security_protocol (transport_settings,
2415 transport_security);
2416 modest_server_account_settings_set_auth_protocol (transport_settings,
2417 transport_auth_protocol);
2418 if (transport_port != 0)
2419 modest_server_account_settings_set_port (transport_settings,
2422 ModestProtocolRegistry *registry;
2423 ModestProtocol *store_proto;
2425 registry = modest_runtime_get_protocol_registry ();
2426 /* Use custom pages because no preset was specified: */
2427 transport_hostname = g_strdup (modest_entry_get_text (priv->entry_outgoingserver ));
2429 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2432 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2433 /* fallback to SMTP if none was specified */
2434 g_warning ("No transport protocol was specified for store %d (%s)",
2435 modest_protocol_get_type_id (store_proto),
2436 modest_protocol_get_display_name (store_proto));
2437 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2440 modest_security_options_view_save_settings (
2441 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2445 /* now we store the common transport account settings */
2446 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2447 modest_server_account_settings_set_username (transport_settings, (alternate_username) ? alternate_username : username);
2448 modest_server_account_settings_set_password (transport_settings, password);
2449 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2451 g_object_unref (transport_settings);
2452 g_free (transport_hostname);
2453 if (alternate_username)
2454 g_free (alternate_username);
2456 fullname = modest_entry_get_text (priv->entry_user_name);
2457 email_address = modest_entry_get_text (priv->entry_user_email);
2458 modest_account_settings_set_fullname (priv->settings, fullname);
2459 modest_account_settings_set_email_address (priv->settings, email_address);
2460 /* we don't set retrieve type to preserve advanced settings if
2461 any. By default account settings are set to headers only */
2463 /* Save the connection-specific SMTP server accounts. */
2464 if (priv->checkbox_outgoing_smtp_specific) {
2465 modest_account_settings_set_use_connection_specific_smtp
2467 modest_togglable_get_active(priv->checkbox_outgoing_smtp_specific));
2470 display_name = get_entered_account_title (self);
2471 modest_account_settings_set_display_name (priv->settings, display_name);
2472 g_free (display_name);
2473 g_free (provider_id);
2475 /* This values are hardcoded for Fremantle */
2476 modest_account_settings_set_retrieve_type (priv->settings,
2477 MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS);
2478 modest_account_settings_set_retrieve_limit (priv->settings, 20);
2483 on_update_model (ModestWizardDialog *dialog)
2485 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2486 save_to_settings (self);
2491 on_save (ModestWizardDialog *dialog)
2493 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2494 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2496 save_to_settings (self);
2498 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2499 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2503 return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2509 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2511 GError *error = NULL;
2512 ModestProtocolType protocol_type;
2513 const gchar* hostname;
2514 const gchar* username;
2515 ModestProtocolType security_protocol_incoming_type;
2516 ModestProtocolRegistry *registry;
2518 GList *list_auth_methods;
2519 ModestEasysetupWizardDialogPrivate *priv;
2521 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2522 registry = modest_runtime_get_protocol_registry ();
2523 protocol_type = modest_servertype_picker_get_active_servertype (
2524 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2525 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2526 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2527 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2528 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2529 port_num = get_port_from_protocol(protocol_type, FALSE);
2530 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2531 username, GTK_WINDOW (self), &error);
2533 if (list_auth_methods) {
2534 /* TODO: Select the correct method */
2537 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2538 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2539 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2540 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2541 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2545 g_list_free(list_auth_methods);
2551 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2552 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2554 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2555 _("mcen_ib_unableto_discover_auth_methods"));
2559 g_error_free(error);
2565 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2567 GList* methods = check_for_supported_auth_methods(self);
2573 g_list_free(methods);
2578 check_support_show_progress (gpointer userdata)
2580 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2581 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2583 priv->check_support_show_progress_id = 0;
2585 if (priv->destroyed)
2588 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
2594 check_support_progress_pulse (gpointer userdata)
2596 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2597 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2599 if (priv->destroyed || priv->check_support_progress == NULL) {
2600 priv->check_support_progress_pulse_id = 0;
2604 gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->check_support_progress));
2610 check_support_callback (ModestAccountProtocol *protocol,
2614 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2615 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2617 priv->pending_check_support --;
2619 if (priv->check_support_show_progress_id > 0) {
2620 g_source_remove (priv->check_support_show_progress_id);
2621 priv->check_support_show_progress_id = 0;
2624 if (priv->pending_check_support == 0) {
2625 priv->check_support_done = TRUE;
2627 if (priv->check_support_cancel_note) {
2628 gtk_widget_destroy (priv->check_support_cancel_note);
2629 priv->check_support_cancel_note = NULL;
2630 priv->check_support_progress = NULL;
2633 if (!priv->destroyed) {
2635 fill_providers (self);
2636 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
2637 invoke_enable_buttons_vfunc (self);
2638 gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
2641 g_object_unref (self);
2645 on_check_support_cancel (GtkDialog *cancel_note,
2647 ModestEasysetupWizardDialog *self)
2649 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2650 ModestProtocolRegistry *registry;
2651 GSList *provider_protos, *node;
2653 registry = modest_runtime_get_protocol_registry ();
2654 provider_protos = modest_protocol_registry_get_by_tag (registry,
2655 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2657 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2658 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2660 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2661 modest_protocol_get_type_id (proto),
2662 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2665 if (modest_protocol_registry_protocol_type_has_tag
2667 modest_protocol_get_type_id (proto),
2668 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2669 /* Check if there's already an account configured with this account type */
2670 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2671 modest_protocol_get_type_id (proto)))
2675 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2676 modest_account_protocol_cancel_check_support (MODEST_ACCOUNT_PROTOCOL (proto));
2679 g_slist_free (provider_protos);
2681 gtk_widget_destroy (GTK_WIDGET (cancel_note));
2682 priv->check_support_cancel_note = NULL;
2683 priv->check_support_progress = NULL;
2687 check_support_of_protocols (ModestEasysetupWizardDialog *self)
2689 ModestProtocolRegistry *registry;
2690 GSList *provider_protos, *node, *check_support_providers;
2691 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2693 registry = modest_runtime_get_protocol_registry ();
2694 provider_protos = modest_protocol_registry_get_by_tag (registry,
2695 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2697 check_support_providers = NULL;
2698 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2699 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2701 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2702 modest_protocol_get_type_id (proto),
2703 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2706 if (modest_protocol_registry_protocol_type_has_tag
2708 modest_protocol_get_type_id (proto),
2709 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2710 /* Check if there's already an account configured with this account type */
2711 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2712 modest_protocol_get_type_id (proto)))
2716 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2717 priv->pending_check_support ++;
2718 check_support_providers = g_slist_prepend (check_support_providers, proto);
2721 g_slist_free (provider_protos);
2723 for (node = check_support_providers; node != NULL; node = g_slist_next (node)) {
2724 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2726 modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
2727 check_support_callback,
2728 g_object_ref (self));
2730 g_slist_free (check_support_providers);
2732 if (priv->pending_check_support > 0) {
2733 priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
2734 check_support_show_progress,
2735 g_object_ref (self), g_object_unref);
2736 priv->check_support_progress_pulse_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 200,
2737 check_support_progress_pulse,
2738 g_object_ref (self), g_object_unref);
2739 priv->check_support_progress = gtk_progress_bar_new ();
2740 priv->check_support_cancel_note = hildon_note_new_cancel_with_progress_bar (GTK_WINDOW (self),
2741 _("mcen_cn_availability_check"),
2742 GTK_PROGRESS_BAR (priv->check_support_progress));
2743 gtk_widget_show (priv->check_support_cancel_note);
2744 g_signal_connect (priv->check_support_cancel_note, "response", G_CALLBACK (on_check_support_cancel), self);
2746 priv->check_support_done = TRUE;
2748 fill_providers (self);
2750 invoke_enable_buttons_vfunc (self);