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),
442 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
443 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
444 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
445 caption = create_caption_new_with_asterix (self, sizegroup,
446 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
447 gtk_widget_show (self->entry_user_password);
448 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
449 gtk_widget_show (caption);
451 /* The email address widgets: */
452 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
453 /* Auto-capitalization is the default, so let's turn it off: */
454 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
455 caption = create_caption_new_with_asterix (self, sizegroup,
456 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
457 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
458 gtk_widget_show (self->entry_user_email);
459 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
460 gtk_widget_show (caption);
462 /* Set max length as in the UI spec:
463 * The UI spec seems to want us to show a dialog if we hit the maximum. */
464 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
465 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
469 gtk_widget_show (GTK_WIDGET (box));
471 return GTK_WIDGET (box);
474 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
476 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
477 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
478 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
479 gtk_widget_show (label);
480 gtk_widget_show (GTK_WIDGET (box));
481 return GTK_WIDGET (box);
484 /** Change the caption title for the incoming server,
485 * as specified in the UI spec:
487 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
489 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
490 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
492 (protocol == MODEST_PROTOCOL_STORE_POP ?
493 _("mail_fi_emailtype_pop3") :
494 _("mail_fi_emailtype_imap") );
497 /* Note that this produces a compiler warning,
498 * because the compiler does not know that the translated string will have a %s in it.
499 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
500 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
501 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
502 g_free(incomingserver_title);
505 /** Change the caption title for the incoming server,
506 * as specified in the UI spec:
508 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
510 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
511 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
513 /* Fill the combo with appropriately titled choices for POP or IMAP. */
514 /* The choices are the same, but the titles are different, as in the UI spec. */
515 modest_serversecurity_combo_box_fill (
516 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
519 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
521 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
522 update_incoming_server_title (self);
523 update_incoming_server_security_choices (self);
526 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
528 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
530 /* Create a size group to be used by all captions.
531 * Note that HildonCaption does not create a default size group if we do not specify one.
532 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
533 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
535 /* The incoming server widgets: */
536 if (!self->combo_incoming_servertype)
537 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
538 easysetup_servertype_combo_box_set_active_servertype (
539 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
540 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
541 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
542 gtk_widget_show (self->combo_incoming_servertype);
543 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
544 gtk_widget_show (caption);
546 if(!self->entry_incomingserver)
547 self->entry_incomingserver = gtk_entry_new ();
548 /* Auto-capitalization is the default, so let's turn it off: */
549 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
550 set_default_custom_servernames (self);
552 if (self->caption_incoming)
553 gtk_widget_destroy (self->caption_incoming);
555 /* The caption title will be updated in update_incoming_server_title().
556 * so this default text will never be seen: */
557 /* (Note: Changing the title seems pointless. murrayc) */
558 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
559 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
560 update_incoming_server_title (self);
561 gtk_widget_show (self->entry_incomingserver);
562 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
563 gtk_widget_show (self->caption_incoming);
565 /* Change the caption title when the servertype changes,
566 * as in the UI spec: */
567 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
568 G_CALLBACK (on_combo_servertype_changed), self);
570 /* The secure connection widgets: */
571 if (!self->combo_incoming_security)
572 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
573 update_incoming_server_security_choices (self);
574 modest_serversecurity_combo_box_set_active_serversecurity (
575 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
576 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
577 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
578 gtk_widget_show (self->combo_incoming_security);
579 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
580 gtk_widget_show (caption);
582 if(!self->checkbox_incoming_auth)
583 self->checkbox_incoming_auth = gtk_check_button_new ();
584 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
585 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
586 gtk_widget_show (self->checkbox_incoming_auth);
587 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
588 gtk_widget_show (caption);
590 gtk_widget_show (GTK_WIDGET (box));
592 return GTK_WIDGET (box);
596 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
598 GtkWidget *widget = GTK_WIDGET (user_data);
600 /* Enable the widget only if the toggle button is active: */
601 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
602 gtk_widget_set_sensitive (widget, enable);
605 /* Make the sensitivity of a widget depend on a toggle button.
608 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
610 g_signal_connect (G_OBJECT (button), "toggled",
611 G_CALLBACK (on_toggle_button_changed), widget);
613 /* Set the starting sensitivity: */
614 on_toggle_button_changed (button, widget);
618 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
620 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
622 /* Create the window, if necessary: */
623 if (!(self->specific_window)) {
624 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
625 modest_connection_specific_smtp_window_fill_with_connections (
626 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
627 NULL /* account_name, not known yet. */);
630 /* Show the window: */
631 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
632 gtk_widget_show (self->specific_window);
635 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
637 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
639 /* Create a size group to be used by all captions.
640 * Note that HildonCaption does not create a default size group if we do not specify one.
641 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
642 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
644 /* The outgoing server widgets: */
645 if (!self->entry_outgoingserver)
646 self->entry_outgoingserver = gtk_entry_new ();
647 /* Auto-capitalization is the default, so let's turn it off: */
648 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
649 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
650 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
651 gtk_widget_show (self->entry_outgoingserver);
652 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
653 gtk_widget_show (caption);
654 set_default_custom_servernames (self);
656 /* The secure connection widgets: */
657 if (!self->combo_outgoing_security)
658 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
659 modest_serversecurity_combo_box_fill (
660 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
661 modest_serversecurity_combo_box_set_active_serversecurity (
662 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
663 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
664 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
665 gtk_widget_show (self->combo_outgoing_security);
666 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
667 gtk_widget_show (caption);
669 /* The secure authentication widgets: */
670 if (!self->combo_outgoing_auth)
671 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
672 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
673 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
674 gtk_widget_show (self->combo_outgoing_auth);
675 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
676 gtk_widget_show (caption);
678 GtkWidget *separator = gtk_hseparator_new ();
679 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
680 gtk_widget_show (separator);
682 /* connection-specific checkbox: */
683 if (!self->checkbox_outgoing_smtp_specific) {
684 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
685 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
688 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
689 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
690 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
691 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
692 gtk_widget_show (caption);
694 /* Connection-specific SMTP-Severs Edit button: */
695 if (!self->button_outgoing_smtp_servers)
696 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
697 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
698 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
699 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
700 gtk_widget_show (self->button_outgoing_smtp_servers);
701 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
702 gtk_widget_show (caption);
704 /* Only enable the button when the checkbox is checked: */
705 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
706 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
708 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
709 G_CALLBACK (on_button_outgoing_smtp_servers), self);
712 gtk_widget_show (GTK_WIDGET (box));
714 return GTK_WIDGET (box);
718 on_timeout_show_advanced_edit(gpointer user_data)
720 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
722 if (!(self->saved_account_name))
725 /* Show the Account Settings window: */
726 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
727 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
729 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
731 gtk_dialog_run (GTK_DIALOG (dialog));
733 /* TODO: The hide() is not necessary.
734 * It is just here to show that it doesn't work,
735 * just as destroy doesn't work.
737 gtk_widget_hide (GTK_WIDGET(dialog));
739 /* TODO: The dialog remains on screen, not allowing any interaction.
740 * But gtk_widget_destroy() should always destroy.
742 printf("debug: destroying settings dialog\n");
743 gtk_widget_destroy (GTK_WIDGET (dialog));
744 printf("debug: after destroying settings dialog (doesn't seem to work).\n");
746 return FALSE; /* Do not call this timeout callback again. */
750 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
752 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
754 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
755 * without recoding it to use non-gconf information.
756 * This account will be deleted if Finish is never actually clicked. */
758 gboolean saved = TRUE;
759 gboolean was_already_saved = TRUE;
760 if (!(self->saved_account_name)) {
761 saved = create_account (self, FALSE);
762 was_already_saved = FALSE;
768 if (!(self->saved_account_name))
771 /* Show the Account Settings window: */
772 if (was_already_saved) {
773 /* Just show the dialog immediately: */
774 on_timeout_show_advanced_edit(self);
778 printf ("debug: waiting for gconf to update its local cache. "
779 "This is a hack to work around a maemo gconf bug in maemo bora.\n");
781 g_timeout_add (5000, on_timeout_show_advanced_edit, self);
784 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
786 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
787 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
788 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
789 gtk_widget_show (label);
791 if (!self->button_edit)
792 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
793 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
794 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
795 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
796 gtk_widget_show (self->button_edit);
797 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
798 gtk_widget_show (caption);
800 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
801 G_CALLBACK (on_button_edit_advanced_settings), self);
803 gtk_widget_show (GTK_WIDGET (box));
804 return GTK_WIDGET (box);
811 on_response (ModestWizardDialog *wizard_dialog,
815 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
817 if (response_id == GTK_RESPONSE_CANCEL) {
818 /* Remove any temporarily-saved account that will not actually be needed: */
819 if (self->saved_account_name) {
820 modest_account_mgr_remove_account (self->account_manager,
821 self->saved_account_name, FALSE);
825 invoke_enable_buttons_vfunc (self);
829 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
831 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
833 /* Create the notebook to be used by the ModestWizardDialog base class:
834 * Each page of the notebook will be a page of the wizard: */
835 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
837 /* Set the notebook used by the ModestWizardDialog base class: */
838 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
840 /* Set the wizard title:
841 * The actual window title will be a combination of this and the page's tab label title. */
842 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
844 /* Read in the information about known service providers: */
845 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
847 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
848 priv->presets = modest_presets_new (filepath);
849 if (!(priv->presets)) {
850 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
853 g_assert(priv->presets);
856 /* Get the account manager object,
857 * so we can check for existing accounts,
858 * and create new accounts: */
859 self->account_manager = modest_runtime_get_account_mgr ();
860 g_assert (self->account_manager);
861 g_object_ref (self->account_manager);
863 /* Create the common pages,
865 self->page_welcome = create_page_welcome (self);
866 self->page_account_details = create_page_account_details (self);
867 self->page_user_details = create_page_user_details (self);
869 /* Add the common pages: */
870 gtk_notebook_append_page (notebook, self->page_welcome,
871 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
872 gtk_notebook_append_page (notebook, self->page_account_details,
873 gtk_label_new (_("mcen_ti_accountdetails")));
874 gtk_notebook_append_page (notebook, self->page_user_details,
875 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
877 /* Create and add the easysetup-specific pages,
878 * because we need _some_ final page to enable the Next and Finish buttons: */
879 create_subsequent_easysetup_pages (self);
882 /* Connect to the dialog's response signal so we can enable/disable buttons
883 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
884 * Note that we use g_signal_connect_after() instead of g_signal_connect()
885 * so that we can be enable/disable after ModestWizardDialog has done its own
886 * enabling/disabling of buttons.
888 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
889 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
891 * It's not enough to connect to the notebook's switch-page signal, because
892 * ModestWizardDialog's "response" signal handler enables the buttons itself,
893 * _after_ switching the page (understandably).
894 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
895 * then gtk_notebook_get_current_page() would return an incorrect value.)
897 g_signal_connect_after (G_OBJECT (self), "response",
898 G_CALLBACK (on_response), self);
900 /* When this window is shown, hibernation should not be possible,
901 * because there is no sensible way to save the state: */
902 modest_window_mgr_prevent_hibernation_while_window_is_shown (
903 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
906 ModestEasysetupWizardDialog*
907 modest_easysetup_wizard_dialog_new (void)
909 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
912 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
914 GtkNotebook *notebook = NULL;
915 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
918 /* Create the custom pages: */
919 if(!(self->page_custom_incoming)) {
920 self->page_custom_incoming = create_page_custom_incoming (self);
923 if(!(self->page_custom_outgoing)) {
924 self->page_custom_outgoing = create_page_custom_outgoing (self);
927 if(!(self->page_complete_customsetup)) {
928 self->page_complete_customsetup = create_page_complete_custom (self);
931 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
932 gtk_notebook_append_page (notebook, self->page_custom_incoming,
933 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
935 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
936 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
937 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
939 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
940 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
941 gtk_label_new (_("mcen_ti_emailsetup_complete")));
943 /* This is unnecessary with GTK+ 2.10: */
944 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
947 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
949 GtkNotebook *notebook = NULL;
950 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
953 /* Create the easysetup-specific pages: */
954 if(!self->page_complete_easysetup)
955 self->page_complete_easysetup = create_page_complete_easysetup (self);
957 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
958 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
959 gtk_label_new (_("mcen_ti_emailsetup_complete")));
961 /* This is unnecessary with GTK+ 2.10: */
962 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
964 /* After the user details page,
965 * the following pages depend on whether "Other" was chosen
966 * in the provider combobox on the account page
968 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
970 if (easysetup_provider_combo_box_get_active_provider_id (
971 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
972 /* "Other..." was selected: */
974 /* Make sure that the easysetup pages do not exist: */
975 if(self->page_complete_easysetup) {
976 gtk_widget_destroy (self->page_complete_easysetup);
977 self->page_complete_easysetup = NULL;
980 create_subsequent_customsetup_pages (self);
983 /* A specific provider was selected: */
985 /* Make sure that the custom pages do not exist:
986 * Because they will be used if they exist, when creating the account. */
987 if(self->page_custom_incoming) {
988 gtk_widget_destroy (self->page_custom_incoming);
989 self->page_custom_incoming = NULL;
992 if(self->page_custom_outgoing) {
993 gtk_widget_destroy (self->page_custom_outgoing);
994 self->page_custom_outgoing = NULL;
997 if(self->page_complete_customsetup) {
998 gtk_widget_destroy (self->page_complete_customsetup);
999 self->page_complete_customsetup = NULL;
1003 /* Create the easysetup pages: */
1004 create_subsequent_easysetup_pages (self);
1010 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
1015 gchar* at = g_utf8_strchr (email_address, -1, '@');
1016 if (!at || (g_utf8_strlen (at, -1) < 2))
1019 gchar* domain = g_utf8_next_char (at);
1023 const gchar* hostname = NULL;
1024 if (servertype == MODEST_PROTOCOL_STORE_POP)
1026 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1028 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1034 return g_strdup_printf ("%s.%s", hostname, domain);
1037 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1039 if (!account_wizard->entry_incomingserver)
1042 /* Set a default domain for the server, based on the email address,
1043 * if no server name was already specified.
1045 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
1046 if ((!incoming_existing || (strlen(incoming_existing) == 0))
1047 && account_wizard->entry_user_email) {
1048 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1049 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1050 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1052 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1053 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1054 g_free (servername);
1057 /* Set a default domain for the server, based on the email address,
1058 * if no server name was already specified.
1060 if (!account_wizard->entry_outgoingserver)
1063 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
1064 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
1065 && account_wizard->entry_user_email) {
1066 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1068 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1069 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1070 g_free (servername);
1075 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1077 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1079 /* Do extra validation that couldn't be done for every key press,
1080 * either because it was too slow,
1081 * or because it requires interaction:
1083 if (current_page == account_wizard->page_account_details) {
1084 /* Check that the title is not already in use: */
1085 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1086 if ((!account_title) || (strlen(account_title) == 0))
1089 /* Aavoid a clash with an existing display name: */
1090 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1091 account_wizard->account_manager, account_title);
1094 /* Warn the user via a dialog: */
1095 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1100 else if (current_page == account_wizard->page_user_details) {
1101 /* Check that the email address is valud: */
1102 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1103 if ((!email_address) || (strlen(email_address) == 0))
1106 if (!modest_text_utils_validate_email_address (email_address)) {
1107 /* Warn the user via a dialog: */
1108 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1110 /* Return focus to the email address entry: */
1111 gtk_widget_grab_focus (account_wizard->entry_user_email);
1116 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1117 create_subsequent_pages (account_wizard);
1120 /* TODO: The UI Spec wants us to check that the servernames are valid,
1121 * but does not specify how.
1124 if(next_page == account_wizard->page_custom_incoming) {
1125 set_default_custom_servernames (account_wizard);
1127 else if (next_page == account_wizard->page_custom_outgoing) {
1128 set_default_custom_servernames (account_wizard);
1131 /* If this is the last page, and this is a click on Finish,
1132 * then attempt to create the dialog.
1134 if(!next_page) /* This is NULL when this is a click on Finish. */
1136 if (account_wizard->saved_account_name) {
1137 /* Just enable the already-saved account (temporarily created when
1138 * editing advanced settings): */
1139 modest_account_mgr_set_enabled (account_wizard->account_manager,
1140 account_wizard->saved_account_name, TRUE);
1142 create_account (account_wizard, TRUE /* enabled */);
1150 static gboolean entry_is_empty (GtkWidget *entry)
1155 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1156 if ((!text) || (strlen(text) == 0))
1163 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1165 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1167 gboolean enable_next = TRUE;
1168 if (current_page == account_wizard->page_welcome) {
1171 else if (current_page == account_wizard->page_account_details) {
1172 /* The account details title is mandatory: */
1173 if (entry_is_empty(account_wizard->entry_account_title))
1174 enable_next = FALSE;
1176 else if (current_page == account_wizard->page_user_details) {
1177 /* The user details username is mandatory: */
1178 if (entry_is_empty(account_wizard->entry_user_username))
1179 enable_next = FALSE;
1181 /* The user details email address is mandatory: */
1182 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1183 enable_next = FALSE;
1185 else if (current_page == account_wizard->page_custom_incoming) {
1186 /* The custom incoming server is mandatory: */
1187 if (entry_is_empty(account_wizard->entry_incomingserver))
1188 enable_next = FALSE;
1191 /* Enable the buttons,
1192 * identifying them via their associated response codes: */
1194 /* Disable the Finish button until we are on the last page,
1195 * because HildonWizardDialog enables this for all but the first page: */
1196 GtkNotebook *notebook = NULL;
1197 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1198 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1200 gint current = gtk_notebook_get_current_page (notebook);
1201 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1202 const gboolean is_last = (current == last);
1205 gtk_dialog_set_response_sensitive (dialog_base,
1206 MODEST_WIZARD_DIALOG_FINISH,
1210 /* Disable Next on the last page: */
1211 enable_next = FALSE;
1214 gtk_dialog_set_response_sensitive (dialog_base,
1215 MODEST_WIZARD_DIALOG_NEXT,
1220 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1222 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1223 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1226 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1227 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1228 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1229 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1231 /* Provide a vfunc implementation so we can decide
1232 * when to enable/disable the prev/next buttons.
1234 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1235 base_klass->before_next = on_before_next;
1236 base_klass->enable_buttons = on_enable_buttons;
1240 show_error (GtkWindow *parent_window, const gchar* text)
1242 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1244 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1251 gtk_dialog_run (dialog);
1252 gtk_widget_destroy (GTK_WIDGET (dialog));
1255 /** Attempt to create the account from the information that the user has entered.
1256 * @result: TRUE if the account was successfully created.
1259 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1261 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1263 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1269 /* We should have checked for this already,
1270 * and changed that name accordingly,
1271 * but let's check again just in case:
1273 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1276 /* Increment the non-user visible name if necessary,
1277 * based on the display name: */
1278 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1279 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1280 account_name_start, FALSE /* not a server account */);
1281 g_free (account_name_start);
1283 /* username and password (for both incoming and outgoing): */
1284 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1285 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1287 /* Incoming server: */
1288 /* Note: We need something as default for the ModestProtocol values,
1289 * or modest_account_mgr_add_server_account will fail. */
1290 gchar* servername_incoming = NULL;
1291 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1292 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1293 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1295 /* Get details from the specified presets: */
1296 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1297 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1301 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1302 TRUE /* incoming */);
1304 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1305 TRUE /* incoming */);
1308 /* We don't check for SMTP here as that is impossible for an incoming server. */
1309 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1310 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1311 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1312 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1314 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1315 TRUE /* incoming */);
1318 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1319 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1321 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1322 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1325 /* Use custom pages because no preset was specified: */
1326 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1328 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1329 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1331 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1332 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1334 /* The UI spec says:
1335 * If secure authentication is unchecked, allow sending username and password also as plain text.
1336 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1337 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1339 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1340 ? MODEST_PROTOCOL_AUTH_CRAMMD5
1341 : MODEST_PROTOCOL_AUTH_PASSWORD;
1345 /* First we add the 2 server accounts, and then we add the account that uses them.
1346 * If we don't do it in this order then we will experience a crash. */
1348 /* Add a (incoming) server account, to be used by the account: */
1349 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1350 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1351 store_name_start, TRUE /* server account */);
1352 g_free (store_name_start);
1353 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1355 servername_incoming,
1358 protocol_security_incoming,
1359 protocol_authentication_incoming);
1361 g_free (servername_incoming);
1364 /* TODO: Provide a Logical ID for the text: */
1365 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1370 /* There must be at least one account now: */
1371 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1372 * fixed in versions after 3.1. */
1373 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1376 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1378 g_slist_free (account_names);
1381 /* Outgoing server: */
1382 gchar* servername_outgoing = NULL;
1383 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1384 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1385 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1389 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1390 FALSE /* incoming */);
1392 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1393 FALSE /* incoming */);
1395 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1396 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1397 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1398 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1400 ModestPresetsSecurity security_outgoing =
1401 modest_presets_get_info_server_security (priv->presets, provider_id,
1402 FALSE /* incoming */);
1404 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1405 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1406 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1408 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1409 /* TODO: There is no SMTP authentication enum for presets. */
1412 /* Use custom pages because no preset was specified: */
1413 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1415 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1417 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1418 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1420 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1421 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1424 /* Add a (outgoing) server account to be used by the account: */
1425 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1426 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1427 transport_name_start, TRUE /* server account */);
1428 g_free (transport_name_start);
1429 created = modest_account_mgr_add_server_account (self->account_manager,
1431 servername_outgoing,
1434 protocol_security_outgoing,
1435 protocol_authentication_outgoing);
1437 g_free (servername_outgoing);
1440 /* TODO: Provide a Logical ID for the text: */
1441 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1446 /* Create the account, which will contain the two "server accounts": */
1447 created = modest_account_mgr_add_account (self->account_manager, account_name,
1448 store_name, /* The name of our POP/IMAP server account. */
1449 transport_name, /* The name of our SMTP server account. */
1451 g_free (store_name);
1452 g_free (transport_name);
1455 /* TODO: Provide a Logical ID for the text: */
1456 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1460 /* The user name and email address must be set additionally: */
1461 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1462 modest_account_mgr_set_string (self->account_manager, account_name,
1463 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1465 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1466 modest_account_mgr_set_string (self->account_manager, account_name,
1467 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1469 /* Set the display name: */
1470 modest_account_mgr_set_string (self->account_manager, account_name,
1471 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1473 /* Save the connection-specific SMTP server accounts. */
1474 gboolean result = TRUE;
1475 if (self->specific_window)
1476 result = modest_connection_specific_smtp_window_save_server_accounts (
1477 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1479 g_free (self->saved_account_name);
1480 self->saved_account_name = g_strdup (account_name);
1482 g_free (account_name);