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;
74 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
75 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
76 } ModestEasysetupWizardDialogServerChanges;
78 struct _ModestEasysetupWizardDialogPrivate
80 ModestPresets *presets;
82 /* Remember what fields the user edited manually to not prefill them
84 ModestEasysetupWizardDialogServerChanges server_changes;
86 /* Check if the user changes a field to show a confirmation dialog */
91 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
93 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(wizard);
94 g_return_if_fail (priv != NULL);
99 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
100 GValue *value, GParamSpec *pspec)
102 switch (property_id) {
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
109 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
110 const GValue *value, GParamSpec *pspec)
112 switch (property_id) {
114 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
119 modest_easysetup_wizard_dialog_dispose (GObject *object)
121 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
122 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
126 modest_easysetup_wizard_dialog_finalize (GObject *object)
128 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
129 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
131 if (self->account_manager)
132 g_object_unref (G_OBJECT (self->account_manager));
135 modest_presets_destroy (priv->presets);
137 if (self->specific_window)
138 gtk_widget_destroy (self->specific_window);
140 g_free (self->saved_account_name);
142 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
146 show_error (GtkWindow *parent_window, const gchar* text);
149 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
152 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
155 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
157 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
159 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
160 ModestPresetsSecurity security_incoming)
162 int serverport_incoming = 0;
163 /* We don't check for SMTP here as that is impossible for an incoming server. */
164 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
165 serverport_incoming =
166 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
167 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
168 serverport_incoming =
169 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
171 return serverport_incoming;
174 static GList* check_for_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
176 GError *error = NULL;
177 const ModestTransportStoreProtocol protocol =
178 easysetup_servertype_combo_box_get_active_servertype (
179 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
180 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
181 const gchar* username = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_user_username));
182 const ModestConnectionProtocol protocol_security_incoming =
183 modest_serversecurity_combo_box_get_active_serversecurity (
184 MODEST_SERVERSECURITY_COMBO_BOX (
185 account_wizard->combo_incoming_security));
186 int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
187 GList *list_auth_methods =
188 modest_maemo_utils_get_supported_secure_authentication_methods (
190 hostname, port_num, username, GTK_WINDOW (account_wizard), &error);
191 if (list_auth_methods) {
192 /* TODO: Select the correct method */
195 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
196 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
197 if (modest_protocol_info_auth_is_secure(auth)) {
198 list = g_list_append(list, GINT_TO_POINTER(auth));
201 g_list_free(list_auth_methods);
206 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
207 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
209 GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(account_wizard),
210 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
211 GTK_BUTTONS_OK, (error != NULL) ? error->message : _("Server does not support secure authentication!"));
212 gtk_dialog_run(GTK_DIALOG(error_dialog));
213 gtk_widget_destroy(error_dialog);
216 if(error != NULL) g_error_free(error);
221 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
223 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
225 /* Call the vfunc, which may be overridden by derived classes: */
226 if (klass->enable_buttons) {
227 GtkNotebook *notebook = NULL;
228 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
230 const gint current_page_num = gtk_notebook_get_current_page (notebook);
231 if (current_page_num == -1)
234 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
235 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
240 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
242 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
244 invoke_enable_buttons_vfunc(self);
248 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
250 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
252 invoke_enable_buttons_vfunc(self);
255 /** This is a convenience function to create a caption containing a mandatory widget.
256 * When the widget is edited, the enable_buttons() vfunc will be called.
258 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
263 HildonCaptionStatus flag)
265 GtkWidget *caption = NULL;
267 /* Note: Previously, the translated strings already contained the "*",
268 * Comment out this code if they do again.
270 /* Add a * character to indicate mandatory fields,
271 * as specified in our "Email UI Specification": */
272 if (flag == HILDON_CAPTION_MANDATORY) {
273 gchar* title = g_strdup_printf("%s*", value);
274 caption = hildon_caption_new (group, title, control, icon, flag);
278 caption = hildon_caption_new (group, value, control, icon, flag);
280 /* Connect to the appropriate changed signal for the widget,
281 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
283 if (GTK_IS_ENTRY (control)) {
284 g_signal_connect (G_OBJECT (control), "changed",
285 G_CALLBACK (on_caption_entry_changed), self);
288 else if (GTK_IS_COMBO_BOX (control)) {
289 g_signal_connect (G_OBJECT (control), "changed",
290 G_CALLBACK (on_caption_combobox_changed), self);
297 create_page_welcome (ModestEasysetupWizardDialog *self)
299 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
300 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
301 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
302 /* So that it is not truncated: */
303 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
304 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
305 gtk_widget_show (label);
306 gtk_widget_show (GTK_WIDGET (box));
307 return GTK_WIDGET (box);
311 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
313 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
315 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
319 /* Fill the providers combo, based on the selected country: */
320 GSList *list_mcc_ids = easysetup_country_combo_box_get_active_country_ids (
321 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
322 easysetup_provider_combo_box_fill (
323 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, list_mcc_ids);
327 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
329 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
331 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
335 /* Fill the providers combo, based on the selected country: */
336 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
337 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
339 gchar* domain_name = NULL;
341 domain_name = modest_presets_get_domain (priv->presets, provider_id);
344 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
346 if (self->entry_user_email)
347 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
349 g_free (domain_name);
351 g_free (provider_id);
355 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
357 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
358 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
362 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
364 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
365 /* We could add a special case for whitespace here
366 if (character == NULL) ...
368 hildon_banner_show_information (
369 GTK_WIDGET(dialog), NULL, _("ckdg_ib_illegal_characters_entered"));
373 create_page_account_details (ModestEasysetupWizardDialog *self)
375 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
376 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
377 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
378 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
379 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
380 gtk_widget_show (label);
382 /* Create a size group to be used by all captions.
383 * Note that HildonCaption does not create a default size group if we do not specify one.
384 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
385 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
387 /* The country widgets: */
388 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
389 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
390 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
391 gtk_widget_show (self->combo_account_country);
392 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
393 gtk_widget_show (caption);
395 /* connect to country combo's changed signal, so we can fill the provider combo: */
396 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
397 G_CALLBACK (on_combo_account_country), self);
399 GtkWidget *separator = gtk_hseparator_new ();
400 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
401 gtk_widget_show (separator);
403 /* The service provider widgets: */
404 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
406 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
407 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
408 gtk_widget_show (self->combo_account_serviceprovider);
409 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
410 gtk_widget_show (caption);
412 /* connect to providers combo's changed signal, so we can fill the email address: */
413 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
414 G_CALLBACK (on_combo_account_serviceprovider), self);
416 /* TODO: Default to the current country somehow.
417 * But I don't know how to get the information that is specified in the
418 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
420 * This is probably not the best choice of gconf key:
421 * This is the "mcc used in the last pairing", ie. the last connection you made.
422 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
425 GConfClient *client = gconf_client_get_default ();
426 GError *error = NULL;
427 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
428 gint mcc_id = gconf_client_get_int(client, key, &error);
434 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
435 g_error_free (error);
441 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
442 * This might just be a Maemo bug.
446 /* For now, we default to Finland when there is nothing better: */
450 easysetup_country_combo_box_set_active_country_id (
451 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
454 /* The description widgets: */
455 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
456 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
457 G_CALLBACK(on_easysetup_changed), self);
458 /* Do use auto-capitalization: */
459 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
460 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
462 /* Set a default account title, choosing one that does not already exist: */
463 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
464 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
465 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
466 self->account_manager, default_account_name_start);
467 g_free (default_account_name_start);
468 default_account_name_start = NULL;
470 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
471 g_free (default_account_name);
472 default_account_name = NULL;
474 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
475 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
476 gtk_widget_show (self->entry_account_title);
477 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
478 gtk_widget_show (caption);
480 /* Prevent the use of some characters in the account title,
481 * as required by our UI specification: */
482 GList *list_prevent = NULL;
483 list_prevent = g_list_append (list_prevent, "\\");
484 list_prevent = g_list_append (list_prevent, "/");
485 list_prevent = g_list_append (list_prevent, ":");
486 list_prevent = g_list_append (list_prevent, "*");
487 list_prevent = g_list_append (list_prevent, "?");
488 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
489 list_prevent = g_list_append (list_prevent, "“");
490 list_prevent = g_list_append (list_prevent, "<");
491 list_prevent = g_list_append (list_prevent, ">");
492 list_prevent = g_list_append (list_prevent, "|");
493 list_prevent = g_list_append (list_prevent, "^");
494 modest_validating_entry_set_unallowed_characters (
495 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
496 g_list_free (list_prevent);
497 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
498 on_entry_invalid_character, self);
500 /* Set max length as in the UI spec:
501 * The UI spec seems to want us to show a dialog if we hit the maximum. */
502 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
503 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
506 gtk_widget_show (GTK_WIDGET (box));
508 return GTK_WIDGET (box);
512 create_page_user_details (ModestEasysetupWizardDialog *self)
514 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
516 /* Create a size group to be used by all captions.
517 * Note that HildonCaption does not create a default size group if we do not specify one.
518 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
519 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
521 /* The name widgets: */
522 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
523 /* Auto-capitalization is the default, so let's turn it off: */
524 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
525 /* Set max length as in the UI spec:
526 * The UI spec seems to want us to show a dialog if we hit the maximum. */
527 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
528 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
530 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
531 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
532 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
533 G_CALLBACK(on_easysetup_changed), self);
534 gtk_widget_show (self->entry_user_name);
535 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
536 gtk_widget_show (caption);
538 /* Prevent the use of some characters in the name,
539 * as required by our UI specification: */
540 GList *list_prevent = NULL;
541 list_prevent = g_list_append (list_prevent, "<");
542 list_prevent = g_list_append (list_prevent, ">");
543 modest_validating_entry_set_unallowed_characters (
544 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
545 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
546 on_entry_invalid_character, self);
547 g_list_free (list_prevent);
549 /* The username widgets: */
550 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
551 /* Auto-capitalization is the default, so let's turn it off: */
552 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
553 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
554 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
555 gtk_widget_show (self->entry_user_username);
556 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
557 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
558 G_CALLBACK(on_easysetup_changed), self);
559 gtk_widget_show (caption);
561 /* Prevent the use of some characters in the username,
562 * as required by our UI specification: */
563 modest_validating_entry_set_unallowed_characters_whitespace (
564 MODEST_VALIDATING_ENTRY (self->entry_user_username));
565 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
566 on_entry_invalid_character, self);
568 /* Set max length as in the UI spec:
569 * The UI spec seems to want us to show a dialog if we hit the maximum. */
570 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
571 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
574 /* The password widgets: */
575 self->entry_user_password = gtk_entry_new ();
576 /* Auto-capitalization is the default, so let's turn it off: */
577 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
578 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
579 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
580 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
581 caption = create_caption_new_with_asterisk (self, sizegroup,
582 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
583 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
584 G_CALLBACK(on_easysetup_changed), self);
585 gtk_widget_show (self->entry_user_password);
586 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
587 gtk_widget_show (caption);
589 /* The email address widgets: */
590 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
591 /* Auto-capitalization is the default, so let's turn it off: */
592 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
593 caption = create_caption_new_with_asterisk (self, sizegroup,
594 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
595 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
596 gtk_widget_show (self->entry_user_email);
597 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
598 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
599 G_CALLBACK(on_easysetup_changed), self);
600 gtk_widget_show (caption);
602 /* Set max length as in the UI spec:
603 * The UI spec seems to want us to show a dialog if we hit the maximum. */
604 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
605 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
609 gtk_widget_show (GTK_WIDGET (box));
611 return GTK_WIDGET (box);
614 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
616 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
618 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
619 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
620 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
621 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
622 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
623 gtk_widget_show (label);
625 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
626 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
627 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
628 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
629 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
630 gtk_widget_show (label);
632 gtk_widget_show (GTK_WIDGET (box));
633 return GTK_WIDGET (box);
636 /** Change the caption title for the incoming server,
637 * as specified in the UI spec:
639 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
641 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
642 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
644 (protocol == MODEST_PROTOCOL_STORE_POP ?
645 _("mail_fi_emailtype_pop3") :
646 _("mail_fi_emailtype_imap") );
649 /* Note that this produces a compiler warning,
650 * because the compiler does not know that the translated string will have a %s in it.
651 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
652 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
653 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
654 g_free(incomingserver_title);
657 /** Change the caption title for the incoming server,
658 * as specified in the UI spec:
660 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
662 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
663 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
665 /* Fill the combo with appropriately titled choices for POP or IMAP. */
666 /* The choices are the same, but the titles are different, as in the UI spec. */
667 modest_serversecurity_combo_box_fill (
668 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
671 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
673 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
674 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
678 update_incoming_server_title (self);
679 update_incoming_server_security_choices (self);
681 set_default_custom_servernames (self);
684 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
686 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
687 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
689 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
692 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
694 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
696 /* Show note that account type cannot be changed in future: */
697 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
698 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
699 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
700 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
701 gtk_widget_show (label);
703 /* Create a size group to be used by all captions.
704 * Note that HildonCaption does not create a default size group if we do not specify one.
705 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
706 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
708 /* The incoming server widgets: */
709 if (!self->combo_incoming_servertype)
710 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
711 easysetup_servertype_combo_box_set_active_servertype (
712 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
713 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
714 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
715 gtk_widget_show (self->combo_incoming_servertype);
716 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
717 gtk_widget_show (caption);
719 if(!self->entry_incomingserver)
721 self->entry_incomingserver = gtk_entry_new ();
722 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed",
723 G_CALLBACK(on_easysetup_changed), self);
725 /* Auto-capitalization is the default, so let's turn it off: */
726 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
727 set_default_custom_servernames (self);
729 if (self->caption_incoming)
730 gtk_widget_destroy (self->caption_incoming);
732 /* The caption title will be updated in update_incoming_server_title().
733 * so this default text will never be seen: */
734 /* (Note: Changing the title seems pointless. murrayc) */
735 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
736 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
737 update_incoming_server_title (self);
738 gtk_widget_show (self->entry_incomingserver);
739 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
740 gtk_widget_show (self->caption_incoming);
742 /* Change the caption title when the servertype changes,
743 * as in the UI spec: */
744 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
745 G_CALLBACK (on_combo_servertype_changed), self);
747 /* Remember when the servername was changed manually: */
748 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
749 G_CALLBACK (on_entry_incoming_servername_changed), self);
751 /* The secure connection widgets: */
752 if (!self->combo_incoming_security)
753 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
754 update_incoming_server_security_choices (self);
755 modest_serversecurity_combo_box_set_active_serversecurity (
756 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
757 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
758 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
759 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
760 G_CALLBACK (on_easysetup_changed), self);
761 gtk_widget_show (self->combo_incoming_security);
762 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
763 gtk_widget_show (caption);
765 if(!self->checkbox_incoming_auth)
767 self->checkbox_incoming_auth = gtk_check_button_new ();
768 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
769 G_CALLBACK (on_easysetup_changed), self);
771 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
772 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
774 gtk_widget_show (self->checkbox_incoming_auth);
775 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
776 gtk_widget_show (caption);
778 gtk_widget_show (GTK_WIDGET (box));
780 return GTK_WIDGET (box);
784 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
786 GtkWidget *widget = GTK_WIDGET (user_data);
788 /* Enable the widget only if the toggle button is active: */
789 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
790 gtk_widget_set_sensitive (widget, enable);
793 /* Make the sensitivity of a widget depend on a toggle button.
796 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
798 g_signal_connect (G_OBJECT (button), "toggled",
799 G_CALLBACK (on_toggle_button_changed), widget);
801 /* Set the starting sensitivity: */
802 on_toggle_button_changed (button, widget);
806 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
808 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
809 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
811 /* We set dirty here because setting it depending on the connection specific dialog
815 /* Create the window, if necessary: */
816 if (!(self->specific_window)) {
817 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
818 modest_connection_specific_smtp_window_fill_with_connections (
819 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
820 NULL /* account_name, not known yet. */);
823 /* Show the window: */
824 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
825 gtk_widget_show (self->specific_window);
828 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
830 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
831 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
832 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
835 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
837 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
839 /* Create a size group to be used by all captions.
840 * Note that HildonCaption does not create a default size group if we do not specify one.
841 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
842 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
844 /* The outgoing server widgets: */
845 if (!self->entry_outgoingserver)
847 self->entry_outgoingserver = gtk_entry_new ();
848 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
849 G_CALLBACK (on_easysetup_changed), self);
851 /* Auto-capitalization is the default, so let's turn it off: */
852 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
853 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
854 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
855 gtk_widget_show (self->entry_outgoingserver);
856 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
857 gtk_widget_show (caption);
858 set_default_custom_servernames (self);
860 /* The secure connection widgets: */
861 if (!self->combo_outgoing_security)
863 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
864 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
865 G_CALLBACK (on_easysetup_changed), self);
867 modest_serversecurity_combo_box_fill (
868 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
869 modest_serversecurity_combo_box_set_active_serversecurity (
870 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
871 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
872 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
873 gtk_widget_show (self->combo_outgoing_security);
874 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
875 gtk_widget_show (caption);
877 /* The secure authentication widgets: */
878 if (!self->combo_outgoing_auth)
880 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
881 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
882 G_CALLBACK (on_easysetup_changed), self);
884 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
885 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
886 gtk_widget_show (self->combo_outgoing_auth);
887 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
888 gtk_widget_show (caption);
890 GtkWidget *separator = gtk_hseparator_new ();
891 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
892 gtk_widget_show (separator);
894 /* connection-specific checkbox: */
895 if (!self->checkbox_outgoing_smtp_specific) {
896 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
897 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
899 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
900 G_CALLBACK (on_easysetup_changed), self);
903 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
904 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
905 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
906 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
907 gtk_widget_show (caption);
909 /* Connection-specific SMTP-Severs Edit button: */
910 if (!self->button_outgoing_smtp_servers)
911 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
912 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
913 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
914 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
915 gtk_widget_show (self->button_outgoing_smtp_servers);
916 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
917 gtk_widget_show (caption);
919 /* Only enable the button when the checkbox is checked: */
920 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
921 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
923 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
924 G_CALLBACK (on_button_outgoing_smtp_servers), self);
926 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
927 G_CALLBACK (on_entry_outgoing_servername_changed), self);
930 gtk_widget_show (GTK_WIDGET (box));
932 return GTK_WIDGET (box);
936 show_advanced_edit(gpointer user_data)
938 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
940 if (!(self->saved_account_name))
943 /* Show the Account Settings window: */
944 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
945 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
947 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
949 gtk_dialog_run (GTK_DIALOG (dialog));
951 gtk_widget_destroy (GTK_WIDGET (dialog));
953 return FALSE; /* Do not call this timeout callback again. */
957 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
959 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
961 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
962 * without recoding it to use non-gconf information.
963 * This account will be deleted if Finish is never actually clicked. */
965 gboolean saved = TRUE;
966 if (!(self->saved_account_name)) {
967 saved = create_account (self, FALSE);
973 if (!(self->saved_account_name))
976 /* Show the Account Settings window: */
977 show_advanced_edit(self);
979 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
981 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
982 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
983 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
984 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
985 gtk_widget_show (label);
987 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
988 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
989 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
990 gtk_widget_show (label);
992 if (!self->button_edit)
993 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
994 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
995 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
996 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
997 gtk_widget_show (self->button_edit);
998 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
999 gtk_widget_show (caption);
1001 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
1002 G_CALLBACK (on_button_edit_advanced_settings), self);
1004 gtk_widget_show (GTK_WIDGET (box));
1005 return GTK_WIDGET (box);
1012 on_response (ModestWizardDialog *wizard_dialog,
1016 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1017 if (response_id == GTK_RESPONSE_CANCEL) {
1018 /* Remove any temporarily-saved account that will not actually be needed: */
1019 if (self->saved_account_name) {
1020 modest_account_mgr_remove_account (self->account_manager,
1021 self->saved_account_name, FALSE);
1025 invoke_enable_buttons_vfunc (self);
1029 on_response_before (ModestWizardDialog *wizard_dialog,
1033 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1034 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1035 if (response_id == GTK_RESPONSE_CANCEL) {
1036 /* This is mostly copied from
1037 * src/maemo/modest-account-settings-dialog.c */
1040 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1041 _("imum_nc_wizard_confirm_lose_changes")));
1042 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1044 const gint dialog_response = gtk_dialog_run (dialog);
1045 gtk_widget_destroy (GTK_WIDGET (dialog));
1047 if (dialog_response != GTK_RESPONSE_OK)
1049 /* This is a nasty hack. murrayc. */
1050 /* Don't let the dialog close */
1051 g_signal_stop_emission_by_name (wizard_dialog, "response");
1058 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1060 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1062 /* Create the notebook to be used by the ModestWizardDialog base class:
1063 * Each page of the notebook will be a page of the wizard: */
1064 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1066 /* Set the notebook used by the ModestWizardDialog base class: */
1067 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1069 /* Set the wizard title:
1070 * The actual window title will be a combination of this and the page's tab label title. */
1071 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1073 /* Read in the information about known service providers: */
1074 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1076 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
1077 priv->presets = modest_presets_new (filepath);
1078 if (!(priv->presets)) {
1079 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
1082 g_assert(priv->presets);
1084 /* The server fields did not have been manually changed yet */
1085 priv->server_changes = 0;
1087 /* Get the account manager object,
1088 * so we can check for existing accounts,
1089 * and create new accounts: */
1090 self->account_manager = modest_runtime_get_account_mgr ();
1091 g_assert (self->account_manager);
1092 g_object_ref (self->account_manager);
1094 /* Create the common pages,
1096 self->page_welcome = create_page_welcome (self);
1097 self->page_account_details = create_page_account_details (self);
1098 self->page_user_details = create_page_user_details (self);
1100 /* Add the common pages: */
1101 gtk_notebook_append_page (notebook, self->page_welcome,
1102 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1103 gtk_notebook_append_page (notebook, self->page_account_details,
1104 gtk_label_new (_("mcen_ti_accountdetails")));
1105 gtk_notebook_append_page (notebook, self->page_user_details,
1106 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1108 /* Create and add the easysetup-specific pages,
1109 * because we need _some_ final page to enable the Next and Finish buttons: */
1110 create_subsequent_easysetup_pages (self);
1112 /* Connect to the dialog's response signal so we can enable/disable buttons
1113 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1114 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1115 * so that we can be enable/disable after ModestWizardDialog has done its own
1116 * enabling/disabling of buttons.
1118 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1119 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1121 * It's not enough to connect to the notebook's switch-page signal, because
1122 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1123 * _after_ switching the page (understandably).
1124 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1125 * then gtk_notebook_get_current_page() would return an incorrect value.)
1127 g_signal_connect_after (G_OBJECT (self), "response",
1128 G_CALLBACK (on_response), self);
1130 /* This is to show a confirmation dialog when the user hits cancel */
1131 g_signal_connect (G_OBJECT (self), "response",
1132 G_CALLBACK (on_response_before), self);
1134 /* Reset dirty, because there was no user input until now */
1135 priv->dirty = FALSE;
1137 /* When this window is shown, hibernation should not be possible,
1138 * because there is no sensible way to save the state: */
1139 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1140 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1143 ModestEasysetupWizardDialog*
1144 modest_easysetup_wizard_dialog_new (void)
1146 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1149 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1151 GtkNotebook *notebook = NULL;
1152 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1155 /* Create the custom pages: */
1156 if(!(self->page_custom_incoming)) {
1157 self->page_custom_incoming = create_page_custom_incoming (self);
1160 if(!(self->page_custom_outgoing)) {
1161 self->page_custom_outgoing = create_page_custom_outgoing (self);
1164 if(!(self->page_complete_customsetup)) {
1165 self->page_complete_customsetup = create_page_complete_custom (self);
1168 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1169 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1170 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1172 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1173 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1174 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1176 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1177 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1178 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1180 /* This is unnecessary with GTK+ 2.10: */
1181 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1184 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1186 GtkNotebook *notebook = NULL;
1187 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1190 /* Create the easysetup-specific pages: */
1191 if(!self->page_complete_easysetup)
1192 self->page_complete_easysetup = create_page_complete_easysetup (self);
1194 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1195 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1196 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1198 /* This is unnecessary with GTK+ 2.10: */
1199 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1201 /* After the user details page,
1202 * the following pages depend on whether "Other" was chosen
1203 * in the provider combobox on the account page
1205 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1207 if (easysetup_provider_combo_box_get_active_provider_id (
1208 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1209 /* "Other..." was selected: */
1211 /* Make sure that the easysetup pages do not exist: */
1212 if(self->page_complete_easysetup) {
1213 gtk_widget_destroy (self->page_complete_easysetup);
1214 self->page_complete_easysetup = NULL;
1217 create_subsequent_customsetup_pages (self);
1220 /* A specific provider was selected: */
1222 /* Make sure that the custom pages do not exist:
1223 * Because they will be used if they exist, when creating the account. */
1224 if(self->page_custom_incoming) {
1225 gtk_widget_destroy (self->page_custom_incoming);
1226 self->page_custom_incoming = NULL;
1229 if(self->page_custom_outgoing) {
1230 gtk_widget_destroy (self->page_custom_outgoing);
1231 self->page_custom_outgoing = NULL;
1234 if(self->page_complete_customsetup) {
1235 gtk_widget_destroy (self->page_complete_customsetup);
1236 self->page_complete_customsetup = NULL;
1240 /* Create the easysetup pages: */
1241 create_subsequent_easysetup_pages (self);
1247 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1252 gchar* at = g_utf8_strchr (email_address, -1, '@');
1253 if (!at || (g_utf8_strlen (at, -1) < 2))
1256 gchar* domain = g_utf8_next_char (at);
1260 const gchar* hostname = NULL;
1261 if (servertype == MODEST_PROTOCOL_STORE_POP)
1263 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1265 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1271 return g_strdup_printf ("%s.%s", hostname, domain);
1274 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1276 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1278 if (!account_wizard->entry_incomingserver)
1281 /* Set a default domain for the server, based on the email address,
1282 * if no server name was already specified.
1284 if (account_wizard->entry_user_email
1285 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1286 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1287 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1288 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1290 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1292 /* Do not set the INCOMING_CHANGED flag because of this edit */
1293 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1294 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1295 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1297 g_free (servername);
1300 /* Set a default domain for the server, based on the email address,
1301 * if no server name was already specified.
1303 if (!account_wizard->entry_outgoingserver)
1306 if (account_wizard->entry_user_email
1307 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1308 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1310 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1312 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1313 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1314 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1315 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1317 g_free (servername);
1322 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1324 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1326 /* Do extra validation that couldn't be done for every key press,
1327 * either because it was too slow,
1328 * or because it requires interaction:
1330 if (current_page == account_wizard->page_account_details) {
1331 /* Check that the title is not already in use: */
1332 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1333 if ((!account_title) || (strlen(account_title) == 0))
1336 /* Aavoid a clash with an existing display name: */
1337 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1338 account_wizard->account_manager, account_title);
1341 /* Warn the user via a dialog: */
1342 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1347 else if (current_page == account_wizard->page_user_details) {
1348 /* Check that the email address is valud: */
1349 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1350 if ((!email_address) || (strlen(email_address) == 0))
1353 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1354 /* Warn the user via a dialog: */
1355 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1357 /* Return focus to the email address entry: */
1358 gtk_widget_grab_focus (account_wizard->entry_user_email);
1359 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1364 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1365 create_subsequent_pages (account_wizard);
1368 /* TODO: The UI Spec wants us to check that the servernames are valid,
1369 * but does not specify how.
1372 if(next_page == account_wizard->page_custom_incoming) {
1373 set_default_custom_servernames (account_wizard);
1375 else if (next_page == account_wizard->page_custom_outgoing) {
1376 set_default_custom_servernames (account_wizard);
1377 /* Check if the server supports secure authentication */
1378 const ModestConnectionProtocol security_incoming =
1379 modest_serversecurity_combo_box_get_active_serversecurity (
1380 MODEST_SERVERSECURITY_COMBO_BOX (
1381 account_wizard->combo_incoming_security));
1382 if (gtk_toggle_button_get_active (
1383 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1384 && !modest_protocol_info_is_secure(security_incoming))
1386 GList* methods = check_for_supported_auth_methods(account_wizard);
1389 g_list_free(methods);
1392 g_list_free(methods);
1396 /* If this is the last page, and this is a click on Finish,
1397 * then attempt to create the dialog.
1399 if(!next_page) /* This is NULL when this is a click on Finish. */
1401 if (account_wizard->saved_account_name) {
1402 /* Just enable the already-saved account (temporarily created when
1403 * editing advanced settings): */
1404 modest_account_mgr_set_enabled (account_wizard->account_manager,
1405 account_wizard->saved_account_name, TRUE);
1407 create_account (account_wizard, TRUE /* enabled */);
1415 static gboolean entry_is_empty (GtkWidget *entry)
1420 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1421 if ((!text) || (strlen(text) == 0))
1428 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1430 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1432 gboolean enable_next = TRUE;
1433 if (current_page == account_wizard->page_welcome) {
1436 else if (current_page == account_wizard->page_account_details) {
1437 /* The account details title is mandatory: */
1438 if (entry_is_empty(account_wizard->entry_account_title))
1439 enable_next = FALSE;
1441 else if (current_page == account_wizard->page_user_details) {
1442 /* The user details username is mandatory: */
1443 if (entry_is_empty(account_wizard->entry_user_username))
1444 enable_next = FALSE;
1446 /* The user details email address is mandatory: */
1447 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1448 enable_next = FALSE;
1450 else if (current_page == account_wizard->page_custom_incoming) {
1451 /* The custom incoming server is mandatory: */
1452 if (entry_is_empty(account_wizard->entry_incomingserver))
1453 enable_next = FALSE;
1456 /* Enable the buttons,
1457 * identifying them via their associated response codes: */
1459 /* Disable the Finish button until we are on the last page,
1460 * because HildonWizardDialog enables this for all but the first page: */
1461 GtkNotebook *notebook = NULL;
1462 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1463 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1465 gint current = gtk_notebook_get_current_page (notebook);
1466 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1467 const gboolean is_last = (current == last);
1470 gtk_dialog_set_response_sensitive (dialog_base,
1471 MODEST_WIZARD_DIALOG_FINISH,
1475 /* Disable Next on the last page: */
1476 enable_next = FALSE;
1479 gtk_dialog_set_response_sensitive (dialog_base,
1480 MODEST_WIZARD_DIALOG_NEXT,
1485 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1487 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1488 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1491 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1492 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1493 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1494 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1496 /* Provide a vfunc implementation so we can decide
1497 * when to enable/disable the prev/next buttons.
1499 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1500 base_klass->before_next = on_before_next;
1501 base_klass->enable_buttons = on_enable_buttons;
1505 show_error (GtkWindow *parent_window, const gchar* text)
1507 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1509 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1516 gtk_dialog_run (dialog);
1517 gtk_widget_destroy (GTK_WIDGET (dialog));
1520 /** Attempt to create the account from the information that the user has entered.
1521 * @result: TRUE if the account was successfully created.
1524 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1526 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1528 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1534 /* We should have checked for this already,
1535 * and changed that name accordingly,
1536 * but let's check again just in case:
1538 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1541 /* Increment the non-user visible name if necessary,
1542 * based on the display name: */
1543 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1544 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1545 account_name_start, FALSE /* not a server account */);
1546 g_free (account_name_start);
1548 /* username and password (for both incoming and outgoing): */
1549 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1550 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1551 /* Incoming server: */
1552 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1553 * or modest_account_mgr_add_server_account will fail. */
1554 gchar* servername_incoming = NULL;
1555 guint serverport_incoming = 0;
1556 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1557 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1558 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1560 /* Get details from the specified presets: */
1561 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1562 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1565 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1566 TRUE /* incoming */);
1568 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1570 TRUE /* incoming */);
1571 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1573 TRUE /* incoming */);
1575 g_warning ("security incoming: %x", security_incoming);
1577 /* We don't check for SMTP here as that is impossible for an incoming server. */
1578 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1579 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1580 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1581 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1583 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1585 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1586 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1588 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1589 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1592 /* Use custom pages because no preset was specified: */
1593 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1595 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1596 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1598 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1599 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1601 /* The UI spec says:
1602 * If secure authentication is unchecked, allow sending username and password also as plain text.
1603 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1606 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1607 !modest_protocol_info_is_secure(protocol_security_incoming))
1609 GList* methods = check_for_supported_auth_methods(self);
1613 protocol_authentication_incoming = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
1616 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1619 /* First we add the 2 server accounts, and then we add the account that uses them.
1620 * If we don't do it in this order then we will experience a crash. */
1622 /* Add a (incoming) server account, to be used by the account: */
1623 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1624 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1625 store_name_start, TRUE /* server account */);
1626 g_free (store_name_start);
1627 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1629 servername_incoming,
1630 serverport_incoming,
1633 protocol_security_incoming,
1634 protocol_authentication_incoming);
1636 g_free (servername_incoming);
1639 /* TODO: Provide a Logical ID for the text: */
1640 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1644 /* Outgoing server: */
1645 gchar* servername_outgoing = NULL;
1646 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1647 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1648 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1649 guint serverport_outgoing = 0;
1653 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1654 FALSE /* incoming */);
1656 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1658 FALSE /* incoming */);
1660 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1661 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1662 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1663 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1665 ModestPresetsSecurity security_outgoing =
1666 modest_presets_get_info_server_security (priv->presets, provider_id,
1667 FALSE /* incoming */);
1669 /* TODO: There is no SMTP authentication enum for presets,
1670 so we should probably check what the server supports. */
1671 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1672 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1673 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1674 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1675 serverport_outgoing = 465;
1676 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1678 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1679 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1683 /* Use custom pages because no preset was specified: */
1684 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1686 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1688 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1689 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1691 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1692 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1695 /* Add a (outgoing) server account to be used by the account: */
1696 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1697 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1698 transport_name_start, TRUE /* server account */);
1699 g_free (transport_name_start);
1700 created = modest_account_mgr_add_server_account (self->account_manager,
1702 servername_outgoing,
1703 serverport_outgoing,
1706 protocol_security_outgoing,
1707 protocol_authentication_outgoing);
1709 g_free (servername_outgoing);
1712 /* TODO: Provide a Logical ID for the text: */
1713 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1718 /* Create the account, which will contain the two "server accounts": */
1719 created = modest_account_mgr_add_account (self->account_manager, account_name,
1720 store_name, /* The name of our POP/IMAP server account. */
1721 transport_name, /* The name of our SMTP server account. */
1723 g_free (store_name);
1724 g_free (transport_name);
1727 /* TODO: Provide a Logical ID for the text: */
1728 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1733 /* There must be at least one account now: */
1734 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1735 * fixed in versions after 3.1. */
1736 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1737 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1739 /* The user name and email address must be set additionally: */
1740 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1741 modest_account_mgr_set_string (self->account_manager, account_name,
1742 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1744 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1745 modest_account_mgr_set_string (self->account_manager, account_name,
1746 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1748 /* Set the display name: */
1749 modest_account_mgr_set_string (self->account_manager, account_name,
1750 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1752 /* Set retrieve type */
1753 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1754 modest_account_mgr_set_string (self->account_manager, account_name,
1755 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1757 /* Save the connection-specific SMTP server accounts. */
1758 gboolean result = TRUE;
1759 if (self->specific_window)
1760 result = modest_connection_specific_smtp_window_save_server_accounts (
1761 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1763 g_free (self->saved_account_name);
1764 self->saved_account_name = g_strdup (account_name);
1766 g_free (account_name);