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 "maemo/easysetup/modest-easysetup-country-combo-box.h"
44 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
45 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
46 #include "widgets/modest-serversecurity-combo-box.h"
47 #include "widgets/modest-secureauth-combo-box.h"
48 #include "widgets/modest-validating-entry.h"
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-account-mgr-helpers.h"
52 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "maemo/modest-connection-specific-smtp-window.h"
54 #include "widgets/modest-ui-constants.h"
55 #include "widgets/modest-account-settings-dialog.h"
56 #include "maemo/modest-maemo-utils.h"
57 #include "modest-utils.h"
58 #include <gconf/gconf-client.h>
59 #include <string.h> /* For strlen(). */
60 #include "maemo/modest-hildon-includes.h"
62 /* Include config.h so that _() works: */
67 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
69 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
70 MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
71 ModestEasysetupWizardDialogPrivate))
73 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
77 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
78 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
79 } ModestEasysetupWizardDialogServerChanges;
81 struct _ModestEasysetupWizardDialogPrivate
83 ModestPresets *presets;
85 /* Remember what fields the user edited manually to not prefill them
87 ModestEasysetupWizardDialogServerChanges server_changes;
89 /* Check if the user changes a field to show a confirmation dialog */
92 /* If we have a pending load of settings or not. */
93 gboolean pending_load_settings;
95 /* Used by derived widgets to query existing accounts,
96 * and to create new accounts: */
97 ModestAccountMgr *account_manager;
98 ModestAccountSettings *settings;
100 /* notebook pages: */
101 GtkWidget *page_welcome;
103 GtkWidget *page_account_details;
104 GtkWidget *combo_account_country;
105 GtkWidget *combo_account_serviceprovider;
106 GtkWidget *entry_account_title;
108 GtkWidget *page_user_details;
109 GtkWidget *entry_user_name;
110 GtkWidget *entry_user_username;
111 GtkWidget *entry_user_password;
112 GtkWidget *entry_user_email;
114 GtkWidget *page_complete_easysetup;
116 GtkWidget *page_custom_incoming;
117 GtkWidget *combo_incoming_servertype;
118 GtkWidget *caption_incoming;
119 GtkWidget *entry_incomingserver;
120 GtkWidget *combo_incoming_security;
121 GtkWidget *checkbox_incoming_auth;
123 GtkWidget *page_custom_outgoing;
124 GtkWidget *entry_outgoingserver;
125 GtkWidget *combo_outgoing_security;
126 GtkWidget *combo_outgoing_auth;
127 GtkWidget *checkbox_outgoing_smtp_specific;
128 GtkWidget *button_outgoing_smtp_servers;
130 GtkWidget *page_complete_customsetup;
132 GtkWidget *specific_window;
135 static void save_to_settings (ModestEasysetupWizardDialog *self);
139 on_delete_event (GtkWidget *widget,
141 ModestEasysetupWizardDialog *wizard)
143 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
148 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
150 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
151 g_return_if_fail (priv != NULL);
156 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
157 GValue *value, GParamSpec *pspec)
159 switch (property_id) {
161 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
166 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
167 const GValue *value, GParamSpec *pspec)
169 switch (property_id) {
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
176 modest_easysetup_wizard_dialog_dispose (GObject *object)
178 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
179 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
183 modest_easysetup_wizard_dialog_finalize (GObject *object)
185 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
186 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
188 if (priv->account_manager)
189 g_object_unref (G_OBJECT (priv->account_manager));
192 modest_presets_destroy (priv->presets);
194 if (priv->specific_window)
195 gtk_widget_destroy (priv->specific_window);
198 g_object_unref (priv->settings);
200 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
204 show_error (GtkWidget *parent_widget, const gchar* text);
207 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
210 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
212 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
214 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
215 ModestPresetsSecurity security_incoming)
217 int serverport_incoming = 0;
218 /* We don't check for SMTP here as that is impossible for an incoming server. */
219 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
220 serverport_incoming =
221 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
222 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
223 serverport_incoming =
224 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
226 return serverport_incoming;
230 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
232 GError *error = NULL;
233 ModestTransportStoreProtocol protocol;
234 const gchar* hostname;
235 const gchar* username;
236 ModestConnectionProtocol protocol_security_incoming;
238 GList *list_auth_methods;
239 ModestEasysetupWizardDialogPrivate *priv;
241 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
242 protocol = easysetup_servertype_combo_box_get_active_servertype (
243 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
244 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
245 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
246 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
247 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
248 port_num = get_serverport_incoming(protocol, protocol_security_incoming);
249 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol, hostname, port_num,
250 username, GTK_WINDOW (self), &error);
252 if (list_auth_methods) {
253 /* TODO: Select the correct method */
256 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
257 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
258 if (modest_protocol_info_auth_is_secure(auth)) {
259 list = g_list_append(list, GINT_TO_POINTER(auth));
263 g_list_free(list_auth_methods);
269 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
270 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
272 show_error (GTK_WIDGET(self), _("Could not discover supported secure authentication methods."));
281 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
283 GList* methods = check_for_supported_auth_methods(self);
289 g_list_free(methods);
293 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* self)
295 ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
297 GList* methods = check_for_supported_auth_methods(self);
300 /* Use the first one: */
301 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
302 g_list_free(methods);
309 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
311 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
313 /* Call the vfunc, which may be overridden by derived classes: */
314 if (klass->enable_buttons) {
315 GtkNotebook *notebook = NULL;
316 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
318 const gint current_page_num = gtk_notebook_get_current_page (notebook);
319 if (current_page_num == -1)
322 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
323 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
328 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
330 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
332 invoke_enable_buttons_vfunc(self);
336 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
338 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
340 invoke_enable_buttons_vfunc(self);
343 /** This is a convenience function to create a caption containing a mandatory widget.
344 * When the widget is edited, the enable_buttons() vfunc will be called.
346 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
351 HildonCaptionStatus flag)
353 GtkWidget *caption = NULL;
355 /* Note: Previously, the translated strings already contained the "*",
356 * Comment out this code if they do again.
358 /* Add a * character to indicate mandatory fields,
359 * as specified in our "Email UI Specification": */
360 if (flag == HILDON_CAPTION_MANDATORY) {
361 gchar* title = g_strdup_printf("%s*", value);
362 caption = hildon_caption_new (group, title, control, icon, flag);
366 caption = hildon_caption_new (group, value, control, icon, flag);
368 /* Connect to the appropriate changed signal for the widget,
369 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
371 if (GTK_IS_ENTRY (control)) {
372 g_signal_connect (G_OBJECT (control), "changed",
373 G_CALLBACK (on_caption_entry_changed), self);
376 else if (GTK_IS_COMBO_BOX (control)) {
377 g_signal_connect (G_OBJECT (control), "changed",
378 G_CALLBACK (on_caption_combobox_changed), self);
385 create_page_welcome (ModestEasysetupWizardDialog *self)
387 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
388 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
389 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
390 /* So that it is not truncated: */
391 gtk_widget_set_size_request (label, 600, -1);
392 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
393 gtk_widget_show (label);
394 gtk_widget_show (GTK_WIDGET (box));
395 return GTK_WIDGET (box);
399 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
401 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
403 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
407 /* Fill the providers combo, based on the selected country: */
408 if (priv->presets != NULL) {
409 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
410 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
411 easysetup_provider_combo_box_fill (
412 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider), priv->presets, mcc);
417 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
419 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
421 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
425 /* Fill the providers combo, based on the selected country: */
426 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
427 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
429 gchar* domain_name = NULL;
431 domain_name = modest_presets_get_domain (priv->presets, provider_id);
434 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
436 if (priv->entry_user_email)
437 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), domain_name);
439 g_free (domain_name);
441 g_free (provider_id);
445 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
447 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
448 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
452 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
454 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
456 const gchar *show_char = NULL;
458 show_char = character;
460 /* TODO: We need a logical ID for this: */
461 show_char = _("whitespace");
464 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
465 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
466 show_error (GTK_WIDGET (self), message);
470 get_default_country_code(void)
472 /* TODO: Default to the current country somehow.
473 * But I don't know how to get the information that is specified in the
474 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
476 * This is probably not the best choice of gconf key:
477 * This is the "mcc used in the last pairing", ie. the last connection you made.
478 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
481 GError *error = NULL;
482 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
483 gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
489 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
490 g_error_free (error);
496 /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
497 * This might just be a Maemo bug.
501 /* For now, we default to Finland when there is nothing better: */
508 create_page_account_details (ModestEasysetupWizardDialog *self)
510 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
511 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
512 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
514 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
515 gtk_widget_set_size_request (label, 600, -1);
516 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
517 gtk_widget_show (label);
519 /* Create a size group to be used by all captions.
520 * Note that HildonCaption does not create a default size group if we do not specify one.
521 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
522 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
524 /* The country widgets: */
525 priv->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
526 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
527 priv->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
528 gtk_widget_show (priv->combo_account_country);
529 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
530 gtk_widget_show (caption);
532 /* connect to country combo's changed signal, so we can fill the provider combo: */
533 g_signal_connect (G_OBJECT (priv->combo_account_country), "changed",
534 G_CALLBACK (on_combo_account_country), self);
536 GtkWidget *separator = gtk_hseparator_new ();
537 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
538 gtk_widget_show (separator);
540 /* The service provider widgets: */
541 priv->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
542 gtk_widget_set_size_request (priv->combo_account_serviceprovider, 320, -1);
544 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
545 priv->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
546 gtk_widget_show (priv->combo_account_serviceprovider);
547 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
548 gtk_widget_show (caption);
550 /* connect to providers combo's changed signal, so we can fill the email address: */
551 g_signal_connect (G_OBJECT (priv->combo_account_serviceprovider), "changed",
552 G_CALLBACK (on_combo_account_serviceprovider), self);
554 /* The description widgets: */
555 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
556 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
557 G_CALLBACK(on_easysetup_changed), self);
558 /* Do use auto-capitalization: */
559 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
560 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
562 /* Set a default account title, choosing one that does not already exist: */
563 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
564 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
565 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
566 priv->account_manager, default_account_name_start);
567 g_free (default_account_name_start);
568 default_account_name_start = NULL;
570 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title), default_account_name);
571 g_free (default_account_name);
572 default_account_name = NULL;
574 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
575 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
576 gtk_widget_show (priv->entry_account_title);
577 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
578 gtk_widget_show (caption);
580 /* Prevent the use of some characters in the account title,
581 * as required by our UI specification: */
582 GList *list_prevent = NULL;
583 list_prevent = g_list_append (list_prevent, "\\");
584 list_prevent = g_list_append (list_prevent, "/");
585 list_prevent = g_list_append (list_prevent, ":");
586 list_prevent = g_list_append (list_prevent, "*");
587 list_prevent = g_list_append (list_prevent, "?");
588 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
589 list_prevent = g_list_append (list_prevent, "“");
590 list_prevent = g_list_append (list_prevent, "<");
591 list_prevent = g_list_append (list_prevent, ">");
592 list_prevent = g_list_append (list_prevent, "|");
593 list_prevent = g_list_append (list_prevent, "^");
594 modest_validating_entry_set_unallowed_characters (
595 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
596 g_list_free (list_prevent);
598 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
599 on_entry_invalid_character, self);
601 /* Set max length as in the UI spec:
602 * The UI spec seems to want us to show a dialog if we hit the maximum. */
603 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
604 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
607 gtk_widget_show (GTK_WIDGET (box));
609 return GTK_WIDGET (box);
613 create_page_user_details (ModestEasysetupWizardDialog *self)
615 GtkSizeGroup* sizegroup;
617 ModestEasysetupWizardDialogPrivate *priv;
619 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
621 /* Create a size group to be used by all captions.
622 * Note that HildonCaption does not create a default size group if we do not specify one.
623 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
624 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
625 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
627 /* The name widgets: (use auto cap) */
628 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
629 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
630 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
632 /* Set max length as in the UI spec:
633 * The UI spec seems to want us to show a dialog if we hit the maximum. */
634 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
635 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
637 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
638 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
639 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
640 G_CALLBACK(on_easysetup_changed), self);
641 gtk_widget_show (priv->entry_user_name);
642 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
643 gtk_widget_show (caption);
645 /* Prevent the use of some characters in the name,
646 * as required by our UI specification: */
647 GList *list_prevent = NULL;
648 list_prevent = g_list_append (list_prevent, "<");
649 list_prevent = g_list_append (list_prevent, ">");
650 modest_validating_entry_set_unallowed_characters (
651 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
652 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
653 on_entry_invalid_character, self);
654 g_list_free (list_prevent);
656 /* The username widgets: */
657 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
658 /* Auto-capitalization is the default, so let's turn it off: */
659 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
660 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
661 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
662 gtk_widget_show (priv->entry_user_username);
663 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
664 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
665 G_CALLBACK(on_easysetup_changed), self);
666 gtk_widget_show (caption);
668 /* Prevent the use of some characters in the username,
669 * as required by our UI specification: */
670 modest_validating_entry_set_unallowed_characters_whitespace (
671 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
672 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
673 on_entry_invalid_character, self);
675 /* Set max length as in the UI spec:
676 * The UI spec seems to want us to show a dialog if we hit the maximum. */
677 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
678 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
681 /* The password widgets: */
682 priv->entry_user_password = gtk_entry_new ();
683 /* Auto-capitalization is the default, so let's turn it off: */
684 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
685 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
686 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
687 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
688 caption = create_caption_new_with_asterisk (self, sizegroup,
689 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
690 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
691 G_CALLBACK(on_easysetup_changed), self);
692 gtk_widget_show (priv->entry_user_password);
693 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
694 gtk_widget_show (caption);
696 /* The email address widgets: */
697 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
698 /* Auto-capitalization is the default, so let's turn it off: */
699 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
700 caption = create_caption_new_with_asterisk (self, sizegroup,
701 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
702 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
703 gtk_widget_show (priv->entry_user_email);
704 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
705 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
706 G_CALLBACK(on_easysetup_changed), self);
707 gtk_widget_show (caption);
709 /* Set max length as in the UI spec:
710 * The UI spec seems to want us to show a dialog if we hit the maximum. */
711 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
712 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
716 gtk_widget_show (GTK_WIDGET (box));
718 return GTK_WIDGET (box);
721 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
723 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
725 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
726 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
727 gtk_widget_set_size_request (label, 600, -1);
728 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
729 /* The documentation for gtk_label_set_line_wrap() says that we must
730 * call gtk_widget_set_size_request() with a hard-coded width,
731 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
732 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
733 gtk_widget_show (label);
735 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
736 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
737 gtk_widget_set_size_request (label, 600, -1);
739 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
740 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
741 gtk_widget_show (label);
743 gtk_widget_show (GTK_WIDGET (box));
744 return GTK_WIDGET (box);
747 /** Change the caption title for the incoming server,
748 * as specified in the UI spec:
751 update_incoming_server_title (ModestEasysetupWizardDialog *self)
753 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
754 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
755 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
757 (protocol == MODEST_PROTOCOL_STORE_POP ?
758 _("mail_fi_emailtype_pop3") :
759 _("mail_fi_emailtype_imap") );
762 /* Note that this produces a compiler warning,
763 * because the compiler does not know that the translated string will have a %s in it.
764 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
765 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
766 g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
767 g_free(incomingserver_title);
770 /** Change the caption title for the incoming server,
771 * as specified in the UI spec:
774 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
776 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
777 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
778 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
780 /* Fill the combo with appropriately titled choices for POP or IMAP. */
781 /* The choices are the same, but the titles are different, as in the UI spec. */
782 modest_serversecurity_combo_box_fill (
783 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol);
787 on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
789 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
790 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
794 update_incoming_server_title (self);
795 update_incoming_server_security_choices (self);
797 set_default_custom_servernames (self);
801 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
803 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
804 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
806 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
810 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
812 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
813 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
814 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
816 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
818 GTK_POLICY_AUTOMATIC);
820 /* Show note that account type cannot be changed in future: */
821 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
822 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
823 gtk_widget_set_size_request (label, 600, -1);
824 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
825 gtk_widget_show (label);
827 /* Create a size group to be used by all captions.
828 * Note that HildonCaption does not create a default size group if we do not specify one.
829 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
830 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
832 /* The incoming server widgets: */
833 priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
834 easysetup_servertype_combo_box_set_active_servertype (
835 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
836 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
837 _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
838 gtk_widget_show (priv->combo_incoming_servertype);
839 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
840 gtk_widget_show (caption);
842 priv->entry_incomingserver = gtk_entry_new ();
843 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
844 /* Auto-capitalization is the default, so let's turn it off: */
845 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
846 set_default_custom_servernames (self);
848 /* The caption title will be updated in update_incoming_server_title().
849 * so this default text will never be seen: */
850 /* (Note: Changing the title seems pointless. murrayc) */
851 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
852 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
853 update_incoming_server_title (self);
854 gtk_widget_show (priv->entry_incomingserver);
855 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
856 gtk_widget_show (priv->caption_incoming);
858 /* Change the caption title when the servertype changes,
859 * as in the UI spec: */
860 g_signal_connect (G_OBJECT (priv->combo_incoming_servertype), "changed",
861 G_CALLBACK (on_combo_servertype_changed), self);
863 /* Remember when the servername was changed manually: */
864 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
865 G_CALLBACK (on_entry_incoming_servername_changed), self);
867 /* The secure connection widgets: */
868 priv->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
869 update_incoming_server_security_choices (self);
870 modest_serversecurity_combo_box_set_active_serversecurity (
871 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
872 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
873 priv->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
874 g_signal_connect (G_OBJECT (priv->combo_incoming_security), "changed",
875 G_CALLBACK (on_easysetup_changed), self);
876 gtk_widget_show (priv->combo_incoming_security);
877 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
878 gtk_widget_show (caption);
880 priv->checkbox_incoming_auth = gtk_check_button_new ();
881 g_signal_connect (G_OBJECT (priv->checkbox_incoming_auth), "toggled",
882 G_CALLBACK (on_easysetup_changed), self);
883 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
884 priv->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
886 gtk_widget_show (priv->checkbox_incoming_auth);
887 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
888 gtk_widget_show (caption);
890 gtk_widget_show (GTK_WIDGET (box));
892 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
893 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
894 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
895 gtk_widget_show (scrolled_window);
897 return GTK_WIDGET (scrolled_window);
901 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
903 GtkWidget *widget = GTK_WIDGET (user_data);
905 /* Enable the widget only if the toggle button is active: */
906 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
907 gtk_widget_set_sensitive (widget, enable);
910 /* Make the sensitivity of a widget depend on a toggle button.
913 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
915 g_signal_connect (G_OBJECT (button), "toggled",
916 G_CALLBACK (on_toggle_button_changed), widget);
918 /* Set the starting sensitivity: */
919 on_toggle_button_changed (button, widget);
923 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
925 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
926 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
928 /* We set dirty here because setting it depending on the connection specific dialog
932 /* Create the window, if necessary: */
933 if (!(priv->specific_window)) {
934 priv->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
935 modest_connection_specific_smtp_window_fill_with_connections (
936 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window), priv->account_manager);
939 /* Show the window: */
940 gtk_window_set_transient_for (GTK_WINDOW (priv->specific_window), GTK_WINDOW (self));
941 gtk_window_set_modal (GTK_WINDOW (priv->specific_window), TRUE);
942 gtk_widget_show (priv->specific_window);
946 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
948 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
949 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
950 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
954 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
956 ModestEasysetupWizardDialogPrivate *priv;
957 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
959 /* Create a size group to be used by all captions.
960 * Note that HildonCaption does not create a default size group if we do not specify one.
961 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
962 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
964 /* The outgoing server widgets: */
965 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
966 priv->entry_outgoingserver = gtk_entry_new ();
967 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
968 G_CALLBACK (on_easysetup_changed), self);
969 /* Auto-capitalization is the default, so let's turn it off: */
970 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
971 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
972 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
973 gtk_widget_show (priv->entry_outgoingserver);
974 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
975 gtk_widget_show (caption);
976 set_default_custom_servernames (self);
978 /* The secure connection widgets: */
979 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
980 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed",
981 G_CALLBACK (on_easysetup_changed), self);
982 modest_serversecurity_combo_box_fill (
983 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
984 modest_serversecurity_combo_box_set_active_serversecurity (
985 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
986 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
987 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
988 gtk_widget_show (priv->combo_outgoing_security);
989 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
990 gtk_widget_show (caption);
992 /* The secure authentication widgets: */
993 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
994 g_signal_connect (G_OBJECT (priv->combo_outgoing_auth), "changed",
995 G_CALLBACK (on_easysetup_changed), self);
996 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
997 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
998 gtk_widget_show (priv->combo_outgoing_auth);
999 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1000 gtk_widget_show (caption);
1002 GtkWidget *separator = gtk_hseparator_new ();
1003 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
1004 gtk_widget_show (separator);
1006 /* connection-specific checkbox: */
1007 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
1008 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1010 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1011 G_CALLBACK (on_easysetup_changed), self);
1013 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
1014 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
1015 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1016 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1017 gtk_widget_show (caption);
1019 /* Connection-specific SMTP-Severs Edit button: */
1020 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
1021 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
1022 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
1023 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1024 gtk_widget_show (priv->button_outgoing_smtp_servers);
1025 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1026 gtk_widget_show (caption);
1028 /* Only enable the button when the checkbox is checked: */
1029 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
1030 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
1032 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1033 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1035 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1036 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1039 gtk_widget_show (GTK_WIDGET (box));
1041 return GTK_WIDGET (box);
1045 show_advanced_edit(gpointer user_data)
1047 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1048 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1051 /* Show the Account Settings window: */
1052 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
1053 if (priv->pending_load_settings) {
1054 save_to_settings (self);
1055 priv->pending_load_settings = FALSE;
1057 modest_account_settings_dialog_set_account (dialog, priv->settings);
1059 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
1061 response = gtk_dialog_run (GTK_DIALOG (dialog));
1063 gtk_widget_destroy (GTK_WIDGET (dialog));
1065 return FALSE; /* Do not call this timeout callback again. */
1069 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1071 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1073 /* Show the Account Settings window: */
1074 show_advanced_edit(self);
1076 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1078 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1079 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1080 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1081 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1082 gtk_widget_set_size_request (label, 600, -1);
1083 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1084 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1085 gtk_widget_show (label);
1087 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1088 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1089 gtk_widget_set_size_request (label, 600, -1);
1090 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1091 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1092 gtk_widget_show (label);
1094 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1095 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1096 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1097 gtk_widget_show (button_edit);
1098 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1099 gtk_widget_show (caption);
1101 g_signal_connect (G_OBJECT (button_edit), "clicked",
1102 G_CALLBACK (on_button_edit_advanced_settings), self);
1104 gtk_widget_show (GTK_WIDGET (box));
1105 return GTK_WIDGET (box);
1112 on_response (ModestWizardDialog *wizard_dialog,
1116 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1118 invoke_enable_buttons_vfunc (self);
1122 on_response_before (ModestWizardDialog *wizard_dialog,
1126 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1127 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1128 if (response_id == GTK_RESPONSE_CANCEL) {
1129 /* This is mostly copied from
1130 * src/maemo/modest-account-settings-dialog.c */
1132 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1133 _("imum_nc_wizard_confirm_lose_changes")));
1134 /* TODO: These button names will be ambiguous, and not
1135 * specified in the UI specification. */
1137 const gint dialog_response = gtk_dialog_run (dialog);
1138 gtk_widget_destroy (GTK_WIDGET (dialog));
1140 if (dialog_response != GTK_RESPONSE_OK) {
1141 /* Don't let the dialog close */
1142 g_signal_stop_emission_by_name (wizard_dialog, "response");
1148 typedef struct IdleData {
1149 ModestEasysetupWizardDialog *dialog;
1150 ModestPresets *presets;
1154 presets_idle (gpointer userdata)
1156 IdleData *idle_data = (IdleData *) userdata;
1157 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1158 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1160 g_assert (idle_data->presets);
1162 gdk_threads_enter ();
1164 priv->presets = idle_data->presets;
1166 if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) {
1167 gint mcc = get_default_country_code();
1168 /* Fill the combo in an idle call, as it takes a lot of time */
1169 easysetup_country_combo_box_load_data(
1170 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
1171 easysetup_country_combo_box_set_active_country_mcc (
1172 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc);
1173 easysetup_provider_combo_box_fill (
1174 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider),
1175 priv->presets, mcc);
1178 priv->dirty = FALSE;
1180 g_object_unref (idle_data->dialog);
1183 gdk_threads_leave ();
1189 presets_loader (gpointer userdata)
1191 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1192 ModestPresets *presets = NULL;
1193 IdleData *idle_data;
1195 const gchar* path = NULL;
1196 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1197 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1199 if (access(path1, R_OK) == 0)
1201 else if (access(path2, R_OK) == 0)
1204 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1205 __FUNCTION__, path1, path2);
1209 presets = modest_presets_new (path);
1211 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1215 idle_data = g_new0 (IdleData, 1);
1216 idle_data->dialog = self;
1217 idle_data->presets = presets;
1219 g_idle_add (presets_idle, idle_data);
1225 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1227 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1229 /* Create the notebook to be used by the ModestWizardDialog base class:
1230 * Each page of the notebook will be a page of the wizard: */
1231 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1233 /* Set the notebook used by the ModestWizardDialog base class: */
1234 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1236 /* Set the wizard title:
1237 * The actual window title will be a combination of this and the page's tab label title. */
1238 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1240 /* Read in the information about known service providers: */
1241 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1243 /* The server fields did not have been manually changed yet */
1244 priv->server_changes = 0;
1245 priv->pending_load_settings = TRUE;
1247 /* Get the account manager object,
1248 * so we can check for existing accounts,
1249 * and create new accounts: */
1250 priv->account_manager = modest_runtime_get_account_mgr ();
1251 g_object_ref (priv->account_manager);
1253 /* Initialize fields */
1254 priv->page_welcome = create_page_welcome (self);
1255 priv->page_account_details = create_page_account_details (self);
1256 priv->page_user_details = create_page_user_details (self);
1257 priv->page_complete_easysetup = NULL;
1258 priv->page_custom_incoming = NULL;
1259 priv->combo_incoming_servertype = NULL;
1260 priv->caption_incoming = NULL;
1261 priv->entry_incomingserver = NULL;
1262 priv->combo_incoming_security = NULL;
1263 priv->checkbox_incoming_auth = NULL;
1264 priv->page_custom_outgoing = NULL;
1265 priv->entry_outgoingserver = NULL;
1266 priv->combo_outgoing_security = NULL;
1267 priv->combo_outgoing_auth = NULL;
1268 priv->checkbox_outgoing_smtp_specific = NULL;
1269 priv->button_outgoing_smtp_servers = NULL;
1270 priv->page_complete_customsetup = NULL;
1271 priv->specific_window = NULL;
1273 /* Add the common pages: */
1274 gtk_notebook_append_page (notebook, priv->page_welcome,
1275 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1276 gtk_container_child_set (GTK_CONTAINER (notebook),
1282 gtk_notebook_append_page (notebook, priv->page_account_details,
1283 gtk_label_new (_("mcen_ti_accountdetails")));
1284 gtk_container_child_set (GTK_CONTAINER (notebook),
1285 priv->page_account_details,
1290 gtk_notebook_append_page (notebook, priv->page_user_details,
1291 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1292 gtk_container_child_set (GTK_CONTAINER (notebook),
1293 priv->page_user_details,
1298 /* Create and add the easysetup-specific pages,
1299 * because we need _some_ final page to enable the Next and Finish buttons: */
1300 create_subsequent_easysetup_pages (self);
1302 /* Connect to the dialog's response signal so we can enable/disable buttons
1303 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1304 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1305 * so that we can be enable/disable after ModestWizardDialog has done its own
1306 * enabling/disabling of buttons.
1308 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1309 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1311 * It's not enough to connect to the notebook's switch-page signal, because
1312 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1313 * _after_ switching the page (understandably).
1314 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1315 * then gtk_notebook_get_current_page() would return an incorrect value.)
1317 g_signal_connect_after (G_OBJECT (self), "response",
1318 G_CALLBACK (on_response), self);
1320 /* This is to show a confirmation dialog when the user hits cancel */
1321 g_signal_connect (G_OBJECT (self), "response",
1322 G_CALLBACK (on_response_before), self);
1324 g_signal_connect (G_OBJECT (self), "delete-event",
1325 G_CALLBACK (on_delete_event), self);
1327 /* Reset dirty, because there was no user input until now */
1328 priv->dirty = FALSE;
1330 /* When this window is shown, hibernation should not be possible,
1331 * because there is no sensible way to save the state: */
1332 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1333 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1335 /* Load provider presets */
1336 g_object_ref (self);
1337 g_thread_create (presets_loader, self, FALSE, NULL);
1339 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1340 modest_maemo_utils_get_osso_context());
1342 priv->settings = modest_account_settings_new ();
1345 ModestEasysetupWizardDialog*
1346 modest_easysetup_wizard_dialog_new (void)
1349 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1352 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1354 ModestEasysetupWizardDialogPrivate *priv;
1355 GtkNotebook *notebook = NULL;
1357 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1360 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1362 /* Create the custom pages: */
1363 if(!(priv->page_custom_incoming)) {
1364 priv->page_custom_incoming = create_page_custom_incoming (self);
1367 if(!(priv->page_custom_outgoing)) {
1368 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1371 if(!(priv->page_complete_customsetup)) {
1372 priv->page_complete_customsetup = create_page_complete_custom (self);
1375 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1376 gtk_notebook_append_page (notebook, priv->page_custom_incoming,
1377 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1379 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1380 gtk_notebook_append_page (notebook, priv->page_custom_outgoing,
1381 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1383 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup))) {
1384 gtk_notebook_append_page (notebook, priv->page_complete_customsetup,
1385 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1386 gtk_container_child_set (GTK_CONTAINER (notebook),
1387 priv->page_complete_customsetup,
1393 /* This is unnecessary with GTK+ 2.10: */
1394 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1398 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1400 ModestEasysetupWizardDialogPrivate *priv;
1401 GtkNotebook *notebook = NULL;
1403 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1406 /* Create the easysetup-specific pages: */
1407 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1408 if(!priv->page_complete_easysetup)
1409 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1411 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup))) {
1412 gtk_notebook_append_page (notebook, priv->page_complete_easysetup,
1413 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1414 gtk_container_child_set (GTK_CONTAINER (notebook),
1415 priv->page_complete_easysetup,
1421 /* This is unnecessary with GTK+ 2.10: */
1422 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1424 /* After the user details page,
1425 * the following pages depend on whether "Other" was chosen
1426 * in the provider combobox on the account page
1428 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1430 ModestEasysetupWizardDialogPrivate *priv;
1432 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1434 if (easysetup_provider_combo_box_get_active_provider_id (
1435 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider)) == 0) {
1436 /* "Other..." was selected: */
1438 /* Make sure that the easysetup pages do not exist: */
1439 if(priv->page_complete_easysetup) {
1440 gtk_widget_destroy (priv->page_complete_easysetup);
1441 priv->page_complete_easysetup = NULL;
1444 create_subsequent_customsetup_pages (self);
1447 /* A specific provider was selected: */
1449 /* Make sure that the custom pages do not exist:
1450 * Because they will be used if they exist, when creating the account. */
1451 if(priv->page_custom_incoming) {
1452 gtk_widget_destroy (priv->page_custom_incoming);
1453 priv->page_custom_incoming = NULL;
1454 priv->combo_incoming_servertype = NULL;
1455 priv->caption_incoming = NULL;
1456 priv->entry_incomingserver = NULL;
1457 priv->combo_incoming_security = NULL;
1458 priv->checkbox_incoming_auth = NULL;
1461 if(priv->page_custom_outgoing) {
1462 gtk_widget_destroy (priv->page_custom_outgoing);
1463 priv->page_custom_outgoing = NULL;
1464 priv->entry_outgoingserver = NULL;
1465 priv->combo_outgoing_security = NULL;
1466 priv->combo_outgoing_auth = NULL;
1467 priv->checkbox_outgoing_smtp_specific = NULL;
1468 priv->button_outgoing_smtp_servers = NULL;
1471 if(priv->page_complete_customsetup) {
1472 gtk_widget_destroy (priv->page_complete_customsetup);
1473 priv->page_complete_customsetup = NULL;
1477 /* Create the easysetup pages: */
1478 create_subsequent_easysetup_pages (self);
1484 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1489 gchar* at = g_utf8_strchr (email_address, -1, '@');
1490 if (!at || (g_utf8_strlen (at, -1) < 2))
1493 gchar* domain = g_utf8_next_char (at);
1497 const gchar* hostname = NULL;
1498 if (servertype == MODEST_PROTOCOL_STORE_POP)
1500 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1502 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1508 return g_strdup_printf ("%s.%s", hostname, domain);
1512 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1514 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1516 if (!priv->entry_incomingserver)
1519 /* Set a default domain for the server, based on the email address,
1520 * if no server name was already specified.
1522 if (priv->entry_user_email
1523 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1524 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1525 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1526 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1528 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1530 /* Do not set the INCOMING_CHANGED flag because of this edit */
1531 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1532 gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
1533 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1535 g_free (servername);
1538 /* Set a default domain for the server, based on the email address,
1539 * if no server name was already specified.
1541 if (!priv->entry_outgoingserver)
1544 if (priv->entry_user_email
1545 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1546 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1548 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1550 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1551 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1552 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), servername);
1553 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1555 g_free (servername);
1560 get_entered_account_title (ModestEasysetupWizardDialog *self)
1562 ModestEasysetupWizardDialogPrivate *priv;
1563 const gchar* account_title;
1565 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1566 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
1568 if (!account_title || (strlen (account_title) == 0)) {
1571 /* Strip it of whitespace at the start and end: */
1572 gchar *result = g_strdup (account_title);
1573 result = g_strstrip (result);
1578 if (strlen (result) == 0) {
1588 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1590 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1591 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1593 /* if are browsing pages previous to the last one, then we have pending settings in
1595 if (next_page != NULL)
1596 priv->pending_load_settings = TRUE;
1598 /* Do extra validation that couldn't be done for every key press,
1599 * either because it was too slow,
1600 * or because it requires interaction:
1602 if (current_page == priv->page_account_details) {
1603 /* Check that the title is not already in use: */
1604 gchar* account_title = get_entered_account_title (self);
1608 /* Aavoid a clash with an existing display name: */
1609 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1610 priv->account_manager, account_title);
1613 /* Warn the user via a dialog: */
1614 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1619 else if (current_page == priv->page_user_details) {
1620 /* Check that the email address is valud: */
1621 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1622 if ((!email_address) || (strlen(email_address) == 0))
1625 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1626 /* Warn the user via a dialog: */
1627 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1629 /* Return focus to the email address entry: */
1630 gtk_widget_grab_focus (priv->entry_user_email);
1631 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1636 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1637 create_subsequent_pages (self);
1640 /* TODO: The UI Spec wants us to check that the servernames are valid,
1641 * but does not specify how.
1644 if(next_page == priv->page_custom_incoming) {
1645 set_default_custom_servernames (self);
1647 else if (next_page == priv->page_custom_outgoing) {
1648 set_default_custom_servernames (self);
1650 /* Check if the server supports secure authentication */
1651 const ModestConnectionProtocol security_incoming =
1652 modest_serversecurity_combo_box_get_active_serversecurity (
1653 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1654 if (gtk_toggle_button_get_active (
1655 GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))
1656 && !modest_protocol_info_is_secure(security_incoming))
1658 if (!check_has_supported_auth_methods (self))
1663 /* If this is the last page, and this is a click on Finish,
1664 * then attempt to create the dialog.
1666 if(!next_page) /* This is NULL when this is a click on Finish. */
1668 if (priv->pending_load_settings) {
1669 save_to_settings (self);
1671 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1678 static gboolean entry_is_empty (GtkWidget *entry)
1683 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1684 if ((!text) || (strlen(text) == 0))
1687 /* Strip it of whitespace at the start and end: */
1688 gchar *stripped = g_strdup (text);
1689 stripped = g_strstrip (stripped);
1694 const gboolean result = (strlen (stripped) == 0);
1702 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1704 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1705 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1707 gboolean enable_next = TRUE;
1708 if (current_page == priv->page_welcome) {
1711 else if (current_page == priv->page_account_details) {
1712 /* The account details title is mandatory: */
1713 if (entry_is_empty(priv->entry_account_title))
1714 enable_next = FALSE;
1716 else if (current_page == priv->page_user_details) {
1717 /* The user details username is mandatory: */
1718 if (entry_is_empty(priv->entry_user_username))
1719 enable_next = FALSE;
1721 /* The user details email address is mandatory: */
1722 if (enable_next && entry_is_empty (priv->entry_user_email))
1723 enable_next = FALSE;
1725 else if (current_page == priv->page_custom_incoming) {
1726 /* The custom incoming server is mandatory: */
1727 if (entry_is_empty(priv->entry_incomingserver))
1728 enable_next = FALSE;
1731 /* Enable the buttons,
1732 * identifying them via their associated response codes: */
1734 /* Disable the Finish button until we are on the last page,
1735 * because HildonWizardDialog enables this for all but the first page: */
1736 GtkNotebook *notebook = NULL;
1737 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1738 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1740 gint current = gtk_notebook_get_current_page (notebook);
1741 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1742 const gboolean is_last = (current == last);
1745 gtk_dialog_set_response_sensitive (dialog_base,
1746 MODEST_WIZARD_DIALOG_FINISH,
1750 /* Disable Next on the last page: */
1751 enable_next = FALSE;
1754 gtk_dialog_set_response_sensitive (dialog_base,
1755 MODEST_WIZARD_DIALOG_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->get_property = modest_easysetup_wizard_dialog_get_property;
1767 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1768 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1769 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1771 /* Provide a vfunc implementation so we can decide
1772 * when to enable/disable the prev/next buttons.
1774 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1775 base_klass->before_next = on_before_next;
1776 base_klass->enable_buttons = on_enable_buttons;
1780 show_error (GtkWidget *parent_widget, const gchar* text)
1782 //TODO: Apparently this doesn't show anything in Maemo Bora:
1783 hildon_banner_show_information(parent_widget, NULL, text);
1789 * @self: a #ModestEasysetupWizardDialog
1791 * takes information from all the wizard and stores it in settings
1794 save_to_settings (ModestEasysetupWizardDialog *self)
1796 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1799 gchar* display_name;
1800 const gchar *username, *password;
1801 gchar *store_hostname, *transport_hostname;
1802 guint store_port, transport_port;
1803 ModestTransportStoreProtocol store_protocol, transport_protocol;
1804 ModestConnectionProtocol store_security, transport_security;
1805 ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
1806 ModestServerAccountSettings *store_settings, *transport_settings;
1807 const gchar *fullname, *email_address;
1809 /* Get details from the specified presets: */
1810 provider_id = easysetup_provider_combo_box_get_active_provider_id (
1811 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
1813 /* username and password (for both incoming and outgoing): */
1814 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1815 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1817 /* Incoming server: */
1818 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1819 * or modest_account_mgr_add_server_account will fail. */
1821 store_protocol = MODEST_PROTOCOL_STORE_POP;
1822 store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1823 store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1826 ModestPresetsServerType store_provider_server_type;
1827 ModestPresetsSecurity store_provider_security;
1829 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1832 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1835 store_provider_security = modest_presets_get_info_server_security (priv->presets,
1839 /* We don't check for SMTP here as that is impossible for an incoming server. */
1840 if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
1841 store_protocol = MODEST_PROTOCOL_STORE_IMAP;
1842 else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
1843 store_protocol = MODEST_PROTOCOL_STORE_POP;
1845 store_protocol = MODEST_PROTOCOL_STORE_POP;
1847 /* we check if there is a *special* port */
1848 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1849 if (special_port != 0)
1850 store_port = special_port;
1852 store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
1854 if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1855 store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1857 if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
1858 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1860 /* Use custom pages because no preset was specified: */
1861 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));
1862 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1863 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1864 store_security = modest_serversecurity_combo_box_get_active_serversecurity (
1865 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1867 /* The UI spec says:
1868 * If secure authentication is unchecked, allow sending username and password also as plain text.
1869 * If secure authentication is checked, require one of the secure methods during
1870 * connection: SSL, TLS, CRAM-MD5 etc. */
1871 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth)) &&
1872 !modest_protocol_info_is_secure(store_security)) {
1873 store_auth_protocol = check_first_supported_auth_method (self);
1875 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1879 /* now we store the store account settings */
1880 store_settings = modest_account_settings_get_store_settings (priv->settings);
1881 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1882 modest_server_account_settings_set_username (store_settings, username);
1883 modest_server_account_settings_set_password (store_settings, password);
1884 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1885 modest_server_account_settings_set_security (store_settings, store_security);
1886 modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1887 if (store_port != 0)
1888 modest_server_account_settings_set_port (store_settings, store_port);
1890 g_object_unref (store_settings);
1891 g_free (store_hostname);
1893 /* Outgoing server: */
1894 transport_hostname = NULL;
1895 transport_protocol = MODEST_PROTOCOL_STORE_POP;
1896 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1897 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1901 ModestPresetsServerType transport_provider_server_type;
1902 ModestPresetsSecurity transport_provider_security;
1905 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1906 FALSE /* transport */);
1908 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1910 FALSE /* transport */);
1911 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1913 FALSE /* transport */);
1915 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1916 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1917 if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
1918 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
1920 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1921 if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1922 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1923 transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1924 /* we check if there is a *special* port */
1925 special_port = modest_presets_get_port (priv->presets, provider_id,
1926 FALSE /* transport */);
1927 if (special_port != 0)
1928 transport_port = special_port;
1930 transport_port = 465;
1931 transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1933 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1934 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1937 /* Use custom pages because no preset was specified: */
1938 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
1939 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1940 transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
1941 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
1942 transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
1943 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
1946 /* now we transport the transport account settings */
1947 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1948 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1949 modest_server_account_settings_set_username (transport_settings, username);
1950 modest_server_account_settings_set_password (transport_settings, password);
1951 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1952 modest_server_account_settings_set_security (transport_settings, transport_security);
1953 modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1954 if (transport_port != 0)
1955 modest_server_account_settings_set_port (transport_settings, transport_port);
1957 g_object_unref (transport_settings);
1958 g_free (transport_hostname);
1960 fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1961 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1962 modest_account_settings_set_fullname (priv->settings, fullname);
1963 modest_account_settings_set_email_address (priv->settings, email_address);
1964 /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1965 are set to headers only */
1967 /* Save the connection-specific SMTP server accounts. */
1968 modest_account_settings_set_use_connection_specific_smtp
1970 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1972 display_name = get_entered_account_title (self);
1973 modest_account_settings_set_display_name (priv->settings, display_name);
1974 g_free (display_name);
1976 if (priv->specific_window)
1977 modest_connection_specific_smtp_window_save_server_accounts (
1978 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window));