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 "maemo/modest-maemo-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);
900 ModestEasysetupWizardDialog*
901 modest_easysetup_wizard_dialog_new (void)
903 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
906 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
908 GtkNotebook *notebook = NULL;
909 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
912 /* Create the custom pages: */
913 if(!(self->page_custom_incoming)) {
914 self->page_custom_incoming = create_page_custom_incoming (self);
917 if(!(self->page_custom_outgoing)) {
918 self->page_custom_outgoing = create_page_custom_outgoing (self);
921 if(!(self->page_complete_customsetup)) {
922 self->page_complete_customsetup = create_page_complete_custom (self);
925 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
926 gtk_notebook_append_page (notebook, self->page_custom_incoming,
927 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
929 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
930 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
931 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
933 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
934 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
935 gtk_label_new (_("mcen_ti_emailsetup_complete")));
938 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
940 GtkNotebook *notebook = NULL;
941 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
944 /* Create the easysetup-specific pages: */
945 if(!self->page_complete_easysetup)
946 self->page_complete_easysetup = create_page_complete_easysetup (self);
948 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
949 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
950 gtk_label_new (_("mcen_ti_emailsetup_complete")));
953 /* After the user details page,
954 * the following pages depend on whether "Other" was chosen
955 * in the provider combobox on the account page
957 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
959 if (easysetup_provider_combo_box_get_active_provider_id (
960 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
961 /* "Other..." was selected: */
963 /* Make sure that the easysetup pages do not exist: */
964 if(self->page_complete_easysetup) {
965 gtk_widget_destroy (self->page_complete_easysetup);
966 self->page_complete_easysetup = NULL;
969 create_subsequent_customsetup_pages (self);
972 /* A specific provider was selected: */
974 /* Make sure that the custom pages do not exist:
975 * Because they will be used if they exist, when creating the account. */
976 if(self->page_custom_incoming) {
977 gtk_widget_destroy (self->page_custom_incoming);
978 self->page_custom_incoming = NULL;
981 if(self->page_custom_outgoing) {
982 gtk_widget_destroy (self->page_custom_outgoing);
983 self->page_custom_outgoing = NULL;
986 if(self->page_complete_customsetup) {
987 gtk_widget_destroy (self->page_complete_customsetup);
988 self->page_complete_customsetup = NULL;
992 /* Create the easysetup pages: */
993 create_subsequent_easysetup_pages (self);
999 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
1004 gchar* at = g_utf8_strchr (email_address, -1, '@');
1005 if (!at || (g_utf8_strlen (at, -1) < 2))
1008 gchar* domain = g_utf8_next_char (at);
1012 const gchar* hostname = NULL;
1013 if (servertype == MODEST_PROTOCOL_STORE_POP)
1015 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1017 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1023 return g_strdup_printf ("%s.%s", hostname, domain);
1026 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1028 if (!account_wizard->entry_incomingserver)
1031 /* Set a default domain for the server, based on the email address,
1032 * if no server name was already specified.
1034 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
1035 if ((!incoming_existing || (strlen(incoming_existing) == 0))
1036 && account_wizard->entry_user_email) {
1037 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1038 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1039 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1041 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1042 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1043 g_free (servername);
1046 /* Set a default domain for the server, based on the email address,
1047 * if no server name was already specified.
1049 if (!account_wizard->entry_outgoingserver)
1052 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
1053 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
1054 && account_wizard->entry_user_email) {
1055 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1057 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1058 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1059 g_free (servername);
1064 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1066 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1068 /* Do extra validation that couldn't be done for every key press,
1069 * either because it was too slow,
1070 * or because it requires interaction:
1072 if (current_page == account_wizard->page_account_details) {
1073 /* Check that the title is not already in use: */
1074 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1075 if ((!account_title) || (strlen(account_title) == 0))
1078 /* Aavoid a clash with an existing display name: */
1079 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1080 account_wizard->account_manager, account_title);
1083 /* Warn the user via a dialog: */
1084 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1089 else if (current_page == account_wizard->page_user_details) {
1090 /* Check that the email address is valud: */
1091 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1092 if ((!email_address) || (strlen(email_address) == 0))
1095 if (!modest_text_utils_validate_email_address (email_address)) {
1096 /* Warn the user via a dialog: */
1097 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1099 /* Return focus to the email address entry: */
1100 gtk_widget_grab_focus (account_wizard->entry_user_email);
1105 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1106 create_subsequent_pages (account_wizard);
1109 /* TODO: The UI Spec wants us to check that the servernames are valid,
1110 * but does not specify how.
1113 if(next_page == account_wizard->page_custom_incoming) {
1114 set_default_custom_servernames (account_wizard);
1116 else if (next_page == account_wizard->page_custom_outgoing) {
1117 set_default_custom_servernames (account_wizard);
1120 /* If this is the last page, and this is a click on Finish,
1121 * then attempt to create the dialog.
1123 if(!next_page) /* This is NULL when this is a click on Finish. */
1125 if (account_wizard->saved_account_name) {
1126 /* Just enable the already-saved account (temporarily created when
1127 * editing advanced settings): */
1128 modest_account_mgr_set_enabled (account_wizard->account_manager,
1129 account_wizard->saved_account_name, TRUE);
1131 create_account (account_wizard, TRUE /* enabled */);
1139 static gboolean entry_is_empty (GtkWidget *entry)
1144 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1145 if ((!text) || (strlen(text) == 0))
1152 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1154 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1156 gboolean enable_next = TRUE;
1157 if (current_page == account_wizard->page_welcome) {
1160 else if (current_page == account_wizard->page_account_details) {
1161 /* The account details title is mandatory: */
1162 if (entry_is_empty(account_wizard->entry_account_title))
1163 enable_next = FALSE;
1165 else if (current_page == account_wizard->page_user_details) {
1166 /* The user details username is mandatory: */
1167 if (entry_is_empty(account_wizard->entry_user_username))
1168 enable_next = FALSE;
1170 /* The user details email address is mandatory: */
1171 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1172 enable_next = FALSE;
1174 else if (current_page == account_wizard->page_custom_incoming) {
1175 /* The custom incoming server is mandatory: */
1176 if (entry_is_empty(account_wizard->entry_incomingserver))
1177 enable_next = FALSE;
1180 /* Enable the buttons,
1181 * identifying them via their associated response codes: */
1183 /* Disable the Finish button until we are on the last page,
1184 * because HildonWizardDialog enables this for all but the first page: */
1185 GtkNotebook *notebook = NULL;
1186 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1187 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1189 gint current = gtk_notebook_get_current_page (notebook);
1190 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1191 const gboolean is_last = (current == last);
1194 gtk_dialog_set_response_sensitive (dialog_base,
1195 MODEST_WIZARD_DIALOG_FINISH,
1199 /* Disable Next on the last page: */
1200 enable_next = FALSE;
1203 gtk_dialog_set_response_sensitive (dialog_base,
1204 MODEST_WIZARD_DIALOG_NEXT,
1209 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1211 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1212 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1215 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1216 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1217 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1218 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1220 /* Provide a vfunc implementation so we can decide
1221 * when to enable/disable the prev/next buttons.
1223 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1224 base_klass->before_next = on_before_next;
1225 base_klass->enable_buttons = on_enable_buttons;
1229 show_error (GtkWindow *parent_window, const gchar* text)
1231 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1233 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1240 gtk_dialog_run (dialog);
1241 gtk_widget_destroy (GTK_WIDGET (dialog));
1244 /** Attempt to create the account from the information that the user has entered.
1245 * @result: TRUE if the account was successfully created.
1248 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1250 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1252 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1258 /* We should have checked for this already,
1259 * and changed that name accordingly,
1260 * but let's check again just in case:
1262 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1265 /* Increment the non-user visible name if necessary,
1266 * based on the display name: */
1267 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1268 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1269 account_name_start, FALSE /* not a server account */);
1270 g_free (account_name_start);
1272 /* username and password (for both incoming and outgoing): */
1273 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1274 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1276 /* Incoming server: */
1277 /* Note: We need something as default for the ModestProtocol values,
1278 * or modest_account_mgr_add_server_account will fail. */
1279 gchar* servername_incoming = NULL;
1280 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1281 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1282 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1284 /* Get details from the specified presets: */
1285 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1286 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1290 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1291 TRUE /* incoming */);
1293 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1294 TRUE /* incoming */);
1297 /* We don't check for SMTP here as that is impossible for an incoming server. */
1298 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1299 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1300 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1301 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1303 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1304 TRUE /* incoming */);
1307 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1308 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1310 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1311 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1314 /* Use custom pages because no preset was specified: */
1315 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1317 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1318 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1320 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1321 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1323 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1324 ? MODEST_PROTOCOL_AUTH_PASSWORD
1325 : MODEST_PROTOCOL_AUTH_NONE;
1329 /* First we add the 2 server accounts, and then we add the account that uses them.
1330 * If we don't do it in this order then we will experience a crash. */
1332 /* Add a (incoming) server account, to be used by the account: */
1333 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1334 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1335 store_name_start, TRUE /* server account */);
1336 g_free (store_name_start);
1337 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1339 servername_incoming,
1342 protocol_security_incoming,
1343 protocol_authentication_incoming);
1345 g_free (servername_incoming);
1348 /* TODO: Provide a Logical ID for the text: */
1349 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1354 /* There must be at least one account now: */
1355 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1356 * fixed in versions after 3.1. */
1357 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1360 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1362 g_slist_free (account_names);
1365 /* Outgoing server: */
1366 gchar* servername_outgoing = NULL;
1367 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1368 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1369 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1373 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1374 FALSE /* incoming */);
1376 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1377 FALSE /* incoming */);
1379 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1380 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1381 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1382 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1384 ModestPresetsSecurity security_outgoing =
1385 modest_presets_get_info_server_security (priv->presets, provider_id,
1386 FALSE /* incoming */);
1388 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1389 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1390 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1392 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1393 /* TODO: There is no SMTP authentication enum for presets. */
1396 /* Use custom pages because no preset was specified: */
1397 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1399 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1401 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1402 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1404 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1405 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1408 /* Add a (outgoing) server account to be used by the account: */
1409 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1410 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1411 transport_name_start, TRUE /* server account */);
1412 g_free (transport_name_start);
1413 created = modest_account_mgr_add_server_account (self->account_manager,
1415 servername_outgoing,
1418 protocol_security_outgoing,
1419 protocol_authentication_outgoing);
1421 g_free (servername_outgoing);
1424 /* TODO: Provide a Logical ID for the text: */
1425 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1430 /* Create the account, which will contain the two "server accounts": */
1431 created = modest_account_mgr_add_account (self->account_manager, account_name,
1432 store_name, /* The name of our POP/IMAP server account. */
1433 transport_name, /* The name of our SMTP server account. */
1435 g_free (store_name);
1436 g_free (transport_name);
1439 /* TODO: Provide a Logical ID for the text: */
1440 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1444 /* The user name and email address must be set additionally: */
1445 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1446 modest_account_mgr_set_string (self->account_manager, account_name,
1447 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1449 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1450 modest_account_mgr_set_string (self->account_manager, account_name,
1451 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1453 /* Set the display name: */
1454 modest_account_mgr_set_string (self->account_manager, account_name,
1455 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1457 /* Save the connection-specific SMTP server accounts. */
1458 gboolean result = TRUE;
1459 if (self->specific_window)
1460 result = modest_connection_specific_smtp_window_save_server_accounts (
1461 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1463 g_free (self->saved_account_name);
1464 self->saved_account_name = g_strdup (account_name);
1466 g_free (account_name);