1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "modest-easysetup-wizard.h"
32 #include <glib/gi18n.h>
33 #include <gtk/gtknotebook.h>
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkcombobox.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkseparator.h>
42 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
43 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
44 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
45 #include "widgets/modest-serversecurity-combo-box.h"
46 #include "widgets/modest-secureauth-combo-box.h"
47 #include "widgets/modest-validating-entry.h"
48 #include "modest-text-utils.h"
49 #include "modest-account-mgr.h"
50 #include "modest-account-mgr-helpers.h"
51 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
52 #include "maemo/modest-connection-specific-smtp-window.h"
53 #include "widgets/modest-ui-constants.h"
54 #include "maemo/modest-account-settings-dialog.h"
55 #include <gconf/gconf-client.h>
56 #include <string.h> /* For strlen(). */
58 /* Include config.h so that _() works: */
63 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
65 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
67 #define WIZARD_DIALOG_GET_PRIVATE(o) \
68 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
70 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
72 struct _ModestEasysetupWizardDialogPrivate
74 ModestPresets *presets;
78 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
79 GValue *value, GParamSpec *pspec)
81 switch (property_id) {
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
88 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
89 const GValue *value, GParamSpec *pspec)
91 switch (property_id) {
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
98 modest_easysetup_wizard_dialog_dispose (GObject *object)
100 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
101 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
105 modest_easysetup_wizard_dialog_finalize (GObject *object)
107 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
108 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
110 if (self->account_manager)
111 g_object_unref (G_OBJECT (self->account_manager));
114 modest_presets_destroy (priv->presets);
116 if (self->specific_window)
117 gtk_widget_destroy (self->specific_window);
119 g_free (self->saved_account_name);
121 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
125 show_error (GtkWindow *parent_window, const gchar* text);
128 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
131 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
134 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
136 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
139 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
141 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
143 /* Call the vfunc, which may be overridden by derived classes: */
144 if (klass->enable_buttons) {
145 GtkNotebook *notebook = NULL;
146 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
148 const gint current_page_num = gtk_notebook_get_current_page (notebook);
149 if (current_page_num == -1)
152 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
153 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
158 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
160 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
162 invoke_enable_buttons_vfunc(self);
166 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
168 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
170 invoke_enable_buttons_vfunc(self);
173 /** This is a convenience function to create a caption containing a mandatory widget.
174 * When the widget is edited, the enable_buttons() vfunc will be called.
176 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
181 HildonCaptionStatus flag)
183 GtkWidget *caption = NULL;
185 /* Note: Previously, the translated strings already contained the "*",
186 * Comment out this code if they do again.
188 /* Add a * character to indicate mandatory fields,
189 * as specified in our "Email UI Specification": */
190 if (flag == HILDON_CAPTION_MANDATORY) {
191 gchar* title = g_strdup_printf("%s*", value);
192 caption = hildon_caption_new (group, title, control, icon, flag);
196 caption = hildon_caption_new (group, value, control, icon, flag);
198 /* Connect to the appropriate changed signal for the widget,
199 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
201 if (GTK_IS_ENTRY (control)) {
202 g_signal_connect (G_OBJECT (control), "changed",
203 G_CALLBACK (on_caption_entry_changed), self);
206 else if (GTK_IS_COMBO_BOX (control)) {
207 g_signal_connect (G_OBJECT (control), "changed",
208 G_CALLBACK (on_caption_combobox_changed), self);
215 create_page_welcome (ModestEasysetupWizardDialog *self)
217 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
218 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
219 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
220 /* So that it is not truncated: */
221 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
222 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
223 gtk_widget_show (label);
224 gtk_widget_show (GTK_WIDGET (box));
225 return GTK_WIDGET (box);
229 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
231 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
233 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
235 /* Fill the providers combo, based on the selected country: */
236 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
237 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
238 easysetup_provider_combo_box_fill (
239 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
243 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
245 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
247 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
249 /* Fill the providers combo, based on the selected country: */
250 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
251 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
253 gchar* domain_name = NULL;
255 domain_name = modest_presets_get_domain (priv->presets, provider_id);
258 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
260 if (self->entry_user_email)
261 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
263 g_free (domain_name);
265 g_free (provider_id);
269 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
271 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
272 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
276 create_page_account_details (ModestEasysetupWizardDialog *self)
278 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
279 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
280 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
281 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
282 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
283 gtk_widget_show (label);
285 /* Create a size group to be used by all captions.
286 * Note that HildonCaption does not create a default size group if we do not specify one.
287 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
288 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
290 /* The country widgets: */
291 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
292 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
293 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
294 gtk_widget_show (self->combo_account_country);
295 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
296 gtk_widget_show (caption);
298 /* connect to country combo's changed signal, so we can fill the provider combo: */
299 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
300 G_CALLBACK (on_combo_account_country), self);
302 GtkWidget *separator = gtk_hseparator_new ();
303 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
304 gtk_widget_show (separator);
306 /* The service provider widgets: */
307 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
309 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
310 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
311 gtk_widget_show (self->combo_account_serviceprovider);
312 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
313 gtk_widget_show (caption);
315 /* connect to providers combo's changed signal, so we can fill the email address: */
316 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
317 G_CALLBACK (on_combo_account_serviceprovider), self);
319 /* TODO: Default to the current country somehow.
320 * But I don't know how to get the information that is specified in the
321 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
323 * This is probably not the best choice of gconf key:
324 * This is the "mcc used in the last pairing", ie. the last connection you made.
325 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
328 GConfClient *client = gconf_client_get_default ();
329 GError *error = NULL;
330 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
331 gint mcc_id = gconf_client_get_int(client, key, &error);
337 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
338 g_error_free (error);
344 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
345 * This might just be a Maemo bug.
349 /* For now, we default to Finland when there is nothing better: */
353 easysetup_country_combo_box_set_active_country_id (
354 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
357 /* The description widgets: */
358 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
359 /* Do use auto-capitalization: */
360 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
361 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
363 /* Set a default account title, choosing one that does not already exist: */
364 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
365 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
366 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
367 self->account_manager, default_account_name_start);
368 g_free (default_account_name_start);
369 default_account_name_start = NULL;
371 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
372 g_free (default_account_name);
373 default_account_name = NULL;
375 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
376 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
377 gtk_widget_show (self->entry_account_title);
378 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
379 gtk_widget_show (caption);
381 /* Prevent the use of some characters in the account title,
382 * as required by our UI specification: */
383 GList *list_prevent = NULL;
384 list_prevent = g_list_append (list_prevent, "\\");
385 list_prevent = g_list_append (list_prevent, "/");
386 list_prevent = g_list_append (list_prevent, ":");
387 list_prevent = g_list_append (list_prevent, "*");
388 list_prevent = g_list_append (list_prevent, "?");
389 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
390 list_prevent = g_list_append (list_prevent, "“");
391 list_prevent = g_list_append (list_prevent, "<");
392 list_prevent = g_list_append (list_prevent, ">");
393 list_prevent = g_list_append (list_prevent, "|");
394 list_prevent = g_list_append (list_prevent, "^");
395 modest_validating_entry_set_unallowed_characters (
396 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
397 g_list_free (list_prevent);
399 /* Set max length as in the UI spec:
400 * The UI spec seems to want us to show a dialog if we hit the maximum. */
401 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
402 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
405 gtk_widget_show (GTK_WIDGET (box));
407 return GTK_WIDGET (box);
411 create_page_user_details (ModestEasysetupWizardDialog *self)
413 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
415 /* Create a size group to be used by all captions.
416 * Note that HildonCaption does not create a default size group if we do not specify one.
417 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
418 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
420 /* The name widgets: */
421 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
422 /* Auto-capitalization is the default, so let's turn it off: */
423 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
424 /* Set max length as in the UI spec:
425 * The UI spec seems to want us to show a dialog if we hit the maximum. */
426 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
427 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
429 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
430 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
431 gtk_widget_show (self->entry_user_name);
432 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
433 gtk_widget_show (caption);
435 /* Prevent the use of some characters in the name,
436 * as required by our UI specification: */
437 GList *list_prevent = NULL;
438 list_prevent = g_list_append (list_prevent, "<");
439 list_prevent = g_list_append (list_prevent, ">");
440 modest_validating_entry_set_unallowed_characters (
441 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
442 g_list_free (list_prevent);
444 /* The username widgets: */
445 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
446 /* Auto-capitalization is the default, so let's turn it off: */
447 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
448 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
449 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
450 gtk_widget_show (self->entry_user_username);
451 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
452 gtk_widget_show (caption);
454 /* Prevent the use of some characters in the username,
455 * as required by our UI specification: */
456 modest_validating_entry_set_unallowed_characters_whitespace (
457 MODEST_VALIDATING_ENTRY (self->entry_user_username));
459 /* Set max length as in the UI spec:
460 * The UI spec seems to want us to show a dialog if we hit the maximum. */
461 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
462 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
465 /* The password widgets: */
466 self->entry_user_password = gtk_entry_new ();
467 /* Auto-capitalization is the default, so let's turn it off: */
468 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
469 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
470 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
471 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
472 caption = create_caption_new_with_asterisk (self, sizegroup,
473 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
474 gtk_widget_show (self->entry_user_password);
475 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
476 gtk_widget_show (caption);
478 /* The email address widgets: */
479 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
480 /* Auto-capitalization is the default, so let's turn it off: */
481 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
482 caption = create_caption_new_with_asterisk (self, sizegroup,
483 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
484 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
485 gtk_widget_show (self->entry_user_email);
486 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
487 gtk_widget_show (caption);
489 /* Set max length as in the UI spec:
490 * The UI spec seems to want us to show a dialog if we hit the maximum. */
491 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
492 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
496 gtk_widget_show (GTK_WIDGET (box));
498 return GTK_WIDGET (box);
501 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
503 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
505 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
506 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
507 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
508 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
509 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
510 gtk_widget_show (label);
512 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
513 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
514 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
515 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
516 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
517 gtk_widget_show (label);
519 gtk_widget_show (GTK_WIDGET (box));
520 return GTK_WIDGET (box);
523 /** Change the caption title for the incoming server,
524 * as specified in the UI spec:
526 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
528 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
529 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
531 (protocol == MODEST_PROTOCOL_STORE_POP ?
532 _("mail_fi_emailtype_pop3") :
533 _("mail_fi_emailtype_imap") );
536 /* Note that this produces a compiler warning,
537 * because the compiler does not know that the translated string will have a %s in it.
538 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
539 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
540 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
541 g_free(incomingserver_title);
544 /** Change the caption title for the incoming server,
545 * as specified in the UI spec:
547 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
549 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
550 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
552 /* Fill the combo with appropriately titled choices for POP or IMAP. */
553 /* The choices are the same, but the titles are different, as in the UI spec. */
554 modest_serversecurity_combo_box_fill (
555 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
558 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
560 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
561 update_incoming_server_title (self);
562 update_incoming_server_security_choices (self);
565 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
567 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
569 /* Show note that account type cannot be changed in future: */
570 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
571 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
572 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
573 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
574 gtk_widget_show (label);
576 /* Create a size group to be used by all captions.
577 * Note that HildonCaption does not create a default size group if we do not specify one.
578 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
579 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
581 /* The incoming server widgets: */
582 if (!self->combo_incoming_servertype)
583 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
584 easysetup_servertype_combo_box_set_active_servertype (
585 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
586 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
587 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
588 gtk_widget_show (self->combo_incoming_servertype);
589 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
590 gtk_widget_show (caption);
592 if(!self->entry_incomingserver)
593 self->entry_incomingserver = gtk_entry_new ();
594 /* Auto-capitalization is the default, so let's turn it off: */
595 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
596 set_default_custom_servernames (self);
598 if (self->caption_incoming)
599 gtk_widget_destroy (self->caption_incoming);
601 /* The caption title will be updated in update_incoming_server_title().
602 * so this default text will never be seen: */
603 /* (Note: Changing the title seems pointless. murrayc) */
604 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
605 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
606 update_incoming_server_title (self);
607 gtk_widget_show (self->entry_incomingserver);
608 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
609 gtk_widget_show (self->caption_incoming);
611 /* Change the caption title when the servertype changes,
612 * as in the UI spec: */
613 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
614 G_CALLBACK (on_combo_servertype_changed), self);
616 /* The secure connection widgets: */
617 if (!self->combo_incoming_security)
618 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
619 update_incoming_server_security_choices (self);
620 modest_serversecurity_combo_box_set_active_serversecurity (
621 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
622 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
623 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
624 gtk_widget_show (self->combo_incoming_security);
625 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
626 gtk_widget_show (caption);
628 if(!self->checkbox_incoming_auth)
629 self->checkbox_incoming_auth = gtk_check_button_new ();
630 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
631 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
632 gtk_widget_show (self->checkbox_incoming_auth);
633 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
634 gtk_widget_show (caption);
636 gtk_widget_show (GTK_WIDGET (box));
638 return GTK_WIDGET (box);
642 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
644 GtkWidget *widget = GTK_WIDGET (user_data);
646 /* Enable the widget only if the toggle button is active: */
647 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
648 gtk_widget_set_sensitive (widget, enable);
651 /* Make the sensitivity of a widget depend on a toggle button.
654 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
656 g_signal_connect (G_OBJECT (button), "toggled",
657 G_CALLBACK (on_toggle_button_changed), widget);
659 /* Set the starting sensitivity: */
660 on_toggle_button_changed (button, widget);
664 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
666 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
668 /* Create the window, if necessary: */
669 if (!(self->specific_window)) {
670 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
671 modest_connection_specific_smtp_window_fill_with_connections (
672 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
673 NULL /* account_name, not known yet. */);
676 /* Show the window: */
677 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
678 gtk_widget_show (self->specific_window);
681 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
683 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
685 /* Create a size group to be used by all captions.
686 * Note that HildonCaption does not create a default size group if we do not specify one.
687 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
688 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
690 /* The outgoing server widgets: */
691 if (!self->entry_outgoingserver)
692 self->entry_outgoingserver = gtk_entry_new ();
693 /* Auto-capitalization is the default, so let's turn it off: */
694 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
695 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
696 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
697 gtk_widget_show (self->entry_outgoingserver);
698 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
699 gtk_widget_show (caption);
700 set_default_custom_servernames (self);
702 /* The secure connection widgets: */
703 if (!self->combo_outgoing_security)
704 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
705 modest_serversecurity_combo_box_fill (
706 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
707 modest_serversecurity_combo_box_set_active_serversecurity (
708 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
709 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
710 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
711 gtk_widget_show (self->combo_outgoing_security);
712 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
713 gtk_widget_show (caption);
715 /* The secure authentication widgets: */
716 if (!self->combo_outgoing_auth)
717 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
718 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
719 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
720 gtk_widget_show (self->combo_outgoing_auth);
721 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
722 gtk_widget_show (caption);
724 GtkWidget *separator = gtk_hseparator_new ();
725 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
726 gtk_widget_show (separator);
728 /* connection-specific checkbox: */
729 if (!self->checkbox_outgoing_smtp_specific) {
730 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
731 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
734 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
735 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
736 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
737 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
738 gtk_widget_show (caption);
740 /* Connection-specific SMTP-Severs Edit button: */
741 if (!self->button_outgoing_smtp_servers)
742 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
743 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
744 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
745 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
746 gtk_widget_show (self->button_outgoing_smtp_servers);
747 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
748 gtk_widget_show (caption);
750 /* Only enable the button when the checkbox is checked: */
751 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
752 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
754 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
755 G_CALLBACK (on_button_outgoing_smtp_servers), self);
758 gtk_widget_show (GTK_WIDGET (box));
760 return GTK_WIDGET (box);
764 on_timeout_show_advanced_edit(gpointer user_data)
766 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
768 if (!(self->saved_account_name))
771 /* Show the Account Settings window: */
772 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
773 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
775 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
777 gtk_dialog_run (GTK_DIALOG (dialog));
779 /* TODO: The hide() is not necessary.
780 * It is just here to show that it doesn't work,
781 * just as destroy doesn't work.
783 gtk_widget_hide (GTK_WIDGET(dialog));
785 /* TODO: The dialog remains on screen, not allowing any interaction.
786 * But gtk_widget_destroy() should always destroy.
788 printf("debug: destroying settings dialog\n");
789 gtk_widget_destroy (GTK_WIDGET (dialog));
790 printf("debug: after destroying settings dialog (doesn't seem to work).\n");
792 return FALSE; /* Do not call this timeout callback again. */
796 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
798 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
800 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
801 * without recoding it to use non-gconf information.
802 * This account will be deleted if Finish is never actually clicked. */
804 gboolean saved = TRUE;
805 gboolean was_already_saved = TRUE;
806 if (!(self->saved_account_name)) {
807 saved = create_account (self, FALSE);
808 was_already_saved = FALSE;
814 if (!(self->saved_account_name))
817 /* Show the Account Settings window: */
818 if (was_already_saved) {
819 /* Just show the dialog immediately: */
820 on_timeout_show_advanced_edit(self);
824 printf ("debug: waiting for gconf to update its local cache. "
825 "This is a hack to work around a maemo gconf bug in maemo bora.\n");
827 g_timeout_add (5000, on_timeout_show_advanced_edit, self);
830 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
832 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
833 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
834 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
835 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
836 gtk_widget_show (label);
838 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
839 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
840 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
841 gtk_widget_show (label);
843 if (!self->button_edit)
844 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
845 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
846 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
847 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
848 gtk_widget_show (self->button_edit);
849 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
850 gtk_widget_show (caption);
852 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
853 G_CALLBACK (on_button_edit_advanced_settings), self);
855 gtk_widget_show (GTK_WIDGET (box));
856 return GTK_WIDGET (box);
863 on_response (ModestWizardDialog *wizard_dialog,
867 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
869 if (response_id == GTK_RESPONSE_CANCEL) {
870 /* Remove any temporarily-saved account that will not actually be needed: */
871 if (self->saved_account_name) {
872 modest_account_mgr_remove_account (self->account_manager,
873 self->saved_account_name, FALSE);
877 invoke_enable_buttons_vfunc (self);
881 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
883 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
885 /* Create the notebook to be used by the ModestWizardDialog base class:
886 * Each page of the notebook will be a page of the wizard: */
887 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
889 /* Set the notebook used by the ModestWizardDialog base class: */
890 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
892 /* Set the wizard title:
893 * The actual window title will be a combination of this and the page's tab label title. */
894 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
896 /* Read in the information about known service providers: */
897 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
899 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
900 priv->presets = modest_presets_new (filepath);
901 if (!(priv->presets)) {
902 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
905 g_assert(priv->presets);
908 /* Get the account manager object,
909 * so we can check for existing accounts,
910 * and create new accounts: */
911 self->account_manager = modest_runtime_get_account_mgr ();
912 g_assert (self->account_manager);
913 g_object_ref (self->account_manager);
915 /* Create the common pages,
917 self->page_welcome = create_page_welcome (self);
918 self->page_account_details = create_page_account_details (self);
919 self->page_user_details = create_page_user_details (self);
921 /* Add the common pages: */
922 gtk_notebook_append_page (notebook, self->page_welcome,
923 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
924 gtk_notebook_append_page (notebook, self->page_account_details,
925 gtk_label_new (_("mcen_ti_accountdetails")));
926 gtk_notebook_append_page (notebook, self->page_user_details,
927 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
929 /* Create and add the easysetup-specific pages,
930 * because we need _some_ final page to enable the Next and Finish buttons: */
931 create_subsequent_easysetup_pages (self);
933 /* Connect to the dialog's response signal so we can enable/disable buttons
934 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
935 * Note that we use g_signal_connect_after() instead of g_signal_connect()
936 * so that we can be enable/disable after ModestWizardDialog has done its own
937 * enabling/disabling of buttons.
939 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
940 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
942 * It's not enough to connect to the notebook's switch-page signal, because
943 * ModestWizardDialog's "response" signal handler enables the buttons itself,
944 * _after_ switching the page (understandably).
945 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
946 * then gtk_notebook_get_current_page() would return an incorrect value.)
948 g_signal_connect_after (G_OBJECT (self), "response",
949 G_CALLBACK (on_response), self);
951 /* When this window is shown, hibernation should not be possible,
952 * because there is no sensible way to save the state: */
953 modest_window_mgr_prevent_hibernation_while_window_is_shown (
954 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
957 ModestEasysetupWizardDialog*
958 modest_easysetup_wizard_dialog_new (void)
960 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
963 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
965 GtkNotebook *notebook = NULL;
966 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
969 /* Create the custom pages: */
970 if(!(self->page_custom_incoming)) {
971 self->page_custom_incoming = create_page_custom_incoming (self);
974 if(!(self->page_custom_outgoing)) {
975 self->page_custom_outgoing = create_page_custom_outgoing (self);
978 if(!(self->page_complete_customsetup)) {
979 self->page_complete_customsetup = create_page_complete_custom (self);
982 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
983 gtk_notebook_append_page (notebook, self->page_custom_incoming,
984 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
986 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
987 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
988 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
990 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
991 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
992 gtk_label_new (_("mcen_ti_emailsetup_complete")));
994 /* This is unnecessary with GTK+ 2.10: */
995 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
998 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1000 GtkNotebook *notebook = NULL;
1001 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1004 /* Create the easysetup-specific pages: */
1005 if(!self->page_complete_easysetup)
1006 self->page_complete_easysetup = create_page_complete_easysetup (self);
1008 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1009 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1010 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1012 /* This is unnecessary with GTK+ 2.10: */
1013 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1015 /* After the user details page,
1016 * the following pages depend on whether "Other" was chosen
1017 * in the provider combobox on the account page
1019 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1021 if (easysetup_provider_combo_box_get_active_provider_id (
1022 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1023 /* "Other..." was selected: */
1025 /* Make sure that the easysetup pages do not exist: */
1026 if(self->page_complete_easysetup) {
1027 gtk_widget_destroy (self->page_complete_easysetup);
1028 self->page_complete_easysetup = NULL;
1031 create_subsequent_customsetup_pages (self);
1034 /* A specific provider was selected: */
1036 /* Make sure that the custom pages do not exist:
1037 * Because they will be used if they exist, when creating the account. */
1038 if(self->page_custom_incoming) {
1039 gtk_widget_destroy (self->page_custom_incoming);
1040 self->page_custom_incoming = NULL;
1043 if(self->page_custom_outgoing) {
1044 gtk_widget_destroy (self->page_custom_outgoing);
1045 self->page_custom_outgoing = NULL;
1048 if(self->page_complete_customsetup) {
1049 gtk_widget_destroy (self->page_complete_customsetup);
1050 self->page_complete_customsetup = NULL;
1054 /* Create the easysetup pages: */
1055 create_subsequent_easysetup_pages (self);
1061 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1066 gchar* at = g_utf8_strchr (email_address, -1, '@');
1067 if (!at || (g_utf8_strlen (at, -1) < 2))
1070 gchar* domain = g_utf8_next_char (at);
1074 const gchar* hostname = NULL;
1075 if (servertype == MODEST_PROTOCOL_STORE_POP)
1077 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1079 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1085 return g_strdup_printf ("%s.%s", hostname, domain);
1088 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1090 if (!account_wizard->entry_incomingserver)
1093 /* Set a default domain for the server, based on the email address,
1094 * if no server name was already specified.
1096 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
1097 if ((!incoming_existing || (strlen(incoming_existing) == 0))
1098 && account_wizard->entry_user_email) {
1099 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1100 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1101 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1103 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1104 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1105 g_free (servername);
1108 /* Set a default domain for the server, based on the email address,
1109 * if no server name was already specified.
1111 if (!account_wizard->entry_outgoingserver)
1114 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
1115 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
1116 && account_wizard->entry_user_email) {
1117 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1119 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1120 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1121 g_free (servername);
1126 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1128 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1130 /* Do extra validation that couldn't be done for every key press,
1131 * either because it was too slow,
1132 * or because it requires interaction:
1134 if (current_page == account_wizard->page_account_details) {
1135 /* Check that the title is not already in use: */
1136 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1137 if ((!account_title) || (strlen(account_title) == 0))
1140 /* Aavoid a clash with an existing display name: */
1141 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1142 account_wizard->account_manager, account_title);
1145 /* Warn the user via a dialog: */
1146 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1151 else if (current_page == account_wizard->page_user_details) {
1152 /* Check that the email address is valud: */
1153 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1154 if ((!email_address) || (strlen(email_address) == 0))
1157 if (!modest_text_utils_validate_email_address (email_address)) {
1158 /* Warn the user via a dialog: */
1159 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1161 /* Return focus to the email address entry: */
1162 gtk_widget_grab_focus (account_wizard->entry_user_email);
1167 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1168 create_subsequent_pages (account_wizard);
1171 /* TODO: The UI Spec wants us to check that the servernames are valid,
1172 * but does not specify how.
1175 if(next_page == account_wizard->page_custom_incoming) {
1176 set_default_custom_servernames (account_wizard);
1178 else if (next_page == account_wizard->page_custom_outgoing) {
1179 set_default_custom_servernames (account_wizard);
1182 /* If this is the last page, and this is a click on Finish,
1183 * then attempt to create the dialog.
1185 if(!next_page) /* This is NULL when this is a click on Finish. */
1187 if (account_wizard->saved_account_name) {
1188 /* Just enable the already-saved account (temporarily created when
1189 * editing advanced settings): */
1190 modest_account_mgr_set_enabled (account_wizard->account_manager,
1191 account_wizard->saved_account_name, TRUE);
1193 create_account (account_wizard, TRUE /* enabled */);
1201 static gboolean entry_is_empty (GtkWidget *entry)
1206 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1207 if ((!text) || (strlen(text) == 0))
1214 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1216 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1218 gboolean enable_next = TRUE;
1219 if (current_page == account_wizard->page_welcome) {
1222 else if (current_page == account_wizard->page_account_details) {
1223 /* The account details title is mandatory: */
1224 if (entry_is_empty(account_wizard->entry_account_title))
1225 enable_next = FALSE;
1227 else if (current_page == account_wizard->page_user_details) {
1228 /* The user details username is mandatory: */
1229 if (entry_is_empty(account_wizard->entry_user_username))
1230 enable_next = FALSE;
1232 /* The user details email address is mandatory: */
1233 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1234 enable_next = FALSE;
1236 else if (current_page == account_wizard->page_custom_incoming) {
1237 /* The custom incoming server is mandatory: */
1238 if (entry_is_empty(account_wizard->entry_incomingserver))
1239 enable_next = FALSE;
1242 /* Enable the buttons,
1243 * identifying them via their associated response codes: */
1245 /* Disable the Finish button until we are on the last page,
1246 * because HildonWizardDialog enables this for all but the first page: */
1247 GtkNotebook *notebook = NULL;
1248 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1249 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1251 gint current = gtk_notebook_get_current_page (notebook);
1252 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1253 const gboolean is_last = (current == last);
1256 gtk_dialog_set_response_sensitive (dialog_base,
1257 MODEST_WIZARD_DIALOG_FINISH,
1261 /* Disable Next on the last page: */
1262 enable_next = FALSE;
1265 gtk_dialog_set_response_sensitive (dialog_base,
1266 MODEST_WIZARD_DIALOG_NEXT,
1271 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1273 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1274 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1277 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1278 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1279 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1280 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1282 /* Provide a vfunc implementation so we can decide
1283 * when to enable/disable the prev/next buttons.
1285 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1286 base_klass->before_next = on_before_next;
1287 base_klass->enable_buttons = on_enable_buttons;
1291 show_error (GtkWindow *parent_window, const gchar* text)
1293 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1295 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1302 gtk_dialog_run (dialog);
1303 gtk_widget_destroy (GTK_WIDGET (dialog));
1306 /** Attempt to create the account from the information that the user has entered.
1307 * @result: TRUE if the account was successfully created.
1310 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1312 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1314 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1320 /* We should have checked for this already,
1321 * and changed that name accordingly,
1322 * but let's check again just in case:
1324 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1327 /* Increment the non-user visible name if necessary,
1328 * based on the display name: */
1329 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1330 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1331 account_name_start, FALSE /* not a server account */);
1332 g_free (account_name_start);
1334 /* username and password (for both incoming and outgoing): */
1335 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1336 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1338 /* Incoming server: */
1339 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1340 * or modest_account_mgr_add_server_account will fail. */
1341 gchar* servername_incoming = NULL;
1342 guint serverport_incoming = 0;
1343 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1344 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1345 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1347 /* Get details from the specified presets: */
1348 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1349 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1352 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1353 TRUE /* incoming */);
1355 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1357 TRUE /* incoming */);
1358 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1360 TRUE /* incoming */);
1362 g_warning ("security incoming: %x", security_incoming);
1364 /* We don't check for SMTP here as that is impossible for an incoming server. */
1365 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1366 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1367 serverport_incoming =
1368 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
1369 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1370 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1371 serverport_incoming =
1372 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
1375 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1376 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1378 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1379 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1382 /* Use custom pages because no preset was specified: */
1383 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1385 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1386 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1388 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1389 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1391 /* The UI spec says:
1392 * If secure authentication is unchecked, allow sending username and password also as plain text.
1393 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1394 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1396 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1397 ? MODEST_PROTOCOL_AUTH_CRAMMD5
1398 : MODEST_PROTOCOL_AUTH_PASSWORD;
1401 /* First we add the 2 server accounts, and then we add the account that uses them.
1402 * If we don't do it in this order then we will experience a crash. */
1404 /* Add a (incoming) server account, to be used by the account: */
1405 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1406 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1407 store_name_start, TRUE /* server account */);
1408 g_free (store_name_start);
1409 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1411 servername_incoming,
1412 serverport_incoming,
1415 protocol_security_incoming,
1416 protocol_authentication_incoming);
1418 g_free (servername_incoming);
1421 /* TODO: Provide a Logical ID for the text: */
1422 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1427 /* There must be at least one account now: */
1428 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1429 * fixed in versions after 3.1. */
1430 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1433 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1435 g_slist_free (account_names);
1438 /* Outgoing server: */
1439 gchar* servername_outgoing = NULL;
1440 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1441 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1442 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1443 guint serverport_outgoing = 0;
1447 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1448 FALSE /* incoming */);
1450 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1452 FALSE /* incoming */);
1454 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1455 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1456 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1457 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1459 ModestPresetsSecurity security_outgoing =
1460 modest_presets_get_info_server_security (priv->presets, provider_id,
1461 FALSE /* incoming */);
1463 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1464 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1465 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1466 serverport_outgoing = 465;
1467 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1469 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1470 /* TODO: There is no SMTP authentication enum for presets. */
1473 /* Use custom pages because no preset was specified: */
1474 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1476 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1478 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1479 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1481 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1482 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1485 /* Add a (outgoing) server account to be used by the account: */
1486 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1487 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1488 transport_name_start, TRUE /* server account */);
1489 g_free (transport_name_start);
1490 created = modest_account_mgr_add_server_account (self->account_manager,
1492 servername_outgoing,
1493 serverport_outgoing,
1496 protocol_security_outgoing,
1497 protocol_authentication_outgoing);
1499 g_free (servername_outgoing);
1502 /* TODO: Provide a Logical ID for the text: */
1503 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1508 /* Create the account, which will contain the two "server accounts": */
1509 created = modest_account_mgr_add_account (self->account_manager, account_name,
1510 store_name, /* The name of our POP/IMAP server account. */
1511 transport_name, /* The name of our SMTP server account. */
1513 g_free (store_name);
1514 g_free (transport_name);
1517 /* TODO: Provide a Logical ID for the text: */
1518 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1522 /* The user name and email address must be set additionally: */
1523 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1524 modest_account_mgr_set_string (self->account_manager, account_name,
1525 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1527 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1528 modest_account_mgr_set_string (self->account_manager, account_name,
1529 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1531 /* Set the display name: */
1532 modest_account_mgr_set_string (self->account_manager, account_name,
1533 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1535 /* Set retrieve type */
1536 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1537 modest_account_mgr_set_string (self->account_manager, account_name,
1538 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1540 /* Save the connection-specific SMTP server accounts. */
1541 gboolean result = TRUE;
1542 if (self->specific_window)
1543 result = modest_connection_specific_smtp_window_save_server_accounts (
1544 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1546 g_free (self->saved_account_name);
1547 self->saved_account_name = g_strdup (account_name);
1549 g_free (account_name);