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);
148 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
149 ModestPresetsSecurity security_incoming)
151 int serverport_incoming = 0;
152 /* We don't check for SMTP here as that is impossible for an incoming server. */
153 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
154 serverport_incoming =
155 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
156 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
157 serverport_incoming =
158 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
160 return serverport_incoming;
163 static GList* check_for_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
165 const ModestTransportStoreProtocol protocol =
166 easysetup_servertype_combo_box_get_active_servertype (
167 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
168 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
169 const ModestConnectionProtocol protocol_security_incoming =
170 modest_serversecurity_combo_box_get_active_serversecurity (
171 MODEST_SERVERSECURITY_COMBO_BOX (
172 account_wizard->combo_incoming_security));
173 int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
174 GList *list_auth_methods =
175 modest_maemo_utils_get_supported_secure_authentication_methods (
177 hostname, port_num, GTK_WINDOW (account_wizard));
178 if (list_auth_methods) {
179 /* TODO: Select the correct method */
182 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
184 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
185 if (modest_protocol_info_auth_is_secure(auth))
187 g_list_append(list, GINT_TO_POINTER(auth));
190 g_list_free(list_auth_methods);
194 /* no secure methods supported */
195 GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(account_wizard),
196 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
197 GTK_BUTTONS_OK, _("Server does not support secure authentication!"));
198 gtk_dialog_run(GTK_DIALOG(error_dialog));
199 gtk_widget_destroy(error_dialog);
204 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
206 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
208 /* Call the vfunc, which may be overridden by derived classes: */
209 if (klass->enable_buttons) {
210 GtkNotebook *notebook = NULL;
211 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
213 const gint current_page_num = gtk_notebook_get_current_page (notebook);
214 if (current_page_num == -1)
217 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
218 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
223 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
225 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
227 invoke_enable_buttons_vfunc(self);
231 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
233 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
235 invoke_enable_buttons_vfunc(self);
238 /** This is a convenience function to create a caption containing a mandatory widget.
239 * When the widget is edited, the enable_buttons() vfunc will be called.
241 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
246 HildonCaptionStatus flag)
248 GtkWidget *caption = NULL;
250 /* Note: Previously, the translated strings already contained the "*",
251 * Comment out this code if they do again.
253 /* Add a * character to indicate mandatory fields,
254 * as specified in our "Email UI Specification": */
255 if (flag == HILDON_CAPTION_MANDATORY) {
256 gchar* title = g_strdup_printf("%s*", value);
257 caption = hildon_caption_new (group, title, control, icon, flag);
261 caption = hildon_caption_new (group, value, control, icon, flag);
263 /* Connect to the appropriate changed signal for the widget,
264 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
266 if (GTK_IS_ENTRY (control)) {
267 g_signal_connect (G_OBJECT (control), "changed",
268 G_CALLBACK (on_caption_entry_changed), self);
271 else if (GTK_IS_COMBO_BOX (control)) {
272 g_signal_connect (G_OBJECT (control), "changed",
273 G_CALLBACK (on_caption_combobox_changed), self);
280 create_page_welcome (ModestEasysetupWizardDialog *self)
282 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
283 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
284 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
285 /* So that it is not truncated: */
286 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
287 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
288 gtk_widget_show (label);
289 gtk_widget_show (GTK_WIDGET (box));
290 return GTK_WIDGET (box);
294 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
296 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
298 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
300 /* Fill the providers combo, based on the selected country: */
301 GSList *list_mcc_ids = easysetup_country_combo_box_get_active_country_ids (
302 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
303 easysetup_provider_combo_box_fill (
304 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, list_mcc_ids);
308 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
310 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
312 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
314 /* Fill the providers combo, based on the selected country: */
315 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
316 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
318 gchar* domain_name = NULL;
320 domain_name = modest_presets_get_domain (priv->presets, provider_id);
323 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
325 if (self->entry_user_email)
326 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
328 g_free (domain_name);
330 g_free (provider_id);
334 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
336 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
337 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
341 create_page_account_details (ModestEasysetupWizardDialog *self)
343 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
344 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
345 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
346 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
347 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
348 gtk_widget_show (label);
350 /* Create a size group to be used by all captions.
351 * Note that HildonCaption does not create a default size group if we do not specify one.
352 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
353 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
355 /* The country widgets: */
356 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
357 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
358 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
359 gtk_widget_show (self->combo_account_country);
360 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
361 gtk_widget_show (caption);
363 /* connect to country combo's changed signal, so we can fill the provider combo: */
364 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
365 G_CALLBACK (on_combo_account_country), self);
367 GtkWidget *separator = gtk_hseparator_new ();
368 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
369 gtk_widget_show (separator);
371 /* The service provider widgets: */
372 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
374 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
375 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
376 gtk_widget_show (self->combo_account_serviceprovider);
377 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
378 gtk_widget_show (caption);
380 /* connect to providers combo's changed signal, so we can fill the email address: */
381 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
382 G_CALLBACK (on_combo_account_serviceprovider), self);
384 /* TODO: Default to the current country somehow.
385 * But I don't know how to get the information that is specified in the
386 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
388 * This is probably not the best choice of gconf key:
389 * This is the "mcc used in the last pairing", ie. the last connection you made.
390 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
393 GConfClient *client = gconf_client_get_default ();
394 GError *error = NULL;
395 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
396 gint mcc_id = gconf_client_get_int(client, key, &error);
402 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
403 g_error_free (error);
409 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
410 * This might just be a Maemo bug.
414 /* For now, we default to Finland when there is nothing better: */
418 easysetup_country_combo_box_set_active_country_id (
419 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
422 /* The description widgets: */
423 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
424 /* Do use auto-capitalization: */
425 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
426 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
428 /* Set a default account title, choosing one that does not already exist: */
429 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
430 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
431 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
432 self->account_manager, default_account_name_start);
433 g_free (default_account_name_start);
434 default_account_name_start = NULL;
436 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
437 g_free (default_account_name);
438 default_account_name = NULL;
440 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
441 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
442 gtk_widget_show (self->entry_account_title);
443 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
444 gtk_widget_show (caption);
446 /* Prevent the use of some characters in the account title,
447 * as required by our UI specification: */
448 GList *list_prevent = NULL;
449 list_prevent = g_list_append (list_prevent, "\\");
450 list_prevent = g_list_append (list_prevent, "/");
451 list_prevent = g_list_append (list_prevent, ":");
452 list_prevent = g_list_append (list_prevent, "*");
453 list_prevent = g_list_append (list_prevent, "?");
454 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
455 list_prevent = g_list_append (list_prevent, "“");
456 list_prevent = g_list_append (list_prevent, "<");
457 list_prevent = g_list_append (list_prevent, ">");
458 list_prevent = g_list_append (list_prevent, "|");
459 list_prevent = g_list_append (list_prevent, "^");
460 modest_validating_entry_set_unallowed_characters (
461 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
462 g_list_free (list_prevent);
464 /* Set max length as in the UI spec:
465 * The UI spec seems to want us to show a dialog if we hit the maximum. */
466 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
467 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
470 gtk_widget_show (GTK_WIDGET (box));
472 return GTK_WIDGET (box);
476 create_page_user_details (ModestEasysetupWizardDialog *self)
478 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
480 /* Create a size group to be used by all captions.
481 * Note that HildonCaption does not create a default size group if we do not specify one.
482 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
483 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
485 /* The name widgets: */
486 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
487 /* Auto-capitalization is the default, so let's turn it off: */
488 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
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_name), 64);
492 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
494 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
495 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
496 gtk_widget_show (self->entry_user_name);
497 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
498 gtk_widget_show (caption);
500 /* Prevent the use of some characters in the name,
501 * as required by our UI specification: */
502 GList *list_prevent = NULL;
503 list_prevent = g_list_append (list_prevent, "<");
504 list_prevent = g_list_append (list_prevent, ">");
505 modest_validating_entry_set_unallowed_characters (
506 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
507 g_list_free (list_prevent);
509 /* The username widgets: */
510 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
511 /* Auto-capitalization is the default, so let's turn it off: */
512 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
513 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
514 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
515 gtk_widget_show (self->entry_user_username);
516 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
517 gtk_widget_show (caption);
519 /* Prevent the use of some characters in the username,
520 * as required by our UI specification: */
521 modest_validating_entry_set_unallowed_characters_whitespace (
522 MODEST_VALIDATING_ENTRY (self->entry_user_username));
524 /* Set max length as in the UI spec:
525 * The UI spec seems to want us to show a dialog if we hit the maximum. */
526 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
527 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
530 /* The password widgets: */
531 self->entry_user_password = gtk_entry_new ();
532 /* Auto-capitalization is the default, so let's turn it off: */
533 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
534 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
535 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
536 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
537 caption = create_caption_new_with_asterisk (self, sizegroup,
538 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
539 gtk_widget_show (self->entry_user_password);
540 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
541 gtk_widget_show (caption);
543 /* The email address widgets: */
544 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
545 /* Auto-capitalization is the default, so let's turn it off: */
546 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
547 caption = create_caption_new_with_asterisk (self, sizegroup,
548 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
549 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
550 gtk_widget_show (self->entry_user_email);
551 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
552 gtk_widget_show (caption);
554 /* Set max length as in the UI spec:
555 * The UI spec seems to want us to show a dialog if we hit the maximum. */
556 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
557 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
561 gtk_widget_show (GTK_WIDGET (box));
563 return GTK_WIDGET (box);
566 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
568 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
570 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
571 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
572 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
573 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
574 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
575 gtk_widget_show (label);
577 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
578 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
579 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
580 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
581 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
582 gtk_widget_show (label);
584 gtk_widget_show (GTK_WIDGET (box));
585 return GTK_WIDGET (box);
588 /** Change the caption title for the incoming server,
589 * as specified in the UI spec:
591 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
593 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
594 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
596 (protocol == MODEST_PROTOCOL_STORE_POP ?
597 _("mail_fi_emailtype_pop3") :
598 _("mail_fi_emailtype_imap") );
601 /* Note that this produces a compiler warning,
602 * because the compiler does not know that the translated string will have a %s in it.
603 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
604 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
605 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
606 g_free(incomingserver_title);
609 /** Change the caption title for the incoming server,
610 * as specified in the UI spec:
612 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
614 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
615 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
617 /* Fill the combo with appropriately titled choices for POP or IMAP. */
618 /* The choices are the same, but the titles are different, as in the UI spec. */
619 modest_serversecurity_combo_box_fill (
620 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
623 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
625 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
626 update_incoming_server_title (self);
627 update_incoming_server_security_choices (self);
629 set_default_custom_servernames (self);
632 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
634 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
635 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
636 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
639 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
641 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
643 /* Show note that account type cannot be changed in future: */
644 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
645 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
646 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
647 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
648 gtk_widget_show (label);
650 /* Create a size group to be used by all captions.
651 * Note that HildonCaption does not create a default size group if we do not specify one.
652 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
653 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
655 /* The incoming server widgets: */
656 if (!self->combo_incoming_servertype)
657 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
658 easysetup_servertype_combo_box_set_active_servertype (
659 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
660 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
661 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
662 gtk_widget_show (self->combo_incoming_servertype);
663 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
664 gtk_widget_show (caption);
666 if(!self->entry_incomingserver)
667 self->entry_incomingserver = gtk_entry_new ();
668 /* Auto-capitalization is the default, so let's turn it off: */
669 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
670 set_default_custom_servernames (self);
672 if (self->caption_incoming)
673 gtk_widget_destroy (self->caption_incoming);
675 /* The caption title will be updated in update_incoming_server_title().
676 * so this default text will never be seen: */
677 /* (Note: Changing the title seems pointless. murrayc) */
678 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
679 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
680 update_incoming_server_title (self);
681 gtk_widget_show (self->entry_incomingserver);
682 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
683 gtk_widget_show (self->caption_incoming);
685 /* Change the caption title when the servertype changes,
686 * as in the UI spec: */
687 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
688 G_CALLBACK (on_combo_servertype_changed), self);
690 /* Remember when the servername was changed manually: */
691 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
692 G_CALLBACK (on_entry_incoming_servername_changed), self);
694 /* The secure connection widgets: */
695 if (!self->combo_incoming_security)
696 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
697 update_incoming_server_security_choices (self);
698 modest_serversecurity_combo_box_set_active_serversecurity (
699 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
700 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
701 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
702 gtk_widget_show (self->combo_incoming_security);
703 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
704 gtk_widget_show (caption);
706 if(!self->checkbox_incoming_auth)
707 self->checkbox_incoming_auth = gtk_check_button_new ();
708 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
709 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
710 gtk_widget_show (self->checkbox_incoming_auth);
711 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
712 gtk_widget_show (caption);
714 gtk_widget_show (GTK_WIDGET (box));
716 return GTK_WIDGET (box);
720 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
722 GtkWidget *widget = GTK_WIDGET (user_data);
724 /* Enable the widget only if the toggle button is active: */
725 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
726 gtk_widget_set_sensitive (widget, enable);
729 /* Make the sensitivity of a widget depend on a toggle button.
732 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
734 g_signal_connect (G_OBJECT (button), "toggled",
735 G_CALLBACK (on_toggle_button_changed), widget);
737 /* Set the starting sensitivity: */
738 on_toggle_button_changed (button, widget);
742 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
744 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
746 /* Create the window, if necessary: */
747 if (!(self->specific_window)) {
748 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
749 modest_connection_specific_smtp_window_fill_with_connections (
750 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
751 NULL /* account_name, not known yet. */);
754 /* Show the window: */
755 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
756 gtk_widget_show (self->specific_window);
759 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
761 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
762 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
763 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
766 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
768 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
770 /* Create a size group to be used by all captions.
771 * Note that HildonCaption does not create a default size group if we do not specify one.
772 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
773 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
775 /* The outgoing server widgets: */
776 if (!self->entry_outgoingserver)
777 self->entry_outgoingserver = gtk_entry_new ();
778 /* Auto-capitalization is the default, so let's turn it off: */
779 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
780 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
781 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
782 gtk_widget_show (self->entry_outgoingserver);
783 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
784 gtk_widget_show (caption);
785 set_default_custom_servernames (self);
787 /* The secure connection widgets: */
788 if (!self->combo_outgoing_security)
789 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
790 modest_serversecurity_combo_box_fill (
791 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
792 modest_serversecurity_combo_box_set_active_serversecurity (
793 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
794 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
795 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
796 gtk_widget_show (self->combo_outgoing_security);
797 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
798 gtk_widget_show (caption);
800 /* The secure authentication widgets: */
801 if (!self->combo_outgoing_auth)
802 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
803 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
804 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
805 gtk_widget_show (self->combo_outgoing_auth);
806 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
807 gtk_widget_show (caption);
809 GtkWidget *separator = gtk_hseparator_new ();
810 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
811 gtk_widget_show (separator);
813 /* connection-specific checkbox: */
814 if (!self->checkbox_outgoing_smtp_specific) {
815 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
816 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
819 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
820 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
821 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
822 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
823 gtk_widget_show (caption);
825 /* Connection-specific SMTP-Severs Edit button: */
826 if (!self->button_outgoing_smtp_servers)
827 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
828 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
829 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
830 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
831 gtk_widget_show (self->button_outgoing_smtp_servers);
832 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
833 gtk_widget_show (caption);
835 /* Only enable the button when the checkbox is checked: */
836 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
837 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
839 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
840 G_CALLBACK (on_button_outgoing_smtp_servers), self);
842 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
843 G_CALLBACK (on_entry_outgoing_servername_changed), self);
846 gtk_widget_show (GTK_WIDGET (box));
848 return GTK_WIDGET (box);
852 show_advanced_edit(gpointer user_data)
854 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
856 if (!(self->saved_account_name))
859 /* Show the Account Settings window: */
860 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
861 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
863 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
865 gtk_dialog_run (GTK_DIALOG (dialog));
867 gtk_widget_destroy (GTK_WIDGET (dialog));
869 return FALSE; /* Do not call this timeout callback again. */
873 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
875 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
877 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
878 * without recoding it to use non-gconf information.
879 * This account will be deleted if Finish is never actually clicked. */
881 gboolean saved = TRUE;
882 if (!(self->saved_account_name)) {
883 saved = create_account (self, FALSE);
889 if (!(self->saved_account_name))
892 /* Show the Account Settings window: */
893 show_advanced_edit(self);
895 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
897 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
898 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
899 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
900 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
901 gtk_widget_show (label);
903 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
904 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
905 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
906 gtk_widget_show (label);
908 if (!self->button_edit)
909 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
910 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
911 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
912 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
913 gtk_widget_show (self->button_edit);
914 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
915 gtk_widget_show (caption);
917 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
918 G_CALLBACK (on_button_edit_advanced_settings), self);
920 gtk_widget_show (GTK_WIDGET (box));
921 return GTK_WIDGET (box);
928 on_response (ModestWizardDialog *wizard_dialog,
932 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
934 if (response_id == GTK_RESPONSE_CANCEL) {
935 /* Remove any temporarily-saved account that will not actually be needed: */
936 if (self->saved_account_name) {
937 modest_account_mgr_remove_account (self->account_manager,
938 self->saved_account_name, FALSE);
942 invoke_enable_buttons_vfunc (self);
946 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
948 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
950 /* Create the notebook to be used by the ModestWizardDialog base class:
951 * Each page of the notebook will be a page of the wizard: */
952 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
954 /* Set the notebook used by the ModestWizardDialog base class: */
955 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
957 /* Set the wizard title:
958 * The actual window title will be a combination of this and the page's tab label title. */
959 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
961 /* Read in the information about known service providers: */
962 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
964 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
965 priv->presets = modest_presets_new (filepath);
966 if (!(priv->presets)) {
967 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
970 g_assert(priv->presets);
972 /* The server fields did not have been manually changed yet */
973 priv->server_changes = 0;
975 /* Get the account manager object,
976 * so we can check for existing accounts,
977 * and create new accounts: */
978 self->account_manager = modest_runtime_get_account_mgr ();
979 g_assert (self->account_manager);
980 g_object_ref (self->account_manager);
982 /* Create the common pages,
984 self->page_welcome = create_page_welcome (self);
985 self->page_account_details = create_page_account_details (self);
986 self->page_user_details = create_page_user_details (self);
988 /* Add the common pages: */
989 gtk_notebook_append_page (notebook, self->page_welcome,
990 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
991 gtk_notebook_append_page (notebook, self->page_account_details,
992 gtk_label_new (_("mcen_ti_accountdetails")));
993 gtk_notebook_append_page (notebook, self->page_user_details,
994 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
996 /* Create and add the easysetup-specific pages,
997 * because we need _some_ final page to enable the Next and Finish buttons: */
998 create_subsequent_easysetup_pages (self);
1000 /* Connect to the dialog's response signal so we can enable/disable buttons
1001 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1002 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1003 * so that we can be enable/disable after ModestWizardDialog has done its own
1004 * enabling/disabling of buttons.
1006 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1007 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1009 * It's not enough to connect to the notebook's switch-page signal, because
1010 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1011 * _after_ switching the page (understandably).
1012 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1013 * then gtk_notebook_get_current_page() would return an incorrect value.)
1015 g_signal_connect_after (G_OBJECT (self), "response",
1016 G_CALLBACK (on_response), self);
1018 /* When this window is shown, hibernation should not be possible,
1019 * because there is no sensible way to save the state: */
1020 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1021 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1024 ModestEasysetupWizardDialog*
1025 modest_easysetup_wizard_dialog_new (void)
1027 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1030 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1032 GtkNotebook *notebook = NULL;
1033 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1036 /* Create the custom pages: */
1037 if(!(self->page_custom_incoming)) {
1038 self->page_custom_incoming = create_page_custom_incoming (self);
1041 if(!(self->page_custom_outgoing)) {
1042 self->page_custom_outgoing = create_page_custom_outgoing (self);
1045 if(!(self->page_complete_customsetup)) {
1046 self->page_complete_customsetup = create_page_complete_custom (self);
1049 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1050 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1051 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1053 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1054 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1055 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1057 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1058 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1059 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1061 /* This is unnecessary with GTK+ 2.10: */
1062 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1065 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1067 GtkNotebook *notebook = NULL;
1068 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1071 /* Create the easysetup-specific pages: */
1072 if(!self->page_complete_easysetup)
1073 self->page_complete_easysetup = create_page_complete_easysetup (self);
1075 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1076 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1077 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1079 /* This is unnecessary with GTK+ 2.10: */
1080 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1082 /* After the user details page,
1083 * the following pages depend on whether "Other" was chosen
1084 * in the provider combobox on the account page
1086 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1088 if (easysetup_provider_combo_box_get_active_provider_id (
1089 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1090 /* "Other..." was selected: */
1092 /* Make sure that the easysetup pages do not exist: */
1093 if(self->page_complete_easysetup) {
1094 gtk_widget_destroy (self->page_complete_easysetup);
1095 self->page_complete_easysetup = NULL;
1098 create_subsequent_customsetup_pages (self);
1101 /* A specific provider was selected: */
1103 /* Make sure that the custom pages do not exist:
1104 * Because they will be used if they exist, when creating the account. */
1105 if(self->page_custom_incoming) {
1106 gtk_widget_destroy (self->page_custom_incoming);
1107 self->page_custom_incoming = NULL;
1110 if(self->page_custom_outgoing) {
1111 gtk_widget_destroy (self->page_custom_outgoing);
1112 self->page_custom_outgoing = NULL;
1115 if(self->page_complete_customsetup) {
1116 gtk_widget_destroy (self->page_complete_customsetup);
1117 self->page_complete_customsetup = NULL;
1121 /* Create the easysetup pages: */
1122 create_subsequent_easysetup_pages (self);
1128 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1133 gchar* at = g_utf8_strchr (email_address, -1, '@');
1134 if (!at || (g_utf8_strlen (at, -1) < 2))
1137 gchar* domain = g_utf8_next_char (at);
1141 const gchar* hostname = NULL;
1142 if (servertype == MODEST_PROTOCOL_STORE_POP)
1144 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1146 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1152 return g_strdup_printf ("%s.%s", hostname, domain);
1155 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1157 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1159 if (!account_wizard->entry_incomingserver)
1162 /* Set a default domain for the server, based on the email address,
1163 * if no server name was already specified.
1165 if (account_wizard->entry_user_email
1166 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1167 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1168 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1169 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1171 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1173 /* Do not set the INCOMING_CHANGED flag because of this edit */
1174 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1175 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1176 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1178 g_free (servername);
1181 /* Set a default domain for the server, based on the email address,
1182 * if no server name was already specified.
1184 if (!account_wizard->entry_outgoingserver)
1187 if (account_wizard->entry_user_email
1188 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1189 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1191 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1193 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1194 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1195 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1196 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1198 g_free (servername);
1203 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1205 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1207 /* Do extra validation that couldn't be done for every key press,
1208 * either because it was too slow,
1209 * or because it requires interaction:
1211 if (current_page == account_wizard->page_account_details) {
1212 /* Check that the title is not already in use: */
1213 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1214 if ((!account_title) || (strlen(account_title) == 0))
1217 /* Aavoid a clash with an existing display name: */
1218 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1219 account_wizard->account_manager, account_title);
1222 /* Warn the user via a dialog: */
1223 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1228 else if (current_page == account_wizard->page_user_details) {
1229 /* Check that the email address is valud: */
1230 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1231 if ((!email_address) || (strlen(email_address) == 0))
1234 if (!modest_text_utils_validate_email_address (email_address)) {
1235 /* Warn the user via a dialog: */
1236 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1238 /* Return focus to the email address entry: */
1239 gtk_widget_grab_focus (account_wizard->entry_user_email);
1244 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1245 create_subsequent_pages (account_wizard);
1248 /* TODO: The UI Spec wants us to check that the servernames are valid,
1249 * but does not specify how.
1252 if(next_page == account_wizard->page_custom_incoming) {
1253 set_default_custom_servernames (account_wizard);
1255 else if (next_page == account_wizard->page_custom_outgoing) {
1256 set_default_custom_servernames (account_wizard);
1257 /* Check if the server supports secure authentication */
1258 const ModestConnectionProtocol security_incoming =
1259 modest_serversecurity_combo_box_get_active_serversecurity (
1260 MODEST_SERVERSECURITY_COMBO_BOX (
1261 account_wizard->combo_incoming_security));
1262 if (gtk_toggle_button_get_active (
1263 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1264 && !modest_protocol_info_is_secure(security_incoming))
1266 GList* methods = check_for_supported_auth_methods(account_wizard);
1269 g_list_free(methods);
1272 g_list_free(methods);
1276 /* If this is the last page, and this is a click on Finish,
1277 * then attempt to create the dialog.
1279 if(!next_page) /* This is NULL when this is a click on Finish. */
1281 if (account_wizard->saved_account_name) {
1282 /* Just enable the already-saved account (temporarily created when
1283 * editing advanced settings): */
1284 modest_account_mgr_set_enabled (account_wizard->account_manager,
1285 account_wizard->saved_account_name, TRUE);
1287 create_account (account_wizard, TRUE /* enabled */);
1295 static gboolean entry_is_empty (GtkWidget *entry)
1300 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1301 if ((!text) || (strlen(text) == 0))
1308 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1310 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1312 gboolean enable_next = TRUE;
1313 if (current_page == account_wizard->page_welcome) {
1316 else if (current_page == account_wizard->page_account_details) {
1317 /* The account details title is mandatory: */
1318 if (entry_is_empty(account_wizard->entry_account_title))
1319 enable_next = FALSE;
1321 else if (current_page == account_wizard->page_user_details) {
1322 /* The user details username is mandatory: */
1323 if (entry_is_empty(account_wizard->entry_user_username))
1324 enable_next = FALSE;
1326 /* The user details email address is mandatory: */
1327 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1328 enable_next = FALSE;
1330 else if (current_page == account_wizard->page_custom_incoming) {
1331 /* The custom incoming server is mandatory: */
1332 if (entry_is_empty(account_wizard->entry_incomingserver))
1333 enable_next = FALSE;
1336 /* Enable the buttons,
1337 * identifying them via their associated response codes: */
1339 /* Disable the Finish button until we are on the last page,
1340 * because HildonWizardDialog enables this for all but the first page: */
1341 GtkNotebook *notebook = NULL;
1342 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1343 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1345 gint current = gtk_notebook_get_current_page (notebook);
1346 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1347 const gboolean is_last = (current == last);
1350 gtk_dialog_set_response_sensitive (dialog_base,
1351 MODEST_WIZARD_DIALOG_FINISH,
1355 /* Disable Next on the last page: */
1356 enable_next = FALSE;
1359 gtk_dialog_set_response_sensitive (dialog_base,
1360 MODEST_WIZARD_DIALOG_NEXT,
1365 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1367 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1368 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1371 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1372 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1373 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1374 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1376 /* Provide a vfunc implementation so we can decide
1377 * when to enable/disable the prev/next buttons.
1379 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1380 base_klass->before_next = on_before_next;
1381 base_klass->enable_buttons = on_enable_buttons;
1385 show_error (GtkWindow *parent_window, const gchar* text)
1387 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1389 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1396 gtk_dialog_run (dialog);
1397 gtk_widget_destroy (GTK_WIDGET (dialog));
1400 /** Attempt to create the account from the information that the user has entered.
1401 * @result: TRUE if the account was successfully created.
1404 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1406 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1408 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1414 /* We should have checked for this already,
1415 * and changed that name accordingly,
1416 * but let's check again just in case:
1418 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1421 /* Increment the non-user visible name if necessary,
1422 * based on the display name: */
1423 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1424 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1425 account_name_start, FALSE /* not a server account */);
1426 g_free (account_name_start);
1428 /* username and password (for both incoming and outgoing): */
1429 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1430 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1431 /* Incoming server: */
1432 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1433 * or modest_account_mgr_add_server_account will fail. */
1434 gchar* servername_incoming = NULL;
1435 guint serverport_incoming = 0;
1436 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1437 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1438 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1440 /* Get details from the specified presets: */
1441 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1442 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1445 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1446 TRUE /* incoming */);
1448 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1450 TRUE /* incoming */);
1451 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1453 TRUE /* incoming */);
1455 g_warning ("security incoming: %x", security_incoming);
1457 /* We don't check for SMTP here as that is impossible for an incoming server. */
1458 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1459 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1460 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1461 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1463 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1465 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1466 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1468 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1469 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1472 /* Use custom pages because no preset was specified: */
1473 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1475 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1476 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1478 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1479 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1481 /* The UI spec says:
1482 * If secure authentication is unchecked, allow sending username and password also as plain text.
1483 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1486 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1487 !modest_protocol_info_is_secure(protocol_security_incoming))
1489 GList* methods = check_for_supported_auth_methods(self);
1493 protocol_authentication_incoming = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
1496 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1499 /* First we add the 2 server accounts, and then we add the account that uses them.
1500 * If we don't do it in this order then we will experience a crash. */
1502 /* Add a (incoming) server account, to be used by the account: */
1503 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1504 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1505 store_name_start, TRUE /* server account */);
1506 g_free (store_name_start);
1507 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1509 servername_incoming,
1510 serverport_incoming,
1513 protocol_security_incoming,
1514 protocol_authentication_incoming);
1516 g_free (servername_incoming);
1519 /* TODO: Provide a Logical ID for the text: */
1520 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1524 /* Outgoing server: */
1525 gchar* servername_outgoing = NULL;
1526 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1527 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1528 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1529 guint serverport_outgoing = 0;
1533 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1534 FALSE /* incoming */);
1536 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1538 FALSE /* incoming */);
1540 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1541 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1542 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1543 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1545 ModestPresetsSecurity security_outgoing =
1546 modest_presets_get_info_server_security (priv->presets, provider_id,
1547 FALSE /* incoming */);
1549 /* TODO: There is no SMTP authentication enum for presets,
1550 so we should probably check what the server supports. */
1551 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1552 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1553 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1554 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1555 serverport_outgoing = 465;
1556 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1558 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1559 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1563 /* Use custom pages because no preset was specified: */
1564 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1566 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1568 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1569 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1571 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1572 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1575 /* Add a (outgoing) server account to be used by the account: */
1576 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1577 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1578 transport_name_start, TRUE /* server account */);
1579 g_free (transport_name_start);
1580 created = modest_account_mgr_add_server_account (self->account_manager,
1582 servername_outgoing,
1583 serverport_outgoing,
1586 protocol_security_outgoing,
1587 protocol_authentication_outgoing);
1589 g_free (servername_outgoing);
1592 /* TODO: Provide a Logical ID for the text: */
1593 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1598 /* Create the account, which will contain the two "server accounts": */
1599 created = modest_account_mgr_add_account (self->account_manager, display_name,
1600 store_name, /* The name of our POP/IMAP server account. */
1601 transport_name, /* The name of our SMTP server account. */
1603 g_free (store_name);
1604 g_free (transport_name);
1607 /* TODO: Provide a Logical ID for the text: */
1608 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1614 /* There must be at least one account now: */
1615 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1616 * fixed in versions after 3.1. */
1617 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1620 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1622 g_slist_free (account_names);
1626 /* The user name and email address must be set additionally: */
1627 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1628 modest_account_mgr_set_string (self->account_manager, account_name,
1629 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1631 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1632 modest_account_mgr_set_string (self->account_manager, account_name,
1633 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1635 /* Set the display name: */
1636 modest_account_mgr_set_string (self->account_manager, account_name,
1637 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1639 /* Set retrieve type */
1640 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1641 modest_account_mgr_set_string (self->account_manager, account_name,
1642 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1644 /* Save the connection-specific SMTP server accounts. */
1645 gboolean result = TRUE;
1646 if (self->specific_window)
1647 result = modest_connection_specific_smtp_window_save_server_accounts (
1648 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1650 g_free (self->saved_account_name);
1651 self->saved_account_name = g_strdup (account_name);
1653 g_free (account_name);