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;
638 protocol_display_name = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type));
640 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), protocol_display_name);
641 g_free(incomingserver_title);
645 /** Change the caption title for the incoming server,
646 * as specified in the UI spec:
649 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
651 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
652 ModestServertypePicker *server_type_picker;
653 ModestProtocolType protocol_type;
654 ModestSecurityOptionsView *view;
657 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
659 modest_servertype_picker_get_active_servertype (server_type_picker);
661 /* Fill the combo with appropriately titled choices for all
663 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
664 modest_security_options_view_set_server_type (view, protocol_type);
668 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
670 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
671 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
672 ModestServertypePicker *picker;
673 ModestProtocolType protocol_type;
678 update_incoming_server_title (self);
680 /* Update security options if needed */
681 picker = MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
682 protocol_type = modest_servertype_picker_get_active_servertype (picker);
683 update_incoming_server_security_choices (self);
684 gtk_widget_show (priv->incoming_security);
686 set_default_custom_servernames (self);
690 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
692 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
693 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
695 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
699 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
701 ModestProtocolRegistry *protocol_registry;
702 ModestEasysetupWizardDialogPrivate* priv;
704 GtkWidget *scrolled_window;
706 GtkSizeGroup *title_sizegroup;
707 GtkSizeGroup *value_sizegroup;
709 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
710 protocol_registry = modest_runtime_get_protocol_registry ();
712 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
713 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
715 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
717 GTK_POLICY_AUTOMATIC);
719 /* Show note that account type cannot be changed in future: */
720 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
721 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
722 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
723 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
724 gtk_widget_show (label);
726 /* Create a size group to be used by all captions.
727 * Note that HildonCaption does not create a default size group if we do not specify one.
728 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
729 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
730 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
732 /* The incoming server widgets: */
733 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
734 HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
736 hildon_button_set_title (HILDON_BUTTON (priv->incoming_servertype_picker), _("mcen_li_emailsetup_type"));
737 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
738 G_CALLBACK (on_picker_button_value_changed), self);
739 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
740 gtk_widget_show (priv->incoming_servertype_picker);
742 priv->entry_incomingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
743 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
744 /* Auto-capitalization is the default, so let's turn it off: */
745 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
746 set_default_custom_servernames (self);
748 /* The caption title will be updated in update_incoming_server_title().
749 * so this default text will never be seen: */
750 /* (Note: Changing the title seems pointless. murrayc) */
751 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
753 priv->entry_incomingserver);
754 update_incoming_server_title (self);
755 gtk_widget_show (priv->entry_incomingserver);
756 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
757 gtk_widget_show (priv->caption_incoming);
759 /* Change the caption title when the servertype changes,
760 * as in the UI spec: */
761 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
763 G_CALLBACK (on_servertype_selector_changed), self);
765 /* Remember when the servername was changed manually: */
766 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
767 G_CALLBACK (on_entry_incoming_servername_changed), self);
769 /* The secure connection widgets. These are only valid for
770 protocols with security */
771 priv->incoming_security =
772 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
773 FALSE, title_sizegroup, value_sizegroup);
774 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
775 FALSE, FALSE, MODEST_MARGIN_HALF);
776 gtk_widget_show_all (priv->incoming_security);
778 /* Set default selection */
779 modest_servertype_picker_set_active_servertype (
780 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
781 MODEST_PROTOCOLS_STORE_POP);
783 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
784 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
785 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
786 gtk_widget_show (GTK_WIDGET (box));
787 gtk_widget_show (scrolled_window);
789 g_object_unref (title_sizegroup);
790 g_object_unref (value_sizegroup);
792 return GTK_WIDGET (scrolled_window);
796 on_check_button_changed (HildonCheckButton *button, gpointer user_data)
798 GtkWidget *widget = GTK_WIDGET (user_data);
800 /* Enable the widget only if the check button is active: */
801 const gboolean enable = hildon_check_button_get_active (button);
802 gtk_widget_set_sensitive (widget, enable);
805 /* Make the sensitivity of a widget depend on a check button.
808 enable_widget_for_checkbutton (GtkWidget *widget, HildonCheckButton* button)
810 g_signal_connect (G_OBJECT (button), "toggled",
811 G_CALLBACK (on_check_button_changed), widget);
813 /* Set the starting sensitivity: */
814 on_check_button_changed (button, widget);
818 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
820 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
821 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
822 GtkWidget *specific_window;
824 /* We set dirty here because setting it depending on the connection specific dialog
828 /* Create the window, if necessary: */
829 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
830 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
832 /* Show the window */
833 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window), GTK_WINDOW (self));
834 gtk_widget_show (specific_window);
838 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
840 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
841 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
842 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
846 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
848 ModestEasysetupWizardDialogPrivate *priv;
849 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
851 /* Create a size group to be used by all captions.
852 * Note that HildonCaption does not create a default size group if we do not specify one.
853 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
854 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
855 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
857 /* The outgoing server widgets: */
858 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
859 priv->entry_outgoingserver = hildon_entry_new (MODEST_EDITABLE_SIZE);
860 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
861 G_CALLBACK (on_easysetup_changed), self);
862 /* Auto-capitalization is the default, so let's turn it off: */
863 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
864 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
865 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver);
866 gtk_widget_show (priv->entry_outgoingserver);
867 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
868 gtk_widget_show (caption);
869 set_default_custom_servernames (self);
871 /* The secure connection widgets. These are only valid for
872 protocols with security */
873 priv->outgoing_security =
874 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
875 FALSE, title_sizegroup, value_sizegroup);
876 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
877 FALSE, FALSE, MODEST_MARGIN_HALF);
878 gtk_widget_show (priv->outgoing_security);
880 GtkWidget *separator = gtk_hseparator_new ();
881 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
882 gtk_widget_show (separator);
884 /* connection-specific checkbox: */
885 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
886 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
888 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
889 _("mcen_fi_advsetup_connection_smtp"));
890 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
892 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
893 G_CALLBACK (on_easysetup_changed), self);
895 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
896 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
897 FALSE, FALSE, MODEST_MARGIN_HALF);
899 /* Connection-specific SMTP-Severs Edit button: */
900 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
901 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
902 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
903 gtk_widget_show (priv->button_outgoing_smtp_servers);
904 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers,
905 FALSE, FALSE, MODEST_MARGIN_HALF);
907 /* Only enable the button when the checkbox is checked: */
908 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
909 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific));
911 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
912 G_CALLBACK (on_button_outgoing_smtp_servers), self);
914 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
915 G_CALLBACK (on_entry_outgoing_servername_changed), self);
916 gtk_widget_show (GTK_WIDGET (box));
918 g_object_unref (title_sizegroup);
919 g_object_unref (value_sizegroup);
921 return GTK_WIDGET (box);
925 show_advanced_edit(gpointer user_data)
927 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
928 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
931 /* Show the Account Settings window: */
932 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
933 if (priv->pending_load_settings) {
934 save_to_settings (self);
935 priv->pending_load_settings = FALSE;
937 modest_account_settings_dialog_load_settings (dialog, priv->settings);
939 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), GTK_WINDOW (self));
941 response = gtk_dialog_run (GTK_DIALOG (dialog));
943 gtk_widget_destroy (GTK_WIDGET (dialog));
945 return FALSE; /* Do not call this timeout callback again. */
949 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
951 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
953 /* Show the Account Settings window: */
954 show_advanced_edit(self);
957 create_page_complete_custom (ModestEasysetupWizardDialog *self)
959 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
960 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
961 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_fi_advanced_settings"));
962 hildon_gtk_widget_set_theme_size (button_edit, HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
963 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
964 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
965 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
966 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
967 gtk_widget_show (label);
969 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
970 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
971 gtk_widget_set_size_request (label, LABELS_WIDTH, -1);
972 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
973 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
974 gtk_widget_show (label);
976 gtk_widget_show (button_edit);
977 gtk_box_pack_start (GTK_BOX (box), button_edit, FALSE, FALSE, MODEST_MARGIN_HALF);
979 g_signal_connect (G_OBJECT (button_edit), "clicked",
980 G_CALLBACK (on_button_edit_advanced_settings), self);
982 gtk_widget_show (GTK_WIDGET (box));
983 return GTK_WIDGET (box);
990 on_response (ModestWizardDialog *wizard_dialog,
994 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
996 invoke_enable_buttons_vfunc (self);
1000 on_response_before (ModestWizardDialog *wizard_dialog,
1004 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1005 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1006 if (response_id == GTK_RESPONSE_CANCEL) {
1007 /* This is mostly copied from
1008 * src/maemo/modest-account-settings-dialog.c */
1010 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1011 _("imum_nc_wizard_confirm_lose_changes")));
1012 /* TODO: These button names will be ambiguous, and not
1013 * specified in the UI specification. */
1015 const gint dialog_response = gtk_dialog_run (dialog);
1016 gtk_widget_destroy (GTK_WIDGET (dialog));
1018 if (dialog_response != GTK_RESPONSE_OK) {
1019 /* Don't let the dialog close */
1020 g_signal_stop_emission_by_name (wizard_dialog, "response");
1026 typedef struct IdleData {
1027 ModestEasysetupWizardDialog *dialog;
1028 ModestPresets *presets;
1032 presets_idle (gpointer userdata)
1034 IdleData *idle_data = (IdleData *) userdata;
1035 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1036 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1038 g_assert (idle_data->presets);
1040 gdk_threads_enter ();
1042 priv->presets = idle_data->presets;
1044 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1045 /* gint mcc = get_default_country_code(); */
1047 /* Fill the combo in an idle call, as it takes a lot of time */
1048 modest_country_picker_load_data(
1049 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1050 /* connect to country picker's changed signal, so we can fill the provider picker: */
1051 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1052 (HILDON_PICKER_BUTTON (priv->account_country_picker))),
1054 G_CALLBACK (on_account_country_selector_changed), self);
1056 modest_country_picker_set_active_country_locale (
1057 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1058 mcc = modest_country_picker_get_active_country_mcc (
1059 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1060 modest_provider_picker_fill (
1061 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1062 priv->presets, mcc);
1063 /* connect to providers picker's changed signal, so we can fill the email address: */
1064 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1065 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1067 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1069 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1072 priv->dirty = FALSE;
1074 g_object_unref (idle_data->dialog);
1077 gdk_threads_leave ();
1083 presets_loader (gpointer userdata)
1085 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1086 ModestPresets *presets = NULL;
1087 IdleData *idle_data;
1089 const gchar* path = NULL;
1090 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1091 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1093 if (access(path1, R_OK) == 0)
1095 else if (access(path2, R_OK) == 0)
1098 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1099 __FUNCTION__, path1, path2);
1103 presets = modest_presets_new (path);
1105 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1109 idle_data = g_new0 (IdleData, 1);
1110 idle_data->dialog = self;
1111 idle_data->presets = presets;
1113 g_idle_add (presets_idle, idle_data);
1119 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1124 /* Append page and set attributes */
1125 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1126 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1127 "tab-expand", TRUE, "tab-fill", TRUE,
1129 gtk_widget_show (page);
1133 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1135 priv->page_user_details = NULL;
1136 priv->entry_user_name = NULL;
1137 priv->entry_user_username = NULL;
1138 priv->entry_user_password = NULL;
1139 priv->entry_user_email = NULL;
1143 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1145 priv->page_custom_incoming = NULL;
1146 priv->incoming_servertype_picker = NULL;
1147 priv->caption_incoming = NULL;
1148 priv->entry_incomingserver = NULL;
1149 priv->entry_user_email = NULL;
1150 priv->incoming_security = NULL;
1154 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1156 priv->page_custom_outgoing = NULL;
1157 priv->entry_outgoingserver = NULL;
1158 priv->checkbox_outgoing_smtp_specific = NULL;
1159 priv->button_outgoing_smtp_servers = NULL;
1160 priv->outgoing_security = NULL;
1164 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1166 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1168 /* Create the notebook to be used by the ModestWizardDialog base class:
1169 * Each page of the notebook will be a page of the wizard: */
1170 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1171 gtk_widget_set_size_request (GTK_WIDGET (notebook), DIALOG_WIDTH, -1);
1173 /* Set the notebook used by the ModestWizardDialog base class: */
1174 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1176 /* Set the wizard title:
1177 * The actual window title will be a combination of this and the page's tab label title. */
1178 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1180 /* Read in the information about known service providers: */
1181 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1183 /* The server fields did not have been manually changed yet */
1184 priv->server_changes = 0;
1185 priv->pending_load_settings = TRUE;
1187 /* Get the account manager object,
1188 * so we can check for existing accounts,
1189 * and create new accounts: */
1190 priv->account_manager = modest_runtime_get_account_mgr ();
1191 g_object_ref (priv->account_manager);
1193 /* Initialize fields */
1194 priv->page_welcome = create_page_welcome (self);
1195 priv->page_account_details = create_page_account_details (self);
1197 init_user_page (priv);
1198 init_incoming_page (priv);
1199 init_outgoing_page (priv);
1201 priv->page_complete_easysetup = NULL;
1202 priv->page_complete_customsetup = NULL;
1203 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1204 priv->missing_data_signals = NULL;
1206 /* Add the common pages */
1207 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1208 _("mcen_ti_emailsetup_welcome"));
1209 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1210 _("mcen_ti_accountdetails"));
1212 /* Connect to the dialog's response signal so we can enable/disable buttons
1213 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1214 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1215 * so that we can be enable/disable after ModestWizardDialog has done its own
1216 * enabling/disabling of buttons.
1218 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1219 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1221 * It's not enough to connect to the notebook's switch-page signal, because
1222 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1223 * _after_ switching the page (understandably).
1224 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1225 * then gtk_notebook_get_current_page() would return an incorrect value.)
1227 g_signal_connect_after (G_OBJECT (self), "response",
1228 G_CALLBACK (on_response), self);
1230 /* This is to show a confirmation dialog when the user hits cancel */
1231 g_signal_connect (G_OBJECT (self), "response",
1232 G_CALLBACK (on_response_before), self);
1234 g_signal_connect (G_OBJECT (self), "delete-event",
1235 G_CALLBACK (on_delete_event), self);
1237 /* Reset dirty, because there was no user input until now */
1238 priv->dirty = FALSE;
1240 /* When this window is shown, hibernation should not be possible,
1241 * because there is no sensible way to save the state: */
1242 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1243 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1245 /* Load provider presets */
1246 g_object_ref (self);
1247 g_thread_create (presets_loader, self, FALSE, NULL);
1249 priv->settings = modest_account_settings_new ();
1252 ModestEasysetupWizardDialog*
1253 modest_easysetup_wizard_dialog_new (void)
1256 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1260 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1262 ModestEasysetupWizardDialogPrivate *priv;
1263 GtkNotebook *notebook = NULL;
1265 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1268 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1270 if (!priv->page_user_details) {
1271 priv->page_user_details = create_page_user_details (self);
1274 /* Create the custom pages: */
1275 if(!(priv->page_custom_incoming)) {
1276 priv->page_custom_incoming = create_page_custom_incoming (self);
1279 /* TODO: only if needed */
1280 if(!(priv->page_custom_outgoing)) {
1281 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1284 if(!(priv->page_complete_customsetup)) {
1285 priv->page_complete_customsetup = create_page_complete_custom (self);
1288 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1289 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1290 _("mcen_ti_emailsetup_userdetails"));
1292 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1293 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1294 _("mcen_ti_emailsetup_incomingdetails"));
1296 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1297 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1298 _("mcen_ti_emailsetup_outgoingdetails"));
1300 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1301 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1302 _("mcen_ti_emailsetup_complete"));
1304 /* This is unnecessary with GTK+ 2.10: */
1305 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1309 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1311 ModestEasysetupWizardDialogPrivate *priv;
1312 GtkNotebook *notebook = NULL;
1314 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1317 /* Create the easysetup-specific pages: */
1318 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1319 if(!priv->page_complete_easysetup)
1320 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1322 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1323 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1324 _("mcen_ti_emailsetup_complete"));
1326 /* This is unnecessary with GTK+ 2.10: */
1327 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1332 remove_non_common_tabs (GtkNotebook *notebook,
1333 gboolean remove_user_details)
1336 /* The first 2 tabs are the common ones (welcome tab and the
1337 providers tab), so we always remove starting from the
1340 starting_tab = (remove_user_details) ? 2 : 3;
1341 while (gtk_notebook_get_n_pages (notebook) > starting_tab)
1342 gtk_notebook_remove_page (notebook, -1);
1346 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1350 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1353 /* After the user details page,
1354 * the following pages depend on whether "Other" was chosen
1355 * in the provider combobox on the account page
1358 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1360 ModestEasysetupWizardDialogPrivate *priv;
1361 ModestProviderPicker *picker;
1362 ModestProviderPickerIdType id_type;
1363 GtkNotebook *notebook;
1365 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1366 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1367 id_type = modest_provider_picker_get_active_id_type (picker);
1368 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1370 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1371 /* "Other..." was selected: */
1373 /* If we come from a rollbacked easysetup */
1374 if (priv->page_complete_easysetup) {
1375 remove_non_common_tabs (notebook, FALSE);
1376 priv->page_complete_easysetup = NULL;
1379 /* If we come from a rollbacked plugin protocol setup */
1380 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1381 remove_non_common_tabs (notebook, TRUE);
1382 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1383 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1384 priv->missing_data_signals = NULL;
1387 create_subsequent_customsetup_pages (self);
1389 /* If we come from a rollbacked custom setup */
1390 if (priv->page_custom_incoming) {
1391 remove_non_common_tabs (notebook, TRUE);
1392 init_user_page (priv);
1393 init_incoming_page (priv);
1394 init_outgoing_page (priv);
1395 init_user_page (priv);
1396 priv->page_complete_customsetup = NULL;
1399 /* It's a pluggable protocol and not a provider with presets */
1400 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1401 ModestProtocol *protocol;
1403 ModestProtocolType proto_type;
1406 /* If we come from a rollbacked easy setup */
1407 if (priv->last_plugin_protocol_selected ==
1408 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1409 priv->page_complete_easysetup) {
1410 remove_non_common_tabs (notebook, TRUE);
1411 init_user_page (priv);
1412 priv->page_complete_easysetup = NULL;
1415 proto_name = modest_provider_picker_get_active_provider_id (picker);
1416 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1417 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1419 proto_type = modest_protocol_get_type_id (protocol);
1421 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1422 proto_type != priv->last_plugin_protocol_selected) {
1423 ModestPairList *tabs;
1426 /* Remember the last selected plugin protocol */
1427 priv->last_plugin_protocol_selected = proto_type;
1430 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1431 tmp = (GSList *) tabs;
1433 ModestPair *pair = (ModestPair *) tmp->data;
1434 modest_easysetup_wizard_dialog_append_page (notebook,
1435 GTK_WIDGET (pair->second),
1436 (const gchar *) pair->first);
1438 /* Connect signals */
1439 priv->missing_data_signals =
1440 modest_signal_mgr_connect (priv->missing_data_signals,
1441 G_OBJECT (pair->second),
1442 "missing-mandatory-data",
1443 G_CALLBACK (on_missing_mandatory_data),
1446 g_free (pair->first);
1447 tmp = g_slist_next (tmp);
1448 /* Critical: if you don't show the page then the dialog will ignore it */
1449 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1451 modest_pair_list_free (tabs);
1453 g_free (proto_name);
1455 if (priv->last_plugin_protocol_selected !=
1456 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1457 remove_non_common_tabs (notebook, TRUE);
1458 init_user_page (priv);
1459 priv->page_complete_easysetup = NULL;
1460 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1461 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1462 priv->missing_data_signals = NULL;
1464 if (!priv->page_user_details) {
1465 priv->page_user_details = create_page_user_details (self);
1466 modest_easysetup_wizard_dialog_append_page (notebook,
1467 priv->page_user_details,
1468 _("mcen_ti_emailsetup_userdetails"));
1472 /* Create the easysetup pages: */
1473 create_subsequent_easysetup_pages (self);
1479 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1481 const gchar* hostname = NULL;
1484 ModestProtocolRegistry *protocol_registry;
1485 ModestProtocol *protocol;
1490 at = g_utf8_strchr (email_address, -1, '@');
1491 if (!at || (g_utf8_strlen (at, -1) < 2))
1494 domain = g_utf8_next_char (at);
1498 protocol_registry = modest_runtime_get_protocol_registry ();
1499 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1501 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1502 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1503 hostname = modest_protocol_get_name (protocol);
1509 return g_strdup_printf ("%s.%s", hostname, domain);
1513 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1515 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1517 if (!priv->entry_incomingserver)
1520 /* Set a default domain for the server, based on the email address,
1521 * if no server name was already specified.
1523 if (priv->entry_user_email
1524 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1525 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1526 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1528 /* This could happen when the combo box has still no active iter */
1529 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1530 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1531 gchar* servername = util_get_default_servername_from_email_address (email_address,
1534 /* Do not set the INCOMING_CHANGED flag because of this edit */
1535 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1536 hildon_entry_set_text (HILDON_ENTRY (priv->entry_incomingserver), servername);
1537 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1539 g_free (servername);
1543 /* Set a default domain for the server, based on the email address,
1544 * if no server name was already specified.
1546 if (!priv->entry_outgoingserver)
1549 if (priv->entry_user_email
1550 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1551 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY(priv->entry_user_email));
1553 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1555 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1556 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1557 hildon_entry_set_text (HILDON_ENTRY (priv->entry_outgoingserver), servername);
1558 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1560 g_free (servername);
1565 get_entered_account_title (ModestEasysetupWizardDialog *self)
1567 ModestEasysetupWizardDialogPrivate *priv;
1568 const gchar* account_title;
1570 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1571 account_title = hildon_entry_get_text (HILDON_ENTRY (priv->entry_account_title));
1573 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1576 /* Strip it of whitespace at the start and end: */
1577 gchar *result = g_strdup (account_title);
1578 result = g_strstrip (result);
1583 if (g_utf8_strlen (result, -1) == 0) {
1593 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1595 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1596 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1597 ModestProtocolRegistry *protocol_registry;
1599 protocol_registry = modest_runtime_get_protocol_registry ();
1601 /* if are browsing pages previous to the last one, then we have pending settings in
1603 if (next_page != NULL)
1604 priv->pending_load_settings = TRUE;
1606 /* Do extra validation that couldn't be done for every key press,
1607 * either because it was too slow,
1608 * or because it requires interaction:
1610 if (current_page == priv->page_account_details) {
1611 /* Check that the title is not already in use: */
1612 gchar* account_title = get_entered_account_title (self);
1616 /* Aavoid a clash with an existing display name: */
1617 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1618 priv->account_manager, account_title);
1619 g_free (account_title);
1622 /* Warn the user via a dialog: */
1623 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1628 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1629 create_subsequent_pages (self);
1631 } else if (current_page == priv->page_user_details) {
1632 /* Check that the email address is valud: */
1633 const gchar* email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
1634 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1637 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1638 /* Warn the user via a dialog: */
1639 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1641 /* Return focus to the email address entry: */
1642 gtk_widget_grab_focus (priv->entry_user_email);
1643 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1649 if (next_page == priv->page_custom_incoming) {
1650 set_default_custom_servernames (self);
1651 } else if (next_page == priv->page_custom_outgoing) {
1652 set_default_custom_servernames (self);
1654 /* Check if the server supports secure authentication */
1655 /* if (modest_security_options_view_auth_check (security_options)) */
1656 /* if (!check_has_supported_auth_methods (self)) */
1658 gtk_widget_show (priv->outgoing_security);
1661 /* If this is the last page, and this is a click on Finish,
1662 * then attempt to create the dialog.
1665 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1667 if (priv->pending_load_settings) {
1668 save_to_settings (self);
1671 /* We check if there's already another account with the same configuration */
1672 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1673 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1677 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1684 static gboolean entry_is_empty (GtkWidget *entry)
1689 const gchar* text = hildon_entry_get_text (HILDON_ENTRY (entry));
1690 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1693 /* Strip it of whitespace at the start and end: */
1694 gchar *stripped = g_strdup (text);
1695 stripped = g_strstrip (stripped);
1700 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1708 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1710 GtkNotebook *notebook = NULL;
1711 gboolean is_finish_tab;
1713 ModestEasysetupWizardDialogPrivate *priv;
1716 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1717 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
1719 /* Disable the Finish button until we are on the last page,
1720 * because HildonWizardDialog enables this for all but the
1722 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1723 is_finish_tab = ((current == priv->page_complete_easysetup) ||
1724 (current == priv->page_complete_customsetup));
1726 if (is_finish_tab) {
1727 /* Disable Next on the last page no matter what the
1729 enable_next = FALSE;
1731 /* Not the last one */
1732 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1733 MODEST_WIZARD_DIALOG_FINISH,
1737 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1738 MODEST_WIZARD_DIALOG_NEXT,
1743 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1745 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1746 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1748 gboolean enable_next = TRUE;
1749 if (current_page == priv->page_welcome) {
1751 } else if (current_page == priv->page_account_details) {
1752 /* The account details title is mandatory: */
1753 if (entry_is_empty(priv->entry_account_title))
1754 enable_next = FALSE;
1755 } else if (current_page == priv->page_user_details) {
1756 /* The user details username is mandatory: */
1757 if (entry_is_empty(priv->entry_user_username))
1758 enable_next = FALSE;
1760 /* The user details email address is mandatory: */
1761 if (enable_next && entry_is_empty (priv->entry_user_email))
1762 enable_next = FALSE;
1763 } else if (current_page == priv->page_custom_incoming) {
1764 /* The custom incoming server is mandatory: */
1765 if (entry_is_empty(priv->entry_incomingserver))
1766 enable_next = FALSE;
1767 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1768 enable_next = !modest_easysetup_wizard_page_validate (
1769 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1772 /* Enable/disable buttons */
1773 real_enable_buttons (dialog, enable_next);
1777 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1779 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1780 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1783 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1784 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1786 /* Provide a vfunc implementation so we can decide
1787 * when to enable/disable the prev/next buttons.
1789 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1790 base_klass->before_next = on_before_next;
1791 base_klass->enable_buttons = on_enable_buttons;
1796 * @self: a #ModestEasysetupWizardDialog
1798 * takes information from all the wizard and stores it in settings
1801 save_to_settings (ModestEasysetupWizardDialog *self)
1803 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1805 gchar *provider_id = NULL;
1806 gchar* display_name;
1807 const gchar *username, *password;
1808 gchar *store_hostname, *transport_hostname;
1809 guint store_port, transport_port;
1810 ModestProtocolRegistry *protocol_registry;
1811 ModestProtocolType store_protocol, transport_protocol;
1812 ModestProtocolType store_security, transport_security;
1813 ModestProtocolType store_auth_protocol, transport_auth_protocol;
1814 ModestServerAccountSettings *store_settings, *transport_settings;
1815 const gchar *fullname, *email_address;
1816 ModestProviderPicker *picker;
1817 ModestProviderPickerIdType id_type;
1819 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1820 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1821 protocol_registry = modest_runtime_get_protocol_registry ();
1823 /* Get details from the specified presets: */
1824 id_type = modest_provider_picker_get_active_id_type (picker);
1825 provider_id = modest_provider_picker_get_active_provider_id (picker);
1827 /* Let the plugin save the settings. We do a return in order
1828 to save an indentation level */
1829 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1830 ModestProtocol *protocol;
1832 protocol = modest_protocol_registry_get_protocol_by_name (
1833 modest_runtime_get_protocol_registry (),
1834 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1837 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1838 gint n_pages, i = 0;
1839 GtkNotebook *notebook;
1840 GList *wizard_pages = NULL;
1842 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1843 n_pages = gtk_notebook_get_n_pages (notebook);
1844 for (i = 0; i < n_pages; i++) {
1845 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1846 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1847 wizard_pages = g_list_append (wizard_pages, page);
1849 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1852 g_list_free (wizard_pages);
1854 g_warning ("The selected protocol is a plugin protocol "//
1855 "but it's not a ModestAccountProtocol");
1858 g_free (provider_id);
1862 /* username and password (for both incoming and outgoing): */
1863 username = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_username));
1864 password = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_password));
1866 store_settings = modest_account_settings_get_store_settings (priv->settings);
1867 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1869 /* Incoming server: */
1870 /* Note: We need something as default for the transport store protocol values,
1871 * or modest_account_mgr_add_server_account will fail. */
1873 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1874 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1875 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1878 ModestProtocolType store_provider_server_type;
1879 gboolean store_provider_use_alternate_port;
1881 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1884 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1887 store_security = modest_presets_get_info_server_security (priv->presets,
1890 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
1893 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
1897 /* We don't check for SMTP here as that is impossible for an incoming server. */
1898 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1899 store_protocol = MODEST_PROTOCOLS_STORE_POP;
1901 store_protocol = store_provider_server_type;
1903 /* we check if there is a *special* port */
1904 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1905 if (special_port != 0) {
1906 store_port = special_port;
1908 gboolean use_alternate_port = FALSE;
1909 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
1911 use_alternate_port = TRUE;
1912 store_port = get_port_from_protocol(store_provider_server_type, use_alternate_port);
1915 modest_server_account_settings_set_security_protocol (store_settings,
1917 modest_server_account_settings_set_auth_protocol (store_settings,
1918 store_auth_protocol);
1919 if (store_port != 0)
1920 modest_server_account_settings_set_port (store_settings, store_port);
1922 /* Use custom pages because no preset was specified: */
1923 store_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_incomingserver) ));
1924 store_protocol = modest_servertype_picker_get_active_servertype (
1925 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1927 modest_security_options_view_save_settings (
1928 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1932 /* now we store the common store account settings */
1933 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1934 modest_server_account_settings_set_username (store_settings, username);
1935 modest_server_account_settings_set_password (store_settings, password);
1936 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1938 g_object_unref (store_settings);
1939 g_free (store_hostname);
1941 /* Outgoing server: */
1942 transport_hostname = NULL;
1943 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1944 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1945 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1949 ModestProtocolType transport_provider_server_type;
1950 ModestProtocolType transport_provider_security;
1953 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1954 FALSE /* transport */);
1956 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1958 FALSE /* transport */);
1959 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1961 FALSE /* transport */);
1963 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1964 transport_protocol = transport_provider_server_type;
1965 transport_security = transport_provider_security;
1966 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
1967 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1968 /* we check if there is a *special* port */
1969 special_port = modest_presets_get_port (priv->presets, provider_id,
1970 FALSE /* transport */);
1971 if (special_port != 0)
1972 transport_port = special_port;
1974 transport_port = 465;
1975 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
1977 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1978 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1981 modest_server_account_settings_set_security_protocol (transport_settings,
1982 transport_security);
1983 modest_server_account_settings_set_auth_protocol (transport_settings,
1984 transport_auth_protocol);
1985 if (transport_port != 0)
1986 modest_server_account_settings_set_port (transport_settings,
1989 ModestProtocolRegistry *registry;
1990 ModestProtocol *store_proto;
1992 registry = modest_runtime_get_protocol_registry ();
1993 /* Use custom pages because no preset was specified: */
1994 transport_hostname = g_strdup (hildon_entry_get_text (HILDON_ENTRY (priv->entry_outgoingserver) ));
1996 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
1999 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2000 /* fallback to SMTP if none was specified */
2001 g_warning ("No transport protocol was specified for store %d (%s)",
2002 modest_protocol_get_type_id (store_proto),
2003 modest_protocol_get_display_name (store_proto));
2004 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
2007 modest_security_options_view_save_settings (
2008 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
2012 /* now we store the common transport account settings */
2013 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
2014 modest_server_account_settings_set_username (transport_settings, username);
2015 modest_server_account_settings_set_password (transport_settings, password);
2016 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
2018 g_object_unref (transport_settings);
2019 g_free (transport_hostname);
2021 fullname = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_name));
2022 email_address = hildon_entry_get_text (HILDON_ENTRY (priv->entry_user_email));
2023 modest_account_settings_set_fullname (priv->settings, fullname);
2024 modest_account_settings_set_email_address (priv->settings, email_address);
2025 /* we don't set retrieve type to preserve advanced settings if
2026 any. By default account settings are set to headers only */
2028 /* Save the connection-specific SMTP server accounts. */
2029 modest_account_settings_set_use_connection_specific_smtp
2031 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2033 display_name = get_entered_account_title (self);
2034 modest_account_settings_set_display_name (priv->settings, display_name);
2035 g_free (display_name);
2036 g_free (provider_id);