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 on_incoming_security_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
158 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
159 ModestConnectionProtocol protocol_security_incoming;
161 g_return_if_fail (priv != NULL);
162 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
163 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
165 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth), modest_protocol_info_is_secure (protocol_security_incoming));
166 gtk_widget_set_sensitive (priv->checkbox_incoming_auth, !modest_protocol_info_is_secure (protocol_security_incoming));
168 on_easysetup_changed (widget, wizard);
172 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
173 GValue *value, GParamSpec *pspec)
175 switch (property_id) {
177 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
182 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
183 const GValue *value, GParamSpec *pspec)
185 switch (property_id) {
187 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
192 modest_easysetup_wizard_dialog_dispose (GObject *object)
194 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
195 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
199 modest_easysetup_wizard_dialog_finalize (GObject *object)
201 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
202 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
204 if (priv->account_manager)
205 g_object_unref (G_OBJECT (priv->account_manager));
208 modest_presets_destroy (priv->presets);
210 if (priv->specific_window)
211 gtk_widget_destroy (priv->specific_window);
214 g_object_unref (priv->settings);
216 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
220 show_error (GtkWidget *parent_widget, const gchar* text);
223 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
226 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
228 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
230 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
231 ModestPresetsSecurity security_incoming)
233 int serverport_incoming = 0;
234 /* We don't check for SMTP here as that is impossible for an incoming server. */
235 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
236 serverport_incoming =
237 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
238 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
239 serverport_incoming =
240 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
242 return serverport_incoming;
246 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
248 GError *error = NULL;
249 ModestTransportStoreProtocol protocol;
250 const gchar* hostname;
251 const gchar* username;
252 ModestConnectionProtocol protocol_security_incoming;
254 GList *list_auth_methods;
255 ModestEasysetupWizardDialogPrivate *priv;
257 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
258 protocol = easysetup_servertype_combo_box_get_active_servertype (
259 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
260 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
261 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
262 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
263 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
264 port_num = get_serverport_incoming(protocol, protocol_security_incoming);
265 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol, hostname, port_num,
266 username, GTK_WINDOW (self), &error);
268 if (list_auth_methods) {
269 /* TODO: Select the correct method */
272 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
273 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
274 if (modest_protocol_info_auth_is_secure(auth)) {
275 list = g_list_append(list, GINT_TO_POINTER(auth));
279 g_list_free(list_auth_methods);
285 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
286 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
288 show_error (GTK_WIDGET(self), _("mcen_ib_unableto_discover_auth_methods"));
297 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
299 GList* methods = check_for_supported_auth_methods(self);
305 g_list_free(methods);
309 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* self)
311 ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
313 GList* methods = check_for_supported_auth_methods(self);
316 /* Use the first one: */
317 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
318 g_list_free(methods);
325 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
327 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
329 /* Call the vfunc, which may be overridden by derived classes: */
330 if (klass->enable_buttons) {
331 GtkNotebook *notebook = NULL;
332 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
334 const gint current_page_num = gtk_notebook_get_current_page (notebook);
335 if (current_page_num == -1)
338 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
339 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
344 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
346 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
348 invoke_enable_buttons_vfunc(self);
352 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
354 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
356 invoke_enable_buttons_vfunc(self);
359 /** This is a convenience function to create a caption containing a mandatory widget.
360 * When the widget is edited, the enable_buttons() vfunc will be called.
362 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
367 HildonCaptionStatus flag)
369 GtkWidget *caption = NULL;
371 /* Note: Previously, the translated strings already contained the "*",
372 * Comment out this code if they do again.
374 /* Add a * character to indicate mandatory fields,
375 * as specified in our "Email UI Specification": */
376 if (flag == HILDON_CAPTION_MANDATORY) {
377 gchar* title = g_strdup_printf("%s*", value);
378 caption = hildon_caption_new (group, title, control, icon, flag);
382 caption = hildon_caption_new (group, value, control, icon, flag);
384 /* Connect to the appropriate changed signal for the widget,
385 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
387 if (GTK_IS_ENTRY (control)) {
388 g_signal_connect (G_OBJECT (control), "changed",
389 G_CALLBACK (on_caption_entry_changed), self);
392 else if (GTK_IS_COMBO_BOX (control)) {
393 g_signal_connect (G_OBJECT (control), "changed",
394 G_CALLBACK (on_caption_combobox_changed), self);
401 create_page_welcome (ModestEasysetupWizardDialog *self)
403 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
404 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
405 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
406 /* So that it is not truncated: */
407 gtk_widget_set_size_request (label, 600, -1);
408 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
409 gtk_widget_show (label);
410 gtk_widget_show (GTK_WIDGET (box));
411 return GTK_WIDGET (box);
415 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
417 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
419 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
423 /* Fill the providers combo, based on the selected country: */
424 if (priv->presets != NULL) {
425 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
426 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
427 easysetup_provider_combo_box_fill (
428 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider), priv->presets, mcc);
433 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
435 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
437 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
441 /* Fill the providers combo, based on the selected country: */
442 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
443 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
445 gchar* domain_name = NULL;
447 domain_name = modest_presets_get_domain (priv->presets, provider_id);
450 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
452 if (priv->entry_user_email)
453 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), domain_name);
455 g_free (domain_name);
457 g_free (provider_id);
461 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
463 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
464 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
468 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
470 const gchar *show_char = NULL;
472 show_char = character;
477 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
478 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
479 show_error (GTK_WIDGET (self), message);
483 get_default_country_code(void)
485 /* TODO: Default to the current country somehow.
486 * But I don't know how to get the information that is specified in the
487 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
489 * This is probably not the best choice of gconf key:
490 * This is the "mcc used in the last pairing", ie. the last connection you made.
491 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
494 GError *error = NULL;
495 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
496 gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
502 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
503 g_error_free (error);
509 /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
510 * This might just be a Maemo bug.
514 /* For now, we default to Finland when there is nothing better: */
521 create_page_account_details (ModestEasysetupWizardDialog *self)
523 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
524 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
525 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
527 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
528 gtk_widget_set_size_request (label, 600, -1);
529 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
530 gtk_widget_show (label);
532 /* Create a size group to be used by all captions.
533 * Note that HildonCaption does not create a default size group if we do not specify one.
534 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
535 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
537 /* The country widgets: */
538 priv->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
539 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
540 priv->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
541 gtk_widget_show (priv->combo_account_country);
542 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
543 gtk_widget_show (caption);
545 /* connect to country combo's changed signal, so we can fill the provider combo: */
546 g_signal_connect (G_OBJECT (priv->combo_account_country), "changed",
547 G_CALLBACK (on_combo_account_country), self);
549 GtkWidget *separator = gtk_hseparator_new ();
550 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
551 gtk_widget_show (separator);
553 /* The service provider widgets: */
554 priv->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
555 gtk_widget_set_size_request (priv->combo_account_serviceprovider, 320, -1);
557 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
558 priv->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
559 gtk_widget_show (priv->combo_account_serviceprovider);
560 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
561 gtk_widget_show (caption);
563 /* connect to providers combo's changed signal, so we can fill the email address: */
564 g_signal_connect (G_OBJECT (priv->combo_account_serviceprovider), "changed",
565 G_CALLBACK (on_combo_account_serviceprovider), self);
567 /* The description widgets: */
568 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
569 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
570 G_CALLBACK(on_easysetup_changed), self);
571 /* Do use auto-capitalization: */
572 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
573 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
575 /* Set a default account title, choosing one that does not already exist: */
576 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
577 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
578 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
579 priv->account_manager, default_account_name_start);
580 g_free (default_account_name_start);
581 default_account_name_start = NULL;
583 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title), default_account_name);
584 g_free (default_account_name);
585 default_account_name = NULL;
587 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
588 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
589 gtk_widget_show (priv->entry_account_title);
590 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
591 gtk_widget_show (caption);
593 /* Prevent the use of some characters in the account title,
594 * as required by our UI specification: */
595 GList *list_prevent = NULL;
596 list_prevent = g_list_append (list_prevent, "\\");
597 list_prevent = g_list_append (list_prevent, "/");
598 list_prevent = g_list_append (list_prevent, ":");
599 list_prevent = g_list_append (list_prevent, "*");
600 list_prevent = g_list_append (list_prevent, "?");
601 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
602 list_prevent = g_list_append (list_prevent, "“");
603 list_prevent = g_list_append (list_prevent, "<");
604 list_prevent = g_list_append (list_prevent, ">");
605 list_prevent = g_list_append (list_prevent, "|");
606 list_prevent = g_list_append (list_prevent, "^");
607 modest_validating_entry_set_unallowed_characters (
608 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
609 g_list_free (list_prevent);
611 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
612 on_entry_invalid_character, self);
614 /* Set max length as in the UI spec:
615 * The UI spec seems to want us to show a dialog if we hit the maximum. */
616 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
617 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
620 gtk_widget_show (GTK_WIDGET (box));
622 return GTK_WIDGET (box);
626 create_page_user_details (ModestEasysetupWizardDialog *self)
628 GtkSizeGroup* sizegroup;
630 ModestEasysetupWizardDialogPrivate *priv;
632 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
634 /* Create a size group to be used by all captions.
635 * Note that HildonCaption does not create a default size group if we do not specify one.
636 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
637 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
638 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
640 /* The name widgets: (use auto cap) */
641 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
642 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
643 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
645 /* Set max length as in the UI spec:
646 * The UI spec seems to want us to show a dialog if we hit the maximum. */
647 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
648 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
650 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
651 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
652 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
653 G_CALLBACK(on_easysetup_changed), self);
654 gtk_widget_show (priv->entry_user_name);
655 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
656 gtk_widget_show (caption);
658 /* Prevent the use of some characters in the name,
659 * as required by our UI specification: */
660 GList *list_prevent = NULL;
661 list_prevent = g_list_append (list_prevent, "<");
662 list_prevent = g_list_append (list_prevent, ">");
663 modest_validating_entry_set_unallowed_characters (
664 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
665 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
666 on_entry_invalid_character, self);
667 g_list_free (list_prevent);
669 /* The username widgets: */
670 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
671 /* Auto-capitalization is the default, so let's turn it off: */
672 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
673 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
674 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
675 gtk_widget_show (priv->entry_user_username);
676 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
677 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
678 G_CALLBACK(on_easysetup_changed), self);
679 gtk_widget_show (caption);
681 /* Prevent the use of some characters in the username,
682 * as required by our UI specification: */
683 modest_validating_entry_set_unallowed_characters_whitespace (
684 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
685 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
686 on_entry_invalid_character, self);
688 /* Set max length as in the UI spec:
689 * The UI spec seems to want us to show a dialog if we hit the maximum. */
690 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
691 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
694 /* The password widgets: */
695 priv->entry_user_password = gtk_entry_new ();
696 /* Auto-capitalization is the default, so let's turn it off: */
697 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
698 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
699 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
700 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
701 caption = create_caption_new_with_asterisk (self, sizegroup,
702 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
703 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
704 G_CALLBACK(on_easysetup_changed), self);
705 gtk_widget_show (priv->entry_user_password);
706 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
707 gtk_widget_show (caption);
709 /* The email address widgets: */
710 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
711 /* Auto-capitalization is the default, so let's turn it off: */
712 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
713 caption = create_caption_new_with_asterisk (self, sizegroup,
714 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
715 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
716 gtk_widget_show (priv->entry_user_email);
717 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
718 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
719 G_CALLBACK(on_easysetup_changed), self);
720 gtk_widget_show (caption);
722 /* Set max length as in the UI spec:
723 * The UI spec seems to want us to show a dialog if we hit the maximum. */
724 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
725 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
729 gtk_widget_show (GTK_WIDGET (box));
731 return GTK_WIDGET (box);
734 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
736 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
738 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
739 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
740 gtk_widget_set_size_request (label, 600, -1);
741 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
742 /* The documentation for gtk_label_set_line_wrap() says that we must
743 * call gtk_widget_set_size_request() with a hard-coded width,
744 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
745 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
746 gtk_widget_show (label);
748 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
749 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
750 gtk_widget_set_size_request (label, 600, -1);
752 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
753 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
754 gtk_widget_show (label);
756 gtk_widget_show (GTK_WIDGET (box));
757 return GTK_WIDGET (box);
760 /** Change the caption title for the incoming server,
761 * as specified in the UI spec:
764 update_incoming_server_title (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 (protocol == MODEST_PROTOCOL_STORE_POP ?
771 _("mail_fi_emailtype_pop3") :
772 _("mail_fi_emailtype_imap") );
775 /* Note that this produces a compiler warning,
776 * because the compiler does not know that the translated string will have a %s in it.
777 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
778 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
779 g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
780 g_free(incomingserver_title);
783 /** Change the caption title for the incoming server,
784 * as specified in the UI spec:
787 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
789 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
790 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
791 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
793 /* Fill the combo with appropriately titled choices for POP or IMAP. */
794 /* The choices are the same, but the titles are different, as in the UI spec. */
795 modest_serversecurity_combo_box_fill (
796 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol);
800 on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
802 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
803 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
807 update_incoming_server_title (self);
808 update_incoming_server_security_choices (self);
810 set_default_custom_servernames (self);
814 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
816 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
817 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
819 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
823 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
825 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
826 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
827 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
829 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
831 GTK_POLICY_AUTOMATIC);
833 /* Show note that account type cannot be changed in future: */
834 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
835 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
836 gtk_widget_set_size_request (label, 600, -1);
837 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
838 gtk_widget_show (label);
840 /* Create a size group to be used by all captions.
841 * Note that HildonCaption does not create a default size group if we do not specify one.
842 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
843 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
845 /* The incoming server widgets: */
846 priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
847 easysetup_servertype_combo_box_set_active_servertype (
848 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
849 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
850 _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
851 gtk_widget_show (priv->combo_incoming_servertype);
852 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
853 gtk_widget_show (caption);
855 priv->entry_incomingserver = gtk_entry_new ();
856 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
857 /* Auto-capitalization is the default, so let's turn it off: */
858 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
859 set_default_custom_servernames (self);
861 /* The caption title will be updated in update_incoming_server_title().
862 * so this default text will never be seen: */
863 /* (Note: Changing the title seems pointless. murrayc) */
864 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
865 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
866 update_incoming_server_title (self);
867 gtk_widget_show (priv->entry_incomingserver);
868 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
869 gtk_widget_show (priv->caption_incoming);
871 /* Change the caption title when the servertype changes,
872 * as in the UI spec: */
873 g_signal_connect (G_OBJECT (priv->combo_incoming_servertype), "changed",
874 G_CALLBACK (on_combo_servertype_changed), self);
876 /* Remember when the servername was changed manually: */
877 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
878 G_CALLBACK (on_entry_incoming_servername_changed), self);
880 /* The secure connection widgets: */
881 priv->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
882 update_incoming_server_security_choices (self);
883 modest_serversecurity_combo_box_set_active_serversecurity (
884 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
885 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
886 priv->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
887 g_signal_connect (G_OBJECT (priv->combo_incoming_security), "changed",
888 G_CALLBACK (on_incoming_security_changed), self);
889 gtk_widget_show (priv->combo_incoming_security);
890 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
891 gtk_widget_show (caption);
893 priv->checkbox_incoming_auth = gtk_check_button_new ();
894 g_signal_connect (G_OBJECT (priv->checkbox_incoming_auth), "toggled",
895 G_CALLBACK (on_easysetup_changed), self);
896 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
897 priv->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
899 gtk_widget_show (priv->checkbox_incoming_auth);
900 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
901 gtk_widget_show (caption);
903 gtk_widget_show (GTK_WIDGET (box));
905 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
906 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
907 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
908 gtk_widget_show (scrolled_window);
910 return GTK_WIDGET (scrolled_window);
914 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
916 GtkWidget *widget = GTK_WIDGET (user_data);
918 /* Enable the widget only if the toggle button is active: */
919 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
920 gtk_widget_set_sensitive (widget, enable);
923 /* Make the sensitivity of a widget depend on a toggle button.
926 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
928 g_signal_connect (G_OBJECT (button), "toggled",
929 G_CALLBACK (on_toggle_button_changed), widget);
931 /* Set the starting sensitivity: */
932 on_toggle_button_changed (button, widget);
936 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
938 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
939 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
941 /* We set dirty here because setting it depending on the connection specific dialog
945 /* Create the window, if necessary: */
946 if (!(priv->specific_window)) {
947 priv->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
948 modest_connection_specific_smtp_window_fill_with_connections (
949 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window), priv->account_manager);
952 /* Show the window: */
953 gtk_window_set_transient_for (GTK_WINDOW (priv->specific_window), GTK_WINDOW (self));
954 gtk_window_set_modal (GTK_WINDOW (priv->specific_window), TRUE);
955 gtk_widget_show (priv->specific_window);
959 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
961 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
962 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
963 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
967 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
969 ModestEasysetupWizardDialogPrivate *priv;
970 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
972 /* Create a size group to be used by all captions.
973 * Note that HildonCaption does not create a default size group if we do not specify one.
974 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
975 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
977 /* The outgoing server widgets: */
978 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
979 priv->entry_outgoingserver = gtk_entry_new ();
980 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
981 G_CALLBACK (on_easysetup_changed), self);
982 /* Auto-capitalization is the default, so let's turn it off: */
983 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
984 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
985 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
986 gtk_widget_show (priv->entry_outgoingserver);
987 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
988 gtk_widget_show (caption);
989 set_default_custom_servernames (self);
991 /* The secure connection widgets: */
992 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
993 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed",
994 G_CALLBACK (on_easysetup_changed), self);
995 modest_serversecurity_combo_box_fill (
996 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
997 modest_serversecurity_combo_box_set_active_serversecurity (
998 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
999 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
1000 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
1001 gtk_widget_show (priv->combo_outgoing_security);
1002 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1003 gtk_widget_show (caption);
1005 /* The secure authentication widgets: */
1006 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
1007 g_signal_connect (G_OBJECT (priv->combo_outgoing_auth), "changed",
1008 G_CALLBACK (on_easysetup_changed), self);
1009 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
1010 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
1011 gtk_widget_show (priv->combo_outgoing_auth);
1012 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1013 gtk_widget_show (caption);
1015 GtkWidget *separator = gtk_hseparator_new ();
1016 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
1017 gtk_widget_show (separator);
1019 /* connection-specific checkbox: */
1020 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
1021 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1023 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1024 G_CALLBACK (on_easysetup_changed), self);
1026 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
1027 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
1028 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1029 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1030 gtk_widget_show (caption);
1032 /* Connection-specific SMTP-Severs Edit button: */
1033 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
1034 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
1035 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
1036 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1037 gtk_widget_show (priv->button_outgoing_smtp_servers);
1038 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1039 gtk_widget_show (caption);
1041 /* Only enable the button when the checkbox is checked: */
1042 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
1043 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
1045 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1046 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1048 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1049 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1052 gtk_widget_show (GTK_WIDGET (box));
1054 return GTK_WIDGET (box);
1058 show_advanced_edit(gpointer user_data)
1060 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1061 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1064 /* Show the Account Settings window: */
1065 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
1066 if (priv->pending_load_settings) {
1067 save_to_settings (self);
1068 priv->pending_load_settings = FALSE;
1070 modest_account_settings_dialog_set_account (dialog, priv->settings);
1072 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
1074 response = gtk_dialog_run (GTK_DIALOG (dialog));
1076 gtk_widget_destroy (GTK_WIDGET (dialog));
1078 return FALSE; /* Do not call this timeout callback again. */
1082 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1084 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1086 /* Show the Account Settings window: */
1087 show_advanced_edit(self);
1089 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1091 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1092 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1093 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1094 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1095 gtk_widget_set_size_request (label, 600, -1);
1096 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1097 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1098 gtk_widget_show (label);
1100 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1101 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1102 gtk_widget_set_size_request (label, 600, -1);
1103 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1104 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1105 gtk_widget_show (label);
1107 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1108 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1109 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1110 gtk_widget_show (button_edit);
1111 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1112 gtk_widget_show (caption);
1114 g_signal_connect (G_OBJECT (button_edit), "clicked",
1115 G_CALLBACK (on_button_edit_advanced_settings), self);
1117 gtk_widget_show (GTK_WIDGET (box));
1118 return GTK_WIDGET (box);
1125 on_response (ModestWizardDialog *wizard_dialog,
1129 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1131 invoke_enable_buttons_vfunc (self);
1135 on_response_before (ModestWizardDialog *wizard_dialog,
1139 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1140 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1141 if (response_id == GTK_RESPONSE_CANCEL) {
1142 /* This is mostly copied from
1143 * src/maemo/modest-account-settings-dialog.c */
1145 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1146 _("imum_nc_wizard_confirm_lose_changes")));
1147 /* TODO: These button names will be ambiguous, and not
1148 * specified in the UI specification. */
1150 const gint dialog_response = gtk_dialog_run (dialog);
1151 gtk_widget_destroy (GTK_WIDGET (dialog));
1153 if (dialog_response != GTK_RESPONSE_OK) {
1154 /* Don't let the dialog close */
1155 g_signal_stop_emission_by_name (wizard_dialog, "response");
1161 typedef struct IdleData {
1162 ModestEasysetupWizardDialog *dialog;
1163 ModestPresets *presets;
1167 presets_idle (gpointer userdata)
1169 IdleData *idle_data = (IdleData *) userdata;
1170 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1171 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1173 g_assert (idle_data->presets);
1175 gdk_threads_enter ();
1177 priv->presets = idle_data->presets;
1179 if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) {
1180 gint mcc = get_default_country_code();
1181 /* Fill the combo in an idle call, as it takes a lot of time */
1182 easysetup_country_combo_box_load_data(
1183 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
1184 easysetup_country_combo_box_set_active_country_mcc (
1185 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc);
1186 easysetup_provider_combo_box_fill (
1187 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider),
1188 priv->presets, mcc);
1191 priv->dirty = FALSE;
1193 g_object_unref (idle_data->dialog);
1196 gdk_threads_leave ();
1202 presets_loader (gpointer userdata)
1204 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1205 ModestPresets *presets = NULL;
1206 IdleData *idle_data;
1208 const gchar* path = NULL;
1209 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1210 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1212 if (access(path1, R_OK) == 0)
1214 else if (access(path2, R_OK) == 0)
1217 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1218 __FUNCTION__, path1, path2);
1222 presets = modest_presets_new (path);
1224 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1228 idle_data = g_new0 (IdleData, 1);
1229 idle_data->dialog = self;
1230 idle_data->presets = presets;
1232 g_idle_add (presets_idle, idle_data);
1238 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1240 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1242 /* Create the notebook to be used by the ModestWizardDialog base class:
1243 * Each page of the notebook will be a page of the wizard: */
1244 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1246 /* Set the notebook used by the ModestWizardDialog base class: */
1247 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1249 /* Set the wizard title:
1250 * The actual window title will be a combination of this and the page's tab label title. */
1251 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1253 /* Read in the information about known service providers: */
1254 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1256 /* The server fields did not have been manually changed yet */
1257 priv->server_changes = 0;
1258 priv->pending_load_settings = TRUE;
1260 /* Get the account manager object,
1261 * so we can check for existing accounts,
1262 * and create new accounts: */
1263 priv->account_manager = modest_runtime_get_account_mgr ();
1264 g_object_ref (priv->account_manager);
1266 /* Initialize fields */
1267 priv->page_welcome = create_page_welcome (self);
1268 priv->page_account_details = create_page_account_details (self);
1269 priv->page_user_details = create_page_user_details (self);
1270 priv->page_complete_easysetup = NULL;
1271 priv->page_custom_incoming = NULL;
1272 priv->combo_incoming_servertype = NULL;
1273 priv->caption_incoming = NULL;
1274 priv->entry_incomingserver = NULL;
1275 priv->combo_incoming_security = NULL;
1276 priv->checkbox_incoming_auth = NULL;
1277 priv->page_custom_outgoing = NULL;
1278 priv->entry_outgoingserver = NULL;
1279 priv->combo_outgoing_security = NULL;
1280 priv->combo_outgoing_auth = NULL;
1281 priv->checkbox_outgoing_smtp_specific = NULL;
1282 priv->button_outgoing_smtp_servers = NULL;
1283 priv->page_complete_customsetup = NULL;
1284 priv->specific_window = NULL;
1286 /* Add the common pages: */
1287 gtk_notebook_append_page (notebook, priv->page_welcome,
1288 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1289 gtk_container_child_set (GTK_CONTAINER (notebook),
1295 gtk_notebook_append_page (notebook, priv->page_account_details,
1296 gtk_label_new (_("mcen_ti_accountdetails")));
1297 gtk_container_child_set (GTK_CONTAINER (notebook),
1298 priv->page_account_details,
1303 gtk_notebook_append_page (notebook, priv->page_user_details,
1304 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1305 gtk_container_child_set (GTK_CONTAINER (notebook),
1306 priv->page_user_details,
1311 /* Create and add the easysetup-specific pages,
1312 * because we need _some_ final page to enable the Next and Finish buttons: */
1313 create_subsequent_easysetup_pages (self);
1315 /* Connect to the dialog's response signal so we can enable/disable buttons
1316 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1317 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1318 * so that we can be enable/disable after ModestWizardDialog has done its own
1319 * enabling/disabling of buttons.
1321 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1322 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1324 * It's not enough to connect to the notebook's switch-page signal, because
1325 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1326 * _after_ switching the page (understandably).
1327 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1328 * then gtk_notebook_get_current_page() would return an incorrect value.)
1330 g_signal_connect_after (G_OBJECT (self), "response",
1331 G_CALLBACK (on_response), self);
1333 /* This is to show a confirmation dialog when the user hits cancel */
1334 g_signal_connect (G_OBJECT (self), "response",
1335 G_CALLBACK (on_response_before), self);
1337 g_signal_connect (G_OBJECT (self), "delete-event",
1338 G_CALLBACK (on_delete_event), self);
1340 /* Reset dirty, because there was no user input until now */
1341 priv->dirty = FALSE;
1343 /* When this window is shown, hibernation should not be possible,
1344 * because there is no sensible way to save the state: */
1345 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1346 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1348 /* Load provider presets */
1349 g_object_ref (self);
1350 g_thread_create (presets_loader, self, FALSE, NULL);
1352 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1353 modest_maemo_utils_get_osso_context());
1355 priv->settings = modest_account_settings_new ();
1358 ModestEasysetupWizardDialog*
1359 modest_easysetup_wizard_dialog_new (void)
1362 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1365 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1367 ModestEasysetupWizardDialogPrivate *priv;
1368 GtkNotebook *notebook = NULL;
1370 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1373 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1375 /* Create the custom pages: */
1376 if(!(priv->page_custom_incoming)) {
1377 priv->page_custom_incoming = create_page_custom_incoming (self);
1380 if(!(priv->page_custom_outgoing)) {
1381 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1384 if(!(priv->page_complete_customsetup)) {
1385 priv->page_complete_customsetup = create_page_complete_custom (self);
1388 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1389 gtk_notebook_append_page (notebook, priv->page_custom_incoming,
1390 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1392 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1393 gtk_notebook_append_page (notebook, priv->page_custom_outgoing,
1394 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1396 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup))) {
1397 gtk_notebook_append_page (notebook, priv->page_complete_customsetup,
1398 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1399 gtk_container_child_set (GTK_CONTAINER (notebook),
1400 priv->page_complete_customsetup,
1406 /* This is unnecessary with GTK+ 2.10: */
1407 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1411 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1413 ModestEasysetupWizardDialogPrivate *priv;
1414 GtkNotebook *notebook = NULL;
1416 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1419 /* Create the easysetup-specific pages: */
1420 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1421 if(!priv->page_complete_easysetup)
1422 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1424 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup))) {
1425 gtk_notebook_append_page (notebook, priv->page_complete_easysetup,
1426 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1427 gtk_container_child_set (GTK_CONTAINER (notebook),
1428 priv->page_complete_easysetup,
1434 /* This is unnecessary with GTK+ 2.10: */
1435 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1437 /* After the user details page,
1438 * the following pages depend on whether "Other" was chosen
1439 * in the provider combobox on the account page
1441 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1443 ModestEasysetupWizardDialogPrivate *priv;
1445 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1447 if (easysetup_provider_combo_box_get_active_provider_id (
1448 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider)) == 0) {
1449 /* "Other..." was selected: */
1451 /* Make sure that the easysetup pages do not exist: */
1452 if(priv->page_complete_easysetup) {
1453 gtk_widget_destroy (priv->page_complete_easysetup);
1454 priv->page_complete_easysetup = NULL;
1457 create_subsequent_customsetup_pages (self);
1460 /* A specific provider was selected: */
1462 /* Make sure that the custom pages do not exist:
1463 * Because they will be used if they exist, when creating the account. */
1464 if(priv->page_custom_incoming) {
1465 gtk_widget_destroy (priv->page_custom_incoming);
1466 priv->page_custom_incoming = NULL;
1467 priv->combo_incoming_servertype = NULL;
1468 priv->caption_incoming = NULL;
1469 priv->entry_incomingserver = NULL;
1470 priv->combo_incoming_security = NULL;
1471 priv->checkbox_incoming_auth = NULL;
1474 if(priv->page_custom_outgoing) {
1475 gtk_widget_destroy (priv->page_custom_outgoing);
1476 priv->page_custom_outgoing = NULL;
1477 priv->entry_outgoingserver = NULL;
1478 priv->combo_outgoing_security = NULL;
1479 priv->combo_outgoing_auth = NULL;
1480 priv->checkbox_outgoing_smtp_specific = NULL;
1481 priv->button_outgoing_smtp_servers = NULL;
1484 if(priv->page_complete_customsetup) {
1485 gtk_widget_destroy (priv->page_complete_customsetup);
1486 priv->page_complete_customsetup = NULL;
1490 /* Create the easysetup pages: */
1491 create_subsequent_easysetup_pages (self);
1497 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1502 gchar* at = g_utf8_strchr (email_address, -1, '@');
1503 if (!at || (g_utf8_strlen (at, -1) < 2))
1506 gchar* domain = g_utf8_next_char (at);
1510 const gchar* hostname = NULL;
1511 if (servertype == MODEST_PROTOCOL_STORE_POP)
1513 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1515 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1521 return g_strdup_printf ("%s.%s", hostname, domain);
1525 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1527 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1529 if (!priv->entry_incomingserver)
1532 /* Set a default domain for the server, based on the email address,
1533 * if no server name was already specified.
1535 if (priv->entry_user_email
1536 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1537 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1538 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1539 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1541 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1543 /* Do not set the INCOMING_CHANGED flag because of this edit */
1544 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1545 gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
1546 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1548 g_free (servername);
1551 /* Set a default domain for the server, based on the email address,
1552 * if no server name was already specified.
1554 if (!priv->entry_outgoingserver)
1557 if (priv->entry_user_email
1558 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1559 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1561 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1563 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1564 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1565 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), servername);
1566 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1568 g_free (servername);
1573 get_entered_account_title (ModestEasysetupWizardDialog *self)
1575 ModestEasysetupWizardDialogPrivate *priv;
1576 const gchar* account_title;
1578 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1579 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
1581 if (!account_title || (strlen (account_title) == 0)) {
1584 /* Strip it of whitespace at the start and end: */
1585 gchar *result = g_strdup (account_title);
1586 result = g_strstrip (result);
1591 if (strlen (result) == 0) {
1601 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1603 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1604 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1606 /* if are browsing pages previous to the last one, then we have pending settings in
1608 if (next_page != NULL)
1609 priv->pending_load_settings = TRUE;
1611 /* Do extra validation that couldn't be done for every key press,
1612 * either because it was too slow,
1613 * or because it requires interaction:
1615 if (current_page == priv->page_account_details) {
1616 /* Check that the title is not already in use: */
1617 gchar* account_title = get_entered_account_title (self);
1621 /* Aavoid a clash with an existing display name: */
1622 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1623 priv->account_manager, account_title);
1626 /* Warn the user via a dialog: */
1627 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1632 else if (current_page == priv->page_user_details) {
1633 /* Check that the email address is valud: */
1634 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1635 if ((!email_address) || (strlen(email_address) == 0))
1638 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1639 /* Warn the user via a dialog: */
1640 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1642 /* Return focus to the email address entry: */
1643 gtk_widget_grab_focus (priv->entry_user_email);
1644 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1649 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1650 create_subsequent_pages (self);
1653 /* TODO: The UI Spec wants us to check that the servernames are valid,
1654 * but does not specify how.
1657 if(next_page == priv->page_custom_incoming) {
1658 set_default_custom_servernames (self);
1660 else if (next_page == priv->page_custom_outgoing) {
1661 set_default_custom_servernames (self);
1663 /* Check if the server supports secure authentication */
1664 const ModestConnectionProtocol security_incoming =
1665 modest_serversecurity_combo_box_get_active_serversecurity (
1666 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1667 if (gtk_toggle_button_get_active (
1668 GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))
1669 && !modest_protocol_info_is_secure(security_incoming))
1671 if (!check_has_supported_auth_methods (self))
1676 /* If this is the last page, and this is a click on Finish,
1677 * then attempt to create the dialog.
1679 if(!next_page) /* This is NULL when this is a click on Finish. */
1681 if (priv->pending_load_settings) {
1682 save_to_settings (self);
1684 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1691 static gboolean entry_is_empty (GtkWidget *entry)
1696 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1697 if ((!text) || (strlen(text) == 0))
1700 /* Strip it of whitespace at the start and end: */
1701 gchar *stripped = g_strdup (text);
1702 stripped = g_strstrip (stripped);
1707 const gboolean result = (strlen (stripped) == 0);
1715 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1717 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1718 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1720 gboolean enable_next = TRUE;
1721 if (current_page == priv->page_welcome) {
1724 else if (current_page == priv->page_account_details) {
1725 /* The account details title is mandatory: */
1726 if (entry_is_empty(priv->entry_account_title))
1727 enable_next = FALSE;
1729 else if (current_page == priv->page_user_details) {
1730 /* The user details username is mandatory: */
1731 if (entry_is_empty(priv->entry_user_username))
1732 enable_next = FALSE;
1734 /* The user details email address is mandatory: */
1735 if (enable_next && entry_is_empty (priv->entry_user_email))
1736 enable_next = FALSE;
1738 else if (current_page == priv->page_custom_incoming) {
1739 /* The custom incoming server is mandatory: */
1740 if (entry_is_empty(priv->entry_incomingserver))
1741 enable_next = FALSE;
1744 /* Enable the buttons,
1745 * identifying them via their associated response codes: */
1747 /* Disable the Finish button until we are on the last page,
1748 * because HildonWizardDialog enables this for all but the first page: */
1749 GtkNotebook *notebook = NULL;
1750 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1751 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1753 gint current = gtk_notebook_get_current_page (notebook);
1754 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1755 const gboolean is_last = (current == last);
1758 gtk_dialog_set_response_sensitive (dialog_base,
1759 MODEST_WIZARD_DIALOG_FINISH,
1763 /* Disable Next on the last page: */
1764 enable_next = FALSE;
1767 gtk_dialog_set_response_sensitive (dialog_base,
1768 MODEST_WIZARD_DIALOG_NEXT,
1773 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1775 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1776 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1779 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1780 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1781 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1782 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1784 /* Provide a vfunc implementation so we can decide
1785 * when to enable/disable the prev/next buttons.
1787 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1788 base_klass->before_next = on_before_next;
1789 base_klass->enable_buttons = on_enable_buttons;
1793 show_error (GtkWidget *parent_widget, const gchar* text)
1795 //TODO: Apparently this doesn't show anything in Maemo Bora:
1796 hildon_banner_show_information(parent_widget, NULL, text);
1802 * @self: a #ModestEasysetupWizardDialog
1804 * takes information from all the wizard and stores it in settings
1807 save_to_settings (ModestEasysetupWizardDialog *self)
1809 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1812 gchar* display_name;
1813 const gchar *username, *password;
1814 gchar *store_hostname, *transport_hostname;
1815 guint store_port, transport_port;
1816 ModestTransportStoreProtocol store_protocol, transport_protocol;
1817 ModestConnectionProtocol store_security, transport_security;
1818 ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
1819 ModestServerAccountSettings *store_settings, *transport_settings;
1820 const gchar *fullname, *email_address;
1822 /* Get details from the specified presets: */
1823 provider_id = easysetup_provider_combo_box_get_active_provider_id (
1824 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
1826 /* username and password (for both incoming and outgoing): */
1827 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1828 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1830 /* Incoming server: */
1831 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1832 * or modest_account_mgr_add_server_account will fail. */
1834 store_protocol = MODEST_PROTOCOL_STORE_POP;
1835 store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1836 store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1839 ModestPresetsServerType store_provider_server_type;
1840 ModestPresetsSecurity store_provider_security;
1842 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1845 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1848 store_provider_security = modest_presets_get_info_server_security (priv->presets,
1852 /* We don't check for SMTP here as that is impossible for an incoming server. */
1853 if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
1854 store_protocol = MODEST_PROTOCOL_STORE_IMAP;
1855 else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
1856 store_protocol = MODEST_PROTOCOL_STORE_POP;
1858 store_protocol = MODEST_PROTOCOL_STORE_POP;
1860 /* we check if there is a *special* port */
1861 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1862 if (special_port != 0)
1863 store_port = special_port;
1865 store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
1867 if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1868 store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1870 if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
1871 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1873 /* Use custom pages because no preset was specified: */
1874 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));
1875 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1876 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1877 store_security = modest_serversecurity_combo_box_get_active_serversecurity (
1878 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1880 /* The UI spec says:
1881 * If secure authentication is unchecked, allow sending username and password also as plain text.
1882 * If secure authentication is checked, require one of the secure methods during
1883 * connection: SSL, TLS, CRAM-MD5 etc. */
1884 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth)) &&
1885 !modest_protocol_info_is_secure(store_security)) {
1886 store_auth_protocol = check_first_supported_auth_method (self);
1888 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1892 /* now we store the store account settings */
1893 store_settings = modest_account_settings_get_store_settings (priv->settings);
1894 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1895 modest_server_account_settings_set_username (store_settings, username);
1896 modest_server_account_settings_set_password (store_settings, password);
1897 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1898 modest_server_account_settings_set_security (store_settings, store_security);
1899 modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1900 if (store_port != 0)
1901 modest_server_account_settings_set_port (store_settings, store_port);
1903 g_object_unref (store_settings);
1904 g_free (store_hostname);
1906 /* Outgoing server: */
1907 transport_hostname = NULL;
1908 transport_protocol = MODEST_PROTOCOL_STORE_POP;
1909 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1910 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1914 ModestPresetsServerType transport_provider_server_type;
1915 ModestPresetsSecurity transport_provider_security;
1918 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1919 FALSE /* transport */);
1921 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1923 FALSE /* transport */);
1924 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1926 FALSE /* transport */);
1928 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1929 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1930 if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
1931 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
1933 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1934 if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1935 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1936 transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1937 /* we check if there is a *special* port */
1938 special_port = modest_presets_get_port (priv->presets, provider_id,
1939 FALSE /* transport */);
1940 if (special_port != 0)
1941 transport_port = special_port;
1943 transport_port = 465;
1944 transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1946 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1947 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1950 /* Use custom pages because no preset was specified: */
1951 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
1952 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1953 transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
1954 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
1955 transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
1956 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
1959 /* now we transport the transport account settings */
1960 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1961 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1962 modest_server_account_settings_set_username (transport_settings, username);
1963 modest_server_account_settings_set_password (transport_settings, password);
1964 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1965 modest_server_account_settings_set_security (transport_settings, transport_security);
1966 modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1967 if (transport_port != 0)
1968 modest_server_account_settings_set_port (transport_settings, transport_port);
1970 g_object_unref (transport_settings);
1971 g_free (transport_hostname);
1973 fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1974 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1975 modest_account_settings_set_fullname (priv->settings, fullname);
1976 modest_account_settings_set_email_address (priv->settings, email_address);
1977 /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1978 are set to headers only */
1980 /* Save the connection-specific SMTP server accounts. */
1981 modest_account_settings_set_use_connection_specific_smtp
1983 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1985 display_name = get_entered_account_title (self);
1986 modest_account_settings_set_display_name (priv->settings, display_name);
1987 g_free (display_name);
1989 if (priv->specific_window)
1990 modest_connection_specific_smtp_window_save_server_accounts (
1991 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window));