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 "maemo/modest-maemo-utils.h"
56 #include <gconf/gconf-client.h>
57 #include <string.h> /* For strlen(). */
59 /* Include config.h so that _() works: */
64 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
66 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
68 #define WIZARD_DIALOG_GET_PRIVATE(o) \
69 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
71 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
74 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
75 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
76 } ModestEasysetupWizardDialogServerChanges;
78 struct _ModestEasysetupWizardDialogPrivate
80 ModestPresets *presets;
82 /* Remember what fields the user edited manually to not prefill them
84 ModestEasysetupWizardDialogServerChanges server_changes;
88 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
89 GValue *value, GParamSpec *pspec)
91 switch (property_id) {
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
98 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
99 const GValue *value, GParamSpec *pspec)
101 switch (property_id) {
103 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
108 modest_easysetup_wizard_dialog_dispose (GObject *object)
110 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
111 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
115 modest_easysetup_wizard_dialog_finalize (GObject *object)
117 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
118 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
120 if (self->account_manager)
121 g_object_unref (G_OBJECT (self->account_manager));
124 modest_presets_destroy (priv->presets);
126 if (self->specific_window)
127 gtk_widget_destroy (self->specific_window);
129 g_free (self->saved_account_name);
131 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
135 show_error (GtkWindow *parent_window, const gchar* text);
138 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
141 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
144 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
146 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
149 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
151 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
153 /* Call the vfunc, which may be overridden by derived classes: */
154 if (klass->enable_buttons) {
155 GtkNotebook *notebook = NULL;
156 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
158 const gint current_page_num = gtk_notebook_get_current_page (notebook);
159 if (current_page_num == -1)
162 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
163 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
168 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
170 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
172 invoke_enable_buttons_vfunc(self);
176 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
178 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
180 invoke_enable_buttons_vfunc(self);
183 /** This is a convenience function to create a caption containing a mandatory widget.
184 * When the widget is edited, the enable_buttons() vfunc will be called.
186 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
191 HildonCaptionStatus flag)
193 GtkWidget *caption = NULL;
195 /* Note: Previously, the translated strings already contained the "*",
196 * Comment out this code if they do again.
198 /* Add a * character to indicate mandatory fields,
199 * as specified in our "Email UI Specification": */
200 if (flag == HILDON_CAPTION_MANDATORY) {
201 gchar* title = g_strdup_printf("%s*", value);
202 caption = hildon_caption_new (group, title, control, icon, flag);
206 caption = hildon_caption_new (group, value, control, icon, flag);
208 /* Connect to the appropriate changed signal for the widget,
209 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
211 if (GTK_IS_ENTRY (control)) {
212 g_signal_connect (G_OBJECT (control), "changed",
213 G_CALLBACK (on_caption_entry_changed), self);
216 else if (GTK_IS_COMBO_BOX (control)) {
217 g_signal_connect (G_OBJECT (control), "changed",
218 G_CALLBACK (on_caption_combobox_changed), self);
225 create_page_welcome (ModestEasysetupWizardDialog *self)
227 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
228 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
229 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
230 /* So that it is not truncated: */
231 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
232 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
233 gtk_widget_show (label);
234 gtk_widget_show (GTK_WIDGET (box));
235 return GTK_WIDGET (box);
239 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
241 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
243 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
245 /* Fill the providers combo, based on the selected country: */
246 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
247 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
248 easysetup_provider_combo_box_fill (
249 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
253 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
255 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
257 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
259 /* Fill the providers combo, based on the selected country: */
260 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
261 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
263 gchar* domain_name = NULL;
265 domain_name = modest_presets_get_domain (priv->presets, provider_id);
268 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
270 if (self->entry_user_email)
271 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
273 g_free (domain_name);
275 g_free (provider_id);
279 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
281 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
282 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
286 create_page_account_details (ModestEasysetupWizardDialog *self)
288 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
289 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
290 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
291 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
292 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
293 gtk_widget_show (label);
295 /* Create a size group to be used by all captions.
296 * Note that HildonCaption does not create a default size group if we do not specify one.
297 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
298 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
300 /* The country widgets: */
301 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
302 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
303 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
304 gtk_widget_show (self->combo_account_country);
305 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
306 gtk_widget_show (caption);
308 /* connect to country combo's changed signal, so we can fill the provider combo: */
309 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
310 G_CALLBACK (on_combo_account_country), self);
312 GtkWidget *separator = gtk_hseparator_new ();
313 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
314 gtk_widget_show (separator);
316 /* The service provider widgets: */
317 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
319 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
320 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
321 gtk_widget_show (self->combo_account_serviceprovider);
322 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
323 gtk_widget_show (caption);
325 /* connect to providers combo's changed signal, so we can fill the email address: */
326 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
327 G_CALLBACK (on_combo_account_serviceprovider), self);
329 /* TODO: Default to the current country somehow.
330 * But I don't know how to get the information that is specified in the
331 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
333 * This is probably not the best choice of gconf key:
334 * This is the "mcc used in the last pairing", ie. the last connection you made.
335 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
338 GConfClient *client = gconf_client_get_default ();
339 GError *error = NULL;
340 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
341 gint mcc_id = gconf_client_get_int(client, key, &error);
347 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
348 g_error_free (error);
354 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
355 * This might just be a Maemo bug.
359 /* For now, we default to Finland when there is nothing better: */
363 easysetup_country_combo_box_set_active_country_id (
364 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
367 /* The description widgets: */
368 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
369 /* Do use auto-capitalization: */
370 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
371 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
373 /* Set a default account title, choosing one that does not already exist: */
374 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
375 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
376 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
377 self->account_manager, default_account_name_start);
378 g_free (default_account_name_start);
379 default_account_name_start = NULL;
381 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
382 g_free (default_account_name);
383 default_account_name = NULL;
385 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
386 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
387 gtk_widget_show (self->entry_account_title);
388 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
389 gtk_widget_show (caption);
391 /* Prevent the use of some characters in the account title,
392 * as required by our UI specification: */
393 GList *list_prevent = NULL;
394 list_prevent = g_list_append (list_prevent, "\\");
395 list_prevent = g_list_append (list_prevent, "/");
396 list_prevent = g_list_append (list_prevent, ":");
397 list_prevent = g_list_append (list_prevent, "*");
398 list_prevent = g_list_append (list_prevent, "?");
399 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
400 list_prevent = g_list_append (list_prevent, "“");
401 list_prevent = g_list_append (list_prevent, "<");
402 list_prevent = g_list_append (list_prevent, ">");
403 list_prevent = g_list_append (list_prevent, "|");
404 list_prevent = g_list_append (list_prevent, "^");
405 modest_validating_entry_set_unallowed_characters (
406 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
407 g_list_free (list_prevent);
409 /* Set max length as in the UI spec:
410 * The UI spec seems to want us to show a dialog if we hit the maximum. */
411 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
412 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
415 gtk_widget_show (GTK_WIDGET (box));
417 return GTK_WIDGET (box);
421 create_page_user_details (ModestEasysetupWizardDialog *self)
423 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
425 /* Create a size group to be used by all captions.
426 * Note that HildonCaption does not create a default size group if we do not specify one.
427 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
428 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
430 /* The name widgets: */
431 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
432 /* Auto-capitalization is the default, so let's turn it off: */
433 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
434 /* Set max length as in the UI spec:
435 * The UI spec seems to want us to show a dialog if we hit the maximum. */
436 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
437 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
439 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
440 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
441 gtk_widget_show (self->entry_user_name);
442 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
443 gtk_widget_show (caption);
445 /* Prevent the use of some characters in the name,
446 * as required by our UI specification: */
447 GList *list_prevent = NULL;
448 list_prevent = g_list_append (list_prevent, "<");
449 list_prevent = g_list_append (list_prevent, ">");
450 modest_validating_entry_set_unallowed_characters (
451 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
452 g_list_free (list_prevent);
454 /* The username widgets: */
455 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
456 /* Auto-capitalization is the default, so let's turn it off: */
457 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
458 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
459 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
460 gtk_widget_show (self->entry_user_username);
461 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
462 gtk_widget_show (caption);
464 /* Prevent the use of some characters in the username,
465 * as required by our UI specification: */
466 modest_validating_entry_set_unallowed_characters_whitespace (
467 MODEST_VALIDATING_ENTRY (self->entry_user_username));
469 /* Set max length as in the UI spec:
470 * The UI spec seems to want us to show a dialog if we hit the maximum. */
471 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
472 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
475 /* The password widgets: */
476 self->entry_user_password = gtk_entry_new ();
477 /* Auto-capitalization is the default, so let's turn it off: */
478 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
479 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
480 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
481 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
482 caption = create_caption_new_with_asterisk (self, sizegroup,
483 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
484 gtk_widget_show (self->entry_user_password);
485 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
486 gtk_widget_show (caption);
488 /* The email address widgets: */
489 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
490 /* Auto-capitalization is the default, so let's turn it off: */
491 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
492 caption = create_caption_new_with_asterisk (self, sizegroup,
493 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
494 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
495 gtk_widget_show (self->entry_user_email);
496 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
497 gtk_widget_show (caption);
499 /* Set max length as in the UI spec:
500 * The UI spec seems to want us to show a dialog if we hit the maximum. */
501 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
502 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
506 gtk_widget_show (GTK_WIDGET (box));
508 return GTK_WIDGET (box);
511 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
513 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
515 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
516 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
517 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
518 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
519 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
520 gtk_widget_show (label);
522 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
523 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
524 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
525 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
526 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
527 gtk_widget_show (label);
529 gtk_widget_show (GTK_WIDGET (box));
530 return GTK_WIDGET (box);
533 /** Change the caption title for the incoming server,
534 * as specified in the UI spec:
536 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
538 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
539 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
541 (protocol == MODEST_PROTOCOL_STORE_POP ?
542 _("mail_fi_emailtype_pop3") :
543 _("mail_fi_emailtype_imap") );
546 /* Note that this produces a compiler warning,
547 * because the compiler does not know that the translated string will have a %s in it.
548 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
549 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
550 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
551 g_free(incomingserver_title);
554 /** Change the caption title for the incoming server,
555 * as specified in the UI spec:
557 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
559 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
560 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
562 /* Fill the combo with appropriately titled choices for POP or IMAP. */
563 /* The choices are the same, but the titles are different, as in the UI spec. */
564 modest_serversecurity_combo_box_fill (
565 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
568 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
570 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
571 update_incoming_server_title (self);
572 update_incoming_server_security_choices (self);
574 set_default_custom_servernames (self);
577 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
579 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
580 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
581 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
584 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
586 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
588 /* Show note that account type cannot be changed in future: */
589 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
590 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
591 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
592 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
593 gtk_widget_show (label);
595 /* Create a size group to be used by all captions.
596 * Note that HildonCaption does not create a default size group if we do not specify one.
597 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
598 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
600 /* The incoming server widgets: */
601 if (!self->combo_incoming_servertype)
602 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
603 easysetup_servertype_combo_box_set_active_servertype (
604 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
605 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
606 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
607 gtk_widget_show (self->combo_incoming_servertype);
608 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
609 gtk_widget_show (caption);
611 if(!self->entry_incomingserver)
612 self->entry_incomingserver = gtk_entry_new ();
613 /* Auto-capitalization is the default, so let's turn it off: */
614 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
615 set_default_custom_servernames (self);
617 if (self->caption_incoming)
618 gtk_widget_destroy (self->caption_incoming);
620 /* The caption title will be updated in update_incoming_server_title().
621 * so this default text will never be seen: */
622 /* (Note: Changing the title seems pointless. murrayc) */
623 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
624 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
625 update_incoming_server_title (self);
626 gtk_widget_show (self->entry_incomingserver);
627 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
628 gtk_widget_show (self->caption_incoming);
630 /* Change the caption title when the servertype changes,
631 * as in the UI spec: */
632 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
633 G_CALLBACK (on_combo_servertype_changed), self);
635 /* Remember when the servername was changed manually: */
636 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
637 G_CALLBACK (on_entry_incoming_servername_changed), self);
639 /* The secure connection widgets: */
640 if (!self->combo_incoming_security)
641 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
642 update_incoming_server_security_choices (self);
643 modest_serversecurity_combo_box_set_active_serversecurity (
644 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
645 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
646 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
647 gtk_widget_show (self->combo_incoming_security);
648 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
649 gtk_widget_show (caption);
651 if(!self->checkbox_incoming_auth)
652 self->checkbox_incoming_auth = gtk_check_button_new ();
653 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
654 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
655 gtk_widget_show (self->checkbox_incoming_auth);
656 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
657 gtk_widget_show (caption);
659 gtk_widget_show (GTK_WIDGET (box));
661 return GTK_WIDGET (box);
665 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
667 GtkWidget *widget = GTK_WIDGET (user_data);
669 /* Enable the widget only if the toggle button is active: */
670 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
671 gtk_widget_set_sensitive (widget, enable);
674 /* Make the sensitivity of a widget depend on a toggle button.
677 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
679 g_signal_connect (G_OBJECT (button), "toggled",
680 G_CALLBACK (on_toggle_button_changed), widget);
682 /* Set the starting sensitivity: */
683 on_toggle_button_changed (button, widget);
687 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
689 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
691 /* Create the window, if necessary: */
692 if (!(self->specific_window)) {
693 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
694 modest_connection_specific_smtp_window_fill_with_connections (
695 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
696 NULL /* account_name, not known yet. */);
699 /* Show the window: */
700 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
701 gtk_widget_show (self->specific_window);
704 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
706 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
707 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
708 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
711 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
713 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
715 /* Create a size group to be used by all captions.
716 * Note that HildonCaption does not create a default size group if we do not specify one.
717 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
718 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
720 /* The outgoing server widgets: */
721 if (!self->entry_outgoingserver)
722 self->entry_outgoingserver = gtk_entry_new ();
723 /* Auto-capitalization is the default, so let's turn it off: */
724 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
725 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
726 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
727 gtk_widget_show (self->entry_outgoingserver);
728 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
729 gtk_widget_show (caption);
730 set_default_custom_servernames (self);
732 /* The secure connection widgets: */
733 if (!self->combo_outgoing_security)
734 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
735 modest_serversecurity_combo_box_fill (
736 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
737 modest_serversecurity_combo_box_set_active_serversecurity (
738 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
739 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
740 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
741 gtk_widget_show (self->combo_outgoing_security);
742 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
743 gtk_widget_show (caption);
745 /* The secure authentication widgets: */
746 if (!self->combo_outgoing_auth)
747 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
748 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
749 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
750 gtk_widget_show (self->combo_outgoing_auth);
751 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
752 gtk_widget_show (caption);
754 GtkWidget *separator = gtk_hseparator_new ();
755 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
756 gtk_widget_show (separator);
758 /* connection-specific checkbox: */
759 if (!self->checkbox_outgoing_smtp_specific) {
760 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
761 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
764 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
765 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
766 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
767 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
768 gtk_widget_show (caption);
770 /* Connection-specific SMTP-Severs Edit button: */
771 if (!self->button_outgoing_smtp_servers)
772 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
773 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
774 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
775 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
776 gtk_widget_show (self->button_outgoing_smtp_servers);
777 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
778 gtk_widget_show (caption);
780 /* Only enable the button when the checkbox is checked: */
781 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
782 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
784 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
785 G_CALLBACK (on_button_outgoing_smtp_servers), self);
787 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
788 G_CALLBACK (on_entry_outgoing_servername_changed), self);
791 gtk_widget_show (GTK_WIDGET (box));
793 return GTK_WIDGET (box);
797 on_timeout_show_advanced_edit(gpointer user_data)
799 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
801 if (!(self->saved_account_name))
804 /* Show the Account Settings window: */
805 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
806 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
808 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
810 gtk_dialog_run (GTK_DIALOG (dialog));
812 /* TODO: The hide() is not necessary.
813 * It is just here to show that it doesn't work,
814 * just as destroy doesn't work.
816 gtk_widget_hide (GTK_WIDGET(dialog));
818 /* TODO: The dialog remains on screen, not allowing any interaction.
819 * But gtk_widget_destroy() should always destroy.
821 printf("debug: destroying settings dialog\n");
822 gtk_widget_destroy (GTK_WIDGET (dialog));
823 printf("debug: after destroying settings dialog (doesn't seem to work).\n");
825 return FALSE; /* Do not call this timeout callback again. */
829 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
831 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
833 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
834 * without recoding it to use non-gconf information.
835 * This account will be deleted if Finish is never actually clicked. */
837 gboolean saved = TRUE;
838 gboolean was_already_saved = TRUE;
839 if (!(self->saved_account_name)) {
840 saved = create_account (self, FALSE);
841 was_already_saved = FALSE;
847 if (!(self->saved_account_name))
850 /* Show the Account Settings window: */
851 if (was_already_saved) {
852 /* Just show the dialog immediately: */
853 on_timeout_show_advanced_edit(self);
857 printf ("debug: waiting for gconf to update its local cache. "
858 "This is a hack to work around a maemo gconf bug in maemo bora.\n");
860 g_timeout_add (5000, on_timeout_show_advanced_edit, self);
863 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
865 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
866 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
867 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
868 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
869 gtk_widget_show (label);
871 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
872 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
873 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
874 gtk_widget_show (label);
876 if (!self->button_edit)
877 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
878 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
879 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
880 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
881 gtk_widget_show (self->button_edit);
882 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
883 gtk_widget_show (caption);
885 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
886 G_CALLBACK (on_button_edit_advanced_settings), self);
888 gtk_widget_show (GTK_WIDGET (box));
889 return GTK_WIDGET (box);
896 on_response (ModestWizardDialog *wizard_dialog,
900 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
902 if (response_id == GTK_RESPONSE_CANCEL) {
903 /* Remove any temporarily-saved account that will not actually be needed: */
904 if (self->saved_account_name) {
905 modest_account_mgr_remove_account (self->account_manager,
906 self->saved_account_name, FALSE);
910 invoke_enable_buttons_vfunc (self);
914 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
916 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
918 /* Create the notebook to be used by the ModestWizardDialog base class:
919 * Each page of the notebook will be a page of the wizard: */
920 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
922 /* Set the notebook used by the ModestWizardDialog base class: */
923 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
925 /* Set the wizard title:
926 * The actual window title will be a combination of this and the page's tab label title. */
927 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
929 /* Read in the information about known service providers: */
930 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
932 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
933 priv->presets = modest_presets_new (filepath);
934 if (!(priv->presets)) {
935 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
938 g_assert(priv->presets);
940 /* The server fields did not have been manually changed yet */
941 priv->server_changes = 0;
943 /* Get the account manager object,
944 * so we can check for existing accounts,
945 * and create new accounts: */
946 self->account_manager = modest_runtime_get_account_mgr ();
947 g_assert (self->account_manager);
948 g_object_ref (self->account_manager);
950 /* Create the common pages,
952 self->page_welcome = create_page_welcome (self);
953 self->page_account_details = create_page_account_details (self);
954 self->page_user_details = create_page_user_details (self);
956 /* Add the common pages: */
957 gtk_notebook_append_page (notebook, self->page_welcome,
958 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
959 gtk_notebook_append_page (notebook, self->page_account_details,
960 gtk_label_new (_("mcen_ti_accountdetails")));
961 gtk_notebook_append_page (notebook, self->page_user_details,
962 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
964 /* Create and add the easysetup-specific pages,
965 * because we need _some_ final page to enable the Next and Finish buttons: */
966 create_subsequent_easysetup_pages (self);
968 /* Connect to the dialog's response signal so we can enable/disable buttons
969 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
970 * Note that we use g_signal_connect_after() instead of g_signal_connect()
971 * so that we can be enable/disable after ModestWizardDialog has done its own
972 * enabling/disabling of buttons.
974 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
975 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
977 * It's not enough to connect to the notebook's switch-page signal, because
978 * ModestWizardDialog's "response" signal handler enables the buttons itself,
979 * _after_ switching the page (understandably).
980 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
981 * then gtk_notebook_get_current_page() would return an incorrect value.)
983 g_signal_connect_after (G_OBJECT (self), "response",
984 G_CALLBACK (on_response), self);
986 /* When this window is shown, hibernation should not be possible,
987 * because there is no sensible way to save the state: */
988 modest_window_mgr_prevent_hibernation_while_window_is_shown (
989 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
992 ModestEasysetupWizardDialog*
993 modest_easysetup_wizard_dialog_new (void)
995 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
998 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1000 GtkNotebook *notebook = NULL;
1001 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1004 /* Create the custom pages: */
1005 if(!(self->page_custom_incoming)) {
1006 self->page_custom_incoming = create_page_custom_incoming (self);
1009 if(!(self->page_custom_outgoing)) {
1010 self->page_custom_outgoing = create_page_custom_outgoing (self);
1013 if(!(self->page_complete_customsetup)) {
1014 self->page_complete_customsetup = create_page_complete_custom (self);
1017 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1018 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1019 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1021 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1022 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1023 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1025 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1026 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1027 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1029 /* This is unnecessary with GTK+ 2.10: */
1030 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1033 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1035 GtkNotebook *notebook = NULL;
1036 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1039 /* Create the easysetup-specific pages: */
1040 if(!self->page_complete_easysetup)
1041 self->page_complete_easysetup = create_page_complete_easysetup (self);
1043 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1044 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1045 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1047 /* This is unnecessary with GTK+ 2.10: */
1048 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1050 /* After the user details page,
1051 * the following pages depend on whether "Other" was chosen
1052 * in the provider combobox on the account page
1054 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1056 if (easysetup_provider_combo_box_get_active_provider_id (
1057 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1058 /* "Other..." was selected: */
1060 /* Make sure that the easysetup pages do not exist: */
1061 if(self->page_complete_easysetup) {
1062 gtk_widget_destroy (self->page_complete_easysetup);
1063 self->page_complete_easysetup = NULL;
1066 create_subsequent_customsetup_pages (self);
1069 /* A specific provider was selected: */
1071 /* Make sure that the custom pages do not exist:
1072 * Because they will be used if they exist, when creating the account. */
1073 if(self->page_custom_incoming) {
1074 gtk_widget_destroy (self->page_custom_incoming);
1075 self->page_custom_incoming = NULL;
1078 if(self->page_custom_outgoing) {
1079 gtk_widget_destroy (self->page_custom_outgoing);
1080 self->page_custom_outgoing = NULL;
1083 if(self->page_complete_customsetup) {
1084 gtk_widget_destroy (self->page_complete_customsetup);
1085 self->page_complete_customsetup = NULL;
1089 /* Create the easysetup pages: */
1090 create_subsequent_easysetup_pages (self);
1096 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1101 gchar* at = g_utf8_strchr (email_address, -1, '@');
1102 if (!at || (g_utf8_strlen (at, -1) < 2))
1105 gchar* domain = g_utf8_next_char (at);
1109 const gchar* hostname = NULL;
1110 if (servertype == MODEST_PROTOCOL_STORE_POP)
1112 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1114 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1120 return g_strdup_printf ("%s.%s", hostname, domain);
1123 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1125 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1127 if (!account_wizard->entry_incomingserver)
1130 /* Set a default domain for the server, based on the email address,
1131 * if no server name was already specified.
1133 if (account_wizard->entry_user_email
1134 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1135 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1136 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1137 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1139 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1141 /* Do not set the INCOMING_CHANGED flag because of this edit */
1142 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1143 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1144 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1146 g_free (servername);
1149 /* Set a default domain for the server, based on the email address,
1150 * if no server name was already specified.
1152 if (!account_wizard->entry_outgoingserver)
1155 if (account_wizard->entry_user_email
1156 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1157 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1159 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1161 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1162 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1163 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1164 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1166 g_free (servername);
1171 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1173 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1175 /* Do extra validation that couldn't be done for every key press,
1176 * either because it was too slow,
1177 * or because it requires interaction:
1179 if (current_page == account_wizard->page_account_details) {
1180 /* Check that the title is not already in use: */
1181 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1182 if ((!account_title) || (strlen(account_title) == 0))
1185 /* Aavoid a clash with an existing display name: */
1186 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1187 account_wizard->account_manager, account_title);
1190 /* Warn the user via a dialog: */
1191 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1196 else if (current_page == account_wizard->page_user_details) {
1197 /* Check that the email address is valud: */
1198 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1199 if ((!email_address) || (strlen(email_address) == 0))
1202 if (!modest_text_utils_validate_email_address (email_address)) {
1203 /* Warn the user via a dialog: */
1204 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1206 /* Return focus to the email address entry: */
1207 gtk_widget_grab_focus (account_wizard->entry_user_email);
1212 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1213 create_subsequent_pages (account_wizard);
1216 /* TODO: The UI Spec wants us to check that the servernames are valid,
1217 * but does not specify how.
1220 if(next_page == account_wizard->page_custom_incoming) {
1221 set_default_custom_servernames (account_wizard);
1223 else if (next_page == account_wizard->page_custom_outgoing) {
1224 set_default_custom_servernames (account_wizard);
1225 /* Check if the server support secure authentication */
1226 if (gtk_toggle_button_get_active (
1227 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))) {
1229 const ModestTransportStoreProtocol protocol =
1230 easysetup_servertype_combo_box_get_active_servertype (
1231 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1232 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
1233 /* FIXME: Get correct port */
1236 GList *list_auth_methods =
1237 modest_maemo_utils_get_supported_secure_authentication_methods (
1239 hostname, port_num, GTK_WINDOW (dialog));
1240 if (list_auth_methods) {
1241 /* TODO: Select the correct method */
1242 g_list_free (list_auth_methods);
1246 GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(dialog),
1247 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
1248 GTK_BUTTONS_OK, _("Server does not support secure authentication!"));
1249 gtk_dialog_run(GTK_DIALOG(error_dialog));
1250 gtk_widget_destroy(error_dialog);
1257 /* If this is the last page, and this is a click on Finish,
1258 * then attempt to create the dialog.
1260 if(!next_page) /* This is NULL when this is a click on Finish. */
1262 if (account_wizard->saved_account_name) {
1263 /* Just enable the already-saved account (temporarily created when
1264 * editing advanced settings): */
1265 modest_account_mgr_set_enabled (account_wizard->account_manager,
1266 account_wizard->saved_account_name, TRUE);
1268 create_account (account_wizard, TRUE /* enabled */);
1276 static gboolean entry_is_empty (GtkWidget *entry)
1281 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1282 if ((!text) || (strlen(text) == 0))
1289 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1291 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1293 gboolean enable_next = TRUE;
1294 if (current_page == account_wizard->page_welcome) {
1297 else if (current_page == account_wizard->page_account_details) {
1298 /* The account details title is mandatory: */
1299 if (entry_is_empty(account_wizard->entry_account_title))
1300 enable_next = FALSE;
1302 else if (current_page == account_wizard->page_user_details) {
1303 /* The user details username is mandatory: */
1304 if (entry_is_empty(account_wizard->entry_user_username))
1305 enable_next = FALSE;
1307 /* The user details email address is mandatory: */
1308 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1309 enable_next = FALSE;
1311 else if (current_page == account_wizard->page_custom_incoming) {
1312 /* The custom incoming server is mandatory: */
1313 if (entry_is_empty(account_wizard->entry_incomingserver))
1314 enable_next = FALSE;
1317 /* Enable the buttons,
1318 * identifying them via their associated response codes: */
1320 /* Disable the Finish button until we are on the last page,
1321 * because HildonWizardDialog enables this for all but the first page: */
1322 GtkNotebook *notebook = NULL;
1323 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1324 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1326 gint current = gtk_notebook_get_current_page (notebook);
1327 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1328 const gboolean is_last = (current == last);
1331 gtk_dialog_set_response_sensitive (dialog_base,
1332 MODEST_WIZARD_DIALOG_FINISH,
1336 /* Disable Next on the last page: */
1337 enable_next = FALSE;
1340 gtk_dialog_set_response_sensitive (dialog_base,
1341 MODEST_WIZARD_DIALOG_NEXT,
1346 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1348 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1349 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1352 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1353 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1354 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1355 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1357 /* Provide a vfunc implementation so we can decide
1358 * when to enable/disable the prev/next buttons.
1360 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1361 base_klass->before_next = on_before_next;
1362 base_klass->enable_buttons = on_enable_buttons;
1366 show_error (GtkWindow *parent_window, const gchar* text)
1368 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1370 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1377 gtk_dialog_run (dialog);
1378 gtk_widget_destroy (GTK_WIDGET (dialog));
1381 /** Attempt to create the account from the information that the user has entered.
1382 * @result: TRUE if the account was successfully created.
1385 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1387 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1389 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1395 /* We should have checked for this already,
1396 * and changed that name accordingly,
1397 * but let's check again just in case:
1399 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1402 /* Increment the non-user visible name if necessary,
1403 * based on the display name: */
1404 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1405 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1406 account_name_start, FALSE /* not a server account */);
1407 g_free (account_name_start);
1409 /* username and password (for both incoming and outgoing): */
1410 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1411 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1413 /* Incoming server: */
1414 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1415 * or modest_account_mgr_add_server_account will fail. */
1416 gchar* servername_incoming = NULL;
1417 guint serverport_incoming = 0;
1418 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1419 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1420 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1422 /* Get details from the specified presets: */
1423 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1424 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1427 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1428 TRUE /* incoming */);
1430 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1432 TRUE /* incoming */);
1433 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1435 TRUE /* incoming */);
1437 g_warning ("security incoming: %x", security_incoming);
1439 /* We don't check for SMTP here as that is impossible for an incoming server. */
1440 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1441 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1442 serverport_incoming =
1443 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
1444 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1445 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1446 serverport_incoming =
1447 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
1450 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1451 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1453 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1454 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1457 /* Use custom pages because no preset was specified: */
1458 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1460 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1461 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1463 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1464 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1466 /* The UI spec says:
1467 * If secure authentication is unchecked, allow sending username and password also as plain text.
1468 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1469 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1471 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1472 ? MODEST_PROTOCOL_AUTH_CRAMMD5
1473 : MODEST_PROTOCOL_AUTH_PASSWORD;
1476 /* First we add the 2 server accounts, and then we add the account that uses them.
1477 * If we don't do it in this order then we will experience a crash. */
1479 /* Add a (incoming) server account, to be used by the account: */
1480 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1481 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1482 store_name_start, TRUE /* server account */);
1483 g_free (store_name_start);
1484 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1486 servername_incoming,
1487 serverport_incoming,
1490 protocol_security_incoming,
1491 protocol_authentication_incoming);
1493 g_free (servername_incoming);
1496 /* TODO: Provide a Logical ID for the text: */
1497 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1502 /* There must be at least one account now: */
1503 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1504 * fixed in versions after 3.1. */
1505 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1508 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1510 g_slist_free (account_names);
1513 /* Outgoing server: */
1514 gchar* servername_outgoing = NULL;
1515 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1516 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1517 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1518 guint serverport_outgoing = 0;
1522 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1523 FALSE /* incoming */);
1525 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1527 FALSE /* incoming */);
1529 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1530 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1531 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1532 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1534 ModestPresetsSecurity security_outgoing =
1535 modest_presets_get_info_server_security (priv->presets, provider_id,
1536 FALSE /* incoming */);
1538 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1539 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1540 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1541 serverport_outgoing = 465;
1542 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1544 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1545 /* TODO: There is no SMTP authentication enum for presets. */
1548 /* Use custom pages because no preset was specified: */
1549 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1551 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1553 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1554 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1556 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1557 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1560 /* Add a (outgoing) server account to be used by the account: */
1561 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1562 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1563 transport_name_start, TRUE /* server account */);
1564 g_free (transport_name_start);
1565 created = modest_account_mgr_add_server_account (self->account_manager,
1567 servername_outgoing,
1568 serverport_outgoing,
1571 protocol_security_outgoing,
1572 protocol_authentication_outgoing);
1574 g_free (servername_outgoing);
1577 /* TODO: Provide a Logical ID for the text: */
1578 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1583 /* Create the account, which will contain the two "server accounts": */
1584 created = modest_account_mgr_add_account (self->account_manager, account_name,
1585 store_name, /* The name of our POP/IMAP server account. */
1586 transport_name, /* The name of our SMTP server account. */
1588 g_free (store_name);
1589 g_free (transport_name);
1592 /* TODO: Provide a Logical ID for the text: */
1593 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1597 /* The user name and email address must be set additionally: */
1598 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1599 modest_account_mgr_set_string (self->account_manager, account_name,
1600 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1602 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1603 modest_account_mgr_set_string (self->account_manager, account_name,
1604 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1606 /* Set the display name: */
1607 modest_account_mgr_set_string (self->account_manager, account_name,
1608 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1610 /* Set retrieve type */
1611 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1612 modest_account_mgr_set_string (self->account_manager, account_name,
1613 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1615 /* Save the connection-specific SMTP server accounts. */
1616 gboolean result = TRUE;
1617 if (self->specific_window)
1618 result = modest_connection_specific_smtp_window_save_server_accounts (
1619 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1621 g_free (self->saved_account_name);
1622 self->saved_account_name = g_strdup (account_name);
1624 g_free (account_name);