1 /* Copyright (c) 2007, Nokia Corporation
7 #include "modest-easysetup-wizard.h"
8 #include <glib/gi18n.h>
9 #include <gtk/gtknotebook.h>
10 #include <gtk/gtkvbox.h>
11 #include <gtk/gtklabel.h>
12 #include <gtk/gtkcombobox.h>
13 #include <gtk/gtkentry.h>
14 #include <gtk/gtkbutton.h>
15 #include <gtk/gtkcheckbutton.h>
16 #include <gtk/gtkmessagedialog.h>
17 #include <gtk/gtkseparator.h>
18 #include <hildon-widgets/hildon-caption.h>
19 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
20 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
21 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
22 #include "widgets/modest-serversecurity-combo-box.h"
23 #include "widgets/modest-secureauth-combo-box.h"
24 #include "widgets/modest-validating-entry.h"
25 #include "modest-text-utils.h"
26 #include "modest-account-mgr.h"
27 #include "modest-account-mgr-helpers.h"
28 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
29 #include "maemo/modest-connection-specific-smtp-window.h"
30 #include <gconf/gconf-client.h>
31 #include <string.h> /* For strlen(). */
33 /* Include config.h so that _() works: */
38 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
40 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
42 #define WIZARD_DIALOG_GET_PRIVATE(o) \
43 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
45 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
47 struct _ModestEasysetupWizardDialogPrivate
49 ModestPresets *presets;
53 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
54 GValue *value, GParamSpec *pspec)
56 switch (property_id) {
58 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
63 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
64 const GValue *value, GParamSpec *pspec)
66 switch (property_id) {
68 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
73 modest_easysetup_wizard_dialog_dispose (GObject *object)
75 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
76 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
80 modest_easysetup_wizard_dialog_finalize (GObject *object)
82 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
83 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
85 if (self->account_manager)
86 g_object_unref (G_OBJECT (self->account_manager));
89 modest_presets_destroy (priv->presets);
91 if (self->specific_window)
92 gtk_widget_destroy (self->specific_window);
94 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
98 show_error (GtkWindow *parent_window, const gchar* text);
101 create_account (ModestEasysetupWizardDialog *self);
104 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
107 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
109 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
112 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
114 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
116 /* Call the vfunc, which may be overridden by derived classes: */
117 if (klass->enable_buttons) {
118 GtkNotebook *notebook = NULL;
119 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
121 const gint current_page_num = gtk_notebook_get_current_page (notebook);
122 if (current_page_num == -1)
125 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
126 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
131 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
133 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
135 invoke_enable_buttons_vfunc(self);
139 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
141 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
143 invoke_enable_buttons_vfunc(self);
146 /** This is a convenience function to create a caption containing a mandatory widget.
147 * When the widget is edited, the enable_buttons() vfunc will be called.
149 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
154 HildonCaptionStatus flag)
156 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
158 /* The translated strings seem to already contain the *,
159 * but this code can be used if that is not true in future.
162 /* Add a * character to indicate mandatory fields,
163 * as specified in our "Email UI Specification": */
164 if (flag == HILDON_CAPTION_MANDATORY) {
165 gchar* title = g_strdup_printf("%s*", value);
166 caption = hildon_caption_new (group, title, control, icon, flag);
170 caption = hildon_caption_new (group, value, control, icon, flag);
173 /* Connect to the appropriate changed signal for the widget,
174 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
176 if (GTK_IS_ENTRY (control)) {
177 g_signal_connect (G_OBJECT (control), "changed",
178 G_CALLBACK (on_caption_entry_changed), self);
181 else if (GTK_IS_COMBO_BOX (control)) {
182 g_signal_connect (G_OBJECT (control), "changed",
183 G_CALLBACK (on_caption_combobox_changed), self);
190 create_page_welcome (ModestEasysetupWizardDialog *self)
192 GtkWidget *box = gtk_vbox_new (FALSE, 2);
193 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
194 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
195 gtk_widget_show (label);
196 gtk_widget_show (GTK_WIDGET (box));
197 return GTK_WIDGET (box);
201 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
203 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
205 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
207 /* Fill the providers combo, based on the selected country: */
208 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
209 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
210 easysetup_provider_combo_box_fill (
211 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
215 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
217 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
219 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
221 /* Fill the providers combo, based on the selected country: */
222 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
223 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
225 gchar* domain_name = NULL;
227 domain_name = modest_presets_get_domain (priv->presets, provider_id);
230 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
232 if (self->entry_user_email)
233 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
235 g_free (domain_name);
237 g_free (provider_id);
242 create_page_account_details (ModestEasysetupWizardDialog *self)
244 GtkWidget *box = gtk_vbox_new (FALSE, 2);
245 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
246 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
247 gtk_widget_show (label);
249 /* Create a size group to be used by all captions.
250 * Note that HildonCaption does not create a default size group if we do not specify one.
251 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
252 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
254 /* The country widgets: */
255 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
256 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
257 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
258 gtk_widget_show (self->combo_account_country);
259 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
260 gtk_widget_show (caption);
262 /* connect to country combo's changed signal, so we can fill the provider combo: */
263 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
264 G_CALLBACK (on_combo_account_country), self);
266 GtkWidget *separator = gtk_hseparator_new ();
267 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 2);
268 gtk_widget_show (separator);
270 /* The service provider widgets: */
271 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
273 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
274 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
275 gtk_widget_show (self->combo_account_serviceprovider);
276 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
277 gtk_widget_show (caption);
279 /* connect to providers combo's changed signal, so we can fill the email address: */
280 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
281 G_CALLBACK (on_combo_account_serviceprovider), self);
283 /* TODO: Default to the current country somehow.
284 * But I don't know how to get the information that is specified in the
285 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
287 * This is probably not the best choice of gconf key:
288 * This is the "mcc used in the last pairing", ie. the last connection you made.
289 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
292 GConfClient *client = gconf_client_get_default ();
293 GError *error = NULL;
294 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
295 gint mcc_id = gconf_client_get_int(client, key, &error);
301 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
302 g_error_free (error);
308 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
309 * This might just be a Maemo bug.
313 /* For now, we default to Finland when there is nothing better: */
317 easysetup_country_combo_box_set_active_country_id (
318 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
321 /* The description widgets: */
322 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
324 /* Set a default account title, choosing one that does not already exist: */
325 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
326 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
327 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
328 self->account_manager, default_account_name_start);
329 g_free (default_account_name_start);
330 default_account_name_start = NULL;
332 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
333 g_free (default_account_name);
334 default_account_name = NULL;
336 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
337 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
338 gtk_widget_show (self->entry_account_title);
339 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
340 gtk_widget_show (caption);
342 /* Prevent the use of some characters in the account title,
343 * as required by our UI specification: */
344 GList *list_prevent = NULL;
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 list_prevent = g_list_append (list_prevent, "?");
350 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
351 list_prevent = g_list_append (list_prevent, "“");
352 list_prevent = g_list_append (list_prevent, "<");
353 list_prevent = g_list_append (list_prevent, ">");
354 list_prevent = g_list_append (list_prevent, "|");
355 list_prevent = g_list_append (list_prevent, "^");
356 easysetup_validating_entry_set_unallowed_characters (
357 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
358 g_list_free (list_prevent);
360 /* Set max length as in the UI spec:
361 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
362 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
364 gtk_widget_show (GTK_WIDGET (box));
366 return GTK_WIDGET (box);
370 create_page_user_details (ModestEasysetupWizardDialog *self)
372 GtkWidget *box = gtk_vbox_new (FALSE, 2);
374 /* Create a size group to be used by all captions.
375 * Note that HildonCaption does not create a default size group if we do not specify one.
376 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
377 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
379 /* The name widgets: */
380 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
381 /* Set max length as in the UI spec:
382 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
383 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
384 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
385 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
386 gtk_widget_show (self->entry_user_name);
387 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
388 gtk_widget_show (caption);
390 /* Prevent the use of some characters in the name,
391 * as required by our UI specification: */
392 GList *list_prevent = NULL;
393 list_prevent = g_list_append (list_prevent, "<");
394 list_prevent = g_list_append (list_prevent, ">");
395 easysetup_validating_entry_set_unallowed_characters (
396 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
397 g_list_free (list_prevent);
399 /* The username widgets: */
400 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
401 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
402 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
403 gtk_widget_show (self->entry_user_username);
404 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
405 gtk_widget_show (caption);
407 /* Prevent the use of some characters in the username,
408 * as required by our UI specification: */
409 easysetup_validating_entry_set_unallowed_characters_whitespace (
410 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
412 /* Set max length as in the UI spec:
413 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
414 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
416 /* The password widgets: */
417 self->entry_user_password = gtk_entry_new ();
418 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
419 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
420 caption = create_caption_new_with_asterix (self, sizegroup,
421 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
422 gtk_widget_show (self->entry_user_password);
423 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
424 gtk_widget_show (caption);
426 /* The email address widgets: */
427 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
428 caption = create_caption_new_with_asterix (self, sizegroup,
429 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
430 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
431 gtk_widget_show (self->entry_user_email);
432 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
433 gtk_widget_show (caption);
435 /* Set max length as in the UI spec:
436 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
437 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
440 gtk_widget_show (GTK_WIDGET (box));
442 return GTK_WIDGET (box);
445 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
447 GtkWidget *box = gtk_vbox_new (FALSE, 2);
448 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
449 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
450 gtk_widget_show (label);
451 gtk_widget_show (GTK_WIDGET (box));
452 return GTK_WIDGET (box);
455 /** Change the caption title for the incoming server,
456 * as specified in the UI spec:
458 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
460 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
461 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
463 (protocol == MODEST_PROTOCOL_STORE_POP ?
464 _("mail_fi_emailtype_pop3") :
465 _("mail_fi_emailtype_imap") );
468 /* Note that this produces a compiler warning,
469 * because the compiler does not know that the translated string will have a %s in it.
470 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
471 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
472 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
473 g_free(incomingserver_title);
476 /** Change the caption title for the incoming server,
477 * as specified in the UI spec:
479 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
481 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
482 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
484 /* Fill the combo with appropriately titled choices for POP or IMAP. */
485 /* The choices are the same, but the titles are different, as in the UI spec. */
486 modest_serversecurity_combo_box_fill (
487 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
490 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
492 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
493 update_incoming_server_title (self);
494 update_incoming_server_security_choices (self);
497 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
499 GtkWidget *box = gtk_vbox_new (FALSE, 2);
501 /* Create a size group to be used by all captions.
502 * Note that HildonCaption does not create a default size group if we do not specify one.
503 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
504 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
506 /* The incoming server widgets: */
507 if (!self->combo_incoming_servertype)
508 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
509 easysetup_servertype_combo_box_set_active_servertype (
510 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
511 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
512 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
513 gtk_widget_show (self->combo_incoming_servertype);
514 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
515 gtk_widget_show (caption);
517 if(!self->entry_incomingserver)
518 self->entry_incomingserver = gtk_entry_new ();
519 set_default_custom_servernames (self);
521 if (self->caption_incoming)
522 gtk_widget_destroy (self->caption_incoming);
524 /* The caption title will be updated in update_incoming_server_title().
525 * so this default text will never be seen: */
526 /* (Note: Changing the title seems pointless. murrayc) */
527 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
528 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
529 update_incoming_server_title (self);
530 gtk_widget_show (self->entry_incomingserver);
531 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
532 gtk_widget_show (self->caption_incoming);
534 /* Change the caption title when the servertype changes,
535 * as in the UI spec: */
536 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
537 G_CALLBACK (on_combo_servertype_changed), self);
539 /* The secure connection widgets: */
540 if (!self->combo_incoming_security)
541 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
542 update_incoming_server_security_choices (self);
543 modest_serversecurity_combo_box_set_active_serversecurity (
544 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
545 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
546 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
547 gtk_widget_show (self->combo_incoming_security);
548 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
549 gtk_widget_show (caption);
551 if(!self->checkbox_incoming_auth)
552 self->checkbox_incoming_auth =
553 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
554 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
555 gtk_widget_show (self->checkbox_incoming_auth);
557 gtk_widget_show (GTK_WIDGET (box));
559 return GTK_WIDGET (box);
563 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
565 GtkWidget *widget = GTK_WIDGET (user_data);
567 /* Enable the widget only if the toggle button is active: */
568 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
569 gtk_widget_set_sensitive (widget, enable);
572 /* Make the sensitivity of a widget depend on a toggle button.
575 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
577 g_signal_connect (G_OBJECT (button), "toggled",
578 G_CALLBACK (on_toggle_button_changed), widget);
580 /* Set the starting sensitivity: */
581 on_toggle_button_changed (button, widget);
585 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
587 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
589 /* Create the window, if necessary: */
590 if (!(self->specific_window)) {
591 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
592 modest_connection_specific_smtp_window_fill_with_connections (
593 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
594 NULL /* account_name, not known yet. */);
597 /* Show the window: */
598 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
599 gtk_widget_show (self->specific_window);
602 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
604 GtkWidget *box = gtk_vbox_new (FALSE, 2);
606 /* Create a size group to be used by all captions.
607 * Note that HildonCaption does not create a default size group if we do not specify one.
608 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
609 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
611 /* The outgoing server widgets: */
612 if (!self->entry_outgoingserver)
613 self->entry_outgoingserver = gtk_entry_new ();
614 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
615 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
616 gtk_widget_show (self->entry_outgoingserver);
617 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
618 gtk_widget_show (caption);
619 set_default_custom_servernames (self);
621 /* The secure connection widgets: */
622 if (!self->combo_outgoing_security)
623 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
624 modest_serversecurity_combo_box_fill (
625 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
626 modest_serversecurity_combo_box_set_active_serversecurity (
627 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
628 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
629 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
630 gtk_widget_show (self->combo_outgoing_security);
631 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
632 gtk_widget_show (caption);
634 /* The secure authentication widgets: */
635 if (!self->combo_outgoing_auth)
636 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
637 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
638 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
639 gtk_widget_show (self->combo_outgoing_auth);
640 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
641 gtk_widget_show (caption);
643 /* connection-specific checkbox: */
644 if (!self->checkbox_outgoing_smtp_specific) {
645 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
646 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
649 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
650 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
652 GtkWidget *separator = gtk_hseparator_new ();
653 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 2);
654 gtk_widget_show (separator);
656 /* Connection-specific SMTP-Severs Edit button: */
657 if (!self->button_outgoing_smtp_servers)
658 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
659 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
660 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
661 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
662 gtk_widget_show (self->button_outgoing_smtp_servers);
663 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
664 gtk_widget_show (caption);
666 /* Only enable the button when the checkbox is checked: */
667 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
668 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
670 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
671 G_CALLBACK (on_button_outgoing_smtp_servers), self);
674 gtk_widget_show (GTK_WIDGET (box));
676 return GTK_WIDGET (box);
679 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
681 GtkWidget *box = gtk_vbox_new (FALSE, 2);
682 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
683 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
684 gtk_widget_show (label);
686 if (!self->button_edit)
687 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
688 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
689 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
690 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
691 gtk_widget_show (self->button_edit);
692 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
693 gtk_widget_show (caption);
695 gtk_widget_show (GTK_WIDGET (box));
696 return GTK_WIDGET (box);
703 on_response (ModestWizardDialog *wizard_dialog,
707 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
708 invoke_enable_buttons_vfunc (self);
712 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
714 /* Create the notebook to be used by the ModestWizardDialog base class:
715 * Each page of the notebook will be a page of the wizard: */
716 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
718 /* Set the notebook used by the ModestWizardDialog base class: */
719 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
721 /* Set the wizard title:
722 * The actual window title will be a combination of this and the page's tab label title. */
723 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
725 /* Read in the information about known service providers: */
726 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
728 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
729 priv->presets = modest_presets_new (filepath);
730 if (!(priv->presets)) {
731 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
734 g_assert(priv->presets);
737 /* Get the account manager object,
738 * so we can check for existing accounts,
739 * and create new accounts: */
740 self->account_manager = modest_runtime_get_account_mgr ();
741 g_assert (self->account_manager);
742 g_object_ref (self->account_manager);
744 /* Create the common pages,
746 self->page_welcome = create_page_welcome (self);
747 self->page_account_details = create_page_account_details (self);
748 self->page_user_details = create_page_user_details (self);
750 /* Add the common pages: */
751 gtk_notebook_append_page (notebook, self->page_welcome,
752 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
753 gtk_notebook_append_page (notebook, self->page_account_details,
754 gtk_label_new (_("mcen_ti_accountdetails")));
755 gtk_notebook_append_page (notebook, self->page_user_details,
756 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
758 /* Create and add the easysetup-specific pages,
759 * because we need _some_ final page to enable the Next and Finish buttons: */
760 create_subsequent_easysetup_pages (self);
763 /* Connect to the dialog's response signal so we can enable/disable buttons
764 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
765 * Note that we use g_signal_connect_after() instead of g_signal_connect()
766 * so that we can be enable/disable after ModestWizardDialog has done its own
767 * enabling/disabling of buttons.
769 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
770 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
772 * It's not enough to connect to the notebook's switch-page signal, because
773 * ModestWizardDialog's "response" signal handler enables the buttons itself,
774 * _after_ switching the page (understandably).
775 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
776 * then gtk_notebook_get_current_page() would return an incorrect value.)
778 g_signal_connect_after (G_OBJECT (self), "response",
779 G_CALLBACK (on_response), self);
782 ModestEasysetupWizardDialog*
783 modest_easysetup_wizard_dialog_new (void)
785 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
788 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
790 GtkNotebook *notebook = NULL;
791 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
794 /* Create the custom pages: */
795 if(!(self->page_custom_incoming)) {
796 self->page_custom_incoming = create_page_custom_incoming (self);
799 if(!(self->page_custom_outgoing)) {
800 self->page_custom_outgoing = create_page_custom_outgoing (self);
803 if(!(self->page_complete_customsetup)) {
804 self->page_complete_customsetup = create_page_complete_custom (self);
807 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
808 gtk_notebook_append_page (notebook, self->page_custom_incoming,
809 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
811 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
812 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
813 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
815 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
816 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
817 gtk_label_new (_("mcen_ti_emailsetup_complete")));
820 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
822 GtkNotebook *notebook = NULL;
823 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
826 /* Create the easysetup-specific pages: */
827 if(!self->page_complete_easysetup)
828 self->page_complete_easysetup = create_page_complete_easysetup (self);
830 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
831 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
832 gtk_label_new (_("mcen_ti_emailsetup_complete")));
835 /* After the user details page,
836 * the following pages depend on whether "Other" was chosen
837 * in the provider combobox on the account page
839 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
841 if (easysetup_provider_combo_box_get_active_provider_id (
842 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
843 /* "Other..." was selected: */
845 /* Make sure that the easysetup pages do not exist: */
846 if(self->page_complete_easysetup) {
847 gtk_widget_destroy (self->page_complete_easysetup);
848 self->page_complete_easysetup = NULL;
851 create_subsequent_customsetup_pages (self);
854 /* A specific provider was selected: */
856 /* Make sure that the custom pages do not exist:
857 * Because they will be used if they exist, when creating the account. */
858 if(self->page_custom_incoming) {
859 gtk_widget_destroy (self->page_custom_incoming);
860 self->page_custom_incoming = NULL;
863 if(self->page_custom_outgoing) {
864 gtk_widget_destroy (self->page_custom_outgoing);
865 self->page_custom_outgoing = NULL;
868 if(self->page_complete_customsetup) {
869 gtk_widget_destroy (self->page_complete_customsetup);
870 self->page_complete_customsetup = NULL;
874 /* Create the easysetup pages: */
875 create_subsequent_easysetup_pages (self);
881 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
886 gchar* at = g_utf8_strchr (email_address, -1, '@');
887 if (!at || (g_utf8_strlen (at, -1) < 2))
890 gchar* domain = g_utf8_next_char (at);
894 const gchar* hostname = NULL;
895 if (servertype == MODEST_PROTOCOL_STORE_POP)
897 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
899 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
905 return g_strdup_printf ("%s.%s", hostname, domain);
908 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
910 if (!account_wizard->entry_incomingserver)
913 /* Set a default domain for the server, based on the email address,
914 * if no server name was already specified.
916 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
917 if ((!incoming_existing || (strlen(incoming_existing) == 0))
918 && account_wizard->entry_user_email) {
919 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
920 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
921 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
923 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
924 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
928 /* Set a default domain for the server, based on the email address,
929 * if no server name was already specified.
931 if (!account_wizard->entry_outgoingserver)
934 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
935 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
936 && account_wizard->entry_user_email) {
937 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
939 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
940 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
946 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
948 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
950 /* Do extra validation that couldn't be done for every key press,
951 * either because it was too slow,
952 * or because it requires interaction:
954 if (current_page == account_wizard->page_account_details) {
955 /* Check that the title is not already in use: */
956 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
957 if ((!account_title) || (strlen(account_title) == 0))
960 /* Aavoid a clash with an existing display name: */
961 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
962 account_wizard->account_manager, account_title);
965 /* Warn the user via a dialog: */
966 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
971 else if (current_page == account_wizard->page_user_details) {
972 /* Check that the email address is valud: */
973 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
974 if ((!email_address) || (strlen(email_address) == 0))
977 if (!modest_text_utils_validate_email_address (email_address)) {
978 /* Warn the user via a dialog: */
979 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
981 /* Return focus to the email address entry: */
982 gtk_widget_grab_focus (account_wizard->entry_user_email);
987 /* Make sure that the subsequent pages are appropriate for the provider choice. */
988 create_subsequent_pages (account_wizard);
991 /* TODO: The UI Spec wants us to check that the servernames are valid,
992 * but does not specify how.
995 if(next_page == account_wizard->page_custom_incoming) {
996 set_default_custom_servernames (account_wizard);
998 else if (next_page == account_wizard->page_custom_outgoing) {
999 set_default_custom_servernames (account_wizard);
1002 /* If this is the last page, and this is a click on Finish,
1003 * then attempt to create the dialog.
1005 if(!next_page) /* This is NULL when this is a click on Finish. */
1007 create_account (account_wizard);
1014 static gboolean entry_is_empty (GtkWidget *entry)
1019 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1020 if ((!text) || (strlen(text) == 0))
1027 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1029 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1031 gboolean enable_next = TRUE;
1032 if (current_page == account_wizard->page_welcome) {
1035 else if (current_page == account_wizard->page_account_details) {
1036 /* The account details title is mandatory: */
1037 if (entry_is_empty(account_wizard->entry_account_title))
1038 enable_next = FALSE;
1040 else if (current_page == account_wizard->page_user_details) {
1041 /* The user details username is mandatory: */
1042 if (entry_is_empty(account_wizard->entry_user_username))
1043 enable_next = FALSE;
1045 /* The user details email address is mandatory: */
1046 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1047 enable_next = FALSE;
1049 else if (current_page == account_wizard->page_custom_incoming) {
1050 /* The custom incoming server is mandatory: */
1051 if (entry_is_empty(account_wizard->entry_incomingserver))
1052 enable_next = FALSE;
1055 /* Enable the buttons,
1056 * identifying them via their associated response codes:
1058 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1059 gtk_dialog_set_response_sensitive (dialog_base,
1060 MODEST_WIZARD_DIALOG_NEXT,
1063 /* Disable the Finish button until we are on the last page,
1064 * because HildonWizardDialog enables this for all but the first page: */
1065 GtkNotebook *notebook = NULL;
1066 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1068 gint current = gtk_notebook_get_current_page (notebook);
1069 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1070 gboolean is_last = (current == last);
1073 gtk_dialog_set_response_sensitive (dialog_base,
1074 MODEST_WIZARD_DIALOG_FINISH,
1080 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1082 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1083 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1086 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1087 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1088 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1089 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1091 /* Provide a vfunc implementation so we can decide
1092 * when to enable/disable the prev/next buttons.
1094 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1095 base_klass->before_next = on_before_next;
1096 base_klass->enable_buttons = on_enable_buttons;
1100 show_error (GtkWindow *parent_window, const gchar* text)
1102 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1108 gtk_dialog_run (dialog);
1109 gtk_widget_destroy (GTK_WIDGET (dialog));
1112 /** Attempt to create the account from the information that the user has entered.
1113 * @result: TRUE if the account was successfully created.
1116 create_account (ModestEasysetupWizardDialog *self)
1118 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1120 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1126 /* We should have checked for this already,
1127 * and changed that name accordingly,
1128 * but let's check again just in case:
1130 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1133 /* Increment the non-user visible name if necessary,
1134 * based on the display name: */
1135 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1136 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1137 account_name_start, FALSE /* not a server account */);
1138 g_free (account_name_start);
1140 /* username and password (for both incoming and outgoing): */
1141 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1142 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1144 /* Incoming server: */
1145 /* Note: We need something as default for the ModestProtocol values,
1146 * or modest_account_mgr_add_server_account will fail. */
1147 gchar* servername_incoming = NULL;
1148 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1149 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1150 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1152 /* Get details from the specified presets: */
1153 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1154 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1158 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1159 TRUE /* incoming */);
1161 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1162 TRUE /* incoming */);
1165 /* We don't check for SMTP here as that is impossible for an incoming server. */
1166 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1167 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1168 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1169 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1171 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1172 TRUE /* incoming */);
1175 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1176 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1178 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1179 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1182 /* Use custom pages because no preset was specified: */
1183 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1185 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1186 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1188 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1189 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1191 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1192 ? MODEST_PROTOCOL_AUTH_PASSWORD
1193 : MODEST_PROTOCOL_AUTH_NONE;
1197 /* First we add the 2 server accounts, and then we add the account that uses them.
1198 * If we don't do it in this order then we will experience a crash. */
1200 /* Add a (incoming) server account, to be used by the account: */
1201 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1202 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1203 store_name_start, TRUE /* server account */);
1204 g_free (store_name_start);
1205 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1207 servername_incoming,
1210 protocol_security_incoming,
1211 protocol_authentication_incoming);
1213 g_free (servername_incoming);
1216 /* TODO: Provide a Logical ID for the text: */
1217 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1222 /* There must be at least one account now: */
1223 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1226 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1228 g_slist_free (account_names);
1231 /* Outgoing server: */
1232 gchar* servername_outgoing = NULL;
1233 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1234 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1235 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1239 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1240 FALSE /* incoming */);
1242 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1243 FALSE /* incoming */);
1245 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1246 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1247 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1248 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1250 ModestPresetsSecurity security_outgoing =
1251 modest_presets_get_info_server_security (priv->presets, provider_id,
1252 FALSE /* incoming */);
1254 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1255 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1256 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1258 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1259 /* TODO: There is no SMTP authentication enum for presets. */
1262 /* Use custom pages because no preset was specified: */
1263 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1265 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1267 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1268 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1270 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1271 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1274 gboolean specific = gtk_toggle_button_get_active (
1275 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1280 /* Add a (outgoing) server account to be used by the account: */
1281 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1282 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1283 transport_name_start, TRUE /* server account */);
1284 g_free (transport_name_start);
1285 created = modest_account_mgr_add_server_account (self->account_manager,
1287 servername_outgoing,
1290 protocol_security_outgoing,
1291 protocol_authentication_outgoing);
1293 g_free (servername_outgoing);
1296 /* TODO: Provide a Logical ID for the text: */
1297 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1302 /* Create the account, which will contain the two "server accounts": */
1303 created = modest_account_mgr_add_account (self->account_manager, account_name,
1304 store_name, /* The name of our POP/IMAP server account. */
1305 transport_name /* The name of our SMTP server account. */);
1306 g_free (store_name);
1307 g_free (transport_name);
1310 /* TODO: Provide a Logical ID for the text: */
1311 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1315 /* The user name and email address must be set additionally: */
1316 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1317 modest_account_mgr_set_string (self->account_manager, account_name,
1318 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1320 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1321 modest_account_mgr_set_string (self->account_manager, account_name,
1322 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1324 /* Set the display name: */
1325 modest_account_mgr_set_string (self->account_manager, account_name,
1326 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1328 /* Save the connection-specific SMTP server accounts. */
1329 if (self->specific_window)
1330 return modest_connection_specific_smtp_window_save_server_accounts (
1331 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1333 g_free (account_name);