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 gchar* username = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_user_username));
170 const ModestConnectionProtocol protocol_security_incoming =
171 modest_serversecurity_combo_box_get_active_serversecurity (
172 MODEST_SERVERSECURITY_COMBO_BOX (
173 account_wizard->combo_incoming_security));
174 int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
175 GList *list_auth_methods =
176 modest_maemo_utils_get_supported_secure_authentication_methods (
178 hostname, port_num, username, GTK_WINDOW (account_wizard));
179 if (list_auth_methods) {
180 /* TODO: Select the correct method */
183 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)) {
186 list = g_list_append(list, GINT_TO_POINTER(auth));
189 g_list_free(list_auth_methods);
193 /* no secure methods supported */
194 GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(account_wizard),
195 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
196 GTK_BUTTONS_OK, _("Server does not support secure authentication!"));
197 gtk_dialog_run(GTK_DIALOG(error_dialog));
198 gtk_widget_destroy(error_dialog);
203 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
205 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
207 /* Call the vfunc, which may be overridden by derived classes: */
208 if (klass->enable_buttons) {
209 GtkNotebook *notebook = NULL;
210 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
212 const gint current_page_num = gtk_notebook_get_current_page (notebook);
213 if (current_page_num == -1)
216 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
217 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
222 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
224 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
226 invoke_enable_buttons_vfunc(self);
230 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
232 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
234 invoke_enable_buttons_vfunc(self);
237 /** This is a convenience function to create a caption containing a mandatory widget.
238 * When the widget is edited, the enable_buttons() vfunc will be called.
240 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
245 HildonCaptionStatus flag)
247 GtkWidget *caption = NULL;
249 /* Note: Previously, the translated strings already contained the "*",
250 * Comment out this code if they do again.
252 /* Add a * character to indicate mandatory fields,
253 * as specified in our "Email UI Specification": */
254 if (flag == HILDON_CAPTION_MANDATORY) {
255 gchar* title = g_strdup_printf("%s*", value);
256 caption = hildon_caption_new (group, title, control, icon, flag);
260 caption = hildon_caption_new (group, value, control, icon, flag);
262 /* Connect to the appropriate changed signal for the widget,
263 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
265 if (GTK_IS_ENTRY (control)) {
266 g_signal_connect (G_OBJECT (control), "changed",
267 G_CALLBACK (on_caption_entry_changed), self);
270 else if (GTK_IS_COMBO_BOX (control)) {
271 g_signal_connect (G_OBJECT (control), "changed",
272 G_CALLBACK (on_caption_combobox_changed), self);
279 create_page_welcome (ModestEasysetupWizardDialog *self)
281 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
282 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
283 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
284 /* So that it is not truncated: */
285 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
286 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
287 gtk_widget_show (label);
288 gtk_widget_show (GTK_WIDGET (box));
289 return GTK_WIDGET (box);
293 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
295 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
297 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
299 /* Fill the providers combo, based on the selected country: */
300 GSList *list_mcc_ids = easysetup_country_combo_box_get_active_country_ids (
301 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
302 easysetup_provider_combo_box_fill (
303 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, list_mcc_ids);
307 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
309 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
311 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
313 /* Fill the providers combo, based on the selected country: */
314 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
315 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
317 gchar* domain_name = NULL;
319 domain_name = modest_presets_get_domain (priv->presets, provider_id);
322 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
324 if (self->entry_user_email)
325 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
327 g_free (domain_name);
329 g_free (provider_id);
333 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
335 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
336 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
340 create_page_account_details (ModestEasysetupWizardDialog *self)
342 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
343 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
344 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
345 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
346 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
347 gtk_widget_show (label);
349 /* Create a size group to be used by all captions.
350 * Note that HildonCaption does not create a default size group if we do not specify one.
351 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
352 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
354 /* The country widgets: */
355 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
356 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
357 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
358 gtk_widget_show (self->combo_account_country);
359 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
360 gtk_widget_show (caption);
362 /* connect to country combo's changed signal, so we can fill the provider combo: */
363 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
364 G_CALLBACK (on_combo_account_country), self);
366 GtkWidget *separator = gtk_hseparator_new ();
367 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
368 gtk_widget_show (separator);
370 /* The service provider widgets: */
371 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
373 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
374 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
375 gtk_widget_show (self->combo_account_serviceprovider);
376 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
377 gtk_widget_show (caption);
379 /* connect to providers combo's changed signal, so we can fill the email address: */
380 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
381 G_CALLBACK (on_combo_account_serviceprovider), self);
383 /* TODO: Default to the current country somehow.
384 * But I don't know how to get the information that is specified in the
385 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
387 * This is probably not the best choice of gconf key:
388 * This is the "mcc used in the last pairing", ie. the last connection you made.
389 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
392 GConfClient *client = gconf_client_get_default ();
393 GError *error = NULL;
394 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
395 gint mcc_id = gconf_client_get_int(client, key, &error);
401 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
402 g_error_free (error);
408 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
409 * This might just be a Maemo bug.
413 /* For now, we default to Finland when there is nothing better: */
417 easysetup_country_combo_box_set_active_country_id (
418 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
421 /* The description widgets: */
422 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
423 /* Do use auto-capitalization: */
424 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
425 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
427 /* Set a default account title, choosing one that does not already exist: */
428 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
429 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
430 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
431 self->account_manager, default_account_name_start);
432 g_free (default_account_name_start);
433 default_account_name_start = NULL;
435 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
436 g_free (default_account_name);
437 default_account_name = NULL;
439 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
440 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
441 gtk_widget_show (self->entry_account_title);
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 account title,
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 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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
454 list_prevent = g_list_append (list_prevent, "“");
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 modest_validating_entry_set_unallowed_characters (
460 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
461 g_list_free (list_prevent);
463 /* Set max length as in the UI spec:
464 * The UI spec seems to want us to show a dialog if we hit the maximum. */
465 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
466 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
469 gtk_widget_show (GTK_WIDGET (box));
471 return GTK_WIDGET (box);
475 create_page_user_details (ModestEasysetupWizardDialog *self)
477 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
479 /* Create a size group to be used by all captions.
480 * Note that HildonCaption does not create a default size group if we do not specify one.
481 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
482 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
484 /* The name widgets: */
485 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
486 /* Auto-capitalization is the default, so let's turn it off: */
487 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
488 /* Set max length as in the UI spec:
489 * The UI spec seems to want us to show a dialog if we hit the maximum. */
490 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
491 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
493 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
494 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
495 gtk_widget_show (self->entry_user_name);
496 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
497 gtk_widget_show (caption);
499 /* Prevent the use of some characters in the name,
500 * as required by our UI specification: */
501 GList *list_prevent = NULL;
502 list_prevent = g_list_append (list_prevent, "<");
503 list_prevent = g_list_append (list_prevent, ">");
504 modest_validating_entry_set_unallowed_characters (
505 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
506 g_list_free (list_prevent);
508 /* The username widgets: */
509 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
510 /* Auto-capitalization is the default, so let's turn it off: */
511 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
512 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
513 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
514 gtk_widget_show (self->entry_user_username);
515 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
516 gtk_widget_show (caption);
518 /* Prevent the use of some characters in the username,
519 * as required by our UI specification: */
520 modest_validating_entry_set_unallowed_characters_whitespace (
521 MODEST_VALIDATING_ENTRY (self->entry_user_username));
523 /* Set max length as in the UI spec:
524 * The UI spec seems to want us to show a dialog if we hit the maximum. */
525 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
526 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
529 /* The password widgets: */
530 self->entry_user_password = gtk_entry_new ();
531 /* Auto-capitalization is the default, so let's turn it off: */
532 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
533 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
534 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
535 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
536 caption = create_caption_new_with_asterisk (self, sizegroup,
537 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
538 gtk_widget_show (self->entry_user_password);
539 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
540 gtk_widget_show (caption);
542 /* The email address widgets: */
543 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
544 /* Auto-capitalization is the default, so let's turn it off: */
545 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
546 caption = create_caption_new_with_asterisk (self, sizegroup,
547 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
548 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
549 gtk_widget_show (self->entry_user_email);
550 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
551 gtk_widget_show (caption);
553 /* Set max length as in the UI spec:
554 * The UI spec seems to want us to show a dialog if we hit the maximum. */
555 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
556 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
560 gtk_widget_show (GTK_WIDGET (box));
562 return GTK_WIDGET (box);
565 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
567 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
569 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
570 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
571 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
572 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
573 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
574 gtk_widget_show (label);
576 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
577 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
578 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
579 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
580 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
581 gtk_widget_show (label);
583 gtk_widget_show (GTK_WIDGET (box));
584 return GTK_WIDGET (box);
587 /** Change the caption title for the incoming server,
588 * as specified in the UI spec:
590 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
592 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
593 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
595 (protocol == MODEST_PROTOCOL_STORE_POP ?
596 _("mail_fi_emailtype_pop3") :
597 _("mail_fi_emailtype_imap") );
600 /* Note that this produces a compiler warning,
601 * because the compiler does not know that the translated string will have a %s in it.
602 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
603 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
604 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
605 g_free(incomingserver_title);
608 /** Change the caption title for the incoming server,
609 * as specified in the UI spec:
611 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
613 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
614 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
616 /* Fill the combo with appropriately titled choices for POP or IMAP. */
617 /* The choices are the same, but the titles are different, as in the UI spec. */
618 modest_serversecurity_combo_box_fill (
619 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
622 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
624 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
625 update_incoming_server_title (self);
626 update_incoming_server_security_choices (self);
628 set_default_custom_servernames (self);
631 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
633 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
634 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
635 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
638 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
640 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
642 /* Show note that account type cannot be changed in future: */
643 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
644 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
645 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
646 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
647 gtk_widget_show (label);
649 /* Create a size group to be used by all captions.
650 * Note that HildonCaption does not create a default size group if we do not specify one.
651 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
652 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
654 /* The incoming server widgets: */
655 if (!self->combo_incoming_servertype)
656 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
657 easysetup_servertype_combo_box_set_active_servertype (
658 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
659 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
660 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
661 gtk_widget_show (self->combo_incoming_servertype);
662 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
663 gtk_widget_show (caption);
665 if(!self->entry_incomingserver)
666 self->entry_incomingserver = gtk_entry_new ();
667 /* Auto-capitalization is the default, so let's turn it off: */
668 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
669 set_default_custom_servernames (self);
671 if (self->caption_incoming)
672 gtk_widget_destroy (self->caption_incoming);
674 /* The caption title will be updated in update_incoming_server_title().
675 * so this default text will never be seen: */
676 /* (Note: Changing the title seems pointless. murrayc) */
677 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
678 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
679 update_incoming_server_title (self);
680 gtk_widget_show (self->entry_incomingserver);
681 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
682 gtk_widget_show (self->caption_incoming);
684 /* Change the caption title when the servertype changes,
685 * as in the UI spec: */
686 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
687 G_CALLBACK (on_combo_servertype_changed), self);
689 /* Remember when the servername was changed manually: */
690 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
691 G_CALLBACK (on_entry_incoming_servername_changed), self);
693 /* The secure connection widgets: */
694 if (!self->combo_incoming_security)
695 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
696 update_incoming_server_security_choices (self);
697 modest_serversecurity_combo_box_set_active_serversecurity (
698 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
699 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
700 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
701 gtk_widget_show (self->combo_incoming_security);
702 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
703 gtk_widget_show (caption);
705 if(!self->checkbox_incoming_auth)
706 self->checkbox_incoming_auth = gtk_check_button_new ();
707 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
708 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
709 gtk_widget_show (self->checkbox_incoming_auth);
710 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
711 gtk_widget_show (caption);
713 gtk_widget_show (GTK_WIDGET (box));
715 return GTK_WIDGET (box);
719 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
721 GtkWidget *widget = GTK_WIDGET (user_data);
723 /* Enable the widget only if the toggle button is active: */
724 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
725 gtk_widget_set_sensitive (widget, enable);
728 /* Make the sensitivity of a widget depend on a toggle button.
731 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
733 g_signal_connect (G_OBJECT (button), "toggled",
734 G_CALLBACK (on_toggle_button_changed), widget);
736 /* Set the starting sensitivity: */
737 on_toggle_button_changed (button, widget);
741 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
743 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
745 /* Create the window, if necessary: */
746 if (!(self->specific_window)) {
747 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
748 modest_connection_specific_smtp_window_fill_with_connections (
749 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
750 NULL /* account_name, not known yet. */);
753 /* Show the window: */
754 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
755 gtk_widget_show (self->specific_window);
758 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
760 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
761 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
762 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
765 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
767 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
769 /* Create a size group to be used by all captions.
770 * Note that HildonCaption does not create a default size group if we do not specify one.
771 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
772 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
774 /* The outgoing server widgets: */
775 if (!self->entry_outgoingserver)
776 self->entry_outgoingserver = gtk_entry_new ();
777 /* Auto-capitalization is the default, so let's turn it off: */
778 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
779 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
780 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
781 gtk_widget_show (self->entry_outgoingserver);
782 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
783 gtk_widget_show (caption);
784 set_default_custom_servernames (self);
786 /* The secure connection widgets: */
787 if (!self->combo_outgoing_security)
788 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
789 modest_serversecurity_combo_box_fill (
790 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
791 modest_serversecurity_combo_box_set_active_serversecurity (
792 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
793 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
794 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
795 gtk_widget_show (self->combo_outgoing_security);
796 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
797 gtk_widget_show (caption);
799 /* The secure authentication widgets: */
800 if (!self->combo_outgoing_auth)
801 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
802 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
803 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
804 gtk_widget_show (self->combo_outgoing_auth);
805 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
806 gtk_widget_show (caption);
808 GtkWidget *separator = gtk_hseparator_new ();
809 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
810 gtk_widget_show (separator);
812 /* connection-specific checkbox: */
813 if (!self->checkbox_outgoing_smtp_specific) {
814 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
815 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
818 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
819 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
820 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
821 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
822 gtk_widget_show (caption);
824 /* Connection-specific SMTP-Severs Edit button: */
825 if (!self->button_outgoing_smtp_servers)
826 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
827 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
828 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
829 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
830 gtk_widget_show (self->button_outgoing_smtp_servers);
831 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
832 gtk_widget_show (caption);
834 /* Only enable the button when the checkbox is checked: */
835 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
836 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
838 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
839 G_CALLBACK (on_button_outgoing_smtp_servers), self);
841 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
842 G_CALLBACK (on_entry_outgoing_servername_changed), self);
845 gtk_widget_show (GTK_WIDGET (box));
847 return GTK_WIDGET (box);
851 show_advanced_edit(gpointer user_data)
853 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
855 if (!(self->saved_account_name))
858 /* Show the Account Settings window: */
859 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
860 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
862 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
864 gtk_dialog_run (GTK_DIALOG (dialog));
866 gtk_widget_destroy (GTK_WIDGET (dialog));
868 return FALSE; /* Do not call this timeout callback again. */
872 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
874 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
876 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
877 * without recoding it to use non-gconf information.
878 * This account will be deleted if Finish is never actually clicked. */
880 gboolean saved = TRUE;
881 if (!(self->saved_account_name)) {
882 saved = create_account (self, FALSE);
888 if (!(self->saved_account_name))
891 /* Show the Account Settings window: */
892 show_advanced_edit(self);
894 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
896 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
897 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
898 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
899 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
900 gtk_widget_show (label);
902 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
903 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
904 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
905 gtk_widget_show (label);
907 if (!self->button_edit)
908 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
909 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
910 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
911 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
912 gtk_widget_show (self->button_edit);
913 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
914 gtk_widget_show (caption);
916 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
917 G_CALLBACK (on_button_edit_advanced_settings), self);
919 gtk_widget_show (GTK_WIDGET (box));
920 return GTK_WIDGET (box);
927 on_response (ModestWizardDialog *wizard_dialog,
931 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
933 if (response_id == GTK_RESPONSE_CANCEL) {
934 /* Remove any temporarily-saved account that will not actually be needed: */
935 if (self->saved_account_name) {
936 modest_account_mgr_remove_account (self->account_manager,
937 self->saved_account_name, FALSE);
941 invoke_enable_buttons_vfunc (self);
945 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
947 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
949 /* Create the notebook to be used by the ModestWizardDialog base class:
950 * Each page of the notebook will be a page of the wizard: */
951 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
953 /* Set the notebook used by the ModestWizardDialog base class: */
954 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
956 /* Set the wizard title:
957 * The actual window title will be a combination of this and the page's tab label title. */
958 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
960 /* Read in the information about known service providers: */
961 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
963 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
964 priv->presets = modest_presets_new (filepath);
965 if (!(priv->presets)) {
966 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
969 g_assert(priv->presets);
971 /* The server fields did not have been manually changed yet */
972 priv->server_changes = 0;
974 /* Get the account manager object,
975 * so we can check for existing accounts,
976 * and create new accounts: */
977 self->account_manager = modest_runtime_get_account_mgr ();
978 g_assert (self->account_manager);
979 g_object_ref (self->account_manager);
981 /* Create the common pages,
983 self->page_welcome = create_page_welcome (self);
984 self->page_account_details = create_page_account_details (self);
985 self->page_user_details = create_page_user_details (self);
987 /* Add the common pages: */
988 gtk_notebook_append_page (notebook, self->page_welcome,
989 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
990 gtk_notebook_append_page (notebook, self->page_account_details,
991 gtk_label_new (_("mcen_ti_accountdetails")));
992 gtk_notebook_append_page (notebook, self->page_user_details,
993 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
995 /* Create and add the easysetup-specific pages,
996 * because we need _some_ final page to enable the Next and Finish buttons: */
997 create_subsequent_easysetup_pages (self);
999 /* Connect to the dialog's response signal so we can enable/disable buttons
1000 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1001 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1002 * so that we can be enable/disable after ModestWizardDialog has done its own
1003 * enabling/disabling of buttons.
1005 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1006 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1008 * It's not enough to connect to the notebook's switch-page signal, because
1009 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1010 * _after_ switching the page (understandably).
1011 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1012 * then gtk_notebook_get_current_page() would return an incorrect value.)
1014 g_signal_connect_after (G_OBJECT (self), "response",
1015 G_CALLBACK (on_response), self);
1017 /* When this window is shown, hibernation should not be possible,
1018 * because there is no sensible way to save the state: */
1019 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1020 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1023 ModestEasysetupWizardDialog*
1024 modest_easysetup_wizard_dialog_new (void)
1026 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1029 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1031 GtkNotebook *notebook = NULL;
1032 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1035 /* Create the custom pages: */
1036 if(!(self->page_custom_incoming)) {
1037 self->page_custom_incoming = create_page_custom_incoming (self);
1040 if(!(self->page_custom_outgoing)) {
1041 self->page_custom_outgoing = create_page_custom_outgoing (self);
1044 if(!(self->page_complete_customsetup)) {
1045 self->page_complete_customsetup = create_page_complete_custom (self);
1048 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1049 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1050 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1052 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1053 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1054 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1056 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1057 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1058 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1060 /* This is unnecessary with GTK+ 2.10: */
1061 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1064 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1066 GtkNotebook *notebook = NULL;
1067 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1070 /* Create the easysetup-specific pages: */
1071 if(!self->page_complete_easysetup)
1072 self->page_complete_easysetup = create_page_complete_easysetup (self);
1074 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1075 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1076 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1078 /* This is unnecessary with GTK+ 2.10: */
1079 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1081 /* After the user details page,
1082 * the following pages depend on whether "Other" was chosen
1083 * in the provider combobox on the account page
1085 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1087 if (easysetup_provider_combo_box_get_active_provider_id (
1088 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1089 /* "Other..." was selected: */
1091 /* Make sure that the easysetup pages do not exist: */
1092 if(self->page_complete_easysetup) {
1093 gtk_widget_destroy (self->page_complete_easysetup);
1094 self->page_complete_easysetup = NULL;
1097 create_subsequent_customsetup_pages (self);
1100 /* A specific provider was selected: */
1102 /* Make sure that the custom pages do not exist:
1103 * Because they will be used if they exist, when creating the account. */
1104 if(self->page_custom_incoming) {
1105 gtk_widget_destroy (self->page_custom_incoming);
1106 self->page_custom_incoming = NULL;
1109 if(self->page_custom_outgoing) {
1110 gtk_widget_destroy (self->page_custom_outgoing);
1111 self->page_custom_outgoing = NULL;
1114 if(self->page_complete_customsetup) {
1115 gtk_widget_destroy (self->page_complete_customsetup);
1116 self->page_complete_customsetup = NULL;
1120 /* Create the easysetup pages: */
1121 create_subsequent_easysetup_pages (self);
1127 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1132 gchar* at = g_utf8_strchr (email_address, -1, '@');
1133 if (!at || (g_utf8_strlen (at, -1) < 2))
1136 gchar* domain = g_utf8_next_char (at);
1140 const gchar* hostname = NULL;
1141 if (servertype == MODEST_PROTOCOL_STORE_POP)
1143 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1145 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1151 return g_strdup_printf ("%s.%s", hostname, domain);
1154 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1156 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1158 if (!account_wizard->entry_incomingserver)
1161 /* Set a default domain for the server, based on the email address,
1162 * if no server name was already specified.
1164 if (account_wizard->entry_user_email
1165 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1166 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1167 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1168 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1170 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1172 /* Do not set the INCOMING_CHANGED flag because of this edit */
1173 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1174 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1175 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1177 g_free (servername);
1180 /* Set a default domain for the server, based on the email address,
1181 * if no server name was already specified.
1183 if (!account_wizard->entry_outgoingserver)
1186 if (account_wizard->entry_user_email
1187 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1188 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1190 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1192 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1193 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1194 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1195 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1197 g_free (servername);
1202 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1204 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1206 /* Do extra validation that couldn't be done for every key press,
1207 * either because it was too slow,
1208 * or because it requires interaction:
1210 if (current_page == account_wizard->page_account_details) {
1211 /* Check that the title is not already in use: */
1212 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1213 if ((!account_title) || (strlen(account_title) == 0))
1216 /* Aavoid a clash with an existing display name: */
1217 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1218 account_wizard->account_manager, account_title);
1221 /* Warn the user via a dialog: */
1222 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1227 else if (current_page == account_wizard->page_user_details) {
1228 /* Check that the email address is valud: */
1229 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1230 if ((!email_address) || (strlen(email_address) == 0))
1233 if (!modest_text_utils_validate_email_address (email_address)) {
1234 /* Warn the user via a dialog: */
1235 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1237 /* Return focus to the email address entry: */
1238 gtk_widget_grab_focus (account_wizard->entry_user_email);
1239 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
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, account_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."));
1613 /* There must be at least one account now: */
1614 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1615 * fixed in versions after 3.1. */
1616 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1617 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1619 /* The user name and email address must be set additionally: */
1620 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1621 modest_account_mgr_set_string (self->account_manager, account_name,
1622 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1624 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1625 modest_account_mgr_set_string (self->account_manager, account_name,
1626 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1628 /* Set the display name: */
1629 modest_account_mgr_set_string (self->account_manager, account_name,
1630 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1632 /* Set retrieve type */
1633 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1634 modest_account_mgr_set_string (self->account_manager, account_name,
1635 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1637 /* Save the connection-specific SMTP server accounts. */
1638 gboolean result = TRUE;
1639 if (self->specific_window)
1640 result = modest_connection_specific_smtp_window_save_server_accounts (
1641 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1643 g_free (self->saved_account_name);
1644 self->saved_account_name = g_strdup (account_name);
1646 g_free (account_name);