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 <hildon-widgets/hildon-caption.h>
18 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
19 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
20 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
21 #include "maemo/easysetup/modest-easysetup-serversecurity-combo-box.h"
22 #include "maemo/easysetup/modest-easysetup-secureauth-combo-box.h"
23 #include "maemo/easysetup/modest-validating-entry.h"
24 #include "modest-text-utils.h"
25 #include "modest-account-mgr.h"
26 #include "modest-account-mgr-helpers.h"
27 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
28 #include "maemo/modest-connection-specific-smtp-window.h"
29 #include <gconf/gconf-client.h>
30 #include <string.h> /* For strlen(). */
32 /* Include config.h so that _() works: */
37 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
39 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
41 #define WIZARD_DIALOG_GET_PRIVATE(o) \
42 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
44 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
46 struct _ModestEasysetupWizardDialogPrivate
48 ModestPresets *presets;
52 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
53 GValue *value, GParamSpec *pspec)
55 switch (property_id) {
57 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
62 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
63 const GValue *value, GParamSpec *pspec)
65 switch (property_id) {
67 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
72 modest_easysetup_wizard_dialog_dispose (GObject *object)
74 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
75 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
79 modest_easysetup_wizard_dialog_finalize (GObject *object)
81 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
82 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
84 if (self->account_manager)
85 g_object_unref (G_OBJECT (self->account_manager));
88 modest_presets_destroy (priv->presets);
90 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
94 show_error (GtkWindow *parent_window, const gchar* text);
97 create_account (ModestEasysetupWizardDialog *self);
100 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
103 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
105 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
108 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
110 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
112 /* Call the vfunc, which may be overridden by derived classes: */
113 if (klass->enable_buttons) {
114 GtkNotebook *notebook = NULL;
115 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
117 const gint current_page_num = gtk_notebook_get_current_page (notebook);
118 if (current_page_num == -1)
121 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
122 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
127 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
129 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
131 invoke_enable_buttons_vfunc(self);
135 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
137 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
139 invoke_enable_buttons_vfunc(self);
142 /** This is a convenience function to create a caption containing a mandatory widget.
143 * When the widget is edited, the enable_buttons() vfunc will be called.
145 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
150 HildonCaptionStatus flag)
152 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
154 /* The translated strings seem to already contain the *,
155 * but this code can be used if that is not true in future.
158 /* Add a * character to indicate mandatory fields,
159 * as specified in our "Email UI Specification": */
160 if (flag == HILDON_CAPTION_MANDATORY) {
161 gchar* title = g_strdup_printf("%s*", value);
162 caption = hildon_caption_new (group, title, control, icon, flag);
166 caption = hildon_caption_new (group, value, control, icon, flag);
169 /* Connect to the appropriate changed signal for the widget,
170 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
172 if (GTK_IS_ENTRY (control)) {
173 g_signal_connect (G_OBJECT (control), "changed",
174 G_CALLBACK (on_caption_entry_changed), self);
177 else if (GTK_IS_COMBO_BOX (control)) {
178 g_signal_connect (G_OBJECT (control), "changed",
179 G_CALLBACK (on_caption_combobox_changed), self);
186 create_page_welcome (ModestEasysetupWizardDialog *self)
188 GtkWidget *box = gtk_vbox_new (FALSE, 2);
189 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
190 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
191 gtk_widget_show (label);
192 gtk_widget_show (GTK_WIDGET (box));
193 return GTK_WIDGET (box);
197 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
199 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
201 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
203 /* Fill the providers combo, based on the selected country: */
204 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
205 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
206 easysetup_provider_combo_box_fill (
207 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
211 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
213 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
215 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
217 /* Fill the providers combo, based on the selected country: */
218 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
219 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
221 gchar* domain_name = NULL;
223 domain_name = modest_presets_get_domain (priv->presets, provider_id);
226 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
228 if (self->entry_user_email)
229 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
231 g_free (domain_name);
233 g_free (provider_id);
238 create_page_account_details (ModestEasysetupWizardDialog *self)
240 GtkWidget *box = gtk_vbox_new (FALSE, 2);
241 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
242 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
243 gtk_widget_show (label);
245 /* Create a size group to be used by all captions.
246 * Note that HildonCaption does not create a default size group if we do not specify one.
247 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
248 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
250 /* The country widgets: */
251 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
252 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
253 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
254 gtk_widget_show (self->combo_account_country);
255 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
256 gtk_widget_show (caption);
258 /* connect to country combo's changed signal, so we can fill the provider combo: */
259 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
260 G_CALLBACK (on_combo_account_country), self);
263 /* The service provider widgets: */
264 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
266 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
267 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
268 gtk_widget_show (self->combo_account_serviceprovider);
269 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
270 gtk_widget_show (caption);
272 /* connect to providers combo's changed signal, so we can fill the email address: */
273 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
274 G_CALLBACK (on_combo_account_serviceprovider), self);
276 /* TODO: Default to the current country somehow.
277 * But I don't know how to get the information that is specified in the
278 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
280 * This is probably not the best choice of gconf key:
281 * This is the "mcc used in the last pairing", ie. the last connection you made.
282 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
285 GConfClient *client = gconf_client_get_default ();
286 GError *error = NULL;
287 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
288 gint mcc_id = gconf_client_get_int(client, key, &error);
294 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
295 g_error_free (error);
301 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
302 * This might just be a Maemo bug.
306 /* For now, we default to Finland when there is nothing better: */
310 easysetup_country_combo_box_set_active_country_id (
311 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
314 /* The description widgets: */
315 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
317 /* Set a default account title, choosing one that does not already exist: */
318 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
319 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
320 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
321 self->account_manager, default_account_name_start);
322 g_free (default_account_name_start);
323 default_account_name_start = NULL;
325 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
326 g_free (default_account_name);
327 default_account_name = NULL;
329 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
330 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
331 gtk_widget_show (self->entry_account_title);
332 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
333 gtk_widget_show (caption);
335 /* Prevent the use of some characters in the account title,
336 * as required by our UI specification: */
337 GList *list_prevent = NULL;
338 list_prevent = g_list_append (list_prevent, "\\");
339 list_prevent = g_list_append (list_prevent, "/");
340 list_prevent = g_list_append (list_prevent, ":");
341 list_prevent = g_list_append (list_prevent, "*");
342 list_prevent = g_list_append (list_prevent, "?");
343 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
344 list_prevent = g_list_append (list_prevent, "“");
345 list_prevent = g_list_append (list_prevent, "<");
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 easysetup_validating_entry_set_unallowed_characters (
350 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
351 g_list_free (list_prevent);
353 /* Set max length as in the UI spec:
354 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
355 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
357 gtk_widget_show (GTK_WIDGET (box));
359 return GTK_WIDGET (box);
363 create_page_user_details (ModestEasysetupWizardDialog *self)
365 GtkWidget *box = gtk_vbox_new (FALSE, 2);
367 /* Create a size group to be used by all captions.
368 * Note that HildonCaption does not create a default size group if we do not specify one.
369 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
370 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
372 /* The name widgets: */
373 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
374 /* Set max length as in the UI spec:
375 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
376 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
377 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
378 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
379 gtk_widget_show (self->entry_user_name);
380 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
381 gtk_widget_show (caption);
383 /* Prevent the use of some characters in the name,
384 * as required by our UI specification: */
385 GList *list_prevent = NULL;
386 list_prevent = g_list_append (list_prevent, "<");
387 list_prevent = g_list_append (list_prevent, ">");
388 easysetup_validating_entry_set_unallowed_characters (
389 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
390 g_list_free (list_prevent);
392 /* The username widgets: */
393 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
394 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
395 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
396 gtk_widget_show (self->entry_user_username);
397 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
398 gtk_widget_show (caption);
400 /* Prevent the use of some characters in the username,
401 * as required by our UI specification: */
402 easysetup_validating_entry_set_unallowed_characters_whitespace (
403 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
405 /* Set max length as in the UI spec:
406 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
407 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
409 /* The password widgets: */
410 self->entry_user_password = gtk_entry_new ();
411 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
412 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
413 caption = create_caption_new_with_asterix (self, sizegroup,
414 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
415 gtk_widget_show (self->entry_user_password);
416 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
417 gtk_widget_show (caption);
419 /* The email address widgets: */
420 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
421 caption = create_caption_new_with_asterix (self, sizegroup,
422 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
423 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
424 gtk_widget_show (self->entry_user_email);
425 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
426 gtk_widget_show (caption);
428 /* Set max length as in the UI spec:
429 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
430 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
433 gtk_widget_show (GTK_WIDGET (box));
435 return GTK_WIDGET (box);
438 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
440 GtkWidget *box = gtk_vbox_new (FALSE, 2);
441 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
442 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
443 gtk_widget_show (label);
444 gtk_widget_show (GTK_WIDGET (box));
445 return GTK_WIDGET (box);
448 /** Change the caption title for the incoming server,
449 * as specified in the UI spec:
451 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
453 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
454 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
456 (protocol == MODEST_PROTOCOL_STORE_POP ?
457 _("mail_fi_emailtype_pop3") :
458 _("mail_fi_emailtype_imap") );
461 /* Note that this produces a compiler warning,
462 * because the compiler does not know that the translated string will have a %s in it.
463 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
464 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
465 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
466 g_free(incomingserver_title);
469 /** Change the caption title for the incoming server,
470 * as specified in the UI spec:
472 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
474 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
475 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
477 /* Fill the combo with appropriately titled choices for POP or IMAP. */
478 /* The choices are the same, but the titles are different, as in the UI spec. */
479 easysetup_serversecurity_combo_box_fill (
480 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
483 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
485 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
486 update_incoming_server_title (self);
487 update_incoming_server_security_choices (self);
490 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
492 GtkWidget *box = gtk_vbox_new (FALSE, 2);
494 /* Create a size group to be used by all captions.
495 * Note that HildonCaption does not create a default size group if we do not specify one.
496 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
497 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
499 /* The incoming server widgets: */
500 if (!self->combo_incoming_servertype)
501 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
502 easysetup_servertype_combo_box_set_active_servertype (
503 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
504 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
505 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
506 gtk_widget_show (self->combo_incoming_servertype);
507 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
508 gtk_widget_show (caption);
510 if(!self->entry_incomingserver)
511 self->entry_incomingserver = gtk_entry_new ();
512 set_default_custom_servernames (self);
514 if (self->caption_incoming)
515 gtk_widget_destroy (self->caption_incoming);
517 /* The caption title will be updated in update_incoming_server_title().
518 * so this default text will never be seen: */
519 /* (Note: Changing the title seems pointless. murrayc) */
520 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
521 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
522 update_incoming_server_title (self);
523 gtk_widget_show (self->entry_incomingserver);
524 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
525 gtk_widget_show (self->caption_incoming);
527 /* Change the caption title when the servertype changes,
528 * as in the UI spec: */
529 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
530 G_CALLBACK (on_combo_servertype_changed), self);
532 /* The secure connection widgets: */
533 if (!self->combo_incoming_security)
534 self->combo_incoming_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
535 update_incoming_server_security_choices (self);
536 easysetup_serversecurity_combo_box_set_active_serversecurity (
537 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
538 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
539 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
540 gtk_widget_show (self->combo_incoming_security);
541 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
542 gtk_widget_show (caption);
544 if(!self->checkbox_incoming_auth)
545 self->checkbox_incoming_auth =
546 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
547 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
548 gtk_widget_show (self->checkbox_incoming_auth);
550 gtk_widget_show (GTK_WIDGET (box));
552 return GTK_WIDGET (box);
556 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
558 GtkWidget *widget = GTK_WIDGET (user_data);
560 /* Enable the widget only if the toggle button is active: */
561 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
562 gtk_widget_set_sensitive (widget, enable);
565 /* Make the sensitivity of a widget depend on a toggle button.
568 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
570 g_signal_connect (G_OBJECT (button), "toggled",
571 G_CALLBACK (on_toggle_button_changed), widget);
573 /* Set the starting sensitivity: */
574 on_toggle_button_changed (button, widget);
578 on_smtp_servers_window_hide (GtkWindow *window, gpointer user_data)
580 /* Destroy the window when it is closed: */
581 gtk_widget_destroy (GTK_WIDGET (window));
585 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
587 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
589 /* Show the window: */
590 /* TODO: Retrieve the chosen settings,
591 * so we can supply them when creating the connection somehow.
593 GtkWidget *window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
595 gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (self));
596 g_signal_connect (G_OBJECT (window), "hide",
597 G_CALLBACK (on_smtp_servers_window_hide), self);
598 gtk_widget_show (window);
601 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
603 GtkWidget *box = gtk_vbox_new (FALSE, 2);
605 /* Create a size group to be used by all captions.
606 * Note that HildonCaption does not create a default size group if we do not specify one.
607 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
608 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
610 /* The outgoing server widgets: */
611 if (!self->entry_outgoingserver)
612 self->entry_outgoingserver = gtk_entry_new ();
613 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
614 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
615 gtk_widget_show (self->entry_outgoingserver);
616 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
617 gtk_widget_show (caption);
618 set_default_custom_servernames (self);
620 /* The secure connection widgets: */
621 if (!self->combo_outgoing_security)
622 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
623 easysetup_serversecurity_combo_box_fill (
624 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
625 easysetup_serversecurity_combo_box_set_active_serversecurity (
626 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
627 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
628 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
629 gtk_widget_show (self->combo_outgoing_security);
630 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
631 gtk_widget_show (caption);
633 /* The secure authentication widgets: */
634 if (!self->combo_outgoing_auth)
635 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
636 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
637 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
638 gtk_widget_show (self->combo_outgoing_auth);
639 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
640 gtk_widget_show (caption);
642 /* connection-specific checkbox: */
643 if (!self->checkbox_outgoing_smtp_specific) {
644 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
645 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
648 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
649 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
651 /* Connection-specific SMTP-Severs Edit button: */
652 if (!self->button_outgoing_smtp_servers)
653 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
654 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
655 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
656 gtk_widget_show (self->button_outgoing_smtp_servers);
657 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
658 gtk_widget_show (caption);
660 /* Only enable the button when the checkbox is checked: */
661 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
662 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
664 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
665 G_CALLBACK (on_button_outgoing_smtp_servers), self);
668 gtk_widget_show (GTK_WIDGET (box));
670 return GTK_WIDGET (box);
673 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
675 GtkWidget *box = gtk_vbox_new (FALSE, 2);
676 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
677 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
678 gtk_widget_show (label);
680 if (!self->button_edit)
681 self->button_edit = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
682 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
683 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
684 gtk_widget_show (self->button_edit);
685 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
686 gtk_widget_show (caption);
688 gtk_widget_show (GTK_WIDGET (box));
689 return GTK_WIDGET (box);
696 on_response (ModestWizardDialog *wizard_dialog,
700 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
701 invoke_enable_buttons_vfunc (self);
705 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
707 /* Create the notebook to be used by the ModestWizardDialog base class:
708 * Each page of the notebook will be a page of the wizard: */
709 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
711 /* Set the notebook used by the ModestWizardDialog base class: */
712 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
714 /* Set the wizard title:
715 * The actual window title will be a combination of this and the page's tab label title. */
716 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
718 /* Read in the information about known service providers: */
719 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
721 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
722 priv->presets = modest_presets_new (filepath);
723 if (!(priv->presets)) {
724 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
727 g_assert(priv->presets);
730 /* Get the account manager object,
731 * so we can check for existing accounts,
732 * and create new accounts: */
733 self->account_manager = modest_runtime_get_account_mgr ();
734 g_assert (self->account_manager);
735 g_object_ref (self->account_manager);
737 /* Create the common pages,
739 self->page_welcome = create_page_welcome (self);
740 self->page_account_details = create_page_account_details (self);
741 self->page_user_details = create_page_user_details (self);
743 /* Add the common pages: */
744 gtk_notebook_append_page (notebook, self->page_welcome,
745 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
746 gtk_notebook_append_page (notebook, self->page_account_details,
747 gtk_label_new (_("mcen_ti_accountdetails")));
748 gtk_notebook_append_page (notebook, self->page_user_details,
749 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
751 /* Create and add the easysetup-specific pages,
752 * because we need _some_ final page to enable the Next and Finish buttons: */
753 create_subsequent_easysetup_pages (self);
756 /* Connect to the dialog's response signal so we can enable/disable buttons
757 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
758 * Note that we use g_signal_connect_after() instead of g_signal_connect()
759 * so that we can be enable/disable after ModestWizardDialog has done its own
760 * enabling/disabling of buttons.
762 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
763 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
765 * It's not enough to connect to the notebook's switch-page signal, because
766 * ModestWizardDialog's "response" signal handler enables the buttons itself,
767 * _after_ switching the page (understandably).
768 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
769 * then gtk_notebook_get_current_page() would return an incorrect value.)
771 g_signal_connect_after (G_OBJECT (self), "response",
772 G_CALLBACK (on_response), self);
775 ModestEasysetupWizardDialog*
776 modest_easysetup_wizard_dialog_new (void)
778 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
781 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
783 GtkNotebook *notebook = NULL;
784 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
787 /* Create the custom pages: */
788 if(!(self->page_custom_incoming)) {
789 self->page_custom_incoming = create_page_custom_incoming (self);
792 if(!(self->page_custom_outgoing)) {
793 self->page_custom_outgoing = create_page_custom_outgoing (self);
796 if(!(self->page_complete_customsetup)) {
797 self->page_complete_customsetup = create_page_complete_custom (self);
800 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
801 gtk_notebook_append_page (notebook, self->page_custom_incoming,
802 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
804 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
805 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
806 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
808 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
809 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
810 gtk_label_new (_("mcen_ti_emailsetup_complete")));
813 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
815 GtkNotebook *notebook = NULL;
816 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
819 /* Create the easysetup-specific pages: */
820 if(!self->page_complete_easysetup)
821 self->page_complete_easysetup = create_page_complete_easysetup (self);
823 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
824 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
825 gtk_label_new (_("mcen_ti_emailsetup_complete")));
828 /* After the user details page,
829 * the following pages depend on whether "Other" was chosen
830 * in the provider combobox on the account page
832 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
834 if (easysetup_provider_combo_box_get_active_provider_id (
835 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
836 /* "Other..." was selected: */
838 /* Make sure that the easysetup pages do not exist: */
839 if(self->page_complete_easysetup) {
840 gtk_widget_destroy (self->page_complete_easysetup);
841 self->page_complete_easysetup = NULL;
844 create_subsequent_customsetup_pages (self);
847 /* A specific provider was selected: */
849 /* Make sure that the custom pages do not exist:
850 * Because they will be used if they exist, when creating the account. */
851 if(self->page_custom_incoming) {
852 gtk_widget_destroy (self->page_custom_incoming);
853 self->page_custom_incoming = NULL;
856 if(self->page_custom_outgoing) {
857 gtk_widget_destroy (self->page_custom_outgoing);
858 self->page_custom_outgoing = NULL;
861 if(self->page_complete_customsetup) {
862 gtk_widget_destroy (self->page_complete_customsetup);
863 self->page_complete_customsetup = NULL;
867 /* Create the easysetup pages: */
868 create_subsequent_easysetup_pages (self);
874 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
879 gchar* at = g_utf8_strchr (email_address, -1, '@');
880 if (!at || (g_utf8_strlen (at, -1) < 2))
883 gchar* domain = g_utf8_next_char (at);
887 const gchar* hostname = NULL;
888 if (servertype == MODEST_PROTOCOL_STORE_POP)
890 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
892 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
898 return g_strdup_printf ("%s.%s", hostname, domain);
901 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
903 if (!account_wizard->entry_incomingserver)
906 /* Set a default domain for the server, based on the email address,
907 * if no server name was already specified.
909 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
910 if ((!incoming_existing || (strlen(incoming_existing) == 0))
911 && account_wizard->entry_user_email) {
912 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
913 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
914 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
916 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
917 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
921 /* Set a default domain for the server, based on the email address,
922 * if no server name was already specified.
924 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
925 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
926 && account_wizard->entry_user_email) {
927 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
929 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
930 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
936 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
938 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
940 /* Do extra validation that couldn't be done for every key press,
941 * either because it was too slow,
942 * or because it requires interaction:
944 if (current_page == account_wizard->page_account_details) {
945 /* Check that the title is not already in use: */
946 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
947 if ((!account_name) || (strlen(account_name) == 0))
950 /* Aavoid a clash with an existing display name: */
951 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
952 account_wizard->account_manager, account_name);
955 /* Warn the user via a dialog: */
956 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
961 else if (current_page == account_wizard->page_user_details) {
962 /* Check that the email address is valud: */
963 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
964 if ((!email_address) || (strlen(email_address) == 0))
967 if (!modest_text_utils_validate_email_address (email_address)) {
968 /* Warn the user via a dialog: */
969 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
971 /* Return focus to the email address entry: */
972 gtk_widget_grab_focus (account_wizard->entry_user_email);
977 /* Make sure that the subsequent pages are appropriate for the provider choice. */
978 create_subsequent_pages (account_wizard);
981 /* TODO: The UI Spec wants us to check that the servernames are valid,
982 * but does not specify how.
985 if(next_page == account_wizard->page_custom_incoming) {
986 set_default_custom_servernames (account_wizard);
988 else if (next_page == account_wizard->page_custom_outgoing) {
989 set_default_custom_servernames (account_wizard);
992 /* If this is the last page, and this is a click on Finish,
993 * then attempt to create the dialog.
995 if(!next_page) /* This is NULL when this is a click on Finish. */
997 create_account (account_wizard);
1004 static gboolean entry_is_empty (GtkWidget *entry)
1009 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1010 if ((!text) || (strlen(text) == 0))
1017 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1019 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1021 gboolean enable_next = TRUE;
1022 if (current_page == account_wizard->page_welcome) {
1025 else if (current_page == account_wizard->page_account_details) {
1026 /* The account details title is mandatory: */
1027 if (entry_is_empty(account_wizard->entry_account_title))
1028 enable_next = FALSE;
1030 else if (current_page == account_wizard->page_user_details) {
1031 /* The user details username is mandatory: */
1032 if (entry_is_empty(account_wizard->entry_user_username))
1033 enable_next = FALSE;
1035 /* The user details email address is mandatory: */
1036 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1037 enable_next = FALSE;
1039 else if (current_page == account_wizard->page_custom_incoming) {
1040 /* The custom incoming server is mandatory: */
1041 if (entry_is_empty(account_wizard->entry_incomingserver))
1042 enable_next = FALSE;
1045 /* Enable the buttons,
1046 * identifying them via their associated response codes:
1048 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1049 gtk_dialog_set_response_sensitive (dialog_base,
1050 MODEST_WIZARD_DIALOG_NEXT,
1053 /* Disable the Finish button until we are on the last page,
1054 * because HildonWizardDialog enables this for all but the first page: */
1055 GtkNotebook *notebook = NULL;
1056 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1058 gint current = gtk_notebook_get_current_page (notebook);
1059 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1060 gboolean is_last = (current == last);
1063 gtk_dialog_set_response_sensitive (dialog_base,
1064 MODEST_WIZARD_DIALOG_FINISH,
1070 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1072 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1073 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1076 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1077 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1078 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1079 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1081 /* Provide a vfunc implementation so we can decide
1082 * when to enable/disable the prev/next buttons.
1084 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1085 base_klass->before_next = on_before_next;
1086 base_klass->enable_buttons = on_enable_buttons;
1090 show_error (GtkWindow *parent_window, const gchar* text)
1092 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1098 gtk_dialog_run (dialog);
1099 gtk_widget_destroy (GTK_WIDGET (dialog));
1102 /** Attempt to create the account from the information that the user has entered.
1103 * @result: TRUE if the account was successfully created.
1106 create_account (ModestEasysetupWizardDialog *self)
1108 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1110 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1116 /* We should have checked for this already,
1117 * and changed that name accordingly,
1118 * but let's check again just in case:
1120 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1123 /* Increment the non-user visible name if necessary,
1124 * based on the display name: */
1125 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1126 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1127 account_name_start, FALSE /* not a server account */);
1128 g_free (account_name_start);
1130 /* username and password (for both incoming and outgoing): */
1131 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1132 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1134 /* Incoming server: */
1135 /* Note: We need something as default for the ModestProtocol values,
1136 * or modest_account_mgr_add_server_account will fail. */
1137 gchar* servername_incoming = NULL;
1138 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1139 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1140 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1142 /* Get details from the specified presets: */
1143 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1144 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1148 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1149 TRUE /* incoming */);
1151 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1152 TRUE /* incoming */);
1155 /* We don't check for SMTP here as that is impossible for an incoming server. */
1156 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1157 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1158 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1159 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1161 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1162 TRUE /* incoming */);
1165 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1166 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1168 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1169 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1172 /* Use custom pages because no preset was specified: */
1173 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1175 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1176 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1178 protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
1179 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1181 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1182 ? MODEST_PROTOCOL_AUTH_PASSWORD
1183 : MODEST_PROTOCOL_AUTH_NONE;
1187 /* First we add the 2 server accounts, and then we add the account that uses them.
1188 * If we don't do it in this order then we will experience a crash. */
1190 /* Add a (incoming) server account, to be used by the account: */
1191 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1192 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1193 store_name_start, TRUE /* server account */);
1194 g_free (store_name_start);
1195 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1197 servername_incoming,
1200 protocol_security_incoming,
1201 protocol_authentication_incoming);
1203 g_free (servername_incoming);
1206 /* TODO: Provide a Logical ID for the text: */
1207 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1212 /* There must be at least one account now: */
1213 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1216 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1218 g_slist_free (account_names);
1221 /* Outgoing server: */
1222 gchar* servername_outgoing = NULL;
1223 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1224 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1225 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1229 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1230 FALSE /* incoming */);
1232 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1233 FALSE /* incoming */);
1235 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1236 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1237 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1238 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1240 ModestPresetsSecurity security_outgoing =
1241 modest_presets_get_info_server_security (priv->presets, provider_id,
1242 FALSE /* incoming */);
1244 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1245 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1246 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1248 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1249 /* TODO: There is no SMTP authentication enum for presets. */
1252 /* Use custom pages because no preset was specified: */
1253 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1255 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1257 protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
1258 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1260 protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
1261 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1264 gboolean specific = gtk_toggle_button_get_active (
1265 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1270 /* Add a (outgoing) server account to be used by the account: */
1271 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1272 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1273 transport_name_start, TRUE /* server account */);
1274 g_free (transport_name_start);
1275 created = modest_account_mgr_add_server_account (self->account_manager,
1277 servername_outgoing,
1280 protocol_security_outgoing,
1281 protocol_authentication_outgoing);
1283 g_free (servername_outgoing);
1286 /* TODO: Provide a Logical ID for the text: */
1287 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1292 /* Create the account, which will contain the two "server accounts": */
1293 created = modest_account_mgr_add_account (self->account_manager, account_name,
1294 store_name, /* The name of our POP/IMAP server account. */
1295 transport_name /* The name of our SMTP server account. */);
1296 g_free (store_name);
1297 g_free (transport_name);
1300 /* TODO: Provide a Logical ID for the text: */
1301 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1305 /* The user name and email address must be set additionally: */
1306 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1307 modest_account_mgr_set_string (self->account_manager, account_name,
1308 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1310 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1311 modest_account_mgr_set_string (self->account_manager, account_name,
1312 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1314 /* Set the display name: */
1315 modest_account_mgr_set_string (self->account_manager, account_name,
1316 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1318 g_free (account_name);