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 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
78 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
79 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
80 } ModestEasysetupWizardDialogServerChanges;
82 struct _ModestEasysetupWizardDialogPrivate
84 ModestPresets *presets;
86 /* Remember what fields the user edited manually to not prefill them
88 ModestEasysetupWizardDialogServerChanges server_changes;
90 /* Check if the user changes a field to show a confirmation dialog */
93 /* If we have a pending load of settings or not. */
94 gboolean pending_load_settings;
96 /* Used by derived widgets to query existing accounts,
97 * and to create new accounts: */
98 ModestAccountMgr *account_manager;
99 ModestAccountSettings *settings;
101 /* notebook pages: */
102 GtkWidget *page_welcome;
104 GtkWidget *page_account_details;
105 GtkWidget *account_country_picker;
106 GtkWidget *account_serviceprovider_picker;
107 GtkWidget *entry_account_title;
109 GtkWidget *page_user_details;
110 GtkWidget *entry_user_name;
111 GtkWidget *entry_user_username;
112 GtkWidget *entry_user_password;
113 GtkWidget *entry_user_email;
115 GtkWidget *page_complete_easysetup;
117 GtkWidget *page_custom_incoming;
118 GtkWidget *incoming_servertype_picker;
119 GtkWidget *caption_incoming;
120 GtkWidget *entry_incomingserver;
122 /* Security widgets */
123 GtkWidget *incoming_security;
124 GtkWidget *outgoing_security;
126 GtkWidget *page_custom_outgoing;
127 GtkWidget *entry_outgoingserver;
128 GtkWidget *checkbox_outgoing_smtp_specific;
129 GtkWidget *button_outgoing_smtp_servers;
131 GtkWidget *page_complete_customsetup;
133 ModestProtocolType last_plugin_protocol_selected;
134 GSList *missing_data_signals;
137 static void save_to_settings (ModestEasysetupWizardDialog *self);
138 static void real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next);
141 on_delete_event (GtkWidget *widget,
143 ModestEasysetupWizardDialog *wizard)
145 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
150 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
152 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
153 g_return_if_fail (priv != NULL);
158 modest_easysetup_wizard_dialog_dispose (GObject *object)
160 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
161 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
165 modest_easysetup_wizard_dialog_finalize (GObject *object)
167 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
168 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
170 if (priv->account_manager)
171 g_object_unref (G_OBJECT (priv->account_manager));
174 modest_presets_destroy (priv->presets);
177 g_object_unref (priv->settings);
179 if (priv->missing_data_signals) {
180 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
181 priv->missing_data_signals = NULL;
184 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
188 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
191 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
193 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
196 get_port_from_protocol (ModestProtocolType server_type,
197 gboolean alternate_port)
200 ModestProtocol *protocol;
201 ModestProtocolRegistry *protocol_registry;
203 protocol_registry = modest_runtime_get_protocol_registry ();
204 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, server_type);
206 if (alternate_port) {
207 server_port = modest_account_protocol_get_alternate_port (MODEST_ACCOUNT_PROTOCOL (protocol));
209 server_port = modest_account_protocol_get_port (MODEST_ACCOUNT_PROTOCOL (protocol));
215 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
217 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
219 /* Call the vfunc, which may be overridden by derived classes: */
220 if (klass->enable_buttons) {
221 GtkNotebook *notebook = NULL;
222 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
224 const gint current_page_num = gtk_notebook_get_current_page (notebook);
225 if (current_page_num == -1)
228 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
229 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
234 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
236 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
238 invoke_enable_buttons_vfunc(self);
242 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
244 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
246 invoke_enable_buttons_vfunc(self);
250 on_picker_button_value_changed (HildonPickerButton *widget, gpointer user_data)
252 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
254 invoke_enable_buttons_vfunc(self);
257 /** This is a convenience function to create a caption containing a mandatory widget.
258 * When the widget is edited, the enable_buttons() vfunc will be called.
261 create_caption_new_with_asterisk (ModestEasysetupWizardDialog *self,
266 HildonCaptionStatus flag)
268 GtkWidget *caption = NULL;
270 /* Note: Previously, the translated strings already contained the "*",
271 * Comment out this code if they do again.
273 /* Add a * character to indicate mandatory fields,
274 * as specified in our "Email UI Specification": */
275 if (flag == HILDON_CAPTION_MANDATORY) {
276 gchar* title = g_strdup_printf("%s*", value);
277 caption = hildon_caption_new (group, title, control, icon, flag);
281 caption = hildon_caption_new (group, value, control, icon, flag);
283 /* Connect to the appropriate changed signal for the widget,
284 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
286 if (GTK_IS_ENTRY (control)) {
287 g_signal_connect (G_OBJECT (control), "changed",
288 G_CALLBACK (on_caption_entry_changed), self);
291 else if (GTK_IS_COMBO_BOX (control)) {
292 g_signal_connect (G_OBJECT (control), "changed",
293 G_CALLBACK (on_caption_combobox_changed), self);
300 create_page_welcome (ModestEasysetupWizardDialog *self)
302 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
303 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
304 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
305 /* So that it is not truncated: */
306 gtk_widget_set_size_request (label, 600, -1);
307 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
308 gtk_widget_show (label);
309 gtk_widget_show (GTK_WIDGET (box));
310 return GTK_WIDGET (box);
314 on_account_country_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
316 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
318 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
322 /* Fill the providers picker, based on the selected country: */
323 if (priv->presets != NULL) {
324 gint mcc = modest_country_picker_get_active_country_mcc (
325 MODEST_COUNTRY_PICKER (priv->account_country_picker));
326 modest_provider_picker_fill (
327 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
332 on_account_serviceprovider_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
334 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
336 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
340 /* Fill the providers combo, based on the selected country: */
341 gchar* provider_id = modest_provider_picker_get_active_provider_id (
342 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
344 gchar* domain_name = NULL;
346 domain_name = modest_presets_get_domain (priv->presets, provider_id);
349 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
351 if (priv->entry_user_email)
352 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), domain_name);
354 g_free (domain_name);
356 g_free (provider_id);
360 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
362 modest_platform_information_banner (GTK_WIDGET (self), NULL,
363 _CS("ckdg_ib_maximum_characters_reached"));
367 create_page_account_details (ModestEasysetupWizardDialog *self)
370 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
371 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
372 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
374 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
375 gtk_widget_set_size_request (label, 600, -1);
376 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
377 gtk_widget_show (label);
379 /* Create a size group to be used by all captions.
380 * Note that HildonCaption does not create a default size group if we do not specify one.
381 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
382 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
384 /* The country widgets: */
385 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new ());
386 hildon_button_set_title (HILDON_BUTTON (priv->account_country_picker), _("mcen_fi_country"));
387 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
388 G_CALLBACK (on_picker_button_value_changed), self);
389 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
390 gtk_widget_show (priv->account_country_picker);
392 GtkWidget *separator = gtk_hseparator_new ();
393 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
394 gtk_widget_show (separator);
396 /* The service provider widgets: */
397 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new ());
398 hildon_button_set_title (HILDON_BUTTON (priv->account_serviceprovider_picker), _("mcen_fi_serviceprovider"));
399 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
400 G_CALLBACK (on_picker_button_value_changed), self);
401 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
402 gtk_widget_show (priv->account_serviceprovider_picker);
404 /* The description widgets: */
405 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
406 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
407 G_CALLBACK(on_easysetup_changed), self);
408 /* Do use auto-capitalization: */
409 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
410 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
412 /* Set a default account title, choosing one that does not already exist: */
413 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
414 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
415 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
416 priv->account_manager, default_account_name_start);
417 g_free (default_account_name_start);
418 default_account_name_start = NULL;
420 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title), default_account_name);
421 g_free (default_account_name);
422 default_account_name = NULL;
424 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
425 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
426 gtk_widget_show (priv->entry_account_title);
427 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
428 gtk_widget_show (caption);
430 /* Prevent the use of some characters in the account title,
431 * as required by our UI specification: */
432 GList *list_prevent = NULL;
433 list_prevent = g_list_append (list_prevent, "\\");
434 list_prevent = g_list_append (list_prevent, "/");
435 list_prevent = g_list_append (list_prevent, ":");
436 list_prevent = g_list_append (list_prevent, "*");
437 list_prevent = g_list_append (list_prevent, "?");
438 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
439 list_prevent = g_list_append (list_prevent, "“");
440 list_prevent = g_list_append (list_prevent, "<");
441 list_prevent = g_list_append (list_prevent, ">");
442 list_prevent = g_list_append (list_prevent, "|");
443 list_prevent = g_list_append (list_prevent, "^");
444 modest_validating_entry_set_unallowed_characters (
445 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
446 g_list_free (list_prevent);
448 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
449 modest_utils_on_entry_invalid_character, self);
451 /* Set max length as in the UI spec:
452 * The UI spec seems to want us to show a dialog if we hit the maximum. */
453 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
454 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
457 gtk_widget_show (GTK_WIDGET (box));
459 return GTK_WIDGET (box);
463 create_page_user_details (ModestEasysetupWizardDialog *self)
465 GtkSizeGroup* sizegroup;
467 ModestEasysetupWizardDialogPrivate *priv;
469 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
471 /* Create a size group to be used by all captions.
472 * Note that HildonCaption does not create a default size group if we do not specify one.
473 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
474 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
475 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
477 /* The name widgets: (use auto cap) */
478 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
479 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
480 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
482 /* Set max length as in the UI spec:
483 * The UI spec seems to want us to show a dialog if we hit the maximum. */
484 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
485 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
487 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
488 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
489 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
490 G_CALLBACK(on_easysetup_changed), self);
491 gtk_widget_show (priv->entry_user_name);
492 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
493 gtk_widget_show (caption);
495 /* Prevent the use of some characters in the name,
496 * as required by our UI specification: */
497 GList *list_prevent = NULL;
498 list_prevent = g_list_append (list_prevent, "<");
499 list_prevent = g_list_append (list_prevent, ">");
500 modest_validating_entry_set_unallowed_characters (
501 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
502 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
503 modest_utils_on_entry_invalid_character, self);
504 g_list_free (list_prevent);
506 /* The username widgets: */
507 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
508 /* Auto-capitalization is the default, so let's turn it off: */
509 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
510 HILDON_GTK_INPUT_MODE_FULL);
511 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
512 priv->entry_user_username,
513 NULL, HILDON_CAPTION_MANDATORY);
514 gtk_widget_show (priv->entry_user_username);
515 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
516 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
517 G_CALLBACK(on_easysetup_changed), self);
518 gtk_widget_show (caption);
520 /* Prevent the use of some characters in the username,
521 * as required by our UI specification: */
522 modest_validating_entry_set_unallowed_characters_whitespace (
523 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
524 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
525 modest_utils_on_entry_invalid_character, self);
527 /* Set max length as in the UI spec:
528 * The UI spec seems to want us to show a dialog if we hit the maximum. */
529 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
530 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
533 /* The password widgets: */
534 priv->entry_user_password = gtk_entry_new ();
535 /* Auto-capitalization is the default, so let's turn it off: */
536 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
537 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
538 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
539 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
540 caption = create_caption_new_with_asterisk (self, sizegroup,
541 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
542 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
543 G_CALLBACK(on_easysetup_changed), self);
544 gtk_widget_show (priv->entry_user_password);
545 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
546 gtk_widget_show (caption);
548 /* The email address widgets: */
549 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
550 /* Auto-capitalization is the default, so let's turn it off: */
551 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
552 caption = create_caption_new_with_asterisk (self, sizegroup,
553 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
554 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
555 gtk_widget_show (priv->entry_user_email);
556 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
557 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
558 G_CALLBACK(on_easysetup_changed), self);
559 gtk_widget_show (caption);
561 /* Set max length as in the UI spec:
562 * The UI spec seems to want us to show a dialog if we hit the maximum. */
563 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
564 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
568 gtk_widget_show (GTK_WIDGET (box));
570 return GTK_WIDGET (box);
574 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
576 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
578 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
579 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
580 gtk_widget_set_size_request (label, 600, -1);
581 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
582 /* The documentation for gtk_label_set_line_wrap() says that we must
583 * call gtk_widget_set_size_request() with a hard-coded width,
584 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
585 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
586 gtk_widget_show (label);
588 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
589 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
590 gtk_widget_set_size_request (label, 600, -1);
592 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
593 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
594 gtk_widget_show (label);
596 gtk_widget_show (GTK_WIDGET (box));
597 return GTK_WIDGET (box);
600 /** Change the caption title for the incoming server,
601 * as specified in the UI spec:
604 update_incoming_server_title (ModestEasysetupWizardDialog *self)
606 ModestEasysetupWizardDialogPrivate* priv;
607 ModestProtocolType protocol_type;
608 ModestProtocolRegistry *protocol_registry;
610 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
611 protocol_registry = modest_runtime_get_protocol_registry ();
613 protocol_type = modest_servertype_picker_get_active_servertype (
614 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
616 /* This could happen when the combo box has still no active iter */
617 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
618 gchar* incomingserver_title;
619 const gchar *protocol_display_name;
621 protocol_display_name = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type));
623 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), protocol_display_name);
624 g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
625 g_free(incomingserver_title);
629 /** Change the caption title for the incoming server,
630 * as specified in the UI spec:
633 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
635 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
636 ModestServertypePicker *server_type_picker;
637 ModestProtocolType protocol_type;
638 ModestSecurityOptionsView *view;
641 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
643 modest_servertype_picker_get_active_servertype (server_type_picker);
645 /* Fill the combo with appropriately titled choices for all
647 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
648 modest_security_options_view_set_server_type (view, protocol_type);
652 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
654 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
655 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
656 ModestServertypePicker *picker;
657 ModestProtocolType protocol_type;
662 update_incoming_server_title (self);
664 /* Update security options if needed */
665 picker = MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
666 protocol_type = modest_servertype_picker_get_active_servertype (picker);
667 update_incoming_server_security_choices (self);
668 gtk_widget_show (priv->incoming_security);
670 set_default_custom_servernames (self);
674 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
676 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
677 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
679 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
683 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
685 ModestProtocolRegistry *protocol_registry;
686 ModestEasysetupWizardDialogPrivate* priv;
688 GtkWidget *scrolled_window;
690 GtkSizeGroup *sizegroup;
692 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
693 protocol_registry = modest_runtime_get_protocol_registry ();
695 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
696 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
698 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
700 GTK_POLICY_AUTOMATIC);
702 /* Show note that account type cannot be changed in future: */
703 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
704 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
705 gtk_widget_set_size_request (label, 600, -1);
706 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
707 gtk_widget_show (label);
709 /* Create a size group to be used by all captions.
710 * Note that HildonCaption does not create a default size group if we do not specify one.
711 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
712 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
714 /* The incoming server widgets: */
715 priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (TRUE));
716 hildon_button_set_title (HILDON_BUTTON (priv->incoming_servertype_picker), _("mcen_li_emailsetup_type"));
717 g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
718 G_CALLBACK (on_picker_button_value_changed), self);
719 gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
720 gtk_widget_show (priv->incoming_servertype_picker);
722 priv->entry_incomingserver = gtk_entry_new ();
723 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
724 /* Auto-capitalization is the default, so let's turn it off: */
725 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
726 set_default_custom_servernames (self);
728 /* The caption title will be updated in update_incoming_server_title().
729 * so this default text will never be seen: */
730 /* (Note: Changing the title seems pointless. murrayc) */
731 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
733 priv->entry_incomingserver,
734 NULL, HILDON_CAPTION_MANDATORY);
735 update_incoming_server_title (self);
736 gtk_widget_show (priv->entry_incomingserver);
737 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
738 gtk_widget_show (priv->caption_incoming);
740 /* Change the caption title when the servertype changes,
741 * as in the UI spec: */
742 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
744 G_CALLBACK (on_servertype_selector_changed), self);
746 /* Remember when the servername was changed manually: */
747 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
748 G_CALLBACK (on_entry_incoming_servername_changed), self);
750 /* The secure connection widgets. These are only valid for
751 protocols with security */
752 priv->incoming_security =
753 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
755 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
756 FALSE, FALSE, MODEST_MARGIN_HALF);
758 /* Set default selection */
759 modest_servertype_picker_set_active_servertype (
760 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
761 MODEST_PROTOCOLS_STORE_POP);
763 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
764 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
765 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
766 gtk_widget_show (GTK_WIDGET (box));
767 gtk_widget_show (scrolled_window);
769 return GTK_WIDGET (scrolled_window);
773 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
775 GtkWidget *widget = GTK_WIDGET (user_data);
777 /* Enable the widget only if the toggle button is active: */
778 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
779 gtk_widget_set_sensitive (widget, enable);
782 /* Make the sensitivity of a widget depend on a toggle button.
785 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
787 g_signal_connect (G_OBJECT (button), "toggled",
788 G_CALLBACK (on_toggle_button_changed), widget);
790 /* Set the starting sensitivity: */
791 on_toggle_button_changed (button, widget);
795 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
797 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
798 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
799 GtkWidget *specific_window;
801 /* We set dirty here because setting it depending on the connection specific dialog
805 /* Create the window, if necessary: */
806 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
807 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
809 /* Show the window */
810 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window));
811 gtk_widget_show (specific_window);
815 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
817 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
818 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
819 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
823 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
825 ModestEasysetupWizardDialogPrivate *priv;
826 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
828 /* Create a size group to be used by all captions.
829 * Note that HildonCaption does not create a default size group if we do not specify one.
830 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
831 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
833 /* The outgoing server widgets: */
834 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
835 priv->entry_outgoingserver = gtk_entry_new ();
836 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
837 G_CALLBACK (on_easysetup_changed), self);
838 /* Auto-capitalization is the default, so let's turn it off: */
839 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
840 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
841 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
842 gtk_widget_show (priv->entry_outgoingserver);
843 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
844 gtk_widget_show (caption);
845 set_default_custom_servernames (self);
847 /* The secure connection widgets. These are only valid for
848 protocols with security */
849 priv->outgoing_security =
850 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
852 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
853 FALSE, FALSE, MODEST_MARGIN_HALF);
854 gtk_widget_show (priv->outgoing_security);
856 GtkWidget *separator = gtk_hseparator_new ();
857 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
858 gtk_widget_show (separator);
860 /* connection-specific checkbox: */
861 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
862 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
864 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
865 G_CALLBACK (on_easysetup_changed), self);
867 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
868 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
869 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
870 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
871 gtk_widget_show (caption);
873 /* Connection-specific SMTP-Severs Edit button: */
874 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
875 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
876 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
877 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
878 gtk_widget_show (priv->button_outgoing_smtp_servers);
879 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
880 gtk_widget_show (caption);
882 /* Only enable the button when the checkbox is checked: */
883 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
884 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
886 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
887 G_CALLBACK (on_button_outgoing_smtp_servers), self);
889 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
890 G_CALLBACK (on_entry_outgoing_servername_changed), self);
893 gtk_widget_show (GTK_WIDGET (box));
895 return GTK_WIDGET (box);
899 show_advanced_edit(gpointer user_data)
901 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
902 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
905 /* Show the Account Settings window: */
906 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
907 if (priv->pending_load_settings) {
908 save_to_settings (self);
909 priv->pending_load_settings = FALSE;
911 modest_account_settings_dialog_load_settings (dialog, priv->settings);
913 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
915 response = gtk_dialog_run (GTK_DIALOG (dialog));
917 gtk_widget_destroy (GTK_WIDGET (dialog));
919 return FALSE; /* Do not call this timeout callback again. */
923 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
925 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
927 /* Show the Account Settings window: */
928 show_advanced_edit(self);
931 create_page_complete_custom (ModestEasysetupWizardDialog *self)
933 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
934 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
935 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
936 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
937 gtk_widget_set_size_request (label, 600, -1);
938 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
939 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
940 gtk_widget_show (label);
942 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
943 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
944 gtk_widget_set_size_request (label, 600, -1);
945 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
946 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
947 gtk_widget_show (label);
949 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
950 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
951 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
952 gtk_widget_show (button_edit);
953 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
954 gtk_widget_show (caption);
956 g_signal_connect (G_OBJECT (button_edit), "clicked",
957 G_CALLBACK (on_button_edit_advanced_settings), self);
959 gtk_widget_show (GTK_WIDGET (box));
960 return GTK_WIDGET (box);
967 on_response (ModestWizardDialog *wizard_dialog,
971 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
973 invoke_enable_buttons_vfunc (self);
977 on_response_before (ModestWizardDialog *wizard_dialog,
981 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
982 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
983 if (response_id == GTK_RESPONSE_CANCEL) {
984 /* This is mostly copied from
985 * src/maemo/modest-account-settings-dialog.c */
987 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
988 _("imum_nc_wizard_confirm_lose_changes")));
989 /* TODO: These button names will be ambiguous, and not
990 * specified in the UI specification. */
992 const gint dialog_response = gtk_dialog_run (dialog);
993 gtk_widget_destroy (GTK_WIDGET (dialog));
995 if (dialog_response != GTK_RESPONSE_OK) {
996 /* Don't let the dialog close */
997 g_signal_stop_emission_by_name (wizard_dialog, "response");
1003 typedef struct IdleData {
1004 ModestEasysetupWizardDialog *dialog;
1005 ModestPresets *presets;
1009 presets_idle (gpointer userdata)
1011 IdleData *idle_data = (IdleData *) userdata;
1012 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1013 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1015 g_assert (idle_data->presets);
1017 gdk_threads_enter ();
1019 priv->presets = idle_data->presets;
1021 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1022 /* gint mcc = get_default_country_code(); */
1024 /* Fill the combo in an idle call, as it takes a lot of time */
1025 modest_country_picker_load_data(
1026 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1027 /* connect to country picker's changed signal, so we can fill the provider picker: */
1028 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1029 (HILDON_PICKER_BUTTON (priv->account_country_picker))),
1031 G_CALLBACK (on_account_country_selector_changed), self);
1033 modest_country_picker_set_active_country_locale (
1034 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1035 mcc = modest_country_picker_get_active_country_mcc (
1036 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1037 modest_provider_picker_fill (
1038 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1039 priv->presets, mcc);
1040 /* connect to providers picker's changed signal, so we can fill the email address: */
1041 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
1042 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
1044 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
1046 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1049 priv->dirty = FALSE;
1051 g_object_unref (idle_data->dialog);
1054 gdk_threads_leave ();
1060 presets_loader (gpointer userdata)
1062 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1063 ModestPresets *presets = NULL;
1064 IdleData *idle_data;
1066 const gchar* path = NULL;
1067 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1068 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1070 if (access(path1, R_OK) == 0)
1072 else if (access(path2, R_OK) == 0)
1075 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1076 __FUNCTION__, path1, path2);
1080 presets = modest_presets_new (path);
1082 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1086 idle_data = g_new0 (IdleData, 1);
1087 idle_data->dialog = self;
1088 idle_data->presets = presets;
1090 g_idle_add (presets_idle, idle_data);
1096 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1101 /* Append page and set attributes */
1102 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1103 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1104 "tab-expand", TRUE, "tab-fill", TRUE,
1106 gtk_widget_show (page);
1110 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1112 priv->page_user_details = NULL;
1113 priv->entry_user_name = NULL;
1114 priv->entry_user_username = NULL;
1115 priv->entry_user_password = NULL;
1116 priv->entry_user_email = NULL;
1120 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1122 priv->page_custom_incoming = NULL;
1123 priv->incoming_servertype_picker = NULL;
1124 priv->caption_incoming = NULL;
1125 priv->entry_incomingserver = NULL;
1126 priv->entry_user_email = NULL;
1127 priv->incoming_security = NULL;
1131 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1133 priv->page_custom_outgoing = NULL;
1134 priv->entry_outgoingserver = NULL;
1135 priv->checkbox_outgoing_smtp_specific = NULL;
1136 priv->button_outgoing_smtp_servers = NULL;
1137 priv->outgoing_security = NULL;
1141 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1143 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1145 /* Create the notebook to be used by the ModestWizardDialog base class:
1146 * Each page of the notebook will be a page of the wizard: */
1147 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1149 /* Set the notebook used by the ModestWizardDialog base class: */
1150 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1152 /* Set the wizard title:
1153 * The actual window title will be a combination of this and the page's tab label title. */
1154 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1156 /* Read in the information about known service providers: */
1157 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1159 /* The server fields did not have been manually changed yet */
1160 priv->server_changes = 0;
1161 priv->pending_load_settings = TRUE;
1163 /* Get the account manager object,
1164 * so we can check for existing accounts,
1165 * and create new accounts: */
1166 priv->account_manager = modest_runtime_get_account_mgr ();
1167 g_object_ref (priv->account_manager);
1169 /* Initialize fields */
1170 priv->page_welcome = create_page_welcome (self);
1171 priv->page_account_details = create_page_account_details (self);
1173 init_user_page (priv);
1174 init_incoming_page (priv);
1175 init_outgoing_page (priv);
1177 priv->page_complete_easysetup = NULL;
1178 priv->page_complete_customsetup = NULL;
1179 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1180 priv->missing_data_signals = NULL;
1182 /* Add the common pages */
1183 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1184 _("mcen_ti_emailsetup_welcome"));
1185 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1186 _("mcen_ti_accountdetails"));
1188 /* Connect to the dialog's response signal so we can enable/disable buttons
1189 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1190 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1191 * so that we can be enable/disable after ModestWizardDialog has done its own
1192 * enabling/disabling of buttons.
1194 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1195 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1197 * It's not enough to connect to the notebook's switch-page signal, because
1198 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1199 * _after_ switching the page (understandably).
1200 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1201 * then gtk_notebook_get_current_page() would return an incorrect value.)
1203 g_signal_connect_after (G_OBJECT (self), "response",
1204 G_CALLBACK (on_response), self);
1206 /* This is to show a confirmation dialog when the user hits cancel */
1207 g_signal_connect (G_OBJECT (self), "response",
1208 G_CALLBACK (on_response_before), self);
1210 g_signal_connect (G_OBJECT (self), "delete-event",
1211 G_CALLBACK (on_delete_event), self);
1213 /* Reset dirty, because there was no user input until now */
1214 priv->dirty = FALSE;
1216 /* When this window is shown, hibernation should not be possible,
1217 * because there is no sensible way to save the state: */
1218 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1219 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1221 /* Load provider presets */
1222 g_object_ref (self);
1223 g_thread_create (presets_loader, self, FALSE, NULL);
1225 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1226 modest_maemo_utils_get_osso_context());
1228 priv->settings = modest_account_settings_new ();
1231 ModestEasysetupWizardDialog*
1232 modest_easysetup_wizard_dialog_new (void)
1235 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1239 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1241 ModestEasysetupWizardDialogPrivate *priv;
1242 GtkNotebook *notebook = NULL;
1244 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1247 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1249 if (!priv->page_user_details) {
1250 priv->page_user_details = create_page_user_details (self);
1253 /* Create the custom pages: */
1254 if(!(priv->page_custom_incoming)) {
1255 priv->page_custom_incoming = create_page_custom_incoming (self);
1258 /* TODO: only if needed */
1259 if(!(priv->page_custom_outgoing)) {
1260 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1263 if(!(priv->page_complete_customsetup)) {
1264 priv->page_complete_customsetup = create_page_complete_custom (self);
1267 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1268 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1269 _("mcen_ti_emailsetup_userdetails"));
1271 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1272 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1273 _("mcen_ti_emailsetup_incomingdetails"));
1275 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1276 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1277 _("mcen_ti_emailsetup_outgoingdetails"));
1279 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1280 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1281 _("mcen_ti_emailsetup_complete"));
1283 /* This is unnecessary with GTK+ 2.10: */
1284 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1288 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1290 ModestEasysetupWizardDialogPrivate *priv;
1291 GtkNotebook *notebook = NULL;
1293 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1296 /* Create the easysetup-specific pages: */
1297 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1298 if(!priv->page_complete_easysetup)
1299 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1301 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1302 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1303 _("mcen_ti_emailsetup_complete"));
1305 /* This is unnecessary with GTK+ 2.10: */
1306 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1311 remove_non_common_tabs (GtkNotebook *notebook,
1312 gboolean remove_user_details)
1315 /* The first 2 tabs are the common ones (welcome tab and the
1316 providers tab), so we always remove starting from the
1319 starting_tab = (remove_user_details) ? 2 : 3;
1320 while (gtk_notebook_get_n_pages (notebook) > starting_tab)
1321 gtk_notebook_remove_page (notebook, -1);
1325 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1329 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1332 /* After the user details page,
1333 * the following pages depend on whether "Other" was chosen
1334 * in the provider combobox on the account page
1337 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1339 ModestEasysetupWizardDialogPrivate *priv;
1340 ModestProviderPicker *picker;
1341 ModestProviderPickerIdType id_type;
1342 GtkNotebook *notebook;
1344 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1345 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1346 id_type = modest_provider_picker_get_active_id_type (picker);
1347 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1349 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1350 /* "Other..." was selected: */
1352 /* If we come from a rollbacked easysetup */
1353 if (priv->page_complete_easysetup) {
1354 remove_non_common_tabs (notebook, FALSE);
1355 priv->page_complete_easysetup = NULL;
1358 /* If we come from a rollbacked plugin protocol setup */
1359 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1360 remove_non_common_tabs (notebook, TRUE);
1361 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1362 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1363 priv->missing_data_signals = NULL;
1366 create_subsequent_customsetup_pages (self);
1368 /* If we come from a rollbacked custom setup */
1369 if (priv->page_custom_incoming) {
1370 remove_non_common_tabs (notebook, TRUE);
1371 init_user_page (priv);
1372 init_incoming_page (priv);
1373 init_outgoing_page (priv);
1374 init_user_page (priv);
1375 priv->page_complete_customsetup = NULL;
1378 /* It's a pluggable protocol and not a provider with presets */
1379 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1380 ModestProtocol *protocol;
1382 ModestProtocolType proto_type;
1385 /* If we come from a rollbacked easy setup */
1386 if (priv->last_plugin_protocol_selected ==
1387 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1388 priv->page_complete_easysetup) {
1389 remove_non_common_tabs (notebook, TRUE);
1390 init_user_page (priv);
1391 priv->page_complete_easysetup = NULL;
1394 proto_name = modest_provider_picker_get_active_provider_id (picker);
1395 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1396 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1398 proto_type = modest_protocol_get_type_id (protocol);
1400 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1401 proto_type != priv->last_plugin_protocol_selected) {
1402 ModestPairList *tabs;
1405 /* Remember the last selected plugin protocol */
1406 priv->last_plugin_protocol_selected = proto_type;
1409 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1410 tmp = (GSList *) tabs;
1412 ModestPair *pair = (ModestPair *) tmp->data;
1413 modest_easysetup_wizard_dialog_append_page (notebook,
1414 GTK_WIDGET (pair->second),
1415 (const gchar *) pair->first);
1417 /* Connect signals */
1418 priv->missing_data_signals =
1419 modest_signal_mgr_connect (priv->missing_data_signals,
1420 G_OBJECT (pair->second),
1421 "missing-mandatory-data",
1422 G_CALLBACK (on_missing_mandatory_data),
1425 g_free (pair->first);
1426 tmp = g_slist_next (tmp);
1427 /* Critical: if you don't show the page then the dialog will ignore it */
1428 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1430 modest_pair_list_free (tabs);
1432 g_free (proto_name);
1434 if (priv->last_plugin_protocol_selected !=
1435 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1436 remove_non_common_tabs (notebook, TRUE);
1437 init_user_page (priv);
1438 priv->page_complete_easysetup = NULL;
1439 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1440 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1441 priv->missing_data_signals = NULL;
1443 if (!priv->page_user_details) {
1444 priv->page_user_details = create_page_user_details (self);
1445 modest_easysetup_wizard_dialog_append_page (notebook,
1446 priv->page_user_details,
1447 _("mcen_ti_emailsetup_userdetails"));
1451 /* Create the easysetup pages: */
1452 create_subsequent_easysetup_pages (self);
1458 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1460 const gchar* hostname = NULL;
1463 ModestProtocolRegistry *protocol_registry;
1464 ModestProtocol *protocol;
1469 at = g_utf8_strchr (email_address, -1, '@');
1470 if (!at || (g_utf8_strlen (at, -1) < 2))
1473 domain = g_utf8_next_char (at);
1477 protocol_registry = modest_runtime_get_protocol_registry ();
1478 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1480 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1481 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1482 hostname = modest_protocol_get_name (protocol);
1488 return g_strdup_printf ("%s.%s", hostname, domain);
1492 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1494 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1496 if (!priv->entry_incomingserver)
1499 /* Set a default domain for the server, based on the email address,
1500 * if no server name was already specified.
1502 if (priv->entry_user_email
1503 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1504 const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
1505 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1507 /* This could happen when the combo box has still no active iter */
1508 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1509 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1510 gchar* servername = util_get_default_servername_from_email_address (email_address,
1513 /* Do not set the INCOMING_CHANGED flag because of this edit */
1514 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1515 gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
1516 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1518 g_free (servername);
1522 /* Set a default domain for the server, based on the email address,
1523 * if no server name was already specified.
1525 if (!priv->entry_outgoingserver)
1528 if (priv->entry_user_email
1529 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1530 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1532 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1534 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1535 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1536 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), servername);
1537 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1539 g_free (servername);
1544 get_entered_account_title (ModestEasysetupWizardDialog *self)
1546 ModestEasysetupWizardDialogPrivate *priv;
1547 const gchar* account_title;
1549 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1550 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
1552 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1555 /* Strip it of whitespace at the start and end: */
1556 gchar *result = g_strdup (account_title);
1557 result = g_strstrip (result);
1562 if (g_utf8_strlen (result, -1) == 0) {
1572 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1574 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1575 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1576 ModestProtocolRegistry *protocol_registry;
1578 protocol_registry = modest_runtime_get_protocol_registry ();
1580 /* if are browsing pages previous to the last one, then we have pending settings in
1582 if (next_page != NULL)
1583 priv->pending_load_settings = TRUE;
1585 /* Do extra validation that couldn't be done for every key press,
1586 * either because it was too slow,
1587 * or because it requires interaction:
1589 if (current_page == priv->page_account_details) {
1590 /* Check that the title is not already in use: */
1591 gchar* account_title = get_entered_account_title (self);
1595 /* Aavoid a clash with an existing display name: */
1596 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1597 priv->account_manager, account_title);
1600 /* Warn the user via a dialog: */
1601 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1606 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1607 create_subsequent_pages (self);
1609 } else if (current_page == priv->page_user_details) {
1610 /* Check that the email address is valud: */
1611 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1612 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1615 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1616 /* Warn the user via a dialog: */
1617 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1619 /* Return focus to the email address entry: */
1620 gtk_widget_grab_focus (priv->entry_user_email);
1621 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1627 if (next_page == priv->page_custom_incoming) {
1628 set_default_custom_servernames (self);
1629 } else if (next_page == priv->page_custom_outgoing) {
1630 set_default_custom_servernames (self);
1632 /* Check if the server supports secure authentication */
1633 /* if (modest_security_options_view_auth_check (security_options)) */
1634 /* if (!check_has_supported_auth_methods (self)) */
1636 gtk_widget_show (priv->outgoing_security);
1639 /* If this is the last page, and this is a click on Finish,
1640 * then attempt to create the dialog.
1643 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1645 if (priv->pending_load_settings) {
1646 save_to_settings (self);
1649 /* We check if there's already another account with the same configuration */
1650 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1651 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1655 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1662 static gboolean entry_is_empty (GtkWidget *entry)
1667 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1668 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1671 /* Strip it of whitespace at the start and end: */
1672 gchar *stripped = g_strdup (text);
1673 stripped = g_strstrip (stripped);
1678 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1686 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1688 GtkNotebook *notebook = NULL;
1689 gboolean is_finish_tab;
1691 ModestEasysetupWizardDialogPrivate *priv;
1694 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1695 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
1697 /* Disable the Finish button until we are on the last page,
1698 * because HildonWizardDialog enables this for all but the
1700 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1701 is_finish_tab = ((current == priv->page_complete_easysetup) ||
1702 (current == priv->page_complete_customsetup));
1704 if (is_finish_tab) {
1705 /* Disable Next on the last page no matter what the
1707 enable_next = FALSE;
1709 /* Not the last one */
1710 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1711 MODEST_WIZARD_DIALOG_FINISH,
1715 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1716 MODEST_WIZARD_DIALOG_NEXT,
1721 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1723 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1724 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1726 gboolean enable_next = TRUE;
1727 if (current_page == priv->page_welcome) {
1729 } else if (current_page == priv->page_account_details) {
1730 /* The account details title is mandatory: */
1731 if (entry_is_empty(priv->entry_account_title))
1732 enable_next = FALSE;
1733 } else if (current_page == priv->page_user_details) {
1734 /* The user details username is mandatory: */
1735 if (entry_is_empty(priv->entry_user_username))
1736 enable_next = FALSE;
1738 /* The user details email address is mandatory: */
1739 if (enable_next && entry_is_empty (priv->entry_user_email))
1740 enable_next = FALSE;
1741 } else if (current_page == priv->page_custom_incoming) {
1742 /* The custom incoming server is mandatory: */
1743 if (entry_is_empty(priv->entry_incomingserver))
1744 enable_next = FALSE;
1745 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1746 enable_next = !modest_easysetup_wizard_page_validate (
1747 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1750 /* Enable/disable buttons */
1751 real_enable_buttons (dialog, enable_next);
1755 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1757 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1758 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1761 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1762 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1764 /* Provide a vfunc implementation so we can decide
1765 * when to enable/disable the prev/next buttons.
1767 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1768 base_klass->before_next = on_before_next;
1769 base_klass->enable_buttons = on_enable_buttons;
1774 * @self: a #ModestEasysetupWizardDialog
1776 * takes information from all the wizard and stores it in settings
1779 save_to_settings (ModestEasysetupWizardDialog *self)
1781 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1784 gchar* display_name;
1785 const gchar *username, *password;
1786 gchar *store_hostname, *transport_hostname;
1787 guint store_port, transport_port;
1788 ModestProtocolRegistry *protocol_registry;
1789 ModestProtocolType store_protocol, transport_protocol;
1790 ModestProtocolType store_security, transport_security;
1791 ModestProtocolType store_auth_protocol, transport_auth_protocol;
1792 ModestServerAccountSettings *store_settings, *transport_settings;
1793 const gchar *fullname, *email_address;
1794 ModestProviderPicker *picker;
1795 ModestProviderPickerIdType id_type;
1797 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1798 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1799 protocol_registry = modest_runtime_get_protocol_registry ();
1801 /* Get details from the specified presets: */
1802 id_type = modest_provider_picker_get_active_id_type (picker);
1803 provider_id = modest_provider_picker_get_active_provider_id (picker);
1805 /* Let the plugin save the settings. We do a return in order
1806 to save an indentation level */
1807 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1808 ModestProtocol *protocol;
1810 protocol = modest_protocol_registry_get_protocol_by_name (
1811 modest_runtime_get_protocol_registry (),
1812 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1815 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1816 gint n_pages, i = 0;
1817 GtkNotebook *notebook;
1818 GList *wizard_pages = NULL;
1820 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1821 n_pages = gtk_notebook_get_n_pages (notebook);
1822 for (i = 0; i < n_pages; i++) {
1823 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1824 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1825 wizard_pages = g_list_append (wizard_pages, page);
1827 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1830 g_list_free (wizard_pages);
1832 g_warning ("The selected protocol is a plugin protocol "//
1833 "but it's not a ModestAccountProtocol");
1839 /* username and password (for both incoming and outgoing): */
1840 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1841 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1843 store_settings = modest_account_settings_get_store_settings (priv->settings);
1844 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1846 /* Incoming server: */
1847 /* Note: We need something as default for the transport store protocol values,
1848 * or modest_account_mgr_add_server_account will fail. */
1850 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1851 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1852 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1855 ModestProtocolType store_provider_server_type;
1856 gboolean store_provider_use_alternate_port;
1858 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1861 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1864 store_security = modest_presets_get_info_server_security (priv->presets,
1867 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
1870 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
1874 /* We don't check for SMTP here as that is impossible for an incoming server. */
1875 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1876 store_protocol = MODEST_PROTOCOLS_STORE_POP;
1878 store_protocol = store_provider_server_type;
1880 /* we check if there is a *special* port */
1881 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1882 if (special_port != 0)
1883 store_port = special_port;
1885 store_port = get_port_from_protocol(store_provider_server_type, store_security);
1887 modest_server_account_settings_set_security_protocol (store_settings,
1889 modest_server_account_settings_set_auth_protocol (store_settings,
1890 store_auth_protocol);
1891 if (store_port != 0)
1892 modest_server_account_settings_set_port (store_settings, store_port);
1894 /* Use custom pages because no preset was specified: */
1895 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));
1896 store_protocol = modest_servertype_picker_get_active_servertype (
1897 MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
1899 modest_security_options_view_save_settings (
1900 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1904 /* now we store the common store account settings */
1905 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1906 modest_server_account_settings_set_username (store_settings, username);
1907 modest_server_account_settings_set_password (store_settings, password);
1908 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1910 g_object_unref (store_settings);
1911 g_free (store_hostname);
1913 /* Outgoing server: */
1914 transport_hostname = NULL;
1915 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1916 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1917 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1921 ModestProtocolType transport_provider_server_type;
1922 ModestProtocolType transport_provider_security;
1925 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1926 FALSE /* transport */);
1928 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1930 FALSE /* transport */);
1931 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1933 FALSE /* transport */);
1935 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1936 transport_protocol = transport_provider_server_type;
1937 transport_security = transport_provider_security;
1938 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
1939 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1940 /* we check if there is a *special* port */
1941 special_port = modest_presets_get_port (priv->presets, provider_id,
1942 FALSE /* transport */);
1943 if (special_port != 0)
1944 transport_port = special_port;
1946 transport_port = 465;
1947 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
1949 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1950 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1953 modest_server_account_settings_set_security_protocol (transport_settings,
1954 transport_security);
1955 modest_server_account_settings_set_auth_protocol (transport_settings,
1956 transport_auth_protocol);
1957 if (transport_port != 0)
1958 modest_server_account_settings_set_port (transport_settings,
1961 ModestProtocolRegistry *registry;
1962 ModestProtocol *store_proto;
1964 registry = modest_runtime_get_protocol_registry ();
1965 /* Use custom pages because no preset was specified: */
1966 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
1968 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
1971 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1972 /* fallback to SMTP if none was specified */
1973 g_warning ("No transport protocol was specified for store %d (%s)",
1974 modest_protocol_get_type_id (store_proto),
1975 modest_protocol_get_display_name (store_proto));
1976 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
1979 modest_security_options_view_save_settings (
1980 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1984 /* now we store the common transport account settings */
1985 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1986 modest_server_account_settings_set_username (transport_settings, username);
1987 modest_server_account_settings_set_password (transport_settings, password);
1988 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1990 g_object_unref (transport_settings);
1991 g_free (transport_hostname);
1993 fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1994 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1995 modest_account_settings_set_fullname (priv->settings, fullname);
1996 modest_account_settings_set_email_address (priv->settings, email_address);
1997 /* we don't set retrieve type to preserve advanced settings if
1998 any. By default account settings are set to headers only */
2000 /* Save the connection-specific SMTP server accounts. */
2001 modest_account_settings_set_use_connection_specific_smtp
2003 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2005 display_name = get_entered_account_title (self);
2006 modest_account_settings_set_display_name (priv->settings, display_name);
2007 g_free (display_name);