1 /* Copyright (c) 2007, Nokia Corporation
7 #include "modest-easysetup-wizard.h"
8 #include <glib/gi18n.h>
9 #include <gtk/gtknotebook.h>
10 #include <gtk/gtkvbox.h>
11 #include <gtk/gtklabel.h>
12 #include <gtk/gtkcombobox.h>
13 #include <gtk/gtkentry.h>
14 #include <gtk/gtkbutton.h>
15 #include <gtk/gtkcheckbutton.h>
16 #include <gtk/gtkmessagedialog.h>
17 #include <gtk/gtkseparator.h>
18 #include <hildon-widgets/hildon-caption.h>
19 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
20 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
21 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
22 #include "widgets/modest-serversecurity-combo-box.h"
23 #include "widgets/modest-secureauth-combo-box.h"
24 #include "widgets/modest-validating-entry.h"
25 #include "modest-text-utils.h"
26 #include "modest-account-mgr.h"
27 #include "modest-account-mgr-helpers.h"
28 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
29 #include "maemo/modest-connection-specific-smtp-window.h"
30 #include "maemo/modest-maemo-ui-constants.h"
31 #include <gconf/gconf-client.h>
32 #include <string.h> /* For strlen(). */
34 /* Include config.h so that _() works: */
39 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
41 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
43 #define WIZARD_DIALOG_GET_PRIVATE(o) \
44 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
46 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
48 struct _ModestEasysetupWizardDialogPrivate
50 ModestPresets *presets;
54 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
55 GValue *value, GParamSpec *pspec)
57 switch (property_id) {
59 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
64 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
65 const GValue *value, GParamSpec *pspec)
67 switch (property_id) {
69 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
74 modest_easysetup_wizard_dialog_dispose (GObject *object)
76 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
77 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
81 modest_easysetup_wizard_dialog_finalize (GObject *object)
83 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
84 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
86 if (self->account_manager)
87 g_object_unref (G_OBJECT (self->account_manager));
90 modest_presets_destroy (priv->presets);
92 if (self->specific_window)
93 gtk_widget_destroy (self->specific_window);
95 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
99 show_error (GtkWindow *parent_window, const gchar* text);
102 create_account (ModestEasysetupWizardDialog *self);
105 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
108 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
110 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
113 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
115 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
117 /* Call the vfunc, which may be overridden by derived classes: */
118 if (klass->enable_buttons) {
119 GtkNotebook *notebook = NULL;
120 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
122 const gint current_page_num = gtk_notebook_get_current_page (notebook);
123 if (current_page_num == -1)
126 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
127 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
132 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
134 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
136 invoke_enable_buttons_vfunc(self);
140 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
142 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
144 invoke_enable_buttons_vfunc(self);
147 /** This is a convenience function to create a caption containing a mandatory widget.
148 * When the widget is edited, the enable_buttons() vfunc will be called.
150 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
155 HildonCaptionStatus flag)
157 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
159 /* The translated strings seem to already contain the *,
160 * but this code can be used if that is not true in future.
163 /* Add a * character to indicate mandatory fields,
164 * as specified in our "Email UI Specification": */
165 if (flag == HILDON_CAPTION_MANDATORY) {
166 gchar* title = g_strdup_printf("%s*", value);
167 caption = hildon_caption_new (group, title, control, icon, flag);
171 caption = hildon_caption_new (group, value, control, icon, flag);
174 /* Connect to the appropriate changed signal for the widget,
175 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
177 if (GTK_IS_ENTRY (control)) {
178 g_signal_connect (G_OBJECT (control), "changed",
179 G_CALLBACK (on_caption_entry_changed), self);
182 else if (GTK_IS_COMBO_BOX (control)) {
183 g_signal_connect (G_OBJECT (control), "changed",
184 G_CALLBACK (on_caption_combobox_changed), self);
191 create_page_welcome (ModestEasysetupWizardDialog *self)
193 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
194 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
195 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
196 gtk_widget_show (label);
197 gtk_widget_show (GTK_WIDGET (box));
198 return GTK_WIDGET (box);
202 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
204 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
206 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
208 /* Fill the providers combo, based on the selected country: */
209 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
210 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
211 easysetup_provider_combo_box_fill (
212 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
216 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
218 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
220 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
222 /* Fill the providers combo, based on the selected country: */
223 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
224 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
226 gchar* domain_name = NULL;
228 domain_name = modest_presets_get_domain (priv->presets, provider_id);
231 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
233 if (self->entry_user_email)
234 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
236 g_free (domain_name);
238 g_free (provider_id);
243 create_page_account_details (ModestEasysetupWizardDialog *self)
245 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
246 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
247 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
248 gtk_widget_show (label);
250 /* Create a size group to be used by all captions.
251 * Note that HildonCaption does not create a default size group if we do not specify one.
252 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
253 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
255 /* The country widgets: */
256 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
257 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
258 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
259 gtk_widget_show (self->combo_account_country);
260 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
261 gtk_widget_show (caption);
263 /* connect to country combo's changed signal, so we can fill the provider combo: */
264 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
265 G_CALLBACK (on_combo_account_country), self);
267 GtkWidget *separator = gtk_hseparator_new ();
268 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
269 gtk_widget_show (separator);
271 /* The service provider widgets: */
272 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
274 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
275 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
276 gtk_widget_show (self->combo_account_serviceprovider);
277 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
278 gtk_widget_show (caption);
280 /* connect to providers combo's changed signal, so we can fill the email address: */
281 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
282 G_CALLBACK (on_combo_account_serviceprovider), self);
284 /* TODO: Default to the current country somehow.
285 * But I don't know how to get the information that is specified in the
286 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
288 * This is probably not the best choice of gconf key:
289 * This is the "mcc used in the last pairing", ie. the last connection you made.
290 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
293 GConfClient *client = gconf_client_get_default ();
294 GError *error = NULL;
295 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
296 gint mcc_id = gconf_client_get_int(client, key, &error);
302 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
303 g_error_free (error);
309 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
310 * This might just be a Maemo bug.
314 /* For now, we default to Finland when there is nothing better: */
318 easysetup_country_combo_box_set_active_country_id (
319 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
322 /* The description widgets: */
323 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
325 /* Set a default account title, choosing one that does not already exist: */
326 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
327 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
328 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
329 self->account_manager, default_account_name_start);
330 g_free (default_account_name_start);
331 default_account_name_start = NULL;
333 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
334 g_free (default_account_name);
335 default_account_name = NULL;
337 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
338 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
339 gtk_widget_show (self->entry_account_title);
340 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
341 gtk_widget_show (caption);
343 /* Prevent the use of some characters in the account title,
344 * as required by our UI specification: */
345 GList *list_prevent = NULL;
346 list_prevent = g_list_append (list_prevent, "\\");
347 list_prevent = g_list_append (list_prevent, "/");
348 list_prevent = g_list_append (list_prevent, ":");
349 list_prevent = g_list_append (list_prevent, "*");
350 list_prevent = g_list_append (list_prevent, "?");
351 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
352 list_prevent = g_list_append (list_prevent, "“");
353 list_prevent = g_list_append (list_prevent, "<");
354 list_prevent = g_list_append (list_prevent, ">");
355 list_prevent = g_list_append (list_prevent, "|");
356 list_prevent = g_list_append (list_prevent, "^");
357 easysetup_validating_entry_set_unallowed_characters (
358 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
359 g_list_free (list_prevent);
361 /* Set max length as in the UI spec:
362 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
363 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
365 gtk_widget_show (GTK_WIDGET (box));
367 return GTK_WIDGET (box);
371 create_page_user_details (ModestEasysetupWizardDialog *self)
373 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
375 /* Create a size group to be used by all captions.
376 * Note that HildonCaption does not create a default size group if we do not specify one.
377 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
378 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
380 /* The name widgets: */
381 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
382 /* Set max length as in the UI spec:
383 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
384 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
385 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
386 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
387 gtk_widget_show (self->entry_user_name);
388 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
389 gtk_widget_show (caption);
391 /* Prevent the use of some characters in the name,
392 * as required by our UI specification: */
393 GList *list_prevent = NULL;
394 list_prevent = g_list_append (list_prevent, "<");
395 list_prevent = g_list_append (list_prevent, ">");
396 easysetup_validating_entry_set_unallowed_characters (
397 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
398 g_list_free (list_prevent);
400 /* The username widgets: */
401 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
402 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
403 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
404 gtk_widget_show (self->entry_user_username);
405 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
406 gtk_widget_show (caption);
408 /* Prevent the use of some characters in the username,
409 * as required by our UI specification: */
410 easysetup_validating_entry_set_unallowed_characters_whitespace (
411 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
413 /* Set max length as in the UI spec:
414 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
415 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
417 /* The password widgets: */
418 self->entry_user_password = gtk_entry_new ();
419 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
420 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
421 caption = create_caption_new_with_asterix (self, sizegroup,
422 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
423 gtk_widget_show (self->entry_user_password);
424 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
425 gtk_widget_show (caption);
427 /* The email address widgets: */
428 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
429 caption = create_caption_new_with_asterix (self, sizegroup,
430 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
431 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
432 gtk_widget_show (self->entry_user_email);
433 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
434 gtk_widget_show (caption);
436 /* Set max length as in the UI spec:
437 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
438 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
441 gtk_widget_show (GTK_WIDGET (box));
443 return GTK_WIDGET (box);
446 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
448 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
449 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
450 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
451 gtk_widget_show (label);
452 gtk_widget_show (GTK_WIDGET (box));
453 return GTK_WIDGET (box);
456 /** Change the caption title for the incoming server,
457 * as specified in the UI spec:
459 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
461 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
462 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
464 (protocol == MODEST_PROTOCOL_STORE_POP ?
465 _("mail_fi_emailtype_pop3") :
466 _("mail_fi_emailtype_imap") );
469 /* Note that this produces a compiler warning,
470 * because the compiler does not know that the translated string will have a %s in it.
471 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
472 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
473 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
474 g_free(incomingserver_title);
477 /** Change the caption title for the incoming server,
478 * as specified in the UI spec:
480 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
482 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
483 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
485 /* Fill the combo with appropriately titled choices for POP or IMAP. */
486 /* The choices are the same, but the titles are different, as in the UI spec. */
487 modest_serversecurity_combo_box_fill (
488 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
491 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
493 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
494 update_incoming_server_title (self);
495 update_incoming_server_security_choices (self);
498 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
500 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
502 /* Create a size group to be used by all captions.
503 * Note that HildonCaption does not create a default size group if we do not specify one.
504 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
505 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
507 /* The incoming server widgets: */
508 if (!self->combo_incoming_servertype)
509 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
510 easysetup_servertype_combo_box_set_active_servertype (
511 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
512 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
513 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
514 gtk_widget_show (self->combo_incoming_servertype);
515 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
516 gtk_widget_show (caption);
518 if(!self->entry_incomingserver)
519 self->entry_incomingserver = gtk_entry_new ();
520 set_default_custom_servernames (self);
522 if (self->caption_incoming)
523 gtk_widget_destroy (self->caption_incoming);
525 /* The caption title will be updated in update_incoming_server_title().
526 * so this default text will never be seen: */
527 /* (Note: Changing the title seems pointless. murrayc) */
528 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
529 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
530 update_incoming_server_title (self);
531 gtk_widget_show (self->entry_incomingserver);
532 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
533 gtk_widget_show (self->caption_incoming);
535 /* Change the caption title when the servertype changes,
536 * as in the UI spec: */
537 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
538 G_CALLBACK (on_combo_servertype_changed), self);
540 /* The secure connection widgets: */
541 if (!self->combo_incoming_security)
542 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
543 update_incoming_server_security_choices (self);
544 modest_serversecurity_combo_box_set_active_serversecurity (
545 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
546 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
547 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
548 gtk_widget_show (self->combo_incoming_security);
549 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
550 gtk_widget_show (caption);
552 if(!self->checkbox_incoming_auth)
553 self->checkbox_incoming_auth =
554 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
555 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, MODEST_MARGIN_HALF);
556 gtk_widget_show (self->checkbox_incoming_auth);
558 gtk_widget_show (GTK_WIDGET (box));
560 return GTK_WIDGET (box);
564 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
566 GtkWidget *widget = GTK_WIDGET (user_data);
568 /* Enable the widget only if the toggle button is active: */
569 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
570 gtk_widget_set_sensitive (widget, enable);
573 /* Make the sensitivity of a widget depend on a toggle button.
576 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
578 g_signal_connect (G_OBJECT (button), "toggled",
579 G_CALLBACK (on_toggle_button_changed), widget);
581 /* Set the starting sensitivity: */
582 on_toggle_button_changed (button, widget);
586 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
588 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
590 /* Create the window, if necessary: */
591 if (!(self->specific_window)) {
592 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
593 modest_connection_specific_smtp_window_fill_with_connections (
594 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
595 NULL /* account_name, not known yet. */);
598 /* Show the window: */
599 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
600 gtk_widget_show (self->specific_window);
603 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
605 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
607 /* Create a size group to be used by all captions.
608 * Note that HildonCaption does not create a default size group if we do not specify one.
609 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
610 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
612 /* The outgoing server widgets: */
613 if (!self->entry_outgoingserver)
614 self->entry_outgoingserver = gtk_entry_new ();
615 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
616 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
617 gtk_widget_show (self->entry_outgoingserver);
618 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
619 gtk_widget_show (caption);
620 set_default_custom_servernames (self);
622 /* The secure connection widgets: */
623 if (!self->combo_outgoing_security)
624 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
625 modest_serversecurity_combo_box_fill (
626 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
627 modest_serversecurity_combo_box_set_active_serversecurity (
628 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
629 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
630 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
631 gtk_widget_show (self->combo_outgoing_security);
632 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
633 gtk_widget_show (caption);
635 /* The secure authentication widgets: */
636 if (!self->combo_outgoing_auth)
637 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
638 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
639 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
640 gtk_widget_show (self->combo_outgoing_auth);
641 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
642 gtk_widget_show (caption);
644 /* connection-specific checkbox: */
645 if (!self->checkbox_outgoing_smtp_specific) {
646 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
647 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
650 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, MODEST_MARGIN_HALF);
651 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
653 GtkWidget *separator = gtk_hseparator_new ();
654 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
655 gtk_widget_show (separator);
657 /* Connection-specific SMTP-Severs Edit button: */
658 if (!self->button_outgoing_smtp_servers)
659 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
660 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
661 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
662 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
663 gtk_widget_show (self->button_outgoing_smtp_servers);
664 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
665 gtk_widget_show (caption);
667 /* Only enable the button when the checkbox is checked: */
668 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
669 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
671 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
672 G_CALLBACK (on_button_outgoing_smtp_servers), self);
675 gtk_widget_show (GTK_WIDGET (box));
677 return GTK_WIDGET (box);
680 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
682 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
683 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
684 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
685 gtk_widget_show (label);
687 if (!self->button_edit)
688 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
689 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
690 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
691 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
692 gtk_widget_show (self->button_edit);
693 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
694 gtk_widget_show (caption);
696 gtk_widget_show (GTK_WIDGET (box));
697 return GTK_WIDGET (box);
704 on_response (ModestWizardDialog *wizard_dialog,
708 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
709 invoke_enable_buttons_vfunc (self);
713 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
715 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
717 /* Create the notebook to be used by the ModestWizardDialog base class:
718 * Each page of the notebook will be a page of the wizard: */
719 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
721 /* Set the notebook used by the ModestWizardDialog base class: */
722 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
724 /* Set the wizard title:
725 * The actual window title will be a combination of this and the page's tab label title. */
726 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
728 /* Read in the information about known service providers: */
729 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
731 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
732 priv->presets = modest_presets_new (filepath);
733 if (!(priv->presets)) {
734 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
737 g_assert(priv->presets);
740 /* Get the account manager object,
741 * so we can check for existing accounts,
742 * and create new accounts: */
743 self->account_manager = modest_runtime_get_account_mgr ();
744 g_assert (self->account_manager);
745 g_object_ref (self->account_manager);
747 /* Create the common pages,
749 self->page_welcome = create_page_welcome (self);
750 self->page_account_details = create_page_account_details (self);
751 self->page_user_details = create_page_user_details (self);
753 /* Add the common pages: */
754 gtk_notebook_append_page (notebook, self->page_welcome,
755 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
756 gtk_notebook_append_page (notebook, self->page_account_details,
757 gtk_label_new (_("mcen_ti_accountdetails")));
758 gtk_notebook_append_page (notebook, self->page_user_details,
759 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
761 /* Create and add the easysetup-specific pages,
762 * because we need _some_ final page to enable the Next and Finish buttons: */
763 create_subsequent_easysetup_pages (self);
766 /* Connect to the dialog's response signal so we can enable/disable buttons
767 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
768 * Note that we use g_signal_connect_after() instead of g_signal_connect()
769 * so that we can be enable/disable after ModestWizardDialog has done its own
770 * enabling/disabling of buttons.
772 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
773 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
775 * It's not enough to connect to the notebook's switch-page signal, because
776 * ModestWizardDialog's "response" signal handler enables the buttons itself,
777 * _after_ switching the page (understandably).
778 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
779 * then gtk_notebook_get_current_page() would return an incorrect value.)
781 g_signal_connect_after (G_OBJECT (self), "response",
782 G_CALLBACK (on_response), self);
785 ModestEasysetupWizardDialog*
786 modest_easysetup_wizard_dialog_new (void)
788 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
791 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
793 GtkNotebook *notebook = NULL;
794 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
797 /* Create the custom pages: */
798 if(!(self->page_custom_incoming)) {
799 self->page_custom_incoming = create_page_custom_incoming (self);
802 if(!(self->page_custom_outgoing)) {
803 self->page_custom_outgoing = create_page_custom_outgoing (self);
806 if(!(self->page_complete_customsetup)) {
807 self->page_complete_customsetup = create_page_complete_custom (self);
810 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
811 gtk_notebook_append_page (notebook, self->page_custom_incoming,
812 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
814 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
815 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
816 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
818 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
819 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
820 gtk_label_new (_("mcen_ti_emailsetup_complete")));
823 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
825 GtkNotebook *notebook = NULL;
826 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
829 /* Create the easysetup-specific pages: */
830 if(!self->page_complete_easysetup)
831 self->page_complete_easysetup = create_page_complete_easysetup (self);
833 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
834 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
835 gtk_label_new (_("mcen_ti_emailsetup_complete")));
838 /* After the user details page,
839 * the following pages depend on whether "Other" was chosen
840 * in the provider combobox on the account page
842 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
844 if (easysetup_provider_combo_box_get_active_provider_id (
845 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
846 /* "Other..." was selected: */
848 /* Make sure that the easysetup pages do not exist: */
849 if(self->page_complete_easysetup) {
850 gtk_widget_destroy (self->page_complete_easysetup);
851 self->page_complete_easysetup = NULL;
854 create_subsequent_customsetup_pages (self);
857 /* A specific provider was selected: */
859 /* Make sure that the custom pages do not exist:
860 * Because they will be used if they exist, when creating the account. */
861 if(self->page_custom_incoming) {
862 gtk_widget_destroy (self->page_custom_incoming);
863 self->page_custom_incoming = NULL;
866 if(self->page_custom_outgoing) {
867 gtk_widget_destroy (self->page_custom_outgoing);
868 self->page_custom_outgoing = NULL;
871 if(self->page_complete_customsetup) {
872 gtk_widget_destroy (self->page_complete_customsetup);
873 self->page_complete_customsetup = NULL;
877 /* Create the easysetup pages: */
878 create_subsequent_easysetup_pages (self);
884 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
889 gchar* at = g_utf8_strchr (email_address, -1, '@');
890 if (!at || (g_utf8_strlen (at, -1) < 2))
893 gchar* domain = g_utf8_next_char (at);
897 const gchar* hostname = NULL;
898 if (servertype == MODEST_PROTOCOL_STORE_POP)
900 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
902 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
908 return g_strdup_printf ("%s.%s", hostname, domain);
911 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
913 if (!account_wizard->entry_incomingserver)
916 /* Set a default domain for the server, based on the email address,
917 * if no server name was already specified.
919 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
920 if ((!incoming_existing || (strlen(incoming_existing) == 0))
921 && account_wizard->entry_user_email) {
922 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
923 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
924 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
926 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
927 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
931 /* Set a default domain for the server, based on the email address,
932 * if no server name was already specified.
934 if (!account_wizard->entry_outgoingserver)
937 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
938 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
939 && account_wizard->entry_user_email) {
940 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
942 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
943 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
949 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
951 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
953 /* Do extra validation that couldn't be done for every key press,
954 * either because it was too slow,
955 * or because it requires interaction:
957 if (current_page == account_wizard->page_account_details) {
958 /* Check that the title is not already in use: */
959 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
960 if ((!account_title) || (strlen(account_title) == 0))
963 /* Aavoid a clash with an existing display name: */
964 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
965 account_wizard->account_manager, account_title);
968 /* Warn the user via a dialog: */
969 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
974 else if (current_page == account_wizard->page_user_details) {
975 /* Check that the email address is valud: */
976 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
977 if ((!email_address) || (strlen(email_address) == 0))
980 if (!modest_text_utils_validate_email_address (email_address)) {
981 /* Warn the user via a dialog: */
982 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
984 /* Return focus to the email address entry: */
985 gtk_widget_grab_focus (account_wizard->entry_user_email);
990 /* Make sure that the subsequent pages are appropriate for the provider choice. */
991 create_subsequent_pages (account_wizard);
994 /* TODO: The UI Spec wants us to check that the servernames are valid,
995 * but does not specify how.
998 if(next_page == account_wizard->page_custom_incoming) {
999 set_default_custom_servernames (account_wizard);
1001 else if (next_page == account_wizard->page_custom_outgoing) {
1002 set_default_custom_servernames (account_wizard);
1005 /* If this is the last page, and this is a click on Finish,
1006 * then attempt to create the dialog.
1008 if(!next_page) /* This is NULL when this is a click on Finish. */
1010 create_account (account_wizard);
1017 static gboolean entry_is_empty (GtkWidget *entry)
1022 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1023 if ((!text) || (strlen(text) == 0))
1030 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1032 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1034 gboolean enable_next = TRUE;
1035 if (current_page == account_wizard->page_welcome) {
1038 else if (current_page == account_wizard->page_account_details) {
1039 /* The account details title is mandatory: */
1040 if (entry_is_empty(account_wizard->entry_account_title))
1041 enable_next = FALSE;
1043 else if (current_page == account_wizard->page_user_details) {
1044 /* The user details username is mandatory: */
1045 if (entry_is_empty(account_wizard->entry_user_username))
1046 enable_next = FALSE;
1048 /* The user details email address is mandatory: */
1049 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1050 enable_next = FALSE;
1052 else if (current_page == account_wizard->page_custom_incoming) {
1053 /* The custom incoming server is mandatory: */
1054 if (entry_is_empty(account_wizard->entry_incomingserver))
1055 enable_next = FALSE;
1058 /* Enable the buttons,
1059 * identifying them via their associated response codes:
1061 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1062 gtk_dialog_set_response_sensitive (dialog_base,
1063 MODEST_WIZARD_DIALOG_NEXT,
1066 /* Disable the Finish button until we are on the last page,
1067 * because HildonWizardDialog enables this for all but the first page: */
1068 GtkNotebook *notebook = NULL;
1069 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1071 gint current = gtk_notebook_get_current_page (notebook);
1072 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1073 gboolean is_last = (current == last);
1076 gtk_dialog_set_response_sensitive (dialog_base,
1077 MODEST_WIZARD_DIALOG_FINISH,
1083 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1085 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1086 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1089 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1090 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1091 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1092 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1094 /* Provide a vfunc implementation so we can decide
1095 * when to enable/disable the prev/next buttons.
1097 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1098 base_klass->before_next = on_before_next;
1099 base_klass->enable_buttons = on_enable_buttons;
1103 show_error (GtkWindow *parent_window, const gchar* text)
1105 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1111 gtk_dialog_run (dialog);
1112 gtk_widget_destroy (GTK_WIDGET (dialog));
1115 /** Attempt to create the account from the information that the user has entered.
1116 * @result: TRUE if the account was successfully created.
1119 create_account (ModestEasysetupWizardDialog *self)
1121 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1123 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1129 /* We should have checked for this already,
1130 * and changed that name accordingly,
1131 * but let's check again just in case:
1133 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1136 /* Increment the non-user visible name if necessary,
1137 * based on the display name: */
1138 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1139 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1140 account_name_start, FALSE /* not a server account */);
1141 g_free (account_name_start);
1143 /* username and password (for both incoming and outgoing): */
1144 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1145 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1147 /* Incoming server: */
1148 /* Note: We need something as default for the ModestProtocol values,
1149 * or modest_account_mgr_add_server_account will fail. */
1150 gchar* servername_incoming = NULL;
1151 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1152 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1153 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1155 /* Get details from the specified presets: */
1156 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1157 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1161 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1162 TRUE /* incoming */);
1164 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1165 TRUE /* incoming */);
1168 /* We don't check for SMTP here as that is impossible for an incoming server. */
1169 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1170 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1171 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1172 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1174 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1175 TRUE /* incoming */);
1178 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1179 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1181 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1182 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1185 /* Use custom pages because no preset was specified: */
1186 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1188 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1189 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1191 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1192 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1194 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1195 ? MODEST_PROTOCOL_AUTH_PASSWORD
1196 : MODEST_PROTOCOL_AUTH_NONE;
1200 /* First we add the 2 server accounts, and then we add the account that uses them.
1201 * If we don't do it in this order then we will experience a crash. */
1203 /* Add a (incoming) server account, to be used by the account: */
1204 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1205 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1206 store_name_start, TRUE /* server account */);
1207 g_free (store_name_start);
1208 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1210 servername_incoming,
1213 protocol_security_incoming,
1214 protocol_authentication_incoming);
1216 g_free (servername_incoming);
1219 /* TODO: Provide a Logical ID for the text: */
1220 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1225 /* There must be at least one account now: */
1226 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1229 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1231 g_slist_free (account_names);
1234 /* Outgoing server: */
1235 gchar* servername_outgoing = NULL;
1236 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1237 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1238 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1242 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1243 FALSE /* incoming */);
1245 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1246 FALSE /* incoming */);
1248 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1249 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1250 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1251 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1253 ModestPresetsSecurity security_outgoing =
1254 modest_presets_get_info_server_security (priv->presets, provider_id,
1255 FALSE /* incoming */);
1257 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1258 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1259 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1261 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1262 /* TODO: There is no SMTP authentication enum for presets. */
1265 /* Use custom pages because no preset was specified: */
1266 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1268 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1270 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1271 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1273 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1274 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1277 gboolean specific = gtk_toggle_button_get_active (
1278 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1283 /* Add a (outgoing) server account to be used by the account: */
1284 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1285 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1286 transport_name_start, TRUE /* server account */);
1287 g_free (transport_name_start);
1288 created = modest_account_mgr_add_server_account (self->account_manager,
1290 servername_outgoing,
1293 protocol_security_outgoing,
1294 protocol_authentication_outgoing);
1296 g_free (servername_outgoing);
1299 /* TODO: Provide a Logical ID for the text: */
1300 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1305 /* Create the account, which will contain the two "server accounts": */
1306 created = modest_account_mgr_add_account (self->account_manager, account_name,
1307 store_name, /* The name of our POP/IMAP server account. */
1308 transport_name /* The name of our SMTP server account. */);
1309 g_free (store_name);
1310 g_free (transport_name);
1313 /* TODO: Provide a Logical ID for the text: */
1314 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1318 /* The user name and email address must be set additionally: */
1319 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1320 modest_account_mgr_set_string (self->account_manager, account_name,
1321 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1323 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1324 modest_account_mgr_set_string (self->account_manager, account_name,
1325 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1327 /* Set the display name: */
1328 modest_account_mgr_set_string (self->account_manager, account_name,
1329 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1331 /* Save the connection-specific SMTP server accounts. */
1332 if (self->specific_window)
1333 return modest_connection_specific_smtp_window_save_server_accounts (
1334 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1336 g_free (account_name);