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/gtkcombobox.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkbutton.h>
40 #include <gtk/gtkcheckbutton.h>
41 #include <gtk/gtkmessagedialog.h>
42 #include <gtk/gtkseparator.h>
43 #include "modest-country-picker.h"
44 #include "modest-provider-picker.h"
45 #include "modest-easysetup-servertype-combo-box.h"
46 #include "widgets/modest-validating-entry.h"
47 #include "modest-text-utils.h"
48 #include "modest-conf.h"
49 #include "modest-defs.h"
50 #include "modest-account-mgr.h"
51 #include "modest-signal-mgr.h"
52 #include "modest-account-mgr-helpers.h"
53 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
54 #include "modest-connection-specific-smtp-window.h"
55 #include "widgets/modest-ui-constants.h"
56 #include "widgets/modest-default-account-settings-dialog.h"
57 #include "widgets/modest-easysetup-wizard-page.h"
58 #include "modest-maemo-utils.h"
59 #include "modest-utils.h"
60 #include "modest-hildon-includes.h"
61 #include "modest-maemo-security-options-view.h"
62 #include <modest-account-protocol.h>
64 /* Include config.h so that _() works: */
69 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
71 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
72 MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
73 ModestEasysetupWizardDialogPrivate))
75 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
79 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
80 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
81 } ModestEasysetupWizardDialogServerChanges;
83 struct _ModestEasysetupWizardDialogPrivate
85 ModestPresets *presets;
87 /* Remember what fields the user edited manually to not prefill them
89 ModestEasysetupWizardDialogServerChanges server_changes;
91 /* Check if the user changes a field to show a confirmation dialog */
94 /* If we have a pending load of settings or not. */
95 gboolean pending_load_settings;
97 /* Used by derived widgets to query existing accounts,
98 * and to create new accounts: */
99 ModestAccountMgr *account_manager;
100 ModestAccountSettings *settings;
102 /* notebook pages: */
103 GtkWidget *page_welcome;
105 GtkWidget *page_account_details;
106 GtkWidget *account_country_picker;
107 GtkWidget *account_serviceprovider_picker;
108 GtkWidget *entry_account_title;
110 GtkWidget *page_user_details;
111 GtkWidget *entry_user_name;
112 GtkWidget *entry_user_username;
113 GtkWidget *entry_user_password;
114 GtkWidget *entry_user_email;
116 GtkWidget *page_complete_easysetup;
118 GtkWidget *page_custom_incoming;
119 GtkWidget *combo_incoming_servertype;
120 GtkWidget *caption_incoming;
121 GtkWidget *entry_incomingserver;
123 /* Security widgets */
124 GtkWidget *incoming_security;
125 GtkWidget *outgoing_security;
127 GtkWidget *page_custom_outgoing;
128 GtkWidget *entry_outgoingserver;
129 GtkWidget *combo_outgoing_security;
130 GtkWidget *combo_outgoing_auth;
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_combo_servertype_changed(GtkComboBox *combobox, 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_caption_new_with_asterisk (ModestEasysetupWizardDialog *self,
269 HildonCaptionStatus flag)
271 GtkWidget *caption = NULL;
273 /* Note: Previously, the translated strings already contained the "*",
274 * Comment out this code if they do again.
276 /* Add a * character to indicate mandatory fields,
277 * as specified in our "Email UI Specification": */
278 if (flag == HILDON_CAPTION_MANDATORY) {
279 gchar* title = g_strdup_printf("%s*", value);
280 caption = hildon_caption_new (group, title, control, icon, flag);
284 caption = hildon_caption_new (group, value, control, icon, flag);
286 /* Connect to the appropriate changed signal for the widget,
287 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
289 if (GTK_IS_ENTRY (control)) {
290 g_signal_connect (G_OBJECT (control), "changed",
291 G_CALLBACK (on_caption_entry_changed), self);
294 else if (GTK_IS_COMBO_BOX (control)) {
295 g_signal_connect (G_OBJECT (control), "changed",
296 G_CALLBACK (on_caption_combobox_changed), self);
303 create_page_welcome (ModestEasysetupWizardDialog *self)
305 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
306 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
307 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
308 /* So that it is not truncated: */
309 gtk_widget_set_size_request (label, 600, -1);
310 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
311 gtk_widget_show (label);
312 gtk_widget_show (GTK_WIDGET (box));
313 return GTK_WIDGET (box);
317 on_account_country_selector_changed (HildonTouchSelector *widget, gint column, gpointer user_data)
319 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
321 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
325 /* Fill the providers combo, based on the selected country: */
326 if (priv->presets != NULL) {
327 gint mcc = modest_country_picker_get_active_country_mcc (
328 MODEST_COUNTRY_PICKER (priv->account_country_picker));
329 modest_provider_picker_fill (
330 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker), priv->presets, mcc);
335 on_account_serviceprovider_selector_changed (GtkComboBox *widget, gint column, gpointer user_data)
337 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
339 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
343 /* Fill the providers combo, based on the selected country: */
344 gchar* provider_id = modest_provider_picker_get_active_provider_id (
345 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
347 gchar* domain_name = NULL;
349 domain_name = modest_presets_get_domain (priv->presets, provider_id);
352 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
354 if (priv->entry_user_email)
355 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), domain_name);
357 g_free (domain_name);
359 g_free (provider_id);
363 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
365 modest_platform_information_banner (GTK_WIDGET (self), NULL,
366 _CS("ckdg_ib_maximum_characters_reached"));
370 create_page_account_details (ModestEasysetupWizardDialog *self)
373 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
374 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
375 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
377 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
378 gtk_widget_set_size_request (label, 600, -1);
379 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
380 gtk_widget_show (label);
382 /* Create a size group to be used by all captions.
383 * Note that HildonCaption does not create a default size group if we do not specify one.
384 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
385 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
387 /* The country widgets: */
388 priv->account_country_picker = GTK_WIDGET (modest_country_picker_new ());
389 hildon_button_set_title (HILDON_BUTTON (priv->account_country_picker), _("mcen_fi_country"));
390 g_signal_connect (G_OBJECT (priv->account_country_picker), "value-changed",
391 G_CALLBACK (on_picker_button_value_changed), self);
392 gtk_box_pack_start (GTK_BOX (box), priv->account_country_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
393 gtk_widget_show (priv->account_country_picker);
395 /* connect to country combo's changed signal, so we can fill the provider picker: */
396 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
397 (HILDON_PICKER_BUTTON (priv->account_country_picker))),
399 G_CALLBACK (on_account_country_selector_changed), self);
401 GtkWidget *separator = gtk_hseparator_new ();
402 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
403 gtk_widget_show (separator);
405 /* The service provider widgets: */
406 priv->account_serviceprovider_picker = GTK_WIDGET (modest_provider_picker_new ());
407 hildon_button_set_title (HILDON_BUTTON (priv->account_serviceprovider_picker), _("mcen_fi_serviceprovider"));
408 g_signal_connect (G_OBJECT (priv->account_serviceprovider_picker), "value-changed",
409 G_CALLBACK (on_picker_button_value_changed), self);
410 gtk_box_pack_start (GTK_BOX (box), priv->account_serviceprovider_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
411 gtk_widget_show (priv->account_serviceprovider_picker);
413 /* connect to providers combo's changed signal, so we can fill the email address: */
414 g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
415 (HILDON_PICKER_BUTTON (priv->account_serviceprovider_picker))),
417 G_CALLBACK (on_account_serviceprovider_selector_changed), self);
419 /* The description widgets: */
420 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
421 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
422 G_CALLBACK(on_easysetup_changed), self);
423 /* Do use auto-capitalization: */
424 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
425 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
427 /* Set a default account title, choosing one that does not already exist: */
428 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
429 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
430 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
431 priv->account_manager, default_account_name_start);
432 g_free (default_account_name_start);
433 default_account_name_start = NULL;
435 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title), default_account_name);
436 g_free (default_account_name);
437 default_account_name = NULL;
439 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
440 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
441 gtk_widget_show (priv->entry_account_title);
442 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
443 gtk_widget_show (caption);
445 /* Prevent the use of some characters in the account title,
446 * as required by our UI specification: */
447 GList *list_prevent = NULL;
448 list_prevent = g_list_append (list_prevent, "\\");
449 list_prevent = g_list_append (list_prevent, "/");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
454 list_prevent = g_list_append (list_prevent, "“");
455 list_prevent = g_list_append (list_prevent, "<");
456 list_prevent = g_list_append (list_prevent, ">");
457 list_prevent = g_list_append (list_prevent, "|");
458 list_prevent = g_list_append (list_prevent, "^");
459 modest_validating_entry_set_unallowed_characters (
460 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
461 g_list_free (list_prevent);
463 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
464 modest_utils_on_entry_invalid_character, self);
466 /* Set max length as in the UI spec:
467 * The UI spec seems to want us to show a dialog if we hit the maximum. */
468 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
469 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
472 gtk_widget_show (GTK_WIDGET (box));
474 return GTK_WIDGET (box);
478 create_page_user_details (ModestEasysetupWizardDialog *self)
480 GtkSizeGroup* 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 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
492 /* The name widgets: (use auto cap) */
493 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
494 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
495 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
497 /* Set max length as in the UI spec:
498 * The UI spec seems to want us to show a dialog if we hit the maximum. */
499 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
500 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
502 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
503 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
504 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
505 G_CALLBACK(on_easysetup_changed), self);
506 gtk_widget_show (priv->entry_user_name);
507 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
508 gtk_widget_show (caption);
510 /* Prevent the use of some characters in the name,
511 * as required by our UI specification: */
512 GList *list_prevent = NULL;
513 list_prevent = g_list_append (list_prevent, "<");
514 list_prevent = g_list_append (list_prevent, ">");
515 modest_validating_entry_set_unallowed_characters (
516 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
517 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
518 modest_utils_on_entry_invalid_character, self);
519 g_list_free (list_prevent);
521 /* The username widgets: */
522 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
523 /* Auto-capitalization is the default, so let's turn it off: */
524 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username),
525 HILDON_GTK_INPUT_MODE_FULL);
526 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
527 priv->entry_user_username,
528 NULL, HILDON_CAPTION_MANDATORY);
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 = gtk_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_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_caption_new_with_asterisk (self, sizegroup,
556 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
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_caption_new_with_asterisk (self, sizegroup,
568 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
569 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
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));
585 return GTK_WIDGET (box);
589 create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
591 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
593 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
594 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
595 gtk_widget_set_size_request (label, 600, -1);
596 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
597 /* The documentation for gtk_label_set_line_wrap() says that we must
598 * call gtk_widget_set_size_request() with a hard-coded width,
599 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
600 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
601 gtk_widget_show (label);
603 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
604 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
605 gtk_widget_set_size_request (label, 600, -1);
607 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
608 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
609 gtk_widget_show (label);
611 gtk_widget_show (GTK_WIDGET (box));
612 return GTK_WIDGET (box);
615 /** Change the caption title for the incoming server,
616 * as specified in the UI spec:
619 update_incoming_server_title (ModestEasysetupWizardDialog *self)
621 ModestEasysetupWizardDialogPrivate* priv;
622 ModestProtocolType protocol_type;
623 ModestProtocolRegistry *protocol_registry;
625 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
626 protocol_registry = modest_runtime_get_protocol_registry ();
628 protocol_type = easysetup_servertype_combo_box_get_active_servertype (
629 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
631 /* This could happen when the combo box has still no active iter */
632 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
633 gchar* incomingserver_title;
634 const gchar *protocol_display_name;
636 protocol_display_name = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type));
638 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), protocol_display_name);
639 g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
640 g_free(incomingserver_title);
644 /** Change the caption title for the incoming server,
645 * as specified in the UI spec:
648 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
650 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
651 EasysetupServertypeComboBox *server_type_combo;
652 ModestProtocolType protocol_type;
653 ModestSecurityOptionsView *view;
656 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype);
658 easysetup_servertype_combo_box_get_active_servertype (server_type_combo);
660 /* Fill the combo with appropriately titled choices for all
662 view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
663 modest_security_options_view_set_server_type (view, protocol_type);
667 on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
669 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
670 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
671 EasysetupServertypeComboBox *combo;
672 ModestProtocolType protocol_type;
677 update_incoming_server_title (self);
679 /* Update security options if needed */
680 combo = EASYSETUP_SERVERTYPE_COMBO_BOX (combobox);
681 protocol_type = easysetup_servertype_combo_box_get_active_servertype (combo);
682 update_incoming_server_security_choices (self);
683 gtk_widget_show (priv->incoming_security);
685 set_default_custom_servernames (self);
689 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
691 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
692 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
694 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
698 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
700 ModestProtocolRegistry *protocol_registry;
701 ModestEasysetupWizardDialogPrivate* priv;
703 GtkWidget *scrolled_window;
705 GtkSizeGroup *sizegroup;
708 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
709 protocol_registry = modest_runtime_get_protocol_registry ();
711 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
712 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
714 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
716 GTK_POLICY_AUTOMATIC);
718 /* Show note that account type cannot be changed in future: */
719 label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
720 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
721 gtk_widget_set_size_request (label, 600, -1);
722 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
723 gtk_widget_show (label);
725 /* Create a size group to be used by all captions.
726 * Note that HildonCaption does not create a default size group if we do not specify one.
727 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
728 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
730 /* The incoming server widgets: */
731 priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new (TRUE));
732 caption = create_caption_new_with_asterisk (self, sizegroup,
733 _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
734 gtk_widget_show (priv->combo_incoming_servertype);
735 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
736 gtk_widget_show (caption);
738 priv->entry_incomingserver = gtk_entry_new ();
739 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
740 /* Auto-capitalization is the default, so let's turn it off: */
741 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
742 set_default_custom_servernames (self);
744 /* The caption title will be updated in update_incoming_server_title().
745 * so this default text will never be seen: */
746 /* (Note: Changing the title seems pointless. murrayc) */
747 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
749 priv->entry_incomingserver,
750 NULL, HILDON_CAPTION_MANDATORY);
751 update_incoming_server_title (self);
752 gtk_widget_show (priv->entry_incomingserver);
753 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
754 gtk_widget_show (priv->caption_incoming);
756 /* Change the caption title when the servertype changes,
757 * as in the UI spec: */
758 g_signal_connect (G_OBJECT (priv->combo_incoming_servertype), "changed",
759 G_CALLBACK (on_combo_servertype_changed), self);
761 /* Remember when the servername was changed manually: */
762 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
763 G_CALLBACK (on_entry_incoming_servername_changed), self);
765 /* The secure connection widgets. These are only valid for
766 protocols with security */
767 priv->incoming_security =
768 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
770 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
771 FALSE, FALSE, MODEST_MARGIN_HALF);
773 /* Set default selection */
774 easysetup_servertype_combo_box_set_active_servertype (
775 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype),
776 MODEST_PROTOCOLS_STORE_POP);
778 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
779 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
780 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
781 gtk_widget_show (GTK_WIDGET (box));
782 gtk_widget_show (scrolled_window);
784 return GTK_WIDGET (scrolled_window);
788 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
790 GtkWidget *widget = GTK_WIDGET (user_data);
792 /* Enable the widget only if the toggle button is active: */
793 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
794 gtk_widget_set_sensitive (widget, enable);
797 /* Make the sensitivity of a widget depend on a toggle button.
800 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
802 g_signal_connect (G_OBJECT (button), "toggled",
803 G_CALLBACK (on_toggle_button_changed), widget);
805 /* Set the starting sensitivity: */
806 on_toggle_button_changed (button, widget);
810 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
812 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
813 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
814 GtkWidget *specific_window;
816 /* We set dirty here because setting it depending on the connection specific dialog
820 /* Create the window, if necessary: */
821 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
822 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
824 /* Show the window */
825 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window));
826 gtk_widget_show (specific_window);
830 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
832 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
833 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
834 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
838 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
840 ModestEasysetupWizardDialogPrivate *priv;
841 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
843 /* Create a size group to be used by all captions.
844 * Note that HildonCaption does not create a default size group if we do not specify one.
845 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
846 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
848 /* The outgoing server widgets: */
849 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
850 priv->entry_outgoingserver = gtk_entry_new ();
851 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
852 G_CALLBACK (on_easysetup_changed), self);
853 /* Auto-capitalization is the default, so let's turn it off: */
854 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
855 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
856 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
857 gtk_widget_show (priv->entry_outgoingserver);
858 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
859 gtk_widget_show (caption);
860 set_default_custom_servernames (self);
862 /* The secure connection widgets. These are only valid for
863 protocols with security */
864 priv->outgoing_security =
865 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
867 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
868 FALSE, FALSE, MODEST_MARGIN_HALF);
869 gtk_widget_show (priv->outgoing_security);
871 GtkWidget *separator = gtk_hseparator_new ();
872 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
873 gtk_widget_show (separator);
875 /* connection-specific checkbox: */
876 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
877 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
879 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
880 G_CALLBACK (on_easysetup_changed), self);
882 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
883 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
884 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
885 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
886 gtk_widget_show (caption);
888 /* Connection-specific SMTP-Severs Edit button: */
889 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
890 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
891 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
892 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
893 gtk_widget_show (priv->button_outgoing_smtp_servers);
894 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
895 gtk_widget_show (caption);
897 /* Only enable the button when the checkbox is checked: */
898 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
899 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
901 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
902 G_CALLBACK (on_button_outgoing_smtp_servers), self);
904 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
905 G_CALLBACK (on_entry_outgoing_servername_changed), self);
908 gtk_widget_show (GTK_WIDGET (box));
910 return GTK_WIDGET (box);
914 show_advanced_edit(gpointer user_data)
916 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
917 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
920 /* Show the Account Settings window: */
921 ModestAccountSettingsDialog *dialog = modest_default_account_settings_dialog_new ();
922 if (priv->pending_load_settings) {
923 save_to_settings (self);
924 priv->pending_load_settings = FALSE;
926 modest_account_settings_dialog_load_settings (dialog, priv->settings);
928 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
930 response = gtk_dialog_run (GTK_DIALOG (dialog));
932 gtk_widget_destroy (GTK_WIDGET (dialog));
934 return FALSE; /* Do not call this timeout callback again. */
938 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
940 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
942 /* Show the Account Settings window: */
943 show_advanced_edit(self);
946 create_page_complete_custom (ModestEasysetupWizardDialog *self)
948 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
949 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
950 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
951 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
952 gtk_widget_set_size_request (label, 600, -1);
953 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
954 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
955 gtk_widget_show (label);
957 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
958 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
959 gtk_widget_set_size_request (label, 600, -1);
960 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
961 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
962 gtk_widget_show (label);
964 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
965 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
966 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
967 gtk_widget_show (button_edit);
968 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
969 gtk_widget_show (caption);
971 g_signal_connect (G_OBJECT (button_edit), "clicked",
972 G_CALLBACK (on_button_edit_advanced_settings), self);
974 gtk_widget_show (GTK_WIDGET (box));
975 return GTK_WIDGET (box);
982 on_response (ModestWizardDialog *wizard_dialog,
986 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
988 invoke_enable_buttons_vfunc (self);
992 on_response_before (ModestWizardDialog *wizard_dialog,
996 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
997 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
998 if (response_id == GTK_RESPONSE_CANCEL) {
999 /* This is mostly copied from
1000 * src/maemo/modest-account-settings-dialog.c */
1002 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1003 _("imum_nc_wizard_confirm_lose_changes")));
1004 /* TODO: These button names will be ambiguous, and not
1005 * specified in the UI specification. */
1007 const gint dialog_response = gtk_dialog_run (dialog);
1008 gtk_widget_destroy (GTK_WIDGET (dialog));
1010 if (dialog_response != GTK_RESPONSE_OK) {
1011 /* Don't let the dialog close */
1012 g_signal_stop_emission_by_name (wizard_dialog, "response");
1018 typedef struct IdleData {
1019 ModestEasysetupWizardDialog *dialog;
1020 ModestPresets *presets;
1024 presets_idle (gpointer userdata)
1026 IdleData *idle_data = (IdleData *) userdata;
1027 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1028 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1030 g_assert (idle_data->presets);
1032 gdk_threads_enter ();
1034 priv->presets = idle_data->presets;
1036 if (MODEST_IS_COUNTRY_PICKER (priv->account_country_picker)) {
1037 /* gint mcc = get_default_country_code(); */
1039 /* Fill the combo in an idle call, as it takes a lot of time */
1040 modest_country_picker_load_data(
1041 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1042 modest_country_picker_set_active_country_locale (
1043 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1044 mcc = modest_country_picker_get_active_country_mcc (
1045 MODEST_COUNTRY_PICKER (priv->account_country_picker));
1046 modest_provider_picker_fill (
1047 MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker),
1048 priv->presets, mcc);
1049 modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker));
1052 priv->dirty = FALSE;
1054 g_object_unref (idle_data->dialog);
1057 gdk_threads_leave ();
1063 presets_loader (gpointer userdata)
1065 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1066 ModestPresets *presets = NULL;
1067 IdleData *idle_data;
1069 const gchar* path = NULL;
1070 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1071 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1073 if (access(path1, R_OK) == 0)
1075 else if (access(path2, R_OK) == 0)
1078 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1079 __FUNCTION__, path1, path2);
1083 presets = modest_presets_new (path);
1085 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1089 idle_data = g_new0 (IdleData, 1);
1090 idle_data->dialog = self;
1091 idle_data->presets = presets;
1093 g_idle_add (presets_idle, idle_data);
1099 modest_easysetup_wizard_dialog_append_page (GtkNotebook *notebook,
1104 /* Append page and set attributes */
1105 index = gtk_notebook_append_page (notebook, page, gtk_label_new (label));
1106 gtk_container_child_set (GTK_CONTAINER (notebook), page,
1107 "tab-expand", TRUE, "tab-fill", TRUE,
1109 gtk_widget_show (page);
1113 init_user_page (ModestEasysetupWizardDialogPrivate *priv)
1115 priv->page_user_details = NULL;
1116 priv->entry_user_name = NULL;
1117 priv->entry_user_username = NULL;
1118 priv->entry_user_password = NULL;
1119 priv->entry_user_email = NULL;
1123 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
1125 priv->page_custom_incoming = NULL;
1126 priv->combo_incoming_servertype = NULL;
1127 priv->caption_incoming = NULL;
1128 priv->entry_incomingserver = NULL;
1129 priv->entry_user_email = NULL;
1130 priv->incoming_security = NULL;
1134 init_outgoing_page (ModestEasysetupWizardDialogPrivate *priv)
1136 priv->page_custom_outgoing = NULL;
1137 priv->entry_outgoingserver = NULL;
1138 priv->combo_outgoing_security = NULL;
1139 priv->combo_outgoing_auth = NULL;
1140 priv->checkbox_outgoing_smtp_specific = NULL;
1141 priv->button_outgoing_smtp_servers = NULL;
1142 priv->outgoing_security = NULL;
1146 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1148 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1150 /* Create the notebook to be used by the ModestWizardDialog base class:
1151 * Each page of the notebook will be a page of the wizard: */
1152 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1154 /* Set the notebook used by the ModestWizardDialog base class: */
1155 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1157 /* Set the wizard title:
1158 * The actual window title will be a combination of this and the page's tab label title. */
1159 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1161 /* Read in the information about known service providers: */
1162 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1164 /* The server fields did not have been manually changed yet */
1165 priv->server_changes = 0;
1166 priv->pending_load_settings = TRUE;
1168 /* Get the account manager object,
1169 * so we can check for existing accounts,
1170 * and create new accounts: */
1171 priv->account_manager = modest_runtime_get_account_mgr ();
1172 g_object_ref (priv->account_manager);
1174 /* Initialize fields */
1175 priv->page_welcome = create_page_welcome (self);
1176 priv->page_account_details = create_page_account_details (self);
1178 init_user_page (priv);
1179 init_incoming_page (priv);
1180 init_outgoing_page (priv);
1182 priv->page_complete_easysetup = NULL;
1183 priv->page_complete_customsetup = NULL;
1184 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1185 priv->missing_data_signals = NULL;
1187 /* Add the common pages */
1188 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_welcome,
1189 _("mcen_ti_emailsetup_welcome"));
1190 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_account_details,
1191 _("mcen_ti_accountdetails"));
1193 /* Connect to the dialog's response signal so we can enable/disable buttons
1194 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1195 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1196 * so that we can be enable/disable after ModestWizardDialog has done its own
1197 * enabling/disabling of buttons.
1199 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1200 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1202 * It's not enough to connect to the notebook's switch-page signal, because
1203 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1204 * _after_ switching the page (understandably).
1205 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1206 * then gtk_notebook_get_current_page() would return an incorrect value.)
1208 g_signal_connect_after (G_OBJECT (self), "response",
1209 G_CALLBACK (on_response), self);
1211 /* This is to show a confirmation dialog when the user hits cancel */
1212 g_signal_connect (G_OBJECT (self), "response",
1213 G_CALLBACK (on_response_before), self);
1215 g_signal_connect (G_OBJECT (self), "delete-event",
1216 G_CALLBACK (on_delete_event), self);
1218 /* Reset dirty, because there was no user input until now */
1219 priv->dirty = FALSE;
1221 /* When this window is shown, hibernation should not be possible,
1222 * because there is no sensible way to save the state: */
1223 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1224 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1226 /* Load provider presets */
1227 g_object_ref (self);
1228 g_thread_create (presets_loader, self, FALSE, NULL);
1230 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1231 modest_maemo_utils_get_osso_context());
1233 priv->settings = modest_account_settings_new ();
1236 ModestEasysetupWizardDialog*
1237 modest_easysetup_wizard_dialog_new (void)
1240 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1244 create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1246 ModestEasysetupWizardDialogPrivate *priv;
1247 GtkNotebook *notebook = NULL;
1249 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1252 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1254 if (!priv->page_user_details) {
1255 priv->page_user_details = create_page_user_details (self);
1258 /* Create the custom pages: */
1259 if(!(priv->page_custom_incoming)) {
1260 priv->page_custom_incoming = create_page_custom_incoming (self);
1263 /* TODO: only if needed */
1264 if(!(priv->page_custom_outgoing)) {
1265 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1268 if(!(priv->page_complete_customsetup)) {
1269 priv->page_complete_customsetup = create_page_complete_custom (self);
1272 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_user_details)))
1273 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_user_details,
1274 _("mcen_ti_emailsetup_userdetails"));
1276 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1277 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_incoming,
1278 _("mcen_ti_emailsetup_incomingdetails"));
1280 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1281 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_custom_outgoing,
1282 _("mcen_ti_emailsetup_outgoingdetails"));
1284 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup)))
1285 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_customsetup,
1286 _("mcen_ti_emailsetup_complete"));
1288 /* This is unnecessary with GTK+ 2.10: */
1289 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1293 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1295 ModestEasysetupWizardDialogPrivate *priv;
1296 GtkNotebook *notebook = NULL;
1298 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1301 /* Create the easysetup-specific pages: */
1302 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1303 if(!priv->page_complete_easysetup)
1304 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1306 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup)))
1307 modest_easysetup_wizard_dialog_append_page (notebook, priv->page_complete_easysetup,
1308 _("mcen_ti_emailsetup_complete"));
1310 /* This is unnecessary with GTK+ 2.10: */
1311 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1316 remove_non_common_tabs (GtkNotebook *notebook,
1317 gboolean remove_user_details)
1320 /* The first 2 tabs are the common ones (welcome tab and the
1321 providers tab), so we always remove starting from the
1324 starting_tab = (remove_user_details) ? 2 : 3;
1325 while (gtk_notebook_get_n_pages (notebook) > starting_tab)
1326 gtk_notebook_remove_page (notebook, -1);
1330 on_missing_mandatory_data (ModestAccountProtocol *protocol,
1334 real_enable_buttons (MODEST_WIZARD_DIALOG (user_data), !missing);
1337 /* After the user details page,
1338 * the following pages depend on whether "Other" was chosen
1339 * in the provider combobox on the account page
1342 create_subsequent_pages (ModestEasysetupWizardDialog *self)
1344 ModestEasysetupWizardDialogPrivate *priv;
1345 ModestProviderPicker *picker;
1346 ModestProviderPickerIdType id_type;
1347 GtkNotebook *notebook;
1349 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1350 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1351 id_type = modest_provider_picker_get_active_id_type (picker);
1352 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1354 if (id_type == MODEST_PROVIDER_PICKER_ID_OTHER) {
1355 /* "Other..." was selected: */
1357 /* If we come from a rollbacked easysetup */
1358 if (priv->page_complete_easysetup) {
1359 remove_non_common_tabs (notebook, FALSE);
1360 priv->page_complete_easysetup = NULL;
1363 /* If we come from a rollbacked plugin protocol setup */
1364 if (priv->last_plugin_protocol_selected != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1365 remove_non_common_tabs (notebook, TRUE);
1366 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1367 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1368 priv->missing_data_signals = NULL;
1371 create_subsequent_customsetup_pages (self);
1373 /* If we come from a rollbacked custom setup */
1374 if (priv->page_custom_incoming) {
1375 remove_non_common_tabs (notebook, TRUE);
1376 init_user_page (priv);
1377 init_incoming_page (priv);
1378 init_outgoing_page (priv);
1379 init_user_page (priv);
1380 priv->page_complete_customsetup = NULL;
1383 /* It's a pluggable protocol and not a provider with presets */
1384 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1385 ModestProtocol *protocol;
1387 ModestProtocolType proto_type;
1390 /* If we come from a rollbacked easy setup */
1391 if (priv->last_plugin_protocol_selected ==
1392 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID &&
1393 priv->page_complete_easysetup) {
1394 remove_non_common_tabs (notebook, TRUE);
1395 init_user_page (priv);
1396 priv->page_complete_easysetup = NULL;
1399 proto_name = modest_provider_picker_get_active_provider_id (picker);
1400 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
1401 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1403 proto_type = modest_protocol_get_type_id (protocol);
1405 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol) &&
1406 proto_type != priv->last_plugin_protocol_selected) {
1407 ModestPairList *tabs;
1410 /* Remember the last selected plugin protocol */
1411 priv->last_plugin_protocol_selected = proto_type;
1414 tabs = modest_account_protocol_get_easysetupwizard_tabs (MODEST_ACCOUNT_PROTOCOL (protocol));
1415 tmp = (GSList *) tabs;
1417 ModestPair *pair = (ModestPair *) tmp->data;
1418 modest_easysetup_wizard_dialog_append_page (notebook,
1419 GTK_WIDGET (pair->second),
1420 (const gchar *) pair->first);
1422 /* Connect signals */
1423 priv->missing_data_signals =
1424 modest_signal_mgr_connect (priv->missing_data_signals,
1425 G_OBJECT (pair->second),
1426 "missing-mandatory-data",
1427 G_CALLBACK (on_missing_mandatory_data),
1430 g_free (pair->first);
1431 tmp = g_slist_next (tmp);
1432 /* Critical: if you don't show the page then the dialog will ignore it */
1433 /* gtk_widget_show (GTK_WIDGET (pair->second)); */
1435 modest_pair_list_free (tabs);
1437 g_free (proto_name);
1439 if (priv->last_plugin_protocol_selected !=
1440 MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1441 remove_non_common_tabs (notebook, TRUE);
1442 init_user_page (priv);
1443 priv->page_complete_easysetup = NULL;
1444 priv->last_plugin_protocol_selected = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1445 modest_signal_mgr_disconnect_all_and_destroy (priv->missing_data_signals);
1446 priv->missing_data_signals = NULL;
1448 if (!priv->page_user_details) {
1449 priv->page_user_details = create_page_user_details (self);
1450 modest_easysetup_wizard_dialog_append_page (notebook,
1451 priv->page_user_details,
1452 _("mcen_ti_emailsetup_userdetails"));
1456 /* Create the easysetup pages: */
1457 create_subsequent_easysetup_pages (self);
1463 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocolType protocol_type)
1465 const gchar* hostname = NULL;
1468 ModestProtocolRegistry *protocol_registry;
1469 ModestProtocol *protocol;
1474 at = g_utf8_strchr (email_address, -1, '@');
1475 if (!at || (g_utf8_strlen (at, -1) < 2))
1478 domain = g_utf8_next_char (at);
1482 protocol_registry = modest_runtime_get_protocol_registry ();
1483 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
1485 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS) ||
1486 modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type, MODEST_PROTOCOL_REGISTRY_TRANSPORT_PROTOCOLS)) {
1487 hostname = modest_protocol_get_name (protocol);
1493 return g_strdup_printf ("%s.%s", hostname, domain);
1497 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1499 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1501 if (!priv->entry_incomingserver)
1504 /* Set a default domain for the server, based on the email address,
1505 * if no server name was already specified.
1507 if (priv->entry_user_email
1508 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1509 const ModestProtocolType protocol_type = easysetup_servertype_combo_box_get_active_servertype (
1510 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1512 /* This could happen when the combo box has still no active iter */
1513 if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1514 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1515 gchar* servername = util_get_default_servername_from_email_address (email_address,
1518 /* Do not set the INCOMING_CHANGED flag because of this edit */
1519 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1520 gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
1521 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1523 g_free (servername);
1527 /* Set a default domain for the server, based on the email address,
1528 * if no server name was already specified.
1530 if (!priv->entry_outgoingserver)
1533 if (priv->entry_user_email
1534 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1535 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1537 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOLS_TRANSPORT_SMTP);
1539 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1540 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1541 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), servername);
1542 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1544 g_free (servername);
1549 get_entered_account_title (ModestEasysetupWizardDialog *self)
1551 ModestEasysetupWizardDialogPrivate *priv;
1552 const gchar* account_title;
1554 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1555 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
1557 if (!account_title || (g_utf8_strlen (account_title, -1) == 0)) {
1560 /* Strip it of whitespace at the start and end: */
1561 gchar *result = g_strdup (account_title);
1562 result = g_strstrip (result);
1567 if (g_utf8_strlen (result, -1) == 0) {
1577 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1579 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1580 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1581 ModestProtocolRegistry *protocol_registry;
1583 protocol_registry = modest_runtime_get_protocol_registry ();
1585 /* if are browsing pages previous to the last one, then we have pending settings in
1587 if (next_page != NULL)
1588 priv->pending_load_settings = TRUE;
1590 /* Do extra validation that couldn't be done for every key press,
1591 * either because it was too slow,
1592 * or because it requires interaction:
1594 if (current_page == priv->page_account_details) {
1595 /* Check that the title is not already in use: */
1596 gchar* account_title = get_entered_account_title (self);
1600 /* Aavoid a clash with an existing display name: */
1601 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1602 priv->account_manager, account_title);
1605 /* Warn the user via a dialog: */
1606 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1611 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1612 create_subsequent_pages (self);
1614 } else if (current_page == priv->page_user_details) {
1615 /* Check that the email address is valud: */
1616 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1617 if ((!email_address) || (g_utf8_strlen (email_address, -1) == 0))
1620 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1621 /* Warn the user via a dialog: */
1622 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1624 /* Return focus to the email address entry: */
1625 gtk_widget_grab_focus (priv->entry_user_email);
1626 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1632 if (next_page == priv->page_custom_incoming) {
1633 set_default_custom_servernames (self);
1634 } else if (next_page == priv->page_custom_outgoing) {
1635 set_default_custom_servernames (self);
1637 /* Check if the server supports secure authentication */
1638 /* if (modest_security_options_view_auth_check (security_options)) */
1639 /* if (!check_has_supported_auth_methods (self)) */
1641 gtk_widget_show (priv->outgoing_security);
1644 /* If this is the last page, and this is a click on Finish,
1645 * then attempt to create the dialog.
1648 current_page != priv->page_account_details) /* This is NULL when this is a click on Finish. */
1650 if (priv->pending_load_settings) {
1651 save_to_settings (self);
1654 /* We check if there's already another account with the same configuration */
1655 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1656 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1660 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1667 static gboolean entry_is_empty (GtkWidget *entry)
1672 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1673 if ((!text) || (g_utf8_strlen (text, -1) == 0))
1676 /* Strip it of whitespace at the start and end: */
1677 gchar *stripped = g_strdup (text);
1678 stripped = g_strstrip (stripped);
1683 const gboolean result = (g_utf8_strlen (stripped, -1) == 0);
1691 real_enable_buttons (ModestWizardDialog *dialog, gboolean enable_next)
1693 GtkNotebook *notebook = NULL;
1694 gboolean is_finish_tab;
1696 ModestEasysetupWizardDialogPrivate *priv;
1699 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (dialog);
1700 g_object_get (dialog, "wizard-notebook", ¬ebook, NULL);
1702 /* Disable the Finish button until we are on the last page,
1703 * because HildonWizardDialog enables this for all but the
1705 current = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook));
1706 is_finish_tab = ((current == priv->page_complete_easysetup) ||
1707 (current == priv->page_complete_customsetup));
1709 if (is_finish_tab) {
1710 /* Disable Next on the last page no matter what the
1712 enable_next = FALSE;
1714 /* Not the last one */
1715 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1716 MODEST_WIZARD_DIALOG_FINISH,
1720 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
1721 MODEST_WIZARD_DIALOG_NEXT,
1726 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1728 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1729 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1731 gboolean enable_next = TRUE;
1732 if (current_page == priv->page_welcome) {
1734 } else if (current_page == priv->page_account_details) {
1735 /* The account details title is mandatory: */
1736 if (entry_is_empty(priv->entry_account_title))
1737 enable_next = FALSE;
1738 } else if (current_page == priv->page_user_details) {
1739 /* The user details username is mandatory: */
1740 if (entry_is_empty(priv->entry_user_username))
1741 enable_next = FALSE;
1743 /* The user details email address is mandatory: */
1744 if (enable_next && entry_is_empty (priv->entry_user_email))
1745 enable_next = FALSE;
1746 } else if (current_page == priv->page_custom_incoming) {
1747 /* The custom incoming server is mandatory: */
1748 if (entry_is_empty(priv->entry_incomingserver))
1749 enable_next = FALSE;
1750 } else if (MODEST_IS_EASYSETUP_WIZARD_PAGE (current_page)) {
1751 enable_next = !modest_easysetup_wizard_page_validate (
1752 MODEST_EASYSETUP_WIZARD_PAGE (current_page));
1755 /* Enable/disable buttons */
1756 real_enable_buttons (dialog, enable_next);
1760 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1762 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1763 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1766 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1767 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1769 /* Provide a vfunc implementation so we can decide
1770 * when to enable/disable the prev/next buttons.
1772 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1773 base_klass->before_next = on_before_next;
1774 base_klass->enable_buttons = on_enable_buttons;
1779 * @self: a #ModestEasysetupWizardDialog
1781 * takes information from all the wizard and stores it in settings
1784 save_to_settings (ModestEasysetupWizardDialog *self)
1786 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1789 gchar* display_name;
1790 const gchar *username, *password;
1791 gchar *store_hostname, *transport_hostname;
1792 guint store_port, transport_port;
1793 ModestProtocolRegistry *protocol_registry;
1794 ModestProtocolType store_protocol, transport_protocol;
1795 ModestProtocolType store_security, transport_security;
1796 ModestProtocolType store_auth_protocol, transport_auth_protocol;
1797 ModestServerAccountSettings *store_settings, *transport_settings;
1798 const gchar *fullname, *email_address;
1799 ModestProviderPicker *picker;
1800 ModestProviderPickerIdType id_type;
1802 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1803 picker = MODEST_PROVIDER_PICKER (priv->account_serviceprovider_picker);
1804 protocol_registry = modest_runtime_get_protocol_registry ();
1806 /* Get details from the specified presets: */
1807 id_type = modest_provider_picker_get_active_id_type (picker);
1808 provider_id = modest_provider_picker_get_active_provider_id (picker);
1810 /* Let the plugin save the settings. We do a return in order
1811 to save an indentation level */
1812 if (id_type == MODEST_PROVIDER_PICKER_ID_PLUGIN_PROTOCOL) {
1813 ModestProtocol *protocol;
1815 protocol = modest_protocol_registry_get_protocol_by_name (
1816 modest_runtime_get_protocol_registry (),
1817 MODEST_PROTOCOL_REGISTRY_PROVIDER_PROTOCOLS,
1820 if (protocol && MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
1821 gint n_pages, i = 0;
1822 GtkNotebook *notebook;
1823 GList *wizard_pages = NULL;
1825 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1826 n_pages = gtk_notebook_get_n_pages (notebook);
1827 for (i = 0; i < n_pages; i++) {
1828 GtkWidget *page = gtk_notebook_get_nth_page (notebook, i);
1829 if (MODEST_IS_EASYSETUP_WIZARD_PAGE (page))
1830 wizard_pages = g_list_append (wizard_pages, page);
1832 modest_account_protocol_save_wizard_settings (MODEST_ACCOUNT_PROTOCOL (protocol),
1835 g_list_free (wizard_pages);
1837 g_warning ("The selected protocol is a plugin protocol "//
1838 "but it's not a ModestAccountProtocol");
1844 /* username and password (for both incoming and outgoing): */
1845 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1846 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1848 store_settings = modest_account_settings_get_store_settings (priv->settings);
1849 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1851 /* Incoming server: */
1852 /* Note: We need something as default for the transport store protocol values,
1853 * or modest_account_mgr_add_server_account will fail. */
1855 store_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1856 store_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1857 store_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1860 ModestProtocolType store_provider_server_type;
1861 gboolean store_provider_use_alternate_port;
1863 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1866 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1869 store_security = modest_presets_get_info_server_security (priv->presets,
1872 store_auth_protocol = modest_presets_get_info_server_auth (priv->presets,
1875 store_provider_use_alternate_port = modest_presets_get_info_server_use_alternate_port (priv->presets,
1879 /* We don't check for SMTP here as that is impossible for an incoming server. */
1880 if (store_provider_server_type == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID)
1881 store_protocol = MODEST_PROTOCOLS_STORE_POP;
1883 store_protocol = store_provider_server_type;
1885 /* we check if there is a *special* port */
1886 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1887 if (special_port != 0)
1888 store_port = special_port;
1890 store_port = get_port_from_protocol(store_provider_server_type, store_security);
1892 modest_server_account_settings_set_security_protocol (store_settings,
1894 modest_server_account_settings_set_auth_protocol (store_settings,
1895 store_auth_protocol);
1896 if (store_port != 0)
1897 modest_server_account_settings_set_port (store_settings, store_port);
1899 /* Use custom pages because no preset was specified: */
1900 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));
1901 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1902 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1904 modest_security_options_view_save_settings (
1905 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1909 /* now we store the common store account settings */
1910 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1911 modest_server_account_settings_set_username (store_settings, username);
1912 modest_server_account_settings_set_password (store_settings, password);
1913 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1915 g_object_unref (store_settings);
1916 g_free (store_hostname);
1918 /* Outgoing server: */
1919 transport_hostname = NULL;
1920 transport_protocol = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
1921 transport_security = MODEST_PROTOCOLS_CONNECTION_NONE;
1922 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1926 ModestProtocolType transport_provider_server_type;
1927 ModestProtocolType transport_provider_security;
1930 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1931 FALSE /* transport */);
1933 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1935 FALSE /* transport */);
1936 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1938 FALSE /* transport */);
1940 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1941 transport_protocol = transport_provider_server_type;
1942 transport_security = transport_provider_security;
1943 if (transport_security == MODEST_PROTOCOLS_CONNECTION_SSL) {
1944 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1945 /* we check if there is a *special* port */
1946 special_port = modest_presets_get_port (priv->presets, provider_id,
1947 FALSE /* transport */);
1948 if (special_port != 0)
1949 transport_port = special_port;
1951 transport_port = 465;
1952 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
1954 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1955 transport_auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
1958 modest_server_account_settings_set_security_protocol (transport_settings,
1959 transport_security);
1960 modest_server_account_settings_set_auth_protocol (transport_settings,
1961 transport_auth_protocol);
1962 if (transport_port != 0)
1963 modest_server_account_settings_set_port (transport_settings,
1966 ModestProtocolRegistry *registry;
1967 ModestProtocol *store_proto;
1969 registry = modest_runtime_get_protocol_registry ();
1970 /* Use custom pages because no preset was specified: */
1971 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
1973 store_proto = modest_protocol_registry_get_protocol_by_type (registry,
1976 if (transport_protocol == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1977 /* fallback to SMTP if none was specified */
1978 g_warning ("No transport protocol was specified for store %d (%s)",
1979 modest_protocol_get_type_id (store_proto),
1980 modest_protocol_get_display_name (store_proto));
1981 transport_protocol = MODEST_PROTOCOLS_TRANSPORT_SMTP;
1984 modest_security_options_view_save_settings (
1985 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1989 /* now we store the common transport account settings */
1990 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1991 modest_server_account_settings_set_username (transport_settings, username);
1992 modest_server_account_settings_set_password (transport_settings, password);
1993 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1995 g_object_unref (transport_settings);
1996 g_free (transport_hostname);
1998 fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1999 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
2000 modest_account_settings_set_fullname (priv->settings, fullname);
2001 modest_account_settings_set_email_address (priv->settings, email_address);
2002 /* we don't set retrieve type to preserve advanced settings if
2003 any. By default account settings are set to headers only */
2005 /* Save the connection-specific SMTP server accounts. */
2006 modest_account_settings_set_use_connection_specific_smtp
2008 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
2010 display_name = get_entered_account_title (self);
2011 modest_account_settings_set_display_name (priv->settings, display_name);
2012 g_free (display_name);