1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "modest-easysetup-wizard.h"
32 #include <glib/gi18n.h>
33 #include <gtk/gtknotebook.h>
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkcombobox.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkseparator.h>
42 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
43 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
44 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
45 #include "widgets/modest-serversecurity-combo-box.h"
46 #include "widgets/modest-secureauth-combo-box.h"
47 #include "widgets/modest-validating-entry.h"
48 #include "modest-text-utils.h"
49 #include "modest-account-mgr.h"
50 #include "modest-account-mgr-helpers.h"
51 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
52 #include "maemo/modest-connection-specific-smtp-window.h"
53 #include "widgets/modest-ui-constants.h"
54 #include "maemo/modest-account-settings-dialog.h"
55 #include "maemo/modest-maemo-utils.h"
56 #include <gconf/gconf-client.h>
57 #include <string.h> /* For strlen(). */
59 /* Include config.h so that _() works: */
64 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
66 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
68 #define WIZARD_DIALOG_GET_PRIVATE(o) \
69 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
71 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
75 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
76 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
77 } ModestEasysetupWizardDialogServerChanges;
79 struct _ModestEasysetupWizardDialogPrivate
81 ModestPresets *presets;
83 /* Remember what fields the user edited manually to not prefill them
85 ModestEasysetupWizardDialogServerChanges server_changes;
87 /* Check if the user changes a field to show a confirmation dialog */
92 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
94 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(wizard);
95 g_return_if_fail (priv != NULL);
100 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
101 GValue *value, GParamSpec *pspec)
103 switch (property_id) {
105 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
110 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
111 const GValue *value, GParamSpec *pspec)
113 switch (property_id) {
115 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
120 modest_easysetup_wizard_dialog_dispose (GObject *object)
122 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
123 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
127 modest_easysetup_wizard_dialog_finalize (GObject *object)
129 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
130 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
132 if (self->account_manager)
133 g_object_unref (G_OBJECT (self->account_manager));
136 modest_presets_destroy (priv->presets);
138 if (self->specific_window)
139 gtk_widget_destroy (self->specific_window);
141 g_free (self->saved_account_name);
143 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
147 show_error (GtkWidget *parent_widget, const gchar* text);
150 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
153 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
156 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
158 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
160 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
161 ModestPresetsSecurity security_incoming)
163 int serverport_incoming = 0;
164 /* We don't check for SMTP here as that is impossible for an incoming server. */
165 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
166 serverport_incoming =
167 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
168 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
169 serverport_incoming =
170 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
172 return serverport_incoming;
175 static GList* check_for_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
177 GError *error = NULL;
178 const ModestTransportStoreProtocol protocol =
179 easysetup_servertype_combo_box_get_active_servertype (
180 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
181 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
182 const gchar* username = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_user_username));
183 const ModestConnectionProtocol protocol_security_incoming =
184 modest_serversecurity_combo_box_get_active_serversecurity (
185 MODEST_SERVERSECURITY_COMBO_BOX (
186 account_wizard->combo_incoming_security));
187 const int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
188 GList *list_auth_methods =
189 modest_maemo_utils_get_supported_secure_authentication_methods (
191 hostname, port_num, username, GTK_WINDOW (account_wizard), &error);
192 if (list_auth_methods) {
193 /* TODO: Select the correct method */
196 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
197 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
198 if (modest_protocol_info_auth_is_secure(auth)) {
199 list = g_list_append(list, GINT_TO_POINTER(auth));
203 g_list_free(list_auth_methods);
209 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
210 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
212 show_error (GTK_WIDGET(account_wizard), _("Could not discover supported secure authentication methods."));
221 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
223 GList* methods = check_for_supported_auth_methods(account_wizard);
229 g_list_free(methods);
233 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* account_wizard)
235 ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
237 GList* methods = check_for_supported_auth_methods(account_wizard);
240 /* Use the first one: */
241 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
242 g_list_free(methods);
249 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
251 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
253 /* Call the vfunc, which may be overridden by derived classes: */
254 if (klass->enable_buttons) {
255 GtkNotebook *notebook = NULL;
256 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
258 const gint current_page_num = gtk_notebook_get_current_page (notebook);
259 if (current_page_num == -1)
262 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
263 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
268 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
270 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
272 invoke_enable_buttons_vfunc(self);
276 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
278 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
280 invoke_enable_buttons_vfunc(self);
283 /** This is a convenience function to create a caption containing a mandatory widget.
284 * When the widget is edited, the enable_buttons() vfunc will be called.
286 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
291 HildonCaptionStatus flag)
293 GtkWidget *caption = NULL;
295 /* Note: Previously, the translated strings already contained the "*",
296 * Comment out this code if they do again.
298 /* Add a * character to indicate mandatory fields,
299 * as specified in our "Email UI Specification": */
300 if (flag == HILDON_CAPTION_MANDATORY) {
301 gchar* title = g_strdup_printf("%s*", value);
302 caption = hildon_caption_new (group, title, control, icon, flag);
306 caption = hildon_caption_new (group, value, control, icon, flag);
308 /* Connect to the appropriate changed signal for the widget,
309 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
311 if (GTK_IS_ENTRY (control)) {
312 g_signal_connect (G_OBJECT (control), "changed",
313 G_CALLBACK (on_caption_entry_changed), self);
316 else if (GTK_IS_COMBO_BOX (control)) {
317 g_signal_connect (G_OBJECT (control), "changed",
318 G_CALLBACK (on_caption_combobox_changed), self);
325 create_page_welcome (ModestEasysetupWizardDialog *self)
327 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
328 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
329 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
330 /* So that it is not truncated: */
331 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
332 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
333 gtk_widget_show (label);
334 gtk_widget_show (GTK_WIDGET (box));
335 return GTK_WIDGET (box);
339 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
341 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
343 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
347 /* Fill the providers combo, based on the selected country: */
348 GSList *list_mcc_ids = easysetup_country_combo_box_get_active_country_ids (
349 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
350 easysetup_provider_combo_box_fill (
351 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, list_mcc_ids);
355 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
357 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
359 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
363 /* Fill the providers combo, based on the selected country: */
364 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
365 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
367 gchar* domain_name = NULL;
369 domain_name = modest_presets_get_domain (priv->presets, provider_id);
372 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
374 if (self->entry_user_email)
375 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
377 g_free (domain_name);
379 g_free (provider_id);
383 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
385 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
386 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
390 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
392 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
394 const gchar *show_char = NULL;
396 show_char = character;
398 /* TODO: We need a logical ID for this: */
399 show_char = _("whitespace");
402 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
403 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
404 show_error (GTK_WIDGET (self), message);
408 create_page_account_details (ModestEasysetupWizardDialog *self)
410 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
411 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
412 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
413 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
414 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
415 gtk_widget_show (label);
417 /* Create a size group to be used by all captions.
418 * Note that HildonCaption does not create a default size group if we do not specify one.
419 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
420 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
422 /* The country widgets: */
423 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
424 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
425 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
426 gtk_widget_show (self->combo_account_country);
427 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
428 gtk_widget_show (caption);
430 /* connect to country combo's changed signal, so we can fill the provider combo: */
431 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
432 G_CALLBACK (on_combo_account_country), self);
434 GtkWidget *separator = gtk_hseparator_new ();
435 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
436 gtk_widget_show (separator);
438 /* The service provider widgets: */
439 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
441 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
442 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
443 gtk_widget_show (self->combo_account_serviceprovider);
444 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
445 gtk_widget_show (caption);
447 /* connect to providers combo's changed signal, so we can fill the email address: */
448 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
449 G_CALLBACK (on_combo_account_serviceprovider), self);
451 /* TODO: Default to the current country somehow.
452 * But I don't know how to get the information that is specified in the
453 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
455 * This is probably not the best choice of gconf key:
456 * This is the "mcc used in the last pairing", ie. the last connection you made.
457 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
460 GConfClient *client = gconf_client_get_default ();
461 GError *error = NULL;
462 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
463 gint mcc_id = gconf_client_get_int(client, key, &error);
469 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
470 g_error_free (error);
476 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
477 * This might just be a Maemo bug.
481 /* For now, we default to Finland when there is nothing better: */
485 easysetup_country_combo_box_set_active_country_id (
486 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
489 /* The description widgets: */
490 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
491 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
492 G_CALLBACK(on_easysetup_changed), self);
493 /* Do use auto-capitalization: */
494 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
495 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
497 /* Set a default account title, choosing one that does not already exist: */
498 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
499 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
500 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
501 self->account_manager, default_account_name_start);
502 g_free (default_account_name_start);
503 default_account_name_start = NULL;
505 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
506 g_free (default_account_name);
507 default_account_name = NULL;
509 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
510 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
511 gtk_widget_show (self->entry_account_title);
512 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
513 gtk_widget_show (caption);
515 /* Prevent the use of some characters in the account title,
516 * as required by our UI specification: */
517 GList *list_prevent = NULL;
518 list_prevent = g_list_append (list_prevent, "\\");
519 list_prevent = g_list_append (list_prevent, "/");
520 list_prevent = g_list_append (list_prevent, ":");
521 list_prevent = g_list_append (list_prevent, "*");
522 list_prevent = g_list_append (list_prevent, "?");
523 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
524 list_prevent = g_list_append (list_prevent, "“");
525 list_prevent = g_list_append (list_prevent, "<");
526 list_prevent = g_list_append (list_prevent, ">");
527 list_prevent = g_list_append (list_prevent, "|");
528 list_prevent = g_list_append (list_prevent, "^");
529 modest_validating_entry_set_unallowed_characters (
530 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
531 g_list_free (list_prevent);
533 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
534 on_entry_invalid_character, self);
536 /* Set max length as in the UI spec:
537 * The UI spec seems to want us to show a dialog if we hit the maximum. */
538 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
539 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
542 gtk_widget_show (GTK_WIDGET (box));
544 return GTK_WIDGET (box);
548 create_page_user_details (ModestEasysetupWizardDialog *self)
550 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
552 /* Create a size group to be used by all captions.
553 * Note that HildonCaption does not create a default size group if we do not specify one.
554 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
555 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
557 /* The name widgets: (use auto cap) */
558 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
559 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name),
560 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
562 /* Set max length as in the UI spec:
563 * The UI spec seems to want us to show a dialog if we hit the maximum. */
564 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
565 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
567 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
568 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
569 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
570 G_CALLBACK(on_easysetup_changed), self);
571 gtk_widget_show (self->entry_user_name);
572 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
573 gtk_widget_show (caption);
575 /* Prevent the use of some characters in the name,
576 * as required by our UI specification: */
577 GList *list_prevent = NULL;
578 list_prevent = g_list_append (list_prevent, "<");
579 list_prevent = g_list_append (list_prevent, ">");
580 modest_validating_entry_set_unallowed_characters (
581 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
582 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
583 on_entry_invalid_character, self);
584 g_list_free (list_prevent);
586 /* The username widgets: */
587 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
588 /* Auto-capitalization is the default, so let's turn it off: */
589 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
590 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
591 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
592 gtk_widget_show (self->entry_user_username);
593 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
594 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
595 G_CALLBACK(on_easysetup_changed), self);
596 gtk_widget_show (caption);
598 /* Prevent the use of some characters in the username,
599 * as required by our UI specification: */
600 modest_validating_entry_set_unallowed_characters_whitespace (
601 MODEST_VALIDATING_ENTRY (self->entry_user_username));
602 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_username),
603 on_entry_invalid_character, self);
605 /* Set max length as in the UI spec:
606 * The UI spec seems to want us to show a dialog if we hit the maximum. */
607 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
608 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
611 /* The password widgets: */
612 self->entry_user_password = gtk_entry_new ();
613 /* Auto-capitalization is the default, so let's turn it off: */
614 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
615 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
616 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
617 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
618 caption = create_caption_new_with_asterisk (self, sizegroup,
619 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
620 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
621 G_CALLBACK(on_easysetup_changed), self);
622 gtk_widget_show (self->entry_user_password);
623 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
624 gtk_widget_show (caption);
626 /* The email address widgets: */
627 self->entry_user_email = GTK_WIDGET (modest_validating_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_email), HILDON_GTK_INPUT_MODE_FULL);
630 caption = create_caption_new_with_asterisk (self, sizegroup,
631 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
632 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
633 gtk_widget_show (self->entry_user_email);
634 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
635 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
636 G_CALLBACK(on_easysetup_changed), self);
637 gtk_widget_show (caption);
639 /* Set max length as in the UI spec:
640 * The UI spec seems to want us to show a dialog if we hit the maximum. */
641 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
642 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
646 gtk_widget_show (GTK_WIDGET (box));
648 return GTK_WIDGET (box);
651 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
653 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
655 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
656 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
657 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
658 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
659 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
660 gtk_widget_show (label);
662 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
663 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
664 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
666 /* The documentation for gtk_label_set_line_wrap() says that we must
667 * call gtk_widget_set_size_request() with a hard-coded width,
668 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
669 gtk_widget_set_size_request (label, 400, -1);
671 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
672 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
673 gtk_widget_show (label);
675 gtk_widget_show (GTK_WIDGET (box));
676 return GTK_WIDGET (box);
679 /** Change the caption title for the incoming server,
680 * as specified in the UI spec:
682 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
684 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
685 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
687 (protocol == MODEST_PROTOCOL_STORE_POP ?
688 _("mail_fi_emailtype_pop3") :
689 _("mail_fi_emailtype_imap") );
692 /* Note that this produces a compiler warning,
693 * because the compiler does not know that the translated string will have a %s in it.
694 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
695 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
696 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
697 g_free(incomingserver_title);
700 /** Change the caption title for the incoming server,
701 * as specified in the UI spec:
703 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
705 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
706 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
708 /* Fill the combo with appropriately titled choices for POP or IMAP. */
709 /* The choices are the same, but the titles are different, as in the UI spec. */
710 modest_serversecurity_combo_box_fill (
711 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
714 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
716 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
717 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
721 update_incoming_server_title (self);
722 update_incoming_server_security_choices (self);
724 set_default_custom_servernames (self);
727 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
729 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
730 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
732 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
735 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
737 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
739 /* Show note that account type cannot be changed in future: */
740 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
741 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
742 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
743 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
744 gtk_widget_show (label);
746 /* Create a size group to be used by all captions.
747 * Note that HildonCaption does not create a default size group if we do not specify one.
748 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
749 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
751 /* The incoming server widgets: */
752 if (!self->combo_incoming_servertype)
753 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
754 easysetup_servertype_combo_box_set_active_servertype (
755 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
756 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
757 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
758 gtk_widget_show (self->combo_incoming_servertype);
759 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
760 gtk_widget_show (caption);
762 if(!self->entry_incomingserver)
764 self->entry_incomingserver = gtk_entry_new ();
765 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed",
766 G_CALLBACK(on_easysetup_changed), self);
768 /* Auto-capitalization is the default, so let's turn it off: */
769 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
770 set_default_custom_servernames (self);
772 if (self->caption_incoming)
773 gtk_widget_destroy (self->caption_incoming);
775 /* The caption title will be updated in update_incoming_server_title().
776 * so this default text will never be seen: */
777 /* (Note: Changing the title seems pointless. murrayc) */
778 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
779 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
780 update_incoming_server_title (self);
781 gtk_widget_show (self->entry_incomingserver);
782 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
783 gtk_widget_show (self->caption_incoming);
785 /* Change the caption title when the servertype changes,
786 * as in the UI spec: */
787 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
788 G_CALLBACK (on_combo_servertype_changed), self);
790 /* Remember when the servername was changed manually: */
791 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
792 G_CALLBACK (on_entry_incoming_servername_changed), self);
794 /* The secure connection widgets: */
795 if (!self->combo_incoming_security)
796 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
797 update_incoming_server_security_choices (self);
798 modest_serversecurity_combo_box_set_active_serversecurity (
799 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
800 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
801 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
802 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
803 G_CALLBACK (on_easysetup_changed), self);
804 gtk_widget_show (self->combo_incoming_security);
805 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
806 gtk_widget_show (caption);
808 if(!self->checkbox_incoming_auth)
810 self->checkbox_incoming_auth = gtk_check_button_new ();
811 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
812 G_CALLBACK (on_easysetup_changed), self);
814 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
815 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
817 gtk_widget_show (self->checkbox_incoming_auth);
818 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
819 gtk_widget_show (caption);
821 gtk_widget_show (GTK_WIDGET (box));
823 return GTK_WIDGET (box);
827 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
829 GtkWidget *widget = GTK_WIDGET (user_data);
831 /* Enable the widget only if the toggle button is active: */
832 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
833 gtk_widget_set_sensitive (widget, enable);
836 /* Make the sensitivity of a widget depend on a toggle button.
839 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
841 g_signal_connect (G_OBJECT (button), "toggled",
842 G_CALLBACK (on_toggle_button_changed), widget);
844 /* Set the starting sensitivity: */
845 on_toggle_button_changed (button, widget);
849 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
851 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
852 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
854 /* We set dirty here because setting it depending on the connection specific dialog
858 /* Create the window, if necessary: */
859 if (!(self->specific_window)) {
860 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
861 modest_connection_specific_smtp_window_fill_with_connections (
862 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager);
865 /* Show the window: */
866 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
867 gtk_widget_show (self->specific_window);
870 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
872 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
873 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
874 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
877 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
879 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
881 /* Create a size group to be used by all captions.
882 * Note that HildonCaption does not create a default size group if we do not specify one.
883 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
884 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
886 /* The outgoing server widgets: */
887 if (!self->entry_outgoingserver)
889 self->entry_outgoingserver = gtk_entry_new ();
890 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
891 G_CALLBACK (on_easysetup_changed), self);
893 /* Auto-capitalization is the default, so let's turn it off: */
894 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
895 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
896 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
897 gtk_widget_show (self->entry_outgoingserver);
898 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
899 gtk_widget_show (caption);
900 set_default_custom_servernames (self);
902 /* The secure connection widgets: */
903 if (!self->combo_outgoing_security)
905 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
906 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
907 G_CALLBACK (on_easysetup_changed), self);
909 modest_serversecurity_combo_box_fill (
910 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
911 modest_serversecurity_combo_box_set_active_serversecurity (
912 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
913 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
914 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
915 gtk_widget_show (self->combo_outgoing_security);
916 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
917 gtk_widget_show (caption);
919 /* The secure authentication widgets: */
920 if (!self->combo_outgoing_auth)
922 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
923 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
924 G_CALLBACK (on_easysetup_changed), self);
926 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
927 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
928 gtk_widget_show (self->combo_outgoing_auth);
929 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
930 gtk_widget_show (caption);
932 GtkWidget *separator = gtk_hseparator_new ();
933 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
934 gtk_widget_show (separator);
936 /* connection-specific checkbox: */
937 if (!self->checkbox_outgoing_smtp_specific) {
938 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
939 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
941 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
942 G_CALLBACK (on_easysetup_changed), self);
945 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
946 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
947 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
948 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
949 gtk_widget_show (caption);
951 /* Connection-specific SMTP-Severs Edit button: */
952 if (!self->button_outgoing_smtp_servers)
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);
982 if (!(self->saved_account_name))
985 /* Show the Account Settings window: */
986 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
987 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
989 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
991 gtk_dialog_run (GTK_DIALOG (dialog));
993 gtk_widget_destroy (GTK_WIDGET (dialog));
995 return FALSE; /* Do not call this timeout callback again. */
999 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1001 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1003 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
1004 * without recoding it to use non-gconf information.
1005 * This account will be deleted if Finish is never actually clicked. */
1007 gboolean saved = TRUE;
1008 if (!(self->saved_account_name)) {
1009 saved = create_account (self, FALSE);
1015 if (!(self->saved_account_name))
1018 /* Show the Account Settings window: */
1019 show_advanced_edit(self);
1021 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1023 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1024 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1025 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1026 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1027 gtk_widget_show (label);
1029 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1030 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1031 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1032 gtk_widget_show (label);
1034 if (!self->button_edit)
1035 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1036 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1037 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1038 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1039 gtk_widget_show (self->button_edit);
1040 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1041 gtk_widget_show (caption);
1043 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
1044 G_CALLBACK (on_button_edit_advanced_settings), self);
1046 gtk_widget_show (GTK_WIDGET (box));
1047 return GTK_WIDGET (box);
1054 on_response (ModestWizardDialog *wizard_dialog,
1058 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1059 if (response_id == GTK_RESPONSE_CANCEL) {
1060 /* Remove any temporarily-saved account that will not actually be needed: */
1061 if (self->saved_account_name) {
1062 modest_account_mgr_remove_account (self->account_manager,
1063 self->saved_account_name);
1067 invoke_enable_buttons_vfunc (self);
1071 on_response_before (ModestWizardDialog *wizard_dialog,
1075 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1076 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1077 if (response_id == GTK_RESPONSE_CANCEL) {
1078 /* This is mostly copied from
1079 * src/maemo/modest-account-settings-dialog.c */
1082 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1083 _("imum_nc_wizard_confirm_lose_changes")));
1084 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1086 const gint dialog_response = gtk_dialog_run (dialog);
1087 gtk_widget_destroy (GTK_WIDGET (dialog));
1089 if (dialog_response != GTK_RESPONSE_OK)
1091 /* This is a nasty hack. murrayc. */
1092 /* Don't let the dialog close */
1093 g_signal_stop_emission_by_name (wizard_dialog, "response");
1100 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1102 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1104 /* Create the notebook to be used by the ModestWizardDialog base class:
1105 * Each page of the notebook will be a page of the wizard: */
1106 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1108 /* Set the notebook used by the ModestWizardDialog base class: */
1109 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1111 /* Set the wizard title:
1112 * The actual window title will be a combination of this and the page's tab label title. */
1113 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1115 /* Read in the information about known service providers: */
1116 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1118 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
1119 priv->presets = modest_presets_new (filepath);
1120 if (!(priv->presets)) {
1121 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
1124 g_assert(priv->presets);
1126 /* The server fields did not have been manually changed yet */
1127 priv->server_changes = 0;
1129 /* Get the account manager object,
1130 * so we can check for existing accounts,
1131 * and create new accounts: */
1132 self->account_manager = modest_runtime_get_account_mgr ();
1133 g_assert (self->account_manager);
1134 g_object_ref (self->account_manager);
1136 /* Create the common pages,
1138 self->page_welcome = create_page_welcome (self);
1139 self->page_account_details = create_page_account_details (self);
1140 self->page_user_details = create_page_user_details (self);
1142 /* Add the common pages: */
1143 gtk_notebook_append_page (notebook, self->page_welcome,
1144 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1145 gtk_notebook_append_page (notebook, self->page_account_details,
1146 gtk_label_new (_("mcen_ti_accountdetails")));
1147 gtk_notebook_append_page (notebook, self->page_user_details,
1148 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1150 /* Create and add the easysetup-specific pages,
1151 * because we need _some_ final page to enable the Next and Finish buttons: */
1152 create_subsequent_easysetup_pages (self);
1154 /* Connect to the dialog's response signal so we can enable/disable buttons
1155 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1156 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1157 * so that we can be enable/disable after ModestWizardDialog has done its own
1158 * enabling/disabling of buttons.
1160 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1161 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1163 * It's not enough to connect to the notebook's switch-page signal, because
1164 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1165 * _after_ switching the page (understandably).
1166 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1167 * then gtk_notebook_get_current_page() would return an incorrect value.)
1169 g_signal_connect_after (G_OBJECT (self), "response",
1170 G_CALLBACK (on_response), self);
1172 /* This is to show a confirmation dialog when the user hits cancel */
1173 g_signal_connect (G_OBJECT (self), "response",
1174 G_CALLBACK (on_response_before), self);
1176 /* Reset dirty, because there was no user input until now */
1177 priv->dirty = FALSE;
1179 /* When this window is shown, hibernation should not be possible,
1180 * because there is no sensible way to save the state: */
1181 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1182 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1185 ModestEasysetupWizardDialog*
1186 modest_easysetup_wizard_dialog_new (void)
1189 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1192 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1194 GtkNotebook *notebook = NULL;
1195 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1198 /* Create the custom pages: */
1199 if(!(self->page_custom_incoming)) {
1200 self->page_custom_incoming = create_page_custom_incoming (self);
1203 if(!(self->page_custom_outgoing)) {
1204 self->page_custom_outgoing = create_page_custom_outgoing (self);
1207 if(!(self->page_complete_customsetup)) {
1208 self->page_complete_customsetup = create_page_complete_custom (self);
1211 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1212 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1213 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1215 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1216 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1217 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1219 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1220 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1221 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1223 /* This is unnecessary with GTK+ 2.10: */
1224 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1227 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1229 GtkNotebook *notebook = NULL;
1230 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1233 /* Create the easysetup-specific pages: */
1234 if(!self->page_complete_easysetup)
1235 self->page_complete_easysetup = create_page_complete_easysetup (self);
1237 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1238 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1239 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1241 /* This is unnecessary with GTK+ 2.10: */
1242 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1244 /* After the user details page,
1245 * the following pages depend on whether "Other" was chosen
1246 * in the provider combobox on the account page
1248 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1250 if (easysetup_provider_combo_box_get_active_provider_id (
1251 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1252 /* "Other..." was selected: */
1254 /* Make sure that the easysetup pages do not exist: */
1255 if(self->page_complete_easysetup) {
1256 gtk_widget_destroy (self->page_complete_easysetup);
1257 self->page_complete_easysetup = NULL;
1260 create_subsequent_customsetup_pages (self);
1263 /* A specific provider was selected: */
1265 /* Make sure that the custom pages do not exist:
1266 * Because they will be used if they exist, when creating the account. */
1267 if(self->page_custom_incoming) {
1268 gtk_widget_destroy (self->page_custom_incoming);
1269 self->page_custom_incoming = NULL;
1272 if(self->page_custom_outgoing) {
1273 gtk_widget_destroy (self->page_custom_outgoing);
1274 self->page_custom_outgoing = NULL;
1277 if(self->page_complete_customsetup) {
1278 gtk_widget_destroy (self->page_complete_customsetup);
1279 self->page_complete_customsetup = NULL;
1283 /* Create the easysetup pages: */
1284 create_subsequent_easysetup_pages (self);
1290 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1295 gchar* at = g_utf8_strchr (email_address, -1, '@');
1296 if (!at || (g_utf8_strlen (at, -1) < 2))
1299 gchar* domain = g_utf8_next_char (at);
1303 const gchar* hostname = NULL;
1304 if (servertype == MODEST_PROTOCOL_STORE_POP)
1306 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1308 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1314 return g_strdup_printf ("%s.%s", hostname, domain);
1317 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1319 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1321 if (!account_wizard->entry_incomingserver)
1324 /* Set a default domain for the server, based on the email address,
1325 * if no server name was already specified.
1327 if (account_wizard->entry_user_email
1328 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1329 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1330 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1331 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1333 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1335 /* Do not set the INCOMING_CHANGED flag because of this edit */
1336 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1337 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1338 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1340 g_free (servername);
1343 /* Set a default domain for the server, based on the email address,
1344 * if no server name was already specified.
1346 if (!account_wizard->entry_outgoingserver)
1349 if (account_wizard->entry_user_email
1350 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1351 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1353 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1355 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1356 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1357 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1358 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1360 g_free (servername);
1365 get_entered_account_title (ModestEasysetupWizardDialog *account_wizard)
1367 const gchar* account_title =
1368 gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1369 if (!account_title || (strlen (account_title) == 0))
1372 /* Strip it of whitespace at the start and end: */
1373 gchar *result = g_strdup (account_title);
1374 result = g_strstrip (result);
1379 if (strlen (result) == 0) {
1389 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1391 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1393 /* Do extra validation that couldn't be done for every key press,
1394 * either because it was too slow,
1395 * or because it requires interaction:
1397 if (current_page == account_wizard->page_account_details) {
1398 /* Check that the title is not already in use: */
1399 gchar* account_title = get_entered_account_title (account_wizard);
1403 /* Aavoid a clash with an existing display name: */
1404 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1405 account_wizard->account_manager, account_title);
1408 /* Warn the user via a dialog: */
1409 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1414 else if (current_page == account_wizard->page_user_details) {
1415 /* Check that the email address is valud: */
1416 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1417 if ((!email_address) || (strlen(email_address) == 0))
1420 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1421 /* Warn the user via a dialog: */
1422 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1424 /* Return focus to the email address entry: */
1425 gtk_widget_grab_focus (account_wizard->entry_user_email);
1426 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1431 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1432 create_subsequent_pages (account_wizard);
1435 /* TODO: The UI Spec wants us to check that the servernames are valid,
1436 * but does not specify how.
1439 if(next_page == account_wizard->page_custom_incoming) {
1440 set_default_custom_servernames (account_wizard);
1442 else if (next_page == account_wizard->page_custom_outgoing) {
1443 set_default_custom_servernames (account_wizard);
1445 /* Check if the server supports secure authentication */
1446 const ModestConnectionProtocol security_incoming =
1447 modest_serversecurity_combo_box_get_active_serversecurity (
1448 MODEST_SERVERSECURITY_COMBO_BOX (
1449 account_wizard->combo_incoming_security));
1450 if (gtk_toggle_button_get_active (
1451 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1452 && !modest_protocol_info_is_secure(security_incoming))
1454 if (!check_has_supported_auth_methods (account_wizard))
1459 /* If this is the last page, and this is a click on Finish,
1460 * then attempt to create the dialog.
1462 if(!next_page) /* This is NULL when this is a click on Finish. */
1464 if (account_wizard->saved_account_name) {
1465 /* Just enable the already-saved account (temporarily created when
1466 * editing advanced settings): */
1467 modest_account_mgr_set_enabled (account_wizard->account_manager,
1468 account_wizard->saved_account_name, TRUE);
1470 create_account (account_wizard, TRUE /* enabled */);
1478 static gboolean entry_is_empty (GtkWidget *entry)
1483 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1484 if ((!text) || (strlen(text) == 0))
1487 /* Strip it of whitespace at the start and end: */
1488 gchar *stripped = g_strdup (text);
1489 stripped = g_strstrip (stripped);
1494 const gboolean result = (strlen (stripped) == 0);
1502 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1504 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1506 gboolean enable_next = TRUE;
1507 if (current_page == account_wizard->page_welcome) {
1510 else if (current_page == account_wizard->page_account_details) {
1511 /* The account details title is mandatory: */
1512 if (entry_is_empty(account_wizard->entry_account_title))
1513 enable_next = FALSE;
1515 else if (current_page == account_wizard->page_user_details) {
1516 /* The user details username is mandatory: */
1517 if (entry_is_empty(account_wizard->entry_user_username))
1518 enable_next = FALSE;
1520 /* The user details email address is mandatory: */
1521 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1522 enable_next = FALSE;
1524 else if (current_page == account_wizard->page_custom_incoming) {
1525 /* The custom incoming server is mandatory: */
1526 if (entry_is_empty(account_wizard->entry_incomingserver))
1527 enable_next = FALSE;
1530 /* Enable the buttons,
1531 * identifying them via their associated response codes: */
1533 /* Disable the Finish button until we are on the last page,
1534 * because HildonWizardDialog enables this for all but the first page: */
1535 GtkNotebook *notebook = NULL;
1536 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1537 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1539 gint current = gtk_notebook_get_current_page (notebook);
1540 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1541 const gboolean is_last = (current == last);
1544 gtk_dialog_set_response_sensitive (dialog_base,
1545 MODEST_WIZARD_DIALOG_FINISH,
1549 /* Disable Next on the last page: */
1550 enable_next = FALSE;
1553 gtk_dialog_set_response_sensitive (dialog_base,
1554 MODEST_WIZARD_DIALOG_NEXT,
1559 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1561 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1562 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1565 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1566 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1567 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1568 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1570 /* Provide a vfunc implementation so we can decide
1571 * when to enable/disable the prev/next buttons.
1573 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1574 base_klass->before_next = on_before_next;
1575 base_klass->enable_buttons = on_enable_buttons;
1579 show_error (GtkWidget *parent_widget, const gchar* text)
1581 //TODO: Apparently this doesn't show anything in Maemo Bora:
1582 hildon_banner_show_information(parent_widget, NULL, text);
1585 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
1587 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1594 gtk_dialog_run (dialog);
1595 gtk_widget_destroy (GTK_WIDGET (dialog));
1599 /** Attempt to create the account from the information that the user has entered.
1600 * @result: TRUE if the account was successfully created.
1603 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1605 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1607 gchar* display_name = get_entered_account_title (self);
1613 /* We should have checked for this already,
1614 * and changed that name accordingly,
1615 * but let's check again just in case:
1617 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name)) {
1618 g_free (display_name);
1622 /* Increment the non-user visible name if necessary,
1623 * based on the display name: */
1624 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1625 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1626 account_name_start, FALSE /* not a server account */);
1627 g_free (account_name_start);
1629 /* username and password (for both incoming and outgoing): */
1630 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1631 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1632 /* Incoming server: */
1633 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1634 * or modest_account_mgr_add_server_account will fail. */
1635 gchar* servername_incoming = NULL;
1636 guint serverport_incoming = 0;
1637 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1638 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1639 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1641 /* Get details from the specified presets: */
1642 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1643 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1646 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1647 TRUE /* incoming */);
1649 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1651 TRUE /* incoming */);
1652 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1654 TRUE /* incoming */);
1656 g_warning ("security incoming: %x", security_incoming);
1658 /* We don't check for SMTP here as that is impossible for an incoming server. */
1659 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1660 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1661 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1662 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1664 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1666 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1667 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1669 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1670 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1673 /* Use custom pages because no preset was specified: */
1674 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1676 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1677 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1679 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1680 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1682 /* The UI spec says:
1683 * If secure authentication is unchecked, allow sending username and password also as plain text.
1684 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1687 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1688 !modest_protocol_info_is_secure(protocol_security_incoming)) {
1689 protocol_authentication_incoming = check_first_supported_auth_method (self);
1692 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1696 /* First we add the 2 server accounts, and then we add the account that uses them.
1697 * If we don't do it in this order then we will experience a crash. */
1699 /* Add a (incoming) server account, to be used by the account: */
1700 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1701 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1702 store_name_start, TRUE /* server account */);
1703 g_free (store_name_start);
1704 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1706 servername_incoming,
1707 serverport_incoming,
1710 protocol_security_incoming,
1711 protocol_authentication_incoming);
1713 g_free (servername_incoming);
1716 /* TODO: Provide a Logical ID for the text: */
1717 show_error (GTK_WIDGET (self), _("An error occurred while creating the incoming account."));
1718 g_free (display_name);
1722 /* Outgoing server: */
1723 gchar* servername_outgoing = NULL;
1724 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1725 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1726 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1727 guint serverport_outgoing = 0;
1731 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1732 FALSE /* incoming */);
1734 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1736 FALSE /* incoming */);
1738 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1739 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1740 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1741 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1743 ModestPresetsSecurity security_outgoing =
1744 modest_presets_get_info_server_security (priv->presets, provider_id,
1745 FALSE /* incoming */);
1747 /* TODO: The secure-smtp information in the presets data is currently wrong,
1748 * so we choose a reasonable default. Remove this when the presets data is corrected: */
1749 security_outgoing = security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP;
1751 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1752 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1753 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1754 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1755 serverport_outgoing = 465;
1756 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1758 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1759 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1763 /* Use custom pages because no preset was specified: */
1764 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1766 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1768 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1769 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1771 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1772 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1775 /* Add a (outgoing) server account to be used by the account: */
1776 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1777 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1778 transport_name_start, TRUE /* server account */);
1779 g_free (transport_name_start);
1780 created = modest_account_mgr_add_server_account (self->account_manager,
1782 servername_outgoing,
1783 serverport_outgoing,
1786 protocol_security_outgoing,
1787 protocol_authentication_outgoing);
1789 g_free (servername_outgoing);
1792 /* TODO: Provide a Logical ID for the text: */
1793 show_error (GTK_WIDGET (self), _("An error occurred while creating the outgoing account."));
1794 g_free (display_name);
1799 /* Create the account, which will contain the two "server accounts": */
1800 created = modest_account_mgr_add_account (self->account_manager, account_name,
1801 store_name, /* The name of our POP/IMAP server account. */
1802 transport_name, /* The name of our SMTP server account. */
1804 g_free (store_name);
1805 g_free (transport_name);
1808 /* TODO: Provide a Logical ID for the text: */
1809 show_error (GTK_WIDGET (self), _("An error occurred while creating the account."));
1810 g_free (display_name);
1815 /* There must be at least one account now: */
1816 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1817 * fixed in versions after 3.1. */
1818 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1819 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1821 /* The user name and email address must be set additionally: */
1822 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1823 modest_account_mgr_set_string (self->account_manager, account_name,
1824 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1826 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1827 modest_account_mgr_set_string (self->account_manager, account_name,
1828 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1830 /* Set the display name: */
1831 modest_account_mgr_set_string (self->account_manager, account_name,
1832 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1834 /* Set retrieve type */
1835 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1836 modest_account_mgr_set_string (self->account_manager, account_name,
1837 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1839 /* Save the connection-specific SMTP server accounts. */
1840 modest_account_mgr_set_use_connection_specific_smtp(self->account_manager, account_name,
1841 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->checkbox_outgoing_smtp_specific)));
1842 gboolean result = TRUE;
1843 if (self->specific_window)
1844 result = modest_connection_specific_smtp_window_save_server_accounts (
1845 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window));
1847 g_free (self->saved_account_name);
1848 self->saved_account_name = g_strdup (account_name);
1850 g_free (account_name);
1851 g_free (display_name);