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.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 "maemo/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 WIZARD_DIALOG_GET_PRIVATE(o) \
70 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
72 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
76 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
77 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
78 } ModestEasysetupWizardDialogServerChanges;
80 struct _ModestEasysetupWizardDialogPrivate
82 ModestPresets *presets;
84 /* Remember what fields the user edited manually to not prefill them
86 ModestEasysetupWizardDialogServerChanges server_changes;
88 /* Check if the user changes a field to show a confirmation dialog */
91 /* If we have a pending load of settings or not. */
92 gboolean pending_load_settings;
95 static void save_to_settings (ModestEasysetupWizardDialog *self);
99 on_delete_event (GtkWidget *widget,
101 ModestEasysetupWizardDialog *wizard)
103 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
108 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
110 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(wizard);
111 g_return_if_fail (priv != NULL);
116 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
117 GValue *value, GParamSpec *pspec)
119 switch (property_id) {
121 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
126 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
127 const GValue *value, GParamSpec *pspec)
129 switch (property_id) {
131 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
136 modest_easysetup_wizard_dialog_dispose (GObject *object)
138 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
139 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
143 modest_easysetup_wizard_dialog_finalize (GObject *object)
145 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
146 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
148 if (self->account_manager)
149 g_object_unref (G_OBJECT (self->account_manager));
152 modest_presets_destroy (priv->presets);
154 if (self->specific_window)
155 gtk_widget_destroy (self->specific_window);
158 g_object_unref (self->settings);
160 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
164 show_error (GtkWidget *parent_widget, const gchar* text);
167 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
170 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
172 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
174 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
175 ModestPresetsSecurity security_incoming)
177 int serverport_incoming = 0;
178 /* We don't check for SMTP here as that is impossible for an incoming server. */
179 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
180 serverport_incoming =
181 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
182 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
183 serverport_incoming =
184 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
186 return serverport_incoming;
189 static GList* check_for_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
191 GError *error = NULL;
192 const ModestTransportStoreProtocol protocol =
193 easysetup_servertype_combo_box_get_active_servertype (
194 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
195 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
196 const gchar* username = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_user_username));
197 const ModestConnectionProtocol protocol_security_incoming =
198 modest_serversecurity_combo_box_get_active_serversecurity (
199 MODEST_SERVERSECURITY_COMBO_BOX (
200 account_wizard->combo_incoming_security));
201 const int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
202 GList *list_auth_methods =
203 modest_utils_get_supported_secure_authentication_methods (protocol, hostname, port_num,
204 username, GTK_WINDOW (account_wizard), &error);
205 if (list_auth_methods) {
206 /* TODO: Select the correct method */
209 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
210 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
211 if (modest_protocol_info_auth_is_secure(auth)) {
212 list = g_list_append(list, GINT_TO_POINTER(auth));
216 g_list_free(list_auth_methods);
222 if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
223 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
225 show_error (GTK_WIDGET(account_wizard), _("Could not discover supported secure authentication methods."));
234 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
236 GList* methods = check_for_supported_auth_methods(account_wizard);
242 g_list_free(methods);
246 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* account_wizard)
248 ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
250 GList* methods = check_for_supported_auth_methods(account_wizard);
253 /* Use the first one: */
254 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
255 g_list_free(methods);
262 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
264 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
266 /* Call the vfunc, which may be overridden by derived classes: */
267 if (klass->enable_buttons) {
268 GtkNotebook *notebook = NULL;
269 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
271 const gint current_page_num = gtk_notebook_get_current_page (notebook);
272 if (current_page_num == -1)
275 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
276 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
281 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
283 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
285 invoke_enable_buttons_vfunc(self);
289 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
291 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
293 invoke_enable_buttons_vfunc(self);
296 /** This is a convenience function to create a caption containing a mandatory widget.
297 * When the widget is edited, the enable_buttons() vfunc will be called.
299 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
304 HildonCaptionStatus flag)
306 GtkWidget *caption = NULL;
308 /* Note: Previously, the translated strings already contained the "*",
309 * Comment out this code if they do again.
311 /* Add a * character to indicate mandatory fields,
312 * as specified in our "Email UI Specification": */
313 if (flag == HILDON_CAPTION_MANDATORY) {
314 gchar* title = g_strdup_printf("%s*", value);
315 caption = hildon_caption_new (group, title, control, icon, flag);
319 caption = hildon_caption_new (group, value, control, icon, flag);
321 /* Connect to the appropriate changed signal for the widget,
322 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
324 if (GTK_IS_ENTRY (control)) {
325 g_signal_connect (G_OBJECT (control), "changed",
326 G_CALLBACK (on_caption_entry_changed), self);
329 else if (GTK_IS_COMBO_BOX (control)) {
330 g_signal_connect (G_OBJECT (control), "changed",
331 G_CALLBACK (on_caption_combobox_changed), self);
338 create_page_welcome (ModestEasysetupWizardDialog *self)
340 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
341 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
342 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
343 /* So that it is not truncated: */
344 gtk_widget_set_size_request (label, 600, -1);
345 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
346 gtk_widget_show (label);
347 gtk_widget_show (GTK_WIDGET (box));
348 return GTK_WIDGET (box);
352 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
354 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
356 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
360 /* Fill the providers combo, based on the selected country: */
361 if (priv->presets != NULL) {
362 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
363 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
364 easysetup_provider_combo_box_fill (
365 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc);
370 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
372 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
374 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
378 /* Fill the providers combo, based on the selected country: */
379 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
380 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
382 gchar* domain_name = NULL;
384 domain_name = modest_presets_get_domain (priv->presets, provider_id);
387 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
389 if (self->entry_user_email)
390 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
392 g_free (domain_name);
394 g_free (provider_id);
398 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
400 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
401 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
405 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
407 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
409 const gchar *show_char = NULL;
411 show_char = character;
413 /* TODO: We need a logical ID for this: */
414 show_char = _("whitespace");
417 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
418 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
419 show_error (GTK_WIDGET (self), message);
423 get_default_country_code(void)
425 /* TODO: Default to the current country somehow.
426 * But I don't know how to get the information that is specified in the
427 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
429 * This is probably not the best choice of gconf key:
430 * This is the "mcc used in the last pairing", ie. the last connection you made.
431 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
434 GError *error = NULL;
435 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
436 gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
442 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
443 g_error_free (error);
449 /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
450 * This might just be a Maemo bug.
454 /* For now, we default to Finland when there is nothing better: */
461 create_page_account_details (ModestEasysetupWizardDialog *self)
463 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
464 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
465 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
466 gtk_widget_set_size_request (label, 600, -1);
467 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
468 gtk_widget_show (label);
470 /* Create a size group to be used by all captions.
471 * Note that HildonCaption does not create a default size group if we do not specify one.
472 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
473 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
475 /* The country widgets: */
476 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
477 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
478 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
479 gtk_widget_show (self->combo_account_country);
480 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
481 gtk_widget_show (caption);
483 /* connect to country combo's changed signal, so we can fill the provider combo: */
484 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
485 G_CALLBACK (on_combo_account_country), self);
487 GtkWidget *separator = gtk_hseparator_new ();
488 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
489 gtk_widget_show (separator);
491 /* The service provider widgets: */
492 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
493 gtk_widget_set_size_request (self->combo_account_serviceprovider, 320, -1);
495 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
496 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
497 gtk_widget_show (self->combo_account_serviceprovider);
498 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
499 gtk_widget_show (caption);
501 /* connect to providers combo's changed signal, so we can fill the email address: */
502 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
503 G_CALLBACK (on_combo_account_serviceprovider), self);
505 /* The description widgets: */
506 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
507 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
508 G_CALLBACK(on_easysetup_changed), self);
509 /* Do use auto-capitalization: */
510 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
511 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
513 /* Set a default account title, choosing one that does not already exist: */
514 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
515 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
516 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
517 self->account_manager, default_account_name_start);
518 g_free (default_account_name_start);
519 default_account_name_start = NULL;
521 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
522 g_free (default_account_name);
523 default_account_name = NULL;
525 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
526 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
527 gtk_widget_show (self->entry_account_title);
528 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
529 gtk_widget_show (caption);
531 /* Prevent the use of some characters in the account title,
532 * as required by our UI specification: */
533 GList *list_prevent = NULL;
534 list_prevent = g_list_append (list_prevent, "\\");
535 list_prevent = g_list_append (list_prevent, "/");
536 list_prevent = g_list_append (list_prevent, ":");
537 list_prevent = g_list_append (list_prevent, "*");
538 list_prevent = g_list_append (list_prevent, "?");
539 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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, "|");
544 list_prevent = g_list_append (list_prevent, "^");
545 modest_validating_entry_set_unallowed_characters (
546 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
547 g_list_free (list_prevent);
549 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
550 on_entry_invalid_character, self);
552 /* Set max length as in the UI spec:
553 * The UI spec seems to want us to show a dialog if we hit the maximum. */
554 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
555 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
558 gtk_widget_show (GTK_WIDGET (box));
560 return GTK_WIDGET (box);
564 create_page_user_details (ModestEasysetupWizardDialog *self)
566 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
568 /* Create a size group to be used by all captions.
569 * Note that HildonCaption does not create a default size group if we do not specify one.
570 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
571 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
573 /* The name widgets: (use auto cap) */
574 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
575 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name),
576 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
578 /* Set max length as in the UI spec:
579 * The UI spec seems to want us to show a dialog if we hit the maximum. */
580 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
581 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
583 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
584 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
585 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
586 G_CALLBACK(on_easysetup_changed), self);
587 gtk_widget_show (self->entry_user_name);
588 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
589 gtk_widget_show (caption);
591 /* Prevent the use of some characters in the name,
592 * as required by our UI specification: */
593 GList *list_prevent = NULL;
594 list_prevent = g_list_append (list_prevent, "<");
595 list_prevent = g_list_append (list_prevent, ">");
596 modest_validating_entry_set_unallowed_characters (
597 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
598 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
599 on_entry_invalid_character, self);
600 g_list_free (list_prevent);
602 /* The username widgets: */
603 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
604 /* Auto-capitalization is the default, so let's turn it off: */
605 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
606 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
607 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
608 gtk_widget_show (self->entry_user_username);
609 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
610 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
611 G_CALLBACK(on_easysetup_changed), self);
612 gtk_widget_show (caption);
614 /* Prevent the use of some characters in the username,
615 * as required by our UI specification: */
616 modest_validating_entry_set_unallowed_characters_whitespace (
617 MODEST_VALIDATING_ENTRY (self->entry_user_username));
618 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_username),
619 on_entry_invalid_character, self);
621 /* Set max length as in the UI spec:
622 * The UI spec seems to want us to show a dialog if we hit the maximum. */
623 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
624 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
627 /* The password widgets: */
628 self->entry_user_password = gtk_entry_new ();
629 /* Auto-capitalization is the default, so let's turn it off: */
630 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
631 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
632 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
633 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
634 caption = create_caption_new_with_asterisk (self, sizegroup,
635 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
636 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
637 G_CALLBACK(on_easysetup_changed), self);
638 gtk_widget_show (self->entry_user_password);
639 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
640 gtk_widget_show (caption);
642 /* The email address widgets: */
643 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
644 /* Auto-capitalization is the default, so let's turn it off: */
645 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
646 caption = create_caption_new_with_asterisk (self, sizegroup,
647 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
648 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
649 gtk_widget_show (self->entry_user_email);
650 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
651 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
652 G_CALLBACK(on_easysetup_changed), self);
653 gtk_widget_show (caption);
655 /* Set max length as in the UI spec:
656 * The UI spec seems to want us to show a dialog if we hit the maximum. */
657 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
658 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
662 gtk_widget_show (GTK_WIDGET (box));
664 return GTK_WIDGET (box);
667 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
669 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
671 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
672 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
673 gtk_widget_set_size_request (label, 600, -1);
674 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
675 /* The documentation for gtk_label_set_line_wrap() says that we must
676 * call gtk_widget_set_size_request() with a hard-coded width,
677 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
678 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
679 gtk_widget_show (label);
681 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
682 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
683 gtk_widget_set_size_request (label, 600, -1);
685 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
686 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
687 gtk_widget_show (label);
689 gtk_widget_show (GTK_WIDGET (box));
690 return GTK_WIDGET (box);
693 /** Change the caption title for the incoming server,
694 * as specified in the UI spec:
696 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
698 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
699 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
701 (protocol == MODEST_PROTOCOL_STORE_POP ?
702 _("mail_fi_emailtype_pop3") :
703 _("mail_fi_emailtype_imap") );
706 /* Note that this produces a compiler warning,
707 * because the compiler does not know that the translated string will have a %s in it.
708 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
709 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
710 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
711 g_free(incomingserver_title);
714 /** Change the caption title for the incoming server,
715 * as specified in the UI spec:
717 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
719 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
720 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
722 /* Fill the combo with appropriately titled choices for POP or IMAP. */
723 /* The choices are the same, but the titles are different, as in the UI spec. */
724 modest_serversecurity_combo_box_fill (
725 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
728 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
730 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
731 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
735 update_incoming_server_title (self);
736 update_incoming_server_security_choices (self);
738 set_default_custom_servernames (self);
741 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
743 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
744 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
746 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
749 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
751 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
752 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
754 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
756 GTK_POLICY_AUTOMATIC);
758 /* Show note that account type cannot be changed in future: */
759 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
760 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
761 gtk_widget_set_size_request (label, 600, -1);
762 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
763 gtk_widget_show (label);
765 /* Create a size group to be used by all captions.
766 * Note that HildonCaption does not create a default size group if we do not specify one.
767 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
768 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
770 /* The incoming server widgets: */
771 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
772 easysetup_servertype_combo_box_set_active_servertype (
773 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
774 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
775 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
776 gtk_widget_show (self->combo_incoming_servertype);
777 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
778 gtk_widget_show (caption);
780 self->entry_incomingserver = gtk_entry_new ();
781 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
782 /* Auto-capitalization is the default, so let's turn it off: */
783 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
784 set_default_custom_servernames (self);
786 /* The caption title will be updated in update_incoming_server_title().
787 * so this default text will never be seen: */
788 /* (Note: Changing the title seems pointless. murrayc) */
789 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
790 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
791 update_incoming_server_title (self);
792 gtk_widget_show (self->entry_incomingserver);
793 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
794 gtk_widget_show (self->caption_incoming);
796 /* Change the caption title when the servertype changes,
797 * as in the UI spec: */
798 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
799 G_CALLBACK (on_combo_servertype_changed), self);
801 /* Remember when the servername was changed manually: */
802 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
803 G_CALLBACK (on_entry_incoming_servername_changed), self);
805 /* The secure connection widgets: */
806 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
807 update_incoming_server_security_choices (self);
808 modest_serversecurity_combo_box_set_active_serversecurity (
809 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
810 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
811 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
812 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
813 G_CALLBACK (on_easysetup_changed), self);
814 gtk_widget_show (self->combo_incoming_security);
815 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
816 gtk_widget_show (caption);
818 self->checkbox_incoming_auth = gtk_check_button_new ();
819 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
820 G_CALLBACK (on_easysetup_changed), self);
821 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
822 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
824 gtk_widget_show (self->checkbox_incoming_auth);
825 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
826 gtk_widget_show (caption);
828 gtk_widget_show (GTK_WIDGET (box));
830 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
831 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
832 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
833 gtk_widget_show (scrolled_window);
835 return GTK_WIDGET (scrolled_window);
839 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
841 GtkWidget *widget = GTK_WIDGET (user_data);
843 /* Enable the widget only if the toggle button is active: */
844 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
845 gtk_widget_set_sensitive (widget, enable);
848 /* Make the sensitivity of a widget depend on a toggle button.
851 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
853 g_signal_connect (G_OBJECT (button), "toggled",
854 G_CALLBACK (on_toggle_button_changed), widget);
856 /* Set the starting sensitivity: */
857 on_toggle_button_changed (button, widget);
861 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
863 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
864 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
866 /* We set dirty here because setting it depending on the connection specific dialog
870 /* Create the window, if necessary: */
871 if (!(self->specific_window)) {
872 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
873 modest_connection_specific_smtp_window_fill_with_connections (
874 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager);
877 /* Show the window: */
878 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
879 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
880 gtk_widget_show (self->specific_window);
883 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
885 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
886 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
887 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
890 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
892 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
894 /* Create a size group to be used by all captions.
895 * Note that HildonCaption does not create a default size group if we do not specify one.
896 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
897 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
899 /* The outgoing server widgets: */
900 self->entry_outgoingserver = gtk_entry_new ();
901 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
902 G_CALLBACK (on_easysetup_changed), self);
903 /* Auto-capitalization is the default, so let's turn it off: */
904 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
905 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
906 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
907 gtk_widget_show (self->entry_outgoingserver);
908 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
909 gtk_widget_show (caption);
910 set_default_custom_servernames (self);
912 /* The secure connection widgets: */
913 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
914 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
915 G_CALLBACK (on_easysetup_changed), self);
916 modest_serversecurity_combo_box_fill (
917 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
918 modest_serversecurity_combo_box_set_active_serversecurity (
919 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
920 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
921 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
922 gtk_widget_show (self->combo_outgoing_security);
923 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
924 gtk_widget_show (caption);
926 /* The secure authentication widgets: */
927 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
928 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
929 G_CALLBACK (on_easysetup_changed), self);
930 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
931 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
932 gtk_widget_show (self->combo_outgoing_auth);
933 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
934 gtk_widget_show (caption);
936 GtkWidget *separator = gtk_hseparator_new ();
937 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
938 gtk_widget_show (separator);
940 /* connection-specific checkbox: */
941 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
942 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
944 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
945 G_CALLBACK (on_easysetup_changed), self);
947 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
948 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
949 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
950 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
951 gtk_widget_show (caption);
953 /* Connection-specific SMTP-Severs Edit button: */
954 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
955 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
956 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
957 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
958 gtk_widget_show (self->button_outgoing_smtp_servers);
959 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
960 gtk_widget_show (caption);
962 /* Only enable the button when the checkbox is checked: */
963 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
964 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
966 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
967 G_CALLBACK (on_button_outgoing_smtp_servers), self);
969 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
970 G_CALLBACK (on_entry_outgoing_servername_changed), self);
973 gtk_widget_show (GTK_WIDGET (box));
975 return GTK_WIDGET (box);
979 show_advanced_edit(gpointer user_data)
981 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
982 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
985 /* Show the Account Settings window: */
986 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
987 if (priv->pending_load_settings) {
988 save_to_settings (self);
989 priv->pending_load_settings = FALSE;
991 modest_account_settings_dialog_set_account (dialog, self->settings);
993 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
995 response = gtk_dialog_run (GTK_DIALOG (dialog));
997 gtk_widget_destroy (GTK_WIDGET (dialog));
999 return FALSE; /* Do not call this timeout callback again. */
1003 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1005 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1007 /* Show the Account Settings window: */
1008 show_advanced_edit(self);
1010 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1012 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1013 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1014 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1015 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1016 gtk_widget_set_size_request (label, 600, -1);
1017 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1018 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1019 gtk_widget_show (label);
1021 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1022 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1023 gtk_widget_set_size_request (label, 600, -1);
1024 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1025 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1026 gtk_widget_show (label);
1028 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1029 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1030 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1031 gtk_widget_show (button_edit);
1032 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1033 gtk_widget_show (caption);
1035 g_signal_connect (G_OBJECT (button_edit), "clicked",
1036 G_CALLBACK (on_button_edit_advanced_settings), self);
1038 gtk_widget_show (GTK_WIDGET (box));
1039 return GTK_WIDGET (box);
1046 on_response (ModestWizardDialog *wizard_dialog,
1050 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1052 invoke_enable_buttons_vfunc (self);
1056 on_response_before (ModestWizardDialog *wizard_dialog,
1060 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1061 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1062 if (response_id == GTK_RESPONSE_CANCEL) {
1063 /* This is mostly copied from
1064 * src/maemo/modest-account-settings-dialog.c */
1066 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1067 _("imum_nc_wizard_confirm_lose_changes")));
1068 /* TODO: These button names will be ambiguous, and not
1069 * specified in the UI specification. */
1071 const gint dialog_response = gtk_dialog_run (dialog);
1072 gtk_widget_destroy (GTK_WIDGET (dialog));
1074 if (dialog_response != GTK_RESPONSE_OK) {
1075 /* Don't let the dialog close */
1076 g_signal_stop_emission_by_name (wizard_dialog, "response");
1082 typedef struct IdleData {
1083 ModestEasysetupWizardDialog *dialog;
1084 ModestPresets *presets;
1088 presets_idle (gpointer userdata)
1090 IdleData *idle_data = (IdleData *) userdata;
1091 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1092 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1094 g_assert (idle_data->presets);
1096 gdk_threads_enter ();
1098 priv->presets = idle_data->presets;
1100 if (self->combo_account_country) {
1101 gint mcc = get_default_country_code();
1102 /* Fill the combo in an idle call, as it takes a lot of time */
1103 easysetup_country_combo_box_load_data(
1104 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
1105 easysetup_country_combo_box_set_active_country_mcc (
1106 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc);
1107 easysetup_provider_combo_box_fill (
1108 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider),
1109 priv->presets, mcc);
1112 priv->dirty = FALSE;
1114 g_object_unref (idle_data->dialog);
1117 gdk_threads_leave ();
1123 presets_loader (gpointer userdata)
1125 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1126 ModestPresets *presets = NULL;
1127 IdleData *idle_data;
1129 const gchar* path = NULL;
1130 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1131 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1133 if (access(path1, R_OK) == 0)
1135 else if (access(path2, R_OK) == 0)
1138 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1139 __FUNCTION__, path1, path2);
1143 presets = modest_presets_new (path);
1145 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1149 idle_data = g_new0 (IdleData, 1);
1150 idle_data->dialog = self;
1151 idle_data->presets = presets;
1153 g_idle_add (presets_idle, idle_data);
1159 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1161 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1163 /* Create the notebook to be used by the ModestWizardDialog base class:
1164 * Each page of the notebook will be a page of the wizard: */
1165 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1167 /* Set the notebook used by the ModestWizardDialog base class: */
1168 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1170 /* Set the wizard title:
1171 * The actual window title will be a combination of this and the page's tab label title. */
1172 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1174 /* Read in the information about known service providers: */
1175 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1177 /* The server fields did not have been manually changed yet */
1178 priv->server_changes = 0;
1179 priv->pending_load_settings = TRUE;
1181 /* Get the account manager object,
1182 * so we can check for existing accounts,
1183 * and create new accounts: */
1184 self->account_manager = modest_runtime_get_account_mgr ();
1185 g_assert (self->account_manager);
1186 g_object_ref (self->account_manager);
1188 /* Create the common pages,
1190 self->page_welcome = create_page_welcome (self);
1191 self->page_account_details = create_page_account_details (self);
1192 self->page_user_details = create_page_user_details (self);
1194 /* Add the common pages: */
1195 gtk_notebook_append_page (notebook, self->page_welcome,
1196 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1197 gtk_container_child_set (GTK_CONTAINER (notebook),
1203 gtk_notebook_append_page (notebook, self->page_account_details,
1204 gtk_label_new (_("mcen_ti_accountdetails")));
1205 gtk_container_child_set (GTK_CONTAINER (notebook),
1206 self->page_account_details,
1211 gtk_notebook_append_page (notebook, self->page_user_details,
1212 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1213 gtk_container_child_set (GTK_CONTAINER (notebook),
1214 self->page_user_details,
1219 /* Create and add the easysetup-specific pages,
1220 * because we need _some_ final page to enable the Next and Finish buttons: */
1221 create_subsequent_easysetup_pages (self);
1223 /* Connect to the dialog's response signal so we can enable/disable buttons
1224 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1225 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1226 * so that we can be enable/disable after ModestWizardDialog has done its own
1227 * enabling/disabling of buttons.
1229 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1230 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1232 * It's not enough to connect to the notebook's switch-page signal, because
1233 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1234 * _after_ switching the page (understandably).
1235 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1236 * then gtk_notebook_get_current_page() would return an incorrect value.)
1238 g_signal_connect_after (G_OBJECT (self), "response",
1239 G_CALLBACK (on_response), self);
1241 /* This is to show a confirmation dialog when the user hits cancel */
1242 g_signal_connect (G_OBJECT (self), "response",
1243 G_CALLBACK (on_response_before), self);
1245 g_signal_connect (G_OBJECT (self), "delete-event",
1246 G_CALLBACK (on_delete_event), self);
1248 /* Reset dirty, because there was no user input until now */
1249 priv->dirty = FALSE;
1251 /* When this window is shown, hibernation should not be possible,
1252 * because there is no sensible way to save the state: */
1253 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1254 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1256 /* Load provider presets */
1257 g_object_ref (self);
1258 g_thread_create (presets_loader, self, FALSE, NULL);
1260 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1261 modest_maemo_utils_get_osso_context());
1263 self->settings = modest_account_settings_new ();
1266 ModestEasysetupWizardDialog*
1267 modest_easysetup_wizard_dialog_new (void)
1270 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1273 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1275 GtkNotebook *notebook = NULL;
1276 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1279 /* Create the custom pages: */
1280 if(!(self->page_custom_incoming)) {
1281 self->page_custom_incoming = create_page_custom_incoming (self);
1284 if(!(self->page_custom_outgoing)) {
1285 self->page_custom_outgoing = create_page_custom_outgoing (self);
1288 if(!(self->page_complete_customsetup)) {
1289 self->page_complete_customsetup = create_page_complete_custom (self);
1292 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1293 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1294 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1296 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1297 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1298 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1300 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup))) {
1301 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1302 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1303 gtk_container_child_set (GTK_CONTAINER (notebook),
1304 self->page_complete_customsetup,
1310 /* This is unnecessary with GTK+ 2.10: */
1311 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1314 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1316 GtkNotebook *notebook = NULL;
1317 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1320 /* Create the easysetup-specific pages: */
1321 if(!self->page_complete_easysetup)
1322 self->page_complete_easysetup = create_page_complete_easysetup (self);
1324 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup))) {
1325 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1326 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1327 gtk_container_child_set (GTK_CONTAINER (notebook),
1328 self->page_complete_easysetup,
1334 /* This is unnecessary with GTK+ 2.10: */
1335 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1337 /* After the user details page,
1338 * the following pages depend on whether "Other" was chosen
1339 * in the provider combobox on the account page
1341 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1343 if (easysetup_provider_combo_box_get_active_provider_id (
1344 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1345 /* "Other..." was selected: */
1347 /* Make sure that the easysetup pages do not exist: */
1348 if(self->page_complete_easysetup) {
1349 gtk_widget_destroy (self->page_complete_easysetup);
1350 self->page_complete_easysetup = NULL;
1353 create_subsequent_customsetup_pages (self);
1356 /* A specific provider was selected: */
1358 /* Make sure that the custom pages do not exist:
1359 * Because they will be used if they exist, when creating the account. */
1360 if(self->page_custom_incoming) {
1361 gtk_widget_destroy (self->page_custom_incoming);
1362 self->page_custom_incoming = NULL;
1363 self->combo_incoming_servertype = NULL;
1364 self->caption_incoming = NULL;
1365 self->entry_incomingserver = NULL;
1366 self->combo_incoming_security = NULL;
1367 self->checkbox_incoming_auth = NULL;
1370 if(self->page_custom_outgoing) {
1371 gtk_widget_destroy (self->page_custom_outgoing);
1372 self->page_custom_outgoing = NULL;
1373 self->entry_outgoingserver = NULL;
1374 self->combo_outgoing_security = NULL;
1375 self->combo_outgoing_auth = NULL;
1376 self->checkbox_outgoing_smtp_specific = NULL;
1377 self->button_outgoing_smtp_servers = NULL;
1380 if(self->page_complete_customsetup) {
1381 gtk_widget_destroy (self->page_complete_customsetup);
1382 self->page_complete_customsetup = NULL;
1386 /* Create the easysetup pages: */
1387 create_subsequent_easysetup_pages (self);
1393 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1398 gchar* at = g_utf8_strchr (email_address, -1, '@');
1399 if (!at || (g_utf8_strlen (at, -1) < 2))
1402 gchar* domain = g_utf8_next_char (at);
1406 const gchar* hostname = NULL;
1407 if (servertype == MODEST_PROTOCOL_STORE_POP)
1409 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1411 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1417 return g_strdup_printf ("%s.%s", hostname, domain);
1420 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1422 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1424 if (!account_wizard->entry_incomingserver)
1427 /* Set a default domain for the server, based on the email address,
1428 * if no server name was already specified.
1430 if (account_wizard->entry_user_email
1431 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1432 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1433 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1434 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1436 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1438 /* Do not set the INCOMING_CHANGED flag because of this edit */
1439 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1440 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1441 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1443 g_free (servername);
1446 /* Set a default domain for the server, based on the email address,
1447 * if no server name was already specified.
1449 if (!account_wizard->entry_outgoingserver)
1452 if (account_wizard->entry_user_email
1453 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1454 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1456 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1458 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1459 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1460 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1461 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1463 g_free (servername);
1468 get_entered_account_title (ModestEasysetupWizardDialog *account_wizard)
1470 const gchar* account_title =
1471 gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1472 if (!account_title || (strlen (account_title) == 0))
1475 /* Strip it of whitespace at the start and end: */
1476 gchar *result = g_strdup (account_title);
1477 result = g_strstrip (result);
1482 if (strlen (result) == 0) {
1492 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1494 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1495 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (account_wizard);
1497 /* if are browsing pages previous to the last one, then we have pending settings in
1499 if (next_page != NULL)
1500 priv->pending_load_settings = TRUE;
1502 /* Do extra validation that couldn't be done for every key press,
1503 * either because it was too slow,
1504 * or because it requires interaction:
1506 if (current_page == account_wizard->page_account_details) {
1507 /* Check that the title is not already in use: */
1508 gchar* account_title = get_entered_account_title (account_wizard);
1512 /* Aavoid a clash with an existing display name: */
1513 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1514 account_wizard->account_manager, account_title);
1517 /* Warn the user via a dialog: */
1518 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1523 else if (current_page == account_wizard->page_user_details) {
1524 /* Check that the email address is valud: */
1525 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1526 if ((!email_address) || (strlen(email_address) == 0))
1529 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1530 /* Warn the user via a dialog: */
1531 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1533 /* Return focus to the email address entry: */
1534 gtk_widget_grab_focus (account_wizard->entry_user_email);
1535 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1540 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1541 create_subsequent_pages (account_wizard);
1544 /* TODO: The UI Spec wants us to check that the servernames are valid,
1545 * but does not specify how.
1548 if(next_page == account_wizard->page_custom_incoming) {
1549 set_default_custom_servernames (account_wizard);
1551 else if (next_page == account_wizard->page_custom_outgoing) {
1552 set_default_custom_servernames (account_wizard);
1554 /* Check if the server supports secure authentication */
1555 const ModestConnectionProtocol security_incoming =
1556 modest_serversecurity_combo_box_get_active_serversecurity (
1557 MODEST_SERVERSECURITY_COMBO_BOX (account_wizard->combo_incoming_security));
1558 if (gtk_toggle_button_get_active (
1559 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1560 && !modest_protocol_info_is_secure(security_incoming))
1562 if (!check_has_supported_auth_methods (account_wizard))
1567 /* If this is the last page, and this is a click on Finish,
1568 * then attempt to create the dialog.
1570 if(!next_page) /* This is NULL when this is a click on Finish. */
1572 if (priv->pending_load_settings) {
1573 save_to_settings (account_wizard);
1575 modest_account_mgr_add_account_from_settings (account_wizard->account_manager, account_wizard->settings);
1582 static gboolean entry_is_empty (GtkWidget *entry)
1587 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1588 if ((!text) || (strlen(text) == 0))
1591 /* Strip it of whitespace at the start and end: */
1592 gchar *stripped = g_strdup (text);
1593 stripped = g_strstrip (stripped);
1598 const gboolean result = (strlen (stripped) == 0);
1606 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1608 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1610 gboolean enable_next = TRUE;
1611 if (current_page == account_wizard->page_welcome) {
1614 else if (current_page == account_wizard->page_account_details) {
1615 /* The account details title is mandatory: */
1616 if (entry_is_empty(account_wizard->entry_account_title))
1617 enable_next = FALSE;
1619 else if (current_page == account_wizard->page_user_details) {
1620 /* The user details username is mandatory: */
1621 if (entry_is_empty(account_wizard->entry_user_username))
1622 enable_next = FALSE;
1624 /* The user details email address is mandatory: */
1625 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1626 enable_next = FALSE;
1628 else if (current_page == account_wizard->page_custom_incoming) {
1629 /* The custom incoming server is mandatory: */
1630 if (entry_is_empty(account_wizard->entry_incomingserver))
1631 enable_next = FALSE;
1634 /* Enable the buttons,
1635 * identifying them via their associated response codes: */
1637 /* Disable the Finish button until we are on the last page,
1638 * because HildonWizardDialog enables this for all but the first page: */
1639 GtkNotebook *notebook = NULL;
1640 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1641 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1643 gint current = gtk_notebook_get_current_page (notebook);
1644 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1645 const gboolean is_last = (current == last);
1648 gtk_dialog_set_response_sensitive (dialog_base,
1649 MODEST_WIZARD_DIALOG_FINISH,
1653 /* Disable Next on the last page: */
1654 enable_next = FALSE;
1657 gtk_dialog_set_response_sensitive (dialog_base,
1658 MODEST_WIZARD_DIALOG_NEXT,
1663 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1665 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1666 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1669 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1670 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1671 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1672 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1674 /* Provide a vfunc implementation so we can decide
1675 * when to enable/disable the prev/next buttons.
1677 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1678 base_klass->before_next = on_before_next;
1679 base_klass->enable_buttons = on_enable_buttons;
1683 show_error (GtkWidget *parent_widget, const gchar* text)
1685 //TODO: Apparently this doesn't show anything in Maemo Bora:
1686 hildon_banner_show_information(parent_widget, NULL, text);
1692 * @self: a #ModestEasysetupWizardDialog
1694 * takes information from all the wizard and stores it in settings
1697 save_to_settings (ModestEasysetupWizardDialog *self)
1699 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1702 gchar* display_name;
1703 const gchar *username, *password;
1704 gchar *store_hostname, *transport_hostname;
1705 guint store_port, transport_port;
1706 ModestTransportStoreProtocol store_protocol, transport_protocol;
1707 ModestConnectionProtocol store_security, transport_security;
1708 ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
1709 ModestServerAccountSettings *store_settings, *transport_settings;
1710 const gchar *fullname, *email_address;
1712 /* Get details from the specified presets: */
1713 provider_id = easysetup_provider_combo_box_get_active_provider_id (
1714 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1716 /* username and password (for both incoming and outgoing): */
1717 username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1718 password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1720 /* Incoming server: */
1721 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1722 * or modest_account_mgr_add_server_account will fail. */
1724 store_protocol = MODEST_PROTOCOL_STORE_POP;
1725 store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1726 store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1729 ModestPresetsServerType store_provider_server_type;
1730 ModestPresetsSecurity store_provider_security;
1732 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1735 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1738 store_provider_security = modest_presets_get_info_server_security (priv->presets,
1742 /* We don't check for SMTP here as that is impossible for an incoming server. */
1743 if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
1744 store_protocol = MODEST_PROTOCOL_STORE_IMAP;
1745 else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
1746 store_protocol = MODEST_PROTOCOL_STORE_POP;
1748 store_protocol = MODEST_PROTOCOL_STORE_POP;
1750 /* we check if there is a *special* port */
1751 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1752 if (special_port != 0)
1753 store_port = special_port;
1755 store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
1757 if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1758 store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1760 if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
1761 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1763 /* Use custom pages because no preset was specified: */
1764 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1765 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1766 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1767 store_security = modest_serversecurity_combo_box_get_active_serversecurity (
1768 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1770 /* The UI spec says:
1771 * If secure authentication is unchecked, allow sending username and password also as plain text.
1772 * If secure authentication is checked, require one of the secure methods during
1773 * connection: SSL, TLS, CRAM-MD5 etc. */
1774 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1775 !modest_protocol_info_is_secure(store_security)) {
1776 store_auth_protocol = check_first_supported_auth_method (self);
1778 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1782 /* now we store the store account settings */
1783 store_settings = modest_account_settings_get_store_settings (self->settings);
1784 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1785 modest_server_account_settings_set_username (store_settings, username);
1786 modest_server_account_settings_set_password (store_settings, password);
1787 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1788 modest_server_account_settings_set_security (store_settings, store_security);
1789 modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1790 if (store_port != 0)
1791 modest_server_account_settings_set_port (store_settings, store_port);
1793 g_object_unref (store_settings);
1794 g_free (store_hostname);
1796 /* Outgoing server: */
1797 transport_hostname = NULL;
1798 transport_protocol = MODEST_PROTOCOL_STORE_POP;
1799 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1800 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1804 ModestPresetsServerType transport_provider_server_type;
1805 ModestPresetsSecurity transport_provider_security;
1808 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1809 FALSE /* transport */);
1811 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1813 FALSE /* transport */);
1814 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1816 FALSE /* transport */);
1818 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1819 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1820 if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
1821 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
1823 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1824 if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1825 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1826 transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1827 /* we check if there is a *special* port */
1828 special_port = modest_presets_get_port (priv->presets, provider_id,
1829 FALSE /* transport */);
1830 if (special_port != 0)
1831 transport_port = special_port;
1833 transport_port = 465;
1834 transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1836 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1837 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1840 /* Use custom pages because no preset was specified: */
1841 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1842 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1843 transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
1844 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1845 transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
1846 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1849 /* now we transport the transport account settings */
1850 transport_settings = modest_account_settings_get_transport_settings (self->settings);
1851 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1852 modest_server_account_settings_set_username (transport_settings, username);
1853 modest_server_account_settings_set_password (transport_settings, password);
1854 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1855 modest_server_account_settings_set_security (transport_settings, transport_security);
1856 modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1857 if (transport_port != 0)
1858 modest_server_account_settings_set_port (transport_settings, transport_port);
1860 g_object_unref (transport_settings);
1861 g_free (transport_hostname);
1863 fullname = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1864 email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1865 modest_account_settings_set_fullname (self->settings, fullname);
1866 modest_account_settings_set_email_address (self->settings, email_address);
1867 /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1868 are set to headers only */
1870 /* Save the connection-specific SMTP server accounts. */
1871 modest_account_settings_set_use_connection_specific_smtp
1873 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->checkbox_outgoing_smtp_specific)));
1875 display_name = get_entered_account_title (self);
1876 modest_account_settings_set_display_name (self->settings, display_name);
1877 g_free (display_name);
1879 if (self->specific_window)
1880 modest_connection_specific_smtp_window_save_server_accounts (
1881 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window));