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);
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);
718 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
720 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
722 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
723 * without recoding it to use non-gconf information.
724 * This account will be deleted if Finish is never actually clicked. */
726 const gboolean saved = create_account (self);
730 if (!(self->saved_account_name))
733 /* Show the Account Settings window: */
734 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
735 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
737 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
738 printf ("debug: before run\n");
739 gtk_dialog_run (GTK_DIALOG (dialog));
740 printf ("debug: after run\n");
741 gtk_widget_destroy (GTK_WIDGET (dialog));
743 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
745 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
746 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
747 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
748 gtk_widget_show (label);
750 if (!self->button_edit)
751 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
752 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
753 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
754 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
755 gtk_widget_show (self->button_edit);
756 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
757 gtk_widget_show (caption);
759 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
760 G_CALLBACK (on_button_edit_advanced_settings), self);
762 gtk_widget_show (GTK_WIDGET (box));
763 return GTK_WIDGET (box);
770 on_response (ModestWizardDialog *wizard_dialog,
774 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
776 if (response_id == GTK_RESPONSE_CANCEL) {
777 /* Remove any temporarily-saved account that will not actually be needed: */
778 if (self->saved_account_name) {
779 modest_account_mgr_remove_account (self->account_manager,
780 self->saved_account_name, FALSE);
784 invoke_enable_buttons_vfunc (self);
788 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
790 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
792 /* Create the notebook to be used by the ModestWizardDialog base class:
793 * Each page of the notebook will be a page of the wizard: */
794 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
796 /* Set the notebook used by the ModestWizardDialog base class: */
797 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
799 /* Set the wizard title:
800 * The actual window title will be a combination of this and the page's tab label title. */
801 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
803 /* Read in the information about known service providers: */
804 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
806 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
807 priv->presets = modest_presets_new (filepath);
808 if (!(priv->presets)) {
809 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
812 g_assert(priv->presets);
815 /* Get the account manager object,
816 * so we can check for existing accounts,
817 * and create new accounts: */
818 self->account_manager = modest_runtime_get_account_mgr ();
819 g_assert (self->account_manager);
820 g_object_ref (self->account_manager);
822 /* Create the common pages,
824 self->page_welcome = create_page_welcome (self);
825 self->page_account_details = create_page_account_details (self);
826 self->page_user_details = create_page_user_details (self);
828 /* Add the common pages: */
829 gtk_notebook_append_page (notebook, self->page_welcome,
830 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
831 gtk_notebook_append_page (notebook, self->page_account_details,
832 gtk_label_new (_("mcen_ti_accountdetails")));
833 gtk_notebook_append_page (notebook, self->page_user_details,
834 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
836 /* Create and add the easysetup-specific pages,
837 * because we need _some_ final page to enable the Next and Finish buttons: */
838 create_subsequent_easysetup_pages (self);
841 /* Connect to the dialog's response signal so we can enable/disable buttons
842 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
843 * Note that we use g_signal_connect_after() instead of g_signal_connect()
844 * so that we can be enable/disable after ModestWizardDialog has done its own
845 * enabling/disabling of buttons.
847 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
848 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
850 * It's not enough to connect to the notebook's switch-page signal, because
851 * ModestWizardDialog's "response" signal handler enables the buttons itself,
852 * _after_ switching the page (understandably).
853 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
854 * then gtk_notebook_get_current_page() would return an incorrect value.)
856 g_signal_connect_after (G_OBJECT (self), "response",
857 G_CALLBACK (on_response), self);
860 ModestEasysetupWizardDialog*
861 modest_easysetup_wizard_dialog_new (void)
863 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
866 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
868 GtkNotebook *notebook = NULL;
869 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
872 /* Create the custom pages: */
873 if(!(self->page_custom_incoming)) {
874 self->page_custom_incoming = create_page_custom_incoming (self);
877 if(!(self->page_custom_outgoing)) {
878 self->page_custom_outgoing = create_page_custom_outgoing (self);
881 if(!(self->page_complete_customsetup)) {
882 self->page_complete_customsetup = create_page_complete_custom (self);
885 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
886 gtk_notebook_append_page (notebook, self->page_custom_incoming,
887 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
889 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
890 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
891 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
893 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
894 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
895 gtk_label_new (_("mcen_ti_emailsetup_complete")));
898 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
900 GtkNotebook *notebook = NULL;
901 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
904 /* Create the easysetup-specific pages: */
905 if(!self->page_complete_easysetup)
906 self->page_complete_easysetup = create_page_complete_easysetup (self);
908 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
909 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
910 gtk_label_new (_("mcen_ti_emailsetup_complete")));
913 /* After the user details page,
914 * the following pages depend on whether "Other" was chosen
915 * in the provider combobox on the account page
917 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
919 if (easysetup_provider_combo_box_get_active_provider_id (
920 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
921 /* "Other..." was selected: */
923 /* Make sure that the easysetup pages do not exist: */
924 if(self->page_complete_easysetup) {
925 gtk_widget_destroy (self->page_complete_easysetup);
926 self->page_complete_easysetup = NULL;
929 create_subsequent_customsetup_pages (self);
932 /* A specific provider was selected: */
934 /* Make sure that the custom pages do not exist:
935 * Because they will be used if they exist, when creating the account. */
936 if(self->page_custom_incoming) {
937 gtk_widget_destroy (self->page_custom_incoming);
938 self->page_custom_incoming = NULL;
941 if(self->page_custom_outgoing) {
942 gtk_widget_destroy (self->page_custom_outgoing);
943 self->page_custom_outgoing = NULL;
946 if(self->page_complete_customsetup) {
947 gtk_widget_destroy (self->page_complete_customsetup);
948 self->page_complete_customsetup = NULL;
952 /* Create the easysetup pages: */
953 create_subsequent_easysetup_pages (self);
959 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
964 gchar* at = g_utf8_strchr (email_address, -1, '@');
965 if (!at || (g_utf8_strlen (at, -1) < 2))
968 gchar* domain = g_utf8_next_char (at);
972 const gchar* hostname = NULL;
973 if (servertype == MODEST_PROTOCOL_STORE_POP)
975 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
977 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
983 return g_strdup_printf ("%s.%s", hostname, domain);
986 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
988 if (!account_wizard->entry_incomingserver)
991 /* Set a default domain for the server, based on the email address,
992 * if no server name was already specified.
994 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
995 if ((!incoming_existing || (strlen(incoming_existing) == 0))
996 && account_wizard->entry_user_email) {
997 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
998 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
999 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1001 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1002 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1003 g_free (servername);
1006 /* Set a default domain for the server, based on the email address,
1007 * if no server name was already specified.
1009 if (!account_wizard->entry_outgoingserver)
1012 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
1013 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
1014 && account_wizard->entry_user_email) {
1015 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1017 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1018 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1019 g_free (servername);
1024 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1026 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1028 /* Do extra validation that couldn't be done for every key press,
1029 * either because it was too slow,
1030 * or because it requires interaction:
1032 if (current_page == account_wizard->page_account_details) {
1033 /* Check that the title is not already in use: */
1034 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1035 if ((!account_title) || (strlen(account_title) == 0))
1038 /* Aavoid a clash with an existing display name: */
1039 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1040 account_wizard->account_manager, account_title);
1043 /* Warn the user via a dialog: */
1044 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1049 else if (current_page == account_wizard->page_user_details) {
1050 /* Check that the email address is valud: */
1051 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1052 if ((!email_address) || (strlen(email_address) == 0))
1055 if (!modest_text_utils_validate_email_address (email_address)) {
1056 /* Warn the user via a dialog: */
1057 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1059 /* Return focus to the email address entry: */
1060 gtk_widget_grab_focus (account_wizard->entry_user_email);
1065 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1066 create_subsequent_pages (account_wizard);
1069 /* TODO: The UI Spec wants us to check that the servernames are valid,
1070 * but does not specify how.
1073 if(next_page == account_wizard->page_custom_incoming) {
1074 set_default_custom_servernames (account_wizard);
1076 else if (next_page == account_wizard->page_custom_outgoing) {
1077 set_default_custom_servernames (account_wizard);
1080 /* If this is the last page, and this is a click on Finish,
1081 * then attempt to create the dialog.
1083 if(!next_page) /* This is NULL when this is a click on Finish. */
1085 create_account (account_wizard);
1092 static gboolean entry_is_empty (GtkWidget *entry)
1097 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1098 if ((!text) || (strlen(text) == 0))
1105 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1107 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1109 gboolean enable_next = TRUE;
1110 if (current_page == account_wizard->page_welcome) {
1113 else if (current_page == account_wizard->page_account_details) {
1114 /* The account details title is mandatory: */
1115 if (entry_is_empty(account_wizard->entry_account_title))
1116 enable_next = FALSE;
1118 else if (current_page == account_wizard->page_user_details) {
1119 /* The user details username is mandatory: */
1120 if (entry_is_empty(account_wizard->entry_user_username))
1121 enable_next = FALSE;
1123 /* The user details email address is mandatory: */
1124 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1125 enable_next = FALSE;
1127 else if (current_page == account_wizard->page_custom_incoming) {
1128 /* The custom incoming server is mandatory: */
1129 if (entry_is_empty(account_wizard->entry_incomingserver))
1130 enable_next = FALSE;
1133 /* Enable the buttons,
1134 * identifying them via their associated response codes:
1136 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1137 gtk_dialog_set_response_sensitive (dialog_base,
1138 MODEST_WIZARD_DIALOG_NEXT,
1141 /* Disable the Finish button until we are on the last page,
1142 * because HildonWizardDialog enables this for all but the first page: */
1143 GtkNotebook *notebook = NULL;
1144 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1146 gint current = gtk_notebook_get_current_page (notebook);
1147 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1148 gboolean is_last = (current == last);
1151 gtk_dialog_set_response_sensitive (dialog_base,
1152 MODEST_WIZARD_DIALOG_FINISH,
1158 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1160 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1161 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1164 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1165 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1166 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1167 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1169 /* Provide a vfunc implementation so we can decide
1170 * when to enable/disable the prev/next buttons.
1172 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1173 base_klass->before_next = on_before_next;
1174 base_klass->enable_buttons = on_enable_buttons;
1178 show_error (GtkWindow *parent_window, const gchar* text)
1180 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1182 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1189 gtk_dialog_run (dialog);
1190 gtk_widget_destroy (GTK_WIDGET (dialog));
1193 /** Attempt to create the account from the information that the user has entered.
1194 * @result: TRUE if the account was successfully created.
1197 create_account (ModestEasysetupWizardDialog *self)
1199 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1201 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1207 /* We should have checked for this already,
1208 * and changed that name accordingly,
1209 * but let's check again just in case:
1211 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1214 /* Increment the non-user visible name if necessary,
1215 * based on the display name: */
1216 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1217 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1218 account_name_start, FALSE /* not a server account */);
1219 g_free (account_name_start);
1221 /* username and password (for both incoming and outgoing): */
1222 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1223 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1225 /* Incoming server: */
1226 /* Note: We need something as default for the ModestProtocol values,
1227 * or modest_account_mgr_add_server_account will fail. */
1228 gchar* servername_incoming = NULL;
1229 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1230 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1231 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1233 /* Get details from the specified presets: */
1234 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1235 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1239 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1240 TRUE /* incoming */);
1242 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1243 TRUE /* incoming */);
1246 /* We don't check for SMTP here as that is impossible for an incoming server. */
1247 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1248 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1249 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1250 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1252 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1253 TRUE /* incoming */);
1256 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1257 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1259 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1260 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1263 /* Use custom pages because no preset was specified: */
1264 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1266 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1267 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1269 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1270 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1272 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1273 ? MODEST_PROTOCOL_AUTH_PASSWORD
1274 : MODEST_PROTOCOL_AUTH_NONE;
1278 /* First we add the 2 server accounts, and then we add the account that uses them.
1279 * If we don't do it in this order then we will experience a crash. */
1281 /* Add a (incoming) server account, to be used by the account: */
1282 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1283 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1284 store_name_start, TRUE /* server account */);
1285 g_free (store_name_start);
1286 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1288 servername_incoming,
1291 protocol_security_incoming,
1292 protocol_authentication_incoming);
1294 g_free (servername_incoming);
1297 /* TODO: Provide a Logical ID for the text: */
1298 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1303 /* There must be at least one account now: */
1304 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1307 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1309 g_slist_free (account_names);
1312 /* Outgoing server: */
1313 gchar* servername_outgoing = NULL;
1314 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1315 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1316 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1320 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1321 FALSE /* incoming */);
1323 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1324 FALSE /* incoming */);
1326 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1327 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1328 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1329 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1331 ModestPresetsSecurity security_outgoing =
1332 modest_presets_get_info_server_security (priv->presets, provider_id,
1333 FALSE /* incoming */);
1335 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1336 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1337 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1339 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1340 /* TODO: There is no SMTP authentication enum for presets. */
1343 /* Use custom pages because no preset was specified: */
1344 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1346 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1348 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1349 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1351 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1352 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1355 /* Add a (outgoing) server account to be used by the account: */
1356 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1357 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1358 transport_name_start, TRUE /* server account */);
1359 g_free (transport_name_start);
1360 created = modest_account_mgr_add_server_account (self->account_manager,
1362 servername_outgoing,
1365 protocol_security_outgoing,
1366 protocol_authentication_outgoing);
1368 g_free (servername_outgoing);
1371 /* TODO: Provide a Logical ID for the text: */
1372 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1377 /* Create the account, which will contain the two "server accounts": */
1378 created = modest_account_mgr_add_account (self->account_manager, account_name,
1379 store_name, /* The name of our POP/IMAP server account. */
1380 transport_name /* The name of our SMTP server account. */);
1381 g_free (store_name);
1382 g_free (transport_name);
1385 /* TODO: Provide a Logical ID for the text: */
1386 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1390 /* The user name and email address must be set additionally: */
1391 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1392 modest_account_mgr_set_string (self->account_manager, account_name,
1393 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1395 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1396 modest_account_mgr_set_string (self->account_manager, account_name,
1397 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1399 /* Set the display name: */
1400 modest_account_mgr_set_string (self->account_manager, account_name,
1401 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1403 /* Save the connection-specific SMTP server accounts. */
1404 gboolean result = TRUE;
1405 if (self->specific_window)
1406 result = modest_connection_specific_smtp_window_save_server_accounts (
1407 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1409 g_free (self->saved_account_name);
1410 self->saved_account_name = g_strdup (account_name);
1412 g_free (account_name);