2 /* Copyright (c) 2006, Nokia Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the Nokia Corporation nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "modest-easysetup-wizard-dialog.h"
33 #include <glib/gi18n.h>
34 #include <gtk/gtknotebook.h>
35 #include <gtk/gtkvbox.h>
36 #include <gtk/gtklabel.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkseparator.h>
42 #include "modest-country-picker.h"
43 #include "modest-provider-picker.h"
44 #include "modest-servertype-picker.h"
45 #include "widgets/modest-validating-entry.h"
46 #include "modest-text-utils.h"
47 #include "modest-conf.h"
48 #include "modest-defs.h"
49 #include "modest-account-mgr.h"
50 #include "modest-signal-mgr.h"
51 #include "modest-account-mgr-helpers.h"
52 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "modest-connection-specific-smtp-window.h"
54 #include "widgets/modest-ui-constants.h"
55 #include "widgets/modest-default-account-settings-dialog.h"
56 #include "widgets/modest-easysetup-wizard-page.h"
57 #include "modest-maemo-utils.h"
58 #include "modest-utils.h"
59 #include "modest-hildon-includes.h"
60 #include "modest-maemo-security-options-view.h"
61 #include "modest-account-protocol.h"
62 #include "modest-address-book.h"
64 /* Include config.h so that _() works: */
69 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
71 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
72 MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
73 ModestEasysetupWizardDialogPrivate))
75 #define LABELS_WIDTH 520
76 #define DIALOG_WIDTH LABELS_WIDTH + MODEST_MARGIN_DOUBLE
78 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
82 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
83 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
84 } ModestEasysetupWizardDialogServerChanges;
86 struct _ModestEasysetupWizardDialogPrivate
88 ModestPresets *presets;
90 /* Remember what fields the user edited manually to not prefill them
92 ModestEasysetupWizardDialogServerChanges server_changes;
94 /* Check if the user changes a field to show a confirmation dialog */
97 /* If we have a pending load of settings or not. */
98 gboolean pending_load_settings;
100 /* Used by derived widgets to query existing accounts,
101 * and to create new accounts: */
102 ModestAccountMgr *account_manager;
103 ModestAccountSettings *settings;
105 /* notebook pages: */
106 GtkWidget *page_welcome;
107 gboolean check_support_done;
108 guint check_support_show_progress_id;
109 gint pending_check_support;
112 GtkWidget *page_account_details;
113 GtkWidget *account_country_picker;
114 GtkWidget *account_serviceprovider_picker;
115 GtkWidget *entry_account_title;
116 GtkWidget *caption_account_title;
118 GtkWidget *page_user_details;
119 GtkWidget *entry_user_name;
120 GtkWidget *entry_user_username;
121 GtkWidget *entry_user_password;
122 GtkWidget *entry_user_email;
124 GtkWidget *page_complete_easysetup;
126 GtkWidget *page_custom_incoming;
127 GtkWidget *incoming_servertype_picker;
128 GtkWidget *caption_incoming;
129 GtkWidget *entry_incomingserver;
131 /* Security widgets */
132 GtkWidget *incoming_security;
133 GtkWidget *outgoing_security;
135 GtkWidget *page_custom_outgoing;
136 GtkWidget *entry_outgoingserver;
137 GtkWidget *checkbox_outgoing_smtp_specific;
138 GtkWidget *button_outgoing_smtp_servers;
140 GtkWidget *page_complete_customsetup;
142 ModestProtocolType last_plugin_protocol_selected;
143 GSList *missing_data_signals;
146 static void save_to_settings (ModestEasysetupWizardDialog *self);
147 static void real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next);
148 static void on_update_model (ModestWizardDialog *dialog);
149 static gboolean on_save (ModestWizardDialog *dialog);
150 static GList* check_for_supported_auth_methods (ModestEasysetupWizardDialog* self);
151 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self);
152 static void check_support_callback (ModestAccountProtocol *protocol,
155 static void check_support_of_protocols (ModestEasysetupWizardDialog *self);
156 static gboolean check_support_show_progress (gpointer userdata);
159 on_delete_event (GtkWidget *widget,
161 ModestEasysetupWizardDialog *wizard)
163 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
168 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
170 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
171 g_return_if_fail (priv != NULL);
176 modest_easysetup_wizard_dialog_dispose (GObject *object)
178 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (object);
179 priv->destroyed = TRUE;
181 if (priv->check_support_show_progress_id > 0) {
182 g_source_remove (priv->check_support_show_progress_id);
183 priv->check_support_show_progress_id = 0;
186 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
187 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
191 modest_easysetup_wizard_dialog_finalize (GObject *object)
193 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
194 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
196 if (priv->account_manager)
197 g_object_unref (G_OBJECT (priv->account_manager));
200 modest_presets_destroy (priv->presets);
203 g_object_unref (priv->settings);
205 if (priv->missing_data_signals) {
206 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
207 priv->missing_data_signals = NULL;
210 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
214 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
217 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
219 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
222 get_port_from_protocol (ModestProtocolType server_type,
223 gboolean alternate_port)
226 ModestProtocol *protocol;
227 ModestProtocolRegistry *protocol_registry;
229 protocol_registry = modest_runtime_get_protocol_registry ();
230 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
232 if (alternate_port) {
233 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
235 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
241 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
243 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
245 /* Call the vfunc, which may be overridden by derived classes: */
246 if (klass->enable_buttons) {
247 GtkNotebook *notebook = NULL;
248 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
250 const gint current_page_num = gtk_notebook_get_current_page (notebook);
251 if (current_page_num == -1)
254 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
255 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
260 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
262 ModestEasysetupWizardDialog *self;
264 g_return_if_fail (user_data);
266 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
268 invoke_enable_buttons_vfunc(self);
272 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
274 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
276 invoke_enable_buttons_vfunc(self);
280 on_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
282 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
284 invoke_enable_buttons_vfunc(self);
288 on_serviceprovider_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
290 gchar* default_account_name_start;
291 gchar* default_account_name;
292 ModestEasysetupWizardDialog *self;
293 ModestEasysetupWizardDialogPrivate *priv;
294 ModestProviderPickerIdType provider_id_type;
295 ModestProtocol *protocol;
297 ModestProtocolType proto_type;
298 gboolean hide_account_title;
300 self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
301 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
303 on_picker_button_value_changed (widget, user_data);
305 provider_id_type = modest_provider_picker_get_active_id_type (
306 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
307 if (provider_id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
308 default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
312 selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (widget)));
313 default_account_name_start =
314 g_strdup (hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector)));
317 default_account_name = modest_account_mgr_get_unused_account_display_name (
318 priv->account_manager, default_account_name_start);
319 g_free (default_account_name_start);
320 default_account_name_start = NULL;
322 hide_account_title = FALSE;
323 proto_name = modest_provider_picker_get_active_provider_id (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
324 if (proto_name != NULL) {
325 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
326 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
328 if (protocol != NULL) {
329 proto_type = modest_protocol_get_type_id (protocol);
331 hide_account_title = (modest_protocol_registry_protocol_type_has_tag
332 (modest_runtime_get_protocol_registry (),
334 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS) ||
335 modest_protocol_registry_protocol_type_has_tag
336 (modest_runtime_get_protocol_registry (),
338 MODEST_PROTOCOL_REGISTRY_MULTI_MAILBOX_PROVIDER_PROTOCOLS));
342 if (hide_account_title)
343 gtk_widget_hide (priv->caption_account_title);
345 gtk_widget_show (priv->caption_account_title);
347 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
348 g_free (default_account_name);
351 /** This is a convenience function to create a caption containing a mandatory widget.
352 * When the widget is edited, the enable_buttons() vfunc will be called.
355 create_captioned (ModestEasysetupWizardDialog *self,
356 GtkSizeGroup *title_size_group,
357 GtkSizeGroup *value_size_group,
364 result = modest_maemo_utils_create_captioned_with_size_type (title_size_group, value_size_group,
365 value, use_markup, control,
366 MODEST_EDITABLE_SIZE);
368 /* Connect to the appropriate changed signal for the widget,
369 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
371 if (GTK_IS_ENTRY (control)) {
372 g_signal_connect (G_OBJECT (control), "changed",
373 G_CALLBACK (on_caption_entry_changed), self);
376 else if (GTK_IS_COMBO_BOX (control)) {
377 g_signal_connect (G_OBJECT (control), "changed",
378 G_CALLBACK (on_caption_combobox_changed), self);
385 create_page_welcome (ModestEasysetupWizardDialog *self)
391 ModestEasysetupWizardDialogPrivate *priv;
393 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
394 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
395 pannable = hildon_pannable_area_new ();
396 label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
397 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
398 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
399 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
400 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
401 /* So that it is not truncated: */
402 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
403 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
404 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
405 gtk_container_add (GTK_CONTAINER (align), box);
406 gtk_widget_show (label);
408 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
409 gtk_widget_show (GTK_WIDGET (box));
410 gtk_widget_show (GTK_WIDGET (align));
411 gtk_widget_show (pannable);
413 return GTK_WIDGET (pannable);
417 on_account_country_selector_changed (HildonTouchSelector *widget, gpointer user_data)
419 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
421 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
425 /* Fill the providers picker, based on the selected country: */
426 if (priv->presets != NULL) {
427 gint mcc = modest_country_picker_get_active_country_mcc (
428 MODEST_COUNTRY_PICKER (priv->account_country_picker));
429 modest_provider_picker_fill (
430 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
435 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
437 ModestEasysetupWizardDialogPrivate *priv;
438 gchar* provider_id = NULL, *with_at = NULL;
441 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
443 /* Fill the providers combo, based on the selected country: */
444 provider_id = modest_provider_picker_get_active_provider_id (
445 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
448 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
449 with_at = g_strdup_printf ("%c%s", '@', domain_name);
450 g_free (domain_name);
453 /* The sample address already contains the '@' */
455 with_at = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
457 if (priv->entry_user_email)
458 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), with_at);
461 g_free (provider_id);
465 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
467 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
469 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
473 update_user_email_from_provider (self);
477 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
479 modest_platform_information_banner (GTK_WIDGET (self), NULL,
480 _CS("ckdg_ib_maximum_characters_reached"));
484 create_page_account_details (ModestEasysetupWizardDialog *self)
487 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
488 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
489 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
491 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
492 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
493 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
494 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
495 gtk_widget_show (label);
497 /* Create a size group to be used by all captions.
498 * Note that HildonCaption does not create a default size group if we do not specify one.
499 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
500 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
501 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
503 /* The country widgets: */
504 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
505 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
506 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
507 _("mcen_fi_country"), priv->account_country_picker);
508 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
509 G_CALLBACK (on_picker_button_value_changed), self);
510 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
511 gtk_widget_show (priv->account_country_picker);
513 /* The service provider widgets: */
514 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
515 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
516 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
517 _("mcen_fi_serviceprovider"),
518 priv->account_serviceprovider_picker);
519 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
520 G_CALLBACK (on_serviceprovider_picker_button_value_changed), self);
521 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, 0);
522 gtk_widget_show (priv->account_serviceprovider_picker);
524 /* The description widgets: */
525 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
527 /* Do use auto-capitalization: */
528 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
529 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
531 /* Set a default account title, choosing one that does not already exist: */
532 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
533 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
534 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
535 priv->account_manager, default_account_name_start);
536 g_free (default_account_name_start);
537 default_account_name_start = NULL;
539 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
540 g_free (default_account_name);
541 default_account_name = NULL;
543 /* Connect signal after changing the text in the entry */
544 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
545 G_CALLBACK(on_easysetup_changed), self);
547 priv->caption_account_title = create_captioned (self, title_sizegroup, value_sizegroup,
548 _("mcen_fi_account_title"), FALSE,
549 priv->entry_account_title);
550 gtk_widget_show (priv->entry_account_title);
551 gtk_box_pack_start (GTK_BOX (box), priv->caption_account_title, FALSE, FALSE, 0);
552 gtk_widget_show (priv->caption_account_title);
553 gtk_widget_set_no_show_all (priv->caption_account_title, TRUE);
555 /* Prevent the use of some characters in the account title,
556 * as required by our UI specification: */
557 GList *list_prevent = NULL;
558 list_prevent = g_list_append (list_prevent, "\\");
559 list_prevent = g_list_append (list_prevent, "/");
560 list_prevent = g_list_append (list_prevent, ":");
561 list_prevent = g_list_append (list_prevent, "*");
562 list_prevent = g_list_append (list_prevent, "?");
563 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
564 list_prevent = g_list_append (list_prevent, "“");
565 list_prevent = g_list_append (list_prevent, "<");
566 list_prevent = g_list_append (list_prevent, ">");
567 list_prevent = g_list_append (list_prevent, "|");
568 list_prevent = g_list_append (list_prevent, "^");
569 modest_validating_entry_set_unallowed_characters (
570 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
571 g_list_free (list_prevent);
573 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
574 modest_utils_on_entry_invalid_character, self);
576 /* Set max length as in the UI spec:
577 * The UI spec seems to want us to show a dialog if we hit the maximum. */
578 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
579 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
582 gtk_widget_show (GTK_WIDGET (box));
584 g_object_unref (title_sizegroup);
585 g_object_unref (value_sizegroup);
587 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
588 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
589 gtk_widget_show (align);
590 gtk_container_add (GTK_CONTAINER (align), box);
592 return GTK_WIDGET (align);
596 on_user_username_changed(GtkWidget* widget, ModestEasysetupWizardDialog *self)
598 ModestEasysetupWizardDialogPrivate* priv;
599 gchar* provider_id = NULL;
601 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
603 /* Work out the user email address */
604 provider_id = modest_provider_picker_get_active_provider_id (
605 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
608 const gchar *current_username;
609 gchar *email_address;
610 gchar *domain_name = modest_presets_get_domain (priv->presets, provider_id);
612 current_username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
614 if (current_username && strstr (current_username, "@")) {
615 email_address = g_strdup (current_username);
617 email_address = g_strdup_printf ("%s@%s",
622 /* Update the email address */
623 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), email_address);
625 g_free (email_address);
626 g_free (domain_name);
627 g_free (provider_id);
631 on_easysetup_changed(widget, self);
636 create_page_user_details (ModestEasysetupWizardDialog *self)
638 GtkSizeGroup* title_sizegroup;
639 GtkSizeGroup* value_sizegroup;
641 ModestEasysetupWizardDialogPrivate *priv;
643 const gchar *my_name;
645 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
647 /* Create a size group to be used by all captions.
648 * Note that HildonCaption does not create a default size group if we do not specify one.
649 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
650 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
651 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
652 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
654 /* The name widgets: (use auto cap) */
655 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
656 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
657 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
659 /* Set max length as in the UI spec:
660 * The UI spec seems to want us to show a dialog if we hit the maximum. */
661 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
662 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
664 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
665 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
667 /* Try to initialize the user name with my own contact */
668 my_name = modest_address_book_get_my_name ();
670 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_name), my_name);
672 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
673 G_CALLBACK(on_easysetup_changed), self);
674 gtk_widget_show (priv->entry_user_name);
675 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
676 gtk_widget_show (caption);
678 /* Prevent the use of some characters in the name,
679 * as required by our UI specification: */
680 GList *list_prevent = NULL;
681 list_prevent = g_list_append (list_prevent, "<");
682 list_prevent = g_list_append (list_prevent, ">");
683 modest_validating_entry_set_unallowed_characters (
684 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
685 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
686 modest_utils_on_entry_invalid_character, self);
687 g_list_free (list_prevent);
689 /* The username widgets: */
690 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
691 /* Auto-capitalization is the default, so let's turn it off: */
692 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
693 HILDON_GTK_INPUT_MODE_FULL);
694 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
695 priv->entry_user_username);
696 gtk_widget_show (priv->entry_user_username);
697 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
698 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
699 G_CALLBACK(on_user_username_changed), self);
700 gtk_widget_show (caption);
702 /* Prevent the use of some characters in the username,
703 * as required by our UI specification: */
704 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
705 modest_utils_on_entry_invalid_character, self);
707 /* Set max length as in the UI spec:
708 * The UI spec seems to want us to show a dialog if we hit the maximum. */
709 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
710 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
713 /* The password widgets: */
714 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
715 /* Auto-capitalization is the default, so let's turn it off: */
716 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
717 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
718 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
719 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
720 caption = create_captioned (self, title_sizegroup, value_sizegroup,
721 _("mail_fi_password"), FALSE, priv->entry_user_password);
722 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
723 G_CALLBACK(on_easysetup_changed), self);
724 gtk_widget_show (priv->entry_user_password);
725 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
726 gtk_widget_show (caption);
728 /* The email address widgets: */
729 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
730 /* Auto-capitalization is the default, so let's turn it off: */
731 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
732 caption = create_captioned (self, title_sizegroup, value_sizegroup,
733 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
734 update_user_email_from_provider (self);
735 gtk_widget_show (priv->entry_user_email);
736 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
737 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
738 G_CALLBACK(on_easysetup_changed), self);
739 gtk_widget_show (caption);
741 /* Set max length as in the UI spec:
742 * The UI spec seems to want us to show a dialog if we hit the maximum. */
743 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
744 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
748 gtk_widget_show (GTK_WIDGET (box));
749 g_object_unref (title_sizegroup);
750 g_object_unref (value_sizegroup);
752 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
753 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
754 gtk_widget_show (align);
755 gtk_container_add (GTK_CONTAINER (align), box);
757 return GTK_WIDGET (align);
761 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
764 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
766 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
767 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
768 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
769 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
770 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
772 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
773 gtk_widget_show (label);
775 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
776 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
777 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
779 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
780 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 1.0);
781 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
782 gtk_widget_show (label);
784 gtk_widget_show (GTK_WIDGET (box));
786 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
787 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
788 gtk_widget_show (align);
789 gtk_container_add (GTK_CONTAINER (align), box);
791 return GTK_WIDGET (align);
794 /** Change the caption title for the incoming server,
795 * as specified in the UI spec:
798 update_incoming_server_title (ModestEasysetupWizardDialog *self)
800 ModestEasysetupWizardDialogPrivate* priv;
801 ModestProtocolType protocol_type;
802 ModestProtocolRegistry *protocol_registry;
804 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
805 protocol_registry = modest_runtime_get_protocol_registry ();
807 protocol_type = modest_servertype_picker_get_active_servertype (
808 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
810 /* This could happen when the combo box has still no active iter */
811 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
812 gchar* incomingserver_title;
813 const gchar *protocol_display_name;
814 ModestProtocol *protocol;
816 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
818 protocol_display_name = modest_protocol_get_display_name (protocol);
820 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
821 protocol_display_name, ")</small>", NULL);
823 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
825 g_free(incomingserver_title);
829 /** Change the caption title for the incoming server,
830 * as specified in the UI spec:
833 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
835 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
836 ModestServertypePicker *server_type_picker;
837 ModestProtocolType protocol_type;
838 ModestSecurityOptionsView *view;
841 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
843 modest_servertype_picker_get_active_servertype (server_type_picker);
845 /* Fill the combo with appropriately titled choices for all
847 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
848 modest_security_options_view_set_server_type (view, protocol_type);
852 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
854 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
855 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
860 update_incoming_server_title (self);
862 /* Update security options if needed */
863 update_incoming_server_security_choices (self);
864 gtk_widget_show (priv->incoming_security);
866 set_default_custom_servernames (self);
870 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
872 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
873 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
875 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
879 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
881 ModestProtocolRegistry *protocol_registry;
882 ModestEasysetupWizardDialogPrivate* priv;
887 GtkSizeGroup *title_sizegroup;
888 GtkSizeGroup *value_sizegroup;
890 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
891 protocol_registry = modest_runtime_get_protocol_registry ();
893 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
894 pannable = hildon_pannable_area_new ();
896 /* Show note that account type cannot be changed in future: */
897 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
898 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
899 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
900 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
901 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
902 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
903 gtk_widget_show (label);
905 /* Create a size group to be used by all captions.
906 * Note that HildonCaption does not create a default size group if we do not specify one.
907 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
908 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
909 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
911 /* The incoming server widgets: */
912 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
913 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
915 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
916 _("mcen_li_emailsetup_type"),
917 priv->incoming_servertype_picker);
918 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
919 G_CALLBACK (on_picker_button_value_changed), self);
920 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, 0);
921 gtk_widget_show (priv->incoming_servertype_picker);
923 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
925 /* Auto-capitalization is the default, so let's turn it off: */
926 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
927 set_default_custom_servernames (self);
929 /* The caption title will be updated in update_incoming_server_title().
930 * so this default text will never be seen: */
931 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
932 "This will be removed",
933 FALSE, priv->entry_incomingserver);
934 update_incoming_server_title (self);
935 gtk_widget_show (priv->entry_incomingserver);
936 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
937 gtk_widget_show (priv->caption_incoming);
939 /* Remember when the servername was changed manually: */
940 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
941 G_CALLBACK (on_entry_incoming_servername_changed), self);
943 /* The secure connection widgets. These are only valid for
944 protocols with security */
945 priv->incoming_security =
946 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
947 FALSE, title_sizegroup, value_sizegroup);
948 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
950 gtk_widget_show (priv->incoming_security);
952 /* Set default selection */
953 modest_servertype_picker_set_active_servertype (
954 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
955 MODEST_PROTOCOLS_STORE_POP);
956 update_incoming_server_title (self);
957 update_incoming_server_security_choices (self);
958 set_default_custom_servernames (self);
960 /* Change the caption title when the servertype changes,
961 * as in the UI spec: */
962 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
964 G_CALLBACK (on_servertype_selector_changed), self);
966 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
967 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
968 gtk_widget_show (align);
969 gtk_container_add (GTK_CONTAINER (align), box);
971 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
972 gtk_widget_show (GTK_WIDGET (box));
973 gtk_widget_show (pannable);
975 g_object_unref (title_sizegroup);
976 g_object_unref (value_sizegroup);
978 /* Connect changed signals. We do it here after initializing everything */
979 g_signal_connect (G_OBJECT(priv->entry_incomingserver), "changed",
980 G_CALLBACK(on_easysetup_changed), self);
983 return GTK_WIDGET (pannable);
987 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
989 GtkWidget *widget = GTK_WIDGET (user_data);
991 /* Enable the widget only if the check button is active: */
992 const gboolean enable = hildon_check_button_get_active (button);
993 gtk_widget_set_sensitive (widget, enable);
996 /* Make the sensitivity of a widget depend on a check button.
999 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
1001 g_signal_connect (G_OBJECT (button), "toggled",
1002 G_CALLBACK (on_check_button_changed), widget);
1004 /* Set the starting sensitivity: */
1005 on_check_button_changed (button, widget);
1009 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
1011 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1012 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1013 GtkWidget *specific_window;
1015 /* We set dirty here because setting it depending on the connection specific dialog
1019 /* Create the window, if necessary: */
1020 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
1021 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
1023 /* Show the window */
1024 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
1025 gtk_widget_show (specific_window);
1029 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
1031 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1032 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1033 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
1037 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
1039 ModestEasysetupWizardDialogPrivate *priv;
1040 gchar *smtp_caption_label;
1041 GtkWidget *pannable;
1043 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1045 pannable = hildon_pannable_area_new ();
1047 /* Create a size group to be used by all captions.
1048 * Note that HildonCaption does not create a default size group if we do not specify one.
1049 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1050 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1051 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1053 /* The outgoing server widgets: */
1054 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1055 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
1057 /* Auto-capitalization is the default, so let's turn it off: */
1058 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
1059 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
1060 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
1061 smtp_caption_label, TRUE, priv->entry_outgoingserver);
1062 g_free (smtp_caption_label);
1063 gtk_widget_show (priv->entry_outgoingserver);
1064 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
1065 gtk_widget_show (caption);
1066 set_default_custom_servernames (self);
1068 /* The secure connection widgets. These are only valid for
1069 protocols with security */
1070 priv->outgoing_security =
1071 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
1072 FALSE, title_sizegroup, value_sizegroup);
1073 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
1075 gtk_widget_show (priv->outgoing_security);
1077 GtkWidget *separator = gtk_hseparator_new ();
1078 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
1079 gtk_widget_show (separator);
1081 /* connection-specific checkbox: */
1082 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
1083 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1085 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1086 _("mcen_fi_advsetup_connection_smtp"));
1087 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1090 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1091 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
1094 /* Connection-specific SMTP-Severs Edit button: */
1095 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
1096 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
1097 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1098 gtk_widget_show (priv->button_outgoing_smtp_servers);
1099 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
1102 /* Only enable the button when the checkbox is checked: */
1103 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
1104 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
1106 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1107 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1109 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1110 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1113 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1114 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1115 gtk_widget_show (align);
1116 gtk_container_add (GTK_CONTAINER (align), box);
1118 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
1119 gtk_widget_show (GTK_WIDGET (box));
1120 gtk_widget_show (pannable);
1122 g_object_unref (title_sizegroup);
1123 g_object_unref (value_sizegroup);
1125 /* Connect changed signals. We do it here after initializing everything */
1126 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1127 G_CALLBACK (on_easysetup_changed), self);
1128 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1129 G_CALLBACK (on_easysetup_changed), self);
1131 return GTK_WIDGET (pannable);
1135 show_advanced_edit(gpointer user_data)
1137 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1138 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1141 /* Show the Account Settings window: */
1142 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
1143 if (priv->pending_load_settings) {
1144 save_to_settings (self);
1145 priv->pending_load_settings = FALSE;
1147 modest_account_settings_dialog_load_settings (dialog, priv->settings);
1149 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
1151 response = gtk_dialog_run (GTK_DIALOG (dialog));
1153 gtk_widget_destroy (GTK_WIDGET (dialog));
1155 return FALSE; /* Do not call this timeout callback again. */
1159 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1161 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1163 /* Show the Account Settings window: */
1164 show_advanced_edit(self);
1167 create_page_complete_custom (ModestEasysetupWizardDialog *self)
1169 gchar *complete_string;
1173 GtkWidget *button_edit;
1175 box = gtk_vbox_new (FALSE, MODEST_MARGIN_DEFAULT);
1176 complete_string = g_strconcat (_("mcen_ia_emailsetup_setup_complete"), " ",
1177 _("mcen_ia_customsetup_complete"), NULL);
1178 label = gtk_label_new(complete_string);
1179 g_free (complete_string);
1180 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1181 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
1182 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1183 gtk_misc_set_padding (GTK_MISC (label), MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE);
1184 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
1185 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
1186 gtk_widget_show (label);
1188 button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
1189 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
1190 gtk_widget_show (button_edit);
1191 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, 0);
1193 g_signal_connect (G_OBJECT (button_edit), "clicked",
1194 G_CALLBACK (on_button_edit_advanced_settings), self);
1196 gtk_widget_show (GTK_WIDGET (box));
1198 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1199 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, MODEST_MARGIN_DOUBLE, MODEST_MARGIN_DOUBLE, 0);
1200 gtk_widget_show (align);
1201 gtk_container_add (GTK_CONTAINER (align), box);
1203 return GTK_WIDGET (align);
1210 on_response (ModestWizardDialog *wizard_dialog,
1214 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1216 invoke_enable_buttons_vfunc (self);
1220 on_response_before (ModestWizardDialog *wizard_dialog,
1224 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1225 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1226 if (response_id == GTK_RESPONSE_CANCEL) {
1227 /* This is mostly copied from
1228 * src/maemo/modest-account-settings-dialog.c */
1230 gint dialog_response;
1233 dialog = hildon_note_new_confirmation ((GtkWindow *) self,
1234 _("imum_nc_wizard_confirm_lose_changes"));
1236 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
1237 (GtkWindow *) dialog,
1238 (GtkWindow *) wizard_dialog);
1240 dialog_response = gtk_dialog_run ((GtkDialog *) dialog);
1241 gtk_widget_destroy (GTK_WIDGET (dialog));
1243 if (dialog_response != GTK_RESPONSE_OK) {
1244 /* Don't let the dialog close */
1245 g_signal_stop_emission_by_name (wizard_dialog, "response");
1252 fill_providers (ModestEasysetupWizardDialog *self)
1254 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1256 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1257 /* gint mcc = get_default_country_code(); */
1259 /* Fill the combo in an idle call, as it takes a lot of time */
1260 modest_country_picker_load_data(
1261 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1262 /* connect to country picker's changed signal, so we can fill the provider picker: */
1263 g_signal_connect ((GObject *) priv->account_country_picker,
1265 G_CALLBACK (on_account_country_selector_changed), self);
1267 modest_country_picker_set_active_country_locale (
1268 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1269 mcc = modest_country_picker_get_active_country_mcc (
1270 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1271 modest_provider_picker_fill (
1272 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1273 priv->presets, mcc);
1274 /* connect to providers picker's changed signal, so we can fill the email address: */
1275 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1276 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1278 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1280 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1283 priv->dirty = FALSE;
1287 typedef struct IdleData {
1288 ModestEasysetupWizardDialog *dialog;
1289 ModestPresets *presets;
1293 presets_idle (gpointer userdata)
1295 IdleData *idle_data = (IdleData *) userdata;
1296 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1297 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1299 g_assert (idle_data->presets);
1301 gdk_threads_enter ();
1303 priv->presets = idle_data->presets;
1305 if (priv->check_support_done)
1306 fill_providers (self);
1308 g_object_unref (idle_data->dialog);
1311 gdk_threads_leave ();
1317 presets_loader (gpointer userdata)
1319 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1320 ModestPresets *presets = NULL;
1321 IdleData *idle_data;
1323 const gchar* path = NULL;
1324 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1325 const gchar* path2 = MODEST_FALLBACK_PROVIDER_DATA_FILE;
1327 if (access(path1, R_OK) == 0)
1329 else if (access(path2, R_OK) == 0)
1332 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1333 __FUNCTION__, path1, path2);
1337 presets = modest_presets_new (path);
1339 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1343 idle_data = g_new0 (IdleData, 1);
1344 idle_data->dialog = self;
1345 idle_data->presets = presets;
1347 g_idle_add (presets_idle, idle_data);
1353 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1359 /* Append page and set attributes */
1360 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1361 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1362 "tab-expand", TRUE, "tab-fill", TRUE,
1365 /* Give focus to page and show it */
1366 gtk_container_set_focus_child (GTK_CONTAINER (notebook), page);
1367 gtk_widget_show (page);
1371 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1373 priv->page_user_details = NULL;
1374 priv->entry_user_name = NULL;
1375 priv->entry_user_username = NULL;
1376 priv->entry_user_password = NULL;
1377 priv->entry_user_email = NULL;
1381 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1383 priv->page_custom_incoming = NULL;
1384 priv->incoming_servertype_picker = NULL;
1385 priv->caption_incoming = NULL;
1386 priv->entry_incomingserver = NULL;
1387 priv->entry_user_email = NULL;
1388 priv->incoming_security = NULL;
1392 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1394 priv->page_custom_outgoing = NULL;
1395 priv->entry_outgoingserver = NULL;
1396 priv->checkbox_outgoing_smtp_specific = NULL;
1397 priv->button_outgoing_smtp_servers = NULL;
1398 priv->outgoing_security = NULL;
1402 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1404 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1406 /* Create the notebook to be used by the ModestWizardDialog base class:
1407 * Each page of the notebook will be a page of the wizard: */
1408 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1409 gtk_widget_set_size_request (GTK_WIDGET (notebook), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1411 /* Set the notebook used by the ModestWizardDialog base class: */
1412 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1414 /* Set the wizard title:
1415 * The actual window title will be a combination of this and the page's tab label title. */
1416 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1418 /* Read in the information about known service providers: */
1419 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1421 /* The server fields did not have been manually changed yet */
1422 priv->server_changes = 0;
1423 priv->pending_load_settings = TRUE;
1425 /* Get the account manager object,
1426 * so we can check for existing accounts,
1427 * and create new accounts: */
1428 priv->account_manager = modest_runtime_get_account_mgr ();
1429 g_object_ref (priv->account_manager);
1431 /* Initialize fields */
1432 priv->check_support_done = FALSE;
1433 priv->check_support_show_progress_id = 0;
1434 priv->pending_check_support = 0;
1435 priv->destroyed = FALSE;
1436 priv->page_welcome = create_page_welcome (self);
1437 gtk_widget_show (priv->page_welcome);
1438 priv->page_account_details = create_page_account_details (self);
1440 init_user_page (priv);
1441 init_incoming_page (priv);
1442 init_outgoing_page (priv);
1444 priv->page_complete_easysetup = NULL;
1445 priv->page_complete_customsetup = NULL;
1446 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1447 priv->missing_data_signals = NULL;
1449 /* Add the common pages */
1450 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1451 _("mcen_ti_emailsetup_welcome"));
1452 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1453 _("mcen_ti_accountdetails"));
1455 /* Connect to the dialog's response signal so we can enable/disable buttons
1456 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1457 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1458 * so that we can be enable/disable after ModestWizardDialog has done its own
1459 * enabling/disabling of buttons.
1461 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1462 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1464 * It's not enough to connect to the notebook's switch-page signal, because
1465 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1466 * _after_ switching the page (understandably).
1467 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1468 * then gtk_notebook_get_current_page() would return an incorrect value.)
1470 g_signal_connect_after (G_OBJECT (self), "response",
1471 G_CALLBACK (on_response), self);
1473 /* This is to show a confirmation dialog when the user hits cancel */
1474 g_signal_connect (G_OBJECT (self), "response",
1475 G_CALLBACK (on_response_before), self);
1477 g_signal_connect (G_OBJECT (self), "delete-event",
1478 G_CALLBACK (on_delete_event), self);
1480 /* Reset dirty, because there was no user input until now */
1481 priv->dirty = FALSE;
1483 /* When this window is shown, hibernation should not be possible,
1484 * because there is no sensible way to save the state: */
1485 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1486 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1488 /* Load provider presets */
1489 g_object_ref (self);
1490 g_thread_create (presets_loader, self, FALSE, NULL);
1492 priv->settings = modest_account_settings_new ();
1496 ModestEasysetupWizardDialog*
1497 modest_easysetup_wizard_dialog_new (void)
1500 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1504 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1506 ModestEasysetupWizardDialogPrivate *priv;
1507 GtkNotebook *notebook = NULL;
1509 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1512 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1514 if (!priv->page_user_details) {
1515 priv->page_user_details = create_page_user_details (self);
1518 /* Create the custom pages: */
1519 if(!(priv->page_custom_incoming)) {
1520 priv->page_custom_incoming = create_page_custom_incoming (self);
1523 /* TODO: only if needed */
1524 if(!(priv->page_custom_outgoing)) {
1525 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1528 if(!(priv->page_complete_customsetup)) {
1529 priv->page_complete_customsetup = create_page_complete_custom (self);
1532 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1533 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1534 _("mcen_ti_emailsetup_userdetails"));
1536 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1537 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1538 _("mcen_ti_emailsetup_incomingdetails"));
1540 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1541 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1542 _("mcen_ti_emailsetup_outgoingdetails"));
1544 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1545 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1546 _("mcen_ti_emailsetup_complete"));
1548 /* This is unnecessary with GTK+ 2.10: */
1549 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1553 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1555 ModestEasysetupWizardDialogPrivate *priv;
1556 GtkNotebook *notebook = NULL;
1558 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1561 /* Create the easysetup-specific pages: */
1562 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1563 if(!priv->page_complete_easysetup)
1564 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1566 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1567 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1568 _("mcen_ti_emailsetup_complete"));
1570 /* This is unnecessary with GTK+ 2.10: */
1571 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1576 remove_non_common_tabs (ModestEasysetupWizardDialog *self,
1577 gboolean remove_user_details)
1580 GtkNotebook *notebook;
1581 ModestEasysetupWizardDialogPrivate *priv;
1583 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1584 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1586 /* The first 2 tabs are the common ones (welcome tab and the
1587 providers tab), so we always remove starting from the
1589 starting_tab = (remove_user_details) ? 2 : 3;
1590 while (gtk_notebook_get_n_pages (notebook) > starting_tab) {
1591 /* Disconnect signal */
1592 GtkWidget *page = gtk_notebook_get_nth_page (notebook, -1);
1593 if (modest_signal_mgr_is_connected (priv->missing_data_signals, (GObject *) page, "missing-mandatory-data")) {
1594 priv->missing_data_signals = modest_signal_mgr_disconnect (priv->missing_data_signals,
1596 "missing-mandatory-data");
1598 /* Remove page from notebook */
1599 gtk_notebook_remove_page (notebook, -1);
1604 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1608 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1611 /* After the user details page,
1612 * the following pages depend on whether "Other" was chosen
1613 * in the provider combobox on the account page
1616 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1618 ModestEasysetupWizardDialogPrivate *priv;
1619 ModestProviderPicker *picker;
1620 ModestProviderPickerIdType id_type;
1621 GtkNotebook *notebook;
1623 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1624 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1625 id_type = modest_provider_picker_get_active_id_type (picker);
1626 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1628 /* Remove the response override handler for non-plugin
1629 protocols. For plugins it'll be overriden later */
1630 if (id_type != MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL)
1631 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1635 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1636 /* "Other..." was selected: */
1638 /* If we come from a rollbacked easysetup */
1639 if (priv->page_complete_easysetup) {
1640 remove_non_common_tabs (self, FALSE);
1641 priv->page_complete_easysetup = NULL;
1644 /* If we come from a rollbacked plugin protocol setup */
1645 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1646 remove_non_common_tabs (self, TRUE);
1647 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1648 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1649 priv->missing_data_signals = NULL;
1652 create_subsequent_customsetup_pages (self);
1654 /* If we come from a rollbacked custom setup */
1655 if (priv->page_custom_incoming) {
1656 remove_non_common_tabs (self, TRUE);
1657 init_user_page (priv);
1658 init_incoming_page (priv);
1659 init_outgoing_page (priv);
1660 init_user_page (priv);
1661 priv->page_complete_customsetup = NULL;
1664 /* It's a pluggable protocol and not a provider with presets */
1665 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1666 ModestProtocol *protocol;
1668 ModestProtocolType proto_type;
1669 ModestWizardDialogResponseOverrideFunc response_override;
1671 /* Get protocol data */
1672 proto_name = modest_provider_picker_get_active_provider_id (picker);
1673 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1674 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1676 proto_type = modest_protocol_get_type_id (protocol);
1679 /* If we come from a rollbacked easy setup */
1680 if (priv->last_plugin_protocol_selected != proto_type &&
1681 priv->page_complete_easysetup) {
1682 remove_non_common_tabs (self, TRUE);
1683 init_user_page (priv);
1684 priv->page_complete_easysetup = NULL;
1687 /* Ensure that the response override handler
1688 is set. It might happen that plugins clear
1690 response_override = modest_account_protocol_get_wizard_response_override
1691 (MODEST_ACCOUNT_PROTOCOL (protocol));
1692 modest_wizard_dialog_set_response_override_handler (MODEST_WIZARD_DIALOG (self),
1695 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1696 proto_type != priv->last_plugin_protocol_selected) {
1697 ModestPairList *tabs;
1699 gboolean first_page = TRUE;
1701 /* Remember the last selected plugin protocol */
1702 priv->last_plugin_protocol_selected = proto_type;
1705 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1706 tmp = (GSList *) tabs;
1708 ModestPair *pair = (ModestPair *) tmp->data;
1709 modest_easysetup_wizard_dialog_append_page (notebook,
1710 GTK_WIDGET (pair->second),
1711 (const gchar *) pair->first);
1713 gtk_container_set_focus_child (GTK_CONTAINER (notebook),
1714 GTK_WIDGET (pair->second));
1718 /* Connect signals */
1719 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (pair->second)) {
1720 priv->missing_data_signals =
1721 modest_signal_mgr_connect (priv->missing_data_signals,
1722 G_OBJECT (pair->second),
1723 "missing-mandatory-data",
1724 G_CALLBACK (on_missing_mandatory_data),
1728 g_free (pair->first);
1729 tmp = g_slist_next (tmp);
1730 /* Critical: if you don't show the page then the dialog will ignore it */
1731 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1733 modest_pair_list_free (tabs);
1735 g_free (proto_name);
1737 if (priv->last_plugin_protocol_selected !=
1738 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1739 remove_non_common_tabs (self, TRUE);
1740 init_user_page (priv);
1741 priv->page_complete_easysetup = NULL;
1742 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1743 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1744 priv->missing_data_signals = NULL;
1746 if (!priv->page_user_details) {
1747 priv->page_user_details = create_page_user_details (self);
1748 modest_easysetup_wizard_dialog_append_page (notebook,
1749 priv->page_user_details,
1750 _("mcen_ti_emailsetup_userdetails"));
1754 /* Create the easysetup pages: */
1755 create_subsequent_easysetup_pages (self);
1761 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1763 const gchar* hostname = NULL;
1766 ModestProtocolRegistry *protocol_registry;
1767 ModestProtocol *protocol;
1772 at = g_utf8_strchr (email_address, -1, '@');
1773 if (!at || (g_utf8_strlen (at, -1) < 2))
1776 domain = g_utf8_next_char (at);
1780 protocol_registry = modest_runtime_get_protocol_registry ();
1781 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1783 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1784 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1785 hostname = modest_protocol_get_name (protocol);
1791 return g_strdup_printf ("%s.%s", hostname, domain);
1795 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1797 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1799 if (!priv->entry_incomingserver)
1802 /* Set a default domain for the server, based on the email address,
1803 * if no server name was already specified.
1805 if (priv->entry_user_email
1806 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1807 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1808 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1810 /* This could happen when the combo box has still no active iter */
1811 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1812 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1813 gchar* servername = util_get_default_servername_from_email_address (email_address,
1816 /* Do not set the INCOMING_CHANGED flag because of this edit */
1817 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1818 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1819 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1821 g_free (servername);
1825 /* Set a default domain for the server, based on the email address,
1826 * if no server name was already specified.
1828 if (!priv->entry_outgoingserver)
1831 if (priv->entry_user_email
1832 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1833 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1835 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1837 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1838 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1839 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1840 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1842 g_free (servername);
1847 get_entered_account_title (ModestEasysetupWizardDialog *self)
1849 ModestEasysetupWizardDialogPrivate *priv;
1850 const gchar* account_title;
1852 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1853 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1855 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1858 /* Strip it of whitespace at the start and end: */
1859 gchar *result = g_strdup (account_title);
1860 result = g_strstrip (result);
1865 if (g_utf8_strlen (result, -1) == 0) {
1875 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1877 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1878 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1879 ModestProtocolRegistry *protocol_registry;
1881 protocol_registry = modest_runtime_get_protocol_registry ();
1883 /* if are browsing pages previous to the last one, then we have pending settings in
1885 if (next_page != NULL)
1886 priv->pending_load_settings = TRUE;
1888 /* Do extra validation that couldn't be done for every key press,
1889 * either because it was too slow,
1890 * or because it requires interaction:
1892 if (current_page == priv->page_welcome) {
1893 if (!priv->check_support_done) {
1894 check_support_of_protocols (self);
1895 return priv->check_support_done;
1897 } else if (current_page == priv->page_account_details) {
1898 /* Check that the title is not already in use: */
1899 gchar* account_title = get_entered_account_title (self);
1903 /* Aavoid a clash with an existing display name: */
1904 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1905 priv->account_manager, account_title);
1906 g_free (account_title);
1909 /* Warn the user via a dialog: */
1910 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1915 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1916 create_subsequent_pages (self);
1918 } else if (current_page == priv->page_user_details) {
1919 /* Check that the email address is valud: */
1920 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1921 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1924 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1925 /* Warn the user via a dialog: */
1926 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1928 /* Return focus to the email address entry: */
1929 gtk_widget_grab_focus (priv->entry_user_email);
1930 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1934 } else if (current_page == priv->page_custom_incoming ||
1935 current_page == priv->page_custom_outgoing) {
1937 const gchar *hostname;
1938 GtkWidget *entry = (current_page == priv->page_custom_incoming) ?
1939 priv->entry_incomingserver :
1940 priv->entry_outgoingserver;
1942 hostname = gtk_entry_get_text (GTK_ENTRY (entry));
1943 if (!modest_text_utils_validate_domain_name (hostname)) {
1945 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
1947 /* Return focus to the email address entry: */
1948 gtk_widget_grab_focus (entry);
1949 gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
1955 if (next_page == priv->page_custom_incoming) {
1956 set_default_custom_servernames (self);
1957 } else if (next_page == priv->page_custom_outgoing) {
1958 set_default_custom_servernames (self);
1960 /* Check if the server supports secure authentication */
1961 if (modest_security_options_view_auth_check (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security)))
1962 if (!check_has_supported_auth_methods (self))
1964 gtk_widget_show (priv->outgoing_security);
1967 /* If this is the last page, and this is a click on Finish,
1968 * then attempt to create the dialog.
1971 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1973 if (priv->pending_load_settings) {
1974 save_to_settings (self);
1977 /* We check if there's already another account with the same configuration */
1978 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1979 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1983 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1990 static gboolean entry_is_empty (GtkWidget *entry)
1995 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1996 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1999 /* Strip it of whitespace at the start and end: */
2000 gchar *stripped = g_strdup (text);
2001 stripped = g_strstrip (stripped);
2006 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
2014 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
2016 GtkNotebook *notebook = NULL;
2017 gboolean is_finish_tab;
2019 ModestEasysetupWizardDialogPrivate *priv;
2022 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
2023 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
2025 /* Disable the Finish button until we are on the last page,
2026 * because HildonWizardDialog enables this for all but the
2028 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
2029 is_finish_tab = ((current == priv->page_complete_easysetup) ||
2030 (current == priv->page_complete_customsetup));
2032 if (is_finish_tab) {
2033 /* Disable Next on the last page no matter what the
2035 enable_next = FALSE;
2037 /* Not the last one */
2038 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2039 MODEST_WIZARD_DIALOG_FINISH,
2042 /* If the check support is not done then do not enable
2043 the wizard to continue */
2044 enable_next = enable_next && priv->pending_check_support == 0;
2047 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
2048 MODEST_WIZARD_DIALOG_NEXT,
2053 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
2055 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2056 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2058 gboolean enable_next = TRUE;
2059 if (current_page == priv->page_welcome) {
2061 } else if (current_page == priv->page_account_details) {
2062 /* The account details title is mandatory: */
2063 if (entry_is_empty(priv->entry_account_title))
2064 enable_next = FALSE;
2065 } else if (current_page == priv->page_user_details) {
2066 /* The user details username is mandatory: */
2067 if (entry_is_empty(priv->entry_user_username))
2068 enable_next = FALSE;
2070 /* The user details email address is mandatory: */
2071 if (enable_next && entry_is_empty (priv->entry_user_email))
2072 enable_next = FALSE;
2073 } else if (current_page == priv->page_custom_incoming) {
2074 /* The custom incoming server is mandatory: */
2075 if (entry_is_empty(priv->entry_incomingserver))
2076 enable_next = FALSE;
2077 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
2078 enable_next = !modest_easysetup_wizard_page_validate (
2079 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
2082 /* Enable/disable buttons */
2083 real_enable_buttons (dialog, enable_next);
2087 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
2089 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2090 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
2093 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
2094 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
2096 /* Provide a vfunc implementation so we can decide
2097 * when to enable/disable the prev/next buttons.
2099 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
2100 base_klass->before_next = on_before_next;
2101 base_klass->enable_buttons = on_enable_buttons;
2102 base_klass->update_model = on_update_model;
2103 base_klass->save = on_save;
2108 * @self: a #ModestEasysetupWizardDialog
2110 * takes information from all the wizard and stores it in settings
2113 save_to_settings (ModestEasysetupWizardDialog *self)
2115 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2117 gchar *provider_id = NULL;
2118 gchar* display_name;
2119 const gchar *username, *password;
2120 gchar *store_hostname, *transport_hostname;
2121 guint store_port, transport_port;
2122 ModestProtocolRegistry *protocol_registry;
2123 ModestProtocolType store_protocol, transport_protocol;
2124 ModestProtocolType store_security, transport_security;
2125 ModestProtocolType store_auth_protocol, transport_auth_protocol;
2126 ModestServerAccountSettings *store_settings, *transport_settings;
2127 const gchar *fullname, *email_address;
2128 ModestProviderPicker *picker;
2129 ModestProviderPickerIdType id_type;
2131 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2132 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
2133 protocol_registry = modest_runtime_get_protocol_registry ();
2135 /* Get details from the specified presets: */
2136 id_type = modest_provider_picker_get_active_id_type (picker);
2137 provider_id = modest_provider_picker_get_active_provider_id (picker);
2139 /* Let the plugin save the settings. We do a return in order
2140 to save an indentation level */
2141 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
2142 ModestProtocol *protocol;
2144 protocol = modest_protocol_registry_get_protocol_by_name (
2145 modest_runtime_get_protocol_registry (),
2146 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
2149 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
2150 gint n_pages, i = 0;
2151 GtkNotebook *notebook;
2152 GList *wizard_pages = NULL;
2154 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
2155 n_pages = gtk_notebook_get_n_pages (notebook);
2156 for (i = 0; i < n_pages; i++) {
2157 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
2158 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
2159 wizard_pages = g_list_append (wizard_pages, page);
2161 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
2164 g_list_free (wizard_pages);
2166 g_debug ("The selected protocol is a plugin protocol "//
2167 "but it's not a ModestAccountProtocol");
2170 g_free (provider_id);
2174 /* username and password (for both incoming and outgoing): */
2175 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
2176 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
2178 store_settings = modest_account_settings_get_store_settings (priv->settings);
2179 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
2181 /* Incoming server: */
2182 /* Note: We need something as default for the transport store protocol values,
2183 * or modest_account_mgr_add_server_account will fail. */
2185 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2186 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2187 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2190 ModestProtocolType store_provider_server_type;
2191 gboolean store_provider_use_alternate_port;
2193 store_hostname = modest_presets_get_server (priv->presets, provider_id,
2196 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2199 store_security = modest_presets_get_info_server_security (priv->presets,
2202 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
2205 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
2209 /* We don't check for SMTP here as that is impossible for an incoming server. */
2210 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
2211 store_protocol = MODEST_PROTOCOLS_STORE_POP;
2213 store_protocol = store_provider_server_type;
2215 /* we check if there is a *special* port */
2216 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
2217 if (special_port != 0) {
2218 store_port = special_port;
2220 gboolean use_alternate_port = FALSE;
2221 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2223 use_alternate_port = TRUE;
2224 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
2227 modest_server_account_settings_set_security_protocol (store_settings,
2229 modest_server_account_settings_set_auth_protocol (store_settings,
2230 store_auth_protocol);
2231 if (store_port != 0)
2232 modest_server_account_settings_set_port (store_settings, store_port);
2234 /* Use custom pages because no preset was specified: */
2235 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
2236 store_protocol = modest_servertype_picker_get_active_servertype (
2237 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2239 modest_security_options_view_save_settings (
2240 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
2244 /* now we store the common store account settings */
2245 modest_server_account_settings_set_hostname (store_settings, store_hostname);
2246 modest_server_account_settings_set_username (store_settings, username);
2247 modest_server_account_settings_set_password (store_settings, password);
2248 modest_server_account_settings_set_protocol (store_settings, store_protocol);
2250 g_object_unref (store_settings);
2251 g_free (store_hostname);
2253 /* Outgoing server: */
2254 transport_hostname = NULL;
2255 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
2256 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
2257 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2261 ModestProtocolType transport_provider_server_type;
2262 ModestProtocolType transport_provider_security;
2266 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
2267 FALSE /* transport */);
2269 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
2271 FALSE /* transport */);
2272 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
2274 FALSE /* transport */);
2276 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
2277 transport_protocol = transport_provider_server_type;
2278 transport_security = transport_provider_security;
2279 is_secure = modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
2280 transport_security);
2282 /* we check if there is a *special* port */
2283 special_port = modest_presets_get_port (priv->presets, provider_id,
2284 FALSE /* transport */);
2285 if (special_port != 0) {
2286 transport_port = special_port;
2288 gboolean use_alternate_port = FALSE;
2289 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL)
2290 use_alternate_port = TRUE;
2291 transport_port = get_port_from_protocol(transport_provider_server_type, use_alternate_port);
2295 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
2297 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
2299 modest_server_account_settings_set_security_protocol (transport_settings,
2300 transport_security);
2301 modest_server_account_settings_set_auth_protocol (transport_settings,
2302 transport_auth_protocol);
2303 if (transport_port != 0)
2304 modest_server_account_settings_set_port (transport_settings,
2307 ModestProtocolRegistry *registry;
2308 ModestProtocol *store_proto;
2310 registry = modest_runtime_get_protocol_registry ();
2311 /* Use custom pages because no preset was specified: */
2312 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2314 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2317 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2318 /* fallback to SMTP if none was specified */
2319 g_warning ("No transport protocol was specified for store %d (%s)",
2320 modest_protocol_get_type_id (store_proto),
2321 modest_protocol_get_display_name (store_proto));
2322 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2325 modest_security_options_view_save_settings (
2326 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2330 /* now we store the common transport account settings */
2331 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2332 modest_server_account_settings_set_username (transport_settings, username);
2333 modest_server_account_settings_set_password (transport_settings, password);
2334 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2336 g_object_unref (transport_settings);
2337 g_free (transport_hostname);
2339 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2340 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2341 modest_account_settings_set_fullname (priv->settings, fullname);
2342 modest_account_settings_set_email_address (priv->settings, email_address);
2343 /* we don't set retrieve type to preserve advanced settings if
2344 any. By default account settings are set to headers only */
2346 /* Save the connection-specific SMTP server accounts. */
2347 if (priv->checkbox_outgoing_smtp_specific) {
2348 modest_account_settings_set_use_connection_specific_smtp
2350 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2353 display_name = get_entered_account_title (self);
2354 modest_account_settings_set_display_name (priv->settings, display_name);
2355 g_free (display_name);
2356 g_free (provider_id);
2358 /* This values are hardcoded for Fremantle */
2359 modest_account_settings_set_retrieve_type (priv->settings,
2360 MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS);
2361 modest_account_settings_set_retrieve_limit (priv->settings, 20);
2366 on_update_model (ModestWizardDialog *dialog)
2368 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2369 save_to_settings (self);
2374 on_save (ModestWizardDialog *dialog)
2376 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
2377 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2379 save_to_settings (self);
2381 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
2382 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
2386 return modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
2392 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
2394 GError *error = NULL;
2395 ModestProtocolType protocol_type;
2396 const gchar* hostname;
2397 const gchar* username;
2398 ModestProtocolType security_protocol_incoming_type;
2399 ModestProtocolRegistry *registry;
2401 GList *list_auth_methods;
2402 ModestEasysetupWizardDialogPrivate *priv;
2404 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2405 registry = modest_runtime_get_protocol_registry ();
2406 protocol_type = modest_servertype_picker_get_active_servertype (
2407 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
2408 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
2409 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
2410 security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
2411 (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security));
2412 port_num = get_port_from_protocol(protocol_type, FALSE);
2413 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol_type, hostname, port_num,
2414 username, GTK_WINDOW (self), &error);
2416 if (list_auth_methods) {
2417 /* TODO: Select the correct method */
2420 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
2421 ModestProtocolType auth_protocol_type = (ModestProtocolType) (GPOINTER_TO_INT(method->data));
2422 if (modest_protocol_registry_protocol_type_has_tag (registry, auth_protocol_type,
2423 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS)) {
2424 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
2428 g_list_free(list_auth_methods);
2434 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
2435 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
2437 modest_platform_information_banner (GTK_WIDGET(self), NULL,
2438 _("mcen_ib_unableto_discover_auth_methods"));
2442 g_error_free(error);
2448 check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
2450 GList* methods = check_for_supported_auth_methods(self);
2456 g_list_free(methods);
2461 check_support_show_progress (gpointer userdata)
2463 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2464 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2466 priv->check_support_show_progress_id = 0;
2468 if (priv->destroyed)
2471 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), TRUE);
2477 check_support_callback (ModestAccountProtocol *protocol,
2481 ModestEasysetupWizardDialog *self = (ModestEasysetupWizardDialog *) userdata;
2482 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2484 priv->pending_check_support --;
2486 if (priv->check_support_show_progress_id > 0) {
2487 g_source_remove (priv->check_support_show_progress_id);
2488 priv->check_support_show_progress_id = 0;
2491 if (priv->pending_check_support == 0) {
2492 priv->check_support_done = TRUE;
2494 if (!priv->destroyed) {
2496 fill_providers (self);
2497 hildon_gtk_window_set_progress_indicator (GTK_WINDOW (self), FALSE);
2498 invoke_enable_buttons_vfunc (self);
2499 gtk_dialog_response (GTK_DIALOG (self), MODEST_WIZARD_DIALOG_NEXT);
2502 g_object_unref (self);
2507 check_support_of_protocols (ModestEasysetupWizardDialog *self)
2509 ModestProtocolRegistry *registry;
2510 GSList *provider_protos, *node;
2511 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
2513 registry = modest_runtime_get_protocol_registry ();
2514 provider_protos = modest_protocol_registry_get_by_tag (registry,
2515 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS);
2517 for (node = provider_protos; node != NULL; node = g_slist_next (node)) {
2518 ModestProtocol *proto = MODEST_PROTOCOL (node->data);
2520 if (!modest_protocol_registry_protocol_type_has_tag (registry,
2521 modest_protocol_get_type_id (proto),
2522 MODEST_PROTOCOL_REGISTRY_STORE_PROTOCOLS))
2525 if (modest_protocol_registry_protocol_type_has_tag
2527 modest_protocol_get_type_id (proto),
2528 MODEST_PROTOCOL_REGISTRY_SINGLETON_PROVIDER_PROTOCOLS)) {
2529 /* Check if there's already an account configured with this account type */
2530 if (modest_account_mgr_singleton_protocol_exists (modest_runtime_get_account_mgr (),
2531 modest_protocol_get_type_id (proto)))
2535 if (MODEST_ACCOUNT_PROTOCOL (proto)) {
2536 priv->pending_check_support ++;
2537 modest_account_protocol_check_support (MODEST_ACCOUNT_PROTOCOL (proto),
2538 check_support_callback,
2539 g_object_ref (self));
2542 g_slist_free (provider_protos);
2544 if (priv->pending_check_support > 0) {
2545 priv->check_support_show_progress_id = g_timeout_add_full (G_PRIORITY_DEFAULT, 1000,
2546 check_support_show_progress,
2547 g_object_ref (self), g_object_unref);
2549 priv->check_support_done = TRUE;
2551 invoke_enable_buttons_vfunc (self);