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 <string.h> /* For strlen(). */
44 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
45 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
46 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
47 #include "widgets/modest-serversecurity-combo-box.h"
48 #include "widgets/modest-secureauth-combo-box.h"
49 #include "widgets/modest-validating-entry.h"
50 #include "modest-text-utils.h"
51 #include "modest-conf.h"
52 #include "modest-account-mgr.h"
53 #include "modest-account-mgr-helpers.h"
54 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
55 #include "maemo/modest-connection-specific-smtp-window.h"
56 #include "widgets/modest-ui-constants.h"
57 #include "widgets/modest-account-settings-dialog.h"
58 #include "maemo/modest-maemo-utils.h"
59 #include "modest-utils.h"
60 #include "maemo/modest-hildon-includes.h"
62 /* Include config.h so that _() works: */
67 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
69 #define MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
70 MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, \
71 ModestEasysetupWizardDialogPrivate))
73 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
77 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
78 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
79 } ModestEasysetupWizardDialogServerChanges;
81 struct _ModestEasysetupWizardDialogPrivate
83 ModestPresets *presets;
85 /* Remember what fields the user edited manually to not prefill them
87 ModestEasysetupWizardDialogServerChanges server_changes;
89 /* Check if the user changes a field to show a confirmation dialog */
92 /* If we have a pending load of settings or not. */
93 gboolean pending_load_settings;
95 /* Used by derived widgets to query existing accounts,
96 * and to create new accounts: */
97 ModestAccountMgr *account_manager;
98 ModestAccountSettings *settings;
100 /* notebook pages: */
101 GtkWidget *page_welcome;
103 GtkWidget *page_account_details;
104 GtkWidget *combo_account_country;
105 GtkWidget *combo_account_serviceprovider;
106 GtkWidget *entry_account_title;
108 GtkWidget *page_user_details;
109 GtkWidget *entry_user_name;
110 GtkWidget *entry_user_username;
111 GtkWidget *entry_user_password;
112 GtkWidget *entry_user_email;
114 GtkWidget *page_complete_easysetup;
116 GtkWidget *page_custom_incoming;
117 GtkWidget *combo_incoming_servertype;
118 GtkWidget *caption_incoming;
119 GtkWidget *entry_incomingserver;
120 GtkWidget *combo_incoming_security;
121 GtkWidget *checkbox_incoming_auth;
123 GtkWidget *page_custom_outgoing;
124 GtkWidget *entry_outgoingserver;
125 GtkWidget *combo_outgoing_security;
126 GtkWidget *combo_outgoing_auth;
127 GtkWidget *checkbox_outgoing_smtp_specific;
128 GtkWidget *button_outgoing_smtp_servers;
130 GtkWidget *page_complete_customsetup;
133 static void save_to_settings (ModestEasysetupWizardDialog *self);
137 on_delete_event (GtkWidget *widget,
139 ModestEasysetupWizardDialog *wizard)
141 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
146 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
148 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
149 g_return_if_fail (priv != NULL);
154 on_incoming_security_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
156 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard);
157 ModestConnectionProtocol protocol_security_incoming;
159 g_return_if_fail (priv != NULL);
160 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
161 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
163 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth), modest_protocol_info_is_secure (protocol_security_incoming));
164 gtk_widget_set_sensitive (priv->checkbox_incoming_auth, !modest_protocol_info_is_secure (protocol_security_incoming));
166 on_easysetup_changed (widget, wizard);
170 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
171 GValue *value, GParamSpec *pspec)
173 switch (property_id) {
175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
180 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
181 const GValue *value, GParamSpec *pspec)
183 switch (property_id) {
185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
190 modest_easysetup_wizard_dialog_dispose (GObject *object)
192 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
193 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
197 modest_easysetup_wizard_dialog_finalize (GObject *object)
199 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
200 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
202 if (priv->account_manager)
203 g_object_unref (G_OBJECT (priv->account_manager));
206 modest_presets_destroy (priv->presets);
209 g_object_unref (priv->settings);
211 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
215 show_error (GtkWidget *parent_widget, const gchar* text);
218 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
221 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
223 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
225 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
226 ModestPresetsSecurity security_incoming)
228 int serverport_incoming = 0;
229 /* We don't check for SMTP here as that is impossible for an incoming server. */
230 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
231 serverport_incoming =
232 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
233 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
234 serverport_incoming =
235 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
237 return serverport_incoming;
241 check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
243 GError *error = NULL;
244 ModestTransportStoreProtocol protocol;
245 const gchar* hostname;
246 const gchar* username;
247 ModestConnectionProtocol protocol_security_incoming;
249 GList *list_auth_methods;
250 ModestEasysetupWizardDialogPrivate *priv;
252 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
253 protocol = easysetup_servertype_combo_box_get_active_servertype (
254 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
255 hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
256 username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
257 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
258 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
259 port_num = get_serverport_incoming(protocol, protocol_security_incoming);
260 list_auth_methods = modest_utils_get_supported_secure_authentication_methods (protocol, hostname, port_num,
261 username, GTK_WINDOW (self), &error);
263 if (list_auth_methods) {
264 /* TODO: Select the correct method */
267 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
268 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
269 if (modest_protocol_info_auth_is_secure(auth)) {
270 list = g_list_append(list, GINT_TO_POINTER(auth));
274 g_list_free(list_auth_methods);
280 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
281 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
283 show_error (GTK_WIDGET(self), _("mcen_ib_unableto_discover_auth_methods"));
292 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* self)
294 GList* methods = check_for_supported_auth_methods(self);
300 g_list_free(methods);
304 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* self)
306 ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
308 GList* methods = check_for_supported_auth_methods(self);
311 /* Use the first one: */
312 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
313 g_list_free(methods);
320 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
322 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
324 /* Call the vfunc, which may be overridden by derived classes: */
325 if (klass->enable_buttons) {
326 GtkNotebook *notebook = NULL;
327 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
329 const gint current_page_num = gtk_notebook_get_current_page (notebook);
330 if (current_page_num == -1)
333 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
334 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
339 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
341 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
343 invoke_enable_buttons_vfunc(self);
347 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
349 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
351 invoke_enable_buttons_vfunc(self);
354 /** This is a convenience function to create a caption containing a mandatory widget.
355 * When the widget is edited, the enable_buttons() vfunc will be called.
357 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
362 HildonCaptionStatus flag)
364 GtkWidget *caption = NULL;
366 /* Note: Previously, the translated strings already contained the "*",
367 * Comment out this code if they do again.
369 /* Add a * character to indicate mandatory fields,
370 * as specified in our "Email UI Specification": */
371 if (flag == HILDON_CAPTION_MANDATORY) {
372 gchar* title = g_strdup_printf("%s*", value);
373 caption = hildon_caption_new (group, title, control, icon, flag);
377 caption = hildon_caption_new (group, value, control, icon, flag);
379 /* Connect to the appropriate changed signal for the widget,
380 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
382 if (GTK_IS_ENTRY (control)) {
383 g_signal_connect (G_OBJECT (control), "changed",
384 G_CALLBACK (on_caption_entry_changed), self);
387 else if (GTK_IS_COMBO_BOX (control)) {
388 g_signal_connect (G_OBJECT (control), "changed",
389 G_CALLBACK (on_caption_combobox_changed), self);
396 create_page_welcome (ModestEasysetupWizardDialog *self)
398 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
399 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
400 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
401 /* So that it is not truncated: */
402 gtk_widget_set_size_request (label, 600, -1);
403 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
404 gtk_widget_show (label);
405 gtk_widget_show (GTK_WIDGET (box));
406 return GTK_WIDGET (box);
410 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
412 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
414 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
418 /* Fill the providers combo, based on the selected country: */
419 if (priv->presets != NULL) {
420 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
421 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
422 easysetup_provider_combo_box_fill (
423 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider), priv->presets, mcc);
428 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
430 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
432 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
436 /* Fill the providers combo, based on the selected country: */
437 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
438 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
440 gchar* domain_name = NULL;
442 domain_name = modest_presets_get_domain (priv->presets, provider_id);
445 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
447 if (priv->entry_user_email)
448 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), domain_name);
450 g_free (domain_name);
452 g_free (provider_id);
456 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
458 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
459 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
463 create_page_account_details (ModestEasysetupWizardDialog *self)
465 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
466 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
467 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
469 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
470 gtk_widget_set_size_request (label, 600, -1);
471 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
472 gtk_widget_show (label);
474 /* Create a size group to be used by all captions.
475 * Note that HildonCaption does not create a default size group if we do not specify one.
476 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
477 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
479 /* The country widgets: */
480 priv->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
481 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
482 priv->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
483 gtk_widget_show (priv->combo_account_country);
484 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
485 gtk_widget_show (caption);
487 /* connect to country combo's changed signal, so we can fill the provider combo: */
488 g_signal_connect (G_OBJECT (priv->combo_account_country), "changed",
489 G_CALLBACK (on_combo_account_country), self);
491 GtkWidget *separator = gtk_hseparator_new ();
492 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
493 gtk_widget_show (separator);
495 /* The service provider widgets: */
496 priv->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
497 gtk_widget_set_size_request (priv->combo_account_serviceprovider, 320, -1);
499 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
500 priv->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
501 gtk_widget_show (priv->combo_account_serviceprovider);
502 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
503 gtk_widget_show (caption);
505 /* connect to providers combo's changed signal, so we can fill the email address: */
506 g_signal_connect (G_OBJECT (priv->combo_account_serviceprovider), "changed",
507 G_CALLBACK (on_combo_account_serviceprovider), self);
509 /* The description widgets: */
510 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
511 g_signal_connect(G_OBJECT(priv->entry_account_title), "changed",
512 G_CALLBACK(on_easysetup_changed), self);
513 /* Do use auto-capitalization: */
514 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
515 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
517 /* Set a default account title, choosing one that does not already exist: */
518 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
519 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
520 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
521 priv->account_manager, default_account_name_start);
522 g_free (default_account_name_start);
523 default_account_name_start = NULL;
525 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title), default_account_name);
526 g_free (default_account_name);
527 default_account_name = NULL;
529 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
530 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
531 gtk_widget_show (priv->entry_account_title);
532 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
533 gtk_widget_show (caption);
535 /* Prevent the use of some characters in the account title,
536 * as required by our UI specification: */
537 GList *list_prevent = NULL;
538 list_prevent = g_list_append (list_prevent, "\\");
539 list_prevent = g_list_append (list_prevent, "/");
540 list_prevent = g_list_append (list_prevent, ":");
541 list_prevent = g_list_append (list_prevent, "*");
542 list_prevent = g_list_append (list_prevent, "?");
543 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
544 list_prevent = g_list_append (list_prevent, "“");
545 list_prevent = g_list_append (list_prevent, "<");
546 list_prevent = g_list_append (list_prevent, ">");
547 list_prevent = g_list_append (list_prevent, "|");
548 list_prevent = g_list_append (list_prevent, "^");
549 modest_validating_entry_set_unallowed_characters (
550 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
551 g_list_free (list_prevent);
553 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
554 modest_maemo_utils_on_entry_invalid_character, self);
556 /* Set max length as in the UI spec:
557 * The UI spec seems to want us to show a dialog if we hit the maximum. */
558 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
559 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
562 gtk_widget_show (GTK_WIDGET (box));
564 return GTK_WIDGET (box);
568 create_page_user_details (ModestEasysetupWizardDialog *self)
570 GtkSizeGroup* sizegroup;
572 ModestEasysetupWizardDialogPrivate *priv;
574 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
576 /* Create a size group to be used by all captions.
577 * Note that HildonCaption does not create a default size group if we do not specify one.
578 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
579 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
580 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
582 /* The name widgets: (use auto cap) */
583 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
584 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
585 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
587 /* Set max length as in the UI spec:
588 * The UI spec seems to want us to show a dialog if we hit the maximum. */
589 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
590 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
592 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
593 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
594 g_signal_connect(G_OBJECT(priv->entry_user_name), "changed",
595 G_CALLBACK(on_easysetup_changed), self);
596 gtk_widget_show (priv->entry_user_name);
597 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
598 gtk_widget_show (caption);
600 /* Prevent the use of some characters in the name,
601 * as required by our UI specification: */
602 GList *list_prevent = NULL;
603 list_prevent = g_list_append (list_prevent, "<");
604 list_prevent = g_list_append (list_prevent, ">");
605 modest_validating_entry_set_unallowed_characters (
606 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
607 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
608 modest_maemo_utils_on_entry_invalid_character, self);
609 g_list_free (list_prevent);
611 /* The username widgets: */
612 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
613 /* Auto-capitalization is the default, so let's turn it off: */
614 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
615 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
616 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
617 gtk_widget_show (priv->entry_user_username);
618 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
619 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed",
620 G_CALLBACK(on_easysetup_changed), self);
621 gtk_widget_show (caption);
623 /* Prevent the use of some characters in the username,
624 * as required by our UI specification: */
625 modest_validating_entry_set_unallowed_characters_whitespace (
626 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
627 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_username),
628 modest_maemo_utils_on_entry_invalid_character, self);
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_username), 64);
633 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
636 /* The password widgets: */
637 priv->entry_user_password = gtk_entry_new ();
638 /* Auto-capitalization is the default, so let's turn it off: */
639 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
640 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
641 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
642 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
643 caption = create_caption_new_with_asterisk (self, sizegroup,
644 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
645 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed",
646 G_CALLBACK(on_easysetup_changed), self);
647 gtk_widget_show (priv->entry_user_password);
648 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
649 gtk_widget_show (caption);
651 /* The email address widgets: */
652 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
653 /* Auto-capitalization is the default, so let's turn it off: */
654 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
655 caption = create_caption_new_with_asterisk (self, sizegroup,
656 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
657 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
658 gtk_widget_show (priv->entry_user_email);
659 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
660 g_signal_connect(G_OBJECT(priv->entry_user_email), "changed",
661 G_CALLBACK(on_easysetup_changed), self);
662 gtk_widget_show (caption);
664 /* Set max length as in the UI spec:
665 * The UI spec seems to want us to show a dialog if we hit the maximum. */
666 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
667 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
671 gtk_widget_show (GTK_WIDGET (box));
673 return GTK_WIDGET (box);
676 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
678 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
680 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
681 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
682 gtk_widget_set_size_request (label, 600, -1);
683 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
684 /* The documentation for gtk_label_set_line_wrap() says that we must
685 * call gtk_widget_set_size_request() with a hard-coded width,
686 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
687 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
688 gtk_widget_show (label);
690 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
691 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
692 gtk_widget_set_size_request (label, 600, -1);
694 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
695 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
696 gtk_widget_show (label);
698 gtk_widget_show (GTK_WIDGET (box));
699 return GTK_WIDGET (box);
702 /** Change the caption title for the incoming server,
703 * as specified in the UI spec:
706 update_incoming_server_title (ModestEasysetupWizardDialog *self)
708 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
709 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
710 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
712 (protocol == MODEST_PROTOCOL_STORE_POP ?
713 _("mail_fi_emailtype_pop3") :
714 _("mail_fi_emailtype_imap") );
717 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
718 g_object_set (G_OBJECT (priv->caption_incoming), "label", incomingserver_title, NULL);
719 g_free(incomingserver_title);
722 /** Change the caption title for the incoming server,
723 * as specified in the UI spec:
726 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
728 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
729 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
730 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
732 /* Fill the combo with appropriately titled choices for POP or IMAP. */
733 /* The choices are the same, but the titles are different, as in the UI spec. */
734 modest_serversecurity_combo_box_fill (
735 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol);
739 on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
741 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
742 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
746 update_incoming_server_title (self);
747 update_incoming_server_security_choices (self);
749 set_default_custom_servernames (self);
753 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
755 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
756 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
758 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
762 create_page_custom_incoming (ModestEasysetupWizardDialog *self)
764 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
765 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
766 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
768 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
770 GTK_POLICY_AUTOMATIC);
772 /* Show note that account type cannot be changed in future: */
773 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
774 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
775 gtk_widget_set_size_request (label, 600, -1);
776 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
777 gtk_widget_show (label);
779 /* Create a size group to be used by all captions.
780 * Note that HildonCaption does not create a default size group if we do not specify one.
781 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
782 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
784 /* The incoming server widgets: */
785 priv->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
786 easysetup_servertype_combo_box_set_active_servertype (
787 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
788 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
789 _("mcen_li_emailsetup_type"), priv->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
790 gtk_widget_show (priv->combo_incoming_servertype);
791 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
792 gtk_widget_show (caption);
794 priv->entry_incomingserver = gtk_entry_new ();
795 g_signal_connect(G_OBJECT(priv->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
796 /* Auto-capitalization is the default, so let's turn it off: */
797 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
798 set_default_custom_servernames (self);
800 /* The caption title will be updated in update_incoming_server_title().
801 * so this default text will never be seen: */
802 /* (Note: Changing the title seems pointless. murrayc) */
803 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
804 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
805 update_incoming_server_title (self);
806 gtk_widget_show (priv->entry_incomingserver);
807 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
808 gtk_widget_show (priv->caption_incoming);
810 /* Change the caption title when the servertype changes,
811 * as in the UI spec: */
812 g_signal_connect (G_OBJECT (priv->combo_incoming_servertype), "changed",
813 G_CALLBACK (on_combo_servertype_changed), self);
815 /* Remember when the servername was changed manually: */
816 g_signal_connect (G_OBJECT (priv->entry_incomingserver), "changed",
817 G_CALLBACK (on_entry_incoming_servername_changed), self);
819 /* The secure connection widgets: */
820 priv->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
821 update_incoming_server_security_choices (self);
822 modest_serversecurity_combo_box_set_active_serversecurity (
823 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
824 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
825 priv->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
826 g_signal_connect (G_OBJECT (priv->combo_incoming_security), "changed",
827 G_CALLBACK (on_incoming_security_changed), self);
828 gtk_widget_show (priv->combo_incoming_security);
829 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
830 gtk_widget_show (caption);
832 priv->checkbox_incoming_auth = gtk_check_button_new ();
833 g_signal_connect (G_OBJECT (priv->checkbox_incoming_auth), "toggled",
834 G_CALLBACK (on_easysetup_changed), self);
835 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
836 priv->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
838 gtk_widget_show (priv->checkbox_incoming_auth);
839 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
840 gtk_widget_show (caption);
842 gtk_widget_show (GTK_WIDGET (box));
844 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
845 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
846 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
847 gtk_widget_show (scrolled_window);
849 return GTK_WIDGET (scrolled_window);
853 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
855 GtkWidget *widget = GTK_WIDGET (user_data);
857 /* Enable the widget only if the toggle button is active: */
858 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
859 gtk_widget_set_sensitive (widget, enable);
862 /* Make the sensitivity of a widget depend on a toggle button.
865 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
867 g_signal_connect (G_OBJECT (button), "toggled",
868 G_CALLBACK (on_toggle_button_changed), widget);
870 /* Set the starting sensitivity: */
871 on_toggle_button_changed (button, widget);
875 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
877 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
878 ModestEasysetupWizardDialogPrivate* priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
879 GtkWidget *specific_window;
881 /* We set dirty here because setting it depending on the connection specific dialog
885 /* Create the window, if necessary: */
886 specific_window = (GtkWidget *) modest_connection_specific_smtp_window_new ();
887 modest_connection_specific_smtp_window_fill_with_connections (MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), priv->account_manager);
889 /* Show the window */
890 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (specific_window));
891 gtk_widget_show (specific_window);
895 on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
897 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
898 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
899 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
903 create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
905 ModestEasysetupWizardDialogPrivate *priv;
906 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
908 /* Create a size group to be used by all captions.
909 * Note that HildonCaption does not create a default size group if we do not specify one.
910 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
911 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
913 /* The outgoing server widgets: */
914 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
915 priv->entry_outgoingserver = gtk_entry_new ();
916 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
917 G_CALLBACK (on_easysetup_changed), self);
918 /* Auto-capitalization is the default, so let's turn it off: */
919 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
920 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
921 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
922 gtk_widget_show (priv->entry_outgoingserver);
923 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
924 gtk_widget_show (caption);
925 set_default_custom_servernames (self);
927 /* The secure connection widgets: */
928 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
929 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed",
930 G_CALLBACK (on_easysetup_changed), self);
931 modest_serversecurity_combo_box_fill (
932 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
933 modest_serversecurity_combo_box_set_active_serversecurity (
934 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
935 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
936 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
937 gtk_widget_show (priv->combo_outgoing_security);
938 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
939 gtk_widget_show (caption);
941 /* The secure authentication widgets: */
942 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
943 g_signal_connect (G_OBJECT (priv->combo_outgoing_auth), "changed",
944 G_CALLBACK (on_easysetup_changed), self);
945 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
946 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
947 gtk_widget_show (priv->combo_outgoing_auth);
948 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
949 gtk_widget_show (caption);
951 GtkWidget *separator = gtk_hseparator_new ();
952 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
953 gtk_widget_show (separator);
955 /* connection-specific checkbox: */
956 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
957 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
959 g_signal_connect (G_OBJECT (priv->checkbox_outgoing_smtp_specific), "toggled",
960 G_CALLBACK (on_easysetup_changed), self);
962 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
963 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
964 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
965 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
966 gtk_widget_show (caption);
968 /* Connection-specific SMTP-Severs Edit button: */
969 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
970 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
971 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
972 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
973 gtk_widget_show (priv->button_outgoing_smtp_servers);
974 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
975 gtk_widget_show (caption);
977 /* Only enable the button when the checkbox is checked: */
978 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
979 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
981 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
982 G_CALLBACK (on_button_outgoing_smtp_servers), self);
984 g_signal_connect (G_OBJECT (priv->entry_outgoingserver), "changed",
985 G_CALLBACK (on_entry_outgoing_servername_changed), self);
988 gtk_widget_show (GTK_WIDGET (box));
990 return GTK_WIDGET (box);
994 show_advanced_edit(gpointer user_data)
996 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
997 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1000 /* Show the Account Settings window: */
1001 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
1002 if (priv->pending_load_settings) {
1003 save_to_settings (self);
1004 priv->pending_load_settings = FALSE;
1006 modest_account_settings_dialog_set_account (dialog, priv->settings);
1008 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
1010 response = gtk_dialog_run (GTK_DIALOG (dialog));
1012 gtk_widget_destroy (GTK_WIDGET (dialog));
1014 return FALSE; /* Do not call this timeout callback again. */
1018 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1020 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1022 /* Show the Account Settings window: */
1023 show_advanced_edit(self);
1025 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1027 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1028 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1029 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1030 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1031 gtk_widget_set_size_request (label, 600, -1);
1032 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1033 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1034 gtk_widget_show (label);
1036 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1037 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1038 gtk_widget_set_size_request (label, 600, -1);
1039 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1040 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1041 gtk_widget_show (label);
1043 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1044 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1045 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1046 gtk_widget_show (button_edit);
1047 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1048 gtk_widget_show (caption);
1050 g_signal_connect (G_OBJECT (button_edit), "clicked",
1051 G_CALLBACK (on_button_edit_advanced_settings), self);
1053 gtk_widget_show (GTK_WIDGET (box));
1054 return GTK_WIDGET (box);
1061 on_response (ModestWizardDialog *wizard_dialog,
1065 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1067 invoke_enable_buttons_vfunc (self);
1071 on_response_before (ModestWizardDialog *wizard_dialog,
1075 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1076 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1077 if (response_id == GTK_RESPONSE_CANCEL) {
1078 /* This is mostly copied from
1079 * src/maemo/modest-account-settings-dialog.c */
1081 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1082 _("imum_nc_wizard_confirm_lose_changes")));
1083 /* TODO: These button names will be ambiguous, and not
1084 * specified in the UI specification. */
1086 const gint dialog_response = gtk_dialog_run (dialog);
1087 gtk_widget_destroy (GTK_WIDGET (dialog));
1089 if (dialog_response != GTK_RESPONSE_OK) {
1090 /* Don't let the dialog close */
1091 g_signal_stop_emission_by_name (wizard_dialog, "response");
1097 typedef struct IdleData {
1098 ModestEasysetupWizardDialog *dialog;
1099 ModestPresets *presets;
1103 presets_idle (gpointer userdata)
1105 IdleData *idle_data = (IdleData *) userdata;
1106 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1107 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1109 g_assert (idle_data->presets);
1111 gdk_threads_enter ();
1113 priv->presets = idle_data->presets;
1115 if (MODEST_EASYSETUP_IS_COUNTRY_COMBO_BOX (priv->combo_account_country)) {
1116 /* gint mcc = get_default_country_code(); */
1118 /* Fill the combo in an idle call, as it takes a lot of time */
1119 easysetup_country_combo_box_load_data(
1120 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
1121 /* easysetup_country_combo_box_set_active_country_mcc ( */
1122 /* MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country), mcc); */
1123 easysetup_country_combo_box_set_active_country_locale (
1124 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
1125 mcc = easysetup_country_combo_box_get_active_country_mcc (
1126 MODEST_EASYSETUP_COUNTRY_COMBO_BOX (priv->combo_account_country));
1127 easysetup_provider_combo_box_fill (
1128 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider),
1129 priv->presets, mcc);
1132 priv->dirty = FALSE;
1134 g_object_unref (idle_data->dialog);
1137 gdk_threads_leave ();
1143 presets_loader (gpointer userdata)
1145 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1146 ModestPresets *presets = NULL;
1147 IdleData *idle_data;
1149 const gchar* path = NULL;
1150 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1151 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1153 if (access(path1, R_OK) == 0)
1155 else if (access(path2, R_OK) == 0)
1158 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1159 __FUNCTION__, path1, path2);
1163 presets = modest_presets_new (path);
1165 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1169 idle_data = g_new0 (IdleData, 1);
1170 idle_data->dialog = self;
1171 idle_data->presets = presets;
1173 g_idle_add (presets_idle, idle_data);
1179 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1181 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1183 /* Create the notebook to be used by the ModestWizardDialog base class:
1184 * Each page of the notebook will be a page of the wizard: */
1185 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1187 /* Set the notebook used by the ModestWizardDialog base class: */
1188 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1190 /* Set the wizard title:
1191 * The actual window title will be a combination of this and the page's tab label title. */
1192 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1194 /* Read in the information about known service providers: */
1195 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1197 /* The server fields did not have been manually changed yet */
1198 priv->server_changes = 0;
1199 priv->pending_load_settings = TRUE;
1201 /* Get the account manager object,
1202 * so we can check for existing accounts,
1203 * and create new accounts: */
1204 priv->account_manager = modest_runtime_get_account_mgr ();
1205 g_object_ref (priv->account_manager);
1207 /* Initialize fields */
1208 priv->page_welcome = create_page_welcome (self);
1209 priv->page_account_details = create_page_account_details (self);
1210 priv->page_user_details = create_page_user_details (self);
1211 priv->page_complete_easysetup = NULL;
1212 priv->page_custom_incoming = NULL;
1213 priv->combo_incoming_servertype = NULL;
1214 priv->caption_incoming = NULL;
1215 priv->entry_incomingserver = NULL;
1216 priv->combo_incoming_security = NULL;
1217 priv->checkbox_incoming_auth = NULL;
1218 priv->page_custom_outgoing = NULL;
1219 priv->entry_outgoingserver = NULL;
1220 priv->combo_outgoing_security = NULL;
1221 priv->combo_outgoing_auth = NULL;
1222 priv->checkbox_outgoing_smtp_specific = NULL;
1223 priv->button_outgoing_smtp_servers = NULL;
1224 priv->page_complete_customsetup = NULL;
1226 /* Add the common pages: */
1227 gtk_notebook_append_page (notebook, priv->page_welcome,
1228 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1229 gtk_container_child_set (GTK_CONTAINER (notebook),
1235 gtk_notebook_append_page (notebook, priv->page_account_details,
1236 gtk_label_new (_("mcen_ti_accountdetails")));
1237 gtk_container_child_set (GTK_CONTAINER (notebook),
1238 priv->page_account_details,
1243 gtk_notebook_append_page (notebook, priv->page_user_details,
1244 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1245 gtk_container_child_set (GTK_CONTAINER (notebook),
1246 priv->page_user_details,
1251 /* Create and add the easysetup-specific pages,
1252 * because we need _some_ final page to enable the Next and Finish buttons: */
1253 create_subsequent_easysetup_pages (self);
1255 /* Connect to the dialog's response signal so we can enable/disable buttons
1256 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1257 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1258 * so that we can be enable/disable after ModestWizardDialog has done its own
1259 * enabling/disabling of buttons.
1261 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1262 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1264 * It's not enough to connect to the notebook's switch-page signal, because
1265 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1266 * _after_ switching the page (understandably).
1267 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1268 * then gtk_notebook_get_current_page() would return an incorrect value.)
1270 g_signal_connect_after (G_OBJECT (self), "response",
1271 G_CALLBACK (on_response), self);
1273 /* This is to show a confirmation dialog when the user hits cancel */
1274 g_signal_connect (G_OBJECT (self), "response",
1275 G_CALLBACK (on_response_before), self);
1277 g_signal_connect (G_OBJECT (self), "delete-event",
1278 G_CALLBACK (on_delete_event), self);
1280 /* Reset dirty, because there was no user input until now */
1281 priv->dirty = FALSE;
1283 /* When this window is shown, hibernation should not be possible,
1284 * because there is no sensible way to save the state: */
1285 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1286 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1288 /* Load provider presets */
1289 g_object_ref (self);
1290 g_thread_create (presets_loader, self, FALSE, NULL);
1292 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1293 modest_maemo_utils_get_osso_context());
1295 priv->settings = modest_account_settings_new ();
1298 ModestEasysetupWizardDialog*
1299 modest_easysetup_wizard_dialog_new (void)
1302 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1305 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1307 ModestEasysetupWizardDialogPrivate *priv;
1308 GtkNotebook *notebook = NULL;
1310 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1313 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1315 /* Create the custom pages: */
1316 if(!(priv->page_custom_incoming)) {
1317 priv->page_custom_incoming = create_page_custom_incoming (self);
1320 if(!(priv->page_custom_outgoing)) {
1321 priv->page_custom_outgoing = create_page_custom_outgoing (self);
1324 if(!(priv->page_complete_customsetup)) {
1325 priv->page_complete_customsetup = create_page_complete_custom (self);
1328 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_incoming)))
1329 gtk_notebook_append_page (notebook, priv->page_custom_incoming,
1330 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1332 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_custom_outgoing)))
1333 gtk_notebook_append_page (notebook, priv->page_custom_outgoing,
1334 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1336 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_customsetup))) {
1337 gtk_notebook_append_page (notebook, priv->page_complete_customsetup,
1338 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1339 gtk_container_child_set (GTK_CONTAINER (notebook),
1340 priv->page_complete_customsetup,
1346 /* This is unnecessary with GTK+ 2.10: */
1347 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1351 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1353 ModestEasysetupWizardDialogPrivate *priv;
1354 GtkNotebook *notebook = NULL;
1356 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1359 /* Create the easysetup-specific pages: */
1360 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1361 if(!priv->page_complete_easysetup)
1362 priv->page_complete_easysetup = create_page_complete_easysetup (self);
1364 if (!gtk_widget_get_parent (GTK_WIDGET (priv->page_complete_easysetup))) {
1365 gtk_notebook_append_page (notebook, priv->page_complete_easysetup,
1366 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1367 gtk_container_child_set (GTK_CONTAINER (notebook),
1368 priv->page_complete_easysetup,
1374 /* This is unnecessary with GTK+ 2.10: */
1375 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1377 /* After the user details page,
1378 * the following pages depend on whether "Other" was chosen
1379 * in the provider combobox on the account page
1381 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1383 ModestEasysetupWizardDialogPrivate *priv;
1385 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1387 if (easysetup_provider_combo_box_get_active_provider_id (
1388 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider)) == 0) {
1389 /* "Other..." was selected: */
1391 /* Make sure that the easysetup pages do not exist: */
1392 if(priv->page_complete_easysetup) {
1393 gtk_widget_destroy (priv->page_complete_easysetup);
1394 priv->page_complete_easysetup = NULL;
1397 create_subsequent_customsetup_pages (self);
1400 /* A specific provider was selected: */
1402 /* Make sure that the custom pages do not exist:
1403 * Because they will be used if they exist, when creating the account. */
1404 if(priv->page_custom_incoming) {
1405 gtk_widget_destroy (priv->page_custom_incoming);
1406 priv->page_custom_incoming = NULL;
1407 priv->combo_incoming_servertype = NULL;
1408 priv->caption_incoming = NULL;
1409 priv->entry_incomingserver = NULL;
1410 priv->combo_incoming_security = NULL;
1411 priv->checkbox_incoming_auth = NULL;
1414 if(priv->page_custom_outgoing) {
1415 gtk_widget_destroy (priv->page_custom_outgoing);
1416 priv->page_custom_outgoing = NULL;
1417 priv->entry_outgoingserver = NULL;
1418 priv->combo_outgoing_security = NULL;
1419 priv->combo_outgoing_auth = NULL;
1420 priv->checkbox_outgoing_smtp_specific = NULL;
1421 priv->button_outgoing_smtp_servers = NULL;
1424 if(priv->page_complete_customsetup) {
1425 gtk_widget_destroy (priv->page_complete_customsetup);
1426 priv->page_complete_customsetup = NULL;
1430 /* Create the easysetup pages: */
1431 create_subsequent_easysetup_pages (self);
1437 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1442 gchar* at = g_utf8_strchr (email_address, -1, '@');
1443 if (!at || (g_utf8_strlen (at, -1) < 2))
1446 gchar* domain = g_utf8_next_char (at);
1450 const gchar* hostname = NULL;
1451 if (servertype == MODEST_PROTOCOL_STORE_POP)
1453 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1455 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1461 return g_strdup_printf ("%s.%s", hostname, domain);
1465 set_default_custom_servernames (ModestEasysetupWizardDialog *self)
1467 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1469 if (!priv->entry_incomingserver)
1472 /* Set a default domain for the server, based on the email address,
1473 * if no server name was already specified.
1475 if (priv->entry_user_email
1476 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1477 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1478 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1479 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1481 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1483 /* Do not set the INCOMING_CHANGED flag because of this edit */
1484 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1485 gtk_entry_set_text (GTK_ENTRY (priv->entry_incomingserver), servername);
1486 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), self);
1488 g_free (servername);
1491 /* Set a default domain for the server, based on the email address,
1492 * if no server name was already specified.
1494 if (!priv->entry_outgoingserver)
1497 if (priv->entry_user_email
1498 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1499 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(priv->entry_user_email));
1501 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1503 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1504 g_signal_handlers_block_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1505 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), servername);
1506 g_signal_handlers_unblock_by_func (G_OBJECT (priv->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), self);
1508 g_free (servername);
1513 get_entered_account_title (ModestEasysetupWizardDialog *self)
1515 ModestEasysetupWizardDialogPrivate *priv;
1516 const gchar* account_title;
1518 priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
1519 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
1521 if (!account_title || (strlen (account_title) == 0)) {
1524 /* Strip it of whitespace at the start and end: */
1525 gchar *result = g_strdup (account_title);
1526 result = g_strstrip (result);
1531 if (strlen (result) == 0) {
1541 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1543 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1544 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1546 /* if are browsing pages previous to the last one, then we have pending settings in
1548 if (next_page != NULL)
1549 priv->pending_load_settings = TRUE;
1551 /* Do extra validation that couldn't be done for every key press,
1552 * either because it was too slow,
1553 * or because it requires interaction:
1555 if (current_page == priv->page_account_details) {
1556 /* Check that the title is not already in use: */
1557 gchar* account_title = get_entered_account_title (self);
1561 /* Aavoid a clash with an existing display name: */
1562 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1563 priv->account_manager, account_title);
1566 /* Warn the user via a dialog: */
1567 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1572 else if (current_page == priv->page_user_details) {
1573 /* Check that the email address is valud: */
1574 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1575 if ((!email_address) || (strlen(email_address) == 0))
1578 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1579 /* Warn the user via a dialog: */
1580 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1582 /* Return focus to the email address entry: */
1583 gtk_widget_grab_focus (priv->entry_user_email);
1584 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
1589 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1590 create_subsequent_pages (self);
1593 /* TODO: The UI Spec wants us to check that the servernames are valid,
1594 * but does not specify how.
1597 if(next_page == priv->page_custom_incoming) {
1598 set_default_custom_servernames (self);
1600 else if (next_page == priv->page_custom_outgoing) {
1601 set_default_custom_servernames (self);
1603 /* Check if the server supports secure authentication */
1604 const ModestConnectionProtocol security_incoming =
1605 modest_serversecurity_combo_box_get_active_serversecurity (
1606 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1607 if (gtk_toggle_button_get_active (
1608 GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))
1609 && !modest_protocol_info_is_secure(security_incoming))
1611 if (!check_has_supported_auth_methods (self))
1616 /* If this is the last page, and this is a click on Finish,
1617 * then attempt to create the dialog.
1619 if(!next_page) /* This is NULL when this is a click on Finish. */
1621 if (priv->pending_load_settings) {
1622 save_to_settings (self);
1625 /* We check if there's already another account with the same configuration */
1626 if (modest_account_mgr_check_already_configured_account (priv->account_manager, priv->settings)) {
1627 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1631 modest_account_mgr_add_account_from_settings (priv->account_manager, priv->settings);
1638 static gboolean entry_is_empty (GtkWidget *entry)
1643 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1644 if ((!text) || (strlen(text) == 0))
1647 /* Strip it of whitespace at the start and end: */
1648 gchar *stripped = g_strdup (text);
1649 stripped = g_strstrip (stripped);
1654 const gboolean result = (strlen (stripped) == 0);
1662 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1664 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1665 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1667 gboolean enable_next = TRUE;
1668 if (current_page == priv->page_welcome) {
1671 else if (current_page == priv->page_account_details) {
1672 /* The account details title is mandatory: */
1673 if (entry_is_empty(priv->entry_account_title))
1674 enable_next = FALSE;
1676 else if (current_page == priv->page_user_details) {
1677 /* The user details username is mandatory: */
1678 if (entry_is_empty(priv->entry_user_username))
1679 enable_next = FALSE;
1681 /* The user details email address is mandatory: */
1682 if (enable_next && entry_is_empty (priv->entry_user_email))
1683 enable_next = FALSE;
1685 else if (current_page == priv->page_custom_incoming) {
1686 /* The custom incoming server is mandatory: */
1687 if (entry_is_empty(priv->entry_incomingserver))
1688 enable_next = FALSE;
1691 /* Enable the buttons,
1692 * identifying them via their associated response codes: */
1694 /* Disable the Finish button until we are on the last page,
1695 * because HildonWizardDialog enables this for all but the first page: */
1696 GtkNotebook *notebook = NULL;
1697 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1698 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1700 gint current = gtk_notebook_get_current_page (notebook);
1701 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1702 const gboolean is_last = (current == last);
1705 gtk_dialog_set_response_sensitive (dialog_base,
1706 MODEST_WIZARD_DIALOG_FINISH,
1710 /* Disable Next on the last page: */
1711 enable_next = FALSE;
1714 gtk_dialog_set_response_sensitive (dialog_base,
1715 MODEST_WIZARD_DIALOG_NEXT,
1720 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1722 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1723 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1726 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1727 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1728 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1729 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1731 /* Provide a vfunc implementation so we can decide
1732 * when to enable/disable the prev/next buttons.
1734 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1735 base_klass->before_next = on_before_next;
1736 base_klass->enable_buttons = on_enable_buttons;
1740 show_error (GtkWidget *parent_widget, const gchar* text)
1742 //TODO: Apparently this doesn't show anything in Maemo Bora:
1743 hildon_banner_show_information(parent_widget, NULL, text);
1749 * @self: a #ModestEasysetupWizardDialog
1751 * takes information from all the wizard and stores it in settings
1754 save_to_settings (ModestEasysetupWizardDialog *self)
1756 ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
1759 gchar* display_name;
1760 const gchar *username, *password;
1761 gchar *store_hostname, *transport_hostname;
1762 guint store_port, transport_port;
1763 ModestTransportStoreProtocol store_protocol, transport_protocol;
1764 ModestConnectionProtocol store_security, transport_security;
1765 ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
1766 ModestServerAccountSettings *store_settings, *transport_settings;
1767 const gchar *fullname, *email_address;
1769 /* Get details from the specified presets: */
1770 provider_id = easysetup_provider_combo_box_get_active_provider_id (
1771 EASYSETUP_PROVIDER_COMBO_BOX (priv->combo_account_serviceprovider));
1773 /* username and password (for both incoming and outgoing): */
1774 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1775 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1777 /* Incoming server: */
1778 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1779 * or modest_account_mgr_add_server_account will fail. */
1781 store_protocol = MODEST_PROTOCOL_STORE_POP;
1782 store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1783 store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1786 ModestPresetsServerType store_provider_server_type;
1787 ModestPresetsSecurity store_provider_security;
1789 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1792 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1795 store_provider_security = modest_presets_get_info_server_security (priv->presets,
1799 /* We don't check for SMTP here as that is impossible for an incoming server. */
1800 if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
1801 store_protocol = MODEST_PROTOCOL_STORE_IMAP;
1802 else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
1803 store_protocol = MODEST_PROTOCOL_STORE_POP;
1805 store_protocol = MODEST_PROTOCOL_STORE_POP;
1807 /* we check if there is a *special* port */
1808 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1809 if (special_port != 0)
1810 store_port = special_port;
1812 store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
1814 if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1815 store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1817 if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
1818 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1820 /* Use custom pages because no preset was specified: */
1821 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver) ));
1822 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1823 EASYSETUP_SERVERTYPE_COMBO_BOX (priv->combo_incoming_servertype));
1824 store_security = modest_serversecurity_combo_box_get_active_serversecurity (
1825 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security));
1827 /* The UI spec says:
1828 * If secure authentication is unchecked, allow sending username and password also as plain text.
1829 * If secure authentication is checked, require one of the secure methods during
1830 * connection: SSL, TLS, CRAM-MD5 etc. */
1831 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth)) &&
1832 !modest_protocol_info_is_secure(store_security)) {
1833 store_auth_protocol = check_first_supported_auth_method (self);
1835 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1839 /* now we store the store account settings */
1840 store_settings = modest_account_settings_get_store_settings (priv->settings);
1841 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1842 modest_server_account_settings_set_username (store_settings, username);
1843 modest_server_account_settings_set_password (store_settings, password);
1844 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1845 modest_server_account_settings_set_security (store_settings, store_security);
1846 modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1847 if (store_port != 0)
1848 modest_server_account_settings_set_port (store_settings, store_port);
1850 g_object_unref (store_settings);
1851 g_free (store_hostname);
1853 /* Outgoing server: */
1854 transport_hostname = NULL;
1855 transport_protocol = MODEST_PROTOCOL_STORE_POP;
1856 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1857 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1861 ModestPresetsServerType transport_provider_server_type;
1862 ModestPresetsSecurity transport_provider_security;
1865 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1866 FALSE /* transport */);
1868 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1870 FALSE /* transport */);
1871 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1873 FALSE /* transport */);
1875 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1876 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1877 if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
1878 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
1880 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1881 if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1882 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1883 transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1884 /* we check if there is a *special* port */
1885 special_port = modest_presets_get_port (priv->presets, provider_id,
1886 FALSE /* transport */);
1887 if (special_port != 0)
1888 transport_port = special_port;
1890 transport_port = 465;
1891 transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1893 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1894 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1897 /* Use custom pages because no preset was specified: */
1898 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver) ));
1899 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1900 transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
1901 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
1902 transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
1903 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
1906 /* now we transport the transport account settings */
1907 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1908 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1909 modest_server_account_settings_set_username (transport_settings, username);
1910 modest_server_account_settings_set_password (transport_settings, password);
1911 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1912 modest_server_account_settings_set_security (transport_settings, transport_security);
1913 modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1914 if (transport_port != 0)
1915 modest_server_account_settings_set_port (transport_settings, transport_port);
1917 g_object_unref (transport_settings);
1918 g_free (transport_hostname);
1920 fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1921 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1922 modest_account_settings_set_fullname (priv->settings, fullname);
1923 modest_account_settings_set_email_address (priv->settings, email_address);
1924 /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1925 are set to headers only */
1927 /* Save the connection-specific SMTP server accounts. */
1928 modest_account_settings_set_use_connection_specific_smtp
1930 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1932 display_name = get_entered_account_title (self);
1933 modest_account_settings_set_display_name (priv->settings, display_name);
1934 g_free (display_name);