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 "maemo/easysetup/modest-easysetup-country-combo-box.h"
19 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
20 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
21 #include "widgets/modest-serversecurity-combo-box.h"
22 #include "widgets/modest-secureauth-combo-box.h"
23 #include "widgets/modest-validating-entry.h"
24 #include "modest-text-utils.h"
25 #include "modest-account-mgr.h"
26 #include "modest-account-mgr-helpers.h"
27 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
28 #include "maemo/modest-connection-specific-smtp-window.h"
29 #include "widgets/modest-ui-constants.h"
30 #include "maemo/modest-account-settings-dialog.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_free (self->saved_account_name);
97 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
101 show_error (GtkWindow *parent_window, const gchar* text);
104 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
107 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
110 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
112 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
115 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
117 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
119 /* Call the vfunc, which may be overridden by derived classes: */
120 if (klass->enable_buttons) {
121 GtkNotebook *notebook = NULL;
122 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
124 const gint current_page_num = gtk_notebook_get_current_page (notebook);
125 if (current_page_num == -1)
128 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
129 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
134 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
136 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
138 invoke_enable_buttons_vfunc(self);
142 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
144 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
146 invoke_enable_buttons_vfunc(self);
149 /** This is a convenience function to create a caption containing a mandatory widget.
150 * When the widget is edited, the enable_buttons() vfunc will be called.
152 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
157 HildonCaptionStatus flag)
159 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
161 /* The translated strings seem to already contain the *,
162 * but this code can be used if that is not true in future.
165 /* Add a * character to indicate mandatory fields,
166 * as specified in our "Email UI Specification": */
167 if (flag == HILDON_CAPTION_MANDATORY) {
168 gchar* title = g_strdup_printf("%s*", value);
169 caption = hildon_caption_new (group, title, control, icon, flag);
173 caption = hildon_caption_new (group, value, control, icon, flag);
176 /* Connect to the appropriate changed signal for the widget,
177 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
179 if (GTK_IS_ENTRY (control)) {
180 g_signal_connect (G_OBJECT (control), "changed",
181 G_CALLBACK (on_caption_entry_changed), self);
184 else if (GTK_IS_COMBO_BOX (control)) {
185 g_signal_connect (G_OBJECT (control), "changed",
186 G_CALLBACK (on_caption_combobox_changed), self);
193 create_page_welcome (ModestEasysetupWizardDialog *self)
195 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
196 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
197 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
198 gtk_widget_show (label);
199 gtk_widget_show (GTK_WIDGET (box));
200 return GTK_WIDGET (box);
204 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
206 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
208 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
210 /* Fill the providers combo, based on the selected country: */
211 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
212 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
213 easysetup_provider_combo_box_fill (
214 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
218 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
220 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
222 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
224 /* Fill the providers combo, based on the selected country: */
225 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
226 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
228 gchar* domain_name = NULL;
230 domain_name = modest_presets_get_domain (priv->presets, provider_id);
233 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
235 if (self->entry_user_email)
236 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
238 g_free (domain_name);
240 g_free (provider_id);
244 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
246 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
247 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
251 create_page_account_details (ModestEasysetupWizardDialog *self)
253 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
254 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
255 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
256 gtk_widget_show (label);
258 /* Create a size group to be used by all captions.
259 * Note that HildonCaption does not create a default size group if we do not specify one.
260 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
261 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
263 /* The country widgets: */
264 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
265 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
266 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
267 gtk_widget_show (self->combo_account_country);
268 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
269 gtk_widget_show (caption);
271 /* connect to country combo's changed signal, so we can fill the provider combo: */
272 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
273 G_CALLBACK (on_combo_account_country), self);
275 GtkWidget *separator = gtk_hseparator_new ();
276 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
277 gtk_widget_show (separator);
279 /* The service provider widgets: */
280 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
282 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
283 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
284 gtk_widget_show (self->combo_account_serviceprovider);
285 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
286 gtk_widget_show (caption);
288 /* connect to providers combo's changed signal, so we can fill the email address: */
289 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
290 G_CALLBACK (on_combo_account_serviceprovider), self);
292 /* TODO: Default to the current country somehow.
293 * But I don't know how to get the information that is specified in the
294 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
296 * This is probably not the best choice of gconf key:
297 * This is the "mcc used in the last pairing", ie. the last connection you made.
298 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
301 GConfClient *client = gconf_client_get_default ();
302 GError *error = NULL;
303 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
304 gint mcc_id = gconf_client_get_int(client, key, &error);
310 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
311 g_error_free (error);
317 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
318 * This might just be a Maemo bug.
322 /* For now, we default to Finland when there is nothing better: */
326 easysetup_country_combo_box_set_active_country_id (
327 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
330 /* The description widgets: */
331 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
332 /* Do use auto-capitalization: */
333 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
334 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
336 /* Set a default account title, choosing one that does not already exist: */
337 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
338 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
339 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
340 self->account_manager, default_account_name_start);
341 g_free (default_account_name_start);
342 default_account_name_start = NULL;
344 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
345 g_free (default_account_name);
346 default_account_name = NULL;
348 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
349 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
350 gtk_widget_show (self->entry_account_title);
351 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
352 gtk_widget_show (caption);
354 /* Prevent the use of some characters in the account title,
355 * as required by our UI specification: */
356 GList *list_prevent = NULL;
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, "*");
361 list_prevent = g_list_append (list_prevent, "?");
362 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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 list_prevent = g_list_append (list_prevent, "|");
367 list_prevent = g_list_append (list_prevent, "^");
368 modest_validating_entry_set_unallowed_characters (
369 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
370 g_list_free (list_prevent);
372 /* Set max length as in the UI spec:
373 * The UI spec seems to want us to show a dialog if we hit the maximum. */
374 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
375 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
378 gtk_widget_show (GTK_WIDGET (box));
380 return GTK_WIDGET (box);
384 create_page_user_details (ModestEasysetupWizardDialog *self)
386 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
388 /* Create a size group to be used by all captions.
389 * Note that HildonCaption does not create a default size group if we do not specify one.
390 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
391 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
393 /* The name widgets: */
394 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
395 /* Auto-capitalization is the default, so let's turn it off: */
396 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
397 /* Set max length as in the UI spec:
398 * The UI spec seems to want us to show a dialog if we hit the maximum. */
399 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
400 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
402 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
403 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
404 gtk_widget_show (self->entry_user_name);
405 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
406 gtk_widget_show (caption);
408 /* Prevent the use of some characters in the name,
409 * as required by our UI specification: */
410 GList *list_prevent = NULL;
411 list_prevent = g_list_append (list_prevent, "<");
412 list_prevent = g_list_append (list_prevent, ">");
413 modest_validating_entry_set_unallowed_characters (
414 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
415 g_list_free (list_prevent);
417 /* The username widgets: */
418 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
419 /* Auto-capitalization is the default, so let's turn it off: */
420 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
421 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
422 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
423 gtk_widget_show (self->entry_user_username);
424 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
425 gtk_widget_show (caption);
427 /* Prevent the use of some characters in the username,
428 * as required by our UI specification: */
429 modest_validating_entry_set_unallowed_characters_whitespace (
430 MODEST_VALIDATING_ENTRY (self->entry_user_username));
432 /* Set max length as in the UI spec:
433 * The UI spec seems to want us to show a dialog if we hit the maximum. */
434 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
435 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
438 /* The password widgets: */
439 self->entry_user_password = gtk_entry_new ();
440 /* Auto-capitalization is the default, so let's turn it off: */
441 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password), HILDON_GTK_INPUT_MODE_FULL);
442 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
443 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
444 caption = create_caption_new_with_asterix (self, sizegroup,
445 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
446 gtk_widget_show (self->entry_user_password);
447 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
448 gtk_widget_show (caption);
450 /* The email address widgets: */
451 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
452 /* Auto-capitalization is the default, so let's turn it off: */
453 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
454 caption = create_caption_new_with_asterix (self, sizegroup,
455 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
456 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
457 gtk_widget_show (self->entry_user_email);
458 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
459 gtk_widget_show (caption);
461 /* Set max length as in the UI spec:
462 * The UI spec seems to want us to show a dialog if we hit the maximum. */
463 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
464 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
468 gtk_widget_show (GTK_WIDGET (box));
470 return GTK_WIDGET (box);
473 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
475 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
476 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
477 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
478 gtk_widget_show (label);
479 gtk_widget_show (GTK_WIDGET (box));
480 return GTK_WIDGET (box);
483 /** Change the caption title for the incoming server,
484 * as specified in the UI spec:
486 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
488 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
489 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
491 (protocol == MODEST_PROTOCOL_STORE_POP ?
492 _("mail_fi_emailtype_pop3") :
493 _("mail_fi_emailtype_imap") );
496 /* Note that this produces a compiler warning,
497 * because the compiler does not know that the translated string will have a %s in it.
498 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
499 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
500 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
501 g_free(incomingserver_title);
504 /** Change the caption title for the incoming server,
505 * as specified in the UI spec:
507 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
509 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
510 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
512 /* Fill the combo with appropriately titled choices for POP or IMAP. */
513 /* The choices are the same, but the titles are different, as in the UI spec. */
514 modest_serversecurity_combo_box_fill (
515 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
518 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
520 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
521 update_incoming_server_title (self);
522 update_incoming_server_security_choices (self);
525 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
527 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
529 /* Create a size group to be used by all captions.
530 * Note that HildonCaption does not create a default size group if we do not specify one.
531 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
532 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
534 /* The incoming server widgets: */
535 if (!self->combo_incoming_servertype)
536 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
537 easysetup_servertype_combo_box_set_active_servertype (
538 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
539 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
540 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
541 gtk_widget_show (self->combo_incoming_servertype);
542 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
543 gtk_widget_show (caption);
545 if(!self->entry_incomingserver)
546 self->entry_incomingserver = gtk_entry_new ();
547 /* Auto-capitalization is the default, so let's turn it off: */
548 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
549 set_default_custom_servernames (self);
551 if (self->caption_incoming)
552 gtk_widget_destroy (self->caption_incoming);
554 /* The caption title will be updated in update_incoming_server_title().
555 * so this default text will never be seen: */
556 /* (Note: Changing the title seems pointless. murrayc) */
557 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
558 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
559 update_incoming_server_title (self);
560 gtk_widget_show (self->entry_incomingserver);
561 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
562 gtk_widget_show (self->caption_incoming);
564 /* Change the caption title when the servertype changes,
565 * as in the UI spec: */
566 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
567 G_CALLBACK (on_combo_servertype_changed), self);
569 /* The secure connection widgets: */
570 if (!self->combo_incoming_security)
571 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
572 update_incoming_server_security_choices (self);
573 modest_serversecurity_combo_box_set_active_serversecurity (
574 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
575 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
576 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
577 gtk_widget_show (self->combo_incoming_security);
578 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
579 gtk_widget_show (caption);
581 if(!self->checkbox_incoming_auth)
582 self->checkbox_incoming_auth = gtk_check_button_new ();
583 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
584 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
585 gtk_widget_show (self->checkbox_incoming_auth);
586 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
587 gtk_widget_show (caption);
589 gtk_widget_show (GTK_WIDGET (box));
591 return GTK_WIDGET (box);
595 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
597 GtkWidget *widget = GTK_WIDGET (user_data);
599 /* Enable the widget only if the toggle button is active: */
600 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
601 gtk_widget_set_sensitive (widget, enable);
604 /* Make the sensitivity of a widget depend on a toggle button.
607 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
609 g_signal_connect (G_OBJECT (button), "toggled",
610 G_CALLBACK (on_toggle_button_changed), widget);
612 /* Set the starting sensitivity: */
613 on_toggle_button_changed (button, widget);
617 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
619 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
621 /* Create the window, if necessary: */
622 if (!(self->specific_window)) {
623 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
624 modest_connection_specific_smtp_window_fill_with_connections (
625 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
626 NULL /* account_name, not known yet. */);
629 /* Show the window: */
630 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
631 gtk_widget_show (self->specific_window);
634 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
636 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
638 /* Create a size group to be used by all captions.
639 * Note that HildonCaption does not create a default size group if we do not specify one.
640 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
641 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
643 /* The outgoing server widgets: */
644 if (!self->entry_outgoingserver)
645 self->entry_outgoingserver = gtk_entry_new ();
646 /* Auto-capitalization is the default, so let's turn it off: */
647 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
648 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
649 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
650 gtk_widget_show (self->entry_outgoingserver);
651 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
652 gtk_widget_show (caption);
653 set_default_custom_servernames (self);
655 /* The secure connection widgets: */
656 if (!self->combo_outgoing_security)
657 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
658 modest_serversecurity_combo_box_fill (
659 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
660 modest_serversecurity_combo_box_set_active_serversecurity (
661 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
662 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
663 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
664 gtk_widget_show (self->combo_outgoing_security);
665 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
666 gtk_widget_show (caption);
668 /* The secure authentication widgets: */
669 if (!self->combo_outgoing_auth)
670 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
671 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
672 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
673 gtk_widget_show (self->combo_outgoing_auth);
674 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
675 gtk_widget_show (caption);
677 GtkWidget *separator = gtk_hseparator_new ();
678 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
679 gtk_widget_show (separator);
681 /* connection-specific checkbox: */
682 if (!self->checkbox_outgoing_smtp_specific) {
683 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
684 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
687 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
688 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
689 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
690 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
691 gtk_widget_show (caption);
693 /* Connection-specific SMTP-Severs Edit button: */
694 if (!self->button_outgoing_smtp_servers)
695 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
696 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
697 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
698 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
699 gtk_widget_show (self->button_outgoing_smtp_servers);
700 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
701 gtk_widget_show (caption);
703 /* Only enable the button when the checkbox is checked: */
704 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
705 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
707 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
708 G_CALLBACK (on_button_outgoing_smtp_servers), self);
711 gtk_widget_show (GTK_WIDGET (box));
713 return GTK_WIDGET (box);
717 on_timeout_show_advanced_edit(gpointer user_data)
719 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
721 if (!(self->saved_account_name))
724 /* Show the Account Settings window: */
725 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
726 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
728 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
730 gtk_dialog_run (GTK_DIALOG (dialog));
732 /* TODO: The hide() is not necessary.
733 * It is just here to show that it doesn't work,
734 * just as destroy doesn't work.
736 gtk_widget_hide (GTK_WIDGET(dialog));
738 /* TODO: The dialog remains on screen, not allowing any interaction.
739 * But gtk_widget_destroy() should always destroy.
741 printf("debug: destroying settings dialog\n");
742 gtk_widget_destroy (GTK_WIDGET (dialog));
743 printf("debug: after destroying settings dialog (doesn't seem to work).\n");
745 return FALSE; /* Do not call this timeout callback again. */
749 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
751 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
753 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
754 * without recoding it to use non-gconf information.
755 * This account will be deleted if Finish is never actually clicked. */
757 gboolean saved = TRUE;
758 gboolean was_already_saved = TRUE;
759 if (!(self->saved_account_name)) {
760 saved = create_account (self, FALSE);
761 was_already_saved = FALSE;
767 if (!(self->saved_account_name))
770 /* Show the Account Settings window: */
771 if (was_already_saved) {
772 /* Just show the dialog immediately: */
773 on_timeout_show_advanced_edit(self);
777 printf ("debug: waiting for gconf to update its local cache. "
778 "This is a hack to work around a maemo gconf bug in maemo bora.\n");
780 g_timeout_add (5000, on_timeout_show_advanced_edit, self);
783 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
785 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
786 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
787 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
788 gtk_widget_show (label);
790 if (!self->button_edit)
791 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
792 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
793 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
794 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
795 gtk_widget_show (self->button_edit);
796 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
797 gtk_widget_show (caption);
799 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
800 G_CALLBACK (on_button_edit_advanced_settings), self);
802 gtk_widget_show (GTK_WIDGET (box));
803 return GTK_WIDGET (box);
810 on_response (ModestWizardDialog *wizard_dialog,
814 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
816 if (response_id == GTK_RESPONSE_CANCEL) {
817 /* Remove any temporarily-saved account that will not actually be needed: */
818 if (self->saved_account_name) {
819 modest_account_mgr_remove_account (self->account_manager,
820 self->saved_account_name, FALSE);
824 invoke_enable_buttons_vfunc (self);
828 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
830 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
832 /* Create the notebook to be used by the ModestWizardDialog base class:
833 * Each page of the notebook will be a page of the wizard: */
834 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
836 /* Set the notebook used by the ModestWizardDialog base class: */
837 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
839 /* Set the wizard title:
840 * The actual window title will be a combination of this and the page's tab label title. */
841 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
843 /* Read in the information about known service providers: */
844 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
846 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
847 priv->presets = modest_presets_new (filepath);
848 if (!(priv->presets)) {
849 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
852 g_assert(priv->presets);
855 /* Get the account manager object,
856 * so we can check for existing accounts,
857 * and create new accounts: */
858 self->account_manager = modest_runtime_get_account_mgr ();
859 g_assert (self->account_manager);
860 g_object_ref (self->account_manager);
862 /* Create the common pages,
864 self->page_welcome = create_page_welcome (self);
865 self->page_account_details = create_page_account_details (self);
866 self->page_user_details = create_page_user_details (self);
868 /* Add the common pages: */
869 gtk_notebook_append_page (notebook, self->page_welcome,
870 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
871 gtk_notebook_append_page (notebook, self->page_account_details,
872 gtk_label_new (_("mcen_ti_accountdetails")));
873 gtk_notebook_append_page (notebook, self->page_user_details,
874 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
876 /* Create and add the easysetup-specific pages,
877 * because we need _some_ final page to enable the Next and Finish buttons: */
878 create_subsequent_easysetup_pages (self);
881 /* Connect to the dialog's response signal so we can enable/disable buttons
882 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
883 * Note that we use g_signal_connect_after() instead of g_signal_connect()
884 * so that we can be enable/disable after ModestWizardDialog has done its own
885 * enabling/disabling of buttons.
887 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
888 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
890 * It's not enough to connect to the notebook's switch-page signal, because
891 * ModestWizardDialog's "response" signal handler enables the buttons itself,
892 * _after_ switching the page (understandably).
893 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
894 * then gtk_notebook_get_current_page() would return an incorrect value.)
896 g_signal_connect_after (G_OBJECT (self), "response",
897 G_CALLBACK (on_response), self);
899 /* When this window is shown, hibernation should not be possible,
900 * because there is no sensible way to save the state: */
901 modest_window_mgr_prevent_hibernation_while_window_is_shown (
902 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
905 ModestEasysetupWizardDialog*
906 modest_easysetup_wizard_dialog_new (void)
908 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
911 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
913 GtkNotebook *notebook = NULL;
914 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
917 /* Create the custom pages: */
918 if(!(self->page_custom_incoming)) {
919 self->page_custom_incoming = create_page_custom_incoming (self);
922 if(!(self->page_custom_outgoing)) {
923 self->page_custom_outgoing = create_page_custom_outgoing (self);
926 if(!(self->page_complete_customsetup)) {
927 self->page_complete_customsetup = create_page_complete_custom (self);
930 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
931 gtk_notebook_append_page (notebook, self->page_custom_incoming,
932 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
934 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
935 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
936 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
938 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
939 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
940 gtk_label_new (_("mcen_ti_emailsetup_complete")));
942 /* This is unnecessary with GTK+ 2.10: */
943 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
946 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
948 GtkNotebook *notebook = NULL;
949 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
952 /* Create the easysetup-specific pages: */
953 if(!self->page_complete_easysetup)
954 self->page_complete_easysetup = create_page_complete_easysetup (self);
956 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
957 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
958 gtk_label_new (_("mcen_ti_emailsetup_complete")));
960 /* This is unnecessary with GTK+ 2.10: */
961 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
963 /* After the user details page,
964 * the following pages depend on whether "Other" was chosen
965 * in the provider combobox on the account page
967 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
969 if (easysetup_provider_combo_box_get_active_provider_id (
970 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
971 /* "Other..." was selected: */
973 /* Make sure that the easysetup pages do not exist: */
974 if(self->page_complete_easysetup) {
975 gtk_widget_destroy (self->page_complete_easysetup);
976 self->page_complete_easysetup = NULL;
979 create_subsequent_customsetup_pages (self);
982 /* A specific provider was selected: */
984 /* Make sure that the custom pages do not exist:
985 * Because they will be used if they exist, when creating the account. */
986 if(self->page_custom_incoming) {
987 gtk_widget_destroy (self->page_custom_incoming);
988 self->page_custom_incoming = NULL;
991 if(self->page_custom_outgoing) {
992 gtk_widget_destroy (self->page_custom_outgoing);
993 self->page_custom_outgoing = NULL;
996 if(self->page_complete_customsetup) {
997 gtk_widget_destroy (self->page_complete_customsetup);
998 self->page_complete_customsetup = NULL;
1002 /* Create the easysetup pages: */
1003 create_subsequent_easysetup_pages (self);
1009 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
1014 gchar* at = g_utf8_strchr (email_address, -1, '@');
1015 if (!at || (g_utf8_strlen (at, -1) < 2))
1018 gchar* domain = g_utf8_next_char (at);
1022 const gchar* hostname = NULL;
1023 if (servertype == MODEST_PROTOCOL_STORE_POP)
1025 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1027 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1033 return g_strdup_printf ("%s.%s", hostname, domain);
1036 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1038 if (!account_wizard->entry_incomingserver)
1041 /* Set a default domain for the server, based on the email address,
1042 * if no server name was already specified.
1044 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
1045 if ((!incoming_existing || (strlen(incoming_existing) == 0))
1046 && account_wizard->entry_user_email) {
1047 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1048 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1049 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1051 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1052 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1053 g_free (servername);
1056 /* Set a default domain for the server, based on the email address,
1057 * if no server name was already specified.
1059 if (!account_wizard->entry_outgoingserver)
1062 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
1063 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
1064 && account_wizard->entry_user_email) {
1065 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1067 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1068 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1069 g_free (servername);
1074 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1076 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1078 /* Do extra validation that couldn't be done for every key press,
1079 * either because it was too slow,
1080 * or because it requires interaction:
1082 if (current_page == account_wizard->page_account_details) {
1083 /* Check that the title is not already in use: */
1084 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1085 if ((!account_title) || (strlen(account_title) == 0))
1088 /* Aavoid a clash with an existing display name: */
1089 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1090 account_wizard->account_manager, account_title);
1093 /* Warn the user via a dialog: */
1094 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1099 else if (current_page == account_wizard->page_user_details) {
1100 /* Check that the email address is valud: */
1101 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1102 if ((!email_address) || (strlen(email_address) == 0))
1105 if (!modest_text_utils_validate_email_address (email_address)) {
1106 /* Warn the user via a dialog: */
1107 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1109 /* Return focus to the email address entry: */
1110 gtk_widget_grab_focus (account_wizard->entry_user_email);
1115 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1116 create_subsequent_pages (account_wizard);
1119 /* TODO: The UI Spec wants us to check that the servernames are valid,
1120 * but does not specify how.
1123 if(next_page == account_wizard->page_custom_incoming) {
1124 set_default_custom_servernames (account_wizard);
1126 else if (next_page == account_wizard->page_custom_outgoing) {
1127 set_default_custom_servernames (account_wizard);
1130 /* If this is the last page, and this is a click on Finish,
1131 * then attempt to create the dialog.
1133 if(!next_page) /* This is NULL when this is a click on Finish. */
1135 if (account_wizard->saved_account_name) {
1136 /* Just enable the already-saved account (temporarily created when
1137 * editing advanced settings): */
1138 modest_account_mgr_set_enabled (account_wizard->account_manager,
1139 account_wizard->saved_account_name, TRUE);
1141 create_account (account_wizard, TRUE /* enabled */);
1149 static gboolean entry_is_empty (GtkWidget *entry)
1154 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1155 if ((!text) || (strlen(text) == 0))
1162 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1164 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1166 gboolean enable_next = TRUE;
1167 if (current_page == account_wizard->page_welcome) {
1170 else if (current_page == account_wizard->page_account_details) {
1171 /* The account details title is mandatory: */
1172 if (entry_is_empty(account_wizard->entry_account_title))
1173 enable_next = FALSE;
1175 else if (current_page == account_wizard->page_user_details) {
1176 /* The user details username is mandatory: */
1177 if (entry_is_empty(account_wizard->entry_user_username))
1178 enable_next = FALSE;
1180 /* The user details email address is mandatory: */
1181 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1182 enable_next = FALSE;
1184 else if (current_page == account_wizard->page_custom_incoming) {
1185 /* The custom incoming server is mandatory: */
1186 if (entry_is_empty(account_wizard->entry_incomingserver))
1187 enable_next = FALSE;
1190 /* Enable the buttons,
1191 * identifying them via their associated response codes: */
1193 /* Disable the Finish button until we are on the last page,
1194 * because HildonWizardDialog enables this for all but the first page: */
1195 GtkNotebook *notebook = NULL;
1196 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1197 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1199 gint current = gtk_notebook_get_current_page (notebook);
1200 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1201 const gboolean is_last = (current == last);
1204 gtk_dialog_set_response_sensitive (dialog_base,
1205 MODEST_WIZARD_DIALOG_FINISH,
1209 /* Disable Next on the last page: */
1210 enable_next = FALSE;
1213 gtk_dialog_set_response_sensitive (dialog_base,
1214 MODEST_WIZARD_DIALOG_NEXT,
1219 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1221 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1222 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1225 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1226 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1227 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1228 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1230 /* Provide a vfunc implementation so we can decide
1231 * when to enable/disable the prev/next buttons.
1233 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1234 base_klass->before_next = on_before_next;
1235 base_klass->enable_buttons = on_enable_buttons;
1239 show_error (GtkWindow *parent_window, const gchar* text)
1241 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1243 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1250 gtk_dialog_run (dialog);
1251 gtk_widget_destroy (GTK_WIDGET (dialog));
1254 /** Attempt to create the account from the information that the user has entered.
1255 * @result: TRUE if the account was successfully created.
1258 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1260 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1262 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1268 /* We should have checked for this already,
1269 * and changed that name accordingly,
1270 * but let's check again just in case:
1272 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1275 /* Increment the non-user visible name if necessary,
1276 * based on the display name: */
1277 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1278 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1279 account_name_start, FALSE /* not a server account */);
1280 g_free (account_name_start);
1282 /* username and password (for both incoming and outgoing): */
1283 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1284 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1286 /* Incoming server: */
1287 /* Note: We need something as default for the ModestProtocol values,
1288 * or modest_account_mgr_add_server_account will fail. */
1289 gchar* servername_incoming = NULL;
1290 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1291 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1292 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1294 /* Get details from the specified presets: */
1295 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1296 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1300 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1301 TRUE /* incoming */);
1303 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1304 TRUE /* incoming */);
1307 /* We don't check for SMTP here as that is impossible for an incoming server. */
1308 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1309 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1310 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1311 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1313 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1314 TRUE /* incoming */);
1317 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1318 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1320 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1321 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1324 /* Use custom pages because no preset was specified: */
1325 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1327 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1328 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1330 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1331 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1333 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1334 ? MODEST_PROTOCOL_AUTH_PASSWORD
1335 : MODEST_PROTOCOL_AUTH_NONE;
1339 /* First we add the 2 server accounts, and then we add the account that uses them.
1340 * If we don't do it in this order then we will experience a crash. */
1342 /* Add a (incoming) server account, to be used by the account: */
1343 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1344 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1345 store_name_start, TRUE /* server account */);
1346 g_free (store_name_start);
1347 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1349 servername_incoming,
1352 protocol_security_incoming,
1353 protocol_authentication_incoming);
1355 g_free (servername_incoming);
1358 /* TODO: Provide a Logical ID for the text: */
1359 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1364 /* There must be at least one account now: */
1365 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1366 * fixed in versions after 3.1. */
1367 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1370 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1372 g_slist_free (account_names);
1375 /* Outgoing server: */
1376 gchar* servername_outgoing = NULL;
1377 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1378 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1379 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1383 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1384 FALSE /* incoming */);
1386 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1387 FALSE /* incoming */);
1389 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1390 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1391 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1392 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1394 ModestPresetsSecurity security_outgoing =
1395 modest_presets_get_info_server_security (priv->presets, provider_id,
1396 FALSE /* incoming */);
1398 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1399 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1400 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1402 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1403 /* TODO: There is no SMTP authentication enum for presets. */
1406 /* Use custom pages because no preset was specified: */
1407 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1409 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1411 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1412 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1414 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1415 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1418 /* Add a (outgoing) server account to be used by the account: */
1419 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1420 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1421 transport_name_start, TRUE /* server account */);
1422 g_free (transport_name_start);
1423 created = modest_account_mgr_add_server_account (self->account_manager,
1425 servername_outgoing,
1428 protocol_security_outgoing,
1429 protocol_authentication_outgoing);
1431 g_free (servername_outgoing);
1434 /* TODO: Provide a Logical ID for the text: */
1435 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1440 /* Create the account, which will contain the two "server accounts": */
1441 created = modest_account_mgr_add_account (self->account_manager, account_name,
1442 store_name, /* The name of our POP/IMAP server account. */
1443 transport_name, /* The name of our SMTP server account. */
1445 g_free (store_name);
1446 g_free (transport_name);
1449 /* TODO: Provide a Logical ID for the text: */
1450 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1454 /* The user name and email address must be set additionally: */
1455 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1456 modest_account_mgr_set_string (self->account_manager, account_name,
1457 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1459 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1460 modest_account_mgr_set_string (self->account_manager, account_name,
1461 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1463 /* Set the display name: */
1464 modest_account_mgr_set_string (self->account_manager, account_name,
1465 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1467 /* Save the connection-specific SMTP server accounts. */
1468 gboolean result = TRUE;
1469 if (self->specific_window)
1470 result = modest_connection_specific_smtp_window_save_server_accounts (
1471 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1473 g_free (self->saved_account_name);
1474 self->saved_account_name = g_strdup (account_name);
1476 g_free (account_name);