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);
242 on_entry_max (EasysetupValidatingEntry *self, gpointer user_data)
244 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
245 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
249 create_page_account_details (ModestEasysetupWizardDialog *self)
251 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
252 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
253 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
254 gtk_widget_show (label);
256 /* Create a size group to be used by all captions.
257 * Note that HildonCaption does not create a default size group if we do not specify one.
258 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
259 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
261 /* The country widgets: */
262 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
263 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
264 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
265 gtk_widget_show (self->combo_account_country);
266 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
267 gtk_widget_show (caption);
269 /* connect to country combo's changed signal, so we can fill the provider combo: */
270 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
271 G_CALLBACK (on_combo_account_country), self);
273 GtkWidget *separator = gtk_hseparator_new ();
274 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
275 gtk_widget_show (separator);
277 /* The service provider widgets: */
278 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
280 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
281 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
282 gtk_widget_show (self->combo_account_serviceprovider);
283 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
284 gtk_widget_show (caption);
286 /* connect to providers combo's changed signal, so we can fill the email address: */
287 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
288 G_CALLBACK (on_combo_account_serviceprovider), self);
290 /* TODO: Default to the current country somehow.
291 * But I don't know how to get the information that is specified in the
292 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
294 * This is probably not the best choice of gconf key:
295 * This is the "mcc used in the last pairing", ie. the last connection you made.
296 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
299 GConfClient *client = gconf_client_get_default ();
300 GError *error = NULL;
301 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
302 gint mcc_id = gconf_client_get_int(client, key, &error);
308 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
309 g_error_free (error);
315 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
316 * This might just be a Maemo bug.
320 /* For now, we default to Finland when there is nothing better: */
324 easysetup_country_combo_box_set_active_country_id (
325 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
328 /* The description widgets: */
329 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
331 /* Set a default account title, choosing one that does not already exist: */
332 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
333 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
334 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
335 self->account_manager, default_account_name_start);
336 g_free (default_account_name_start);
337 default_account_name_start = NULL;
339 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
340 g_free (default_account_name);
341 default_account_name = NULL;
343 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
344 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
345 gtk_widget_show (self->entry_account_title);
346 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
347 gtk_widget_show (caption);
349 /* Prevent the use of some characters in the account title,
350 * as required by our UI specification: */
351 GList *list_prevent = NULL;
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 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
358 list_prevent = g_list_append (list_prevent, "“");
359 list_prevent = g_list_append (list_prevent, "<");
360 list_prevent = g_list_append (list_prevent, ">");
361 list_prevent = g_list_append (list_prevent, "|");
362 list_prevent = g_list_append (list_prevent, "^");
363 easysetup_validating_entry_set_unallowed_characters (
364 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
365 g_list_free (list_prevent);
367 /* Set max length as in the UI spec:
368 * The UI spec seems to want us to show a dialog if we hit the maximum. */
369 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
370 easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_account_title),
373 gtk_widget_show (GTK_WIDGET (box));
375 return GTK_WIDGET (box);
379 create_page_user_details (ModestEasysetupWizardDialog *self)
381 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
383 /* Create a size group to be used by all captions.
384 * Note that HildonCaption does not create a default size group if we do not specify one.
385 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
386 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
388 /* The name widgets: */
389 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
390 /* Auto-capitalization is the default, so let's turn it off: */
391 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
392 /* Set max length as in the UI spec:
393 * The UI spec seems to want us to show a dialog if we hit the maximum. */
394 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
395 easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_name),
397 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
398 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
399 gtk_widget_show (self->entry_user_name);
400 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
401 gtk_widget_show (caption);
403 /* Prevent the use of some characters in the name,
404 * as required by our UI specification: */
405 GList *list_prevent = NULL;
406 list_prevent = g_list_append (list_prevent, "<");
407 list_prevent = g_list_append (list_prevent, ">");
408 easysetup_validating_entry_set_unallowed_characters (
409 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
410 g_list_free (list_prevent);
412 /* The username widgets: */
413 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
414 /* Auto-capitalization is the default, so let's turn it off: */
415 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
416 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
417 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
418 gtk_widget_show (self->entry_user_username);
419 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
420 gtk_widget_show (caption);
422 /* Prevent the use of some characters in the username,
423 * as required by our UI specification: */
424 easysetup_validating_entry_set_unallowed_characters_whitespace (
425 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
427 /* Set max length as in the UI spec:
428 * The UI spec seems to want us to show a dialog if we hit the maximum. */
429 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
430 easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_username),
433 /* The password widgets: */
434 self->entry_user_password = gtk_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_password), HILDON_GTK_INPUT_MODE_FULL);
437 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
438 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
439 caption = create_caption_new_with_asterix (self, sizegroup,
440 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
441 gtk_widget_show (self->entry_user_password);
442 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
443 gtk_widget_show (caption);
445 /* The email address widgets: */
446 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
447 /* Auto-capitalization is the default, so let's turn it off: */
448 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
449 caption = create_caption_new_with_asterix (self, sizegroup,
450 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
451 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
452 gtk_widget_show (self->entry_user_email);
453 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
454 gtk_widget_show (caption);
456 /* Set max length as in the UI spec:
457 * The UI spec seems to want us to show a dialog if we hit the maximum. */
458 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
459 easysetup_validating_entry_set_max_func (EASYSETUP_VALIDATING_ENTRY (self->entry_user_email),
463 gtk_widget_show (GTK_WIDGET (box));
465 return GTK_WIDGET (box);
468 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
470 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
471 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
472 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
473 gtk_widget_show (label);
474 gtk_widget_show (GTK_WIDGET (box));
475 return GTK_WIDGET (box);
478 /** Change the caption title for the incoming server,
479 * as specified in the UI spec:
481 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
483 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
484 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
486 (protocol == MODEST_PROTOCOL_STORE_POP ?
487 _("mail_fi_emailtype_pop3") :
488 _("mail_fi_emailtype_imap") );
491 /* Note that this produces a compiler warning,
492 * because the compiler does not know that the translated string will have a %s in it.
493 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
494 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
495 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
496 g_free(incomingserver_title);
499 /** Change the caption title for the incoming server,
500 * as specified in the UI spec:
502 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
504 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
505 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
507 /* Fill the combo with appropriately titled choices for POP or IMAP. */
508 /* The choices are the same, but the titles are different, as in the UI spec. */
509 modest_serversecurity_combo_box_fill (
510 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
513 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
515 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
516 update_incoming_server_title (self);
517 update_incoming_server_security_choices (self);
520 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
522 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
524 /* Create a size group to be used by all captions.
525 * Note that HildonCaption does not create a default size group if we do not specify one.
526 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
527 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
529 /* The incoming server widgets: */
530 if (!self->combo_incoming_servertype)
531 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
532 easysetup_servertype_combo_box_set_active_servertype (
533 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
534 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
535 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
536 gtk_widget_show (self->combo_incoming_servertype);
537 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
538 gtk_widget_show (caption);
540 if(!self->entry_incomingserver)
541 self->entry_incomingserver = gtk_entry_new ();
542 /* Auto-capitalization is the default, so let's turn it off: */
543 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
544 set_default_custom_servernames (self);
546 if (self->caption_incoming)
547 gtk_widget_destroy (self->caption_incoming);
549 /* The caption title will be updated in update_incoming_server_title().
550 * so this default text will never be seen: */
551 /* (Note: Changing the title seems pointless. murrayc) */
552 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
553 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
554 update_incoming_server_title (self);
555 gtk_widget_show (self->entry_incomingserver);
556 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
557 gtk_widget_show (self->caption_incoming);
559 /* Change the caption title when the servertype changes,
560 * as in the UI spec: */
561 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
562 G_CALLBACK (on_combo_servertype_changed), self);
564 /* The secure connection widgets: */
565 if (!self->combo_incoming_security)
566 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
567 update_incoming_server_security_choices (self);
568 modest_serversecurity_combo_box_set_active_serversecurity (
569 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
570 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
571 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
572 gtk_widget_show (self->combo_incoming_security);
573 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
574 gtk_widget_show (caption);
576 if(!self->checkbox_incoming_auth)
577 self->checkbox_incoming_auth =
578 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
579 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, MODEST_MARGIN_HALF);
580 gtk_widget_show (self->checkbox_incoming_auth);
582 gtk_widget_show (GTK_WIDGET (box));
584 return GTK_WIDGET (box);
588 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
590 GtkWidget *widget = GTK_WIDGET (user_data);
592 /* Enable the widget only if the toggle button is active: */
593 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
594 gtk_widget_set_sensitive (widget, enable);
597 /* Make the sensitivity of a widget depend on a toggle button.
600 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
602 g_signal_connect (G_OBJECT (button), "toggled",
603 G_CALLBACK (on_toggle_button_changed), widget);
605 /* Set the starting sensitivity: */
606 on_toggle_button_changed (button, widget);
610 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
612 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
614 /* Create the window, if necessary: */
615 if (!(self->specific_window)) {
616 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
617 modest_connection_specific_smtp_window_fill_with_connections (
618 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
619 NULL /* account_name, not known yet. */);
622 /* Show the window: */
623 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
624 gtk_widget_show (self->specific_window);
627 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
629 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
631 /* Create a size group to be used by all captions.
632 * Note that HildonCaption does not create a default size group if we do not specify one.
633 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
634 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
636 /* The outgoing server widgets: */
637 if (!self->entry_outgoingserver)
638 self->entry_outgoingserver = gtk_entry_new ();
639 /* Auto-capitalization is the default, so let's turn it off: */
640 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
641 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
642 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
643 gtk_widget_show (self->entry_outgoingserver);
644 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
645 gtk_widget_show (caption);
646 set_default_custom_servernames (self);
648 /* The secure connection widgets: */
649 if (!self->combo_outgoing_security)
650 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
651 modest_serversecurity_combo_box_fill (
652 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
653 modest_serversecurity_combo_box_set_active_serversecurity (
654 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
655 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
656 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
657 gtk_widget_show (self->combo_outgoing_security);
658 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
659 gtk_widget_show (caption);
661 /* The secure authentication widgets: */
662 if (!self->combo_outgoing_auth)
663 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
664 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
665 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
666 gtk_widget_show (self->combo_outgoing_auth);
667 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
668 gtk_widget_show (caption);
670 /* connection-specific checkbox: */
671 if (!self->checkbox_outgoing_smtp_specific) {
672 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
673 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
676 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, MODEST_MARGIN_HALF);
677 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
679 GtkWidget *separator = gtk_hseparator_new ();
680 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
681 gtk_widget_show (separator);
683 /* Connection-specific SMTP-Severs Edit button: */
684 if (!self->button_outgoing_smtp_servers)
685 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
686 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
687 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
688 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
689 gtk_widget_show (self->button_outgoing_smtp_servers);
690 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
691 gtk_widget_show (caption);
693 /* Only enable the button when the checkbox is checked: */
694 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
695 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
697 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
698 G_CALLBACK (on_button_outgoing_smtp_servers), self);
701 gtk_widget_show (GTK_WIDGET (box));
703 return GTK_WIDGET (box);
706 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
708 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
709 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
710 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
711 gtk_widget_show (label);
713 if (!self->button_edit)
714 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
715 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
716 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
717 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
718 gtk_widget_show (self->button_edit);
719 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
720 gtk_widget_show (caption);
722 gtk_widget_show (GTK_WIDGET (box));
723 return GTK_WIDGET (box);
730 on_response (ModestWizardDialog *wizard_dialog,
734 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
735 invoke_enable_buttons_vfunc (self);
739 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
741 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
743 /* Create the notebook to be used by the ModestWizardDialog base class:
744 * Each page of the notebook will be a page of the wizard: */
745 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
747 /* Set the notebook used by the ModestWizardDialog base class: */
748 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
750 /* Set the wizard title:
751 * The actual window title will be a combination of this and the page's tab label title. */
752 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
754 /* Read in the information about known service providers: */
755 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
757 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
758 priv->presets = modest_presets_new (filepath);
759 if (!(priv->presets)) {
760 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
763 g_assert(priv->presets);
766 /* Get the account manager object,
767 * so we can check for existing accounts,
768 * and create new accounts: */
769 self->account_manager = modest_runtime_get_account_mgr ();
770 g_assert (self->account_manager);
771 g_object_ref (self->account_manager);
773 /* Create the common pages,
775 self->page_welcome = create_page_welcome (self);
776 self->page_account_details = create_page_account_details (self);
777 self->page_user_details = create_page_user_details (self);
779 /* Add the common pages: */
780 gtk_notebook_append_page (notebook, self->page_welcome,
781 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
782 gtk_notebook_append_page (notebook, self->page_account_details,
783 gtk_label_new (_("mcen_ti_accountdetails")));
784 gtk_notebook_append_page (notebook, self->page_user_details,
785 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
787 /* Create and add the easysetup-specific pages,
788 * because we need _some_ final page to enable the Next and Finish buttons: */
789 create_subsequent_easysetup_pages (self);
792 /* Connect to the dialog's response signal so we can enable/disable buttons
793 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
794 * Note that we use g_signal_connect_after() instead of g_signal_connect()
795 * so that we can be enable/disable after ModestWizardDialog has done its own
796 * enabling/disabling of buttons.
798 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
799 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
801 * It's not enough to connect to the notebook's switch-page signal, because
802 * ModestWizardDialog's "response" signal handler enables the buttons itself,
803 * _after_ switching the page (understandably).
804 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
805 * then gtk_notebook_get_current_page() would return an incorrect value.)
807 g_signal_connect_after (G_OBJECT (self), "response",
808 G_CALLBACK (on_response), self);
811 ModestEasysetupWizardDialog*
812 modest_easysetup_wizard_dialog_new (void)
814 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
817 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
819 GtkNotebook *notebook = NULL;
820 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
823 /* Create the custom pages: */
824 if(!(self->page_custom_incoming)) {
825 self->page_custom_incoming = create_page_custom_incoming (self);
828 if(!(self->page_custom_outgoing)) {
829 self->page_custom_outgoing = create_page_custom_outgoing (self);
832 if(!(self->page_complete_customsetup)) {
833 self->page_complete_customsetup = create_page_complete_custom (self);
836 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
837 gtk_notebook_append_page (notebook, self->page_custom_incoming,
838 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
840 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
841 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
842 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
844 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
845 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
846 gtk_label_new (_("mcen_ti_emailsetup_complete")));
849 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
851 GtkNotebook *notebook = NULL;
852 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
855 /* Create the easysetup-specific pages: */
856 if(!self->page_complete_easysetup)
857 self->page_complete_easysetup = create_page_complete_easysetup (self);
859 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
860 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
861 gtk_label_new (_("mcen_ti_emailsetup_complete")));
864 /* After the user details page,
865 * the following pages depend on whether "Other" was chosen
866 * in the provider combobox on the account page
868 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
870 if (easysetup_provider_combo_box_get_active_provider_id (
871 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
872 /* "Other..." was selected: */
874 /* Make sure that the easysetup pages do not exist: */
875 if(self->page_complete_easysetup) {
876 gtk_widget_destroy (self->page_complete_easysetup);
877 self->page_complete_easysetup = NULL;
880 create_subsequent_customsetup_pages (self);
883 /* A specific provider was selected: */
885 /* Make sure that the custom pages do not exist:
886 * Because they will be used if they exist, when creating the account. */
887 if(self->page_custom_incoming) {
888 gtk_widget_destroy (self->page_custom_incoming);
889 self->page_custom_incoming = NULL;
892 if(self->page_custom_outgoing) {
893 gtk_widget_destroy (self->page_custom_outgoing);
894 self->page_custom_outgoing = NULL;
897 if(self->page_complete_customsetup) {
898 gtk_widget_destroy (self->page_complete_customsetup);
899 self->page_complete_customsetup = NULL;
903 /* Create the easysetup pages: */
904 create_subsequent_easysetup_pages (self);
910 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
915 gchar* at = g_utf8_strchr (email_address, -1, '@');
916 if (!at || (g_utf8_strlen (at, -1) < 2))
919 gchar* domain = g_utf8_next_char (at);
923 const gchar* hostname = NULL;
924 if (servertype == MODEST_PROTOCOL_STORE_POP)
926 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
928 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
934 return g_strdup_printf ("%s.%s", hostname, domain);
937 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
939 if (!account_wizard->entry_incomingserver)
942 /* Set a default domain for the server, based on the email address,
943 * if no server name was already specified.
945 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
946 if ((!incoming_existing || (strlen(incoming_existing) == 0))
947 && account_wizard->entry_user_email) {
948 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
949 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
950 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
952 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
953 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
957 /* Set a default domain for the server, based on the email address,
958 * if no server name was already specified.
960 if (!account_wizard->entry_outgoingserver)
963 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
964 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
965 && account_wizard->entry_user_email) {
966 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
968 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
969 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
975 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
977 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
979 /* Do extra validation that couldn't be done for every key press,
980 * either because it was too slow,
981 * or because it requires interaction:
983 if (current_page == account_wizard->page_account_details) {
984 /* Check that the title is not already in use: */
985 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
986 if ((!account_title) || (strlen(account_title) == 0))
989 /* Aavoid a clash with an existing display name: */
990 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
991 account_wizard->account_manager, account_title);
994 /* Warn the user via a dialog: */
995 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1000 else if (current_page == account_wizard->page_user_details) {
1001 /* Check that the email address is valud: */
1002 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1003 if ((!email_address) || (strlen(email_address) == 0))
1006 if (!modest_text_utils_validate_email_address (email_address)) {
1007 /* Warn the user via a dialog: */
1008 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1010 /* Return focus to the email address entry: */
1011 gtk_widget_grab_focus (account_wizard->entry_user_email);
1016 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1017 create_subsequent_pages (account_wizard);
1020 /* TODO: The UI Spec wants us to check that the servernames are valid,
1021 * but does not specify how.
1024 if(next_page == account_wizard->page_custom_incoming) {
1025 set_default_custom_servernames (account_wizard);
1027 else if (next_page == account_wizard->page_custom_outgoing) {
1028 set_default_custom_servernames (account_wizard);
1031 /* If this is the last page, and this is a click on Finish,
1032 * then attempt to create the dialog.
1034 if(!next_page) /* This is NULL when this is a click on Finish. */
1036 create_account (account_wizard);
1043 static gboolean entry_is_empty (GtkWidget *entry)
1048 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1049 if ((!text) || (strlen(text) == 0))
1056 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1058 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1060 gboolean enable_next = TRUE;
1061 if (current_page == account_wizard->page_welcome) {
1064 else if (current_page == account_wizard->page_account_details) {
1065 /* The account details title is mandatory: */
1066 if (entry_is_empty(account_wizard->entry_account_title))
1067 enable_next = FALSE;
1069 else if (current_page == account_wizard->page_user_details) {
1070 /* The user details username is mandatory: */
1071 if (entry_is_empty(account_wizard->entry_user_username))
1072 enable_next = FALSE;
1074 /* The user details email address is mandatory: */
1075 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1076 enable_next = FALSE;
1078 else if (current_page == account_wizard->page_custom_incoming) {
1079 /* The custom incoming server is mandatory: */
1080 if (entry_is_empty(account_wizard->entry_incomingserver))
1081 enable_next = FALSE;
1084 /* Enable the buttons,
1085 * identifying them via their associated response codes:
1087 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1088 gtk_dialog_set_response_sensitive (dialog_base,
1089 MODEST_WIZARD_DIALOG_NEXT,
1092 /* Disable the Finish button until we are on the last page,
1093 * because HildonWizardDialog enables this for all but the first page: */
1094 GtkNotebook *notebook = NULL;
1095 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1097 gint current = gtk_notebook_get_current_page (notebook);
1098 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1099 gboolean is_last = (current == last);
1102 gtk_dialog_set_response_sensitive (dialog_base,
1103 MODEST_WIZARD_DIALOG_FINISH,
1109 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1111 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1112 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1115 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1116 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1117 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1118 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1120 /* Provide a vfunc implementation so we can decide
1121 * when to enable/disable the prev/next buttons.
1123 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1124 base_klass->before_next = on_before_next;
1125 base_klass->enable_buttons = on_enable_buttons;
1129 show_error (GtkWindow *parent_window, const gchar* text)
1131 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1137 gtk_dialog_run (dialog);
1138 gtk_widget_destroy (GTK_WIDGET (dialog));
1141 /** Attempt to create the account from the information that the user has entered.
1142 * @result: TRUE if the account was successfully created.
1145 create_account (ModestEasysetupWizardDialog *self)
1147 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1149 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1155 /* We should have checked for this already,
1156 * and changed that name accordingly,
1157 * but let's check again just in case:
1159 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1162 /* Increment the non-user visible name if necessary,
1163 * based on the display name: */
1164 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1165 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1166 account_name_start, FALSE /* not a server account */);
1167 g_free (account_name_start);
1169 /* username and password (for both incoming and outgoing): */
1170 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1171 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1173 /* Incoming server: */
1174 /* Note: We need something as default for the ModestProtocol values,
1175 * or modest_account_mgr_add_server_account will fail. */
1176 gchar* servername_incoming = NULL;
1177 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1178 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1179 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1181 /* Get details from the specified presets: */
1182 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1183 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1187 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1188 TRUE /* incoming */);
1190 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1191 TRUE /* incoming */);
1194 /* We don't check for SMTP here as that is impossible for an incoming server. */
1195 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1196 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1197 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1198 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1200 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1201 TRUE /* incoming */);
1204 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1205 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1207 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1208 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1211 /* Use custom pages because no preset was specified: */
1212 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1214 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1215 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1217 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1218 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1220 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1221 ? MODEST_PROTOCOL_AUTH_PASSWORD
1222 : MODEST_PROTOCOL_AUTH_NONE;
1226 /* First we add the 2 server accounts, and then we add the account that uses them.
1227 * If we don't do it in this order then we will experience a crash. */
1229 /* Add a (incoming) server account, to be used by the account: */
1230 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1231 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1232 store_name_start, TRUE /* server account */);
1233 g_free (store_name_start);
1234 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1236 servername_incoming,
1239 protocol_security_incoming,
1240 protocol_authentication_incoming);
1242 g_free (servername_incoming);
1245 /* TODO: Provide a Logical ID for the text: */
1246 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1251 /* There must be at least one account now: */
1252 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1255 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1257 g_slist_free (account_names);
1260 /* Outgoing server: */
1261 gchar* servername_outgoing = NULL;
1262 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1263 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1264 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1268 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1269 FALSE /* incoming */);
1271 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1272 FALSE /* incoming */);
1274 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1275 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1276 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1277 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1279 ModestPresetsSecurity security_outgoing =
1280 modest_presets_get_info_server_security (priv->presets, provider_id,
1281 FALSE /* incoming */);
1283 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1284 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1285 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1287 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1288 /* TODO: There is no SMTP authentication enum for presets. */
1291 /* Use custom pages because no preset was specified: */
1292 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1294 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1296 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1297 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1299 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1300 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1303 /* Add a (outgoing) server account to be used by the account: */
1304 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1305 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1306 transport_name_start, TRUE /* server account */);
1307 g_free (transport_name_start);
1308 created = modest_account_mgr_add_server_account (self->account_manager,
1310 servername_outgoing,
1313 protocol_security_outgoing,
1314 protocol_authentication_outgoing);
1316 g_free (servername_outgoing);
1319 /* TODO: Provide a Logical ID for the text: */
1320 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1325 /* Create the account, which will contain the two "server accounts": */
1326 created = modest_account_mgr_add_account (self->account_manager, account_name,
1327 store_name, /* The name of our POP/IMAP server account. */
1328 transport_name /* The name of our SMTP server account. */);
1329 g_free (store_name);
1330 g_free (transport_name);
1333 /* TODO: Provide a Logical ID for the text: */
1334 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1338 /* The user name and email address must be set additionally: */
1339 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1340 modest_account_mgr_set_string (self->account_manager, account_name,
1341 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1343 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1344 modest_account_mgr_set_string (self->account_manager, account_name,
1345 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1347 /* Set the display name: */
1348 modest_account_mgr_set_string (self->account_manager, account_name,
1349 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1351 /* Save the connection-specific SMTP server accounts. */
1352 if (self->specific_window)
1353 return modest_connection_specific_smtp_window_save_server_accounts (
1354 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1356 g_free (account_name);