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 ());
330 /* Do use auto-capitalization: */
331 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
332 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
334 /* Set a default account title, choosing one that does not already exist: */
335 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
336 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
337 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
338 self->account_manager, default_account_name_start);
339 g_free (default_account_name_start);
340 default_account_name_start = NULL;
342 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
343 g_free (default_account_name);
344 default_account_name = NULL;
346 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
347 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
348 gtk_widget_show (self->entry_account_title);
349 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
350 gtk_widget_show (caption);
352 /* Prevent the use of some characters in the account title,
353 * as required by our UI specification: */
354 GList *list_prevent = NULL;
355 list_prevent = g_list_append (list_prevent, "\\");
356 list_prevent = g_list_append (list_prevent, "/");
357 list_prevent = g_list_append (list_prevent, ":");
358 list_prevent = g_list_append (list_prevent, "*");
359 list_prevent = g_list_append (list_prevent, "?");
360 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
361 list_prevent = g_list_append (list_prevent, "“");
362 list_prevent = g_list_append (list_prevent, "<");
363 list_prevent = g_list_append (list_prevent, ">");
364 list_prevent = g_list_append (list_prevent, "|");
365 list_prevent = g_list_append (list_prevent, "^");
366 modest_validating_entry_set_unallowed_characters (
367 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
368 g_list_free (list_prevent);
370 /* Set max length as in the UI spec:
371 * The UI spec seems to want us to show a dialog if we hit the maximum. */
372 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
373 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
376 gtk_widget_show (GTK_WIDGET (box));
378 return GTK_WIDGET (box);
382 create_page_user_details (ModestEasysetupWizardDialog *self)
384 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
386 /* Create a size group to be used by all captions.
387 * Note that HildonCaption does not create a default size group if we do not specify one.
388 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
389 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
391 /* The name widgets: */
392 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
393 /* Auto-capitalization is the default, so let's turn it off: */
394 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
395 /* Set max length as in the UI spec:
396 * The UI spec seems to want us to show a dialog if we hit the maximum. */
397 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
398 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
400 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
401 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
402 gtk_widget_show (self->entry_user_name);
403 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
404 gtk_widget_show (caption);
406 /* Prevent the use of some characters in the name,
407 * as required by our UI specification: */
408 GList *list_prevent = NULL;
409 list_prevent = g_list_append (list_prevent, "<");
410 list_prevent = g_list_append (list_prevent, ">");
411 modest_validating_entry_set_unallowed_characters (
412 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
413 g_list_free (list_prevent);
415 /* The username widgets: */
416 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
417 /* Auto-capitalization is the default, so let's turn it off: */
418 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
419 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
420 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
421 gtk_widget_show (self->entry_user_username);
422 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
423 gtk_widget_show (caption);
425 /* Prevent the use of some characters in the username,
426 * as required by our UI specification: */
427 modest_validating_entry_set_unallowed_characters_whitespace (
428 MODEST_VALIDATING_ENTRY (self->entry_user_username));
430 /* Set max length as in the UI spec:
431 * The UI spec seems to want us to show a dialog if we hit the maximum. */
432 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
433 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
436 /* The password widgets: */
437 self->entry_user_password = gtk_entry_new ();
438 /* Auto-capitalization is the default, so let's turn it off: */
439 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password), HILDON_GTK_INPUT_MODE_FULL);
440 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
441 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
442 caption = create_caption_new_with_asterix (self, sizegroup,
443 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
444 gtk_widget_show (self->entry_user_password);
445 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
446 gtk_widget_show (caption);
448 /* The email address widgets: */
449 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
450 /* Auto-capitalization is the default, so let's turn it off: */
451 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
452 caption = create_caption_new_with_asterix (self, sizegroup,
453 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
454 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
455 gtk_widget_show (self->entry_user_email);
456 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
457 gtk_widget_show (caption);
459 /* Set max length as in the UI spec:
460 * The UI spec seems to want us to show a dialog if we hit the maximum. */
461 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
462 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
466 gtk_widget_show (GTK_WIDGET (box));
468 return GTK_WIDGET (box);
471 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
473 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
474 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
475 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
476 gtk_widget_show (label);
477 gtk_widget_show (GTK_WIDGET (box));
478 return GTK_WIDGET (box);
481 /** Change the caption title for the incoming server,
482 * as specified in the UI spec:
484 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
486 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
487 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
489 (protocol == MODEST_PROTOCOL_STORE_POP ?
490 _("mail_fi_emailtype_pop3") :
491 _("mail_fi_emailtype_imap") );
494 /* Note that this produces a compiler warning,
495 * because the compiler does not know that the translated string will have a %s in it.
496 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
497 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
498 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
499 g_free(incomingserver_title);
502 /** Change the caption title for the incoming server,
503 * as specified in the UI spec:
505 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
507 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
508 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
510 /* Fill the combo with appropriately titled choices for POP or IMAP. */
511 /* The choices are the same, but the titles are different, as in the UI spec. */
512 modest_serversecurity_combo_box_fill (
513 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
516 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
518 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
519 update_incoming_server_title (self);
520 update_incoming_server_security_choices (self);
523 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
525 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
527 /* Create a size group to be used by all captions.
528 * Note that HildonCaption does not create a default size group if we do not specify one.
529 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
530 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
532 /* The incoming server widgets: */
533 if (!self->combo_incoming_servertype)
534 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
535 easysetup_servertype_combo_box_set_active_servertype (
536 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
537 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
538 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
539 gtk_widget_show (self->combo_incoming_servertype);
540 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
541 gtk_widget_show (caption);
543 if(!self->entry_incomingserver)
544 self->entry_incomingserver = gtk_entry_new ();
545 /* Auto-capitalization is the default, so let's turn it off: */
546 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
547 set_default_custom_servernames (self);
549 if (self->caption_incoming)
550 gtk_widget_destroy (self->caption_incoming);
552 /* The caption title will be updated in update_incoming_server_title().
553 * so this default text will never be seen: */
554 /* (Note: Changing the title seems pointless. murrayc) */
555 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
556 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
557 update_incoming_server_title (self);
558 gtk_widget_show (self->entry_incomingserver);
559 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
560 gtk_widget_show (self->caption_incoming);
562 /* Change the caption title when the servertype changes,
563 * as in the UI spec: */
564 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
565 G_CALLBACK (on_combo_servertype_changed), self);
567 /* The secure connection widgets: */
568 if (!self->combo_incoming_security)
569 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
570 update_incoming_server_security_choices (self);
571 modest_serversecurity_combo_box_set_active_serversecurity (
572 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
573 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
574 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
575 gtk_widget_show (self->combo_incoming_security);
576 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
577 gtk_widget_show (caption);
579 if(!self->checkbox_incoming_auth)
580 self->checkbox_incoming_auth = gtk_check_button_new ();
581 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
582 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
583 gtk_widget_show (self->checkbox_incoming_auth);
584 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
585 gtk_widget_show (caption);
587 gtk_widget_show (GTK_WIDGET (box));
589 return GTK_WIDGET (box);
593 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
595 GtkWidget *widget = GTK_WIDGET (user_data);
597 /* Enable the widget only if the toggle button is active: */
598 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
599 gtk_widget_set_sensitive (widget, enable);
602 /* Make the sensitivity of a widget depend on a toggle button.
605 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
607 g_signal_connect (G_OBJECT (button), "toggled",
608 G_CALLBACK (on_toggle_button_changed), widget);
610 /* Set the starting sensitivity: */
611 on_toggle_button_changed (button, widget);
615 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
617 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
619 /* Create the window, if necessary: */
620 if (!(self->specific_window)) {
621 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
622 modest_connection_specific_smtp_window_fill_with_connections (
623 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
624 NULL /* account_name, not known yet. */);
627 /* Show the window: */
628 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
629 gtk_widget_show (self->specific_window);
632 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
634 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
636 /* Create a size group to be used by all captions.
637 * Note that HildonCaption does not create a default size group if we do not specify one.
638 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
639 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
641 /* The outgoing server widgets: */
642 if (!self->entry_outgoingserver)
643 self->entry_outgoingserver = gtk_entry_new ();
644 /* Auto-capitalization is the default, so let's turn it off: */
645 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
646 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
647 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
648 gtk_widget_show (self->entry_outgoingserver);
649 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
650 gtk_widget_show (caption);
651 set_default_custom_servernames (self);
653 /* The secure connection widgets: */
654 if (!self->combo_outgoing_security)
655 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
656 modest_serversecurity_combo_box_fill (
657 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
658 modest_serversecurity_combo_box_set_active_serversecurity (
659 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
660 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
661 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
662 gtk_widget_show (self->combo_outgoing_security);
663 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
664 gtk_widget_show (caption);
666 /* The secure authentication widgets: */
667 if (!self->combo_outgoing_auth)
668 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
669 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
670 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
671 gtk_widget_show (self->combo_outgoing_auth);
672 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
673 gtk_widget_show (caption);
675 GtkWidget *separator = gtk_hseparator_new ();
676 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
677 gtk_widget_show (separator);
679 /* connection-specific checkbox: */
680 if (!self->checkbox_outgoing_smtp_specific) {
681 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
682 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
685 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
686 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
687 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
688 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
689 gtk_widget_show (caption);
691 /* Connection-specific SMTP-Severs Edit button: */
692 if (!self->button_outgoing_smtp_servers)
693 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
694 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
695 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
696 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
697 gtk_widget_show (self->button_outgoing_smtp_servers);
698 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
699 gtk_widget_show (caption);
701 /* Only enable the button when the checkbox is checked: */
702 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
703 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
705 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
706 G_CALLBACK (on_button_outgoing_smtp_servers), self);
709 gtk_widget_show (GTK_WIDGET (box));
711 return GTK_WIDGET (box);
714 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
716 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
717 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
718 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
719 gtk_widget_show (label);
721 if (!self->button_edit)
722 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
723 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
724 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
725 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
726 gtk_widget_show (self->button_edit);
727 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
728 gtk_widget_show (caption);
730 gtk_widget_show (GTK_WIDGET (box));
731 return GTK_WIDGET (box);
738 on_response (ModestWizardDialog *wizard_dialog,
742 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
743 invoke_enable_buttons_vfunc (self);
747 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
749 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
751 /* Create the notebook to be used by the ModestWizardDialog base class:
752 * Each page of the notebook will be a page of the wizard: */
753 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
755 /* Set the notebook used by the ModestWizardDialog base class: */
756 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
758 /* Set the wizard title:
759 * The actual window title will be a combination of this and the page's tab label title. */
760 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
762 /* Read in the information about known service providers: */
763 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
765 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
766 priv->presets = modest_presets_new (filepath);
767 if (!(priv->presets)) {
768 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
771 g_assert(priv->presets);
774 /* Get the account manager object,
775 * so we can check for existing accounts,
776 * and create new accounts: */
777 self->account_manager = modest_runtime_get_account_mgr ();
778 g_assert (self->account_manager);
779 g_object_ref (self->account_manager);
781 /* Create the common pages,
783 self->page_welcome = create_page_welcome (self);
784 self->page_account_details = create_page_account_details (self);
785 self->page_user_details = create_page_user_details (self);
787 /* Add the common pages: */
788 gtk_notebook_append_page (notebook, self->page_welcome,
789 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
790 gtk_notebook_append_page (notebook, self->page_account_details,
791 gtk_label_new (_("mcen_ti_accountdetails")));
792 gtk_notebook_append_page (notebook, self->page_user_details,
793 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
795 /* Create and add the easysetup-specific pages,
796 * because we need _some_ final page to enable the Next and Finish buttons: */
797 create_subsequent_easysetup_pages (self);
800 /* Connect to the dialog's response signal so we can enable/disable buttons
801 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
802 * Note that we use g_signal_connect_after() instead of g_signal_connect()
803 * so that we can be enable/disable after ModestWizardDialog has done its own
804 * enabling/disabling of buttons.
806 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
807 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
809 * It's not enough to connect to the notebook's switch-page signal, because
810 * ModestWizardDialog's "response" signal handler enables the buttons itself,
811 * _after_ switching the page (understandably).
812 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
813 * then gtk_notebook_get_current_page() would return an incorrect value.)
815 g_signal_connect_after (G_OBJECT (self), "response",
816 G_CALLBACK (on_response), self);
819 ModestEasysetupWizardDialog*
820 modest_easysetup_wizard_dialog_new (void)
822 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
825 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
827 GtkNotebook *notebook = NULL;
828 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
831 /* Create the custom pages: */
832 if(!(self->page_custom_incoming)) {
833 self->page_custom_incoming = create_page_custom_incoming (self);
836 if(!(self->page_custom_outgoing)) {
837 self->page_custom_outgoing = create_page_custom_outgoing (self);
840 if(!(self->page_complete_customsetup)) {
841 self->page_complete_customsetup = create_page_complete_custom (self);
844 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
845 gtk_notebook_append_page (notebook, self->page_custom_incoming,
846 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
848 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
849 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
850 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
852 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
853 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
854 gtk_label_new (_("mcen_ti_emailsetup_complete")));
857 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
859 GtkNotebook *notebook = NULL;
860 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
863 /* Create the easysetup-specific pages: */
864 if(!self->page_complete_easysetup)
865 self->page_complete_easysetup = create_page_complete_easysetup (self);
867 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
868 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
869 gtk_label_new (_("mcen_ti_emailsetup_complete")));
872 /* After the user details page,
873 * the following pages depend on whether "Other" was chosen
874 * in the provider combobox on the account page
876 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
878 if (easysetup_provider_combo_box_get_active_provider_id (
879 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
880 /* "Other..." was selected: */
882 /* Make sure that the easysetup pages do not exist: */
883 if(self->page_complete_easysetup) {
884 gtk_widget_destroy (self->page_complete_easysetup);
885 self->page_complete_easysetup = NULL;
888 create_subsequent_customsetup_pages (self);
891 /* A specific provider was selected: */
893 /* Make sure that the custom pages do not exist:
894 * Because they will be used if they exist, when creating the account. */
895 if(self->page_custom_incoming) {
896 gtk_widget_destroy (self->page_custom_incoming);
897 self->page_custom_incoming = NULL;
900 if(self->page_custom_outgoing) {
901 gtk_widget_destroy (self->page_custom_outgoing);
902 self->page_custom_outgoing = NULL;
905 if(self->page_complete_customsetup) {
906 gtk_widget_destroy (self->page_complete_customsetup);
907 self->page_complete_customsetup = NULL;
911 /* Create the easysetup pages: */
912 create_subsequent_easysetup_pages (self);
918 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
923 gchar* at = g_utf8_strchr (email_address, -1, '@');
924 if (!at || (g_utf8_strlen (at, -1) < 2))
927 gchar* domain = g_utf8_next_char (at);
931 const gchar* hostname = NULL;
932 if (servertype == MODEST_PROTOCOL_STORE_POP)
934 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
936 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
942 return g_strdup_printf ("%s.%s", hostname, domain);
945 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
947 if (!account_wizard->entry_incomingserver)
950 /* Set a default domain for the server, based on the email address,
951 * if no server name was already specified.
953 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
954 if ((!incoming_existing || (strlen(incoming_existing) == 0))
955 && account_wizard->entry_user_email) {
956 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
957 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
958 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
960 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
961 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
965 /* Set a default domain for the server, based on the email address,
966 * if no server name was already specified.
968 if (!account_wizard->entry_outgoingserver)
971 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
972 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
973 && account_wizard->entry_user_email) {
974 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
976 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
977 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
983 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
985 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
987 /* Do extra validation that couldn't be done for every key press,
988 * either because it was too slow,
989 * or because it requires interaction:
991 if (current_page == account_wizard->page_account_details) {
992 /* Check that the title is not already in use: */
993 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
994 if ((!account_title) || (strlen(account_title) == 0))
997 /* Aavoid a clash with an existing display name: */
998 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
999 account_wizard->account_manager, account_title);
1002 /* Warn the user via a dialog: */
1003 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1008 else if (current_page == account_wizard->page_user_details) {
1009 /* Check that the email address is valud: */
1010 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1011 if ((!email_address) || (strlen(email_address) == 0))
1014 if (!modest_text_utils_validate_email_address (email_address)) {
1015 /* Warn the user via a dialog: */
1016 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1018 /* Return focus to the email address entry: */
1019 gtk_widget_grab_focus (account_wizard->entry_user_email);
1024 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1025 create_subsequent_pages (account_wizard);
1028 /* TODO: The UI Spec wants us to check that the servernames are valid,
1029 * but does not specify how.
1032 if(next_page == account_wizard->page_custom_incoming) {
1033 set_default_custom_servernames (account_wizard);
1035 else if (next_page == account_wizard->page_custom_outgoing) {
1036 set_default_custom_servernames (account_wizard);
1039 /* If this is the last page, and this is a click on Finish,
1040 * then attempt to create the dialog.
1042 if(!next_page) /* This is NULL when this is a click on Finish. */
1044 create_account (account_wizard);
1051 static gboolean entry_is_empty (GtkWidget *entry)
1056 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1057 if ((!text) || (strlen(text) == 0))
1064 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1066 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1068 gboolean enable_next = TRUE;
1069 if (current_page == account_wizard->page_welcome) {
1072 else if (current_page == account_wizard->page_account_details) {
1073 /* The account details title is mandatory: */
1074 if (entry_is_empty(account_wizard->entry_account_title))
1075 enable_next = FALSE;
1077 else if (current_page == account_wizard->page_user_details) {
1078 /* The user details username is mandatory: */
1079 if (entry_is_empty(account_wizard->entry_user_username))
1080 enable_next = FALSE;
1082 /* The user details email address is mandatory: */
1083 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1084 enable_next = FALSE;
1086 else if (current_page == account_wizard->page_custom_incoming) {
1087 /* The custom incoming server is mandatory: */
1088 if (entry_is_empty(account_wizard->entry_incomingserver))
1089 enable_next = FALSE;
1092 /* Enable the buttons,
1093 * identifying them via their associated response codes:
1095 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1096 gtk_dialog_set_response_sensitive (dialog_base,
1097 MODEST_WIZARD_DIALOG_NEXT,
1100 /* Disable the Finish button until we are on the last page,
1101 * because HildonWizardDialog enables this for all but the first page: */
1102 GtkNotebook *notebook = NULL;
1103 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1105 gint current = gtk_notebook_get_current_page (notebook);
1106 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1107 gboolean is_last = (current == last);
1110 gtk_dialog_set_response_sensitive (dialog_base,
1111 MODEST_WIZARD_DIALOG_FINISH,
1117 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1119 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1120 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1123 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1124 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1125 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1126 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1128 /* Provide a vfunc implementation so we can decide
1129 * when to enable/disable the prev/next buttons.
1131 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1132 base_klass->before_next = on_before_next;
1133 base_klass->enable_buttons = on_enable_buttons;
1137 show_error (GtkWindow *parent_window, const gchar* text)
1139 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1145 gtk_dialog_run (dialog);
1146 gtk_widget_destroy (GTK_WIDGET (dialog));
1149 /** Attempt to create the account from the information that the user has entered.
1150 * @result: TRUE if the account was successfully created.
1153 create_account (ModestEasysetupWizardDialog *self)
1155 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1157 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1163 /* We should have checked for this already,
1164 * and changed that name accordingly,
1165 * but let's check again just in case:
1167 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1170 /* Increment the non-user visible name if necessary,
1171 * based on the display name: */
1172 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1173 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1174 account_name_start, FALSE /* not a server account */);
1175 g_free (account_name_start);
1177 /* username and password (for both incoming and outgoing): */
1178 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1179 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1181 /* Incoming server: */
1182 /* Note: We need something as default for the ModestProtocol values,
1183 * or modest_account_mgr_add_server_account will fail. */
1184 gchar* servername_incoming = NULL;
1185 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1186 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1187 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1189 /* Get details from the specified presets: */
1190 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1191 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1195 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1196 TRUE /* incoming */);
1198 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1199 TRUE /* incoming */);
1202 /* We don't check for SMTP here as that is impossible for an incoming server. */
1203 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1204 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1205 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1206 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1208 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1209 TRUE /* incoming */);
1212 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1213 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1215 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1216 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1219 /* Use custom pages because no preset was specified: */
1220 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1222 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1223 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1225 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1226 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1228 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1229 ? MODEST_PROTOCOL_AUTH_PASSWORD
1230 : MODEST_PROTOCOL_AUTH_NONE;
1234 /* First we add the 2 server accounts, and then we add the account that uses them.
1235 * If we don't do it in this order then we will experience a crash. */
1237 /* Add a (incoming) server account, to be used by the account: */
1238 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1239 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1240 store_name_start, TRUE /* server account */);
1241 g_free (store_name_start);
1242 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1244 servername_incoming,
1247 protocol_security_incoming,
1248 protocol_authentication_incoming);
1250 g_free (servername_incoming);
1253 /* TODO: Provide a Logical ID for the text: */
1254 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1259 /* There must be at least one account now: */
1260 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1263 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1265 g_slist_free (account_names);
1268 /* Outgoing server: */
1269 gchar* servername_outgoing = NULL;
1270 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1271 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1272 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1276 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1277 FALSE /* incoming */);
1279 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1280 FALSE /* incoming */);
1282 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1283 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1284 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1285 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1287 ModestPresetsSecurity security_outgoing =
1288 modest_presets_get_info_server_security (priv->presets, provider_id,
1289 FALSE /* incoming */);
1291 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1292 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1293 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1295 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1296 /* TODO: There is no SMTP authentication enum for presets. */
1299 /* Use custom pages because no preset was specified: */
1300 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1302 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1304 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1305 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1307 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1308 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1311 /* Add a (outgoing) server account to be used by the account: */
1312 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1313 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1314 transport_name_start, TRUE /* server account */);
1315 g_free (transport_name_start);
1316 created = modest_account_mgr_add_server_account (self->account_manager,
1318 servername_outgoing,
1321 protocol_security_outgoing,
1322 protocol_authentication_outgoing);
1324 g_free (servername_outgoing);
1327 /* TODO: Provide a Logical ID for the text: */
1328 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1333 /* Create the account, which will contain the two "server accounts": */
1334 created = modest_account_mgr_add_account (self->account_manager, account_name,
1335 store_name, /* The name of our POP/IMAP server account. */
1336 transport_name /* The name of our SMTP server account. */);
1337 g_free (store_name);
1338 g_free (transport_name);
1341 /* TODO: Provide a Logical ID for the text: */
1342 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1346 /* The user name and email address must be set additionally: */
1347 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1348 modest_account_mgr_set_string (self->account_manager, account_name,
1349 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1351 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1352 modest_account_mgr_set_string (self->account_manager, account_name,
1353 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1355 /* Set the display name: */
1356 modest_account_mgr_set_string (self->account_manager, account_name,
1357 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1359 /* Save the connection-specific SMTP server accounts. */
1360 if (self->specific_window)
1361 return modest_connection_specific_smtp_window_save_server_accounts (
1362 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1364 g_free (account_name);