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"
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 480
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;
107 GtkWidget *page_account_details;
108 GtkWidget *account_country_picker;
109 GtkWidget *account_serviceprovider_picker;
110 GtkWidget *entry_account_title;
112 GtkWidget *page_user_details;
113 GtkWidget *entry_user_name;
114 GtkWidget *entry_user_username;
115 GtkWidget *entry_user_password;
116 GtkWidget *entry_user_email;
118 GtkWidget *page_complete_easysetup;
120 GtkWidget *page_custom_incoming;
121 GtkWidget *incoming_servertype_picker;
122 GtkWidget *caption_incoming;
123 GtkWidget *entry_incomingserver;
125 /* Security widgets */
126 GtkWidget *incoming_security;
127 GtkWidget *outgoing_security;
129 GtkWidget *page_custom_outgoing;
130 GtkWidget *entry_outgoingserver;
131 GtkWidget *checkbox_outgoing_smtp_specific;
132 GtkWidget *button_outgoing_smtp_servers;
134 GtkWidget *page_complete_customsetup;
136 ModestProtocolType last_plugin_protocol_selected;
137 GSList *missing_data_signals;
140 static void save_to_settings (ModestEasysetupWizardDialog *self);
141 static void real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next);
144 on_delete_event (GtkWidget *widget,
146 ModestEasysetupWizardDialog *wizard)
148 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
153 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
155 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
156 g_return_if_fail (priv != NULL);
161 modest_easysetup_wizard_dialog_dispose (GObject *object)
163 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
164 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
168 modest_easysetup_wizard_dialog_finalize (GObject *object)
170 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
171 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
173 if (priv->account_manager)
174 g_object_unref (G_OBJECT (priv->account_manager));
177 modest_presets_destroy (priv->presets);
180 g_object_unref (priv->settings);
182 if (priv->missing_data_signals) {
183 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
184 priv->missing_data_signals = NULL;
187 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
191 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
194 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
196 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
199 get_port_from_protocol (ModestProtocolType server_type,
200 gboolean alternate_port)
203 ModestProtocol *protocol;
204 ModestProtocolRegistry *protocol_registry;
206 protocol_registry = modest_runtime_get_protocol_registry ();
207 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
209 if (alternate_port) {
210 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
212 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
218 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
220 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
222 /* Call the vfunc, which may be overridden by derived classes: */
223 if (klass->enable_buttons) {
224 GtkNotebook *notebook = NULL;
225 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
227 const gint current_page_num = gtk_notebook_get_current_page (notebook);
228 if (current_page_num == -1)
231 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
232 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
237 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
239 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
241 invoke_enable_buttons_vfunc(self);
245 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
247 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
249 invoke_enable_buttons_vfunc(self);
253 on_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
255 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
257 invoke_enable_buttons_vfunc(self);
260 /** This is a convenience function to create a caption containing a mandatory widget.
261 * When the widget is edited, the enable_buttons() vfunc will be called.
264 create_captioned (ModestEasysetupWizardDialog *self,
265 GtkSizeGroup *title_size_group,
266 GtkSizeGroup *value_size_group,
273 result = modest_maemo_utils_create_captioned (title_size_group, value_size_group,
274 value, use_markup, control);
276 /* Connect to the appropriate changed signal for the widget,
277 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
279 if (GTK_IS_ENTRY (control)) {
280 g_signal_connect (G_OBJECT (control), "changed",
281 G_CALLBACK (on_caption_entry_changed), self);
284 else if (GTK_IS_COMBO_BOX (control)) {
285 g_signal_connect (G_OBJECT (control), "changed",
286 G_CALLBACK (on_caption_combobox_changed), self);
293 create_page_welcome (ModestEasysetupWizardDialog *self)
295 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
296 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
297 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
298 /* So that it is not truncated: */
299 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
300 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
301 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
302 gtk_widget_show (label);
303 gtk_widget_show (GTK_WIDGET (box));
304 return GTK_WIDGET (box);
308 on_account_country_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
310 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
312 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
316 /* Fill the providers picker, based on the selected country: */
317 if (priv->presets != NULL) {
318 gint mcc = modest_country_picker_get_active_country_mcc (
319 MODEST_COUNTRY_PICKER (priv->account_country_picker));
320 modest_provider_picker_fill (
321 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
326 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
328 ModestEasysetupWizardDialogPrivate *priv;
330 gchar* domain_name = NULL;
333 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
335 /* Fill the providers combo, based on the selected country: */
336 provider_id = modest_provider_picker_get_active_provider_id (
337 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
340 domain_name = modest_presets_get_domain (priv->presets, provider_id);
343 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
345 if (priv->entry_user_email)
346 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), domain_name);
348 g_free (domain_name);
350 g_free (provider_id);
354 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
356 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
358 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
362 update_user_email_from_provider (self);
366 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
368 modest_platform_information_banner (GTK_WIDGET (self), NULL,
369 _CS("ckdg_ib_maximum_characters_reached"));
373 create_page_account_details (ModestEasysetupWizardDialog *self)
376 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
377 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
378 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
380 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
381 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
382 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
383 gtk_widget_show (label);
385 /* Create a size group to be used by all captions.
386 * Note that HildonCaption does not create a default size group if we do not specify one.
387 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
388 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
389 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
391 /* The country widgets: */
392 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
393 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
394 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
395 _("mcen_fi_country"), priv->account_country_picker);
396 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
397 G_CALLBACK (on_picker_button_value_changed), self);
398 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
399 gtk_widget_show (priv->account_country_picker);
401 GtkWidget *separator = gtk_hseparator_new ();
402 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
403 gtk_widget_show (separator);
405 /* The service provider widgets: */
406 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
407 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
408 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
409 _("mcen_fi_serviceprovider"),
410 priv->account_serviceprovider_picker);
411 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
412 G_CALLBACK (on_picker_button_value_changed), self);
413 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
414 gtk_widget_show (priv->account_serviceprovider_picker);
416 /* The description widgets: */
417 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
418 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
419 G_CALLBACK(on_easysetup_changed), self);
420 /* Do use auto-capitalization: */
421 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
422 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
424 /* Set a default account title, choosing one that does not already exist: */
425 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
426 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
427 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
428 priv->account_manager, default_account_name_start);
429 g_free (default_account_name_start);
430 default_account_name_start = NULL;
432 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
433 g_free (default_account_name);
434 default_account_name = NULL;
436 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mcen_fi_account_title"), FALSE,
437 priv->entry_account_title);
438 gtk_widget_show (priv->entry_account_title);
439 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
440 gtk_widget_show (caption);
442 /* Prevent the use of some characters in the account title,
443 * as required by our UI specification: */
444 GList *list_prevent = NULL;
445 list_prevent = g_list_append (list_prevent, "\\");
446 list_prevent = g_list_append (list_prevent, "/");
447 list_prevent = g_list_append (list_prevent, ":");
448 list_prevent = g_list_append (list_prevent, "*");
449 list_prevent = g_list_append (list_prevent, "?");
450 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
451 list_prevent = g_list_append (list_prevent, "“");
452 list_prevent = g_list_append (list_prevent, "<");
453 list_prevent = g_list_append (list_prevent, ">");
454 list_prevent = g_list_append (list_prevent, "|");
455 list_prevent = g_list_append (list_prevent, "^");
456 modest_validating_entry_set_unallowed_characters (
457 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
458 g_list_free (list_prevent);
460 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
461 modest_utils_on_entry_invalid_character, self);
463 /* Set max length as in the UI spec:
464 * The UI spec seems to want us to show a dialog if we hit the maximum. */
465 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
466 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
469 gtk_widget_show (GTK_WIDGET (box));
471 g_object_unref (title_sizegroup);
472 g_object_unref (value_sizegroup);
474 return GTK_WIDGET (box);
478 create_page_user_details (ModestEasysetupWizardDialog *self)
480 GtkSizeGroup* title_sizegroup;
481 GtkSizeGroup* value_sizegroup;
483 ModestEasysetupWizardDialogPrivate *priv;
485 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
487 /* Create a size group to be used by all captions.
488 * Note that HildonCaption does not create a default size group if we do not specify one.
489 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
490 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
491 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
492 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
494 /* The name widgets: (use auto cap) */
495 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
496 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
497 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
499 /* Set max length as in the UI spec:
500 * The UI spec seems to want us to show a dialog if we hit the maximum. */
501 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
502 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
504 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
505 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
506 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
507 G_CALLBACK(on_easysetup_changed), self);
508 gtk_widget_show (priv->entry_user_name);
509 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
510 gtk_widget_show (caption);
512 /* Prevent the use of some characters in the name,
513 * as required by our UI specification: */
514 GList *list_prevent = NULL;
515 list_prevent = g_list_append (list_prevent, "<");
516 list_prevent = g_list_append (list_prevent, ">");
517 modest_validating_entry_set_unallowed_characters (
518 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
519 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
520 modest_utils_on_entry_invalid_character, self);
521 g_list_free (list_prevent);
523 /* The username widgets: */
524 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
525 /* Auto-capitalization is the default, so let's turn it off: */
526 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
527 HILDON_GTK_INPUT_MODE_FULL);
528 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"), FALSE,
529 priv->entry_user_username);
530 gtk_widget_show (priv->entry_user_username);
531 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
532 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
533 G_CALLBACK(on_easysetup_changed), self);
534 gtk_widget_show (caption);
536 /* Prevent the use of some characters in the username,
537 * as required by our UI specification: */
538 modest_validating_entry_set_unallowed_characters_whitespace (
539 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
540 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
541 modest_utils_on_entry_invalid_character, self);
543 /* Set max length as in the UI spec:
544 * The UI spec seems to want us to show a dialog if we hit the maximum. */
545 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
546 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
549 /* The password widgets: */
550 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
551 /* Auto-capitalization is the default, so let's turn it off: */
552 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
553 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
554 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
555 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
556 caption = create_captioned (self, title_sizegroup, value_sizegroup,
557 _("mail_fi_password"), FALSE, priv->entry_user_password);
558 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
559 G_CALLBACK(on_easysetup_changed), self);
560 gtk_widget_show (priv->entry_user_password);
561 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
562 gtk_widget_show (caption);
564 /* The email address widgets: */
565 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
566 /* Auto-capitalization is the default, so let's turn it off: */
567 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
568 caption = create_captioned (self, title_sizegroup, value_sizegroup,
569 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
570 update_user_email_from_provider (self);
571 gtk_widget_show (priv->entry_user_email);
572 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
573 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
574 G_CALLBACK(on_easysetup_changed), self);
575 gtk_widget_show (caption);
577 /* Set max length as in the UI spec:
578 * The UI spec seems to want us to show a dialog if we hit the maximum. */
579 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
580 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
584 gtk_widget_show (GTK_WIDGET (box));
585 g_object_unref (title_sizegroup);
586 g_object_unref (value_sizegroup);
588 return GTK_WIDGET (box);
592 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
594 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
596 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
597 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
598 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
599 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
600 /* The documentation for gtk_label_set_line_wrap() says that we must
601 * call gtk_widget_set_size_request() with a hard-coded width,
602 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
603 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
604 gtk_widget_show (label);
606 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
607 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
608 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
610 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
611 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
612 gtk_widget_show (label);
614 gtk_widget_show (GTK_WIDGET (box));
615 return GTK_WIDGET (box);
618 /** Change the caption title for the incoming server,
619 * as specified in the UI spec:
622 update_incoming_server_title (ModestEasysetupWizardDialog *self)
624 ModestEasysetupWizardDialogPrivate* priv;
625 ModestProtocolType protocol_type;
626 ModestProtocolRegistry *protocol_registry;
628 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
629 protocol_registry = modest_runtime_get_protocol_registry ();
631 protocol_type = modest_servertype_picker_get_active_servertype (
632 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
634 /* This could happen when the combo box has still no active iter */
635 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
636 gchar* incomingserver_title;
637 const gchar *protocol_display_name;
638 ModestProtocol *protocol;
640 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
642 protocol_display_name = modest_protocol_get_display_name (protocol);
644 incomingserver_title = g_strconcat (_("mcen_li_emailsetup_servertype"), "\n<small>(",
645 protocol_display_name, ")</small>", NULL);
647 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
649 g_free(incomingserver_title);
653 /** Change the caption title for the incoming server,
654 * as specified in the UI spec:
657 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
659 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
660 ModestServertypePicker *server_type_picker;
661 ModestProtocolType protocol_type;
662 ModestSecurityOptionsView *view;
665 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
667 modest_servertype_picker_get_active_servertype (server_type_picker);
669 /* Fill the combo with appropriately titled choices for all
671 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
672 modest_security_options_view_set_server_type (view, protocol_type);
676 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
678 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
679 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
680 ModestServertypePicker *picker;
681 ModestProtocolType protocol_type;
686 update_incoming_server_title (self);
688 /* Update security options if needed */
689 picker = MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
690 protocol_type = modest_servertype_picker_get_active_servertype (picker);
691 update_incoming_server_security_choices (self);
692 gtk_widget_show (priv->incoming_security);
694 set_default_custom_servernames (self);
698 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
700 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
701 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
703 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
707 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
709 ModestProtocolRegistry *protocol_registry;
710 ModestEasysetupWizardDialogPrivate* priv;
712 GtkWidget *scrolled_window;
714 GtkSizeGroup *title_sizegroup;
715 GtkSizeGroup *value_sizegroup;
717 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
718 protocol_registry = modest_runtime_get_protocol_registry ();
720 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
721 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
723 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
725 GTK_POLICY_AUTOMATIC);
727 /* Show note that account type cannot be changed in future: */
728 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
729 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
730 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
731 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
732 gtk_widget_show (label);
734 /* Create a size group to be used by all captions.
735 * Note that HildonCaption does not create a default size group if we do not specify one.
736 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
737 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
738 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
740 /* The incoming server widgets: */
741 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
742 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
744 hildon_button_set_title (HILDON_BUTTON (priv->incoming_servertype_picker), _("mcen_li_emailsetup_type"));
745 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
746 G_CALLBACK (on_picker_button_value_changed), self);
747 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
748 gtk_widget_show (priv->incoming_servertype_picker);
750 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
751 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
752 /* Auto-capitalization is the default, so let's turn it off: */
753 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
754 set_default_custom_servernames (self);
756 /* The caption title will be updated in update_incoming_server_title().
757 * so this default text will never be seen: */
758 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
759 "This will be removed",
760 FALSE, priv->entry_incomingserver);
761 update_incoming_server_title (self);
762 gtk_widget_show (priv->entry_incomingserver);
763 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
764 gtk_widget_show (priv->caption_incoming);
766 /* Change the caption title when the servertype changes,
767 * as in the UI spec: */
768 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
770 G_CALLBACK (on_servertype_selector_changed), self);
772 /* Remember when the servername was changed manually: */
773 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
774 G_CALLBACK (on_entry_incoming_servername_changed), self);
776 /* The secure connection widgets. These are only valid for
777 protocols with security */
778 priv->incoming_security =
779 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
780 FALSE, title_sizegroup, value_sizegroup);
781 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
782 FALSE, FALSE, MODEST_MARGIN_HALF);
783 gtk_widget_show_all (priv->incoming_security);
785 /* Set default selection */
786 modest_servertype_picker_set_active_servertype (
787 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
788 MODEST_PROTOCOLS_STORE_POP);
790 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
791 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
792 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
793 gtk_widget_show (GTK_WIDGET (box));
794 gtk_widget_show (scrolled_window);
796 g_object_unref (title_sizegroup);
797 g_object_unref (value_sizegroup);
799 return GTK_WIDGET (scrolled_window);
803 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
805 GtkWidget *widget = GTK_WIDGET (user_data);
807 /* Enable the widget only if the check button is active: */
808 const gboolean enable = hildon_check_button_get_active (button);
809 gtk_widget_set_sensitive (widget, enable);
812 /* Make the sensitivity of a widget depend on a check button.
815 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
817 g_signal_connect (G_OBJECT (button), "toggled",
818 G_CALLBACK (on_check_button_changed), widget);
820 /* Set the starting sensitivity: */
821 on_check_button_changed (button, widget);
825 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
827 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
828 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
829 GtkWidget *specific_window;
831 /* We set dirty here because setting it depending on the connection specific dialog
835 /* Create the window, if necessary: */
836 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
837 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
839 /* Show the window */
840 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
841 gtk_widget_show (specific_window);
845 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
847 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
848 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
849 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
853 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
855 ModestEasysetupWizardDialogPrivate *priv;
856 gchar *smtp_caption_label;
857 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
859 /* Create a size group to be used by all captions.
860 * Note that HildonCaption does not create a default size group if we do not specify one.
861 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
862 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
863 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
865 /* The outgoing server widgets: */
866 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
867 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
868 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
869 G_CALLBACK (on_easysetup_changed), self);
870 /* Auto-capitalization is the default, so let's turn it off: */
871 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
872 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
873 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
874 smtp_caption_label, TRUE, priv->entry_outgoingserver);
875 g_free (smtp_caption_label);
876 gtk_widget_show (priv->entry_outgoingserver);
877 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
878 gtk_widget_show (caption);
879 set_default_custom_servernames (self);
881 /* The secure connection widgets. These are only valid for
882 protocols with security */
883 priv->outgoing_security =
884 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
885 FALSE, title_sizegroup, value_sizegroup);
886 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
887 FALSE, FALSE, MODEST_MARGIN_HALF);
888 gtk_widget_show (priv->outgoing_security);
890 GtkWidget *separator = gtk_hseparator_new ();
891 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
892 gtk_widget_show (separator);
894 /* connection-specific checkbox: */
895 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
896 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
898 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
899 _("mcen_fi_advsetup_connection_smtp"));
900 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
902 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
903 G_CALLBACK (on_easysetup_changed), self);
905 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
906 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
907 FALSE, FALSE, MODEST_MARGIN_HALF);
909 /* Connection-specific SMTP-Severs Edit button: */
910 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
911 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
912 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
913 gtk_widget_show (priv->button_outgoing_smtp_servers);
914 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
915 FALSE, FALSE, MODEST_MARGIN_HALF);
917 /* Only enable the button when the checkbox is checked: */
918 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
919 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
921 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
922 G_CALLBACK (on_button_outgoing_smtp_servers), self);
924 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
925 G_CALLBACK (on_entry_outgoing_servername_changed), self);
926 gtk_widget_show (GTK_WIDGET (box));
928 g_object_unref (title_sizegroup);
929 g_object_unref (value_sizegroup);
931 return GTK_WIDGET (box);
935 show_advanced_edit(gpointer user_data)
937 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
938 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
941 /* Show the Account Settings window: */
942 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
943 if (priv->pending_load_settings) {
944 save_to_settings (self);
945 priv->pending_load_settings = FALSE;
947 modest_account_settings_dialog_load_settings (dialog, priv->settings);
949 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
951 response = gtk_dialog_run (GTK_DIALOG (dialog));
953 gtk_widget_destroy (GTK_WIDGET (dialog));
955 return FALSE; /* Do not call this timeout callback again. */
959 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
961 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
963 /* Show the Account Settings window: */
964 show_advanced_edit(self);
967 create_page_complete_custom (ModestEasysetupWizardDialog *self)
969 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
970 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
971 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
972 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
973 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
974 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
975 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
976 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
977 gtk_widget_show (label);
979 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
980 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
981 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
982 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
983 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
984 gtk_widget_show (label);
986 gtk_widget_show (button_edit);
987 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, MODEST_MARGIN_HALF);
989 g_signal_connect (G_OBJECT (button_edit), "clicked",
990 G_CALLBACK (on_button_edit_advanced_settings), self);
992 gtk_widget_show (GTK_WIDGET (box));
993 return GTK_WIDGET (box);
1000 on_response (ModestWizardDialog *wizard_dialog,
1004 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1006 invoke_enable_buttons_vfunc (self);
1010 on_response_before (ModestWizardDialog *wizard_dialog,
1014 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1015 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1016 if (response_id == GTK_RESPONSE_CANCEL) {
1017 /* This is mostly copied from
1018 * src/maemo/modest-account-settings-dialog.c */
1020 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1021 _("imum_nc_wizard_confirm_lose_changes")));
1022 /* TODO: These button names will be ambiguous, and not
1023 * specified in the UI specification. */
1025 const gint dialog_response = gtk_dialog_run (dialog);
1026 gtk_widget_destroy (GTK_WIDGET (dialog));
1028 if (dialog_response != GTK_RESPONSE_OK) {
1029 /* Don't let the dialog close */
1030 g_signal_stop_emission_by_name (wizard_dialog, "response");
1036 typedef struct IdleData {
1037 ModestEasysetupWizardDialog *dialog;
1038 ModestPresets *presets;
1042 presets_idle (gpointer userdata)
1044 IdleData *idle_data = (IdleData *) userdata;
1045 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1046 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1048 g_assert (idle_data->presets);
1050 gdk_threads_enter ();
1052 priv->presets = idle_data->presets;
1054 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1055 /* gint mcc = get_default_country_code(); */
1057 /* Fill the combo in an idle call, as it takes a lot of time */
1058 modest_country_picker_load_data(
1059 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1060 /* connect to country picker's changed signal, so we can fill the provider picker: */
1061 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1062 (HILDON_PICKER_BUTTON (priv->account_country_picker))),
1064 G_CALLBACK (on_account_country_selector_changed), self);
1066 modest_country_picker_set_active_country_locale (
1067 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1068 mcc = modest_country_picker_get_active_country_mcc (
1069 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1070 modest_provider_picker_fill (
1071 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1072 priv->presets, mcc);
1073 /* connect to providers picker's changed signal, so we can fill the email address: */
1074 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1075 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1077 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1079 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1082 priv->dirty = FALSE;
1084 g_object_unref (idle_data->dialog);
1087 gdk_threads_leave ();
1093 presets_loader (gpointer userdata)
1095 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1096 ModestPresets *presets = NULL;
1097 IdleData *idle_data;
1099 const gchar* path = NULL;
1100 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1101 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1103 if (access(path1, R_OK) == 0)
1105 else if (access(path2, R_OK) == 0)
1108 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1109 __FUNCTION__, path1, path2);
1113 presets = modest_presets_new (path);
1115 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1119 idle_data = g_new0 (IdleData, 1);
1120 idle_data->dialog = self;
1121 idle_data->presets = presets;
1123 g_idle_add (presets_idle, idle_data);
1129 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1134 /* Append page and set attributes */
1135 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1136 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1137 "tab-expand", TRUE, "tab-fill", TRUE,
1139 gtk_widget_show (page);
1143 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1145 priv->page_user_details = NULL;
1146 priv->entry_user_name = NULL;
1147 priv->entry_user_username = NULL;
1148 priv->entry_user_password = NULL;
1149 priv->entry_user_email = NULL;
1153 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1155 priv->page_custom_incoming = NULL;
1156 priv->incoming_servertype_picker = NULL;
1157 priv->caption_incoming = NULL;
1158 priv->entry_incomingserver = NULL;
1159 priv->entry_user_email = NULL;
1160 priv->incoming_security = NULL;
1164 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1166 priv->page_custom_outgoing = NULL;
1167 priv->entry_outgoingserver = NULL;
1168 priv->checkbox_outgoing_smtp_specific = NULL;
1169 priv->button_outgoing_smtp_servers = NULL;
1170 priv->outgoing_security = NULL;
1174 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1176 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1178 /* Create the notebook to be used by the ModestWizardDialog base class:
1179 * Each page of the notebook will be a page of the wizard: */
1180 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1181 gtk_widget_set_size_request (GTK_WIDGET (notebook), DIALOG_WIDTH, -1);
1183 /* Set the notebook used by the ModestWizardDialog base class: */
1184 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1186 /* Set the wizard title:
1187 * The actual window title will be a combination of this and the page's tab label title. */
1188 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1190 /* Read in the information about known service providers: */
1191 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1193 /* The server fields did not have been manually changed yet */
1194 priv->server_changes = 0;
1195 priv->pending_load_settings = TRUE;
1197 /* Get the account manager object,
1198 * so we can check for existing accounts,
1199 * and create new accounts: */
1200 priv->account_manager = modest_runtime_get_account_mgr ();
1201 g_object_ref (priv->account_manager);
1203 /* Initialize fields */
1204 priv->page_welcome = create_page_welcome (self);
1205 priv->page_account_details = create_page_account_details (self);
1207 init_user_page (priv);
1208 init_incoming_page (priv);
1209 init_outgoing_page (priv);
1211 priv->page_complete_easysetup = NULL;
1212 priv->page_complete_customsetup = NULL;
1213 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1214 priv->missing_data_signals = NULL;
1216 /* Add the common pages */
1217 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1218 _("mcen_ti_emailsetup_welcome"));
1219 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1220 _("mcen_ti_accountdetails"));
1222 /* Connect to the dialog's response signal so we can enable/disable buttons
1223 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1224 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1225 * so that we can be enable/disable after ModestWizardDialog has done its own
1226 * enabling/disabling of buttons.
1228 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1229 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1231 * It's not enough to connect to the notebook's switch-page signal, because
1232 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1233 * _after_ switching the page (understandably).
1234 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1235 * then gtk_notebook_get_current_page() would return an incorrect value.)
1237 g_signal_connect_after (G_OBJECT (self), "response",
1238 G_CALLBACK (on_response), self);
1240 /* This is to show a confirmation dialog when the user hits cancel */
1241 g_signal_connect (G_OBJECT (self), "response",
1242 G_CALLBACK (on_response_before), self);
1244 g_signal_connect (G_OBJECT (self), "delete-event",
1245 G_CALLBACK (on_delete_event), self);
1247 /* Reset dirty, because there was no user input until now */
1248 priv->dirty = FALSE;
1250 /* When this window is shown, hibernation should not be possible,
1251 * because there is no sensible way to save the state: */
1252 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1253 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1255 /* Load provider presets */
1256 g_object_ref (self);
1257 g_thread_create (presets_loader, self, FALSE, NULL);
1259 priv->settings = modest_account_settings_new ();
1262 ModestEasysetupWizardDialog*
1263 modest_easysetup_wizard_dialog_new (void)
1266 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1270 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1272 ModestEasysetupWizardDialogPrivate *priv;
1273 GtkNotebook *notebook = NULL;
1275 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1278 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1280 if (!priv->page_user_details) {
1281 priv->page_user_details = create_page_user_details (self);
1284 /* Create the custom pages: */
1285 if(!(priv->page_custom_incoming)) {
1286 priv->page_custom_incoming = create_page_custom_incoming (self);
1289 /* TODO: only if needed */
1290 if(!(priv->page_custom_outgoing)) {
1291 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1294 if(!(priv->page_complete_customsetup)) {
1295 priv->page_complete_customsetup = create_page_complete_custom (self);
1298 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1299 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1300 _("mcen_ti_emailsetup_userdetails"));
1302 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1303 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1304 _("mcen_ti_emailsetup_incomingdetails"));
1306 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1307 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1308 _("mcen_ti_emailsetup_outgoingdetails"));
1310 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1311 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1312 _("mcen_ti_emailsetup_complete"));
1314 /* This is unnecessary with GTK+ 2.10: */
1315 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1319 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1321 ModestEasysetupWizardDialogPrivate *priv;
1322 GtkNotebook *notebook = NULL;
1324 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1327 /* Create the easysetup-specific pages: */
1328 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1329 if(!priv->page_complete_easysetup)
1330 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1332 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1333 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1334 _("mcen_ti_emailsetup_complete"));
1336 /* This is unnecessary with GTK+ 2.10: */
1337 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1342 remove_non_common_tabs (GtkNotebook *notebook,
1343 gboolean remove_user_details)
1346 /* The first 2 tabs are the common ones (welcome tab and the
1347 providers tab), so we always remove starting from the
1350 starting_tab = (remove_user_details) ? 2 : 3;
1351 while (gtk_notebook_get_n_pages (notebook) > starting_tab)
1352 gtk_notebook_remove_page (notebook, -1);
1356 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1360 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1363 /* After the user details page,
1364 * the following pages depend on whether "Other" was chosen
1365 * in the provider combobox on the account page
1368 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1370 ModestEasysetupWizardDialogPrivate *priv;
1371 ModestProviderPicker *picker;
1372 ModestProviderPickerIdType id_type;
1373 GtkNotebook *notebook;
1375 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1376 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1377 id_type = modest_provider_picker_get_active_id_type (picker);
1378 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1380 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1381 /* "Other..." was selected: */
1383 /* If we come from a rollbacked easysetup */
1384 if (priv->page_complete_easysetup) {
1385 remove_non_common_tabs (notebook, FALSE);
1386 priv->page_complete_easysetup = NULL;
1389 /* If we come from a rollbacked plugin protocol setup */
1390 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1391 remove_non_common_tabs (notebook, TRUE);
1392 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1393 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1394 priv->missing_data_signals = NULL;
1397 create_subsequent_customsetup_pages (self);
1399 /* If we come from a rollbacked custom setup */
1400 if (priv->page_custom_incoming) {
1401 remove_non_common_tabs (notebook, TRUE);
1402 init_user_page (priv);
1403 init_incoming_page (priv);
1404 init_outgoing_page (priv);
1405 init_user_page (priv);
1406 priv->page_complete_customsetup = NULL;
1409 /* It's a pluggable protocol and not a provider with presets */
1410 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1411 ModestProtocol *protocol;
1413 ModestProtocolType proto_type;
1416 /* If we come from a rollbacked easy setup */
1417 if (priv->last_plugin_protocol_selected ==
1418 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1419 priv->page_complete_easysetup) {
1420 remove_non_common_tabs (notebook, TRUE);
1421 init_user_page (priv);
1422 priv->page_complete_easysetup = NULL;
1425 proto_name = modest_provider_picker_get_active_provider_id (picker);
1426 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1427 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1429 proto_type = modest_protocol_get_type_id (protocol);
1431 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1432 proto_type != priv->last_plugin_protocol_selected) {
1433 ModestPairList *tabs;
1436 /* Remember the last selected plugin protocol */
1437 priv->last_plugin_protocol_selected = proto_type;
1440 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1441 tmp = (GSList *) tabs;
1443 ModestPair *pair = (ModestPair *) tmp->data;
1444 modest_easysetup_wizard_dialog_append_page (notebook,
1445 GTK_WIDGET (pair->second),
1446 (const gchar *) pair->first);
1448 /* Connect signals */
1449 priv->missing_data_signals =
1450 modest_signal_mgr_connect (priv->missing_data_signals,
1451 G_OBJECT (pair->second),
1452 "missing-mandatory-data",
1453 G_CALLBACK (on_missing_mandatory_data),
1456 g_free (pair->first);
1457 tmp = g_slist_next (tmp);
1458 /* Critical: if you don't show the page then the dialog will ignore it */
1459 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1461 modest_pair_list_free (tabs);
1463 g_free (proto_name);
1465 if (priv->last_plugin_protocol_selected !=
1466 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1467 remove_non_common_tabs (notebook, TRUE);
1468 init_user_page (priv);
1469 priv->page_complete_easysetup = NULL;
1470 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1471 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1472 priv->missing_data_signals = NULL;
1474 if (!priv->page_user_details) {
1475 priv->page_user_details = create_page_user_details (self);
1476 modest_easysetup_wizard_dialog_append_page (notebook,
1477 priv->page_user_details,
1478 _("mcen_ti_emailsetup_userdetails"));
1482 /* Create the easysetup pages: */
1483 create_subsequent_easysetup_pages (self);
1489 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1491 const gchar* hostname = NULL;
1494 ModestProtocolRegistry *protocol_registry;
1495 ModestProtocol *protocol;
1500 at = g_utf8_strchr (email_address, -1, '@');
1501 if (!at || (g_utf8_strlen (at, -1) < 2))
1504 domain = g_utf8_next_char (at);
1508 protocol_registry = modest_runtime_get_protocol_registry ();
1509 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1511 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1512 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1513 hostname = modest_protocol_get_name (protocol);
1519 return g_strdup_printf ("%s.%s", hostname, domain);
1523 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1525 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1527 if (!priv->entry_incomingserver)
1530 /* Set a default domain for the server, based on the email address,
1531 * if no server name was already specified.
1533 if (priv->entry_user_email
1534 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1535 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1536 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1538 /* This could happen when the combo box has still no active iter */
1539 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1540 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1541 gchar* servername = util_get_default_servername_from_email_address (email_address,
1544 /* Do not set the INCOMING_CHANGED flag because of this edit */
1545 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1546 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1547 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1549 g_free (servername);
1553 /* Set a default domain for the server, based on the email address,
1554 * if no server name was already specified.
1556 if (!priv->entry_outgoingserver)
1559 if (priv->entry_user_email
1560 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1561 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1563 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1565 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1566 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1567 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1568 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1570 g_free (servername);
1575 get_entered_account_title (ModestEasysetupWizardDialog *self)
1577 ModestEasysetupWizardDialogPrivate *priv;
1578 const gchar* account_title;
1580 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1581 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1583 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1586 /* Strip it of whitespace at the start and end: */
1587 gchar *result = g_strdup (account_title);
1588 result = g_strstrip (result);
1593 if (g_utf8_strlen (result, -1) == 0) {
1603 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1605 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1606 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1607 ModestProtocolRegistry *protocol_registry;
1609 protocol_registry = modest_runtime_get_protocol_registry ();
1611 /* if are browsing pages previous to the last one, then we have pending settings in
1613 if (next_page != NULL)
1614 priv->pending_load_settings = TRUE;
1616 /* Do extra validation that couldn't be done for every key press,
1617 * either because it was too slow,
1618 * or because it requires interaction:
1620 if (current_page == priv->page_account_details) {
1621 /* Check that the title is not already in use: */
1622 gchar* account_title = get_entered_account_title (self);
1626 /* Aavoid a clash with an existing display name: */
1627 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1628 priv->account_manager, account_title);
1629 g_free (account_title);
1632 /* Warn the user via a dialog: */
1633 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1638 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1639 create_subsequent_pages (self);
1641 } else if (current_page == priv->page_user_details) {
1642 /* Check that the email address is valud: */
1643 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1644 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1647 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1648 /* Warn the user via a dialog: */
1649 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1651 /* Return focus to the email address entry: */
1652 gtk_widget_grab_focus (priv->entry_user_email);
1653 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1659 if (next_page == priv->page_custom_incoming) {
1660 set_default_custom_servernames (self);
1661 } else if (next_page == priv->page_custom_outgoing) {
1662 set_default_custom_servernames (self);
1664 /* Check if the server supports secure authentication */
1665 /* if (modest_security_options_view_auth_check (security_options)) */
1666 /* if (!check_has_supported_auth_methods (self)) */
1668 gtk_widget_show (priv->outgoing_security);
1671 /* If this is the last page, and this is a click on Finish,
1672 * then attempt to create the dialog.
1675 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1677 if (priv->pending_load_settings) {
1678 save_to_settings (self);
1681 /* We check if there's already another account with the same configuration */
1682 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1683 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1687 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1694 static gboolean entry_is_empty (GtkWidget *entry)
1699 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1700 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1703 /* Strip it of whitespace at the start and end: */
1704 gchar *stripped = g_strdup (text);
1705 stripped = g_strstrip (stripped);
1710 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1718 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1720 GtkNotebook *notebook = NULL;
1721 gboolean is_finish_tab;
1723 ModestEasysetupWizardDialogPrivate *priv;
1726 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1727 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
1729 /* Disable the Finish button until we are on the last page,
1730 * because HildonWizardDialog enables this for all but the
1732 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1733 is_finish_tab = ((current == priv->page_complete_easysetup) ||
1734 (current == priv->page_complete_customsetup));
1736 if (is_finish_tab) {
1737 /* Disable Next on the last page no matter what the
1739 enable_next = FALSE;
1741 /* Not the last one */
1742 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1743 MODEST_WIZARD_DIALOG_FINISH,
1747 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1748 MODEST_WIZARD_DIALOG_NEXT,
1753 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1755 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1756 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1758 gboolean enable_next = TRUE;
1759 if (current_page == priv->page_welcome) {
1761 } else if (current_page == priv->page_account_details) {
1762 /* The account details title is mandatory: */
1763 if (entry_is_empty(priv->entry_account_title))
1764 enable_next = FALSE;
1765 } else if (current_page == priv->page_user_details) {
1766 /* The user details username is mandatory: */
1767 if (entry_is_empty(priv->entry_user_username))
1768 enable_next = FALSE;
1770 /* The user details email address is mandatory: */
1771 if (enable_next && entry_is_empty (priv->entry_user_email))
1772 enable_next = FALSE;
1773 } else if (current_page == priv->page_custom_incoming) {
1774 /* The custom incoming server is mandatory: */
1775 if (entry_is_empty(priv->entry_incomingserver))
1776 enable_next = FALSE;
1777 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1778 enable_next = !modest_easysetup_wizard_page_validate (
1779 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1782 /* Enable/disable buttons */
1783 real_enable_buttons (dialog, enable_next);
1787 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1789 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1790 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1793 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1794 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1796 /* Provide a vfunc implementation so we can decide
1797 * when to enable/disable the prev/next buttons.
1799 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1800 base_klass->before_next = on_before_next;
1801 base_klass->enable_buttons = on_enable_buttons;
1806 * @self: a #ModestEasysetupWizardDialog
1808 * takes information from all the wizard and stores it in settings
1811 save_to_settings (ModestEasysetupWizardDialog *self)
1813 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1815 gchar *provider_id = NULL;
1816 gchar* display_name;
1817 const gchar *username, *password;
1818 gchar *store_hostname, *transport_hostname;
1819 guint store_port, transport_port;
1820 ModestProtocolRegistry *protocol_registry;
1821 ModestProtocolType store_protocol, transport_protocol;
1822 ModestProtocolType store_security, transport_security;
1823 ModestProtocolType store_auth_protocol, transport_auth_protocol;
1824 ModestServerAccountSettings *store_settings, *transport_settings;
1825 const gchar *fullname, *email_address;
1826 ModestProviderPicker *picker;
1827 ModestProviderPickerIdType id_type;
1829 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1830 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1831 protocol_registry = modest_runtime_get_protocol_registry ();
1833 /* Get details from the specified presets: */
1834 id_type = modest_provider_picker_get_active_id_type (picker);
1835 provider_id = modest_provider_picker_get_active_provider_id (picker);
1837 /* Let the plugin save the settings. We do a return in order
1838 to save an indentation level */
1839 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1840 ModestProtocol *protocol;
1842 protocol = modest_protocol_registry_get_protocol_by_name (
1843 modest_runtime_get_protocol_registry (),
1844 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1847 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1848 gint n_pages, i = 0;
1849 GtkNotebook *notebook;
1850 GList *wizard_pages = NULL;
1852 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1853 n_pages = gtk_notebook_get_n_pages (notebook);
1854 for (i = 0; i < n_pages; i++) {
1855 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1856 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1857 wizard_pages = g_list_append (wizard_pages, page);
1859 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1862 g_list_free (wizard_pages);
1864 g_warning ("The selected protocol is a plugin protocol "//
1865 "but it's not a ModestAccountProtocol");
1868 g_free (provider_id);
1872 /* username and password (for both incoming and outgoing): */
1873 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
1874 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
1876 store_settings = modest_account_settings_get_store_settings (priv->settings);
1877 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1879 /* Incoming server: */
1880 /* Note: We need something as default for the transport store protocol values,
1881 * or modest_account_mgr_add_server_account will fail. */
1883 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1884 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1885 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1888 ModestProtocolType store_provider_server_type;
1889 gboolean store_provider_use_alternate_port;
1891 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1894 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1897 store_security = modest_presets_get_info_server_security (priv->presets,
1900 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
1903 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
1907 /* We don't check for SMTP here as that is impossible for an incoming server. */
1908 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1909 store_protocol = MODEST_PROTOCOLS_STORE_POP;
1911 store_protocol = store_provider_server_type;
1913 /* we check if there is a *special* port */
1914 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1915 if (special_port != 0) {
1916 store_port = special_port;
1918 gboolean use_alternate_port = FALSE;
1919 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
1921 use_alternate_port = TRUE;
1922 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
1925 modest_server_account_settings_set_security_protocol (store_settings,
1927 modest_server_account_settings_set_auth_protocol (store_settings,
1928 store_auth_protocol);
1929 if (store_port != 0)
1930 modest_server_account_settings_set_port (store_settings, store_port);
1932 /* Use custom pages because no preset was specified: */
1933 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
1934 store_protocol = modest_servertype_picker_get_active_servertype (
1935 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1937 modest_security_options_view_save_settings (
1938 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1942 /* now we store the common store account settings */
1943 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1944 modest_server_account_settings_set_username (store_settings, username);
1945 modest_server_account_settings_set_password (store_settings, password);
1946 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1948 g_object_unref (store_settings);
1949 g_free (store_hostname);
1951 /* Outgoing server: */
1952 transport_hostname = NULL;
1953 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1954 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1955 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1959 ModestProtocolType transport_provider_server_type;
1960 ModestProtocolType transport_provider_security;
1963 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1964 FALSE /* transport */);
1966 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1968 FALSE /* transport */);
1969 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1971 FALSE /* transport */);
1973 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1974 transport_protocol = transport_provider_server_type;
1975 transport_security = transport_provider_security;
1976 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
1977 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1978 /* we check if there is a *special* port */
1979 special_port = modest_presets_get_port (priv->presets, provider_id,
1980 FALSE /* transport */);
1981 if (special_port != 0)
1982 transport_port = special_port;
1984 transport_port = 465;
1985 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
1987 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1988 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1991 modest_server_account_settings_set_security_protocol (transport_settings,
1992 transport_security);
1993 modest_server_account_settings_set_auth_protocol (transport_settings,
1994 transport_auth_protocol);
1995 if (transport_port != 0)
1996 modest_server_account_settings_set_port (transport_settings,
1999 ModestProtocolRegistry *registry;
2000 ModestProtocol *store_proto;
2002 registry = modest_runtime_get_protocol_registry ();
2003 /* Use custom pages because no preset was specified: */
2004 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2006 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2009 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2010 /* fallback to SMTP if none was specified */
2011 g_warning ("No transport protocol was specified for store %d (%s)",
2012 modest_protocol_get_type_id (store_proto),
2013 modest_protocol_get_display_name (store_proto));
2014 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2017 modest_security_options_view_save_settings (
2018 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2022 /* now we store the common transport account settings */
2023 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2024 modest_server_account_settings_set_username (transport_settings, username);
2025 modest_server_account_settings_set_password (transport_settings, password);
2026 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2028 g_object_unref (transport_settings);
2029 g_free (transport_hostname);
2031 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2032 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2033 modest_account_settings_set_fullname (priv->settings, fullname);
2034 modest_account_settings_set_email_address (priv->settings, email_address);
2035 /* we don't set retrieve type to preserve advanced settings if
2036 any. By default account settings are set to headers only */
2038 /* Save the connection-specific SMTP server accounts. */
2039 modest_account_settings_set_use_connection_specific_smtp
2041 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2043 display_name = get_entered_account_title (self);
2044 modest_account_settings_set_display_name (priv->settings, display_name);
2045 g_free (display_name);
2046 g_free (provider_id);