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;
133 static void save_to_settings (ModestEasysetupWizardDialog *self);
137 on_delete_event (GtkWidget *widget,
139 ModestEasysetupWizardDialog *wizard)
141 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
146 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
148 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
149 g_return_if_fail (priv != NULL);
154 on_incoming_security_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
156 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
157 ModestConnectionProtocol protocol_security_incoming;
159 g_return_if_fail (priv != NULL);
160 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
161 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
163 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth), modest_protocol_info_is_secure (protocol_security_incoming));
164 gtk_widget_set_sensitive (priv->checkbox_incoming_auth, !modest_protocol_info_is_secure (protocol_security_incoming));
166 on_easysetup_changed (widget, wizard);
170 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
171 GValue *value, GParamSpec *pspec)
173 switch (property_id) {
175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
180 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
181 const GValue *value, GParamSpec *pspec)
183 switch (property_id) {
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
190 modest_easysetup_wizard_dialog_dispose (GObject *object)
192 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
193 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
197 modest_easysetup_wizard_dialog_finalize (GObject *object)
199 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
200 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
202 if (priv->account_manager)
203 g_object_unref (G_OBJECT (priv->account_manager));
206 modest_presets_destroy (priv->presets);
209 g_object_unref (priv->settings);
211 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
215 show_error (GtkWidget *parent_widget, const gchar* text);
218 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
221 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
223 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
225 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
226 ModestPresetsSecurity security_incoming)
228 int serverport_incoming = 0;
229 /* We don't check for SMTP here as that is impossible for an incoming server. */
230 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
231 serverport_incoming =
232 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
233 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
234 serverport_incoming =
235 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
237 return serverport_incoming;
241 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
243 GError *error = NULL;
244 ModestTransportStoreProtocol protocol;
245 const gchar* hostname;
246 const gchar* username;
247 ModestConnectionProtocol protocol_security_incoming;
249 GList *list_auth_methods;
250 ModestEasysetupWizardDialogPrivate *priv;
252 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
253 protocol = easysetup_servertype_combo_box_get_active_servertype (
254 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
255 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
256 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
257 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
258 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
259 port_num = get_serverport_incoming(protocol, protocol_security_incoming);
260 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol, hostname, port_num,
261 username, GTK_WINDOW (self), &error);
263 if (list_auth_methods) {
264 /* TODO: Select the correct method */
267 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
268 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
269 if (modest_protocol_info_auth_is_secure(auth)) {
270 list = g_list_append(list, GINT_TO_POINTER(auth));
274 g_list_free(list_auth_methods);
280 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
281 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
283 show_error (GTK_WIDGET(self), _("mcen_ib_unableto_discover_auth_methods"));
292 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
294 GList* methods = check_for_supported_auth_methods(self);
300 g_list_free(methods);
304 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* self)
306 ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
308 GList* methods = check_for_supported_auth_methods(self);
311 /* Use the first one: */
312 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
313 g_list_free(methods);
320 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
322 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
324 /* Call the vfunc, which may be overridden by derived classes: */
325 if (klass->enable_buttons) {
326 GtkNotebook *notebook = NULL;
327 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
329 const gint current_page_num = gtk_notebook_get_current_page (notebook);
330 if (current_page_num == -1)
333 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
334 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
339 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
341 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
343 invoke_enable_buttons_vfunc(self);
347 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
349 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
351 invoke_enable_buttons_vfunc(self);
354 /** This is a convenience function to create a caption containing a mandatory widget.
355 * When the widget is edited, the enable_buttons() vfunc will be called.
357 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
362 HildonCaptionStatus flag)
364 GtkWidget *caption = NULL;
366 /* Note: Previously, the translated strings already contained the "*",
367 * Comment out this code if they do again.
369 /* Add a * character to indicate mandatory fields,
370 * as specified in our "Email UI Specification": */
371 if (flag == HILDON_CAPTION_MANDATORY) {
372 gchar* title = g_strdup_printf("%s*", value);
373 caption = hildon_caption_new (group, title, control, icon, flag);
377 caption = hildon_caption_new (group, value, control, icon, flag);
379 /* Connect to the appropriate changed signal for the widget,
380 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
382 if (GTK_IS_ENTRY (control)) {
383 g_signal_connect (G_OBJECT (control), "changed",
384 G_CALLBACK (on_caption_entry_changed), self);
387 else if (GTK_IS_COMBO_BOX (control)) {
388 g_signal_connect (G_OBJECT (control), "changed",
389 G_CALLBACK (on_caption_combobox_changed), self);
396 create_page_welcome (ModestEasysetupWizardDialog *self)
398 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
399 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
400 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
401 /* So that it is not truncated: */
402 gtk_widget_set_size_request (label, 600, -1);
403 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
404 gtk_widget_show (label);
405 gtk_widget_show (GTK_WIDGET (box));
406 return GTK_WIDGET (box);
410 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
412 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
414 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
418 /* Fill the providers combo, based on the selected country: */
419 if (priv->presets != NULL) {
420 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
421 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
422 easysetup_provider_combo_box_fill (
423 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider), priv->presets, mcc);
428 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
430 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
432 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
436 /* Fill the providers combo, based on the selected country: */
437 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
438 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
440 gchar* domain_name = NULL;
442 domain_name = modest_presets_get_domain (priv->presets, provider_id);
445 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
447 if (priv->entry_user_email)
448 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), domain_name);
450 g_free (domain_name);
452 g_free (provider_id);
456 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
458 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
459 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
463 get_default_country_code(void)
465 /* TODO: Default to the current country somehow.
466 * But I don't know how to get the information that is specified in the
467 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
469 * This is probably not the best choice of gconf key:
470 * This is the "mcc used in the last pairing", ie. the last connection you made.
471 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
474 GError *error = NULL;
475 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
476 gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
482 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
483 g_error_free (error);
489 /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
490 * This might just be a Maemo bug.
494 /* For now, we default to Finland when there is nothing better: */
501 create_page_account_details (ModestEasysetupWizardDialog *self)
503 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
504 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
505 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
507 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
508 gtk_widget_set_size_request (label, 600, -1);
509 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
510 gtk_widget_show (label);
512 /* Create a size group to be used by all captions.
513 * Note that HildonCaption does not create a default size group if we do not specify one.
514 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
515 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
517 /* The country widgets: */
518 priv->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
519 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
520 priv->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
521 gtk_widget_show (priv->combo_account_country);
522 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
523 gtk_widget_show (caption);
525 /* connect to country combo's changed signal, so we can fill the provider combo: */
526 g_signal_connect (G_OBJECT (priv->combo_account_country), "changed",
527 G_CALLBACK (on_combo_account_country), self);
529 GtkWidget *separator = gtk_hseparator_new ();
530 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
531 gtk_widget_show (separator);
533 /* The service provider widgets: */
534 priv->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
535 gtk_widget_set_size_request (priv->combo_account_serviceprovider, 320, -1);
537 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
538 priv->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
539 gtk_widget_show (priv->combo_account_serviceprovider);
540 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
541 gtk_widget_show (caption);
543 /* connect to providers combo's changed signal, so we can fill the email address: */
544 g_signal_connect (G_OBJECT (priv->combo_account_serviceprovider), "changed",
545 G_CALLBACK (on_combo_account_serviceprovider), self);
547 /* The description widgets: */
548 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
549 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
550 G_CALLBACK(on_easysetup_changed), self);
551 /* Do use auto-capitalization: */
552 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
553 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
555 /* Set a default account title, choosing one that does not already exist: */
556 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
557 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
558 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
559 priv->account_manager, default_account_name_start);
560 g_free (default_account_name_start);
561 default_account_name_start = NULL;
563 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title), default_account_name);
564 g_free (default_account_name);
565 default_account_name = NULL;
567 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
568 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
569 gtk_widget_show (priv->entry_account_title);
570 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
571 gtk_widget_show (caption);
573 /* Prevent the use of some characters in the account title,
574 * as required by our UI specification: */
575 GList *list_prevent = NULL;
576 list_prevent = g_list_append (list_prevent, "\\");
577 list_prevent = g_list_append (list_prevent, "/");
578 list_prevent = g_list_append (list_prevent, ":");
579 list_prevent = g_list_append (list_prevent, "*");
580 list_prevent = g_list_append (list_prevent, "?");
581 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
582 list_prevent = g_list_append (list_prevent, "“");
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 modest_validating_entry_set_unallowed_characters (
588 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
589 g_list_free (list_prevent);
591 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
592 modest_maemo_utils_on_entry_invalid_character, self);
594 /* Set max length as in the UI spec:
595 * The UI spec seems to want us to show a dialog if we hit the maximum. */
596 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
597 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
600 gtk_widget_show (GTK_WIDGET (box));
602 return GTK_WIDGET (box);
606 create_page_user_details (ModestEasysetupWizardDialog *self)
608 GtkSizeGroup* sizegroup;
610 ModestEasysetupWizardDialogPrivate *priv;
612 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
614 /* Create a size group to be used by all captions.
615 * Note that HildonCaption does not create a default size group if we do not specify one.
616 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
617 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
618 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
620 /* The name widgets: (use auto cap) */
621 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
622 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
623 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
625 /* Set max length as in the UI spec:
626 * The UI spec seems to want us to show a dialog if we hit the maximum. */
627 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
628 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
630 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
631 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
632 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
633 G_CALLBACK(on_easysetup_changed), self);
634 gtk_widget_show (priv->entry_user_name);
635 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
636 gtk_widget_show (caption);
638 /* Prevent the use of some characters in the name,
639 * as required by our UI specification: */
640 GList *list_prevent = NULL;
641 list_prevent = g_list_append (list_prevent, "<");
642 list_prevent = g_list_append (list_prevent, ">");
643 modest_validating_entry_set_unallowed_characters (
644 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
645 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
646 modest_maemo_utils_on_entry_invalid_character, self);
647 g_list_free (list_prevent);
649 /* The username widgets: */
650 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
651 /* Auto-capitalization is the default, so let's turn it off: */
652 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
653 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
654 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
655 gtk_widget_show (priv->entry_user_username);
656 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
657 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
658 G_CALLBACK(on_easysetup_changed), self);
659 gtk_widget_show (caption);
661 /* Prevent the use of some characters in the username,
662 * as required by our UI specification: */
663 modest_validating_entry_set_unallowed_characters_whitespace (
664 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
665 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
666 modest_maemo_utils_on_entry_invalid_character, self);
668 /* Set max length as in the UI spec:
669 * The UI spec seems to want us to show a dialog if we hit the maximum. */
670 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
671 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
674 /* The password widgets: */
675 priv->entry_user_password = gtk_entry_new ();
676 /* Auto-capitalization is the default, so let's turn it off: */
677 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
678 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
679 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
680 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
681 caption = create_caption_new_with_asterisk (self, sizegroup,
682 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
683 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
684 G_CALLBACK(on_easysetup_changed), self);
685 gtk_widget_show (priv->entry_user_password);
686 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
687 gtk_widget_show (caption);
689 /* The email address widgets: */
690 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
691 /* Auto-capitalization is the default, so let's turn it off: */
692 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
693 caption = create_caption_new_with_asterisk (self, sizegroup,
694 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
695 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
696 gtk_widget_show (priv->entry_user_email);
697 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
698 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
699 G_CALLBACK(on_easysetup_changed), self);
700 gtk_widget_show (caption);
702 /* Set max length as in the UI spec:
703 * The UI spec seems to want us to show a dialog if we hit the maximum. */
704 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
705 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
709 gtk_widget_show (GTK_WIDGET (box));
711 return GTK_WIDGET (box);
714 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
716 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
718 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
719 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
720 gtk_widget_set_size_request (label, 600, -1);
721 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
722 /* The documentation for gtk_label_set_line_wrap() says that we must
723 * call gtk_widget_set_size_request() with a hard-coded width,
724 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
725 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
726 gtk_widget_show (label);
728 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
729 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
730 gtk_widget_set_size_request (label, 600, -1);
732 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
733 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
734 gtk_widget_show (label);
736 gtk_widget_show (GTK_WIDGET (box));
737 return GTK_WIDGET (box);
740 /** Change the caption title for the incoming server,
741 * as specified in the UI spec:
744 update_incoming_server_title (ModestEasysetupWizardDialog *self)
746 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
747 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
748 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
750 (protocol == MODEST_PROTOCOL_STORE_POP ?
751 _("mail_fi_emailtype_pop3") :
752 _("mail_fi_emailtype_imap") );
755 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
756 g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
757 g_free(incomingserver_title);
760 /** Change the caption title for the incoming server,
761 * as specified in the UI spec:
764 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
766 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
767 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
768 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
770 /* Fill the combo with appropriately titled choices for POP or IMAP. */
771 /* The choices are the same, but the titles are different, as in the UI spec. */
772 modest_serversecurity_combo_box_fill (
773 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol);
777 on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
779 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
780 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
784 update_incoming_server_title (self);
785 update_incoming_server_security_choices (self);
787 set_default_custom_servernames (self);
791 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
793 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
794 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
796 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
800 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
802 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
803 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
804 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
806 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
808 GTK_POLICY_AUTOMATIC);
810 /* Show note that account type cannot be changed in future: */
811 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
812 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
813 gtk_widget_set_size_request (label, 600, -1);
814 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
815 gtk_widget_show (label);
817 /* Create a size group to be used by all captions.
818 * Note that HildonCaption does not create a default size group if we do not specify one.
819 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
820 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
822 /* The incoming server widgets: */
823 priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
824 easysetup_servertype_combo_box_set_active_servertype (
825 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
826 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
827 _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
828 gtk_widget_show (priv->combo_incoming_servertype);
829 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
830 gtk_widget_show (caption);
832 priv->entry_incomingserver = gtk_entry_new ();
833 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
834 /* Auto-capitalization is the default, so let's turn it off: */
835 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
836 set_default_custom_servernames (self);
838 /* The caption title will be updated in update_incoming_server_title().
839 * so this default text will never be seen: */
840 /* (Note: Changing the title seems pointless. murrayc) */
841 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
842 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
843 update_incoming_server_title (self);
844 gtk_widget_show (priv->entry_incomingserver);
845 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
846 gtk_widget_show (priv->caption_incoming);
848 /* Change the caption title when the servertype changes,
849 * as in the UI spec: */
850 g_signal_connect (G_OBJECT (priv->combo_incoming_servertype), "changed",
851 G_CALLBACK (on_combo_servertype_changed), self);
853 /* Remember when the servername was changed manually: */
854 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
855 G_CALLBACK (on_entry_incoming_servername_changed), self);
857 /* The secure connection widgets: */
858 priv->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
859 update_incoming_server_security_choices (self);
860 modest_serversecurity_combo_box_set_active_serversecurity (
861 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
862 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
863 priv->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
864 g_signal_connect (G_OBJECT (priv->combo_incoming_security), "changed",
865 G_CALLBACK (on_incoming_security_changed), self);
866 gtk_widget_show (priv->combo_incoming_security);
867 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
868 gtk_widget_show (caption);
870 priv->checkbox_incoming_auth = gtk_check_button_new ();
871 g_signal_connect (G_OBJECT (priv->checkbox_incoming_auth), "toggled",
872 G_CALLBACK (on_easysetup_changed), self);
873 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
874 priv->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
876 gtk_widget_show (priv->checkbox_incoming_auth);
877 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
878 gtk_widget_show (caption);
880 gtk_widget_show (GTK_WIDGET (box));
882 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
883 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
884 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
885 gtk_widget_show (scrolled_window);
887 return GTK_WIDGET (scrolled_window);
891 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
893 GtkWidget *widget = GTK_WIDGET (user_data);
895 /* Enable the widget only if the toggle button is active: */
896 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
897 gtk_widget_set_sensitive (widget, enable);
900 /* Make the sensitivity of a widget depend on a toggle button.
903 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
905 g_signal_connect (G_OBJECT (button), "toggled",
906 G_CALLBACK (on_toggle_button_changed), widget);
908 /* Set the starting sensitivity: */
909 on_toggle_button_changed (button, widget);
913 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
915 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
916 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
917 GtkWidget *specific_window;
919 /* We set dirty here because setting it depending on the connection specific dialog
923 /* Create the window, if necessary: */
924 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
925 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
927 /* Show the window */
928 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window));
929 gtk_widget_show (specific_window);
933 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
935 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
936 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
937 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
941 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
943 ModestEasysetupWizardDialogPrivate *priv;
944 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
946 /* Create a size group to be used by all captions.
947 * Note that HildonCaption does not create a default size group if we do not specify one.
948 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
949 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
951 /* The outgoing server widgets: */
952 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
953 priv->entry_outgoingserver = gtk_entry_new ();
954 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
955 G_CALLBACK (on_easysetup_changed), self);
956 /* Auto-capitalization is the default, so let's turn it off: */
957 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
958 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
959 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
960 gtk_widget_show (priv->entry_outgoingserver);
961 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
962 gtk_widget_show (caption);
963 set_default_custom_servernames (self);
965 /* The secure connection widgets: */
966 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
967 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed",
968 G_CALLBACK (on_easysetup_changed), self);
969 modest_serversecurity_combo_box_fill (
970 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
971 modest_serversecurity_combo_box_set_active_serversecurity (
972 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
973 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
974 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
975 gtk_widget_show (priv->combo_outgoing_security);
976 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
977 gtk_widget_show (caption);
979 /* The secure authentication widgets: */
980 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
981 g_signal_connect (G_OBJECT (priv->combo_outgoing_auth), "changed",
982 G_CALLBACK (on_easysetup_changed), self);
983 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
984 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
985 gtk_widget_show (priv->combo_outgoing_auth);
986 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
987 gtk_widget_show (caption);
989 GtkWidget *separator = gtk_hseparator_new ();
990 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
991 gtk_widget_show (separator);
993 /* connection-specific checkbox: */
994 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
995 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
997 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
998 G_CALLBACK (on_easysetup_changed), self);
1000 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
1001 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
1002 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1003 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1004 gtk_widget_show (caption);
1006 /* Connection-specific SMTP-Severs Edit button: */
1007 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
1008 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
1009 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
1010 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1011 gtk_widget_show (priv->button_outgoing_smtp_servers);
1012 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1013 gtk_widget_show (caption);
1015 /* Only enable the button when the checkbox is checked: */
1016 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
1017 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
1019 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1020 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1022 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1023 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1026 gtk_widget_show (GTK_WIDGET (box));
1028 return GTK_WIDGET (box);
1032 show_advanced_edit(gpointer user_data)
1034 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1035 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1038 /* Show the Account Settings window: */
1039 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
1040 if (priv->pending_load_settings) {
1041 save_to_settings (self);
1042 priv->pending_load_settings = FALSE;
1044 modest_account_settings_dialog_set_account (dialog, priv->settings);
1046 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
1048 response = gtk_dialog_run (GTK_DIALOG (dialog));
1050 gtk_widget_destroy (GTK_WIDGET (dialog));
1052 return FALSE; /* Do not call this timeout callback again. */
1056 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1058 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1060 /* Show the Account Settings window: */
1061 show_advanced_edit(self);
1063 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1065 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1066 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1067 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1068 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1069 gtk_widget_set_size_request (label, 600, -1);
1070 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1071 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1072 gtk_widget_show (label);
1074 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1075 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1076 gtk_widget_set_size_request (label, 600, -1);
1077 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1078 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1079 gtk_widget_show (label);
1081 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1082 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1083 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1084 gtk_widget_show (button_edit);
1085 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1086 gtk_widget_show (caption);
1088 g_signal_connect (G_OBJECT (button_edit), "clicked",
1089 G_CALLBACK (on_button_edit_advanced_settings), self);
1091 gtk_widget_show (GTK_WIDGET (box));
1092 return GTK_WIDGET (box);
1099 on_response (ModestWizardDialog *wizard_dialog,
1103 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1105 invoke_enable_buttons_vfunc (self);
1109 on_response_before (ModestWizardDialog *wizard_dialog,
1113 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1114 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1115 if (response_id == GTK_RESPONSE_CANCEL) {
1116 /* This is mostly copied from
1117 * src/maemo/modest-account-settings-dialog.c */
1119 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1120 _("imum_nc_wizard_confirm_lose_changes")));
1121 /* TODO: These button names will be ambiguous, and not
1122 * specified in the UI specification. */
1124 const gint dialog_response = gtk_dialog_run (dialog);
1125 gtk_widget_destroy (GTK_WIDGET (dialog));
1127 if (dialog_response != GTK_RESPONSE_OK) {
1128 /* Don't let the dialog close */
1129 g_signal_stop_emission_by_name (wizard_dialog, "response");
1135 typedef struct IdleData {
1136 ModestEasysetupWizardDialog *dialog;
1137 ModestPresets *presets;
1141 presets_idle (gpointer userdata)
1143 IdleData *idle_data = (IdleData *) userdata;
1144 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1145 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1147 g_assert (idle_data->presets);
1149 gdk_threads_enter ();
1151 priv->presets = idle_data->presets;
1153 if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) {
1154 gint mcc = get_default_country_code();
1155 /* Fill the combo in an idle call, as it takes a lot of time */
1156 easysetup_country_combo_box_load_data(
1157 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
1158 easysetup_country_combo_box_set_active_country_mcc (
1159 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc);
1160 easysetup_provider_combo_box_fill (
1161 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider),
1162 priv->presets, mcc);
1165 priv->dirty = FALSE;
1167 g_object_unref (idle_data->dialog);
1170 gdk_threads_leave ();
1176 presets_loader (gpointer userdata)
1178 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1179 ModestPresets *presets = NULL;
1180 IdleData *idle_data;
1182 const gchar* path = NULL;
1183 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1184 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1186 if (access(path1, R_OK) == 0)
1188 else if (access(path2, R_OK) == 0)
1191 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1192 __FUNCTION__, path1, path2);
1196 presets = modest_presets_new (path);
1198 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1202 idle_data = g_new0 (IdleData, 1);
1203 idle_data->dialog = self;
1204 idle_data->presets = presets;
1206 g_idle_add (presets_idle, idle_data);
1212 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1214 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1216 /* Create the notebook to be used by the ModestWizardDialog base class:
1217 * Each page of the notebook will be a page of the wizard: */
1218 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1220 /* Set the notebook used by the ModestWizardDialog base class: */
1221 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1223 /* Set the wizard title:
1224 * The actual window title will be a combination of this and the page's tab label title. */
1225 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1227 /* Read in the information about known service providers: */
1228 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1230 /* The server fields did not have been manually changed yet */
1231 priv->server_changes = 0;
1232 priv->pending_load_settings = TRUE;
1234 /* Get the account manager object,
1235 * so we can check for existing accounts,
1236 * and create new accounts: */
1237 priv->account_manager = modest_runtime_get_account_mgr ();
1238 g_object_ref (priv->account_manager);
1240 /* Initialize fields */
1241 priv->page_welcome = create_page_welcome (self);
1242 priv->page_account_details = create_page_account_details (self);
1243 priv->page_user_details = create_page_user_details (self);
1244 priv->page_complete_easysetup = NULL;
1245 priv->page_custom_incoming = NULL;
1246 priv->combo_incoming_servertype = NULL;
1247 priv->caption_incoming = NULL;
1248 priv->entry_incomingserver = NULL;
1249 priv->combo_incoming_security = NULL;
1250 priv->checkbox_incoming_auth = NULL;
1251 priv->page_custom_outgoing = NULL;
1252 priv->entry_outgoingserver = NULL;
1253 priv->combo_outgoing_security = NULL;
1254 priv->combo_outgoing_auth = NULL;
1255 priv->checkbox_outgoing_smtp_specific = NULL;
1256 priv->button_outgoing_smtp_servers = NULL;
1257 priv->page_complete_customsetup = NULL;
1259 /* Add the common pages: */
1260 gtk_notebook_append_page (notebook, priv->page_welcome,
1261 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1262 gtk_container_child_set (GTK_CONTAINER (notebook),
1268 gtk_notebook_append_page (notebook, priv->page_account_details,
1269 gtk_label_new (_("mcen_ti_accountdetails")));
1270 gtk_container_child_set (GTK_CONTAINER (notebook),
1271 priv->page_account_details,
1276 gtk_notebook_append_page (notebook, priv->page_user_details,
1277 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1278 gtk_container_child_set (GTK_CONTAINER (notebook),
1279 priv->page_user_details,
1284 /* Create and add the easysetup-specific pages,
1285 * because we need _some_ final page to enable the Next and Finish buttons: */
1286 create_subsequent_easysetup_pages (self);
1288 /* Connect to the dialog's response signal so we can enable/disable buttons
1289 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1290 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1291 * so that we can be enable/disable after ModestWizardDialog has done its own
1292 * enabling/disabling of buttons.
1294 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1295 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1297 * It's not enough to connect to the notebook's switch-page signal, because
1298 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1299 * _after_ switching the page (understandably).
1300 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1301 * then gtk_notebook_get_current_page() would return an incorrect value.)
1303 g_signal_connect_after (G_OBJECT (self), "response",
1304 G_CALLBACK (on_response), self);
1306 /* This is to show a confirmation dialog when the user hits cancel */
1307 g_signal_connect (G_OBJECT (self), "response",
1308 G_CALLBACK (on_response_before), self);
1310 g_signal_connect (G_OBJECT (self), "delete-event",
1311 G_CALLBACK (on_delete_event), self);
1313 /* Reset dirty, because there was no user input until now */
1314 priv->dirty = FALSE;
1316 /* When this window is shown, hibernation should not be possible,
1317 * because there is no sensible way to save the state: */
1318 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1319 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1321 /* Load provider presets */
1322 g_object_ref (self);
1323 g_thread_create (presets_loader, self, FALSE, NULL);
1325 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1326 modest_maemo_utils_get_osso_context());
1328 priv->settings = modest_account_settings_new ();
1331 ModestEasysetupWizardDialog*
1332 modest_easysetup_wizard_dialog_new (void)
1335 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1338 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1340 ModestEasysetupWizardDialogPrivate *priv;
1341 GtkNotebook *notebook = NULL;
1343 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1346 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1348 /* Create the custom pages: */
1349 if(!(priv->page_custom_incoming)) {
1350 priv->page_custom_incoming = create_page_custom_incoming (self);
1353 if(!(priv->page_custom_outgoing)) {
1354 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1357 if(!(priv->page_complete_customsetup)) {
1358 priv->page_complete_customsetup = create_page_complete_custom (self);
1361 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1362 gtk_notebook_append_page (notebook, priv->page_custom_incoming,
1363 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1365 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1366 gtk_notebook_append_page (notebook, priv->page_custom_outgoing,
1367 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1369 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup))) {
1370 gtk_notebook_append_page (notebook, priv->page_complete_customsetup,
1371 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1372 gtk_container_child_set (GTK_CONTAINER (notebook),
1373 priv->page_complete_customsetup,
1379 /* This is unnecessary with GTK+ 2.10: */
1380 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1384 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1386 ModestEasysetupWizardDialogPrivate *priv;
1387 GtkNotebook *notebook = NULL;
1389 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1392 /* Create the easysetup-specific pages: */
1393 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1394 if(!priv->page_complete_easysetup)
1395 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1397 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup))) {
1398 gtk_notebook_append_page (notebook, priv->page_complete_easysetup,
1399 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1400 gtk_container_child_set (GTK_CONTAINER (notebook),
1401 priv->page_complete_easysetup,
1407 /* This is unnecessary with GTK+ 2.10: */
1408 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1410 /* After the user details page,
1411 * the following pages depend on whether "Other" was chosen
1412 * in the provider combobox on the account page
1414 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1416 ModestEasysetupWizardDialogPrivate *priv;
1418 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1420 if (easysetup_provider_combo_box_get_active_provider_id (
1421 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider)) == 0) {
1422 /* "Other..." was selected: */
1424 /* Make sure that the easysetup pages do not exist: */
1425 if(priv->page_complete_easysetup) {
1426 gtk_widget_destroy (priv->page_complete_easysetup);
1427 priv->page_complete_easysetup = NULL;
1430 create_subsequent_customsetup_pages (self);
1433 /* A specific provider was selected: */
1435 /* Make sure that the custom pages do not exist:
1436 * Because they will be used if they exist, when creating the account. */
1437 if(priv->page_custom_incoming) {
1438 gtk_widget_destroy (priv->page_custom_incoming);
1439 priv->page_custom_incoming = NULL;
1440 priv->combo_incoming_servertype = NULL;
1441 priv->caption_incoming = NULL;
1442 priv->entry_incomingserver = NULL;
1443 priv->combo_incoming_security = NULL;
1444 priv->checkbox_incoming_auth = NULL;
1447 if(priv->page_custom_outgoing) {
1448 gtk_widget_destroy (priv->page_custom_outgoing);
1449 priv->page_custom_outgoing = NULL;
1450 priv->entry_outgoingserver = NULL;
1451 priv->combo_outgoing_security = NULL;
1452 priv->combo_outgoing_auth = NULL;
1453 priv->checkbox_outgoing_smtp_specific = NULL;
1454 priv->button_outgoing_smtp_servers = NULL;
1457 if(priv->page_complete_customsetup) {
1458 gtk_widget_destroy (priv->page_complete_customsetup);
1459 priv->page_complete_customsetup = NULL;
1463 /* Create the easysetup pages: */
1464 create_subsequent_easysetup_pages (self);
1470 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1475 gchar* at = g_utf8_strchr (email_address, -1, '@');
1476 if (!at || (g_utf8_strlen (at, -1) < 2))
1479 gchar* domain = g_utf8_next_char (at);
1483 const gchar* hostname = NULL;
1484 if (servertype == MODEST_PROTOCOL_STORE_POP)
1486 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1488 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1494 return g_strdup_printf ("%s.%s", hostname, domain);
1498 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1500 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1502 if (!priv->entry_incomingserver)
1505 /* Set a default domain for the server, based on the email address,
1506 * if no server name was already specified.
1508 if (priv->entry_user_email
1509 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1510 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1511 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1512 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1514 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1516 /* Do not set the INCOMING_CHANGED flag because of this edit */
1517 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1518 gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
1519 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1521 g_free (servername);
1524 /* Set a default domain for the server, based on the email address,
1525 * if no server name was already specified.
1527 if (!priv->entry_outgoingserver)
1530 if (priv->entry_user_email
1531 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1532 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1534 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1536 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1537 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1538 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), servername);
1539 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1541 g_free (servername);
1546 get_entered_account_title (ModestEasysetupWizardDialog *self)
1548 ModestEasysetupWizardDialogPrivate *priv;
1549 const gchar* account_title;
1551 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1552 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
1554 if (!account_title || (strlen (account_title) == 0)) {
1557 /* Strip it of whitespace at the start and end: */
1558 gchar *result = g_strdup (account_title);
1559 result = g_strstrip (result);
1564 if (strlen (result) == 0) {
1574 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1576 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1577 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1579 /* if are browsing pages previous to the last one, then we have pending settings in
1581 if (next_page != NULL)
1582 priv->pending_load_settings = TRUE;
1584 /* Do extra validation that couldn't be done for every key press,
1585 * either because it was too slow,
1586 * or because it requires interaction:
1588 if (current_page == priv->page_account_details) {
1589 /* Check that the title is not already in use: */
1590 gchar* account_title = get_entered_account_title (self);
1594 /* Aavoid a clash with an existing display name: */
1595 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1596 priv->account_manager, account_title);
1599 /* Warn the user via a dialog: */
1600 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1605 else if (current_page == priv->page_user_details) {
1606 /* Check that the email address is valud: */
1607 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1608 if ((!email_address) || (strlen(email_address) == 0))
1611 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1612 /* Warn the user via a dialog: */
1613 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1615 /* Return focus to the email address entry: */
1616 gtk_widget_grab_focus (priv->entry_user_email);
1617 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1622 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1623 create_subsequent_pages (self);
1626 /* TODO: The UI Spec wants us to check that the servernames are valid,
1627 * but does not specify how.
1630 if(next_page == priv->page_custom_incoming) {
1631 set_default_custom_servernames (self);
1633 else if (next_page == priv->page_custom_outgoing) {
1634 set_default_custom_servernames (self);
1636 /* Check if the server supports secure authentication */
1637 const ModestConnectionProtocol security_incoming =
1638 modest_serversecurity_combo_box_get_active_serversecurity (
1639 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1640 if (gtk_toggle_button_get_active (
1641 GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))
1642 && !modest_protocol_info_is_secure(security_incoming))
1644 if (!check_has_supported_auth_methods (self))
1649 /* If this is the last page, and this is a click on Finish,
1650 * then attempt to create the dialog.
1652 if(!next_page) /* This is NULL when this is a click on Finish. */
1654 if (priv->pending_load_settings) {
1655 save_to_settings (self);
1657 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1664 static gboolean entry_is_empty (GtkWidget *entry)
1669 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1670 if ((!text) || (strlen(text) == 0))
1673 /* Strip it of whitespace at the start and end: */
1674 gchar *stripped = g_strdup (text);
1675 stripped = g_strstrip (stripped);
1680 const gboolean result = (strlen (stripped) == 0);
1688 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1690 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1691 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1693 gboolean enable_next = TRUE;
1694 if (current_page == priv->page_welcome) {
1697 else if (current_page == priv->page_account_details) {
1698 /* The account details title is mandatory: */
1699 if (entry_is_empty(priv->entry_account_title))
1700 enable_next = FALSE;
1702 else if (current_page == priv->page_user_details) {
1703 /* The user details username is mandatory: */
1704 if (entry_is_empty(priv->entry_user_username))
1705 enable_next = FALSE;
1707 /* The user details email address is mandatory: */
1708 if (enable_next && entry_is_empty (priv->entry_user_email))
1709 enable_next = FALSE;
1711 else if (current_page == priv->page_custom_incoming) {
1712 /* The custom incoming server is mandatory: */
1713 if (entry_is_empty(priv->entry_incomingserver))
1714 enable_next = FALSE;
1717 /* Enable the buttons,
1718 * identifying them via their associated response codes: */
1720 /* Disable the Finish button until we are on the last page,
1721 * because HildonWizardDialog enables this for all but the first page: */
1722 GtkNotebook *notebook = NULL;
1723 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1724 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1726 gint current = gtk_notebook_get_current_page (notebook);
1727 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1728 const gboolean is_last = (current == last);
1731 gtk_dialog_set_response_sensitive (dialog_base,
1732 MODEST_WIZARD_DIALOG_FINISH,
1736 /* Disable Next on the last page: */
1737 enable_next = FALSE;
1740 gtk_dialog_set_response_sensitive (dialog_base,
1741 MODEST_WIZARD_DIALOG_NEXT,
1746 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1748 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1749 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1752 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1753 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1754 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1755 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1757 /* Provide a vfunc implementation so we can decide
1758 * when to enable/disable the prev/next buttons.
1760 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1761 base_klass->before_next = on_before_next;
1762 base_klass->enable_buttons = on_enable_buttons;
1766 show_error (GtkWidget *parent_widget, const gchar* text)
1768 //TODO: Apparently this doesn't show anything in Maemo Bora:
1769 hildon_banner_show_information(parent_widget, NULL, text);
1775 * @self: a #ModestEasysetupWizardDialog
1777 * takes information from all the wizard and stores it in settings
1780 save_to_settings (ModestEasysetupWizardDialog *self)
1782 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1785 gchar* display_name;
1786 const gchar *username, *password;
1787 gchar *store_hostname, *transport_hostname;
1788 guint store_port, transport_port;
1789 ModestTransportStoreProtocol store_protocol, transport_protocol;
1790 ModestConnectionProtocol store_security, transport_security;
1791 ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
1792 ModestServerAccountSettings *store_settings, *transport_settings;
1793 const gchar *fullname, *email_address;
1795 /* Get details from the specified presets: */
1796 provider_id = easysetup_provider_combo_box_get_active_provider_id (
1797 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
1799 /* username and password (for both incoming and outgoing): */
1800 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1801 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1803 /* Incoming server: */
1804 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1805 * or modest_account_mgr_add_server_account will fail. */
1807 store_protocol = MODEST_PROTOCOL_STORE_POP;
1808 store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1809 store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1812 ModestPresetsServerType store_provider_server_type;
1813 ModestPresetsSecurity store_provider_security;
1815 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1818 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1821 store_provider_security = modest_presets_get_info_server_security (priv->presets,
1825 /* We don't check for SMTP here as that is impossible for an incoming server. */
1826 if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
1827 store_protocol = MODEST_PROTOCOL_STORE_IMAP;
1828 else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
1829 store_protocol = MODEST_PROTOCOL_STORE_POP;
1831 store_protocol = MODEST_PROTOCOL_STORE_POP;
1833 /* we check if there is a *special* port */
1834 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1835 if (special_port != 0)
1836 store_port = special_port;
1838 store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
1840 if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1841 store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1843 if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
1844 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1846 /* Use custom pages because no preset was specified: */
1847 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));
1848 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1849 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1850 store_security = modest_serversecurity_combo_box_get_active_serversecurity (
1851 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1853 /* The UI spec says:
1854 * If secure authentication is unchecked, allow sending username and password also as plain text.
1855 * If secure authentication is checked, require one of the secure methods during
1856 * connection: SSL, TLS, CRAM-MD5 etc. */
1857 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth)) &&
1858 !modest_protocol_info_is_secure(store_security)) {
1859 store_auth_protocol = check_first_supported_auth_method (self);
1861 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1865 /* now we store the store account settings */
1866 store_settings = modest_account_settings_get_store_settings (priv->settings);
1867 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1868 modest_server_account_settings_set_username (store_settings, username);
1869 modest_server_account_settings_set_password (store_settings, password);
1870 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1871 modest_server_account_settings_set_security (store_settings, store_security);
1872 modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1873 if (store_port != 0)
1874 modest_server_account_settings_set_port (store_settings, store_port);
1876 g_object_unref (store_settings);
1877 g_free (store_hostname);
1879 /* Outgoing server: */
1880 transport_hostname = NULL;
1881 transport_protocol = MODEST_PROTOCOL_STORE_POP;
1882 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1883 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1887 ModestPresetsServerType transport_provider_server_type;
1888 ModestPresetsSecurity transport_provider_security;
1891 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1892 FALSE /* transport */);
1894 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1896 FALSE /* transport */);
1897 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1899 FALSE /* transport */);
1901 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1902 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1903 if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
1904 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
1906 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1907 if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1908 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1909 transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1910 /* we check if there is a *special* port */
1911 special_port = modest_presets_get_port (priv->presets, provider_id,
1912 FALSE /* transport */);
1913 if (special_port != 0)
1914 transport_port = special_port;
1916 transport_port = 465;
1917 transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1919 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1920 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1923 /* Use custom pages because no preset was specified: */
1924 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
1925 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1926 transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
1927 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
1928 transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
1929 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
1932 /* now we transport the transport account settings */
1933 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1934 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1935 modest_server_account_settings_set_username (transport_settings, username);
1936 modest_server_account_settings_set_password (transport_settings, password);
1937 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1938 modest_server_account_settings_set_security (transport_settings, transport_security);
1939 modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1940 if (transport_port != 0)
1941 modest_server_account_settings_set_port (transport_settings, transport_port);
1943 g_object_unref (transport_settings);
1944 g_free (transport_hostname);
1946 fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1947 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1948 modest_account_settings_set_fullname (priv->settings, fullname);
1949 modest_account_settings_set_email_address (priv->settings, email_address);
1950 /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1951 are set to headers only */
1953 /* Save the connection-specific SMTP server accounts. */
1954 modest_account_settings_set_use_connection_specific_smtp
1956 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1958 display_name = get_entered_account_title (self);
1959 modest_account_settings_set_display_name (priv->settings, display_name);
1960 g_free (display_name);