1 /* Copyright (c) 2007, Nokia Corporation
7 #include "modest-easysetup-wizard.h"
8 #include <glib/gi18n.h>
9 #include <gtk/gtknotebook.h>
10 #include <gtk/gtkvbox.h>
11 #include <gtk/gtklabel.h>
12 #include <gtk/gtkcombobox.h>
13 #include <gtk/gtkentry.h>
14 #include <gtk/gtkbutton.h>
15 #include <gtk/gtkcheckbutton.h>
16 #include <gtk/gtkmessagedialog.h>
17 #include <gtk/gtkseparator.h>
18 #include <hildon-widgets/hildon-caption.h>
19 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
20 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
21 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
22 #include "widgets/modest-serversecurity-combo-box.h"
23 #include "widgets/modest-secureauth-combo-box.h"
24 #include "widgets/modest-validating-entry.h"
25 #include "modest-text-utils.h"
26 #include "modest-account-mgr.h"
27 #include "modest-account-mgr-helpers.h"
28 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
29 #include "maemo/modest-connection-specific-smtp-window.h"
30 #include "maemo/modest-maemo-ui-constants.h"
31 #include <gconf/gconf-client.h>
32 #include <string.h> /* For strlen(). */
34 /* Include config.h so that _() works: */
39 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
41 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
43 #define WIZARD_DIALOG_GET_PRIVATE(o) \
44 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
46 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
48 struct _ModestEasysetupWizardDialogPrivate
50 ModestPresets *presets;
54 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
55 GValue *value, GParamSpec *pspec)
57 switch (property_id) {
59 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
64 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
65 const GValue *value, GParamSpec *pspec)
67 switch (property_id) {
69 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
74 modest_easysetup_wizard_dialog_dispose (GObject *object)
76 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
77 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
81 modest_easysetup_wizard_dialog_finalize (GObject *object)
83 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
84 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
86 if (self->account_manager)
87 g_object_unref (G_OBJECT (self->account_manager));
90 modest_presets_destroy (priv->presets);
92 if (self->specific_window)
93 gtk_widget_destroy (self->specific_window);
95 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
99 show_error (GtkWindow *parent_window, const gchar* text);
102 create_account (ModestEasysetupWizardDialog *self);
105 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
108 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
110 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
113 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
115 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
117 /* Call the vfunc, which may be overridden by derived classes: */
118 if (klass->enable_buttons) {
119 GtkNotebook *notebook = NULL;
120 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
122 const gint current_page_num = gtk_notebook_get_current_page (notebook);
123 if (current_page_num == -1)
126 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
127 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
132 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
134 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
136 invoke_enable_buttons_vfunc(self);
140 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
142 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
144 invoke_enable_buttons_vfunc(self);
147 /** This is a convenience function to create a caption containing a mandatory widget.
148 * When the widget is edited, the enable_buttons() vfunc will be called.
150 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
155 HildonCaptionStatus flag)
157 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
159 /* The translated strings seem to already contain the *,
160 * but this code can be used if that is not true in future.
163 /* Add a * character to indicate mandatory fields,
164 * as specified in our "Email UI Specification": */
165 if (flag == HILDON_CAPTION_MANDATORY) {
166 gchar* title = g_strdup_printf("%s*", value);
167 caption = hildon_caption_new (group, title, control, icon, flag);
171 caption = hildon_caption_new (group, value, control, icon, flag);
174 /* Connect to the appropriate changed signal for the widget,
175 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
177 if (GTK_IS_ENTRY (control)) {
178 g_signal_connect (G_OBJECT (control), "changed",
179 G_CALLBACK (on_caption_entry_changed), self);
182 else if (GTK_IS_COMBO_BOX (control)) {
183 g_signal_connect (G_OBJECT (control), "changed",
184 G_CALLBACK (on_caption_combobox_changed), self);
191 create_page_welcome (ModestEasysetupWizardDialog *self)
193 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
194 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
195 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
196 gtk_widget_show (label);
197 gtk_widget_show (GTK_WIDGET (box));
198 return GTK_WIDGET (box);
202 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
204 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
206 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
208 /* Fill the providers combo, based on the selected country: */
209 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
210 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
211 easysetup_provider_combo_box_fill (
212 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
216 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
218 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
220 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
222 /* Fill the providers combo, based on the selected country: */
223 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
224 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
226 gchar* domain_name = NULL;
228 domain_name = modest_presets_get_domain (priv->presets, provider_id);
231 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
233 if (self->entry_user_email)
234 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
236 g_free (domain_name);
238 g_free (provider_id);
243 create_page_account_details (ModestEasysetupWizardDialog *self)
245 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
246 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
247 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
248 gtk_widget_show (label);
250 /* Create a size group to be used by all captions.
251 * Note that HildonCaption does not create a default size group if we do not specify one.
252 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
253 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
255 /* The country widgets: */
256 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
257 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
258 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
259 gtk_widget_show (self->combo_account_country);
260 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
261 gtk_widget_show (caption);
263 /* connect to country combo's changed signal, so we can fill the provider combo: */
264 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
265 G_CALLBACK (on_combo_account_country), self);
267 GtkWidget *separator = gtk_hseparator_new ();
268 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
269 gtk_widget_show (separator);
271 /* The service provider widgets: */
272 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
274 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
275 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
276 gtk_widget_show (self->combo_account_serviceprovider);
277 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
278 gtk_widget_show (caption);
280 /* connect to providers combo's changed signal, so we can fill the email address: */
281 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
282 G_CALLBACK (on_combo_account_serviceprovider), self);
284 /* TODO: Default to the current country somehow.
285 * But I don't know how to get the information that is specified in the
286 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
288 * This is probably not the best choice of gconf key:
289 * This is the "mcc used in the last pairing", ie. the last connection you made.
290 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
293 GConfClient *client = gconf_client_get_default ();
294 GError *error = NULL;
295 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
296 gint mcc_id = gconf_client_get_int(client, key, &error);
302 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
303 g_error_free (error);
309 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
310 * This might just be a Maemo bug.
314 /* For now, we default to Finland when there is nothing better: */
318 easysetup_country_combo_box_set_active_country_id (
319 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
322 /* The description widgets: */
323 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
325 /* Set a default account title, choosing one that does not already exist: */
326 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
327 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
328 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
329 self->account_manager, default_account_name_start);
330 g_free (default_account_name_start);
331 default_account_name_start = NULL;
333 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
334 g_free (default_account_name);
335 default_account_name = NULL;
337 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
338 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
339 gtk_widget_show (self->entry_account_title);
340 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
341 gtk_widget_show (caption);
343 /* Prevent the use of some characters in the account title,
344 * as required by our UI specification: */
345 GList *list_prevent = NULL;
346 list_prevent = g_list_append (list_prevent, "\\");
347 list_prevent = g_list_append (list_prevent, "/");
348 list_prevent = g_list_append (list_prevent, ":");
349 list_prevent = g_list_append (list_prevent, "*");
350 list_prevent = g_list_append (list_prevent, "?");
351 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
352 list_prevent = g_list_append (list_prevent, "“");
353 list_prevent = g_list_append (list_prevent, "<");
354 list_prevent = g_list_append (list_prevent, ">");
355 list_prevent = g_list_append (list_prevent, "|");
356 list_prevent = g_list_append (list_prevent, "^");
357 easysetup_validating_entry_set_unallowed_characters (
358 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
359 g_list_free (list_prevent);
361 /* Set max length as in the UI spec:
362 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
363 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
365 gtk_widget_show (GTK_WIDGET (box));
367 return GTK_WIDGET (box);
371 create_page_user_details (ModestEasysetupWizardDialog *self)
373 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
375 /* Create a size group to be used by all captions.
376 * Note that HildonCaption does not create a default size group if we do not specify one.
377 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
378 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
380 /* The name widgets: */
381 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
382 /* Auto-capitalization is the default, so let's turn it off: */
383 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
384 /* Set max length as in the UI spec:
385 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
386 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
387 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
388 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
389 gtk_widget_show (self->entry_user_name);
390 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
391 gtk_widget_show (caption);
393 /* Prevent the use of some characters in the name,
394 * as required by our UI specification: */
395 GList *list_prevent = NULL;
396 list_prevent = g_list_append (list_prevent, "<");
397 list_prevent = g_list_append (list_prevent, ">");
398 easysetup_validating_entry_set_unallowed_characters (
399 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
400 g_list_free (list_prevent);
402 /* The username widgets: */
403 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
404 /* Auto-capitalization is the default, so let's turn it off: */
405 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
406 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
407 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
408 gtk_widget_show (self->entry_user_username);
409 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
410 gtk_widget_show (caption);
412 /* Prevent the use of some characters in the username,
413 * as required by our UI specification: */
414 easysetup_validating_entry_set_unallowed_characters_whitespace (
415 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
417 /* Set max length as in the UI spec:
418 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
419 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
421 /* The password widgets: */
422 self->entry_user_password = gtk_entry_new ();
423 /* Auto-capitalization is the default, so let's turn it off: */
424 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password), HILDON_GTK_INPUT_MODE_FULL);
425 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
426 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
427 caption = create_caption_new_with_asterix (self, sizegroup,
428 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
429 gtk_widget_show (self->entry_user_password);
430 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
431 gtk_widget_show (caption);
433 /* The email address widgets: */
434 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
435 /* Auto-capitalization is the default, so let's turn it off: */
436 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
437 caption = create_caption_new_with_asterix (self, sizegroup,
438 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
439 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
440 gtk_widget_show (self->entry_user_email);
441 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
442 gtk_widget_show (caption);
444 /* Set max length as in the UI spec:
445 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
446 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
449 gtk_widget_show (GTK_WIDGET (box));
451 return GTK_WIDGET (box);
454 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
456 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
457 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
458 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
459 gtk_widget_show (label);
460 gtk_widget_show (GTK_WIDGET (box));
461 return GTK_WIDGET (box);
464 /** Change the caption title for the incoming server,
465 * as specified in the UI spec:
467 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
469 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
470 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
472 (protocol == MODEST_PROTOCOL_STORE_POP ?
473 _("mail_fi_emailtype_pop3") :
474 _("mail_fi_emailtype_imap") );
477 /* Note that this produces a compiler warning,
478 * because the compiler does not know that the translated string will have a %s in it.
479 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
480 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
481 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
482 g_free(incomingserver_title);
485 /** Change the caption title for the incoming server,
486 * as specified in the UI spec:
488 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
490 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
491 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
493 /* Fill the combo with appropriately titled choices for POP or IMAP. */
494 /* The choices are the same, but the titles are different, as in the UI spec. */
495 modest_serversecurity_combo_box_fill (
496 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
499 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
501 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
502 update_incoming_server_title (self);
503 update_incoming_server_security_choices (self);
506 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
508 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
510 /* Create a size group to be used by all captions.
511 * Note that HildonCaption does not create a default size group if we do not specify one.
512 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
513 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
515 /* The incoming server widgets: */
516 if (!self->combo_incoming_servertype)
517 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
518 easysetup_servertype_combo_box_set_active_servertype (
519 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
520 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
521 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
522 gtk_widget_show (self->combo_incoming_servertype);
523 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
524 gtk_widget_show (caption);
526 if(!self->entry_incomingserver)
527 self->entry_incomingserver = gtk_entry_new ();
528 /* Auto-capitalization is the default, so let's turn it off: */
529 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
530 set_default_custom_servernames (self);
532 if (self->caption_incoming)
533 gtk_widget_destroy (self->caption_incoming);
535 /* The caption title will be updated in update_incoming_server_title().
536 * so this default text will never be seen: */
537 /* (Note: Changing the title seems pointless. murrayc) */
538 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
539 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
540 update_incoming_server_title (self);
541 gtk_widget_show (self->entry_incomingserver);
542 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
543 gtk_widget_show (self->caption_incoming);
545 /* Change the caption title when the servertype changes,
546 * as in the UI spec: */
547 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
548 G_CALLBACK (on_combo_servertype_changed), self);
550 /* The secure connection widgets: */
551 if (!self->combo_incoming_security)
552 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
553 update_incoming_server_security_choices (self);
554 modest_serversecurity_combo_box_set_active_serversecurity (
555 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
556 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
557 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
558 gtk_widget_show (self->combo_incoming_security);
559 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
560 gtk_widget_show (caption);
562 if(!self->checkbox_incoming_auth)
563 self->checkbox_incoming_auth =
564 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
565 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, MODEST_MARGIN_HALF);
566 gtk_widget_show (self->checkbox_incoming_auth);
568 gtk_widget_show (GTK_WIDGET (box));
570 return GTK_WIDGET (box);
574 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
576 GtkWidget *widget = GTK_WIDGET (user_data);
578 /* Enable the widget only if the toggle button is active: */
579 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
580 gtk_widget_set_sensitive (widget, enable);
583 /* Make the sensitivity of a widget depend on a toggle button.
586 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
588 g_signal_connect (G_OBJECT (button), "toggled",
589 G_CALLBACK (on_toggle_button_changed), widget);
591 /* Set the starting sensitivity: */
592 on_toggle_button_changed (button, widget);
596 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
598 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
600 /* Create the window, if necessary: */
601 if (!(self->specific_window)) {
602 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
603 modest_connection_specific_smtp_window_fill_with_connections (
604 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
605 NULL /* account_name, not known yet. */);
608 /* Show the window: */
609 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
610 gtk_widget_show (self->specific_window);
613 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
615 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
617 /* Create a size group to be used by all captions.
618 * Note that HildonCaption does not create a default size group if we do not specify one.
619 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
620 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
622 /* The outgoing server widgets: */
623 if (!self->entry_outgoingserver)
624 self->entry_outgoingserver = gtk_entry_new ();
625 /* Auto-capitalization is the default, so let's turn it off: */
626 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
627 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
628 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
629 gtk_widget_show (self->entry_outgoingserver);
630 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
631 gtk_widget_show (caption);
632 set_default_custom_servernames (self);
634 /* The secure connection widgets: */
635 if (!self->combo_outgoing_security)
636 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
637 modest_serversecurity_combo_box_fill (
638 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
639 modest_serversecurity_combo_box_set_active_serversecurity (
640 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
641 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
642 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
643 gtk_widget_show (self->combo_outgoing_security);
644 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
645 gtk_widget_show (caption);
647 /* The secure authentication widgets: */
648 if (!self->combo_outgoing_auth)
649 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
650 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
651 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
652 gtk_widget_show (self->combo_outgoing_auth);
653 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
654 gtk_widget_show (caption);
656 /* connection-specific checkbox: */
657 if (!self->checkbox_outgoing_smtp_specific) {
658 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
659 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
662 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, MODEST_MARGIN_HALF);
663 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
665 GtkWidget *separator = gtk_hseparator_new ();
666 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
667 gtk_widget_show (separator);
669 /* Connection-specific SMTP-Severs Edit button: */
670 if (!self->button_outgoing_smtp_servers)
671 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
672 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
673 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
674 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
675 gtk_widget_show (self->button_outgoing_smtp_servers);
676 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
677 gtk_widget_show (caption);
679 /* Only enable the button when the checkbox is checked: */
680 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
681 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
683 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
684 G_CALLBACK (on_button_outgoing_smtp_servers), self);
687 gtk_widget_show (GTK_WIDGET (box));
689 return GTK_WIDGET (box);
692 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
694 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
695 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
696 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
697 gtk_widget_show (label);
699 if (!self->button_edit)
700 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
701 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
702 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
703 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
704 gtk_widget_show (self->button_edit);
705 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
706 gtk_widget_show (caption);
708 gtk_widget_show (GTK_WIDGET (box));
709 return GTK_WIDGET (box);
716 on_response (ModestWizardDialog *wizard_dialog,
720 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
721 invoke_enable_buttons_vfunc (self);
725 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
727 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
729 /* Create the notebook to be used by the ModestWizardDialog base class:
730 * Each page of the notebook will be a page of the wizard: */
731 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
733 /* Set the notebook used by the ModestWizardDialog base class: */
734 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
736 /* Set the wizard title:
737 * The actual window title will be a combination of this and the page's tab label title. */
738 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
740 /* Read in the information about known service providers: */
741 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
743 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
744 priv->presets = modest_presets_new (filepath);
745 if (!(priv->presets)) {
746 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
749 g_assert(priv->presets);
752 /* Get the account manager object,
753 * so we can check for existing accounts,
754 * and create new accounts: */
755 self->account_manager = modest_runtime_get_account_mgr ();
756 g_assert (self->account_manager);
757 g_object_ref (self->account_manager);
759 /* Create the common pages,
761 self->page_welcome = create_page_welcome (self);
762 self->page_account_details = create_page_account_details (self);
763 self->page_user_details = create_page_user_details (self);
765 /* Add the common pages: */
766 gtk_notebook_append_page (notebook, self->page_welcome,
767 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
768 gtk_notebook_append_page (notebook, self->page_account_details,
769 gtk_label_new (_("mcen_ti_accountdetails")));
770 gtk_notebook_append_page (notebook, self->page_user_details,
771 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
773 /* Create and add the easysetup-specific pages,
774 * because we need _some_ final page to enable the Next and Finish buttons: */
775 create_subsequent_easysetup_pages (self);
778 /* Connect to the dialog's response signal so we can enable/disable buttons
779 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
780 * Note that we use g_signal_connect_after() instead of g_signal_connect()
781 * so that we can be enable/disable after ModestWizardDialog has done its own
782 * enabling/disabling of buttons.
784 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
785 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
787 * It's not enough to connect to the notebook's switch-page signal, because
788 * ModestWizardDialog's "response" signal handler enables the buttons itself,
789 * _after_ switching the page (understandably).
790 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
791 * then gtk_notebook_get_current_page() would return an incorrect value.)
793 g_signal_connect_after (G_OBJECT (self), "response",
794 G_CALLBACK (on_response), self);
797 ModestEasysetupWizardDialog*
798 modest_easysetup_wizard_dialog_new (void)
800 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
803 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
805 GtkNotebook *notebook = NULL;
806 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
809 /* Create the custom pages: */
810 if(!(self->page_custom_incoming)) {
811 self->page_custom_incoming = create_page_custom_incoming (self);
814 if(!(self->page_custom_outgoing)) {
815 self->page_custom_outgoing = create_page_custom_outgoing (self);
818 if(!(self->page_complete_customsetup)) {
819 self->page_complete_customsetup = create_page_complete_custom (self);
822 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
823 gtk_notebook_append_page (notebook, self->page_custom_incoming,
824 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
826 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
827 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
828 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
830 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
831 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
832 gtk_label_new (_("mcen_ti_emailsetup_complete")));
835 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
837 GtkNotebook *notebook = NULL;
838 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
841 /* Create the easysetup-specific pages: */
842 if(!self->page_complete_easysetup)
843 self->page_complete_easysetup = create_page_complete_easysetup (self);
845 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
846 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
847 gtk_label_new (_("mcen_ti_emailsetup_complete")));
850 /* After the user details page,
851 * the following pages depend on whether "Other" was chosen
852 * in the provider combobox on the account page
854 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
856 if (easysetup_provider_combo_box_get_active_provider_id (
857 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
858 /* "Other..." was selected: */
860 /* Make sure that the easysetup pages do not exist: */
861 if(self->page_complete_easysetup) {
862 gtk_widget_destroy (self->page_complete_easysetup);
863 self->page_complete_easysetup = NULL;
866 create_subsequent_customsetup_pages (self);
869 /* A specific provider was selected: */
871 /* Make sure that the custom pages do not exist:
872 * Because they will be used if they exist, when creating the account. */
873 if(self->page_custom_incoming) {
874 gtk_widget_destroy (self->page_custom_incoming);
875 self->page_custom_incoming = NULL;
878 if(self->page_custom_outgoing) {
879 gtk_widget_destroy (self->page_custom_outgoing);
880 self->page_custom_outgoing = NULL;
883 if(self->page_complete_customsetup) {
884 gtk_widget_destroy (self->page_complete_customsetup);
885 self->page_complete_customsetup = NULL;
889 /* Create the easysetup pages: */
890 create_subsequent_easysetup_pages (self);
896 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
901 gchar* at = g_utf8_strchr (email_address, -1, '@');
902 if (!at || (g_utf8_strlen (at, -1) < 2))
905 gchar* domain = g_utf8_next_char (at);
909 const gchar* hostname = NULL;
910 if (servertype == MODEST_PROTOCOL_STORE_POP)
912 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
914 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
920 return g_strdup_printf ("%s.%s", hostname, domain);
923 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
925 if (!account_wizard->entry_incomingserver)
928 /* Set a default domain for the server, based on the email address,
929 * if no server name was already specified.
931 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
932 if ((!incoming_existing || (strlen(incoming_existing) == 0))
933 && account_wizard->entry_user_email) {
934 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
935 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
936 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
938 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
939 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
943 /* Set a default domain for the server, based on the email address,
944 * if no server name was already specified.
946 if (!account_wizard->entry_outgoingserver)
949 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
950 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
951 && account_wizard->entry_user_email) {
952 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
954 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
955 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
961 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
963 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
965 /* Do extra validation that couldn't be done for every key press,
966 * either because it was too slow,
967 * or because it requires interaction:
969 if (current_page == account_wizard->page_account_details) {
970 /* Check that the title is not already in use: */
971 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
972 if ((!account_title) || (strlen(account_title) == 0))
975 /* Aavoid a clash with an existing display name: */
976 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
977 account_wizard->account_manager, account_title);
980 /* Warn the user via a dialog: */
981 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
986 else if (current_page == account_wizard->page_user_details) {
987 /* Check that the email address is valud: */
988 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
989 if ((!email_address) || (strlen(email_address) == 0))
992 if (!modest_text_utils_validate_email_address (email_address)) {
993 /* Warn the user via a dialog: */
994 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
996 /* Return focus to the email address entry: */
997 gtk_widget_grab_focus (account_wizard->entry_user_email);
1002 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1003 create_subsequent_pages (account_wizard);
1006 /* TODO: The UI Spec wants us to check that the servernames are valid,
1007 * but does not specify how.
1010 if(next_page == account_wizard->page_custom_incoming) {
1011 set_default_custom_servernames (account_wizard);
1013 else if (next_page == account_wizard->page_custom_outgoing) {
1014 set_default_custom_servernames (account_wizard);
1017 /* If this is the last page, and this is a click on Finish,
1018 * then attempt to create the dialog.
1020 if(!next_page) /* This is NULL when this is a click on Finish. */
1022 create_account (account_wizard);
1029 static gboolean entry_is_empty (GtkWidget *entry)
1034 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1035 if ((!text) || (strlen(text) == 0))
1042 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1044 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1046 gboolean enable_next = TRUE;
1047 if (current_page == account_wizard->page_welcome) {
1050 else if (current_page == account_wizard->page_account_details) {
1051 /* The account details title is mandatory: */
1052 if (entry_is_empty(account_wizard->entry_account_title))
1053 enable_next = FALSE;
1055 else if (current_page == account_wizard->page_user_details) {
1056 /* The user details username is mandatory: */
1057 if (entry_is_empty(account_wizard->entry_user_username))
1058 enable_next = FALSE;
1060 /* The user details email address is mandatory: */
1061 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1062 enable_next = FALSE;
1064 else if (current_page == account_wizard->page_custom_incoming) {
1065 /* The custom incoming server is mandatory: */
1066 if (entry_is_empty(account_wizard->entry_incomingserver))
1067 enable_next = FALSE;
1070 /* Enable the buttons,
1071 * identifying them via their associated response codes:
1073 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1074 gtk_dialog_set_response_sensitive (dialog_base,
1075 MODEST_WIZARD_DIALOG_NEXT,
1078 /* Disable the Finish button until we are on the last page,
1079 * because HildonWizardDialog enables this for all but the first page: */
1080 GtkNotebook *notebook = NULL;
1081 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1083 gint current = gtk_notebook_get_current_page (notebook);
1084 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1085 gboolean is_last = (current == last);
1088 gtk_dialog_set_response_sensitive (dialog_base,
1089 MODEST_WIZARD_DIALOG_FINISH,
1095 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1097 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1098 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1101 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1102 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1103 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1104 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1106 /* Provide a vfunc implementation so we can decide
1107 * when to enable/disable the prev/next buttons.
1109 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1110 base_klass->before_next = on_before_next;
1111 base_klass->enable_buttons = on_enable_buttons;
1115 show_error (GtkWindow *parent_window, const gchar* text)
1117 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1123 gtk_dialog_run (dialog);
1124 gtk_widget_destroy (GTK_WIDGET (dialog));
1127 /** Attempt to create the account from the information that the user has entered.
1128 * @result: TRUE if the account was successfully created.
1131 create_account (ModestEasysetupWizardDialog *self)
1133 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1135 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1141 /* We should have checked for this already,
1142 * and changed that name accordingly,
1143 * but let's check again just in case:
1145 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1148 /* Increment the non-user visible name if necessary,
1149 * based on the display name: */
1150 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1151 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1152 account_name_start, FALSE /* not a server account */);
1153 g_free (account_name_start);
1155 /* username and password (for both incoming and outgoing): */
1156 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1157 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1159 /* Incoming server: */
1160 /* Note: We need something as default for the ModestProtocol values,
1161 * or modest_account_mgr_add_server_account will fail. */
1162 gchar* servername_incoming = NULL;
1163 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1164 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1165 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1167 /* Get details from the specified presets: */
1168 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1169 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1173 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1174 TRUE /* incoming */);
1176 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1177 TRUE /* incoming */);
1180 /* We don't check for SMTP here as that is impossible for an incoming server. */
1181 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1182 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1183 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1184 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1186 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1187 TRUE /* incoming */);
1190 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1191 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1193 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1194 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1197 /* Use custom pages because no preset was specified: */
1198 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1200 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1201 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1203 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1204 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1206 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1207 ? MODEST_PROTOCOL_AUTH_PASSWORD
1208 : MODEST_PROTOCOL_AUTH_NONE;
1212 /* First we add the 2 server accounts, and then we add the account that uses them.
1213 * If we don't do it in this order then we will experience a crash. */
1215 /* Add a (incoming) server account, to be used by the account: */
1216 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1217 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1218 store_name_start, TRUE /* server account */);
1219 g_free (store_name_start);
1220 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1222 servername_incoming,
1225 protocol_security_incoming,
1226 protocol_authentication_incoming);
1228 g_free (servername_incoming);
1231 /* TODO: Provide a Logical ID for the text: */
1232 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1237 /* There must be at least one account now: */
1238 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1241 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1243 g_slist_free (account_names);
1246 /* Outgoing server: */
1247 gchar* servername_outgoing = NULL;
1248 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1249 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1250 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1254 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1255 FALSE /* incoming */);
1257 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1258 FALSE /* incoming */);
1260 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1261 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1262 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1263 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1265 ModestPresetsSecurity security_outgoing =
1266 modest_presets_get_info_server_security (priv->presets, provider_id,
1267 FALSE /* incoming */);
1269 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1270 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1271 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1273 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1274 /* TODO: There is no SMTP authentication enum for presets. */
1277 /* Use custom pages because no preset was specified: */
1278 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1280 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1282 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1283 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1285 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1286 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1289 gboolean specific = gtk_toggle_button_get_active (
1290 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1295 /* Add a (outgoing) server account to be used by the account: */
1296 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1297 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1298 transport_name_start, TRUE /* server account */);
1299 g_free (transport_name_start);
1300 created = modest_account_mgr_add_server_account (self->account_manager,
1302 servername_outgoing,
1305 protocol_security_outgoing,
1306 protocol_authentication_outgoing);
1308 g_free (servername_outgoing);
1311 /* TODO: Provide a Logical ID for the text: */
1312 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1317 /* Create the account, which will contain the two "server accounts": */
1318 created = modest_account_mgr_add_account (self->account_manager, account_name,
1319 store_name, /* The name of our POP/IMAP server account. */
1320 transport_name /* The name of our SMTP server account. */);
1321 g_free (store_name);
1322 g_free (transport_name);
1325 /* TODO: Provide a Logical ID for the text: */
1326 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1330 /* The user name and email address must be set additionally: */
1331 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1332 modest_account_mgr_set_string (self->account_manager, account_name,
1333 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1335 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1336 modest_account_mgr_set_string (self->account_manager, account_name,
1337 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1339 /* Set the display name: */
1340 modest_account_mgr_set_string (self->account_manager, account_name,
1341 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1343 /* Save the connection-specific SMTP server accounts. */
1344 if (self->specific_window)
1345 return modest_connection_specific_smtp_window_save_server_accounts (
1346 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1348 g_free (account_name);