2 /* Copyright (c) 2006, Nokia Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the Nokia Corporation nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "modest-easysetup-wizard-dialog.h"
33 #include <glib/gi18n.h>
34 #include <gtk/gtknotebook.h>
35 #include <gtk/gtkvbox.h>
36 #include <gtk/gtklabel.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkmessagedialog.h>
40 #include <gtk/gtkseparator.h>
41 #include "widgets/modest-validating-entry.h"
42 #include "modest-text-utils.h"
43 #include "modest-conf.h"
44 #include "modest-defs.h"
45 #include "modest-account-mgr.h"
46 #include "modest-signal-mgr.h"
47 #include "modest-account-mgr-helpers.h"
48 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
49 #include "modest-connection-specific-smtp-window.h"
50 #include "widgets/modest-ui-constants.h"
51 #include "widgets/modest-default-account-settings-dialog.h"
52 #include "widgets/modest-easysetup-wizard-page.h"
53 #include "modest-utils.h"
54 #include "modest-account-protocol.h"
55 #include "modest-address-book.h"
56 #include <modest-scrollable.h>
57 #include <modest-toolkit-factory.h>
58 #include <modest-toolkit-utils.h>
59 #ifdef MODEST_TOOLKIT_HILDON2
60 #include <hildon/hildon.h>
63 /* Include config.h so that _() works: */
68 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
70 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
71 MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
72 ModestEasysetupWizardDialogPrivate))
74 #define LABELS_WIDTH 520
75 #define DIALOG_WIDTH LABELS_WIDTH + MODEST_MARGIN_DOUBLE
77 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
81 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
82 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
83 } ModestEasysetupWizardDialogServerChanges;
85 struct _ModestEasysetupWizardDialogPrivate
87 ModestPresets *presets;
89 /* Remember what fields the user edited manually to not prefill them
91 ModestEasysetupWizardDialogServerChanges server_changes;
93 /* Check if the user changes a field to show a confirmation dialog */
96 /* If we have a pending load of settings or not. */
97 gboolean pending_load_settings;
99 /* Used by derived widgets to query existing accounts,
100 * and to create new accounts: */
101 ModestAccountMgr *account_manager;
102 ModestAccountSettings *settings;
104 /* notebook pages: */
105 GtkWidget *page_welcome;
106 gboolean check_support_done;
107 guint check_support_show_progress_id;
108 guint check_support_progress_pulse_id;
109 GtkWidget *check_support_cancel_note;
110 GtkWidget *check_support_progress;
111 gint pending_check_support;
114 GtkWidget *page_account_details;
115 GtkWidget *account_country_selector;
116 GtkWidget *account_serviceprovider_selector;
117 GtkWidget *entry_account_title;
118 GtkWidget *caption_account_title;
120 GtkWidget *page_user_details;
121 GtkWidget *entry_user_name;
122 GtkWidget *entry_user_username;
123 GtkWidget *entry_user_password;
124 GtkWidget *entry_user_email;
126 GtkWidget *page_complete_easysetup;
128 GtkWidget *page_custom_incoming;
129 GtkWidget *incoming_servertype_selector;
130 GtkWidget *caption_incoming;
131 GtkWidget *entry_incomingserver;
133 /* Security widgets */
134 GtkWidget *incoming_security;
135 GtkWidget *outgoing_security;
137 GtkWidget *page_custom_outgoing;
138 GtkWidget *entry_outgoingserver;
139 GtkWidget *checkbox_outgoing_smtp_specific;
140 GtkWidget *button_outgoing_smtp_servers;
142 GtkWidget *page_complete_customsetup;
145 ModestProtocolType last_plugin_protocol_selected;
146 GSList *missing_data_signals;
149 static void save_to_settings (ModestEasysetupWizardDialog *self);
150 static void real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next);
151 static void on_update_model (ModestWizardDialog *dialog);
152 static gboolean on_save (ModestWizardDialog *dialog);
153 static GList* check_for_supported_auth_methods (ModestEasysetupWizardDialog* self);
154 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self);
155 static void check_support_callback (ModestAccountProtocol *protocol,
158 static void check_support_of_protocols (ModestEasysetupWizardDialog *self);
159 static gboolean check_support_show_progress (gpointer userdata);
160 static gboolean check_support_progress_pulse (gpointer userdata);
163 on_delete_event (GtkWidget *widget,
165 ModestEasysetupWizardDialog *wizard)
167 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
172 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
174 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
175 g_return_if_fail (priv != NULL);
180 modest_easysetup_wizard_dialog_dispose (GObject *object)
182 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (object);
183 priv->destroyed = TRUE;
185 if (priv->check_support_show_progress_id > 0) {
186 g_source_remove (priv->check_support_show_progress_id);
187 priv->check_support_show_progress_id = 0;
190 if (priv->check_support_progress_pulse_id > 0) {
191 g_source_remove (priv->check_support_progress_pulse_id);
192 priv->check_support_progress_pulse_id = 0;
195 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
196 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
200 modest_easysetup_wizard_dialog_finalize (GObject *object)
202 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
203 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
204 ModestProtocolRegistry *registry;
205 GSList *provider_protos, *node;
207 registry = modest_runtime_get_protocol_registry ();
208 provider_protos = modest_protocol_registry_get_by_tag (registry,
209 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
211 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
212 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
214 if (!modest_protocol_registry_protocol_type_has_tag (registry,
215 modest_protocol_get_type_id (proto),
216 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
219 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
220 modest_account_protocol_wizard_finished (MODEST_ACCOUNT_PROTOCOL (proto));
223 g_slist_free (provider_protos);
225 if (priv->account_manager)
226 g_object_unref (G_OBJECT (priv->account_manager));
229 modest_presets_destroy (priv->presets);
232 g_object_unref (priv->settings);
234 if (priv->missing_data_signals) {
235 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
236 priv->missing_data_signals = NULL;
239 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
243 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
246 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
248 #ifdef HILDON_PICKER_BUTTON
249 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
253 get_port_from_protocol (ModestProtocolType server_type,
254 gboolean alternate_port)
257 ModestProtocol *protocol;
258 ModestProtocolRegistry *protocol_registry;
260 protocol_registry = modest_runtime_get_protocol_registry ();
261 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
263 if (alternate_port) {
264 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
266 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
272 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
274 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
276 /* Call the vfunc, which may be overridden by derived classes: */
277 if (klass->enable_buttons) {
278 GtkNotebook *notebook = NULL;
279 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
281 const gint current_page_num = gtk_notebook_get_current_page (notebook);
282 if (current_page_num == -1)
285 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
286 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
291 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
293 ModestEasysetupWizardDialog *self;
295 g_return_if_fail (user_data);
297 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
299 invoke_enable_buttons_vfunc(self);
303 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
305 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
307 invoke_enable_buttons_vfunc(self);
311 on_picker_button_value_changed (GtkWidget *widget, gpointer user_data)
313 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
315 invoke_enable_buttons_vfunc(self);
319 on_serviceprovider_selector_value_changed (GtkWidget *widget, gpointer user_data)
321 gchar* default_account_name_start;
322 gchar* default_account_name;
323 ModestEasysetupWizardDialog *self;
324 ModestEasysetupWizardDialogPrivate *priv;
325 ModestProviderSelectorIdType provider_id_type;
326 ModestProtocol *protocol;
328 ModestProtocolType proto_type;
329 gboolean hide_account_title;
331 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
332 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
334 on_picker_button_value_changed (GTK_WIDGET (widget), user_data);
336 provider_id_type = modest_provider_selector_get_active_id_type (
337 priv->account_serviceprovider_selector);
338 if (provider_id_type == MODEST_PROVIDER_SELECTOR_ID_OTHER) {
339 default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
341 /* obtain properly the account name! */
342 default_account_name_start = modest_provider_selector_get_active_provider_label (widget);
344 default_account_name = modest_account_mgr_get_unused_account_display_name (
345 priv->account_manager, default_account_name_start);
346 g_free (default_account_name_start);
347 default_account_name_start = NULL;
349 hide_account_title = FALSE;
350 proto_name = modest_provider_selector_get_active_provider_id (priv->account_serviceprovider_selector);
351 if (proto_name != NULL) {
352 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
353 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
355 if (protocol != NULL) {
356 proto_type = modest_protocol_get_type_id (protocol);
358 hide_account_title = (modest_protocol_registry_protocol_type_has_tag
359 (modest_runtime_get_protocol_registry (),
361 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS) ||
362 modest_protocol_registry_protocol_type_has_tag
363 (modest_runtime_get_protocol_registry (),
365 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS));
369 if (hide_account_title)
370 gtk_widget_hide (priv->caption_account_title);
372 gtk_widget_show (priv->caption_account_title);
374 modest_entry_set_text (priv->entry_account_title, default_account_name);
375 g_free (default_account_name);
378 /** This is a convenience function to create a caption containing a mandatory widget.
379 * When the widget is edited, the enable_buttons() vfunc will be called.
382 create_captioned (ModestEasysetupWizardDialog *self,
383 GtkSizeGroup *title_size_group,
384 GtkSizeGroup *value_size_group,
391 result = modest_toolkit_utils_create_captioned_with_size_type (title_size_group, value_size_group,
392 value, use_markup, control,
393 MODEST_EDITABLE_SIZE);
395 /* Connect to the appropriate changed signal for the widget,
396 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
398 if (GTK_IS_ENTRY (control)) {
399 g_signal_connect (G_OBJECT (control), "changed",
400 G_CALLBACK (on_caption_entry_changed), self);
403 else if (GTK_IS_COMBO_BOX (control)) {
404 g_signal_connect (G_OBJECT (control), "changed",
405 G_CALLBACK (on_caption_combobox_changed), self);
412 create_page_welcome (ModestEasysetupWizardDialog *self)
417 GtkWidget *privacy_note;
418 GtkWidget *scrollable;
419 ModestEasysetupWizardDialogPrivate *priv;
421 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
422 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
423 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
424 label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
425 privacy_note = gtk_label_new (_("mcen_ia_privacy_notice"));
426 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
427 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
428 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
429 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
430 gtk_widget_set_size_request (privacy_note, LABELS_WIDTH, -1);
431 gtk_label_set_line_wrap (GTK_LABEL (privacy_note), TRUE);
432 #ifdef MODEST_TOOLKIT_HILDON2
433 hildon_helper_set_logical_font (privacy_note, "SmallSystemFont");
435 /* So that it is not truncated: */
436 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
437 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
438 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
439 gtk_box_pack_start (GTK_BOX (box), privacy_note, FALSE, FALSE, 0);
440 gtk_container_add (GTK_CONTAINER (align), box);
441 gtk_widget_show (label);
442 gtk_widget_show (privacy_note);
444 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
445 gtk_widget_show (GTK_WIDGET (box));
446 gtk_widget_show (GTK_WIDGET (align));
447 gtk_widget_show (scrollable);
449 return GTK_WIDGET (scrollable);
453 on_account_country_selector_changed (GtkWidget *widget, gpointer user_data)
455 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
457 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
461 /* Fill the providers selector, based on the selected country: */
462 if (priv->presets != NULL) {
463 gint mcc = modest_country_selector_get_active_country_mcc (priv->account_country_selector);
464 if (priv->last_mcc != mcc) {
465 modest_provider_selector_fill (priv->account_serviceprovider_selector, priv->presets, mcc);
467 modest_provider_selector_refresh (priv->account_serviceprovider_selector);
469 priv->last_mcc = mcc;
474 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
476 ModestEasysetupWizardDialogPrivate *priv;
477 gchar* provider_id = NULL, *with_at = NULL;
480 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
482 /* Fill the providers combo, based on the selected country: */
483 provider_id = modest_provider_selector_get_active_provider_id (
484 priv->account_serviceprovider_selector);
487 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
488 with_at = g_strdup_printf ("%c%s", '@', domain_name);
489 g_free (domain_name);
492 /* The sample address already contains the '@' */
494 with_at = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
496 if (priv->entry_user_email)
497 modest_entry_set_text (priv->entry_user_email, with_at);
500 g_free (provider_id);
503 #ifdef HILDON_PICKER_BUTTON
505 on_account_serviceprovider_selector_changed (GtkWidget *widget, gint column, gpointer user_data)
507 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
509 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
513 update_user_email_from_provider (self);
518 on_account_serviceprovider_selector_combo_box_changed (GtkWidget *widget, gpointer user_data)
520 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
522 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
526 update_user_email_from_provider (self);
530 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
532 modest_platform_information_banner (GTK_WIDGET (self), NULL,
533 _CS_MAXIMUM_CHARACTERS_REACHED);
537 create_page_account_details (ModestEasysetupWizardDialog *self)
540 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
541 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
542 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
545 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
546 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
547 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
548 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
549 gtk_widget_show (label);
551 /* Create a size group to be used by all captions.
552 * Note that HildonCaption does not create a default size group if we do not specify one.
553 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
554 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
555 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
557 /* The country widgets: */
558 priv->account_country_selector = modest_toolkit_factory_create_country_selector (modest_runtime_get_toolkit_factory ());
559 if (GTK_IS_COMBO_BOX (priv->account_country_selector)) {
560 GtkWidget *captioned;
561 g_signal_connect (G_OBJECT (priv->account_country_selector), "changed",
562 G_CALLBACK (on_picker_button_value_changed), self);
563 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
564 _("mcen_fi_country"), FALSE,
565 priv->account_country_selector);
567 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
568 gtk_widget_show (captioned);
570 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
571 _("mcen_fi_country"), priv->account_country_selector);
572 g_signal_connect (G_OBJECT (priv->account_country_selector), "value-changed",
573 G_CALLBACK (on_picker_button_value_changed), self);
574 gtk_box_pack_start (GTK_BOX (box), priv->account_country_selector, FALSE, FALSE, MODEST_MARGIN_HALF);
576 gtk_widget_show (priv->account_country_selector);
578 /* The service provider widgets: */
579 priv->account_serviceprovider_selector = modest_toolkit_factory_create_provider_selector (modest_runtime_get_toolkit_factory ());
580 if (GTK_IS_COMBO_BOX (priv->account_serviceprovider_selector)) {
581 GtkWidget *captioned;
582 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "changed",
583 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
584 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
585 _("mcen_fi_serviceprovider"), FALSE,
586 priv->account_serviceprovider_selector);
588 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "changed",
589 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
590 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
591 gtk_widget_show (captioned);
593 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
594 _("mcen_fi_serviceprovider"),
595 priv->account_serviceprovider_selector);
596 g_signal_connect (G_OBJECT (priv->account_serviceprovider_selector), "value-changed",
597 G_CALLBACK (on_serviceprovider_selector_value_changed), self);
598 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_selector, FALSE, FALSE, 0);
600 gtk_widget_show (priv->account_serviceprovider_selector);
602 /* The description widgets: */
603 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
605 /* Do use auto-capitalization: */
607 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
608 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
611 /* Set a default account title, choosing one that does not already exist: */
612 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
613 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
614 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
615 priv->account_manager, default_account_name_start);
616 g_free (default_account_name_start);
617 default_account_name_start = NULL;
619 modest_entry_set_text (priv->entry_account_title, default_account_name);
620 g_free (default_account_name);
621 default_account_name = NULL;
623 /* Connect signal after changing the text in the entry */
624 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
625 G_CALLBACK(on_easysetup_changed), self);
627 tmp_str = g_strconcat (_("mcen_fi_account_title"), "*", NULL);
628 priv->caption_account_title = create_captioned (self, title_sizegroup, value_sizegroup,
630 priv->entry_account_title);
632 gtk_widget_show (priv->entry_account_title);
633 gtk_box_pack_start (GTK_BOX (box), priv->caption_account_title, FALSE, FALSE, 0);
634 gtk_widget_show (priv->caption_account_title);
635 gtk_widget_set_no_show_all (priv->caption_account_title, TRUE);
637 /* Prevent the use of some characters in the account title,
638 * as required by our UI specification: */
639 GList *list_prevent = NULL;
640 list_prevent = g_list_append (list_prevent, "\\");
641 list_prevent = g_list_append (list_prevent, "/");
642 list_prevent = g_list_append (list_prevent, ":");
643 list_prevent = g_list_append (list_prevent, "*");
644 list_prevent = g_list_append (list_prevent, "?");
645 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
646 list_prevent = g_list_append (list_prevent, "“");
647 list_prevent = g_list_append (list_prevent, "<");
648 list_prevent = g_list_append (list_prevent, ">");
649 list_prevent = g_list_append (list_prevent, "|");
650 list_prevent = g_list_append (list_prevent, "^");
651 modest_validating_entry_set_unallowed_characters (
652 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
653 g_list_free (list_prevent);
655 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
656 modest_utils_on_entry_invalid_character, self);
658 /* Set max length as in the UI spec:
659 * The UI spec seems to want us to show a dialog if we hit the maximum. */
660 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
661 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
664 gtk_widget_show (GTK_WIDGET (box));
666 g_object_unref (title_sizegroup);
667 g_object_unref (value_sizegroup);
669 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
670 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
671 gtk_widget_show (align);
672 gtk_container_add (GTK_CONTAINER (align), box);
674 return GTK_WIDGET (align);
678 on_user_username_changed(GtkWidget* widget, ModestEasysetupWizardDialog *self)
680 ModestEasysetupWizardDialogPrivate* priv;
681 gchar* provider_id = NULL;
683 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
685 /* Work out the user email address */
686 provider_id = modest_provider_selector_get_active_provider_id (
687 priv->account_serviceprovider_selector);
690 const gchar *current_username;
691 gchar *email_address;
692 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
694 current_username = modest_entry_get_text (priv->entry_user_username);
696 if (current_username && strstr (current_username, "@")) {
697 email_address = g_strdup (current_username);
699 email_address = g_strdup_printf ("%s@%s",
704 /* Update the email address */
705 modest_entry_set_text (priv->entry_user_email, email_address);
707 g_free (email_address);
708 g_free (domain_name);
709 g_free (provider_id);
713 on_easysetup_changed(widget, self);
718 create_page_user_details (ModestEasysetupWizardDialog *self)
720 GtkSizeGroup* title_sizegroup;
721 GtkSizeGroup* value_sizegroup;
723 ModestEasysetupWizardDialogPrivate *priv;
725 const gchar *my_name;
728 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
730 /* Create a size group to be used by all captions.
731 * Note that HildonCaption does not create a default size group if we do not specify one.
732 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
733 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
734 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
735 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
737 /* The name widgets: (use auto cap) */
738 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
740 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
741 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
744 /* Set max length as in the UI spec:
745 * The UI spec seems to want us to show a dialog if we hit the maximum. */
746 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
747 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
749 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
750 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
752 /* Try to initialize the user name with my own contact */
753 my_name = modest_address_book_get_my_name ();
755 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_name), my_name);
757 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
758 G_CALLBACK(on_easysetup_changed), self);
759 gtk_widget_show (priv->entry_user_name);
760 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
761 gtk_widget_show (caption);
763 /* Prevent the use of some characters in the name,
764 * as required by our UI specification: */
765 GList *list_prevent = NULL;
766 list_prevent = g_list_append (list_prevent, "<");
767 list_prevent = g_list_append (list_prevent, ">");
768 modest_validating_entry_set_unallowed_characters (
769 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
770 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
771 modest_utils_on_entry_invalid_character, self);
772 g_list_free (list_prevent);
774 /* The username widgets: */
775 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
776 /* Auto-capitalization is the default, so let's turn it off: */
778 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
779 HILDON_GTK_INPUT_MODE_FULL);
781 tmp_str = g_strconcat (_("mail_fi_username"), "*", NULL);
782 caption = create_captioned (self, title_sizegroup, value_sizegroup,
784 priv->entry_user_username);
786 gtk_widget_show (priv->entry_user_username);
787 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
788 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
789 G_CALLBACK(on_user_username_changed), self);
790 gtk_widget_show (caption);
792 /* Prevent the use of some characters in the username,
793 * as required by our UI specification: */
794 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
795 modest_utils_on_entry_invalid_character, self);
797 /* Set max length as in the UI spec:
798 * The UI spec seems to want us to show a dialog if we hit the maximum. */
799 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
800 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
803 /* The password widgets: */
804 priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
805 /* Auto-capitalization is the default, so let's turn it off: */
807 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
808 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
810 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
811 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
812 caption = create_captioned (self, title_sizegroup, value_sizegroup,
813 _("mail_fi_password"), FALSE, priv->entry_user_password);
814 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
815 G_CALLBACK(on_easysetup_changed), self);
816 gtk_widget_show (priv->entry_user_password);
817 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
818 gtk_widget_show (caption);
820 /* The email address widgets: */
821 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
822 /* Auto-capitalization is the default, so let's turn it off: */
824 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
826 tmp_str = g_strconcat (_("mcen_li_emailsetup_email_address"), "*", NULL);
827 caption = create_captioned (self, title_sizegroup, value_sizegroup,
828 tmp_str, FALSE, priv->entry_user_email);
830 update_user_email_from_provider (self);
831 gtk_widget_show (priv->entry_user_email);
832 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
833 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
834 G_CALLBACK(on_easysetup_changed), self);
835 gtk_widget_show (caption);
837 /* Set max length as in the UI spec:
838 * The UI spec seems to want us to show a dialog if we hit the maximum. */
839 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
840 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
844 gtk_widget_show (GTK_WIDGET (box));
845 g_object_unref (title_sizegroup);
846 g_object_unref (value_sizegroup);
848 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
849 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
850 gtk_widget_show (align);
851 gtk_container_add (GTK_CONTAINER (align), box);
853 return GTK_WIDGET (align);
857 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
860 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
862 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
863 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
864 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
865 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
866 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
868 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
869 gtk_widget_show (label);
871 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
872 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
873 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
875 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
876 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
877 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
878 gtk_widget_show (label);
880 gtk_widget_show (GTK_WIDGET (box));
882 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
883 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
884 gtk_widget_show (align);
885 gtk_container_add (GTK_CONTAINER (align), box);
887 return GTK_WIDGET (align);
890 /** Change the caption title for the incoming server,
891 * as specified in the UI spec:
894 update_incoming_server_title (ModestEasysetupWizardDialog *self)
896 ModestEasysetupWizardDialogPrivate* priv;
897 ModestProtocolType protocol_type;
898 ModestProtocolRegistry *protocol_registry;
900 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
901 protocol_registry = modest_runtime_get_protocol_registry ();
903 protocol_type = modest_servertype_selector_get_active_servertype (
904 priv->incoming_servertype_selector);
906 /* This could happen when the combo box has still no active iter */
907 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
908 gchar* incomingserver_title;
909 const gchar *protocol_display_name;
910 ModestProtocol *protocol;
912 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
914 protocol_display_name = modest_protocol_get_display_name (protocol);
916 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "*\n<small>(",
917 protocol_display_name, ")</small>", NULL);
919 modest_toolkit_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
921 g_free(incomingserver_title);
925 /** Change the caption title for the incoming server,
926 * as specified in the UI spec:
929 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
931 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
932 GtkWidget *server_type_selector;
933 ModestProtocolType protocol_type;
934 ModestSecurityOptionsView *view;
936 server_type_selector = priv->incoming_servertype_selector;
937 protocol_type = modest_servertype_selector_get_active_servertype (server_type_selector);
939 /* Fill the combo with appropriately titled choices for all
941 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
942 modest_security_options_view_set_server_type (view, protocol_type);
945 #ifdef HILDON_PICKER_BUTTON
947 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
949 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
950 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
955 update_incoming_server_title (self);
957 /* Update security options if needed */
958 update_incoming_server_security_choices (self);
959 gtk_widget_show (priv->incoming_security);
961 set_default_custom_servernames (self);
966 on_servertype_combo_changed(GtkWidget *selector, gpointer user_data)
968 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
969 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
974 update_incoming_server_title (self);
976 /* Update security options if needed */
977 update_incoming_server_security_choices (self);
978 gtk_widget_show (priv->incoming_security);
980 set_default_custom_servernames (self);
984 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
986 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
987 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
989 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
993 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
995 ModestProtocolRegistry *protocol_registry;
996 ModestEasysetupWizardDialogPrivate* priv;
999 GtkWidget *scrollable;
1001 GtkSizeGroup *title_sizegroup;
1002 GtkSizeGroup *value_sizegroup;
1004 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1005 protocol_registry = modest_runtime_get_protocol_registry ();
1007 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1008 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1010 /* Show note that account type cannot be changed in future: */
1011 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
1012 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1013 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1014 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1015 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1016 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1017 gtk_widget_show (label);
1019 /* Create a size group to be used by all captions.
1020 * Note that HildonCaption does not create a default size group if we do not specify one.
1021 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1022 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1023 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1025 /* The incoming server widgets: */
1026 priv->incoming_servertype_selector =
1027 modest_toolkit_factory_create_servertype_selector (modest_runtime_get_toolkit_factory (),
1029 if (GTK_IS_COMBO_BOX (priv->incoming_servertype_selector)) {
1030 GtkWidget *captioned;
1031 g_signal_connect (G_OBJECT (priv->incoming_servertype_selector), "changed",
1032 G_CALLBACK (on_picker_button_value_changed), self);
1033 captioned = modest_toolkit_utils_create_captioned (title_sizegroup, value_sizegroup,
1034 _("mcen_fi_country"), FALSE,
1035 priv->incoming_servertype_selector);
1037 gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
1038 gtk_widget_show (captioned);
1040 modest_toolkit_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
1041 _("mcen_li_emailsetup_type"),
1042 priv->incoming_servertype_selector);
1043 g_signal_connect (G_OBJECT (priv->incoming_servertype_selector), "value-changed",
1044 G_CALLBACK (on_picker_button_value_changed), self);
1045 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_selector, FALSE, FALSE, 0);
1047 gtk_widget_show (priv->incoming_servertype_selector);
1049 priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
1051 /* Auto-capitalization is the default, so let's turn it off: */
1052 #ifdef MAEMO_CHANGES
1053 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
1055 set_default_custom_servernames (self);
1057 /* The caption title will be updated in update_incoming_server_title().
1058 * so this default text will never be seen: */
1059 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
1060 "This will be removed",
1061 FALSE, priv->entry_incomingserver);
1062 update_incoming_server_title (self);
1063 gtk_widget_show (priv->entry_incomingserver);
1064 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
1065 gtk_widget_show (priv->caption_incoming);
1067 /* Remember when the servername was changed manually: */
1068 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
1069 G_CALLBACK (on_entry_incoming_servername_changed), self);
1071 /* The secure connection widgets. These are only valid for
1072 protocols with security */
1073 priv->incoming_security = modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
1074 MODEST_SECURITY_OPTIONS_INCOMING,
1075 FALSE, title_sizegroup, value_sizegroup);
1076 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
1078 gtk_widget_show (priv->incoming_security);
1080 /* Set default selection */
1081 modest_servertype_selector_set_active_servertype (priv->incoming_servertype_selector,
1082 MODEST_PROTOCOLS_STORE_POP);
1083 update_incoming_server_title (self);
1084 update_incoming_server_security_choices (self);
1085 set_default_custom_servernames (self);
1087 /* Change the caption title when the servertype changes,
1088 * as in the UI spec: */
1089 if (GTK_IS_COMBO_BOX (priv->incoming_servertype_selector)) {
1090 g_signal_connect (priv->incoming_servertype_selector,
1092 G_CALLBACK (on_servertype_combo_changed), self);
1094 #ifdef HILDON_PICKER_BUTTON
1095 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_selector))),
1097 G_CALLBACK (on_servertype_selector_changed), self);
1101 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1102 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1103 gtk_widget_show (align);
1104 gtk_container_add (GTK_CONTAINER (align), box);
1106 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1107 gtk_widget_show (GTK_WIDGET (box));
1108 gtk_widget_show (scrollable);
1110 g_object_unref (title_sizegroup);
1111 g_object_unref (value_sizegroup);
1113 /* Connect changed signals. We do it here after initializing everything */
1114 g_signal_connect (G_OBJECT(priv->entry_incomingserver), "changed",
1115 G_CALLBACK(on_easysetup_changed), self);
1118 return GTK_WIDGET (scrollable);
1122 on_check_button_changed (GtkWidget *button, gpointer user_data)
1124 GtkWidget *widget = GTK_WIDGET (user_data);
1126 /* Enable the widget only if the check button is active: */
1127 const gboolean enable = modest_togglable_get_active (button);
1128 gtk_widget_set_sensitive (widget, enable);
1131 /* Make the sensitivity of a widget depend on a check button.
1134 enable_widget_for_checkbutton (GtkWidget *widget, GtkWidget* button)
1136 g_signal_connect (G_OBJECT (button), "toggled",
1137 G_CALLBACK (on_check_button_changed), widget);
1139 /* Set the starting sensitivity: */
1140 on_check_button_changed (button, widget);
1144 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
1146 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1147 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1148 GtkWidget *specific_window;
1150 /* We set dirty here because setting it depending on the connection specific dialog
1154 /* Create the window, if necessary: */
1155 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
1156 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
1158 /* Show the window */
1159 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
1160 gtk_widget_show (specific_window);
1164 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
1166 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1167 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1168 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
1172 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
1174 ModestEasysetupWizardDialogPrivate *priv;
1175 gchar *smtp_caption_label;
1176 GtkWidget *scrollable;
1178 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1180 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1182 /* Create a size group to be used by all captions.
1183 * Note that HildonCaption does not create a default size group if we do not specify one.
1184 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1185 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1186 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1188 /* The outgoing server widgets: */
1189 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1190 priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
1192 /* Auto-capitalization is the default, so let's turn it off: */
1193 #ifdef MAEMO_CHANGES
1194 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
1196 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "*\n<small>(SMTP)</small>", NULL);
1198 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
1199 smtp_caption_label, TRUE, priv->entry_outgoingserver);
1200 g_free (smtp_caption_label);
1201 gtk_widget_show (priv->entry_outgoingserver);
1202 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
1203 gtk_widget_show (caption);
1204 set_default_custom_servernames (self);
1206 /* The secure connection widgets. These are only valid for
1207 protocols with security */
1208 priv->outgoing_security =
1209 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
1210 MODEST_SECURITY_OPTIONS_OUTGOING,
1211 FALSE, title_sizegroup, value_sizegroup);
1212 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
1214 gtk_widget_show (priv->outgoing_security);
1216 GtkWidget *separator = gtk_hseparator_new ();
1217 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
1218 gtk_widget_show (separator);
1220 /* connection-specific checkbox: */
1221 priv->checkbox_outgoing_smtp_specific = modest_toolkit_factory_create_check_button
1222 (modest_runtime_get_toolkit_factory (),
1223 _("mcen_fi_advsetup_connection_smtp"));
1224 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
1227 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1228 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
1231 /* Connection-specific SMTP-Severs Edit button: */
1232 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
1233 #ifdef MAEMO_CHANGES
1234 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
1235 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1237 gtk_widget_show (priv->button_outgoing_smtp_servers);
1238 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
1241 /* Only enable the button when the checkbox is checked: */
1242 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
1243 priv->checkbox_outgoing_smtp_specific);
1245 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1246 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1248 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1249 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1252 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1253 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1254 gtk_widget_show (align);
1255 gtk_container_add (GTK_CONTAINER (align), box);
1257 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1258 gtk_widget_show (GTK_WIDGET (box));
1259 gtk_widget_show (scrollable);
1261 g_object_unref (title_sizegroup);
1262 g_object_unref (value_sizegroup);
1264 /* Connect changed signals. We do it here after initializing everything */
1265 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1266 G_CALLBACK (on_easysetup_changed), self);
1267 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1268 G_CALLBACK (on_easysetup_changed), self);
1270 return GTK_WIDGET (scrollable);
1274 show_advanced_edit(gpointer user_data)
1276 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1277 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1280 /* Show the Account Settings window: */
1281 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
1282 if (priv->pending_load_settings) {
1283 save_to_settings (self);
1284 priv->pending_load_settings = FALSE;
1286 modest_account_settings_dialog_load_settings (dialog, priv->settings);
1288 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
1290 response = gtk_dialog_run (GTK_DIALOG (dialog));
1292 gtk_widget_destroy (GTK_WIDGET (dialog));
1294 return FALSE; /* Do not call this timeout callback again. */
1298 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1300 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1302 /* Show the Account Settings window: */
1303 show_advanced_edit(self);
1306 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1308 gchar *complete_string;
1312 GtkWidget *button_edit;
1314 box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1315 complete_string = g_strconcat (_("mcen_ia_emailsetup_setup_complete"), " ",
1316 _("mcen_ia_customsetup_complete"), NULL);
1317 label = gtk_label_new(complete_string);
1318 g_free (complete_string);
1319 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1320 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1321 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1322 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1323 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1324 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1325 gtk_widget_show (label);
1327 button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1328 #ifdef MAEMO_CHANGES
1329 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1331 gtk_widget_show (button_edit);
1332 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, 0);
1334 g_signal_connect (G_OBJECT (button_edit), "clicked",
1335 G_CALLBACK (on_button_edit_advanced_settings), self);
1337 gtk_widget_show (GTK_WIDGET (box));
1339 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1340 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
1341 gtk_widget_show (align);
1342 gtk_container_add (GTK_CONTAINER (align), box);
1344 return GTK_WIDGET (align);
1351 on_response (ModestWizardDialog *wizard_dialog,
1355 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1357 invoke_enable_buttons_vfunc (self);
1361 on_response_before (ModestWizardDialog *wizard_dialog,
1365 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1366 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1367 if (response_id == GTK_RESPONSE_CANCEL) {
1368 /* This is mostly copied from
1369 * src/maemo/modest-account-settings-dialog.c */
1371 gint dialog_response;
1373 dialog_response = modest_platform_run_confirmation_dialog ((GtkWindow *) self,
1374 _("imum_nc_wizard_confirm_lose_changes"));
1376 if (dialog_response != GTK_RESPONSE_OK) {
1377 /* Don't let the dialog close */
1378 g_signal_stop_emission_by_name (wizard_dialog, "response");
1385 fill_providers (ModestEasysetupWizardDialog *self)
1387 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1389 if (priv->account_country_selector) {
1390 /* gint mcc = get_default_country_code(); */
1392 /* Fill the combo in an idle call, as it takes a lot of time */
1393 modest_country_selector_load_data(priv->account_country_selector);
1394 /* connect to country picker's changed signal, so we can fill the provider picker: */
1395 if (GTK_IS_COMBO_BOX (priv->account_country_selector)) {
1396 g_signal_connect ((GObject *) priv->account_country_selector,
1398 G_CALLBACK (on_account_country_selector_changed), self);
1400 g_signal_connect ((GObject *) priv->account_country_selector,
1402 G_CALLBACK (on_account_country_selector_changed), self);
1405 modest_country_selector_set_active_country_locale (priv->account_country_selector);
1406 mcc = modest_country_selector_get_active_country_mcc (priv->account_country_selector);
1407 if (priv->last_mcc != mcc) {
1408 modest_provider_selector_fill (priv->account_serviceprovider_selector,
1409 priv->presets, mcc);
1411 modest_provider_selector_refresh (priv->account_serviceprovider_selector);
1413 priv->last_mcc = mcc;
1414 /* connect to providers picker's changed signal, so we can fill the email address: */
1415 if (GTK_IS_COMBO_BOX (priv->account_serviceprovider_selector)) {
1416 g_signal_connect (priv->account_serviceprovider_selector,
1418 G_CALLBACK (on_account_serviceprovider_selector_combo_box_changed), self);
1420 #ifdef HILDON_PICKER_BUTTON
1421 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1422 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_selector))),
1424 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1427 modest_provider_selector_set_others_provider (priv->account_serviceprovider_selector);
1430 priv->dirty = FALSE;
1434 typedef struct IdleData {
1435 ModestEasysetupWizardDialog *dialog;
1436 ModestPresets *presets;
1440 presets_idle (gpointer userdata)
1442 IdleData *idle_data = (IdleData *) userdata;
1443 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1444 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1446 g_assert (idle_data->presets);
1448 gdk_threads_enter ();
1450 priv->presets = idle_data->presets;
1452 if (priv->check_support_done)
1453 fill_providers (self);
1455 g_object_unref (idle_data->dialog);
1458 gdk_threads_leave ();
1464 presets_loader (gpointer userdata)
1466 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1467 ModestPresets *presets = NULL;
1468 IdleData *idle_data;
1470 const gchar* path = NULL;
1471 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1472 const gchar* path2 = MODEST_FALLBACK_PROVIDER_DATA_FILE;
1474 if (access(path1, R_OK) == 0)
1476 else if (access(path2, R_OK) == 0)
1479 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1480 __FUNCTION__, path1, path2);
1484 presets = modest_presets_new (path);
1486 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1490 idle_data = g_new0 (IdleData, 1);
1491 idle_data->dialog = self;
1492 idle_data->presets = presets;
1494 g_idle_add (presets_idle, idle_data);
1500 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1506 /* Append page and set attributes */
1507 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1508 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1509 "tab-expand", TRUE, "tab-fill", TRUE,
1512 /* Give focus to page and show it */
1513 gtk_container_set_focus_child (GTK_CONTAINER (notebook), page);
1514 gtk_widget_show (page);
1518 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1520 priv->page_user_details = NULL;
1521 priv->entry_user_name = NULL;
1522 priv->entry_user_username = NULL;
1523 priv->entry_user_password = NULL;
1524 priv->entry_user_email = NULL;
1528 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1530 priv->page_custom_incoming = NULL;
1531 priv->incoming_servertype_selector = NULL;
1532 priv->caption_incoming = NULL;
1533 priv->entry_incomingserver = NULL;
1534 priv->entry_user_email = NULL;
1535 priv->incoming_security = NULL;
1539 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1541 priv->page_custom_outgoing = NULL;
1542 priv->entry_outgoingserver = NULL;
1543 priv->checkbox_outgoing_smtp_specific = NULL;
1544 priv->button_outgoing_smtp_servers = NULL;
1545 priv->outgoing_security = NULL;
1549 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1551 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1553 /* Create the notebook to be used by the ModestWizardDialog base class:
1554 * Each page of the notebook will be a page of the wizard: */
1555 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1556 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1558 /* Set the notebook used by the ModestWizardDialog base class: */
1559 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1561 /* Set the wizard title:
1562 * The actual window title will be a combination of this and the page's tab label title. */
1563 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1565 /* Read in the information about known service providers: */
1566 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1568 /* The server fields did not have been manually changed yet */
1569 priv->server_changes = 0;
1570 priv->pending_load_settings = TRUE;
1572 /* Get the account manager object,
1573 * so we can check for existing accounts,
1574 * and create new accounts: */
1575 priv->account_manager = modest_runtime_get_account_mgr ();
1576 g_object_ref (priv->account_manager);
1578 /* Initialize fields */
1579 priv->check_support_done = FALSE;
1580 priv->check_support_show_progress_id = 0;
1581 priv->check_support_progress_pulse_id = 0;
1582 priv->check_support_cancel_note = NULL;
1583 priv->check_support_progress = NULL;
1584 priv->pending_check_support = 0;
1585 priv->destroyed = FALSE;
1586 priv->page_welcome = create_page_welcome (self);
1587 gtk_widget_show (priv->page_welcome);
1588 priv->page_account_details = create_page_account_details (self);
1590 init_user_page (priv);
1591 init_incoming_page (priv);
1592 init_outgoing_page (priv);
1594 priv->page_complete_easysetup = NULL;
1595 priv->page_complete_customsetup = NULL;
1596 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1597 priv->last_mcc = -1;
1598 priv->missing_data_signals = NULL;
1600 /* Add the common pages */
1601 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1602 _("mcen_ti_emailsetup_welcome"));
1603 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1604 _("mcen_ti_accountdetails"));
1606 /* Connect to the dialog's response signal so we can enable/disable buttons
1607 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1608 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1609 * so that we can be enable/disable after ModestWizardDialog has done its own
1610 * enabling/disabling of buttons.
1612 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1613 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1615 * It's not enough to connect to the notebook's switch-page signal, because
1616 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1617 * _after_ switching the page (understandably).
1618 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1619 * then gtk_notebook_get_current_page() would return an incorrect value.)
1621 g_signal_connect_after (G_OBJECT (self), "response",
1622 G_CALLBACK (on_response), self);
1624 /* This is to show a confirmation dialog when the user hits cancel */
1625 g_signal_connect (G_OBJECT (self), "response",
1626 G_CALLBACK (on_response_before), self);
1628 g_signal_connect (G_OBJECT (self), "delete-event",
1629 G_CALLBACK (on_delete_event), self);
1631 /* Reset dirty, because there was no user input until now */
1632 priv->dirty = FALSE;
1634 /* When this window is shown, hibernation should not be possible,
1635 * because there is no sensible way to save the state: */
1636 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1637 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1639 /* Load provider presets */
1640 g_object_ref (self);
1641 g_thread_create (presets_loader, self, FALSE, NULL);
1643 priv->settings = modest_account_settings_new ();
1647 ModestEasysetupWizardDialog*
1648 modest_easysetup_wizard_dialog_new (void)
1651 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1655 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1657 ModestEasysetupWizardDialogPrivate *priv;
1658 GtkNotebook *notebook = NULL;
1660 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1663 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1665 if (!priv->page_user_details) {
1666 priv->page_user_details = create_page_user_details (self);
1669 /* Create the custom pages: */
1670 if(!(priv->page_custom_incoming)) {
1671 priv->page_custom_incoming = create_page_custom_incoming (self);
1674 /* TODO: only if needed */
1675 if(!(priv->page_custom_outgoing)) {
1676 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1679 if(!(priv->page_complete_customsetup)) {
1680 priv->page_complete_customsetup = create_page_complete_custom (self);
1683 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1684 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1685 _("mcen_ti_emailsetup_userdetails"));
1687 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1688 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1689 _("mcen_ti_emailsetup_incomingdetails"));
1691 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1692 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1693 _("mcen_ti_emailsetup_outgoingdetails"));
1695 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1696 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1697 _("mcen_ti_emailsetup_complete"));
1699 /* This is unnecessary with GTK+ 2.10: */
1700 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1704 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1706 ModestEasysetupWizardDialogPrivate *priv;
1707 GtkNotebook *notebook = NULL;
1709 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1712 /* Create the easysetup-specific pages: */
1713 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1714 if(!priv->page_complete_easysetup)
1715 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1717 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1718 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1719 _("mcen_ti_emailsetup_complete"));
1721 /* This is unnecessary with GTK+ 2.10: */
1722 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1727 remove_non_common_tabs (ModestEasysetupWizardDialog *self,
1728 gboolean remove_user_details)
1731 GtkNotebook *notebook;
1732 ModestEasysetupWizardDialogPrivate *priv;
1734 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1735 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1737 /* The first 2 tabs are the common ones (welcome tab and the
1738 providers tab), so we always remove starting from the
1740 starting_tab = (remove_user_details) ? 2 : 3;
1741 while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
1742 /* Disconnect signal */
1743 GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
1744 if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
1745 priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
1747 "missing-mandatory-data");
1749 /* Remove page from notebook */
1750 gtk_notebook_remove_page (notebook, -1);
1755 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1759 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1762 /* After the user details page,
1763 * the following pages depend on whether "Other" was chosen
1764 * in the provider combobox on the account page
1767 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1769 ModestEasysetupWizardDialogPrivate *priv;
1771 ModestProviderSelectorIdType id_type;
1772 GtkNotebook *notebook;
1774 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1775 picker = priv->account_serviceprovider_selector;
1776 id_type = modest_provider_selector_get_active_id_type (picker);
1777 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1779 /* Remove the response override handler for non-plugin
1780 protocols. For plugins it'll be overriden later */
1781 if (id_type != MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL)
1782 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1786 if (id_type == MODEST_PROVIDER_SELECTOR_ID_OTHER) {
1787 /* "Other..." was selected: */
1789 /* If we come from a rollbacked easysetup */
1790 if (priv->page_complete_easysetup) {
1791 remove_non_common_tabs (self, FALSE);
1792 priv->page_complete_easysetup = NULL;
1795 /* If we come from a rollbacked plugin protocol setup */
1796 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1797 remove_non_common_tabs (self, TRUE);
1798 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1799 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1800 priv->missing_data_signals = NULL;
1803 create_subsequent_customsetup_pages (self);
1805 /* If we come from a rollbacked custom setup */
1806 if (priv->page_custom_incoming) {
1807 remove_non_common_tabs (self, TRUE);
1808 init_user_page (priv);
1809 init_incoming_page (priv);
1810 init_outgoing_page (priv);
1811 init_user_page (priv);
1812 priv->page_complete_customsetup = NULL;
1815 /* It's a pluggable protocol and not a provider with presets */
1816 if (id_type == MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL) {
1817 ModestProtocol *protocol;
1819 ModestProtocolType proto_type;
1820 ModestWizardDialogResponseOverrideFunc response_override;
1822 /* Get protocol data */
1823 proto_name = modest_provider_selector_get_active_provider_id (picker);
1824 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1825 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1827 proto_type = modest_protocol_get_type_id (protocol);
1830 /* If we come from a rollbacked easy setup */
1831 if (priv->last_plugin_protocol_selected != proto_type &&
1832 priv->page_complete_easysetup) {
1833 remove_non_common_tabs (self, TRUE);
1834 init_user_page (priv);
1835 priv->page_complete_easysetup = NULL;
1838 /* Ensure that the response override handler
1839 is set. It might happen that plugins clear
1841 response_override = modest_account_protocol_get_wizard_response_override
1842 (MODEST_ACCOUNT_PROTOCOL (protocol));
1843 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1846 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1847 proto_type != priv->last_plugin_protocol_selected) {
1848 ModestPairList *tabs;
1850 gboolean first_page = TRUE;
1852 /* Remember the last selected plugin protocol */
1853 priv->last_plugin_protocol_selected = proto_type;
1856 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1857 tmp = (GSList *) tabs;
1859 ModestPair *pair = (ModestPair *) tmp->data;
1860 modest_easysetup_wizard_dialog_append_page (notebook,
1861 GTK_WIDGET (pair->second),
1862 (const gchar *) pair->first);
1864 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1865 GTK_WIDGET (pair->second));
1869 /* Connect signals */
1870 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1871 priv->missing_data_signals =
1872 modest_signal_mgr_connect (priv->missing_data_signals,
1873 G_OBJECT (pair->second),
1874 "missing-mandatory-data",
1875 G_CALLBACK (on_missing_mandatory_data),
1879 g_free (pair->first);
1880 tmp = g_slist_next (tmp);
1881 /* Critical: if you don't show the page then the dialog will ignore it */
1882 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1884 modest_pair_list_free (tabs);
1886 g_free (proto_name);
1888 if (priv->last_plugin_protocol_selected !=
1889 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1890 remove_non_common_tabs (self, TRUE);
1891 init_user_page (priv);
1892 priv->page_complete_easysetup = NULL;
1893 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1894 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1895 priv->missing_data_signals = NULL;
1897 if (!priv->page_user_details) {
1898 priv->page_user_details = create_page_user_details (self);
1899 modest_easysetup_wizard_dialog_append_page (notebook,
1900 priv->page_user_details,
1901 _("mcen_ti_emailsetup_userdetails"));
1905 /* Create the easysetup pages: */
1906 create_subsequent_easysetup_pages (self);
1912 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1914 const gchar* hostname = NULL;
1917 ModestProtocolRegistry *protocol_registry;
1918 ModestProtocol *protocol;
1923 at = g_utf8_strchr (email_address, -1, '@');
1924 if (!at || (g_utf8_strlen (at, -1) < 2))
1927 domain = g_utf8_next_char (at);
1931 protocol_registry = modest_runtime_get_protocol_registry ();
1932 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1934 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1935 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1936 hostname = modest_protocol_get_name (protocol);
1942 return g_strdup_printf ("%s.%s", hostname, domain);
1946 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1948 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1950 if (!priv->entry_incomingserver)
1953 /* Set a default domain for the server, based on the email address,
1954 * if no server name was already specified.
1956 if (priv->entry_user_email
1957 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1958 const ModestProtocolType protocol_type = modest_servertype_selector_get_active_servertype (
1959 priv->incoming_servertype_selector);
1961 /* This could happen when the combo box has still no active iter */
1962 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1963 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1964 gchar* servername = util_get_default_servername_from_email_address (email_address,
1967 /* Do not set the INCOMING_CHANGED flag because of this edit */
1968 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1969 modest_entry_set_text (priv->entry_incomingserver, servername);
1970 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1972 g_free (servername);
1976 /* Set a default domain for the server, based on the email address,
1977 * if no server name was already specified.
1979 if (!priv->entry_outgoingserver)
1982 if (priv->entry_user_email
1983 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1984 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
1986 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1988 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1989 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1990 modest_entry_set_text (priv->entry_outgoingserver, servername);
1991 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1993 g_free (servername);
1998 get_entered_account_title (ModestEasysetupWizardDialog *self)
2000 ModestEasysetupWizardDialogPrivate *priv;
2001 const gchar* account_title;
2003 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
2004 account_title = modest_entry_get_text (priv->entry_account_title);
2006 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
2009 /* Strip it of whitespace at the start and end: */
2010 gchar *result = g_strdup (account_title);
2011 result = g_strstrip (result);
2016 if (g_utf8_strlen (result, -1) == 0) {
2026 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
2028 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2029 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2030 ModestProtocolRegistry *protocol_registry;
2032 protocol_registry = modest_runtime_get_protocol_registry ();
2034 /* if are browsing pages previous to the last one, then we have pending settings in
2036 if (next_page != NULL)
2037 priv->pending_load_settings = TRUE;
2039 /* Do extra validation that couldn't be done for every key press,
2040 * either because it was too slow,
2041 * or because it requires interaction:
2043 if (current_page == priv->page_welcome) {
2044 if (!priv->check_support_done) {
2045 check_support_of_protocols (self);
2046 return priv->check_support_done;
2048 } else if (current_page == priv->page_account_details) {
2049 /* Check that the title is not already in use: */
2050 gchar* account_title = get_entered_account_title (self);
2054 /* Aavoid a clash with an existing display name: */
2055 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
2056 priv->account_manager, account_title);
2057 g_free (account_title);
2060 /* Warn the user via a dialog: */
2061 modest_platform_system_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
2066 /* Make sure that the subsequent pages are appropriate for the provider choice. */
2067 create_subsequent_pages (self);
2069 } else if (current_page == priv->page_user_details) {
2070 /* Check that the email address is valud: */
2071 const gchar* email_address = modest_entry_get_text (priv->entry_user_email);
2072 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
2075 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
2076 /* Warn the user via a dialog: */
2077 modest_platform_system_banner (NULL, NULL, _("mcen_ib_invalid_email"));
2079 /* Return focus to the email address entry: */
2080 gtk_widget_grab_focus (priv->entry_user_email);
2081 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
2085 } else if (current_page == priv->page_custom_incoming ||
2086 current_page == priv->page_custom_outgoing) {
2088 const gchar *hostname;
2089 GtkWidget *entry = (current_page == priv->page_custom_incoming) ?
2090 priv->entry_incomingserver :
2091 priv->entry_outgoingserver;
2093 hostname = gtk_entry_get_text (GTK_ENTRY (entry));
2094 if (!modest_text_utils_validate_domain_name (hostname)) {
2096 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
2098 /* Return focus to the email address entry: */
2099 gtk_widget_grab_focus (entry);
2100 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
2106 if (next_page == priv->page_custom_incoming) {
2107 set_default_custom_servernames (self);
2108 } else if (next_page == priv->page_custom_outgoing) {
2109 set_default_custom_servernames (self);
2111 /* Check if the server supports secure authentication */
2112 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
2113 if (!check_has_supported_auth_methods (self))
2115 gtk_widget_show (priv->outgoing_security);
2118 /* If this is the last page, and this is a click on Finish,
2119 * then attempt to create the dialog.
2122 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
2124 if (priv->pending_load_settings) {
2125 save_to_settings (self);
2128 /* We check if there's already another account with the same configuration */
2129 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2130 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2134 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2135 #ifdef MODEST_TOOLKIT_HILDON2
2136 hildon_gtk_window_take_screenshot ((GtkWindow *) dialog, FALSE);
2144 static gboolean entry_is_empty (GtkWidget *entry)
2149 const gchar* text = modest_entry_get_text (entry);
2150 if ((!text) || (g_utf8_strlen (text, -1) == 0))
2153 /* Strip it of whitespace at the start and end: */
2154 gchar *stripped = g_strdup (text);
2155 stripped = g_strstrip (stripped);
2160 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
2168 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
2170 GtkNotebook *notebook = NULL;
2171 gboolean is_finish_tab;
2173 ModestEasysetupWizardDialogPrivate *priv;
2176 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
2177 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
2179 /* Disable the Finish button until we are on the last page,
2180 * because HildonWizardDialog enables this for all but the
2182 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
2183 is_finish_tab = ((current == priv->page_complete_easysetup) ||
2184 (current == priv->page_complete_customsetup));
2186 if (is_finish_tab) {
2187 /* Disable Next on the last page no matter what the
2189 enable_next = FALSE;
2191 /* Not the last one */
2192 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2193 MODEST_WIZARD_DIALOG_FINISH,
2196 /* If the check support is not done then do not enable
2197 the wizard to continue */
2198 enable_next = enable_next && priv->pending_check_support == 0;
2201 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2202 MODEST_WIZARD_DIALOG_NEXT,
2207 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
2209 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2210 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2212 gboolean enable_next = TRUE;
2213 if (current_page == priv->page_welcome) {
2215 } else if (current_page == priv->page_account_details) {
2216 /* The account details title is mandatory: */
2217 if (entry_is_empty(priv->entry_account_title))
2218 enable_next = FALSE;
2219 } else if (current_page == priv->page_user_details) {
2220 /* The user details username is mandatory: */
2221 if (entry_is_empty(priv->entry_user_username))
2222 enable_next = FALSE;
2224 /* The user details email address is mandatory: */
2225 if (enable_next && entry_is_empty (priv->entry_user_email))
2226 enable_next = FALSE;
2227 } else if (current_page == priv->page_custom_incoming) {
2228 /* The custom incoming server is mandatory: */
2229 if (entry_is_empty(priv->entry_incomingserver))
2230 enable_next = FALSE;
2231 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
2232 enable_next = !modest_easysetup_wizard_page_validate (
2233 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
2236 /* Enable/disable buttons */
2237 real_enable_buttons (dialog, enable_next);
2241 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
2243 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2244 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
2247 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
2248 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
2250 /* Provide a vfunc implementation so we can decide
2251 * when to enable/disable the prev/next buttons.
2253 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
2254 base_klass->before_next = on_before_next;
2255 base_klass->enable_buttons = on_enable_buttons;
2256 base_klass->update_model = on_update_model;
2257 base_klass->save = on_save;
2261 check_username_for_provider (const gchar *provider_id,
2262 const gchar *domain,
2265 gchar *providers_to_check[] = { "ovi.com", "yahoomailplus.com", "hotmail.com" };
2267 gboolean found = FALSE;
2270 /* Check if the username contains the @hostname, if not then add it */
2271 if (strchr (*username, '@'))
2274 /* Check if it's one of the providers to check */
2275 for (i = 0; i < G_N_ELEMENTS (providers_to_check) && !found; i++) {
2276 if (!g_ascii_strncasecmp (providers_to_check[i], provider_id, strlen (providers_to_check[i])))
2283 /* Replace the username */
2285 *username = g_strconcat (*username, "@", domain, NULL);
2291 * @self: a #ModestEasysetupWizardDialog
2293 * takes information from all the wizard and stores it in settings
2296 save_to_settings (ModestEasysetupWizardDialog *self)
2298 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2300 gchar *provider_id = NULL;
2301 gchar *alternate_username = NULL;
2302 gchar *display_name;
2303 const gchar *username, *password;
2304 gchar *store_hostname, *transport_hostname;
2305 guint store_port, transport_port;
2306 ModestProtocolRegistry *protocol_registry;
2307 ModestProtocolType store_protocol, transport_protocol;
2308 ModestProtocolType store_security, transport_security;
2309 ModestProtocolType store_auth_protocol, transport_auth_protocol;
2310 ModestServerAccountSettings *store_settings, *transport_settings;
2311 const gchar *fullname, *email_address;
2313 ModestProviderSelectorIdType id_type;
2315 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2316 picker = priv->account_serviceprovider_selector;
2317 protocol_registry = modest_runtime_get_protocol_registry ();
2319 /* Get details from the specified presets: */
2320 id_type = modest_provider_selector_get_active_id_type (picker);
2321 provider_id = modest_provider_selector_get_active_provider_id (picker);
2323 /* Let the plugin save the settings. We do a return in order
2324 to save an indentation level */
2325 if (id_type == MODEST_PROVIDER_SELECTOR_ID_PLUGIN_PROTOCOL) {
2326 ModestProtocol *protocol;
2328 protocol = modest_protocol_registry_get_protocol_by_name (
2329 modest_runtime_get_protocol_registry (),
2330 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
2333 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
2334 gint n_pages, i = 0;
2335 GtkNotebook *notebook;
2336 GList *wizard_pages = NULL;
2338 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
2339 n_pages = gtk_notebook_get_n_pages (notebook);
2340 for (i = 0; i < n_pages; i++) {
2341 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
2342 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
2343 wizard_pages = g_list_append (wizard_pages, page);
2345 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
2348 g_list_free (wizard_pages);
2350 g_debug ("The selected protocol is a plugin protocol "//
2351 "but it's not a ModestAccountProtocol");
2354 g_free (provider_id);
2358 /* username and password (for both incoming and outgoing): */
2359 username = modest_entry_get_text (priv->entry_user_username);
2360 password = modest_entry_get_text (priv->entry_user_password);
2362 store_settings = modest_account_settings_get_store_settings (priv->settings);
2363 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
2365 /* Incoming server: */
2366 /* Note: We need something as default for the transport store protocol values,
2367 * or modest_account_mgr_add_server_account will fail. */
2369 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2370 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2371 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2374 ModestProtocolType store_provider_server_type;
2375 gboolean store_provider_use_alternate_port;
2376 gchar *domain = NULL;
2379 store_hostname = modest_presets_get_server (priv->presets, provider_id,
2382 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2385 store_security = modest_presets_get_info_server_security (priv->presets,
2388 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
2391 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
2396 /* This is HORRIBLE, but it seems that somehow it helps users
2397 that do not like to read the user instructions for their
2399 domain = modest_presets_get_domain (priv->presets, provider_id);
2401 alternate_username = g_strdup (username);
2402 check_username_for_provider (provider_id, domain, &alternate_username);
2406 /* We don't check for SMTP here as that is impossible for an incoming server. */
2407 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
2408 store_protocol = MODEST_PROTOCOLS_STORE_POP;
2410 store_protocol = store_provider_server_type;
2412 /* we check if there is a *special* port */
2413 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
2414 if (special_port != 0) {
2415 store_port = special_port;
2417 gboolean use_alternate_port = FALSE;
2418 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2420 use_alternate_port = TRUE;
2421 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
2424 modest_server_account_settings_set_security_protocol (store_settings,
2426 modest_server_account_settings_set_auth_protocol (store_settings,
2427 store_auth_protocol);
2428 if (store_port != 0)
2429 modest_server_account_settings_set_port (store_settings, store_port);
2431 /* Use custom pages because no preset was specified: */
2432 store_hostname = g_strdup (modest_entry_get_text (priv->entry_incomingserver ));
2433 store_protocol = modest_servertype_selector_get_active_servertype (
2434 priv->incoming_servertype_selector);
2436 modest_security_options_view_save_settings (
2437 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2441 /* now we store the common store account settings */
2442 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2443 modest_server_account_settings_set_username (store_settings, (alternate_username) ? alternate_username : username);
2444 modest_server_account_settings_set_password (store_settings, password);
2445 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2447 g_object_unref (store_settings);
2448 g_free (store_hostname);
2450 /* Outgoing server: */
2451 transport_hostname = NULL;
2452 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2453 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2454 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2458 ModestProtocolType transport_provider_server_type;
2459 ModestProtocolType transport_provider_security;
2463 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2464 FALSE /* transport */);
2466 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2468 FALSE /* transport */);
2469 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2471 FALSE /* transport */);
2473 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2474 transport_protocol = transport_provider_server_type;
2475 transport_security = transport_provider_security;
2476 is_secure = modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2477 transport_security);
2479 /* we check if there is a *special* port */
2480 special_port = modest_presets_get_port (priv->presets, provider_id,
2481 FALSE /* transport */);
2482 if (special_port != 0) {
2483 transport_port = special_port;
2485 gboolean use_alternate_port = FALSE;
2486 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL)
2487 use_alternate_port = TRUE;
2488 transport_port = get_port_from_protocol(transport_provider_server_type, use_alternate_port);
2492 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2494 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2496 modest_server_account_settings_set_security_protocol (transport_settings,
2497 transport_security);
2498 modest_server_account_settings_set_auth_protocol (transport_settings,
2499 transport_auth_protocol);
2500 if (transport_port != 0)
2501 modest_server_account_settings_set_port (transport_settings,
2504 ModestProtocolRegistry *registry;
2505 ModestProtocol *store_proto;
2507 registry = modest_runtime_get_protocol_registry ();
2508 /* Use custom pages because no preset was specified: */
2509 transport_hostname = g_strdup (modest_entry_get_text (priv->entry_outgoingserver ));
2511 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2514 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2515 /* fallback to SMTP if none was specified */
2516 g_warning ("No transport protocol was specified for store %d (%s)",
2517 modest_protocol_get_type_id (store_proto),
2518 modest_protocol_get_display_name (store_proto));
2519 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2522 modest_security_options_view_save_settings (
2523 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2527 /* now we store the common transport account settings */
2528 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2529 modest_server_account_settings_set_username (transport_settings, (alternate_username) ? alternate_username : username);
2530 modest_server_account_settings_set_password (transport_settings, password);
2531 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2533 g_object_unref (transport_settings);
2534 g_free (transport_hostname);
2535 if (alternate_username)
2536 g_free (alternate_username);
2538 fullname = modest_entry_get_text (priv->entry_user_name);
2539 email_address = modest_entry_get_text (priv->entry_user_email);
2540 modest_account_settings_set_fullname (priv->settings, fullname);
2541 modest_account_settings_set_email_address (priv->settings, email_address);
2542 /* we don't set retrieve type to preserve advanced settings if
2543 any. By default account settings are set to headers only */
2545 /* Save the connection-specific SMTP server accounts. */
2546 if (priv->checkbox_outgoing_smtp_specific) {
2547 modest_account_settings_set_use_connection_specific_smtp
2549 modest_togglable_get_active(priv->checkbox_outgoing_smtp_specific));
2552 display_name = get_entered_account_title (self);
2553 modest_account_settings_set_display_name (priv->settings, display_name);
2554 g_free (display_name);
2555 g_free (provider_id);
2557 /* This values are hardcoded for Fremantle */
2558 modest_account_settings_set_retrieve_type (priv->settings,
2559 MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS);
2560 modest_account_settings_set_retrieve_limit (priv->settings, 20);
2565 on_update_model (ModestWizardDialog *dialog)
2567 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2568 save_to_settings (self);
2573 on_save (ModestWizardDialog *dialog)
2575 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2576 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2579 save_to_settings (self);
2581 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2582 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2587 result = modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2588 #ifdef MODEST_TOOLKIT_HILDON2
2590 hildon_gtk_window_take_screenshot ((GtkWindow *) dialog, FALSE);
2599 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2601 GError *error = NULL;
2602 ModestProtocolType protocol_type;
2603 const gchar* hostname;
2604 const gchar* username;
2605 ModestProtocolType security_protocol_incoming_type;
2606 ModestProtocolRegistry *registry;
2608 GList *list_auth_methods;
2609 ModestEasysetupWizardDialogPrivate *priv;
2611 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2612 registry = modest_runtime_get_protocol_registry ();
2613 protocol_type = modest_servertype_selector_get_active_servertype (
2614 priv->incoming_servertype_selector);
2615 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2616 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2617 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2618 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2619 port_num = get_port_from_protocol(protocol_type, FALSE);
2620 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2621 username, GTK_WINDOW (self), &error);
2623 if (list_auth_methods) {
2624 /* TODO: Select the correct method */
2627 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2628 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2629 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2630 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2631 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2635 g_list_free(list_auth_methods);
2641 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2642 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2644 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2645 _("mcen_ib_unableto_discover_auth_methods"));
2649 g_error_free(error);
2655 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2657 GList* methods = check_for_supported_auth_methods(self);
2663 g_list_free(methods);
2668 check_support_show_progress (gpointer userdata)
2670 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2671 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2673 priv->check_support_show_progress_id = 0;
2675 if (priv->destroyed)
2678 #ifdef MODEST_TOOLKIT_HILDON2
2679 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
2686 check_support_progress_pulse (gpointer userdata)
2688 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2689 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2691 if (priv->destroyed || priv->check_support_progress == NULL) {
2692 priv->check_support_progress_pulse_id = 0;
2696 gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->check_support_progress));
2702 check_support_callback (ModestAccountProtocol *protocol,
2706 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2707 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2709 priv->pending_check_support --;
2711 if (priv->check_support_show_progress_id > 0) {
2712 g_source_remove (priv->check_support_show_progress_id);
2713 priv->check_support_show_progress_id = 0;
2716 if (priv->pending_check_support == 0) {
2717 priv->check_support_done = TRUE;
2719 if (priv->check_support_cancel_note) {
2720 gtk_widget_destroy (priv->check_support_cancel_note);
2721 priv->check_support_cancel_note = NULL;
2722 priv->check_support_progress = NULL;
2725 if (!priv->destroyed) {
2727 fill_providers (self);
2728 #ifdef MODEST_TOOLKIT_HILDON2
2729 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
2731 invoke_enable_buttons_vfunc (self);
2732 gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
2735 g_object_unref (self);
2738 #ifdef MODEST_TOOLKIT_HILDON2
2740 on_check_support_cancel (GtkDialog *cancel_note,
2742 ModestEasysetupWizardDialog *self)
2744 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2745 ModestProtocolRegistry *registry;
2746 GSList *provider_protos, *node;
2748 registry = modest_runtime_get_protocol_registry ();
2749 provider_protos = modest_protocol_registry_get_by_tag (registry,
2750 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2752 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2753 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2755 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2756 modest_protocol_get_type_id (proto),
2757 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2760 if (modest_protocol_registry_protocol_type_has_tag
2762 modest_protocol_get_type_id (proto),
2763 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2764 /* Check if there's already an account configured with this account type */
2765 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2766 modest_protocol_get_type_id (proto)))
2770 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2771 modest_account_protocol_cancel_check_support (MODEST_ACCOUNT_PROTOCOL (proto));
2774 g_slist_free (provider_protos);
2776 gtk_widget_destroy (GTK_WIDGET (cancel_note));
2777 priv->check_support_cancel_note = NULL;
2778 priv->check_support_progress = NULL;
2783 check_support_of_protocols (ModestEasysetupWizardDialog *self)
2785 ModestProtocolRegistry *registry;
2786 GSList *provider_protos, *node, *check_support_providers;
2787 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2789 registry = modest_runtime_get_protocol_registry ();
2790 provider_protos = modest_protocol_registry_get_by_tag (registry,
2791 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2793 check_support_providers = NULL;
2794 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2795 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2797 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2798 modest_protocol_get_type_id (proto),
2799 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2802 if (modest_protocol_registry_protocol_type_has_tag
2804 modest_protocol_get_type_id (proto),
2805 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2806 /* Check if there's already an account configured with this account type */
2807 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2808 modest_protocol_get_type_id (proto)))
2812 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2813 priv->pending_check_support ++;
2814 check_support_providers = g_slist_prepend (check_support_providers, proto);
2817 g_slist_free (provider_protos);
2819 for (node = check_support_providers; node != NULL; node = g_slist_next (node)) {
2820 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2822 modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
2823 check_support_callback,
2824 g_object_ref (self));
2826 g_slist_free (check_support_providers);
2828 if (priv->pending_check_support > 0) {
2829 priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
2830 check_support_show_progress,
2831 g_object_ref (self), g_object_unref);
2832 priv->check_support_progress_pulse_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 200,
2833 check_support_progress_pulse,
2834 g_object_ref (self), g_object_unref);
2835 priv->check_support_progress = gtk_progress_bar_new ();
2836 #ifdef MODEST_TOOLKIT_HILDON2
2837 priv->check_support_cancel_note = hildon_note_new_cancel_with_progress_bar (GTK_WINDOW (self),
2838 _("mcen_cn_availability_check"),
2839 GTK_PROGRESS_BAR (priv->check_support_progress));
2840 gtk_widget_show (priv->check_support_cancel_note);
2841 g_signal_connect (priv->check_support_cancel_note, "response", G_CALLBACK (on_check_support_cancel), self);
2844 priv->check_support_done = TRUE;
2846 fill_providers (self);
2848 invoke_enable_buttons_vfunc (self);