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,
272 result = modest_maemo_utils_create_captioned (title_size_group, value_size_group,
275 /* Connect to the appropriate changed signal for the widget,
276 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
278 if (GTK_IS_ENTRY (control)) {
279 g_signal_connect (G_OBJECT (control), "changed",
280 G_CALLBACK (on_caption_entry_changed), self);
283 else if (GTK_IS_COMBO_BOX (control)) {
284 g_signal_connect (G_OBJECT (control), "changed",
285 G_CALLBACK (on_caption_combobox_changed), self);
292 create_page_welcome (ModestEasysetupWizardDialog *self)
294 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
295 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
296 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
297 /* So that it is not truncated: */
298 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
299 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
300 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
301 gtk_widget_show (label);
302 gtk_widget_show (GTK_WIDGET (box));
303 return GTK_WIDGET (box);
307 on_account_country_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
309 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
311 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
315 /* Fill the providers picker, based on the selected country: */
316 if (priv->presets != NULL) {
317 gint mcc = modest_country_picker_get_active_country_mcc (
318 MODEST_COUNTRY_PICKER (priv->account_country_picker));
319 modest_provider_picker_fill (
320 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
325 update_user_email_from_provider (ModestEasysetupWizardDialog *self)
327 ModestEasysetupWizardDialogPrivate *priv;
329 gchar* domain_name = NULL;
332 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
334 /* Fill the providers combo, based on the selected country: */
335 provider_id = modest_provider_picker_get_active_provider_id (
336 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
339 domain_name = modest_presets_get_domain (priv->presets, provider_id);
342 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
344 if (priv->entry_user_email)
345 hildon_entry_set_text (HILDON_ENTRY (priv->entry_user_email), domain_name);
347 g_free (domain_name);
349 g_free (provider_id);
353 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
355 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
357 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
361 update_user_email_from_provider (self);
365 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
367 modest_platform_information_banner (GTK_WIDGET (self), NULL,
368 _CS("ckdg_ib_maximum_characters_reached"));
372 create_page_account_details (ModestEasysetupWizardDialog *self)
375 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
376 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
377 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
379 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
380 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
381 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
382 gtk_widget_show (label);
384 /* Create a size group to be used by all captions.
385 * Note that HildonCaption does not create a default size group if we do not specify one.
386 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
387 GtkSizeGroup* title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
388 GtkSizeGroup* value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
390 /* The country widgets: */
391 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new (MODEST_EDITABLE_SIZE,
392 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
393 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
394 _("mcen_fi_country"), priv->account_country_picker);
395 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
396 G_CALLBACK (on_picker_button_value_changed), self);
397 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
398 gtk_widget_show (priv->account_country_picker);
400 GtkWidget *separator = gtk_hseparator_new ();
401 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
402 gtk_widget_show (separator);
404 /* The service provider widgets: */
405 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new (MODEST_EDITABLE_SIZE,
406 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
407 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
408 _("mcen_fi_serviceprovider"),
409 priv->account_serviceprovider_picker);
410 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
411 G_CALLBACK (on_picker_button_value_changed), self);
412 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
413 gtk_widget_show (priv->account_serviceprovider_picker);
415 /* The description widgets: */
416 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
417 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
418 G_CALLBACK(on_easysetup_changed), self);
419 /* Do use auto-capitalization: */
420 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
421 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
423 /* Set a default account title, choosing one that does not already exist: */
424 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
425 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
426 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
427 priv->account_manager, default_account_name_start);
428 g_free (default_account_name_start);
429 default_account_name_start = NULL;
431 hildon_entry_set_text (HILDON_ENTRY (priv->entry_account_title), default_account_name);
432 g_free (default_account_name);
433 default_account_name = NULL;
435 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mcen_fi_account_title"),
436 priv->entry_account_title);
437 gtk_widget_show (priv->entry_account_title);
438 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
439 gtk_widget_show (caption);
441 /* Prevent the use of some characters in the account title,
442 * as required by our UI specification: */
443 GList *list_prevent = NULL;
444 list_prevent = g_list_append (list_prevent, "\\");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
450 list_prevent = g_list_append (list_prevent, "“");
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 modest_validating_entry_set_unallowed_characters (
456 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
457 g_list_free (list_prevent);
459 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
460 modest_utils_on_entry_invalid_character, self);
462 /* Set max length as in the UI spec:
463 * The UI spec seems to want us to show a dialog if we hit the maximum. */
464 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
465 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
468 gtk_widget_show (GTK_WIDGET (box));
470 g_object_unref (title_sizegroup);
471 g_object_unref (value_sizegroup);
473 return GTK_WIDGET (box);
477 create_page_user_details (ModestEasysetupWizardDialog *self)
479 GtkSizeGroup* title_sizegroup;
480 GtkSizeGroup* value_sizegroup;
482 ModestEasysetupWizardDialogPrivate *priv;
484 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
486 /* Create a size group to be used by all captions.
487 * Note that HildonCaption does not create a default size group if we do not specify one.
488 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
489 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
490 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
491 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
493 /* The name widgets: (use auto cap) */
494 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
495 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
496 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
498 /* Set max length as in the UI spec:
499 * The UI spec seems to want us to show a dialog if we hit the maximum. */
500 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
501 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
503 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
504 _("mcen_li_emailsetup_name"), priv->entry_user_name);
505 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
506 G_CALLBACK(on_easysetup_changed), self);
507 gtk_widget_show (priv->entry_user_name);
508 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
509 gtk_widget_show (caption);
511 /* Prevent the use of some characters in the name,
512 * as required by our UI specification: */
513 GList *list_prevent = NULL;
514 list_prevent = g_list_append (list_prevent, "<");
515 list_prevent = g_list_append (list_prevent, ">");
516 modest_validating_entry_set_unallowed_characters (
517 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
518 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
519 modest_utils_on_entry_invalid_character, self);
520 g_list_free (list_prevent);
522 /* The username widgets: */
523 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
524 /* Auto-capitalization is the default, so let's turn it off: */
525 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
526 HILDON_GTK_INPUT_MODE_FULL);
527 caption = create_captioned (self, title_sizegroup, value_sizegroup, _("mail_fi_username"),
528 priv->entry_user_username);
529 gtk_widget_show (priv->entry_user_username);
530 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
531 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
532 G_CALLBACK(on_easysetup_changed), self);
533 gtk_widget_show (caption);
535 /* Prevent the use of some characters in the username,
536 * as required by our UI specification: */
537 modest_validating_entry_set_unallowed_characters_whitespace (
538 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
539 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
540 modest_utils_on_entry_invalid_character, self);
542 /* Set max length as in the UI spec:
543 * The UI spec seems to want us to show a dialog if we hit the maximum. */
544 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
545 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
548 /* The password widgets: */
549 priv->entry_user_password = hildon_entry_new (MODEST_EDITABLE_SIZE);
550 /* Auto-capitalization is the default, so let's turn it off: */
551 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
552 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
553 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
554 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
555 caption = create_captioned (self, title_sizegroup, value_sizegroup,
556 _("mail_fi_password"), priv->entry_user_password);
557 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
558 G_CALLBACK(on_easysetup_changed), self);
559 gtk_widget_show (priv->entry_user_password);
560 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
561 gtk_widget_show (caption);
563 /* The email address widgets: */
564 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
565 /* Auto-capitalization is the default, so let's turn it off: */
566 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
567 caption = create_captioned (self, title_sizegroup, value_sizegroup,
568 _("mcen_li_emailsetup_email_address"), priv->entry_user_email);
569 update_user_email_from_provider (self);
570 gtk_widget_show (priv->entry_user_email);
571 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
572 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
573 G_CALLBACK(on_easysetup_changed), self);
574 gtk_widget_show (caption);
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_user_email), 64);
579 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
583 gtk_widget_show (GTK_WIDGET (box));
584 g_object_unref (title_sizegroup);
585 g_object_unref (value_sizegroup);
587 return GTK_WIDGET (box);
591 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
593 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
595 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
596 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
597 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
598 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
599 /* The documentation for gtk_label_set_line_wrap() says that we must
600 * call gtk_widget_set_size_request() with a hard-coded width,
601 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
602 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
603 gtk_widget_show (label);
605 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
606 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
607 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
609 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
610 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
611 gtk_widget_show (label);
613 gtk_widget_show (GTK_WIDGET (box));
614 return GTK_WIDGET (box);
617 /** Change the caption title for the incoming server,
618 * as specified in the UI spec:
621 update_incoming_server_title (ModestEasysetupWizardDialog *self)
623 ModestEasysetupWizardDialogPrivate* priv;
624 ModestProtocolType protocol_type;
625 ModestProtocolRegistry *protocol_registry;
627 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
628 protocol_registry = modest_runtime_get_protocol_registry ();
630 protocol_type = modest_servertype_picker_get_active_servertype (
631 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
633 /* This could happen when the combo box has still no active iter */
634 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
635 gchar* incomingserver_title;
636 const gchar *protocol_display_name;
637 ModestProtocol *protocol;
641 /* Get the label and change it. This is ugly */
642 children = gtk_container_get_children (GTK_CONTAINER (priv->caption_incoming));
643 label = (GtkWidget *) children->data;
645 if (!GTK_IS_LABEL (label))
648 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry,
650 protocol_display_name = modest_protocol_get_display_name (protocol);
652 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"),
653 protocol_display_name);
655 gtk_label_set_markup (GTK_LABEL (label), incomingserver_title);
657 g_free(incomingserver_title);
661 /** Change the caption title for the incoming server,
662 * as specified in the UI spec:
665 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
667 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
668 ModestServertypePicker *server_type_picker;
669 ModestProtocolType protocol_type;
670 ModestSecurityOptionsView *view;
673 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
675 modest_servertype_picker_get_active_servertype (server_type_picker);
677 /* Fill the combo with appropriately titled choices for all
679 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
680 modest_security_options_view_set_server_type (view, protocol_type);
684 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
686 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
687 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
688 ModestServertypePicker *picker;
689 ModestProtocolType protocol_type;
694 update_incoming_server_title (self);
696 /* Update security options if needed */
697 picker = MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
698 protocol_type = modest_servertype_picker_get_active_servertype (picker);
699 update_incoming_server_security_choices (self);
700 gtk_widget_show (priv->incoming_security);
702 set_default_custom_servernames (self);
706 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
708 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
709 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
711 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
715 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
717 ModestProtocolRegistry *protocol_registry;
718 ModestEasysetupWizardDialogPrivate* priv;
720 GtkWidget *scrolled_window;
722 GtkSizeGroup *title_sizegroup;
723 GtkSizeGroup *value_sizegroup;
725 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
726 protocol_registry = modest_runtime_get_protocol_registry ();
728 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
729 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
731 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
733 GTK_POLICY_AUTOMATIC);
735 /* Show note that account type cannot be changed in future: */
736 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
737 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
738 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
739 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
740 gtk_widget_show (label);
742 /* Create a size group to be used by all captions.
743 * Note that HildonCaption does not create a default size group if we do not specify one.
744 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
745 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
746 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
748 /* The incoming server widgets: */
749 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
750 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
752 hildon_button_set_title (HILDON_BUTTON (priv->incoming_servertype_picker), _("mcen_li_emailsetup_type"));
753 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
754 G_CALLBACK (on_picker_button_value_changed), self);
755 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
756 gtk_widget_show (priv->incoming_servertype_picker);
758 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
759 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
760 /* Auto-capitalization is the default, so let's turn it off: */
761 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
762 set_default_custom_servernames (self);
764 /* The caption title will be updated in update_incoming_server_title().
765 * so this default text will never be seen: */
766 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
767 "This will be removed",
768 priv->entry_incomingserver);
769 update_incoming_server_title (self);
770 gtk_widget_show (priv->entry_incomingserver);
771 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
772 gtk_widget_show (priv->caption_incoming);
774 /* Change the caption title when the servertype changes,
775 * as in the UI spec: */
776 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
778 G_CALLBACK (on_servertype_selector_changed), self);
780 /* Remember when the servername was changed manually: */
781 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
782 G_CALLBACK (on_entry_incoming_servername_changed), self);
784 /* The secure connection widgets. These are only valid for
785 protocols with security */
786 priv->incoming_security =
787 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
788 FALSE, title_sizegroup, value_sizegroup);
789 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
790 FALSE, FALSE, MODEST_MARGIN_HALF);
791 gtk_widget_show_all (priv->incoming_security);
793 /* Set default selection */
794 modest_servertype_picker_set_active_servertype (
795 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
796 MODEST_PROTOCOLS_STORE_POP);
798 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
799 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
800 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
801 gtk_widget_show (GTK_WIDGET (box));
802 gtk_widget_show (scrolled_window);
804 g_object_unref (title_sizegroup);
805 g_object_unref (value_sizegroup);
807 return GTK_WIDGET (scrolled_window);
811 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
813 GtkWidget *widget = GTK_WIDGET (user_data);
815 /* Enable the widget only if the check button is active: */
816 const gboolean enable = hildon_check_button_get_active (button);
817 gtk_widget_set_sensitive (widget, enable);
820 /* Make the sensitivity of a widget depend on a check button.
823 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
825 g_signal_connect (G_OBJECT (button), "toggled",
826 G_CALLBACK (on_check_button_changed), widget);
828 /* Set the starting sensitivity: */
829 on_check_button_changed (button, widget);
833 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
835 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
836 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
837 GtkWidget *specific_window;
839 /* We set dirty here because setting it depending on the connection specific dialog
843 /* Create the window, if necessary: */
844 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
845 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
847 /* Show the window */
848 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
849 gtk_widget_show (specific_window);
853 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
855 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
856 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
857 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
861 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
863 ModestEasysetupWizardDialogPrivate *priv;
864 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
866 /* Create a size group to be used by all captions.
867 * Note that HildonCaption does not create a default size group if we do not specify one.
868 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
869 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
870 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
872 /* The outgoing server widgets: */
873 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
874 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
875 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
876 G_CALLBACK (on_easysetup_changed), self);
877 /* Auto-capitalization is the default, so let's turn it off: */
878 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
879 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
880 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver);
881 gtk_widget_show (priv->entry_outgoingserver);
882 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
883 gtk_widget_show (caption);
884 set_default_custom_servernames (self);
886 /* The secure connection widgets. These are only valid for
887 protocols with security */
888 priv->outgoing_security =
889 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
890 FALSE, title_sizegroup, value_sizegroup);
891 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
892 FALSE, FALSE, MODEST_MARGIN_HALF);
893 gtk_widget_show (priv->outgoing_security);
895 GtkWidget *separator = gtk_hseparator_new ();
896 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
897 gtk_widget_show (separator);
899 /* connection-specific checkbox: */
900 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
901 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
903 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
904 _("mcen_fi_advsetup_connection_smtp"));
905 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
907 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
908 G_CALLBACK (on_easysetup_changed), self);
910 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
911 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
912 FALSE, FALSE, MODEST_MARGIN_HALF);
914 /* Connection-specific SMTP-Severs Edit button: */
915 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
916 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
917 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
918 gtk_widget_show (priv->button_outgoing_smtp_servers);
919 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
920 FALSE, FALSE, MODEST_MARGIN_HALF);
922 /* Only enable the button when the checkbox is checked: */
923 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
924 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
926 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
927 G_CALLBACK (on_button_outgoing_smtp_servers), self);
929 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
930 G_CALLBACK (on_entry_outgoing_servername_changed), self);
931 gtk_widget_show (GTK_WIDGET (box));
933 g_object_unref (title_sizegroup);
934 g_object_unref (value_sizegroup);
936 return GTK_WIDGET (box);
940 show_advanced_edit(gpointer user_data)
942 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
943 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
946 /* Show the Account Settings window: */
947 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
948 if (priv->pending_load_settings) {
949 save_to_settings (self);
950 priv->pending_load_settings = FALSE;
952 modest_account_settings_dialog_load_settings (dialog, priv->settings);
954 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
956 response = gtk_dialog_run (GTK_DIALOG (dialog));
958 gtk_widget_destroy (GTK_WIDGET (dialog));
960 return FALSE; /* Do not call this timeout callback again. */
964 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
966 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
968 /* Show the Account Settings window: */
969 show_advanced_edit(self);
972 create_page_complete_custom (ModestEasysetupWizardDialog *self)
974 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
975 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
976 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
977 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
978 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
979 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
980 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
981 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
982 gtk_widget_show (label);
984 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
985 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
986 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
987 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
988 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
989 gtk_widget_show (label);
991 gtk_widget_show (button_edit);
992 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, MODEST_MARGIN_HALF);
994 g_signal_connect (G_OBJECT (button_edit), "clicked",
995 G_CALLBACK (on_button_edit_advanced_settings), self);
997 gtk_widget_show (GTK_WIDGET (box));
998 return GTK_WIDGET (box);
1005 on_response (ModestWizardDialog *wizard_dialog,
1009 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1011 invoke_enable_buttons_vfunc (self);
1015 on_response_before (ModestWizardDialog *wizard_dialog,
1019 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1020 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1021 if (response_id == GTK_RESPONSE_CANCEL) {
1022 /* This is mostly copied from
1023 * src/maemo/modest-account-settings-dialog.c */
1025 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1026 _("imum_nc_wizard_confirm_lose_changes")));
1027 /* TODO: These button names will be ambiguous, and not
1028 * specified in the UI specification. */
1030 const gint dialog_response = gtk_dialog_run (dialog);
1031 gtk_widget_destroy (GTK_WIDGET (dialog));
1033 if (dialog_response != GTK_RESPONSE_OK) {
1034 /* Don't let the dialog close */
1035 g_signal_stop_emission_by_name (wizard_dialog, "response");
1041 typedef struct IdleData {
1042 ModestEasysetupWizardDialog *dialog;
1043 ModestPresets *presets;
1047 presets_idle (gpointer userdata)
1049 IdleData *idle_data = (IdleData *) userdata;
1050 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1051 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1053 g_assert (idle_data->presets);
1055 gdk_threads_enter ();
1057 priv->presets = idle_data->presets;
1059 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1060 /* gint mcc = get_default_country_code(); */
1062 /* Fill the combo in an idle call, as it takes a lot of time */
1063 modest_country_picker_load_data(
1064 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1065 /* connect to country picker's changed signal, so we can fill the provider picker: */
1066 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1067 (HILDON_PICKER_BUTTON (priv->account_country_picker))),
1069 G_CALLBACK (on_account_country_selector_changed), self);
1071 modest_country_picker_set_active_country_locale (
1072 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1073 mcc = modest_country_picker_get_active_country_mcc (
1074 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1075 modest_provider_picker_fill (
1076 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1077 priv->presets, mcc);
1078 /* connect to providers picker's changed signal, so we can fill the email address: */
1079 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1080 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1082 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1084 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1087 priv->dirty = FALSE;
1089 g_object_unref (idle_data->dialog);
1092 gdk_threads_leave ();
1098 presets_loader (gpointer userdata)
1100 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1101 ModestPresets *presets = NULL;
1102 IdleData *idle_data;
1104 const gchar* path = NULL;
1105 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1106 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1108 if (access(path1, R_OK) == 0)
1110 else if (access(path2, R_OK) == 0)
1113 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1114 __FUNCTION__, path1, path2);
1118 presets = modest_presets_new (path);
1120 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1124 idle_data = g_new0 (IdleData, 1);
1125 idle_data->dialog = self;
1126 idle_data->presets = presets;
1128 g_idle_add (presets_idle, idle_data);
1134 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1139 /* Append page and set attributes */
1140 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1141 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1142 "tab-expand", TRUE, "tab-fill", TRUE,
1144 gtk_widget_show (page);
1148 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1150 priv->page_user_details = NULL;
1151 priv->entry_user_name = NULL;
1152 priv->entry_user_username = NULL;
1153 priv->entry_user_password = NULL;
1154 priv->entry_user_email = NULL;
1158 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1160 priv->page_custom_incoming = NULL;
1161 priv->incoming_servertype_picker = NULL;
1162 priv->caption_incoming = NULL;
1163 priv->entry_incomingserver = NULL;
1164 priv->entry_user_email = NULL;
1165 priv->incoming_security = NULL;
1169 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1171 priv->page_custom_outgoing = NULL;
1172 priv->entry_outgoingserver = NULL;
1173 priv->checkbox_outgoing_smtp_specific = NULL;
1174 priv->button_outgoing_smtp_servers = NULL;
1175 priv->outgoing_security = NULL;
1179 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1181 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1183 /* Create the notebook to be used by the ModestWizardDialog base class:
1184 * Each page of the notebook will be a page of the wizard: */
1185 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1186 gtk_widget_set_size_request (GTK_WIDGET (notebook), DIALOG_WIDTH, -1);
1188 /* Set the notebook used by the ModestWizardDialog base class: */
1189 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1191 /* Set the wizard title:
1192 * The actual window title will be a combination of this and the page's tab label title. */
1193 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1195 /* Read in the information about known service providers: */
1196 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1198 /* The server fields did not have been manually changed yet */
1199 priv->server_changes = 0;
1200 priv->pending_load_settings = TRUE;
1202 /* Get the account manager object,
1203 * so we can check for existing accounts,
1204 * and create new accounts: */
1205 priv->account_manager = modest_runtime_get_account_mgr ();
1206 g_object_ref (priv->account_manager);
1208 /* Initialize fields */
1209 priv->page_welcome = create_page_welcome (self);
1210 priv->page_account_details = create_page_account_details (self);
1212 init_user_page (priv);
1213 init_incoming_page (priv);
1214 init_outgoing_page (priv);
1216 priv->page_complete_easysetup = NULL;
1217 priv->page_complete_customsetup = NULL;
1218 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1219 priv->missing_data_signals = NULL;
1221 /* Add the common pages */
1222 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1223 _("mcen_ti_emailsetup_welcome"));
1224 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1225 _("mcen_ti_accountdetails"));
1227 /* Connect to the dialog's response signal so we can enable/disable buttons
1228 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1229 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1230 * so that we can be enable/disable after ModestWizardDialog has done its own
1231 * enabling/disabling of buttons.
1233 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1234 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1236 * It's not enough to connect to the notebook's switch-page signal, because
1237 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1238 * _after_ switching the page (understandably).
1239 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1240 * then gtk_notebook_get_current_page() would return an incorrect value.)
1242 g_signal_connect_after (G_OBJECT (self), "response",
1243 G_CALLBACK (on_response), self);
1245 /* This is to show a confirmation dialog when the user hits cancel */
1246 g_signal_connect (G_OBJECT (self), "response",
1247 G_CALLBACK (on_response_before), self);
1249 g_signal_connect (G_OBJECT (self), "delete-event",
1250 G_CALLBACK (on_delete_event), self);
1252 /* Reset dirty, because there was no user input until now */
1253 priv->dirty = FALSE;
1255 /* When this window is shown, hibernation should not be possible,
1256 * because there is no sensible way to save the state: */
1257 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1258 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1260 /* Load provider presets */
1261 g_object_ref (self);
1262 g_thread_create (presets_loader, self, FALSE, NULL);
1264 priv->settings = modest_account_settings_new ();
1267 ModestEasysetupWizardDialog*
1268 modest_easysetup_wizard_dialog_new (void)
1271 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1275 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1277 ModestEasysetupWizardDialogPrivate *priv;
1278 GtkNotebook *notebook = NULL;
1280 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1283 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1285 if (!priv->page_user_details) {
1286 priv->page_user_details = create_page_user_details (self);
1289 /* Create the custom pages: */
1290 if(!(priv->page_custom_incoming)) {
1291 priv->page_custom_incoming = create_page_custom_incoming (self);
1294 /* TODO: only if needed */
1295 if(!(priv->page_custom_outgoing)) {
1296 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1299 if(!(priv->page_complete_customsetup)) {
1300 priv->page_complete_customsetup = create_page_complete_custom (self);
1303 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1304 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1305 _("mcen_ti_emailsetup_userdetails"));
1307 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1308 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1309 _("mcen_ti_emailsetup_incomingdetails"));
1311 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1312 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1313 _("mcen_ti_emailsetup_outgoingdetails"));
1315 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1316 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1317 _("mcen_ti_emailsetup_complete"));
1319 /* This is unnecessary with GTK+ 2.10: */
1320 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1324 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1326 ModestEasysetupWizardDialogPrivate *priv;
1327 GtkNotebook *notebook = NULL;
1329 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1332 /* Create the easysetup-specific pages: */
1333 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1334 if(!priv->page_complete_easysetup)
1335 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1337 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1338 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1339 _("mcen_ti_emailsetup_complete"));
1341 /* This is unnecessary with GTK+ 2.10: */
1342 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1347 remove_non_common_tabs (GtkNotebook *notebook,
1348 gboolean remove_user_details)
1351 /* The first 2 tabs are the common ones (welcome tab and the
1352 providers tab), so we always remove starting from the
1355 starting_tab = (remove_user_details) ? 2 : 3;
1356 while (gtk_notebook_get_n_pages (notebook) > starting_tab)
1357 gtk_notebook_remove_page (notebook, -1);
1361 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1365 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1368 /* After the user details page,
1369 * the following pages depend on whether "Other" was chosen
1370 * in the provider combobox on the account page
1373 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1375 ModestEasysetupWizardDialogPrivate *priv;
1376 ModestProviderPicker *picker;
1377 ModestProviderPickerIdType id_type;
1378 GtkNotebook *notebook;
1380 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1381 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1382 id_type = modest_provider_picker_get_active_id_type (picker);
1383 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1385 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1386 /* "Other..." was selected: */
1388 /* If we come from a rollbacked easysetup */
1389 if (priv->page_complete_easysetup) {
1390 remove_non_common_tabs (notebook, FALSE);
1391 priv->page_complete_easysetup = NULL;
1394 /* If we come from a rollbacked plugin protocol setup */
1395 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1396 remove_non_common_tabs (notebook, TRUE);
1397 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1398 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1399 priv->missing_data_signals = NULL;
1402 create_subsequent_customsetup_pages (self);
1404 /* If we come from a rollbacked custom setup */
1405 if (priv->page_custom_incoming) {
1406 remove_non_common_tabs (notebook, TRUE);
1407 init_user_page (priv);
1408 init_incoming_page (priv);
1409 init_outgoing_page (priv);
1410 init_user_page (priv);
1411 priv->page_complete_customsetup = NULL;
1414 /* It's a pluggable protocol and not a provider with presets */
1415 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1416 ModestProtocol *protocol;
1418 ModestProtocolType proto_type;
1421 /* If we come from a rollbacked easy setup */
1422 if (priv->last_plugin_protocol_selected ==
1423 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1424 priv->page_complete_easysetup) {
1425 remove_non_common_tabs (notebook, TRUE);
1426 init_user_page (priv);
1427 priv->page_complete_easysetup = NULL;
1430 proto_name = modest_provider_picker_get_active_provider_id (picker);
1431 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1432 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1434 proto_type = modest_protocol_get_type_id (protocol);
1436 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1437 proto_type != priv->last_plugin_protocol_selected) {
1438 ModestPairList *tabs;
1441 /* Remember the last selected plugin protocol */
1442 priv->last_plugin_protocol_selected = proto_type;
1445 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1446 tmp = (GSList *) tabs;
1448 ModestPair *pair = (ModestPair *) tmp->data;
1449 modest_easysetup_wizard_dialog_append_page (notebook,
1450 GTK_WIDGET (pair->second),
1451 (const gchar *) pair->first);
1453 /* Connect signals */
1454 priv->missing_data_signals =
1455 modest_signal_mgr_connect (priv->missing_data_signals,
1456 G_OBJECT (pair->second),
1457 "missing-mandatory-data",
1458 G_CALLBACK (on_missing_mandatory_data),
1461 g_free (pair->first);
1462 tmp = g_slist_next (tmp);
1463 /* Critical: if you don't show the page then the dialog will ignore it */
1464 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1466 modest_pair_list_free (tabs);
1468 g_free (proto_name);
1470 if (priv->last_plugin_protocol_selected !=
1471 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1472 remove_non_common_tabs (notebook, TRUE);
1473 init_user_page (priv);
1474 priv->page_complete_easysetup = NULL;
1475 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1476 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1477 priv->missing_data_signals = NULL;
1479 if (!priv->page_user_details) {
1480 priv->page_user_details = create_page_user_details (self);
1481 modest_easysetup_wizard_dialog_append_page (notebook,
1482 priv->page_user_details,
1483 _("mcen_ti_emailsetup_userdetails"));
1487 /* Create the easysetup pages: */
1488 create_subsequent_easysetup_pages (self);
1494 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1496 const gchar* hostname = NULL;
1499 ModestProtocolRegistry *protocol_registry;
1500 ModestProtocol *protocol;
1505 at = g_utf8_strchr (email_address, -1, '@');
1506 if (!at || (g_utf8_strlen (at, -1) < 2))
1509 domain = g_utf8_next_char (at);
1513 protocol_registry = modest_runtime_get_protocol_registry ();
1514 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1516 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1517 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1518 hostname = modest_protocol_get_name (protocol);
1524 return g_strdup_printf ("%s.%s", hostname, domain);
1528 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1530 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1532 if (!priv->entry_incomingserver)
1535 /* Set a default domain for the server, based on the email address,
1536 * if no server name was already specified.
1538 if (priv->entry_user_email
1539 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1540 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1541 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1543 /* This could happen when the combo box has still no active iter */
1544 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1545 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1546 gchar* servername = util_get_default_servername_from_email_address (email_address,
1549 /* Do not set the INCOMING_CHANGED flag because of this edit */
1550 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1551 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1552 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1554 g_free (servername);
1558 /* Set a default domain for the server, based on the email address,
1559 * if no server name was already specified.
1561 if (!priv->entry_outgoingserver)
1564 if (priv->entry_user_email
1565 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1566 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1568 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1570 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1571 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1572 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1573 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1575 g_free (servername);
1580 get_entered_account_title (ModestEasysetupWizardDialog *self)
1582 ModestEasysetupWizardDialogPrivate *priv;
1583 const gchar* account_title;
1585 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1586 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1588 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1591 /* Strip it of whitespace at the start and end: */
1592 gchar *result = g_strdup (account_title);
1593 result = g_strstrip (result);
1598 if (g_utf8_strlen (result, -1) == 0) {
1608 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1610 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1611 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1612 ModestProtocolRegistry *protocol_registry;
1614 protocol_registry = modest_runtime_get_protocol_registry ();
1616 /* if are browsing pages previous to the last one, then we have pending settings in
1618 if (next_page != NULL)
1619 priv->pending_load_settings = TRUE;
1621 /* Do extra validation that couldn't be done for every key press,
1622 * either because it was too slow,
1623 * or because it requires interaction:
1625 if (current_page == priv->page_account_details) {
1626 /* Check that the title is not already in use: */
1627 gchar* account_title = get_entered_account_title (self);
1631 /* Aavoid a clash with an existing display name: */
1632 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1633 priv->account_manager, account_title);
1634 g_free (account_title);
1637 /* Warn the user via a dialog: */
1638 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1643 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1644 create_subsequent_pages (self);
1646 } else if (current_page == priv->page_user_details) {
1647 /* Check that the email address is valud: */
1648 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1649 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1652 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1653 /* Warn the user via a dialog: */
1654 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1656 /* Return focus to the email address entry: */
1657 gtk_widget_grab_focus (priv->entry_user_email);
1658 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1664 if (next_page == priv->page_custom_incoming) {
1665 set_default_custom_servernames (self);
1666 } else if (next_page == priv->page_custom_outgoing) {
1667 set_default_custom_servernames (self);
1669 /* Check if the server supports secure authentication */
1670 /* if (modest_security_options_view_auth_check (security_options)) */
1671 /* if (!check_has_supported_auth_methods (self)) */
1673 gtk_widget_show (priv->outgoing_security);
1676 /* If this is the last page, and this is a click on Finish,
1677 * then attempt to create the dialog.
1680 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1682 if (priv->pending_load_settings) {
1683 save_to_settings (self);
1686 /* We check if there's already another account with the same configuration */
1687 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1688 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1692 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1699 static gboolean entry_is_empty (GtkWidget *entry)
1704 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1705 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1708 /* Strip it of whitespace at the start and end: */
1709 gchar *stripped = g_strdup (text);
1710 stripped = g_strstrip (stripped);
1715 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1723 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1725 GtkNotebook *notebook = NULL;
1726 gboolean is_finish_tab;
1728 ModestEasysetupWizardDialogPrivate *priv;
1731 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1732 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
1734 /* Disable the Finish button until we are on the last page,
1735 * because HildonWizardDialog enables this for all but the
1737 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1738 is_finish_tab = ((current == priv->page_complete_easysetup) ||
1739 (current == priv->page_complete_customsetup));
1741 if (is_finish_tab) {
1742 /* Disable Next on the last page no matter what the
1744 enable_next = FALSE;
1746 /* Not the last one */
1747 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1748 MODEST_WIZARD_DIALOG_FINISH,
1752 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1753 MODEST_WIZARD_DIALOG_NEXT,
1758 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1760 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1761 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1763 gboolean enable_next = TRUE;
1764 if (current_page == priv->page_welcome) {
1766 } else if (current_page == priv->page_account_details) {
1767 /* The account details title is mandatory: */
1768 if (entry_is_empty(priv->entry_account_title))
1769 enable_next = FALSE;
1770 } else if (current_page == priv->page_user_details) {
1771 /* The user details username is mandatory: */
1772 if (entry_is_empty(priv->entry_user_username))
1773 enable_next = FALSE;
1775 /* The user details email address is mandatory: */
1776 if (enable_next && entry_is_empty (priv->entry_user_email))
1777 enable_next = FALSE;
1778 } else if (current_page == priv->page_custom_incoming) {
1779 /* The custom incoming server is mandatory: */
1780 if (entry_is_empty(priv->entry_incomingserver))
1781 enable_next = FALSE;
1782 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1783 enable_next = !modest_easysetup_wizard_page_validate (
1784 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1787 /* Enable/disable buttons */
1788 real_enable_buttons (dialog, enable_next);
1792 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1794 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1795 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1798 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1799 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1801 /* Provide a vfunc implementation so we can decide
1802 * when to enable/disable the prev/next buttons.
1804 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1805 base_klass->before_next = on_before_next;
1806 base_klass->enable_buttons = on_enable_buttons;
1811 * @self: a #ModestEasysetupWizardDialog
1813 * takes information from all the wizard and stores it in settings
1816 save_to_settings (ModestEasysetupWizardDialog *self)
1818 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1820 gchar *provider_id = NULL;
1821 gchar* display_name;
1822 const gchar *username, *password;
1823 gchar *store_hostname, *transport_hostname;
1824 guint store_port, transport_port;
1825 ModestProtocolRegistry *protocol_registry;
1826 ModestProtocolType store_protocol, transport_protocol;
1827 ModestProtocolType store_security, transport_security;
1828 ModestProtocolType store_auth_protocol, transport_auth_protocol;
1829 ModestServerAccountSettings *store_settings, *transport_settings;
1830 const gchar *fullname, *email_address;
1831 ModestProviderPicker *picker;
1832 ModestProviderPickerIdType id_type;
1834 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1835 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1836 protocol_registry = modest_runtime_get_protocol_registry ();
1838 /* Get details from the specified presets: */
1839 id_type = modest_provider_picker_get_active_id_type (picker);
1840 provider_id = modest_provider_picker_get_active_provider_id (picker);
1842 /* Let the plugin save the settings. We do a return in order
1843 to save an indentation level */
1844 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1845 ModestProtocol *protocol;
1847 protocol = modest_protocol_registry_get_protocol_by_name (
1848 modest_runtime_get_protocol_registry (),
1849 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1852 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1853 gint n_pages, i = 0;
1854 GtkNotebook *notebook;
1855 GList *wizard_pages = NULL;
1857 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1858 n_pages = gtk_notebook_get_n_pages (notebook);
1859 for (i = 0; i < n_pages; i++) {
1860 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1861 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1862 wizard_pages = g_list_append (wizard_pages, page);
1864 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1867 g_list_free (wizard_pages);
1869 g_warning ("The selected protocol is a plugin protocol "//
1870 "but it's not a ModestAccountProtocol");
1873 g_free (provider_id);
1877 /* username and password (for both incoming and outgoing): */
1878 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
1879 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
1881 store_settings = modest_account_settings_get_store_settings (priv->settings);
1882 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1884 /* Incoming server: */
1885 /* Note: We need something as default for the transport store protocol values,
1886 * or modest_account_mgr_add_server_account will fail. */
1888 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1889 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1890 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1893 ModestProtocolType store_provider_server_type;
1894 gboolean store_provider_use_alternate_port;
1896 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1899 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1902 store_security = modest_presets_get_info_server_security (priv->presets,
1905 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
1908 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
1912 /* We don't check for SMTP here as that is impossible for an incoming server. */
1913 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1914 store_protocol = MODEST_PROTOCOLS_STORE_POP;
1916 store_protocol = store_provider_server_type;
1918 /* we check if there is a *special* port */
1919 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1920 if (special_port != 0) {
1921 store_port = special_port;
1923 gboolean use_alternate_port = FALSE;
1924 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
1926 use_alternate_port = TRUE;
1927 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
1930 modest_server_account_settings_set_security_protocol (store_settings,
1932 modest_server_account_settings_set_auth_protocol (store_settings,
1933 store_auth_protocol);
1934 if (store_port != 0)
1935 modest_server_account_settings_set_port (store_settings, store_port);
1937 /* Use custom pages because no preset was specified: */
1938 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
1939 store_protocol = modest_servertype_picker_get_active_servertype (
1940 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1942 modest_security_options_view_save_settings (
1943 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1947 /* now we store the common store account settings */
1948 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1949 modest_server_account_settings_set_username (store_settings, username);
1950 modest_server_account_settings_set_password (store_settings, password);
1951 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1953 g_object_unref (store_settings);
1954 g_free (store_hostname);
1956 /* Outgoing server: */
1957 transport_hostname = NULL;
1958 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1959 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1960 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1964 ModestProtocolType transport_provider_server_type;
1965 ModestProtocolType transport_provider_security;
1968 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1969 FALSE /* transport */);
1971 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1973 FALSE /* transport */);
1974 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1976 FALSE /* transport */);
1978 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1979 transport_protocol = transport_provider_server_type;
1980 transport_security = transport_provider_security;
1981 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
1982 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1983 /* we check if there is a *special* port */
1984 special_port = modest_presets_get_port (priv->presets, provider_id,
1985 FALSE /* transport */);
1986 if (special_port != 0)
1987 transport_port = special_port;
1989 transport_port = 465;
1990 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
1992 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1993 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1996 modest_server_account_settings_set_security_protocol (transport_settings,
1997 transport_security);
1998 modest_server_account_settings_set_auth_protocol (transport_settings,
1999 transport_auth_protocol);
2000 if (transport_port != 0)
2001 modest_server_account_settings_set_port (transport_settings,
2004 ModestProtocolRegistry *registry;
2005 ModestProtocol *store_proto;
2007 registry = modest_runtime_get_protocol_registry ();
2008 /* Use custom pages because no preset was specified: */
2009 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
2011 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
2014 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2015 /* fallback to SMTP if none was specified */
2016 g_warning ("No transport protocol was specified for store %d (%s)",
2017 modest_protocol_get_type_id (store_proto),
2018 modest_protocol_get_display_name (store_proto));
2019 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2022 modest_security_options_view_save_settings (
2023 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2027 /* now we store the common transport account settings */
2028 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2029 modest_server_account_settings_set_username (transport_settings, username);
2030 modest_server_account_settings_set_password (transport_settings, password);
2031 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2033 g_object_unref (transport_settings);
2034 g_free (transport_hostname);
2036 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2037 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2038 modest_account_settings_set_fullname (priv->settings, fullname);
2039 modest_account_settings_set_email_address (priv->settings, email_address);
2040 /* we don't set retrieve type to preserve advanced settings if
2041 any. By default account settings are set to headers only */
2043 /* Save the connection-specific SMTP server accounts. */
2044 modest_account_settings_set_use_connection_specific_smtp
2046 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2048 display_name = get_entered_account_title (self);
2049 modest_account_settings_set_display_name (priv->settings, display_name);
2050 g_free (display_name);
2051 g_free (provider_id);