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 get_default_country_code(void)
470 /* TODO: Default to the current country somehow.
471 * But I don't know how to get the information that is specified in the
472 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
474 * This is probably not the best choice of gconf key:
475 * This is the "mcc used in the last pairing", ie. the last connection you made.
476 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
479 GError *error = NULL;
480 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
481 gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
487 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
488 g_error_free (error);
494 /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
495 * This might just be a Maemo bug.
499 /* For now, we default to Finland when there is nothing better: */
506 create_page_account_details (ModestEasysetupWizardDialog *self)
508 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
509 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
510 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
512 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
513 gtk_widget_set_size_request (label, 600, -1);
514 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
515 gtk_widget_show (label);
517 /* Create a size group to be used by all captions.
518 * Note that HildonCaption does not create a default size group if we do not specify one.
519 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
520 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
522 /* The country widgets: */
523 priv->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
524 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
525 priv->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
526 gtk_widget_show (priv->combo_account_country);
527 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
528 gtk_widget_show (caption);
530 /* connect to country combo's changed signal, so we can fill the provider combo: */
531 g_signal_connect (G_OBJECT (priv->combo_account_country), "changed",
532 G_CALLBACK (on_combo_account_country), self);
534 GtkWidget *separator = gtk_hseparator_new ();
535 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
536 gtk_widget_show (separator);
538 /* The service provider widgets: */
539 priv->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
540 gtk_widget_set_size_request (priv->combo_account_serviceprovider, 320, -1);
542 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
543 priv->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
544 gtk_widget_show (priv->combo_account_serviceprovider);
545 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
546 gtk_widget_show (caption);
548 /* connect to providers combo's changed signal, so we can fill the email address: */
549 g_signal_connect (G_OBJECT (priv->combo_account_serviceprovider), "changed",
550 G_CALLBACK (on_combo_account_serviceprovider), self);
552 /* The description widgets: */
553 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
554 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
555 G_CALLBACK(on_easysetup_changed), self);
556 /* Do use auto-capitalization: */
557 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
558 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
560 /* Set a default account title, choosing one that does not already exist: */
561 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
562 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
563 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
564 priv->account_manager, default_account_name_start);
565 g_free (default_account_name_start);
566 default_account_name_start = NULL;
568 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title), default_account_name);
569 g_free (default_account_name);
570 default_account_name = NULL;
572 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
573 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
574 gtk_widget_show (priv->entry_account_title);
575 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
576 gtk_widget_show (caption);
578 /* Prevent the use of some characters in the account title,
579 * as required by our UI specification: */
580 GList *list_prevent = NULL;
581 list_prevent = g_list_append (list_prevent, "\\");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
587 list_prevent = g_list_append (list_prevent, "“");
588 list_prevent = g_list_append (list_prevent, "<");
589 list_prevent = g_list_append (list_prevent, ">");
590 list_prevent = g_list_append (list_prevent, "|");
591 list_prevent = g_list_append (list_prevent, "^");
592 modest_validating_entry_set_unallowed_characters (
593 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
594 g_list_free (list_prevent);
596 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
597 modest_maemo_utils_on_entry_invalid_character, self);
599 /* Set max length as in the UI spec:
600 * The UI spec seems to want us to show a dialog if we hit the maximum. */
601 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
602 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
605 gtk_widget_show (GTK_WIDGET (box));
607 return GTK_WIDGET (box);
611 create_page_user_details (ModestEasysetupWizardDialog *self)
613 GtkSizeGroup* sizegroup;
615 ModestEasysetupWizardDialogPrivate *priv;
617 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
619 /* Create a size group to be used by all captions.
620 * Note that HildonCaption does not create a default size group if we do not specify one.
621 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
622 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
623 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
625 /* The name widgets: (use auto cap) */
626 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
627 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
628 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
630 /* Set max length as in the UI spec:
631 * The UI spec seems to want us to show a dialog if we hit the maximum. */
632 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
633 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
635 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
636 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
637 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
638 G_CALLBACK(on_easysetup_changed), self);
639 gtk_widget_show (priv->entry_user_name);
640 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
641 gtk_widget_show (caption);
643 /* Prevent the use of some characters in the name,
644 * as required by our UI specification: */
645 GList *list_prevent = NULL;
646 list_prevent = g_list_append (list_prevent, "<");
647 list_prevent = g_list_append (list_prevent, ">");
648 modest_validating_entry_set_unallowed_characters (
649 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
650 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
651 modest_maemo_utils_on_entry_invalid_character, self);
652 g_list_free (list_prevent);
654 /* The username widgets: */
655 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
656 /* Auto-capitalization is the default, so let's turn it off: */
657 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
658 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
659 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
660 gtk_widget_show (priv->entry_user_username);
661 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
662 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
663 G_CALLBACK(on_easysetup_changed), self);
664 gtk_widget_show (caption);
666 /* Prevent the use of some characters in the username,
667 * as required by our UI specification: */
668 modest_validating_entry_set_unallowed_characters_whitespace (
669 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
670 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
671 modest_maemo_utils_on_entry_invalid_character, self);
673 /* Set max length as in the UI spec:
674 * The UI spec seems to want us to show a dialog if we hit the maximum. */
675 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
676 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
679 /* The password widgets: */
680 priv->entry_user_password = gtk_entry_new ();
681 /* Auto-capitalization is the default, so let's turn it off: */
682 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
683 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
684 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
685 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
686 caption = create_caption_new_with_asterisk (self, sizegroup,
687 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
688 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
689 G_CALLBACK(on_easysetup_changed), self);
690 gtk_widget_show (priv->entry_user_password);
691 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
692 gtk_widget_show (caption);
694 /* The email address widgets: */
695 priv->entry_user_email = GTK_WIDGET (modest_validating_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_email), HILDON_GTK_INPUT_MODE_FULL);
698 caption = create_caption_new_with_asterisk (self, sizegroup,
699 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
700 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
701 gtk_widget_show (priv->entry_user_email);
702 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
703 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
704 G_CALLBACK(on_easysetup_changed), self);
705 gtk_widget_show (caption);
707 /* Set max length as in the UI spec:
708 * The UI spec seems to want us to show a dialog if we hit the maximum. */
709 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
710 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
714 gtk_widget_show (GTK_WIDGET (box));
716 return GTK_WIDGET (box);
719 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
721 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
723 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
724 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
725 gtk_widget_set_size_request (label, 600, -1);
726 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
727 /* The documentation for gtk_label_set_line_wrap() says that we must
728 * call gtk_widget_set_size_request() with a hard-coded width,
729 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
730 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
731 gtk_widget_show (label);
733 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
734 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
735 gtk_widget_set_size_request (label, 600, -1);
737 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
738 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
739 gtk_widget_show (label);
741 gtk_widget_show (GTK_WIDGET (box));
742 return GTK_WIDGET (box);
745 /** Change the caption title for the incoming server,
746 * as specified in the UI spec:
749 update_incoming_server_title (ModestEasysetupWizardDialog *self)
751 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
752 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
753 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
755 (protocol == MODEST_PROTOCOL_STORE_POP ?
756 _("mail_fi_emailtype_pop3") :
757 _("mail_fi_emailtype_imap") );
760 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
761 g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
762 g_free(incomingserver_title);
765 /** Change the caption title for the incoming server,
766 * as specified in the UI spec:
769 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
771 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
772 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
773 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
775 /* Fill the combo with appropriately titled choices for POP or IMAP. */
776 /* The choices are the same, but the titles are different, as in the UI spec. */
777 modest_serversecurity_combo_box_fill (
778 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol);
782 on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
784 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
785 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
789 update_incoming_server_title (self);
790 update_incoming_server_security_choices (self);
792 set_default_custom_servernames (self);
796 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
798 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
799 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
801 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
805 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
807 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
808 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
809 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
811 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
813 GTK_POLICY_AUTOMATIC);
815 /* Show note that account type cannot be changed in future: */
816 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
817 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
818 gtk_widget_set_size_request (label, 600, -1);
819 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
820 gtk_widget_show (label);
822 /* Create a size group to be used by all captions.
823 * Note that HildonCaption does not create a default size group if we do not specify one.
824 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
825 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
827 /* The incoming server widgets: */
828 priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
829 easysetup_servertype_combo_box_set_active_servertype (
830 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
831 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
832 _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
833 gtk_widget_show (priv->combo_incoming_servertype);
834 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
835 gtk_widget_show (caption);
837 priv->entry_incomingserver = gtk_entry_new ();
838 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
839 /* Auto-capitalization is the default, so let's turn it off: */
840 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
841 set_default_custom_servernames (self);
843 /* The caption title will be updated in update_incoming_server_title().
844 * so this default text will never be seen: */
845 /* (Note: Changing the title seems pointless. murrayc) */
846 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
847 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
848 update_incoming_server_title (self);
849 gtk_widget_show (priv->entry_incomingserver);
850 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
851 gtk_widget_show (priv->caption_incoming);
853 /* Change the caption title when the servertype changes,
854 * as in the UI spec: */
855 g_signal_connect (G_OBJECT (priv->combo_incoming_servertype), "changed",
856 G_CALLBACK (on_combo_servertype_changed), self);
858 /* Remember when the servername was changed manually: */
859 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
860 G_CALLBACK (on_entry_incoming_servername_changed), self);
862 /* The secure connection widgets: */
863 priv->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
864 update_incoming_server_security_choices (self);
865 modest_serversecurity_combo_box_set_active_serversecurity (
866 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
867 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
868 priv->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
869 g_signal_connect (G_OBJECT (priv->combo_incoming_security), "changed",
870 G_CALLBACK (on_incoming_security_changed), self);
871 gtk_widget_show (priv->combo_incoming_security);
872 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
873 gtk_widget_show (caption);
875 priv->checkbox_incoming_auth = gtk_check_button_new ();
876 g_signal_connect (G_OBJECT (priv->checkbox_incoming_auth), "toggled",
877 G_CALLBACK (on_easysetup_changed), self);
878 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
879 priv->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
881 gtk_widget_show (priv->checkbox_incoming_auth);
882 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
883 gtk_widget_show (caption);
885 gtk_widget_show (GTK_WIDGET (box));
887 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
888 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
889 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
890 gtk_widget_show (scrolled_window);
892 return GTK_WIDGET (scrolled_window);
896 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
898 GtkWidget *widget = GTK_WIDGET (user_data);
900 /* Enable the widget only if the toggle button is active: */
901 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
902 gtk_widget_set_sensitive (widget, enable);
905 /* Make the sensitivity of a widget depend on a toggle button.
908 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
910 g_signal_connect (G_OBJECT (button), "toggled",
911 G_CALLBACK (on_toggle_button_changed), widget);
913 /* Set the starting sensitivity: */
914 on_toggle_button_changed (button, widget);
918 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
920 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
921 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
923 /* We set dirty here because setting it depending on the connection specific dialog
927 /* Create the window, if necessary: */
928 if (!(priv->specific_window)) {
929 priv->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
930 modest_connection_specific_smtp_window_fill_with_connections (
931 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window), priv->account_manager);
934 /* Show the window: */
935 gtk_window_set_transient_for (GTK_WINDOW (priv->specific_window), GTK_WINDOW (self));
936 gtk_window_set_modal (GTK_WINDOW (priv->specific_window), TRUE);
937 gtk_widget_show (priv->specific_window);
941 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
943 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
944 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
945 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
949 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
951 ModestEasysetupWizardDialogPrivate *priv;
952 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
954 /* Create a size group to be used by all captions.
955 * Note that HildonCaption does not create a default size group if we do not specify one.
956 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
957 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
959 /* The outgoing server widgets: */
960 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
961 priv->entry_outgoingserver = gtk_entry_new ();
962 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
963 G_CALLBACK (on_easysetup_changed), self);
964 /* Auto-capitalization is the default, so let's turn it off: */
965 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
966 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
967 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
968 gtk_widget_show (priv->entry_outgoingserver);
969 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
970 gtk_widget_show (caption);
971 set_default_custom_servernames (self);
973 /* The secure connection widgets: */
974 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
975 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed",
976 G_CALLBACK (on_easysetup_changed), self);
977 modest_serversecurity_combo_box_fill (
978 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
979 modest_serversecurity_combo_box_set_active_serversecurity (
980 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
981 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
982 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
983 gtk_widget_show (priv->combo_outgoing_security);
984 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
985 gtk_widget_show (caption);
987 /* The secure authentication widgets: */
988 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
989 g_signal_connect (G_OBJECT (priv->combo_outgoing_auth), "changed",
990 G_CALLBACK (on_easysetup_changed), self);
991 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
992 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
993 gtk_widget_show (priv->combo_outgoing_auth);
994 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
995 gtk_widget_show (caption);
997 GtkWidget *separator = gtk_hseparator_new ();
998 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
999 gtk_widget_show (separator);
1001 /* connection-specific checkbox: */
1002 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
1003 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1005 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
1006 G_CALLBACK (on_easysetup_changed), self);
1008 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
1009 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
1010 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
1011 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1012 gtk_widget_show (caption);
1014 /* Connection-specific SMTP-Severs Edit button: */
1015 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
1016 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
1017 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
1018 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1019 gtk_widget_show (priv->button_outgoing_smtp_servers);
1020 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1021 gtk_widget_show (caption);
1023 /* Only enable the button when the checkbox is checked: */
1024 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
1025 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
1027 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
1028 G_CALLBACK (on_button_outgoing_smtp_servers), self);
1030 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
1031 G_CALLBACK (on_entry_outgoing_servername_changed), self);
1034 gtk_widget_show (GTK_WIDGET (box));
1036 return GTK_WIDGET (box);
1040 show_advanced_edit(gpointer user_data)
1042 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1043 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1046 /* Show the Account Settings window: */
1047 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
1048 if (priv->pending_load_settings) {
1049 save_to_settings (self);
1050 priv->pending_load_settings = FALSE;
1052 modest_account_settings_dialog_set_account (dialog, priv->settings);
1054 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
1056 response = gtk_dialog_run (GTK_DIALOG (dialog));
1058 gtk_widget_destroy (GTK_WIDGET (dialog));
1060 return FALSE; /* Do not call this timeout callback again. */
1064 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1066 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1068 /* Show the Account Settings window: */
1069 show_advanced_edit(self);
1071 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1073 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1074 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1075 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1076 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1077 gtk_widget_set_size_request (label, 600, -1);
1078 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1079 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1080 gtk_widget_show (label);
1082 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1083 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1084 gtk_widget_set_size_request (label, 600, -1);
1085 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1086 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1087 gtk_widget_show (label);
1089 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1090 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1091 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1092 gtk_widget_show (button_edit);
1093 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1094 gtk_widget_show (caption);
1096 g_signal_connect (G_OBJECT (button_edit), "clicked",
1097 G_CALLBACK (on_button_edit_advanced_settings), self);
1099 gtk_widget_show (GTK_WIDGET (box));
1100 return GTK_WIDGET (box);
1107 on_response (ModestWizardDialog *wizard_dialog,
1111 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1113 invoke_enable_buttons_vfunc (self);
1117 on_response_before (ModestWizardDialog *wizard_dialog,
1121 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1122 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1123 if (response_id == GTK_RESPONSE_CANCEL) {
1124 /* This is mostly copied from
1125 * src/maemo/modest-account-settings-dialog.c */
1127 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1128 _("imum_nc_wizard_confirm_lose_changes")));
1129 /* TODO: These button names will be ambiguous, and not
1130 * specified in the UI specification. */
1132 const gint dialog_response = gtk_dialog_run (dialog);
1133 gtk_widget_destroy (GTK_WIDGET (dialog));
1135 if (dialog_response != GTK_RESPONSE_OK) {
1136 /* Don't let the dialog close */
1137 g_signal_stop_emission_by_name (wizard_dialog, "response");
1143 typedef struct IdleData {
1144 ModestEasysetupWizardDialog *dialog;
1145 ModestPresets *presets;
1149 presets_idle (gpointer userdata)
1151 IdleData *idle_data = (IdleData *) userdata;
1152 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1153 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1155 g_assert (idle_data->presets);
1157 gdk_threads_enter ();
1159 priv->presets = idle_data->presets;
1161 if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) {
1162 gint mcc = get_default_country_code();
1163 /* Fill the combo in an idle call, as it takes a lot of time */
1164 easysetup_country_combo_box_load_data(
1165 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
1166 easysetup_country_combo_box_set_active_country_mcc (
1167 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc);
1168 easysetup_provider_combo_box_fill (
1169 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider),
1170 priv->presets, mcc);
1173 priv->dirty = FALSE;
1175 g_object_unref (idle_data->dialog);
1178 gdk_threads_leave ();
1184 presets_loader (gpointer userdata)
1186 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1187 ModestPresets *presets = NULL;
1188 IdleData *idle_data;
1190 const gchar* path = NULL;
1191 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1192 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1194 if (access(path1, R_OK) == 0)
1196 else if (access(path2, R_OK) == 0)
1199 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1200 __FUNCTION__, path1, path2);
1204 presets = modest_presets_new (path);
1206 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1210 idle_data = g_new0 (IdleData, 1);
1211 idle_data->dialog = self;
1212 idle_data->presets = presets;
1214 g_idle_add (presets_idle, idle_data);
1220 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1222 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1224 /* Create the notebook to be used by the ModestWizardDialog base class:
1225 * Each page of the notebook will be a page of the wizard: */
1226 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1228 /* Set the notebook used by the ModestWizardDialog base class: */
1229 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1231 /* Set the wizard title:
1232 * The actual window title will be a combination of this and the page's tab label title. */
1233 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1235 /* Read in the information about known service providers: */
1236 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1238 /* The server fields did not have been manually changed yet */
1239 priv->server_changes = 0;
1240 priv->pending_load_settings = TRUE;
1242 /* Get the account manager object,
1243 * so we can check for existing accounts,
1244 * and create new accounts: */
1245 priv->account_manager = modest_runtime_get_account_mgr ();
1246 g_object_ref (priv->account_manager);
1248 /* Initialize fields */
1249 priv->page_welcome = create_page_welcome (self);
1250 priv->page_account_details = create_page_account_details (self);
1251 priv->page_user_details = create_page_user_details (self);
1252 priv->page_complete_easysetup = NULL;
1253 priv->page_custom_incoming = NULL;
1254 priv->combo_incoming_servertype = NULL;
1255 priv->caption_incoming = NULL;
1256 priv->entry_incomingserver = NULL;
1257 priv->combo_incoming_security = NULL;
1258 priv->checkbox_incoming_auth = NULL;
1259 priv->page_custom_outgoing = NULL;
1260 priv->entry_outgoingserver = NULL;
1261 priv->combo_outgoing_security = NULL;
1262 priv->combo_outgoing_auth = NULL;
1263 priv->checkbox_outgoing_smtp_specific = NULL;
1264 priv->button_outgoing_smtp_servers = NULL;
1265 priv->page_complete_customsetup = NULL;
1266 priv->specific_window = NULL;
1268 /* Add the common pages: */
1269 gtk_notebook_append_page (notebook, priv->page_welcome,
1270 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1271 gtk_container_child_set (GTK_CONTAINER (notebook),
1277 gtk_notebook_append_page (notebook, priv->page_account_details,
1278 gtk_label_new (_("mcen_ti_accountdetails")));
1279 gtk_container_child_set (GTK_CONTAINER (notebook),
1280 priv->page_account_details,
1285 gtk_notebook_append_page (notebook, priv->page_user_details,
1286 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1287 gtk_container_child_set (GTK_CONTAINER (notebook),
1288 priv->page_user_details,
1293 /* Create and add the easysetup-specific pages,
1294 * because we need _some_ final page to enable the Next and Finish buttons: */
1295 create_subsequent_easysetup_pages (self);
1297 /* Connect to the dialog's response signal so we can enable/disable buttons
1298 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1299 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1300 * so that we can be enable/disable after ModestWizardDialog has done its own
1301 * enabling/disabling of buttons.
1303 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1304 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1306 * It's not enough to connect to the notebook's switch-page signal, because
1307 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1308 * _after_ switching the page (understandably).
1309 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1310 * then gtk_notebook_get_current_page() would return an incorrect value.)
1312 g_signal_connect_after (G_OBJECT (self), "response",
1313 G_CALLBACK (on_response), self);
1315 /* This is to show a confirmation dialog when the user hits cancel */
1316 g_signal_connect (G_OBJECT (self), "response",
1317 G_CALLBACK (on_response_before), self);
1319 g_signal_connect (G_OBJECT (self), "delete-event",
1320 G_CALLBACK (on_delete_event), self);
1322 /* Reset dirty, because there was no user input until now */
1323 priv->dirty = FALSE;
1325 /* When this window is shown, hibernation should not be possible,
1326 * because there is no sensible way to save the state: */
1327 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1328 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1330 /* Load provider presets */
1331 g_object_ref (self);
1332 g_thread_create (presets_loader, self, FALSE, NULL);
1334 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1335 modest_maemo_utils_get_osso_context());
1337 priv->settings = modest_account_settings_new ();
1340 ModestEasysetupWizardDialog*
1341 modest_easysetup_wizard_dialog_new (void)
1344 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1347 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1349 ModestEasysetupWizardDialogPrivate *priv;
1350 GtkNotebook *notebook = NULL;
1352 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1355 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1357 /* Create the custom pages: */
1358 if(!(priv->page_custom_incoming)) {
1359 priv->page_custom_incoming = create_page_custom_incoming (self);
1362 if(!(priv->page_custom_outgoing)) {
1363 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1366 if(!(priv->page_complete_customsetup)) {
1367 priv->page_complete_customsetup = create_page_complete_custom (self);
1370 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1371 gtk_notebook_append_page (notebook, priv->page_custom_incoming,
1372 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1374 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1375 gtk_notebook_append_page (notebook, priv->page_custom_outgoing,
1376 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1378 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup))) {
1379 gtk_notebook_append_page (notebook, priv->page_complete_customsetup,
1380 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1381 gtk_container_child_set (GTK_CONTAINER (notebook),
1382 priv->page_complete_customsetup,
1388 /* This is unnecessary with GTK+ 2.10: */
1389 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1393 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1395 ModestEasysetupWizardDialogPrivate *priv;
1396 GtkNotebook *notebook = NULL;
1398 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1401 /* Create the easysetup-specific pages: */
1402 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1403 if(!priv->page_complete_easysetup)
1404 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1406 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup))) {
1407 gtk_notebook_append_page (notebook, priv->page_complete_easysetup,
1408 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1409 gtk_container_child_set (GTK_CONTAINER (notebook),
1410 priv->page_complete_easysetup,
1416 /* This is unnecessary with GTK+ 2.10: */
1417 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1419 /* After the user details page,
1420 * the following pages depend on whether "Other" was chosen
1421 * in the provider combobox on the account page
1423 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1425 ModestEasysetupWizardDialogPrivate *priv;
1427 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1429 if (easysetup_provider_combo_box_get_active_provider_id (
1430 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider)) == 0) {
1431 /* "Other..." was selected: */
1433 /* Make sure that the easysetup pages do not exist: */
1434 if(priv->page_complete_easysetup) {
1435 gtk_widget_destroy (priv->page_complete_easysetup);
1436 priv->page_complete_easysetup = NULL;
1439 create_subsequent_customsetup_pages (self);
1442 /* A specific provider was selected: */
1444 /* Make sure that the custom pages do not exist:
1445 * Because they will be used if they exist, when creating the account. */
1446 if(priv->page_custom_incoming) {
1447 gtk_widget_destroy (priv->page_custom_incoming);
1448 priv->page_custom_incoming = NULL;
1449 priv->combo_incoming_servertype = NULL;
1450 priv->caption_incoming = NULL;
1451 priv->entry_incomingserver = NULL;
1452 priv->combo_incoming_security = NULL;
1453 priv->checkbox_incoming_auth = NULL;
1456 if(priv->page_custom_outgoing) {
1457 gtk_widget_destroy (priv->page_custom_outgoing);
1458 priv->page_custom_outgoing = NULL;
1459 priv->entry_outgoingserver = NULL;
1460 priv->combo_outgoing_security = NULL;
1461 priv->combo_outgoing_auth = NULL;
1462 priv->checkbox_outgoing_smtp_specific = NULL;
1463 priv->button_outgoing_smtp_servers = NULL;
1466 if(priv->page_complete_customsetup) {
1467 gtk_widget_destroy (priv->page_complete_customsetup);
1468 priv->page_complete_customsetup = NULL;
1472 /* Create the easysetup pages: */
1473 create_subsequent_easysetup_pages (self);
1479 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1484 gchar* at = g_utf8_strchr (email_address, -1, '@');
1485 if (!at || (g_utf8_strlen (at, -1) < 2))
1488 gchar* domain = g_utf8_next_char (at);
1492 const gchar* hostname = NULL;
1493 if (servertype == MODEST_PROTOCOL_STORE_POP)
1495 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1497 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1503 return g_strdup_printf ("%s.%s", hostname, domain);
1507 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1509 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1511 if (!priv->entry_incomingserver)
1514 /* Set a default domain for the server, based on the email address,
1515 * if no server name was already specified.
1517 if (priv->entry_user_email
1518 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1519 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1520 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1521 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1523 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1525 /* Do not set the INCOMING_CHANGED flag because of this edit */
1526 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1527 gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
1528 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1530 g_free (servername);
1533 /* Set a default domain for the server, based on the email address,
1534 * if no server name was already specified.
1536 if (!priv->entry_outgoingserver)
1539 if (priv->entry_user_email
1540 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1541 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1543 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1545 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1546 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1547 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), servername);
1548 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1550 g_free (servername);
1555 get_entered_account_title (ModestEasysetupWizardDialog *self)
1557 ModestEasysetupWizardDialogPrivate *priv;
1558 const gchar* account_title;
1560 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1561 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
1563 if (!account_title || (strlen (account_title) == 0)) {
1566 /* Strip it of whitespace at the start and end: */
1567 gchar *result = g_strdup (account_title);
1568 result = g_strstrip (result);
1573 if (strlen (result) == 0) {
1583 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1585 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1586 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1588 /* if are browsing pages previous to the last one, then we have pending settings in
1590 if (next_page != NULL)
1591 priv->pending_load_settings = TRUE;
1593 /* Do extra validation that couldn't be done for every key press,
1594 * either because it was too slow,
1595 * or because it requires interaction:
1597 if (current_page == priv->page_account_details) {
1598 /* Check that the title is not already in use: */
1599 gchar* account_title = get_entered_account_title (self);
1603 /* Aavoid a clash with an existing display name: */
1604 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1605 priv->account_manager, account_title);
1608 /* Warn the user via a dialog: */
1609 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1614 else if (current_page == priv->page_user_details) {
1615 /* Check that the email address is valud: */
1616 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1617 if ((!email_address) || (strlen(email_address) == 0))
1620 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1621 /* Warn the user via a dialog: */
1622 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1624 /* Return focus to the email address entry: */
1625 gtk_widget_grab_focus (priv->entry_user_email);
1626 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1631 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1632 create_subsequent_pages (self);
1635 /* TODO: The UI Spec wants us to check that the servernames are valid,
1636 * but does not specify how.
1639 if(next_page == priv->page_custom_incoming) {
1640 set_default_custom_servernames (self);
1642 else if (next_page == priv->page_custom_outgoing) {
1643 set_default_custom_servernames (self);
1645 /* Check if the server supports secure authentication */
1646 const ModestConnectionProtocol security_incoming =
1647 modest_serversecurity_combo_box_get_active_serversecurity (
1648 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1649 if (gtk_toggle_button_get_active (
1650 GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))
1651 && !modest_protocol_info_is_secure(security_incoming))
1653 if (!check_has_supported_auth_methods (self))
1658 /* If this is the last page, and this is a click on Finish,
1659 * then attempt to create the dialog.
1661 if(!next_page) /* This is NULL when this is a click on Finish. */
1663 if (priv->pending_load_settings) {
1664 save_to_settings (self);
1666 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1673 static gboolean entry_is_empty (GtkWidget *entry)
1678 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1679 if ((!text) || (strlen(text) == 0))
1682 /* Strip it of whitespace at the start and end: */
1683 gchar *stripped = g_strdup (text);
1684 stripped = g_strstrip (stripped);
1689 const gboolean result = (strlen (stripped) == 0);
1697 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1699 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1700 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1702 gboolean enable_next = TRUE;
1703 if (current_page == priv->page_welcome) {
1706 else if (current_page == priv->page_account_details) {
1707 /* The account details title is mandatory: */
1708 if (entry_is_empty(priv->entry_account_title))
1709 enable_next = FALSE;
1711 else if (current_page == priv->page_user_details) {
1712 /* The user details username is mandatory: */
1713 if (entry_is_empty(priv->entry_user_username))
1714 enable_next = FALSE;
1716 /* The user details email address is mandatory: */
1717 if (enable_next && entry_is_empty (priv->entry_user_email))
1718 enable_next = FALSE;
1720 else if (current_page == priv->page_custom_incoming) {
1721 /* The custom incoming server is mandatory: */
1722 if (entry_is_empty(priv->entry_incomingserver))
1723 enable_next = FALSE;
1726 /* Enable the buttons,
1727 * identifying them via their associated response codes: */
1729 /* Disable the Finish button until we are on the last page,
1730 * because HildonWizardDialog enables this for all but the first page: */
1731 GtkNotebook *notebook = NULL;
1732 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1733 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1735 gint current = gtk_notebook_get_current_page (notebook);
1736 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1737 const gboolean is_last = (current == last);
1740 gtk_dialog_set_response_sensitive (dialog_base,
1741 MODEST_WIZARD_DIALOG_FINISH,
1745 /* Disable Next on the last page: */
1746 enable_next = FALSE;
1749 gtk_dialog_set_response_sensitive (dialog_base,
1750 MODEST_WIZARD_DIALOG_NEXT,
1755 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1757 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1758 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1761 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1762 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1763 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1764 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1766 /* Provide a vfunc implementation so we can decide
1767 * when to enable/disable the prev/next buttons.
1769 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1770 base_klass->before_next = on_before_next;
1771 base_klass->enable_buttons = on_enable_buttons;
1775 show_error (GtkWidget *parent_widget, const gchar* text)
1777 //TODO: Apparently this doesn't show anything in Maemo Bora:
1778 hildon_banner_show_information(parent_widget, NULL, text);
1784 * @self: a #ModestEasysetupWizardDialog
1786 * takes information from all the wizard and stores it in settings
1789 save_to_settings (ModestEasysetupWizardDialog *self)
1791 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1794 gchar* display_name;
1795 const gchar *username, *password;
1796 gchar *store_hostname, *transport_hostname;
1797 guint store_port, transport_port;
1798 ModestTransportStoreProtocol store_protocol, transport_protocol;
1799 ModestConnectionProtocol store_security, transport_security;
1800 ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
1801 ModestServerAccountSettings *store_settings, *transport_settings;
1802 const gchar *fullname, *email_address;
1804 /* Get details from the specified presets: */
1805 provider_id = easysetup_provider_combo_box_get_active_provider_id (
1806 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
1808 /* username and password (for both incoming and outgoing): */
1809 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1810 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1812 /* Incoming server: */
1813 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1814 * or modest_account_mgr_add_server_account will fail. */
1816 store_protocol = MODEST_PROTOCOL_STORE_POP;
1817 store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1818 store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1821 ModestPresetsServerType store_provider_server_type;
1822 ModestPresetsSecurity store_provider_security;
1824 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1827 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1830 store_provider_security = modest_presets_get_info_server_security (priv->presets,
1834 /* We don't check for SMTP here as that is impossible for an incoming server. */
1835 if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
1836 store_protocol = MODEST_PROTOCOL_STORE_IMAP;
1837 else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
1838 store_protocol = MODEST_PROTOCOL_STORE_POP;
1840 store_protocol = MODEST_PROTOCOL_STORE_POP;
1842 /* we check if there is a *special* port */
1843 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1844 if (special_port != 0)
1845 store_port = special_port;
1847 store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
1849 if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1850 store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1852 if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
1853 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1855 /* Use custom pages because no preset was specified: */
1856 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));
1857 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1858 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1859 store_security = modest_serversecurity_combo_box_get_active_serversecurity (
1860 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1862 /* The UI spec says:
1863 * If secure authentication is unchecked, allow sending username and password also as plain text.
1864 * If secure authentication is checked, require one of the secure methods during
1865 * connection: SSL, TLS, CRAM-MD5 etc. */
1866 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth)) &&
1867 !modest_protocol_info_is_secure(store_security)) {
1868 store_auth_protocol = check_first_supported_auth_method (self);
1870 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1874 /* now we store the store account settings */
1875 store_settings = modest_account_settings_get_store_settings (priv->settings);
1876 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1877 modest_server_account_settings_set_username (store_settings, username);
1878 modest_server_account_settings_set_password (store_settings, password);
1879 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1880 modest_server_account_settings_set_security (store_settings, store_security);
1881 modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1882 if (store_port != 0)
1883 modest_server_account_settings_set_port (store_settings, store_port);
1885 g_object_unref (store_settings);
1886 g_free (store_hostname);
1888 /* Outgoing server: */
1889 transport_hostname = NULL;
1890 transport_protocol = MODEST_PROTOCOL_STORE_POP;
1891 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1892 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1896 ModestPresetsServerType transport_provider_server_type;
1897 ModestPresetsSecurity transport_provider_security;
1900 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1901 FALSE /* transport */);
1903 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1905 FALSE /* transport */);
1906 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1908 FALSE /* transport */);
1910 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1911 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1912 if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
1913 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
1915 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1916 if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1917 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1918 transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1919 /* we check if there is a *special* port */
1920 special_port = modest_presets_get_port (priv->presets, provider_id,
1921 FALSE /* transport */);
1922 if (special_port != 0)
1923 transport_port = special_port;
1925 transport_port = 465;
1926 transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1928 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1929 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1932 /* Use custom pages because no preset was specified: */
1933 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
1934 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1935 transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
1936 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
1937 transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
1938 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
1941 /* now we transport the transport account settings */
1942 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1943 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1944 modest_server_account_settings_set_username (transport_settings, username);
1945 modest_server_account_settings_set_password (transport_settings, password);
1946 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1947 modest_server_account_settings_set_security (transport_settings, transport_security);
1948 modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1949 if (transport_port != 0)
1950 modest_server_account_settings_set_port (transport_settings, transport_port);
1952 g_object_unref (transport_settings);
1953 g_free (transport_hostname);
1955 fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1956 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1957 modest_account_settings_set_fullname (priv->settings, fullname);
1958 modest_account_settings_set_email_address (priv->settings, email_address);
1959 /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1960 are set to headers only */
1962 /* Save the connection-specific SMTP server accounts. */
1963 modest_account_settings_set_use_connection_specific_smtp
1965 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1967 display_name = get_entered_account_title (self);
1968 modest_account_settings_set_display_name (priv->settings, display_name);
1969 g_free (display_name);
1971 if (priv->specific_window)
1972 modest_connection_specific_smtp_window_save_server_accounts (
1973 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (priv->specific_window));