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 "widgets/modest-easysetup-serversecurity-combo-box.h"
22 #include "widgets/modest-easysetup-secureauth-combo-box.h"
23 #include "widgets/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 if (self->specific_window)
91 gtk_widget_destroy (self->specific_window);
93 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
97 show_error (GtkWindow *parent_window, const gchar* text);
100 create_account (ModestEasysetupWizardDialog *self);
103 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
106 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
108 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
111 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
113 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
115 /* Call the vfunc, which may be overridden by derived classes: */
116 if (klass->enable_buttons) {
117 GtkNotebook *notebook = NULL;
118 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
120 const gint current_page_num = gtk_notebook_get_current_page (notebook);
121 if (current_page_num == -1)
124 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
125 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
130 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
132 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
134 invoke_enable_buttons_vfunc(self);
138 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
140 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
142 invoke_enable_buttons_vfunc(self);
145 /** This is a convenience function to create a caption containing a mandatory widget.
146 * When the widget is edited, the enable_buttons() vfunc will be called.
148 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
153 HildonCaptionStatus flag)
155 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
157 /* The translated strings seem to already contain the *,
158 * but this code can be used if that is not true in future.
161 /* Add a * character to indicate mandatory fields,
162 * as specified in our "Email UI Specification": */
163 if (flag == HILDON_CAPTION_MANDATORY) {
164 gchar* title = g_strdup_printf("%s*", value);
165 caption = hildon_caption_new (group, title, control, icon, flag);
169 caption = hildon_caption_new (group, value, control, icon, flag);
172 /* Connect to the appropriate changed signal for the widget,
173 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
175 if (GTK_IS_ENTRY (control)) {
176 g_signal_connect (G_OBJECT (control), "changed",
177 G_CALLBACK (on_caption_entry_changed), self);
180 else if (GTK_IS_COMBO_BOX (control)) {
181 g_signal_connect (G_OBJECT (control), "changed",
182 G_CALLBACK (on_caption_combobox_changed), self);
189 create_page_welcome (ModestEasysetupWizardDialog *self)
191 GtkWidget *box = gtk_vbox_new (FALSE, 2);
192 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
193 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
194 gtk_widget_show (label);
195 gtk_widget_show (GTK_WIDGET (box));
196 return GTK_WIDGET (box);
200 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
202 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
204 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
206 /* Fill the providers combo, based on the selected country: */
207 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
208 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
209 easysetup_provider_combo_box_fill (
210 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
214 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
216 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
218 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
220 /* Fill the providers combo, based on the selected country: */
221 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
222 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
224 gchar* domain_name = NULL;
226 domain_name = modest_presets_get_domain (priv->presets, provider_id);
229 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
231 if (self->entry_user_email)
232 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
234 g_free (domain_name);
236 g_free (provider_id);
241 create_page_account_details (ModestEasysetupWizardDialog *self)
243 GtkWidget *box = gtk_vbox_new (FALSE, 2);
244 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
245 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
246 gtk_widget_show (label);
248 /* Create a size group to be used by all captions.
249 * Note that HildonCaption does not create a default size group if we do not specify one.
250 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
251 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
253 /* The country widgets: */
254 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
255 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
256 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
257 gtk_widget_show (self->combo_account_country);
258 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
259 gtk_widget_show (caption);
261 /* connect to country combo's changed signal, so we can fill the provider combo: */
262 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
263 G_CALLBACK (on_combo_account_country), self);
266 /* The service provider widgets: */
267 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
269 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
270 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
271 gtk_widget_show (self->combo_account_serviceprovider);
272 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
273 gtk_widget_show (caption);
275 /* connect to providers combo's changed signal, so we can fill the email address: */
276 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
277 G_CALLBACK (on_combo_account_serviceprovider), self);
279 /* TODO: Default to the current country somehow.
280 * But I don't know how to get the information that is specified in the
281 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
283 * This is probably not the best choice of gconf key:
284 * This is the "mcc used in the last pairing", ie. the last connection you made.
285 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
288 GConfClient *client = gconf_client_get_default ();
289 GError *error = NULL;
290 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
291 gint mcc_id = gconf_client_get_int(client, key, &error);
297 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
298 g_error_free (error);
304 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
305 * This might just be a Maemo bug.
309 /* For now, we default to Finland when there is nothing better: */
313 easysetup_country_combo_box_set_active_country_id (
314 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
317 /* The description widgets: */
318 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
320 /* Set a default account title, choosing one that does not already exist: */
321 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
322 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
323 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
324 self->account_manager, default_account_name_start);
325 g_free (default_account_name_start);
326 default_account_name_start = NULL;
328 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
329 g_free (default_account_name);
330 default_account_name = NULL;
332 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
333 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
334 gtk_widget_show (self->entry_account_title);
335 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
336 gtk_widget_show (caption);
338 /* Prevent the use of some characters in the account title,
339 * as required by our UI specification: */
340 GList *list_prevent = NULL;
341 list_prevent = g_list_append (list_prevent, "\\");
342 list_prevent = g_list_append (list_prevent, "/");
343 list_prevent = g_list_append (list_prevent, ":");
344 list_prevent = g_list_append (list_prevent, "*");
345 list_prevent = g_list_append (list_prevent, "?");
346 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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, "^");
352 easysetup_validating_entry_set_unallowed_characters (
353 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
354 g_list_free (list_prevent);
356 /* Set max length as in the UI spec:
357 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
358 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
360 gtk_widget_show (GTK_WIDGET (box));
362 return GTK_WIDGET (box);
366 create_page_user_details (ModestEasysetupWizardDialog *self)
368 GtkWidget *box = gtk_vbox_new (FALSE, 2);
370 /* Create a size group to be used by all captions.
371 * Note that HildonCaption does not create a default size group if we do not specify one.
372 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
373 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
375 /* The name widgets: */
376 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
377 /* Set max length as in the UI spec:
378 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
379 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
380 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
381 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
382 gtk_widget_show (self->entry_user_name);
383 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
384 gtk_widget_show (caption);
386 /* Prevent the use of some characters in the name,
387 * as required by our UI specification: */
388 GList *list_prevent = NULL;
389 list_prevent = g_list_append (list_prevent, "<");
390 list_prevent = g_list_append (list_prevent, ">");
391 easysetup_validating_entry_set_unallowed_characters (
392 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
393 g_list_free (list_prevent);
395 /* The username widgets: */
396 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
397 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
398 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
399 gtk_widget_show (self->entry_user_username);
400 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
401 gtk_widget_show (caption);
403 /* Prevent the use of some characters in the username,
404 * as required by our UI specification: */
405 easysetup_validating_entry_set_unallowed_characters_whitespace (
406 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
408 /* Set max length as in the UI spec:
409 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
410 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
412 /* The password widgets: */
413 self->entry_user_password = gtk_entry_new ();
414 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
415 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
416 caption = create_caption_new_with_asterix (self, sizegroup,
417 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
418 gtk_widget_show (self->entry_user_password);
419 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
420 gtk_widget_show (caption);
422 /* The email address widgets: */
423 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
424 caption = create_caption_new_with_asterix (self, sizegroup,
425 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
426 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
427 gtk_widget_show (self->entry_user_email);
428 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
429 gtk_widget_show (caption);
431 /* Set max length as in the UI spec:
432 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
433 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
436 gtk_widget_show (GTK_WIDGET (box));
438 return GTK_WIDGET (box);
441 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
443 GtkWidget *box = gtk_vbox_new (FALSE, 2);
444 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
445 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
446 gtk_widget_show (label);
447 gtk_widget_show (GTK_WIDGET (box));
448 return GTK_WIDGET (box);
451 /** Change the caption title for the incoming server,
452 * as specified in the UI spec:
454 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
456 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
457 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
459 (protocol == MODEST_PROTOCOL_STORE_POP ?
460 _("mail_fi_emailtype_pop3") :
461 _("mail_fi_emailtype_imap") );
464 /* Note that this produces a compiler warning,
465 * because the compiler does not know that the translated string will have a %s in it.
466 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
467 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
468 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
469 g_free(incomingserver_title);
472 /** Change the caption title for the incoming server,
473 * as specified in the UI spec:
475 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
477 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
478 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
480 /* Fill the combo with appropriately titled choices for POP or IMAP. */
481 /* The choices are the same, but the titles are different, as in the UI spec. */
482 easysetup_serversecurity_combo_box_fill (
483 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
486 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
488 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
489 update_incoming_server_title (self);
490 update_incoming_server_security_choices (self);
493 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
495 GtkWidget *box = gtk_vbox_new (FALSE, 2);
497 /* Create a size group to be used by all captions.
498 * Note that HildonCaption does not create a default size group if we do not specify one.
499 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
500 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
502 /* The incoming server widgets: */
503 if (!self->combo_incoming_servertype)
504 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
505 easysetup_servertype_combo_box_set_active_servertype (
506 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
507 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
508 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
509 gtk_widget_show (self->combo_incoming_servertype);
510 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
511 gtk_widget_show (caption);
513 if(!self->entry_incomingserver)
514 self->entry_incomingserver = gtk_entry_new ();
515 set_default_custom_servernames (self);
517 if (self->caption_incoming)
518 gtk_widget_destroy (self->caption_incoming);
520 /* The caption title will be updated in update_incoming_server_title().
521 * so this default text will never be seen: */
522 /* (Note: Changing the title seems pointless. murrayc) */
523 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
524 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
525 update_incoming_server_title (self);
526 gtk_widget_show (self->entry_incomingserver);
527 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
528 gtk_widget_show (self->caption_incoming);
530 /* Change the caption title when the servertype changes,
531 * as in the UI spec: */
532 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
533 G_CALLBACK (on_combo_servertype_changed), self);
535 /* The secure connection widgets: */
536 if (!self->combo_incoming_security)
537 self->combo_incoming_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
538 update_incoming_server_security_choices (self);
539 easysetup_serversecurity_combo_box_set_active_serversecurity (
540 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
541 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
542 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
543 gtk_widget_show (self->combo_incoming_security);
544 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
545 gtk_widget_show (caption);
547 if(!self->checkbox_incoming_auth)
548 self->checkbox_incoming_auth =
549 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
550 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
551 gtk_widget_show (self->checkbox_incoming_auth);
553 gtk_widget_show (GTK_WIDGET (box));
555 return GTK_WIDGET (box);
559 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
561 GtkWidget *widget = GTK_WIDGET (user_data);
563 /* Enable the widget only if the toggle button is active: */
564 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
565 gtk_widget_set_sensitive (widget, enable);
568 /* Make the sensitivity of a widget depend on a toggle button.
571 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
573 g_signal_connect (G_OBJECT (button), "toggled",
574 G_CALLBACK (on_toggle_button_changed), widget);
576 /* Set the starting sensitivity: */
577 on_toggle_button_changed (button, widget);
581 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
583 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
585 /* Create the window, if necessary: */
586 if (!(self->specific_window)) {
587 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
588 modest_connection_specific_smtp_window_fill_with_connections (
589 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
590 NULL /* account_name, not known yet. */);
593 /* Show the window: */
594 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
595 gtk_widget_show (self->specific_window);
598 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
600 GtkWidget *box = gtk_vbox_new (FALSE, 2);
602 /* Create a size group to be used by all captions.
603 * Note that HildonCaption does not create a default size group if we do not specify one.
604 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
605 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
607 /* The outgoing server widgets: */
608 if (!self->entry_outgoingserver)
609 self->entry_outgoingserver = gtk_entry_new ();
610 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
611 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
612 gtk_widget_show (self->entry_outgoingserver);
613 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
614 gtk_widget_show (caption);
615 set_default_custom_servernames (self);
617 /* The secure connection widgets: */
618 if (!self->combo_outgoing_security)
619 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
620 easysetup_serversecurity_combo_box_fill (
621 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
622 easysetup_serversecurity_combo_box_set_active_serversecurity (
623 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
624 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
625 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
626 gtk_widget_show (self->combo_outgoing_security);
627 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
628 gtk_widget_show (caption);
630 /* The secure authentication widgets: */
631 if (!self->combo_outgoing_auth)
632 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
633 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
634 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
635 gtk_widget_show (self->combo_outgoing_auth);
636 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
637 gtk_widget_show (caption);
639 /* connection-specific checkbox: */
640 if (!self->checkbox_outgoing_smtp_specific) {
641 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
642 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
645 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
646 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
648 /* Connection-specific SMTP-Severs Edit button: */
649 if (!self->button_outgoing_smtp_servers)
650 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
651 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
652 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
653 gtk_widget_show (self->button_outgoing_smtp_servers);
654 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
655 gtk_widget_show (caption);
657 /* Only enable the button when the checkbox is checked: */
658 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
659 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
661 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
662 G_CALLBACK (on_button_outgoing_smtp_servers), self);
665 gtk_widget_show (GTK_WIDGET (box));
667 return GTK_WIDGET (box);
670 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
672 GtkWidget *box = gtk_vbox_new (FALSE, 2);
673 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
674 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
675 gtk_widget_show (label);
677 if (!self->button_edit)
678 self->button_edit = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
679 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
680 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
681 gtk_widget_show (self->button_edit);
682 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
683 gtk_widget_show (caption);
685 gtk_widget_show (GTK_WIDGET (box));
686 return GTK_WIDGET (box);
693 on_response (ModestWizardDialog *wizard_dialog,
697 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
698 invoke_enable_buttons_vfunc (self);
702 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
704 /* Create the notebook to be used by the ModestWizardDialog base class:
705 * Each page of the notebook will be a page of the wizard: */
706 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
708 /* Set the notebook used by the ModestWizardDialog base class: */
709 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
711 /* Set the wizard title:
712 * The actual window title will be a combination of this and the page's tab label title. */
713 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
715 /* Read in the information about known service providers: */
716 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
718 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
719 priv->presets = modest_presets_new (filepath);
720 if (!(priv->presets)) {
721 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
724 g_assert(priv->presets);
727 /* Get the account manager object,
728 * so we can check for existing accounts,
729 * and create new accounts: */
730 self->account_manager = modest_runtime_get_account_mgr ();
731 g_assert (self->account_manager);
732 g_object_ref (self->account_manager);
734 /* Create the common pages,
736 self->page_welcome = create_page_welcome (self);
737 self->page_account_details = create_page_account_details (self);
738 self->page_user_details = create_page_user_details (self);
740 /* Add the common pages: */
741 gtk_notebook_append_page (notebook, self->page_welcome,
742 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
743 gtk_notebook_append_page (notebook, self->page_account_details,
744 gtk_label_new (_("mcen_ti_accountdetails")));
745 gtk_notebook_append_page (notebook, self->page_user_details,
746 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
748 /* Create and add the easysetup-specific pages,
749 * because we need _some_ final page to enable the Next and Finish buttons: */
750 create_subsequent_easysetup_pages (self);
753 /* Connect to the dialog's response signal so we can enable/disable buttons
754 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
755 * Note that we use g_signal_connect_after() instead of g_signal_connect()
756 * so that we can be enable/disable after ModestWizardDialog has done its own
757 * enabling/disabling of buttons.
759 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
760 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
762 * It's not enough to connect to the notebook's switch-page signal, because
763 * ModestWizardDialog's "response" signal handler enables the buttons itself,
764 * _after_ switching the page (understandably).
765 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
766 * then gtk_notebook_get_current_page() would return an incorrect value.)
768 g_signal_connect_after (G_OBJECT (self), "response",
769 G_CALLBACK (on_response), self);
772 ModestEasysetupWizardDialog*
773 modest_easysetup_wizard_dialog_new (void)
775 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
778 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
780 GtkNotebook *notebook = NULL;
781 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
784 /* Create the custom pages: */
785 if(!(self->page_custom_incoming)) {
786 self->page_custom_incoming = create_page_custom_incoming (self);
789 if(!(self->page_custom_outgoing)) {
790 self->page_custom_outgoing = create_page_custom_outgoing (self);
793 if(!(self->page_complete_customsetup)) {
794 self->page_complete_customsetup = create_page_complete_custom (self);
797 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
798 gtk_notebook_append_page (notebook, self->page_custom_incoming,
799 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
801 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
802 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
803 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
805 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
806 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
807 gtk_label_new (_("mcen_ti_emailsetup_complete")));
810 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
812 GtkNotebook *notebook = NULL;
813 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
816 /* Create the easysetup-specific pages: */
817 if(!self->page_complete_easysetup)
818 self->page_complete_easysetup = create_page_complete_easysetup (self);
820 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
821 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
822 gtk_label_new (_("mcen_ti_emailsetup_complete")));
825 /* After the user details page,
826 * the following pages depend on whether "Other" was chosen
827 * in the provider combobox on the account page
829 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
831 if (easysetup_provider_combo_box_get_active_provider_id (
832 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
833 /* "Other..." was selected: */
835 /* Make sure that the easysetup pages do not exist: */
836 if(self->page_complete_easysetup) {
837 gtk_widget_destroy (self->page_complete_easysetup);
838 self->page_complete_easysetup = NULL;
841 create_subsequent_customsetup_pages (self);
844 /* A specific provider was selected: */
846 /* Make sure that the custom pages do not exist:
847 * Because they will be used if they exist, when creating the account. */
848 if(self->page_custom_incoming) {
849 gtk_widget_destroy (self->page_custom_incoming);
850 self->page_custom_incoming = NULL;
853 if(self->page_custom_outgoing) {
854 gtk_widget_destroy (self->page_custom_outgoing);
855 self->page_custom_outgoing = NULL;
858 if(self->page_complete_customsetup) {
859 gtk_widget_destroy (self->page_complete_customsetup);
860 self->page_complete_customsetup = NULL;
864 /* Create the easysetup pages: */
865 create_subsequent_easysetup_pages (self);
871 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
876 gchar* at = g_utf8_strchr (email_address, -1, '@');
877 if (!at || (g_utf8_strlen (at, -1) < 2))
880 gchar* domain = g_utf8_next_char (at);
884 const gchar* hostname = NULL;
885 if (servertype == MODEST_PROTOCOL_STORE_POP)
887 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
889 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
895 return g_strdup_printf ("%s.%s", hostname, domain);
898 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
900 if (!account_wizard->entry_incomingserver)
903 /* Set a default domain for the server, based on the email address,
904 * if no server name was already specified.
906 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
907 if ((!incoming_existing || (strlen(incoming_existing) == 0))
908 && account_wizard->entry_user_email) {
909 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
910 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
911 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
913 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
914 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
918 /* Set a default domain for the server, based on the email address,
919 * if no server name was already specified.
921 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
922 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
923 && account_wizard->entry_user_email) {
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, MODEST_PROTOCOL_TRANSPORT_SMTP);
927 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
933 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
935 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
937 /* Do extra validation that couldn't be done for every key press,
938 * either because it was too slow,
939 * or because it requires interaction:
941 if (current_page == account_wizard->page_account_details) {
942 /* Check that the title is not already in use: */
943 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
944 if ((!account_title) || (strlen(account_title) == 0))
947 /* Aavoid a clash with an existing display name: */
948 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
949 account_wizard->account_manager, account_title);
952 /* Warn the user via a dialog: */
953 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
958 else if (current_page == account_wizard->page_user_details) {
959 /* Check that the email address is valud: */
960 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
961 if ((!email_address) || (strlen(email_address) == 0))
964 if (!modest_text_utils_validate_email_address (email_address)) {
965 /* Warn the user via a dialog: */
966 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
968 /* Return focus to the email address entry: */
969 gtk_widget_grab_focus (account_wizard->entry_user_email);
974 /* Make sure that the subsequent pages are appropriate for the provider choice. */
975 create_subsequent_pages (account_wizard);
978 /* TODO: The UI Spec wants us to check that the servernames are valid,
979 * but does not specify how.
982 if(next_page == account_wizard->page_custom_incoming) {
983 set_default_custom_servernames (account_wizard);
985 else if (next_page == account_wizard->page_custom_outgoing) {
986 set_default_custom_servernames (account_wizard);
989 /* If this is the last page, and this is a click on Finish,
990 * then attempt to create the dialog.
992 if(!next_page) /* This is NULL when this is a click on Finish. */
994 create_account (account_wizard);
1001 static gboolean entry_is_empty (GtkWidget *entry)
1006 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1007 if ((!text) || (strlen(text) == 0))
1014 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1016 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1018 gboolean enable_next = TRUE;
1019 if (current_page == account_wizard->page_welcome) {
1022 else if (current_page == account_wizard->page_account_details) {
1023 /* The account details title is mandatory: */
1024 if (entry_is_empty(account_wizard->entry_account_title))
1025 enable_next = FALSE;
1027 else if (current_page == account_wizard->page_user_details) {
1028 /* The user details username is mandatory: */
1029 if (entry_is_empty(account_wizard->entry_user_username))
1030 enable_next = FALSE;
1032 /* The user details email address is mandatory: */
1033 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1034 enable_next = FALSE;
1036 else if (current_page == account_wizard->page_custom_incoming) {
1037 /* The custom incoming server is mandatory: */
1038 if (entry_is_empty(account_wizard->entry_incomingserver))
1039 enable_next = FALSE;
1042 /* Enable the buttons,
1043 * identifying them via their associated response codes:
1045 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1046 gtk_dialog_set_response_sensitive (dialog_base,
1047 MODEST_WIZARD_DIALOG_NEXT,
1050 /* Disable the Finish button until we are on the last page,
1051 * because HildonWizardDialog enables this for all but the first page: */
1052 GtkNotebook *notebook = NULL;
1053 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1055 gint current = gtk_notebook_get_current_page (notebook);
1056 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1057 gboolean is_last = (current == last);
1060 gtk_dialog_set_response_sensitive (dialog_base,
1061 MODEST_WIZARD_DIALOG_FINISH,
1067 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1069 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1070 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1073 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1074 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1075 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1076 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1078 /* Provide a vfunc implementation so we can decide
1079 * when to enable/disable the prev/next buttons.
1081 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1082 base_klass->before_next = on_before_next;
1083 base_klass->enable_buttons = on_enable_buttons;
1087 show_error (GtkWindow *parent_window, const gchar* text)
1089 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1095 gtk_dialog_run (dialog);
1096 gtk_widget_destroy (GTK_WIDGET (dialog));
1099 /** Attempt to create the account from the information that the user has entered.
1100 * @result: TRUE if the account was successfully created.
1103 create_account (ModestEasysetupWizardDialog *self)
1105 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1107 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1113 /* We should have checked for this already,
1114 * and changed that name accordingly,
1115 * but let's check again just in case:
1117 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1120 /* Increment the non-user visible name if necessary,
1121 * based on the display name: */
1122 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1123 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1124 account_name_start, FALSE /* not a server account */);
1125 g_free (account_name_start);
1127 /* username and password (for both incoming and outgoing): */
1128 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1129 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1131 /* Incoming server: */
1132 /* Note: We need something as default for the ModestProtocol values,
1133 * or modest_account_mgr_add_server_account will fail. */
1134 gchar* servername_incoming = NULL;
1135 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1136 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1137 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1139 /* Get details from the specified presets: */
1140 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1141 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1145 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1146 TRUE /* incoming */);
1148 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1149 TRUE /* incoming */);
1152 /* We don't check for SMTP here as that is impossible for an incoming server. */
1153 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1154 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1155 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1156 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1158 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1159 TRUE /* incoming */);
1162 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1163 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1165 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1166 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1169 /* Use custom pages because no preset was specified: */
1170 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1172 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1173 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1175 protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
1176 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1178 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1179 ? MODEST_PROTOCOL_AUTH_PASSWORD
1180 : MODEST_PROTOCOL_AUTH_NONE;
1184 /* First we add the 2 server accounts, and then we add the account that uses them.
1185 * If we don't do it in this order then we will experience a crash. */
1187 /* Add a (incoming) server account, to be used by the account: */
1188 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1189 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1190 store_name_start, TRUE /* server account */);
1191 g_free (store_name_start);
1192 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1194 servername_incoming,
1197 protocol_security_incoming,
1198 protocol_authentication_incoming);
1200 g_free (servername_incoming);
1203 /* TODO: Provide a Logical ID for the text: */
1204 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1209 /* There must be at least one account now: */
1210 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1213 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1215 g_slist_free (account_names);
1218 /* Outgoing server: */
1219 gchar* servername_outgoing = NULL;
1220 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1221 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1222 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1226 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1227 FALSE /* incoming */);
1229 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1230 FALSE /* incoming */);
1232 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1233 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1234 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1235 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1237 ModestPresetsSecurity security_outgoing =
1238 modest_presets_get_info_server_security (priv->presets, provider_id,
1239 FALSE /* incoming */);
1241 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1242 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1243 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1245 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1246 /* TODO: There is no SMTP authentication enum for presets. */
1249 /* Use custom pages because no preset was specified: */
1250 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1252 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1254 protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
1255 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1257 protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
1258 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1261 gboolean specific = gtk_toggle_button_get_active (
1262 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1267 /* Add a (outgoing) server account to be used by the account: */
1268 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1269 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1270 transport_name_start, TRUE /* server account */);
1271 g_free (transport_name_start);
1272 created = modest_account_mgr_add_server_account (self->account_manager,
1274 servername_outgoing,
1277 protocol_security_outgoing,
1278 protocol_authentication_outgoing);
1280 g_free (servername_outgoing);
1283 /* TODO: Provide a Logical ID for the text: */
1284 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1289 /* Create the account, which will contain the two "server accounts": */
1290 created = modest_account_mgr_add_account (self->account_manager, account_name,
1291 store_name, /* The name of our POP/IMAP server account. */
1292 transport_name /* The name of our SMTP server account. */);
1293 g_free (store_name);
1294 g_free (transport_name);
1297 /* TODO: Provide a Logical ID for the text: */
1298 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1302 /* The user name and email address must be set additionally: */
1303 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1304 modest_account_mgr_set_string (self->account_manager, account_name,
1305 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1307 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1308 modest_account_mgr_set_string (self->account_manager, account_name,
1309 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1311 /* Set the display name: */
1312 modest_account_mgr_set_string (self->account_manager, account_name,
1313 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1315 /* Save the connection-specific SMTP server accounts. */
1316 if (self->specific_window)
1317 return modest_connection_specific_smtp_window_save_server_accounts (
1318 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1320 g_free (account_name);