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 (ModestValidatingEntry *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 (modest_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 modest_validating_entry_set_unallowed_characters (
364 MODEST_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 modest_validating_entry_set_max_func (MODEST_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 (modest_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 modest_validating_entry_set_max_func (MODEST_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 modest_validating_entry_set_unallowed_characters (
409 MODEST_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 (modest_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 modest_validating_entry_set_unallowed_characters_whitespace (
425 MODEST_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 modest_validating_entry_set_max_func (MODEST_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 (modest_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 modest_validating_entry_set_max_func (MODEST_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 = gtk_check_button_new ();
578 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
579 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
580 gtk_widget_show (self->checkbox_incoming_auth);
581 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
582 gtk_widget_show (caption);
584 gtk_widget_show (GTK_WIDGET (box));
586 return GTK_WIDGET (box);
590 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
592 GtkWidget *widget = GTK_WIDGET (user_data);
594 /* Enable the widget only if the toggle button is active: */
595 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
596 gtk_widget_set_sensitive (widget, enable);
599 /* Make the sensitivity of a widget depend on a toggle button.
602 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
604 g_signal_connect (G_OBJECT (button), "toggled",
605 G_CALLBACK (on_toggle_button_changed), widget);
607 /* Set the starting sensitivity: */
608 on_toggle_button_changed (button, widget);
612 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
614 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
616 /* Create the window, if necessary: */
617 if (!(self->specific_window)) {
618 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
619 modest_connection_specific_smtp_window_fill_with_connections (
620 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
621 NULL /* account_name, not known yet. */);
624 /* Show the window: */
625 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
626 gtk_widget_show (self->specific_window);
629 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
631 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
633 /* Create a size group to be used by all captions.
634 * Note that HildonCaption does not create a default size group if we do not specify one.
635 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
636 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
638 /* The outgoing server widgets: */
639 if (!self->entry_outgoingserver)
640 self->entry_outgoingserver = gtk_entry_new ();
641 /* Auto-capitalization is the default, so let's turn it off: */
642 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
643 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
644 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
645 gtk_widget_show (self->entry_outgoingserver);
646 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
647 gtk_widget_show (caption);
648 set_default_custom_servernames (self);
650 /* The secure connection widgets: */
651 if (!self->combo_outgoing_security)
652 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
653 modest_serversecurity_combo_box_fill (
654 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
655 modest_serversecurity_combo_box_set_active_serversecurity (
656 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
657 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
658 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
659 gtk_widget_show (self->combo_outgoing_security);
660 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
661 gtk_widget_show (caption);
663 /* The secure authentication widgets: */
664 if (!self->combo_outgoing_auth)
665 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
666 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
667 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
668 gtk_widget_show (self->combo_outgoing_auth);
669 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
670 gtk_widget_show (caption);
672 /* connection-specific checkbox: */
673 if (!self->checkbox_outgoing_smtp_specific) {
674 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
675 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
678 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
679 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
680 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
681 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
682 gtk_widget_show (caption);
684 GtkWidget *separator = gtk_hseparator_new ();
685 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
686 gtk_widget_show (separator);
688 /* Connection-specific SMTP-Severs Edit button: */
689 if (!self->button_outgoing_smtp_servers)
690 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
691 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
692 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
693 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
694 gtk_widget_show (self->button_outgoing_smtp_servers);
695 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
696 gtk_widget_show (caption);
698 /* Only enable the button when the checkbox is checked: */
699 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
700 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
702 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
703 G_CALLBACK (on_button_outgoing_smtp_servers), self);
706 gtk_widget_show (GTK_WIDGET (box));
708 return GTK_WIDGET (box);
711 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
713 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
714 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
715 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
716 gtk_widget_show (label);
718 if (!self->button_edit)
719 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
720 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
721 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
722 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
723 gtk_widget_show (self->button_edit);
724 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
725 gtk_widget_show (caption);
727 gtk_widget_show (GTK_WIDGET (box));
728 return GTK_WIDGET (box);
735 on_response (ModestWizardDialog *wizard_dialog,
739 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
740 invoke_enable_buttons_vfunc (self);
744 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
746 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
748 /* Create the notebook to be used by the ModestWizardDialog base class:
749 * Each page of the notebook will be a page of the wizard: */
750 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
752 /* Set the notebook used by the ModestWizardDialog base class: */
753 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
755 /* Set the wizard title:
756 * The actual window title will be a combination of this and the page's tab label title. */
757 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
759 /* Read in the information about known service providers: */
760 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
762 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
763 priv->presets = modest_presets_new (filepath);
764 if (!(priv->presets)) {
765 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
768 g_assert(priv->presets);
771 /* Get the account manager object,
772 * so we can check for existing accounts,
773 * and create new accounts: */
774 self->account_manager = modest_runtime_get_account_mgr ();
775 g_assert (self->account_manager);
776 g_object_ref (self->account_manager);
778 /* Create the common pages,
780 self->page_welcome = create_page_welcome (self);
781 self->page_account_details = create_page_account_details (self);
782 self->page_user_details = create_page_user_details (self);
784 /* Add the common pages: */
785 gtk_notebook_append_page (notebook, self->page_welcome,
786 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
787 gtk_notebook_append_page (notebook, self->page_account_details,
788 gtk_label_new (_("mcen_ti_accountdetails")));
789 gtk_notebook_append_page (notebook, self->page_user_details,
790 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
792 /* Create and add the easysetup-specific pages,
793 * because we need _some_ final page to enable the Next and Finish buttons: */
794 create_subsequent_easysetup_pages (self);
797 /* Connect to the dialog's response signal so we can enable/disable buttons
798 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
799 * Note that we use g_signal_connect_after() instead of g_signal_connect()
800 * so that we can be enable/disable after ModestWizardDialog has done its own
801 * enabling/disabling of buttons.
803 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
804 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
806 * It's not enough to connect to the notebook's switch-page signal, because
807 * ModestWizardDialog's "response" signal handler enables the buttons itself,
808 * _after_ switching the page (understandably).
809 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
810 * then gtk_notebook_get_current_page() would return an incorrect value.)
812 g_signal_connect_after (G_OBJECT (self), "response",
813 G_CALLBACK (on_response), self);
816 ModestEasysetupWizardDialog*
817 modest_easysetup_wizard_dialog_new (void)
819 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
822 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
824 GtkNotebook *notebook = NULL;
825 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
828 /* Create the custom pages: */
829 if(!(self->page_custom_incoming)) {
830 self->page_custom_incoming = create_page_custom_incoming (self);
833 if(!(self->page_custom_outgoing)) {
834 self->page_custom_outgoing = create_page_custom_outgoing (self);
837 if(!(self->page_complete_customsetup)) {
838 self->page_complete_customsetup = create_page_complete_custom (self);
841 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
842 gtk_notebook_append_page (notebook, self->page_custom_incoming,
843 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
845 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
846 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
847 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
849 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
850 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
851 gtk_label_new (_("mcen_ti_emailsetup_complete")));
854 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
856 GtkNotebook *notebook = NULL;
857 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
860 /* Create the easysetup-specific pages: */
861 if(!self->page_complete_easysetup)
862 self->page_complete_easysetup = create_page_complete_easysetup (self);
864 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
865 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
866 gtk_label_new (_("mcen_ti_emailsetup_complete")));
869 /* After the user details page,
870 * the following pages depend on whether "Other" was chosen
871 * in the provider combobox on the account page
873 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
875 if (easysetup_provider_combo_box_get_active_provider_id (
876 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
877 /* "Other..." was selected: */
879 /* Make sure that the easysetup pages do not exist: */
880 if(self->page_complete_easysetup) {
881 gtk_widget_destroy (self->page_complete_easysetup);
882 self->page_complete_easysetup = NULL;
885 create_subsequent_customsetup_pages (self);
888 /* A specific provider was selected: */
890 /* Make sure that the custom pages do not exist:
891 * Because they will be used if they exist, when creating the account. */
892 if(self->page_custom_incoming) {
893 gtk_widget_destroy (self->page_custom_incoming);
894 self->page_custom_incoming = NULL;
897 if(self->page_custom_outgoing) {
898 gtk_widget_destroy (self->page_custom_outgoing);
899 self->page_custom_outgoing = NULL;
902 if(self->page_complete_customsetup) {
903 gtk_widget_destroy (self->page_complete_customsetup);
904 self->page_complete_customsetup = NULL;
908 /* Create the easysetup pages: */
909 create_subsequent_easysetup_pages (self);
915 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
920 gchar* at = g_utf8_strchr (email_address, -1, '@');
921 if (!at || (g_utf8_strlen (at, -1) < 2))
924 gchar* domain = g_utf8_next_char (at);
928 const gchar* hostname = NULL;
929 if (servertype == MODEST_PROTOCOL_STORE_POP)
931 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
933 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
939 return g_strdup_printf ("%s.%s", hostname, domain);
942 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
944 if (!account_wizard->entry_incomingserver)
947 /* Set a default domain for the server, based on the email address,
948 * if no server name was already specified.
950 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
951 if ((!incoming_existing || (strlen(incoming_existing) == 0))
952 && account_wizard->entry_user_email) {
953 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
954 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
955 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
957 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
958 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
962 /* Set a default domain for the server, based on the email address,
963 * if no server name was already specified.
965 if (!account_wizard->entry_outgoingserver)
968 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
969 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
970 && account_wizard->entry_user_email) {
971 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
973 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
974 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
980 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
982 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
984 /* Do extra validation that couldn't be done for every key press,
985 * either because it was too slow,
986 * or because it requires interaction:
988 if (current_page == account_wizard->page_account_details) {
989 /* Check that the title is not already in use: */
990 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
991 if ((!account_title) || (strlen(account_title) == 0))
994 /* Aavoid a clash with an existing display name: */
995 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
996 account_wizard->account_manager, account_title);
999 /* Warn the user via a dialog: */
1000 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1005 else if (current_page == account_wizard->page_user_details) {
1006 /* Check that the email address is valud: */
1007 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1008 if ((!email_address) || (strlen(email_address) == 0))
1011 if (!modest_text_utils_validate_email_address (email_address)) {
1012 /* Warn the user via a dialog: */
1013 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1015 /* Return focus to the email address entry: */
1016 gtk_widget_grab_focus (account_wizard->entry_user_email);
1021 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1022 create_subsequent_pages (account_wizard);
1025 /* TODO: The UI Spec wants us to check that the servernames are valid,
1026 * but does not specify how.
1029 if(next_page == account_wizard->page_custom_incoming) {
1030 set_default_custom_servernames (account_wizard);
1032 else if (next_page == account_wizard->page_custom_outgoing) {
1033 set_default_custom_servernames (account_wizard);
1036 /* If this is the last page, and this is a click on Finish,
1037 * then attempt to create the dialog.
1039 if(!next_page) /* This is NULL when this is a click on Finish. */
1041 create_account (account_wizard);
1048 static gboolean entry_is_empty (GtkWidget *entry)
1053 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1054 if ((!text) || (strlen(text) == 0))
1061 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1063 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1065 gboolean enable_next = TRUE;
1066 if (current_page == account_wizard->page_welcome) {
1069 else if (current_page == account_wizard->page_account_details) {
1070 /* The account details title is mandatory: */
1071 if (entry_is_empty(account_wizard->entry_account_title))
1072 enable_next = FALSE;
1074 else if (current_page == account_wizard->page_user_details) {
1075 /* The user details username is mandatory: */
1076 if (entry_is_empty(account_wizard->entry_user_username))
1077 enable_next = FALSE;
1079 /* The user details email address is mandatory: */
1080 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1081 enable_next = FALSE;
1083 else if (current_page == account_wizard->page_custom_incoming) {
1084 /* The custom incoming server is mandatory: */
1085 if (entry_is_empty(account_wizard->entry_incomingserver))
1086 enable_next = FALSE;
1089 /* Enable the buttons,
1090 * identifying them via their associated response codes:
1092 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1093 gtk_dialog_set_response_sensitive (dialog_base,
1094 MODEST_WIZARD_DIALOG_NEXT,
1097 /* Disable the Finish button until we are on the last page,
1098 * because HildonWizardDialog enables this for all but the first page: */
1099 GtkNotebook *notebook = NULL;
1100 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1102 gint current = gtk_notebook_get_current_page (notebook);
1103 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1104 gboolean is_last = (current == last);
1107 gtk_dialog_set_response_sensitive (dialog_base,
1108 MODEST_WIZARD_DIALOG_FINISH,
1114 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1116 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1117 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1120 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1121 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1122 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1123 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1125 /* Provide a vfunc implementation so we can decide
1126 * when to enable/disable the prev/next buttons.
1128 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1129 base_klass->before_next = on_before_next;
1130 base_klass->enable_buttons = on_enable_buttons;
1134 show_error (GtkWindow *parent_window, const gchar* text)
1136 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1142 gtk_dialog_run (dialog);
1143 gtk_widget_destroy (GTK_WIDGET (dialog));
1146 /** Attempt to create the account from the information that the user has entered.
1147 * @result: TRUE if the account was successfully created.
1150 create_account (ModestEasysetupWizardDialog *self)
1152 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1154 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1160 /* We should have checked for this already,
1161 * and changed that name accordingly,
1162 * but let's check again just in case:
1164 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1167 /* Increment the non-user visible name if necessary,
1168 * based on the display name: */
1169 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1170 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1171 account_name_start, FALSE /* not a server account */);
1172 g_free (account_name_start);
1174 /* username and password (for both incoming and outgoing): */
1175 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1176 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1178 /* Incoming server: */
1179 /* Note: We need something as default for the ModestProtocol values,
1180 * or modest_account_mgr_add_server_account will fail. */
1181 gchar* servername_incoming = NULL;
1182 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1183 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1184 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1186 /* Get details from the specified presets: */
1187 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1188 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1192 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1193 TRUE /* incoming */);
1195 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1196 TRUE /* incoming */);
1199 /* We don't check for SMTP here as that is impossible for an incoming server. */
1200 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1201 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1202 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1203 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1205 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1206 TRUE /* incoming */);
1209 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1210 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1212 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1213 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1216 /* Use custom pages because no preset was specified: */
1217 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1219 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1220 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1222 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1223 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1225 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1226 ? MODEST_PROTOCOL_AUTH_PASSWORD
1227 : MODEST_PROTOCOL_AUTH_NONE;
1231 /* First we add the 2 server accounts, and then we add the account that uses them.
1232 * If we don't do it in this order then we will experience a crash. */
1234 /* Add a (incoming) server account, to be used by the account: */
1235 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1236 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1237 store_name_start, TRUE /* server account */);
1238 g_free (store_name_start);
1239 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1241 servername_incoming,
1244 protocol_security_incoming,
1245 protocol_authentication_incoming);
1247 g_free (servername_incoming);
1250 /* TODO: Provide a Logical ID for the text: */
1251 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1256 /* There must be at least one account now: */
1257 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1260 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1262 g_slist_free (account_names);
1265 /* Outgoing server: */
1266 gchar* servername_outgoing = NULL;
1267 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1268 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1269 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1273 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1274 FALSE /* incoming */);
1276 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1277 FALSE /* incoming */);
1279 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1280 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1281 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1282 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1284 ModestPresetsSecurity security_outgoing =
1285 modest_presets_get_info_server_security (priv->presets, provider_id,
1286 FALSE /* incoming */);
1288 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1289 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1290 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1292 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1293 /* TODO: There is no SMTP authentication enum for presets. */
1296 /* Use custom pages because no preset was specified: */
1297 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1299 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1301 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1302 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1304 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1305 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1308 /* Add a (outgoing) server account to be used by the account: */
1309 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1310 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1311 transport_name_start, TRUE /* server account */);
1312 g_free (transport_name_start);
1313 created = modest_account_mgr_add_server_account (self->account_manager,
1315 servername_outgoing,
1318 protocol_security_outgoing,
1319 protocol_authentication_outgoing);
1321 g_free (servername_outgoing);
1324 /* TODO: Provide a Logical ID for the text: */
1325 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1330 /* Create the account, which will contain the two "server accounts": */
1331 created = modest_account_mgr_add_account (self->account_manager, account_name,
1332 store_name, /* The name of our POP/IMAP server account. */
1333 transport_name /* The name of our SMTP server account. */);
1334 g_free (store_name);
1335 g_free (transport_name);
1338 /* TODO: Provide a Logical ID for the text: */
1339 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1343 /* The user name and email address must be set additionally: */
1344 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1345 modest_account_mgr_set_string (self->account_manager, account_name,
1346 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1348 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1349 modest_account_mgr_set_string (self->account_manager, account_name,
1350 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1352 /* Set the display name: */
1353 modest_account_mgr_set_string (self->account_manager, account_name,
1354 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1356 /* Save the connection-specific SMTP server accounts. */
1357 if (self->specific_window)
1358 return modest_connection_specific_smtp_window_save_server_accounts (
1359 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1361 g_free (account_name);