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 create_page_account_details (ModestEasysetupWizardDialog *self)
425 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
426 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
427 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
428 gtk_widget_set_size_request (label, 600, -1);
429 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
430 gtk_widget_show (label);
432 /* Create a size group to be used by all captions.
433 * Note that HildonCaption does not create a default size group if we do not specify one.
434 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
435 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
437 /* The country widgets: */
438 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
439 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
440 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
441 gtk_widget_show (self->combo_account_country);
442 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
443 gtk_widget_show (caption);
445 /* connect to country combo's changed signal, so we can fill the provider combo: */
446 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
447 G_CALLBACK (on_combo_account_country), self);
449 GtkWidget *separator = gtk_hseparator_new ();
450 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
451 gtk_widget_show (separator);
453 /* The service provider widgets: */
454 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
455 gtk_widget_set_size_request (self->combo_account_serviceprovider, 320, -1);
457 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
458 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
459 gtk_widget_show (self->combo_account_serviceprovider);
460 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
461 gtk_widget_show (caption);
463 /* connect to providers combo's changed signal, so we can fill the email address: */
464 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
465 G_CALLBACK (on_combo_account_serviceprovider), self);
467 /* TODO: Default to the current country somehow.
468 * But I don't know how to get the information that is specified in the
469 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
471 * This is probably not the best choice of gconf key:
472 * This is the "mcc used in the last pairing", ie. the last connection you made.
473 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
476 GError *error = NULL;
477 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
478 gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
484 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
485 g_error_free (error);
491 /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
492 * This might just be a Maemo bug.
496 /* For now, we default to Finland when there is nothing better: */
500 easysetup_country_combo_box_set_active_country_mcc (
501 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
504 /* The description widgets: */
505 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
506 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
507 G_CALLBACK(on_easysetup_changed), self);
508 /* Do use auto-capitalization: */
509 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
510 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
512 /* Set a default account title, choosing one that does not already exist: */
513 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
514 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
515 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
516 self->account_manager, default_account_name_start);
517 g_free (default_account_name_start);
518 default_account_name_start = NULL;
520 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
521 g_free (default_account_name);
522 default_account_name = NULL;
524 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
525 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
526 gtk_widget_show (self->entry_account_title);
527 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
528 gtk_widget_show (caption);
530 /* Prevent the use of some characters in the account title,
531 * as required by our UI specification: */
532 GList *list_prevent = NULL;
533 list_prevent = g_list_append (list_prevent, "\\");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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, "^");
544 modest_validating_entry_set_unallowed_characters (
545 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
546 g_list_free (list_prevent);
548 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
549 on_entry_invalid_character, self);
551 /* Set max length as in the UI spec:
552 * The UI spec seems to want us to show a dialog if we hit the maximum. */
553 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
554 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
557 gtk_widget_show (GTK_WIDGET (box));
559 return GTK_WIDGET (box);
563 create_page_user_details (ModestEasysetupWizardDialog *self)
565 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
567 /* Create a size group to be used by all captions.
568 * Note that HildonCaption does not create a default size group if we do not specify one.
569 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
570 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
572 /* The name widgets: (use auto cap) */
573 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
574 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name),
575 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
577 /* Set max length as in the UI spec:
578 * The UI spec seems to want us to show a dialog if we hit the maximum. */
579 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
580 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
582 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
583 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
584 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
585 G_CALLBACK(on_easysetup_changed), self);
586 gtk_widget_show (self->entry_user_name);
587 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
588 gtk_widget_show (caption);
590 /* Prevent the use of some characters in the name,
591 * as required by our UI specification: */
592 GList *list_prevent = NULL;
593 list_prevent = g_list_append (list_prevent, "<");
594 list_prevent = g_list_append (list_prevent, ">");
595 modest_validating_entry_set_unallowed_characters (
596 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
597 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
598 on_entry_invalid_character, self);
599 g_list_free (list_prevent);
601 /* The username widgets: */
602 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
603 /* Auto-capitalization is the default, so let's turn it off: */
604 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
605 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
606 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
607 gtk_widget_show (self->entry_user_username);
608 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
609 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
610 G_CALLBACK(on_easysetup_changed), self);
611 gtk_widget_show (caption);
613 /* Prevent the use of some characters in the username,
614 * as required by our UI specification: */
615 modest_validating_entry_set_unallowed_characters_whitespace (
616 MODEST_VALIDATING_ENTRY (self->entry_user_username));
617 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_username),
618 on_entry_invalid_character, self);
620 /* Set max length as in the UI spec:
621 * The UI spec seems to want us to show a dialog if we hit the maximum. */
622 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
623 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
626 /* The password widgets: */
627 self->entry_user_password = gtk_entry_new ();
628 /* Auto-capitalization is the default, so let's turn it off: */
629 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
630 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
631 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
632 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
633 caption = create_caption_new_with_asterisk (self, sizegroup,
634 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
635 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
636 G_CALLBACK(on_easysetup_changed), self);
637 gtk_widget_show (self->entry_user_password);
638 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
639 gtk_widget_show (caption);
641 /* The email address widgets: */
642 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
643 /* Auto-capitalization is the default, so let's turn it off: */
644 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
645 caption = create_caption_new_with_asterisk (self, sizegroup,
646 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
647 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
648 gtk_widget_show (self->entry_user_email);
649 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
650 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
651 G_CALLBACK(on_easysetup_changed), self);
652 gtk_widget_show (caption);
654 /* Set max length as in the UI spec:
655 * The UI spec seems to want us to show a dialog if we hit the maximum. */
656 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
657 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
661 gtk_widget_show (GTK_WIDGET (box));
663 return GTK_WIDGET (box);
666 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
668 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
670 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
671 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
672 gtk_widget_set_size_request (label, 600, -1);
673 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
674 /* The documentation for gtk_label_set_line_wrap() says that we must
675 * call gtk_widget_set_size_request() with a hard-coded width,
676 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
677 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
678 gtk_widget_show (label);
680 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
681 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
682 gtk_widget_set_size_request (label, 600, -1);
684 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
685 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
686 gtk_widget_show (label);
688 gtk_widget_show (GTK_WIDGET (box));
689 return GTK_WIDGET (box);
692 /** Change the caption title for the incoming server,
693 * as specified in the UI spec:
695 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
697 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
698 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
700 (protocol == MODEST_PROTOCOL_STORE_POP ?
701 _("mail_fi_emailtype_pop3") :
702 _("mail_fi_emailtype_imap") );
705 /* Note that this produces a compiler warning,
706 * because the compiler does not know that the translated string will have a %s in it.
707 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
708 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
709 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
710 g_free(incomingserver_title);
713 /** Change the caption title for the incoming server,
714 * as specified in the UI spec:
716 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
718 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
719 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
721 /* Fill the combo with appropriately titled choices for POP or IMAP. */
722 /* The choices are the same, but the titles are different, as in the UI spec. */
723 modest_serversecurity_combo_box_fill (
724 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
727 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
729 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
730 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
734 update_incoming_server_title (self);
735 update_incoming_server_security_choices (self);
737 set_default_custom_servernames (self);
740 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
742 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
743 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
745 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
748 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
750 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
751 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
753 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
755 GTK_POLICY_AUTOMATIC);
757 /* Show note that account type cannot be changed in future: */
758 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
759 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
760 gtk_widget_set_size_request (label, 600, -1);
761 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
762 gtk_widget_show (label);
764 /* Create a size group to be used by all captions.
765 * Note that HildonCaption does not create a default size group if we do not specify one.
766 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
767 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
769 /* The incoming server widgets: */
770 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
771 easysetup_servertype_combo_box_set_active_servertype (
772 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
773 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
774 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
775 gtk_widget_show (self->combo_incoming_servertype);
776 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
777 gtk_widget_show (caption);
779 self->entry_incomingserver = gtk_entry_new ();
780 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
781 /* Auto-capitalization is the default, so let's turn it off: */
782 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
783 set_default_custom_servernames (self);
785 /* The caption title will be updated in update_incoming_server_title().
786 * so this default text will never be seen: */
787 /* (Note: Changing the title seems pointless. murrayc) */
788 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
789 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
790 update_incoming_server_title (self);
791 gtk_widget_show (self->entry_incomingserver);
792 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
793 gtk_widget_show (self->caption_incoming);
795 /* Change the caption title when the servertype changes,
796 * as in the UI spec: */
797 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
798 G_CALLBACK (on_combo_servertype_changed), self);
800 /* Remember when the servername was changed manually: */
801 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
802 G_CALLBACK (on_entry_incoming_servername_changed), self);
804 /* The secure connection widgets: */
805 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
806 update_incoming_server_security_choices (self);
807 modest_serversecurity_combo_box_set_active_serversecurity (
808 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
809 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
810 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
811 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
812 G_CALLBACK (on_easysetup_changed), self);
813 gtk_widget_show (self->combo_incoming_security);
814 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
815 gtk_widget_show (caption);
817 self->checkbox_incoming_auth = gtk_check_button_new ();
818 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
819 G_CALLBACK (on_easysetup_changed), self);
820 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
821 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
823 gtk_widget_show (self->checkbox_incoming_auth);
824 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
825 gtk_widget_show (caption);
827 gtk_widget_show (GTK_WIDGET (box));
829 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
830 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
831 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
832 gtk_widget_show (scrolled_window);
834 return GTK_WIDGET (scrolled_window);
838 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
840 GtkWidget *widget = GTK_WIDGET (user_data);
842 /* Enable the widget only if the toggle button is active: */
843 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
844 gtk_widget_set_sensitive (widget, enable);
847 /* Make the sensitivity of a widget depend on a toggle button.
850 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
852 g_signal_connect (G_OBJECT (button), "toggled",
853 G_CALLBACK (on_toggle_button_changed), widget);
855 /* Set the starting sensitivity: */
856 on_toggle_button_changed (button, widget);
860 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
862 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
863 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
865 /* We set dirty here because setting it depending on the connection specific dialog
869 /* Create the window, if necessary: */
870 if (!(self->specific_window)) {
871 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
872 modest_connection_specific_smtp_window_fill_with_connections (
873 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager);
876 /* Show the window: */
877 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
878 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
879 gtk_widget_show (self->specific_window);
882 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
884 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
885 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
886 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
889 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
891 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
893 /* Create a size group to be used by all captions.
894 * Note that HildonCaption does not create a default size group if we do not specify one.
895 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
896 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
898 /* The outgoing server widgets: */
899 self->entry_outgoingserver = gtk_entry_new ();
900 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
901 G_CALLBACK (on_easysetup_changed), self);
902 /* Auto-capitalization is the default, so let's turn it off: */
903 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
904 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
905 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
906 gtk_widget_show (self->entry_outgoingserver);
907 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
908 gtk_widget_show (caption);
909 set_default_custom_servernames (self);
911 /* The secure connection widgets: */
912 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
913 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
914 G_CALLBACK (on_easysetup_changed), self);
915 modest_serversecurity_combo_box_fill (
916 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
917 modest_serversecurity_combo_box_set_active_serversecurity (
918 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
919 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
920 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
921 gtk_widget_show (self->combo_outgoing_security);
922 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
923 gtk_widget_show (caption);
925 /* The secure authentication widgets: */
926 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
927 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
928 G_CALLBACK (on_easysetup_changed), self);
929 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
930 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
931 gtk_widget_show (self->combo_outgoing_auth);
932 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
933 gtk_widget_show (caption);
935 GtkWidget *separator = gtk_hseparator_new ();
936 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
937 gtk_widget_show (separator);
939 /* connection-specific checkbox: */
940 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
941 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
943 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
944 G_CALLBACK (on_easysetup_changed), self);
946 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
947 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
948 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
949 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
950 gtk_widget_show (caption);
952 /* Connection-specific SMTP-Severs Edit button: */
953 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
954 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
955 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
956 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
957 gtk_widget_show (self->button_outgoing_smtp_servers);
958 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
959 gtk_widget_show (caption);
961 /* Only enable the button when the checkbox is checked: */
962 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
963 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
965 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
966 G_CALLBACK (on_button_outgoing_smtp_servers), self);
968 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
969 G_CALLBACK (on_entry_outgoing_servername_changed), self);
972 gtk_widget_show (GTK_WIDGET (box));
974 return GTK_WIDGET (box);
978 show_advanced_edit(gpointer user_data)
980 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
981 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
984 /* Show the Account Settings window: */
985 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
986 if (priv->pending_load_settings) {
987 save_to_settings (self);
988 priv->pending_load_settings = FALSE;
990 modest_account_settings_dialog_set_account (dialog, self->settings);
992 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
994 response = gtk_dialog_run (GTK_DIALOG (dialog));
996 gtk_widget_destroy (GTK_WIDGET (dialog));
998 return FALSE; /* Do not call this timeout callback again. */
1002 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1004 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1006 /* Show the Account Settings window: */
1007 show_advanced_edit(self);
1009 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1011 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1012 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1013 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1014 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1015 gtk_widget_set_size_request (label, 600, -1);
1016 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1017 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1018 gtk_widget_show (label);
1020 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1021 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1022 gtk_widget_set_size_request (label, 600, -1);
1023 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1024 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1025 gtk_widget_show (label);
1027 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1028 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1029 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1030 gtk_widget_show (button_edit);
1031 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1032 gtk_widget_show (caption);
1034 g_signal_connect (G_OBJECT (button_edit), "clicked",
1035 G_CALLBACK (on_button_edit_advanced_settings), self);
1037 gtk_widget_show (GTK_WIDGET (box));
1038 return GTK_WIDGET (box);
1045 on_response (ModestWizardDialog *wizard_dialog,
1049 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1051 invoke_enable_buttons_vfunc (self);
1055 on_response_before (ModestWizardDialog *wizard_dialog,
1059 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1060 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1061 if (response_id == GTK_RESPONSE_CANCEL) {
1062 /* This is mostly copied from
1063 * src/maemo/modest-account-settings-dialog.c */
1065 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1066 _("imum_nc_wizard_confirm_lose_changes")));
1067 /* TODO: These button names will be ambiguous, and not
1068 * specified in the UI specification. */
1070 const gint dialog_response = gtk_dialog_run (dialog);
1071 gtk_widget_destroy (GTK_WIDGET (dialog));
1073 if (dialog_response != GTK_RESPONSE_OK) {
1074 /* Don't let the dialog close */
1075 g_signal_stop_emission_by_name (wizard_dialog, "response");
1081 typedef struct IdleData {
1082 ModestEasysetupWizardDialog *dialog;
1083 ModestPresets *presets;
1087 presets_idle (gpointer userdata)
1089 IdleData *idle_data = (IdleData *) userdata;
1090 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1091 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1093 g_assert (idle_data->presets);
1095 gdk_threads_enter ();
1097 priv->presets = idle_data->presets;
1099 if (self->combo_account_country) {
1100 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
1101 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
1102 easysetup_provider_combo_box_fill (
1103 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider),
1104 priv->presets, mcc);
1107 priv->dirty = FALSE;
1109 g_object_unref (idle_data->dialog);
1112 gdk_threads_leave ();
1118 presets_loader (gpointer userdata)
1120 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1121 ModestPresets *presets = NULL;
1122 IdleData *idle_data;
1124 const gchar* path = NULL;
1125 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1126 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1128 if (access(path1, R_OK) == 0)
1130 else if (access(path2, R_OK) == 0)
1133 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1134 __FUNCTION__, path1, path2);
1138 presets = modest_presets_new (path);
1140 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1144 idle_data = g_new0 (IdleData, 1);
1145 idle_data->dialog = self;
1146 idle_data->presets = presets;
1148 g_idle_add (presets_idle, idle_data);
1154 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1156 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1158 /* Create the notebook to be used by the ModestWizardDialog base class:
1159 * Each page of the notebook will be a page of the wizard: */
1160 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1162 /* Set the notebook used by the ModestWizardDialog base class: */
1163 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1165 /* Set the wizard title:
1166 * The actual window title will be a combination of this and the page's tab label title. */
1167 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1169 /* Read in the information about known service providers: */
1170 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1172 /* The server fields did not have been manually changed yet */
1173 priv->server_changes = 0;
1174 priv->pending_load_settings = TRUE;
1176 /* Get the account manager object,
1177 * so we can check for existing accounts,
1178 * and create new accounts: */
1179 self->account_manager = modest_runtime_get_account_mgr ();
1180 g_assert (self->account_manager);
1181 g_object_ref (self->account_manager);
1183 /* Create the common pages,
1185 self->page_welcome = create_page_welcome (self);
1186 self->page_account_details = create_page_account_details (self);
1187 self->page_user_details = create_page_user_details (self);
1189 /* Add the common pages: */
1190 gtk_notebook_append_page (notebook, self->page_welcome,
1191 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1192 gtk_container_child_set (GTK_CONTAINER (notebook),
1198 gtk_notebook_append_page (notebook, self->page_account_details,
1199 gtk_label_new (_("mcen_ti_accountdetails")));
1200 gtk_container_child_set (GTK_CONTAINER (notebook),
1201 self->page_account_details,
1206 gtk_notebook_append_page (notebook, self->page_user_details,
1207 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1208 gtk_container_child_set (GTK_CONTAINER (notebook),
1209 self->page_user_details,
1214 /* Create and add the easysetup-specific pages,
1215 * because we need _some_ final page to enable the Next and Finish buttons: */
1216 create_subsequent_easysetup_pages (self);
1218 /* Connect to the dialog's response signal so we can enable/disable buttons
1219 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1220 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1221 * so that we can be enable/disable after ModestWizardDialog has done its own
1222 * enabling/disabling of buttons.
1224 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1225 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1227 * It's not enough to connect to the notebook's switch-page signal, because
1228 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1229 * _after_ switching the page (understandably).
1230 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1231 * then gtk_notebook_get_current_page() would return an incorrect value.)
1233 g_signal_connect_after (G_OBJECT (self), "response",
1234 G_CALLBACK (on_response), self);
1236 /* This is to show a confirmation dialog when the user hits cancel */
1237 g_signal_connect (G_OBJECT (self), "response",
1238 G_CALLBACK (on_response_before), self);
1240 g_signal_connect (G_OBJECT (self), "delete-event",
1241 G_CALLBACK (on_delete_event), self);
1243 /* Reset dirty, because there was no user input until now */
1244 priv->dirty = FALSE;
1246 /* When this window is shown, hibernation should not be possible,
1247 * because there is no sensible way to save the state: */
1248 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1249 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1251 /* Load provider presets */
1252 g_object_ref (self);
1253 g_thread_create (presets_loader, self, FALSE, NULL);
1255 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1256 modest_maemo_utils_get_osso_context());
1258 self->settings = modest_account_settings_new ();
1261 ModestEasysetupWizardDialog*
1262 modest_easysetup_wizard_dialog_new (void)
1265 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1268 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1270 GtkNotebook *notebook = NULL;
1271 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1274 /* Create the custom pages: */
1275 if(!(self->page_custom_incoming)) {
1276 self->page_custom_incoming = create_page_custom_incoming (self);
1279 if(!(self->page_custom_outgoing)) {
1280 self->page_custom_outgoing = create_page_custom_outgoing (self);
1283 if(!(self->page_complete_customsetup)) {
1284 self->page_complete_customsetup = create_page_complete_custom (self);
1287 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1288 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1289 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1291 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1292 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1293 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1295 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup))) {
1296 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1297 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1298 gtk_container_child_set (GTK_CONTAINER (notebook),
1299 self->page_complete_customsetup,
1305 /* This is unnecessary with GTK+ 2.10: */
1306 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1309 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1311 GtkNotebook *notebook = NULL;
1312 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1315 /* Create the easysetup-specific pages: */
1316 if(!self->page_complete_easysetup)
1317 self->page_complete_easysetup = create_page_complete_easysetup (self);
1319 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup))) {
1320 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1321 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1322 gtk_container_child_set (GTK_CONTAINER (notebook),
1323 self->page_complete_easysetup,
1329 /* This is unnecessary with GTK+ 2.10: */
1330 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1332 /* After the user details page,
1333 * the following pages depend on whether "Other" was chosen
1334 * in the provider combobox on the account page
1336 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1338 if (easysetup_provider_combo_box_get_active_provider_id (
1339 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1340 /* "Other..." was selected: */
1342 /* Make sure that the easysetup pages do not exist: */
1343 if(self->page_complete_easysetup) {
1344 gtk_widget_destroy (self->page_complete_easysetup);
1345 self->page_complete_easysetup = NULL;
1348 create_subsequent_customsetup_pages (self);
1351 /* A specific provider was selected: */
1353 /* Make sure that the custom pages do not exist:
1354 * Because they will be used if they exist, when creating the account. */
1355 if(self->page_custom_incoming) {
1356 gtk_widget_destroy (self->page_custom_incoming);
1357 self->page_custom_incoming = NULL;
1358 self->combo_incoming_servertype = NULL;
1359 self->caption_incoming = NULL;
1360 self->entry_incomingserver = NULL;
1361 self->combo_incoming_security = NULL;
1362 self->checkbox_incoming_auth = NULL;
1365 if(self->page_custom_outgoing) {
1366 gtk_widget_destroy (self->page_custom_outgoing);
1367 self->page_custom_outgoing = NULL;
1368 self->entry_outgoingserver = NULL;
1369 self->combo_outgoing_security = NULL;
1370 self->combo_outgoing_auth = NULL;
1371 self->checkbox_outgoing_smtp_specific = NULL;
1372 self->button_outgoing_smtp_servers = NULL;
1375 if(self->page_complete_customsetup) {
1376 gtk_widget_destroy (self->page_complete_customsetup);
1377 self->page_complete_customsetup = NULL;
1381 /* Create the easysetup pages: */
1382 create_subsequent_easysetup_pages (self);
1388 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1393 gchar* at = g_utf8_strchr (email_address, -1, '@');
1394 if (!at || (g_utf8_strlen (at, -1) < 2))
1397 gchar* domain = g_utf8_next_char (at);
1401 const gchar* hostname = NULL;
1402 if (servertype == MODEST_PROTOCOL_STORE_POP)
1404 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1406 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1412 return g_strdup_printf ("%s.%s", hostname, domain);
1415 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1417 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1419 if (!account_wizard->entry_incomingserver)
1422 /* Set a default domain for the server, based on the email address,
1423 * if no server name was already specified.
1425 if (account_wizard->entry_user_email
1426 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1427 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1428 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1429 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1431 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1433 /* Do not set the INCOMING_CHANGED flag because of this edit */
1434 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1435 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1436 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1438 g_free (servername);
1441 /* Set a default domain for the server, based on the email address,
1442 * if no server name was already specified.
1444 if (!account_wizard->entry_outgoingserver)
1447 if (account_wizard->entry_user_email
1448 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1449 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1451 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1453 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1454 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1455 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1456 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1458 g_free (servername);
1463 get_entered_account_title (ModestEasysetupWizardDialog *account_wizard)
1465 const gchar* account_title =
1466 gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1467 if (!account_title || (strlen (account_title) == 0))
1470 /* Strip it of whitespace at the start and end: */
1471 gchar *result = g_strdup (account_title);
1472 result = g_strstrip (result);
1477 if (strlen (result) == 0) {
1487 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1489 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1490 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (account_wizard);
1492 /* if are browsing pages previous to the last one, then we have pending settings in
1494 if (next_page != NULL)
1495 priv->pending_load_settings = TRUE;
1497 /* Do extra validation that couldn't be done for every key press,
1498 * either because it was too slow,
1499 * or because it requires interaction:
1501 if (current_page == account_wizard->page_account_details) {
1502 /* Check that the title is not already in use: */
1503 gchar* account_title = get_entered_account_title (account_wizard);
1507 /* Aavoid a clash with an existing display name: */
1508 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1509 account_wizard->account_manager, account_title);
1512 /* Warn the user via a dialog: */
1513 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1518 else if (current_page == account_wizard->page_user_details) {
1519 /* Check that the email address is valud: */
1520 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1521 if ((!email_address) || (strlen(email_address) == 0))
1524 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1525 /* Warn the user via a dialog: */
1526 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1528 /* Return focus to the email address entry: */
1529 gtk_widget_grab_focus (account_wizard->entry_user_email);
1530 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1535 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1536 create_subsequent_pages (account_wizard);
1539 /* TODO: The UI Spec wants us to check that the servernames are valid,
1540 * but does not specify how.
1543 if(next_page == account_wizard->page_custom_incoming) {
1544 set_default_custom_servernames (account_wizard);
1546 else if (next_page == account_wizard->page_custom_outgoing) {
1547 set_default_custom_servernames (account_wizard);
1549 /* Check if the server supports secure authentication */
1550 const ModestConnectionProtocol security_incoming =
1551 modest_serversecurity_combo_box_get_active_serversecurity (
1552 MODEST_SERVERSECURITY_COMBO_BOX (account_wizard->combo_incoming_security));
1553 if (gtk_toggle_button_get_active (
1554 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1555 && !modest_protocol_info_is_secure(security_incoming))
1557 if (!check_has_supported_auth_methods (account_wizard))
1562 /* If this is the last page, and this is a click on Finish,
1563 * then attempt to create the dialog.
1565 if(!next_page) /* This is NULL when this is a click on Finish. */
1567 if (priv->pending_load_settings) {
1568 save_to_settings (account_wizard);
1570 modest_account_mgr_add_account_from_settings (account_wizard->account_manager, account_wizard->settings);
1577 static gboolean entry_is_empty (GtkWidget *entry)
1582 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1583 if ((!text) || (strlen(text) == 0))
1586 /* Strip it of whitespace at the start and end: */
1587 gchar *stripped = g_strdup (text);
1588 stripped = g_strstrip (stripped);
1593 const gboolean result = (strlen (stripped) == 0);
1601 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1603 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1605 gboolean enable_next = TRUE;
1606 if (current_page == account_wizard->page_welcome) {
1609 else if (current_page == account_wizard->page_account_details) {
1610 /* The account details title is mandatory: */
1611 if (entry_is_empty(account_wizard->entry_account_title))
1612 enable_next = FALSE;
1614 else if (current_page == account_wizard->page_user_details) {
1615 /* The user details username is mandatory: */
1616 if (entry_is_empty(account_wizard->entry_user_username))
1617 enable_next = FALSE;
1619 /* The user details email address is mandatory: */
1620 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1621 enable_next = FALSE;
1623 else if (current_page == account_wizard->page_custom_incoming) {
1624 /* The custom incoming server is mandatory: */
1625 if (entry_is_empty(account_wizard->entry_incomingserver))
1626 enable_next = FALSE;
1629 /* Enable the buttons,
1630 * identifying them via their associated response codes: */
1632 /* Disable the Finish button until we are on the last page,
1633 * because HildonWizardDialog enables this for all but the first page: */
1634 GtkNotebook *notebook = NULL;
1635 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1636 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1638 gint current = gtk_notebook_get_current_page (notebook);
1639 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1640 const gboolean is_last = (current == last);
1643 gtk_dialog_set_response_sensitive (dialog_base,
1644 MODEST_WIZARD_DIALOG_FINISH,
1648 /* Disable Next on the last page: */
1649 enable_next = FALSE;
1652 gtk_dialog_set_response_sensitive (dialog_base,
1653 MODEST_WIZARD_DIALOG_NEXT,
1658 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1660 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1661 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1664 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1665 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1666 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1667 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1669 /* Provide a vfunc implementation so we can decide
1670 * when to enable/disable the prev/next buttons.
1672 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1673 base_klass->before_next = on_before_next;
1674 base_klass->enable_buttons = on_enable_buttons;
1678 show_error (GtkWidget *parent_widget, const gchar* text)
1680 //TODO: Apparently this doesn't show anything in Maemo Bora:
1681 hildon_banner_show_information(parent_widget, NULL, text);
1687 * @self: a #ModestEasysetupWizardDialog
1689 * takes information from all the wizard and stores it in settings
1692 save_to_settings (ModestEasysetupWizardDialog *self)
1694 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1697 gchar* display_name;
1698 const gchar *username, *password;
1699 gchar *store_hostname, *transport_hostname;
1700 guint store_port, transport_port;
1701 ModestTransportStoreProtocol store_protocol, transport_protocol;
1702 ModestConnectionProtocol store_security, transport_security;
1703 ModestAuthProtocol store_auth_protocol, transport_auth_protocol;
1704 ModestServerAccountSettings *store_settings, *transport_settings;
1705 const gchar *fullname, *email_address;
1707 /* Get details from the specified presets: */
1708 provider_id = easysetup_provider_combo_box_get_active_provider_id (
1709 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1711 /* username and password (for both incoming and outgoing): */
1712 username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1713 password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1715 /* Incoming server: */
1716 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1717 * or modest_account_mgr_add_server_account will fail. */
1719 store_protocol = MODEST_PROTOCOL_STORE_POP;
1720 store_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1721 store_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1724 ModestPresetsServerType store_provider_server_type;
1725 ModestPresetsSecurity store_provider_security;
1727 store_hostname = modest_presets_get_server (priv->presets, provider_id,
1730 store_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1733 store_provider_security = modest_presets_get_info_server_security (priv->presets,
1737 /* We don't check for SMTP here as that is impossible for an incoming server. */
1738 if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_IMAP)
1739 store_protocol = MODEST_PROTOCOL_STORE_IMAP;
1740 else if (store_provider_server_type == MODEST_PRESETS_SERVER_TYPE_POP)
1741 store_protocol = MODEST_PROTOCOL_STORE_POP;
1743 store_protocol = MODEST_PROTOCOL_STORE_POP;
1745 /* we check if there is a *special* port */
1746 special_port = modest_presets_get_port (priv->presets, provider_id, TRUE /* incoming */);
1747 if (special_port != 0)
1748 store_port = special_port;
1750 store_port = get_serverport_incoming(store_provider_server_type, store_provider_security);
1752 if (store_provider_security & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1753 store_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1755 if (store_provider_security & MODEST_PRESETS_SECURITY_APOP)
1756 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1758 /* Use custom pages because no preset was specified: */
1759 store_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1760 store_protocol = easysetup_servertype_combo_box_get_active_servertype (
1761 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1762 store_security = modest_serversecurity_combo_box_get_active_serversecurity (
1763 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1765 /* The UI spec says:
1766 * If secure authentication is unchecked, allow sending username and password also as plain text.
1767 * If secure authentication is checked, require one of the secure methods during
1768 * connection: SSL, TLS, CRAM-MD5 etc. */
1769 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1770 !modest_protocol_info_is_secure(store_security)) {
1771 store_auth_protocol = check_first_supported_auth_method (self);
1773 store_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1777 /* now we store the store account settings */
1778 store_settings = modest_account_settings_get_store_settings (self->settings);
1779 modest_server_account_settings_set_hostname (store_settings, store_hostname);
1780 modest_server_account_settings_set_username (store_settings, username);
1781 modest_server_account_settings_set_password (store_settings, password);
1782 modest_server_account_settings_set_protocol (store_settings, store_protocol);
1783 modest_server_account_settings_set_security (store_settings, store_security);
1784 modest_server_account_settings_set_auth_protocol (store_settings, store_auth_protocol);
1785 if (store_port != 0)
1786 modest_server_account_settings_set_port (store_settings, store_port);
1788 g_object_unref (store_settings);
1789 g_free (store_hostname);
1791 /* Outgoing server: */
1792 transport_hostname = NULL;
1793 transport_protocol = MODEST_PROTOCOL_STORE_POP;
1794 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1795 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1799 ModestPresetsServerType transport_provider_server_type;
1800 ModestPresetsSecurity transport_provider_security;
1803 transport_hostname = modest_presets_get_server (priv->presets, provider_id,
1804 FALSE /* transport */);
1806 transport_provider_server_type = modest_presets_get_info_server_type (priv->presets,
1808 FALSE /* transport */);
1809 transport_provider_security = modest_presets_get_info_server_security (priv->presets,
1811 FALSE /* transport */);
1813 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1814 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1815 if (transport_provider_server_type == MODEST_PRESETS_SERVER_TYPE_SMTP)
1816 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP;
1818 transport_security = MODEST_PROTOCOL_CONNECTION_NORMAL;
1819 if (transport_provider_security & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1820 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1821 transport_security = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1822 /* we check if there is a *special* port */
1823 special_port = modest_presets_get_port (priv->presets, provider_id,
1824 FALSE /* transport */);
1825 if (special_port != 0)
1826 transport_port = special_port;
1828 transport_port = 465;
1829 transport_auth_protocol = MODEST_PROTOCOL_AUTH_PASSWORD;
1831 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1832 transport_auth_protocol = MODEST_PROTOCOL_AUTH_NONE;
1835 /* Use custom pages because no preset was specified: */
1836 transport_hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1837 transport_protocol = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1838 transport_security = modest_serversecurity_combo_box_get_active_serversecurity (
1839 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1840 transport_auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
1841 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1844 /* now we transport the transport account settings */
1845 transport_settings = modest_account_settings_get_transport_settings (self->settings);
1846 modest_server_account_settings_set_hostname (transport_settings, transport_hostname);
1847 modest_server_account_settings_set_username (transport_settings, username);
1848 modest_server_account_settings_set_password (transport_settings, password);
1849 modest_server_account_settings_set_protocol (transport_settings, transport_protocol);
1850 modest_server_account_settings_set_security (transport_settings, transport_security);
1851 modest_server_account_settings_set_auth_protocol (transport_settings, transport_auth_protocol);
1852 if (transport_port != 0)
1853 modest_server_account_settings_set_port (transport_settings, transport_port);
1855 g_object_unref (transport_settings);
1856 g_free (transport_hostname);
1858 fullname = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1859 email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1860 modest_account_settings_set_fullname (self->settings, fullname);
1861 modest_account_settings_set_email_address (self->settings, email_address);
1862 /* we don't set retrieve type to preserve advanced settings if any. By default account settings
1863 are set to headers only */
1865 /* Save the connection-specific SMTP server accounts. */
1866 modest_account_settings_set_use_connection_specific_smtp
1868 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->checkbox_outgoing_smtp_specific)));
1870 display_name = get_entered_account_title (self);
1871 modest_account_settings_set_display_name (self->settings, display_name);
1872 g_free (display_name);
1874 if (self->specific_window)
1875 modest_connection_specific_smtp_window_save_server_accounts (
1876 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window));