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)) {
183 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
184 if (modest_protocol_info_auth_is_secure(auth)) {
185 list = g_list_append(list, GINT_TO_POINTER(auth));
188 g_list_free(list_auth_methods);
192 /* no secure methods supported */
193 GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(account_wizard),
194 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
195 GTK_BUTTONS_OK, _("Server does not support secure authentication!"));
196 gtk_dialog_run(GTK_DIALOG(error_dialog));
197 gtk_widget_destroy(error_dialog);
202 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
204 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
206 /* Call the vfunc, which may be overridden by derived classes: */
207 if (klass->enable_buttons) {
208 GtkNotebook *notebook = NULL;
209 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
211 const gint current_page_num = gtk_notebook_get_current_page (notebook);
212 if (current_page_num == -1)
215 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
216 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
221 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
223 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
225 invoke_enable_buttons_vfunc(self);
229 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
231 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
233 invoke_enable_buttons_vfunc(self);
236 /** This is a convenience function to create a caption containing a mandatory widget.
237 * When the widget is edited, the enable_buttons() vfunc will be called.
239 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
244 HildonCaptionStatus flag)
246 GtkWidget *caption = NULL;
248 /* Note: Previously, the translated strings already contained the "*",
249 * Comment out this code if they do again.
251 /* Add a * character to indicate mandatory fields,
252 * as specified in our "Email UI Specification": */
253 if (flag == HILDON_CAPTION_MANDATORY) {
254 gchar* title = g_strdup_printf("%s*", value);
255 caption = hildon_caption_new (group, title, control, icon, flag);
259 caption = hildon_caption_new (group, value, control, icon, flag);
261 /* Connect to the appropriate changed signal for the widget,
262 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
264 if (GTK_IS_ENTRY (control)) {
265 g_signal_connect (G_OBJECT (control), "changed",
266 G_CALLBACK (on_caption_entry_changed), self);
269 else if (GTK_IS_COMBO_BOX (control)) {
270 g_signal_connect (G_OBJECT (control), "changed",
271 G_CALLBACK (on_caption_combobox_changed), self);
278 create_page_welcome (ModestEasysetupWizardDialog *self)
280 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
281 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
282 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
283 /* So that it is not truncated: */
284 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
285 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
286 gtk_widget_show (label);
287 gtk_widget_show (GTK_WIDGET (box));
288 return GTK_WIDGET (box);
292 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
294 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
296 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
298 /* Fill the providers combo, based on the selected country: */
299 GSList *list_mcc_ids = easysetup_country_combo_box_get_active_country_ids (
300 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
301 easysetup_provider_combo_box_fill (
302 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, list_mcc_ids);
306 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
308 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
310 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
312 /* Fill the providers combo, based on the selected country: */
313 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
314 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
316 gchar* domain_name = NULL;
318 domain_name = modest_presets_get_domain (priv->presets, provider_id);
321 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
323 if (self->entry_user_email)
324 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
326 g_free (domain_name);
328 g_free (provider_id);
332 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
334 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
335 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
339 create_page_account_details (ModestEasysetupWizardDialog *self)
341 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
342 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
343 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
344 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
345 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
346 gtk_widget_show (label);
348 /* Create a size group to be used by all captions.
349 * Note that HildonCaption does not create a default size group if we do not specify one.
350 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
351 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
353 /* The country widgets: */
354 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
355 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
356 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
357 gtk_widget_show (self->combo_account_country);
358 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
359 gtk_widget_show (caption);
361 /* connect to country combo's changed signal, so we can fill the provider combo: */
362 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
363 G_CALLBACK (on_combo_account_country), self);
365 GtkWidget *separator = gtk_hseparator_new ();
366 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
367 gtk_widget_show (separator);
369 /* The service provider widgets: */
370 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
372 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
373 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
374 gtk_widget_show (self->combo_account_serviceprovider);
375 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
376 gtk_widget_show (caption);
378 /* connect to providers combo's changed signal, so we can fill the email address: */
379 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
380 G_CALLBACK (on_combo_account_serviceprovider), self);
382 /* TODO: Default to the current country somehow.
383 * But I don't know how to get the information that is specified in the
384 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
386 * This is probably not the best choice of gconf key:
387 * This is the "mcc used in the last pairing", ie. the last connection you made.
388 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
391 GConfClient *client = gconf_client_get_default ();
392 GError *error = NULL;
393 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
394 gint mcc_id = gconf_client_get_int(client, key, &error);
400 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
401 g_error_free (error);
407 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
408 * This might just be a Maemo bug.
412 /* For now, we default to Finland when there is nothing better: */
416 easysetup_country_combo_box_set_active_country_id (
417 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
420 /* The description widgets: */
421 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
422 /* Do use auto-capitalization: */
423 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
424 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
426 /* Set a default account title, choosing one that does not already exist: */
427 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
428 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
429 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
430 self->account_manager, default_account_name_start);
431 g_free (default_account_name_start);
432 default_account_name_start = NULL;
434 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
435 g_free (default_account_name);
436 default_account_name = NULL;
438 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
439 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
440 gtk_widget_show (self->entry_account_title);
441 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
442 gtk_widget_show (caption);
444 /* Prevent the use of some characters in the account title,
445 * as required by our UI specification: */
446 GList *list_prevent = NULL;
447 list_prevent = g_list_append (list_prevent, "\\");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
453 list_prevent = g_list_append (list_prevent, "“");
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 modest_validating_entry_set_unallowed_characters (
459 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
460 g_list_free (list_prevent);
462 /* Set max length as in the UI spec:
463 * The UI spec seems to want us to show a dialog if we hit the maximum. */
464 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
465 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
468 gtk_widget_show (GTK_WIDGET (box));
470 return GTK_WIDGET (box);
474 create_page_user_details (ModestEasysetupWizardDialog *self)
476 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
478 /* Create a size group to be used by all captions.
479 * Note that HildonCaption does not create a default size group if we do not specify one.
480 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
481 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
483 /* The name widgets: */
484 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
485 /* Auto-capitalization is the default, so let's turn it off: */
486 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
487 /* Set max length as in the UI spec:
488 * The UI spec seems to want us to show a dialog if we hit the maximum. */
489 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
490 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
492 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
493 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
494 gtk_widget_show (self->entry_user_name);
495 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
496 gtk_widget_show (caption);
498 /* Prevent the use of some characters in the name,
499 * as required by our UI specification: */
500 GList *list_prevent = NULL;
501 list_prevent = g_list_append (list_prevent, "<");
502 list_prevent = g_list_append (list_prevent, ">");
503 modest_validating_entry_set_unallowed_characters (
504 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
505 g_list_free (list_prevent);
507 /* The username widgets: */
508 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
509 /* Auto-capitalization is the default, so let's turn it off: */
510 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
511 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
512 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
513 gtk_widget_show (self->entry_user_username);
514 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
515 gtk_widget_show (caption);
517 /* Prevent the use of some characters in the username,
518 * as required by our UI specification: */
519 modest_validating_entry_set_unallowed_characters_whitespace (
520 MODEST_VALIDATING_ENTRY (self->entry_user_username));
522 /* Set max length as in the UI spec:
523 * The UI spec seems to want us to show a dialog if we hit the maximum. */
524 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
525 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
528 /* The password widgets: */
529 self->entry_user_password = gtk_entry_new ();
530 /* Auto-capitalization is the default, so let's turn it off: */
531 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
532 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
533 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
534 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
535 caption = create_caption_new_with_asterisk (self, sizegroup,
536 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
537 gtk_widget_show (self->entry_user_password);
538 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
539 gtk_widget_show (caption);
541 /* The email address widgets: */
542 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
543 /* Auto-capitalization is the default, so let's turn it off: */
544 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
545 caption = create_caption_new_with_asterisk (self, sizegroup,
546 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
547 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
548 gtk_widget_show (self->entry_user_email);
549 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
550 gtk_widget_show (caption);
552 /* Set max length as in the UI spec:
553 * The UI spec seems to want us to show a dialog if we hit the maximum. */
554 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
555 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
559 gtk_widget_show (GTK_WIDGET (box));
561 return GTK_WIDGET (box);
564 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
566 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
568 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
569 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
570 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
571 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
572 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
573 gtk_widget_show (label);
575 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
576 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
577 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
578 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
579 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
580 gtk_widget_show (label);
582 gtk_widget_show (GTK_WIDGET (box));
583 return GTK_WIDGET (box);
586 /** Change the caption title for the incoming server,
587 * as specified in the UI spec:
589 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
591 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
592 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
594 (protocol == MODEST_PROTOCOL_STORE_POP ?
595 _("mail_fi_emailtype_pop3") :
596 _("mail_fi_emailtype_imap") );
599 /* Note that this produces a compiler warning,
600 * because the compiler does not know that the translated string will have a %s in it.
601 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
602 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
603 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
604 g_free(incomingserver_title);
607 /** Change the caption title for the incoming server,
608 * as specified in the UI spec:
610 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
612 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
613 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
615 /* Fill the combo with appropriately titled choices for POP or IMAP. */
616 /* The choices are the same, but the titles are different, as in the UI spec. */
617 modest_serversecurity_combo_box_fill (
618 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
621 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
623 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
624 update_incoming_server_title (self);
625 update_incoming_server_security_choices (self);
627 set_default_custom_servernames (self);
630 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
632 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
633 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
634 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
637 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
639 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
641 /* Show note that account type cannot be changed in future: */
642 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
643 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
644 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
645 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
646 gtk_widget_show (label);
648 /* Create a size group to be used by all captions.
649 * Note that HildonCaption does not create a default size group if we do not specify one.
650 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
651 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
653 /* The incoming server widgets: */
654 if (!self->combo_incoming_servertype)
655 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
656 easysetup_servertype_combo_box_set_active_servertype (
657 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
658 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
659 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
660 gtk_widget_show (self->combo_incoming_servertype);
661 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
662 gtk_widget_show (caption);
664 if(!self->entry_incomingserver)
665 self->entry_incomingserver = gtk_entry_new ();
666 /* Auto-capitalization is the default, so let's turn it off: */
667 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
668 set_default_custom_servernames (self);
670 if (self->caption_incoming)
671 gtk_widget_destroy (self->caption_incoming);
673 /* The caption title will be updated in update_incoming_server_title().
674 * so this default text will never be seen: */
675 /* (Note: Changing the title seems pointless. murrayc) */
676 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
677 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
678 update_incoming_server_title (self);
679 gtk_widget_show (self->entry_incomingserver);
680 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
681 gtk_widget_show (self->caption_incoming);
683 /* Change the caption title when the servertype changes,
684 * as in the UI spec: */
685 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
686 G_CALLBACK (on_combo_servertype_changed), self);
688 /* Remember when the servername was changed manually: */
689 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
690 G_CALLBACK (on_entry_incoming_servername_changed), self);
692 /* The secure connection widgets: */
693 if (!self->combo_incoming_security)
694 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
695 update_incoming_server_security_choices (self);
696 modest_serversecurity_combo_box_set_active_serversecurity (
697 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
698 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
699 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
700 gtk_widget_show (self->combo_incoming_security);
701 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
702 gtk_widget_show (caption);
704 if(!self->checkbox_incoming_auth)
705 self->checkbox_incoming_auth = gtk_check_button_new ();
706 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
707 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
708 gtk_widget_show (self->checkbox_incoming_auth);
709 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
710 gtk_widget_show (caption);
712 gtk_widget_show (GTK_WIDGET (box));
714 return GTK_WIDGET (box);
718 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
720 GtkWidget *widget = GTK_WIDGET (user_data);
722 /* Enable the widget only if the toggle button is active: */
723 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
724 gtk_widget_set_sensitive (widget, enable);
727 /* Make the sensitivity of a widget depend on a toggle button.
730 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
732 g_signal_connect (G_OBJECT (button), "toggled",
733 G_CALLBACK (on_toggle_button_changed), widget);
735 /* Set the starting sensitivity: */
736 on_toggle_button_changed (button, widget);
740 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
742 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
744 /* Create the window, if necessary: */
745 if (!(self->specific_window)) {
746 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
747 modest_connection_specific_smtp_window_fill_with_connections (
748 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
749 NULL /* account_name, not known yet. */);
752 /* Show the window: */
753 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
754 gtk_widget_show (self->specific_window);
757 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
759 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
760 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
761 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
764 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
766 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
768 /* Create a size group to be used by all captions.
769 * Note that HildonCaption does not create a default size group if we do not specify one.
770 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
771 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
773 /* The outgoing server widgets: */
774 if (!self->entry_outgoingserver)
775 self->entry_outgoingserver = gtk_entry_new ();
776 /* Auto-capitalization is the default, so let's turn it off: */
777 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
778 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
779 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
780 gtk_widget_show (self->entry_outgoingserver);
781 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
782 gtk_widget_show (caption);
783 set_default_custom_servernames (self);
785 /* The secure connection widgets: */
786 if (!self->combo_outgoing_security)
787 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
788 modest_serversecurity_combo_box_fill (
789 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
790 modest_serversecurity_combo_box_set_active_serversecurity (
791 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
792 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
793 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
794 gtk_widget_show (self->combo_outgoing_security);
795 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
796 gtk_widget_show (caption);
798 /* The secure authentication widgets: */
799 if (!self->combo_outgoing_auth)
800 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
801 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
802 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
803 gtk_widget_show (self->combo_outgoing_auth);
804 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
805 gtk_widget_show (caption);
807 GtkWidget *separator = gtk_hseparator_new ();
808 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
809 gtk_widget_show (separator);
811 /* connection-specific checkbox: */
812 if (!self->checkbox_outgoing_smtp_specific) {
813 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
814 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
817 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
818 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
819 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
820 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
821 gtk_widget_show (caption);
823 /* Connection-specific SMTP-Severs Edit button: */
824 if (!self->button_outgoing_smtp_servers)
825 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
826 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
827 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
828 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
829 gtk_widget_show (self->button_outgoing_smtp_servers);
830 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
831 gtk_widget_show (caption);
833 /* Only enable the button when the checkbox is checked: */
834 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
835 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
837 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
838 G_CALLBACK (on_button_outgoing_smtp_servers), self);
840 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
841 G_CALLBACK (on_entry_outgoing_servername_changed), self);
844 gtk_widget_show (GTK_WIDGET (box));
846 return GTK_WIDGET (box);
850 show_advanced_edit(gpointer user_data)
852 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
854 if (!(self->saved_account_name))
857 /* Show the Account Settings window: */
858 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
859 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
861 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
863 gtk_dialog_run (GTK_DIALOG (dialog));
865 gtk_widget_destroy (GTK_WIDGET (dialog));
867 return FALSE; /* Do not call this timeout callback again. */
871 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
873 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
875 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
876 * without recoding it to use non-gconf information.
877 * This account will be deleted if Finish is never actually clicked. */
879 gboolean saved = TRUE;
880 if (!(self->saved_account_name)) {
881 saved = create_account (self, FALSE);
887 if (!(self->saved_account_name))
890 /* Show the Account Settings window: */
891 show_advanced_edit(self);
893 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
895 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
896 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
897 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
898 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
899 gtk_widget_show (label);
901 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
902 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
903 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
904 gtk_widget_show (label);
906 if (!self->button_edit)
907 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
908 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
909 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
910 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
911 gtk_widget_show (self->button_edit);
912 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
913 gtk_widget_show (caption);
915 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
916 G_CALLBACK (on_button_edit_advanced_settings), self);
918 gtk_widget_show (GTK_WIDGET (box));
919 return GTK_WIDGET (box);
926 on_response (ModestWizardDialog *wizard_dialog,
930 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
932 if (response_id == GTK_RESPONSE_CANCEL) {
933 /* Remove any temporarily-saved account that will not actually be needed: */
934 if (self->saved_account_name) {
935 modest_account_mgr_remove_account (self->account_manager,
936 self->saved_account_name, FALSE);
940 invoke_enable_buttons_vfunc (self);
944 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
946 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
948 /* Create the notebook to be used by the ModestWizardDialog base class:
949 * Each page of the notebook will be a page of the wizard: */
950 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
952 /* Set the notebook used by the ModestWizardDialog base class: */
953 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
955 /* Set the wizard title:
956 * The actual window title will be a combination of this and the page's tab label title. */
957 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
959 /* Read in the information about known service providers: */
960 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
962 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
963 priv->presets = modest_presets_new (filepath);
964 if (!(priv->presets)) {
965 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
968 g_assert(priv->presets);
970 /* The server fields did not have been manually changed yet */
971 priv->server_changes = 0;
973 /* Get the account manager object,
974 * so we can check for existing accounts,
975 * and create new accounts: */
976 self->account_manager = modest_runtime_get_account_mgr ();
977 g_assert (self->account_manager);
978 g_object_ref (self->account_manager);
980 /* Create the common pages,
982 self->page_welcome = create_page_welcome (self);
983 self->page_account_details = create_page_account_details (self);
984 self->page_user_details = create_page_user_details (self);
986 /* Add the common pages: */
987 gtk_notebook_append_page (notebook, self->page_welcome,
988 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
989 gtk_notebook_append_page (notebook, self->page_account_details,
990 gtk_label_new (_("mcen_ti_accountdetails")));
991 gtk_notebook_append_page (notebook, self->page_user_details,
992 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
994 /* Create and add the easysetup-specific pages,
995 * because we need _some_ final page to enable the Next and Finish buttons: */
996 create_subsequent_easysetup_pages (self);
998 /* Connect to the dialog's response signal so we can enable/disable buttons
999 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1000 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1001 * so that we can be enable/disable after ModestWizardDialog has done its own
1002 * enabling/disabling of buttons.
1004 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1005 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1007 * It's not enough to connect to the notebook's switch-page signal, because
1008 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1009 * _after_ switching the page (understandably).
1010 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1011 * then gtk_notebook_get_current_page() would return an incorrect value.)
1013 g_signal_connect_after (G_OBJECT (self), "response",
1014 G_CALLBACK (on_response), self);
1016 /* When this window is shown, hibernation should not be possible,
1017 * because there is no sensible way to save the state: */
1018 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1019 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1022 ModestEasysetupWizardDialog*
1023 modest_easysetup_wizard_dialog_new (void)
1025 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1028 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1030 GtkNotebook *notebook = NULL;
1031 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1034 /* Create the custom pages: */
1035 if(!(self->page_custom_incoming)) {
1036 self->page_custom_incoming = create_page_custom_incoming (self);
1039 if(!(self->page_custom_outgoing)) {
1040 self->page_custom_outgoing = create_page_custom_outgoing (self);
1043 if(!(self->page_complete_customsetup)) {
1044 self->page_complete_customsetup = create_page_complete_custom (self);
1047 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1048 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1049 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1051 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1052 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1053 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1055 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1056 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1057 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1059 /* This is unnecessary with GTK+ 2.10: */
1060 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1063 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1065 GtkNotebook *notebook = NULL;
1066 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1069 /* Create the easysetup-specific pages: */
1070 if(!self->page_complete_easysetup)
1071 self->page_complete_easysetup = create_page_complete_easysetup (self);
1073 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1074 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1075 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1077 /* This is unnecessary with GTK+ 2.10: */
1078 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1080 /* After the user details page,
1081 * the following pages depend on whether "Other" was chosen
1082 * in the provider combobox on the account page
1084 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1086 if (easysetup_provider_combo_box_get_active_provider_id (
1087 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1088 /* "Other..." was selected: */
1090 /* Make sure that the easysetup pages do not exist: */
1091 if(self->page_complete_easysetup) {
1092 gtk_widget_destroy (self->page_complete_easysetup);
1093 self->page_complete_easysetup = NULL;
1096 create_subsequent_customsetup_pages (self);
1099 /* A specific provider was selected: */
1101 /* Make sure that the custom pages do not exist:
1102 * Because they will be used if they exist, when creating the account. */
1103 if(self->page_custom_incoming) {
1104 gtk_widget_destroy (self->page_custom_incoming);
1105 self->page_custom_incoming = NULL;
1108 if(self->page_custom_outgoing) {
1109 gtk_widget_destroy (self->page_custom_outgoing);
1110 self->page_custom_outgoing = NULL;
1113 if(self->page_complete_customsetup) {
1114 gtk_widget_destroy (self->page_complete_customsetup);
1115 self->page_complete_customsetup = NULL;
1119 /* Create the easysetup pages: */
1120 create_subsequent_easysetup_pages (self);
1126 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1131 gchar* at = g_utf8_strchr (email_address, -1, '@');
1132 if (!at || (g_utf8_strlen (at, -1) < 2))
1135 gchar* domain = g_utf8_next_char (at);
1139 const gchar* hostname = NULL;
1140 if (servertype == MODEST_PROTOCOL_STORE_POP)
1142 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1144 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1150 return g_strdup_printf ("%s.%s", hostname, domain);
1153 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1155 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1157 if (!account_wizard->entry_incomingserver)
1160 /* Set a default domain for the server, based on the email address,
1161 * if no server name was already specified.
1163 if (account_wizard->entry_user_email
1164 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1165 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1166 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1167 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1169 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1171 /* Do not set the INCOMING_CHANGED flag because of this edit */
1172 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1173 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1174 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1176 g_free (servername);
1179 /* Set a default domain for the server, based on the email address,
1180 * if no server name was already specified.
1182 if (!account_wizard->entry_outgoingserver)
1185 if (account_wizard->entry_user_email
1186 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1187 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1189 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1191 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1192 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1193 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1194 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1196 g_free (servername);
1201 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1203 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1205 /* Do extra validation that couldn't be done for every key press,
1206 * either because it was too slow,
1207 * or because it requires interaction:
1209 if (current_page == account_wizard->page_account_details) {
1210 /* Check that the title is not already in use: */
1211 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1212 if ((!account_title) || (strlen(account_title) == 0))
1215 /* Aavoid a clash with an existing display name: */
1216 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1217 account_wizard->account_manager, account_title);
1220 /* Warn the user via a dialog: */
1221 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1226 else if (current_page == account_wizard->page_user_details) {
1227 /* Check that the email address is valud: */
1228 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1229 if ((!email_address) || (strlen(email_address) == 0))
1232 if (!modest_text_utils_validate_email_address (email_address)) {
1233 /* Warn the user via a dialog: */
1234 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1236 /* Return focus to the email address entry: */
1237 gtk_widget_grab_focus (account_wizard->entry_user_email);
1238 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1243 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1244 create_subsequent_pages (account_wizard);
1247 /* TODO: The UI Spec wants us to check that the servernames are valid,
1248 * but does not specify how.
1251 if(next_page == account_wizard->page_custom_incoming) {
1252 set_default_custom_servernames (account_wizard);
1254 else if (next_page == account_wizard->page_custom_outgoing) {
1255 set_default_custom_servernames (account_wizard);
1256 /* Check if the server supports secure authentication */
1257 const ModestConnectionProtocol security_incoming =
1258 modest_serversecurity_combo_box_get_active_serversecurity (
1259 MODEST_SERVERSECURITY_COMBO_BOX (
1260 account_wizard->combo_incoming_security));
1261 if (gtk_toggle_button_get_active (
1262 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1263 && !modest_protocol_info_is_secure(security_incoming))
1265 GList* methods = check_for_supported_auth_methods(account_wizard);
1268 g_list_free(methods);
1271 g_list_free(methods);
1275 /* If this is the last page, and this is a click on Finish,
1276 * then attempt to create the dialog.
1278 if(!next_page) /* This is NULL when this is a click on Finish. */
1280 if (account_wizard->saved_account_name) {
1281 /* Just enable the already-saved account (temporarily created when
1282 * editing advanced settings): */
1283 modest_account_mgr_set_enabled (account_wizard->account_manager,
1284 account_wizard->saved_account_name, TRUE);
1286 create_account (account_wizard, TRUE /* enabled */);
1294 static gboolean entry_is_empty (GtkWidget *entry)
1299 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1300 if ((!text) || (strlen(text) == 0))
1307 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1309 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1311 gboolean enable_next = TRUE;
1312 if (current_page == account_wizard->page_welcome) {
1315 else if (current_page == account_wizard->page_account_details) {
1316 /* The account details title is mandatory: */
1317 if (entry_is_empty(account_wizard->entry_account_title))
1318 enable_next = FALSE;
1320 else if (current_page == account_wizard->page_user_details) {
1321 /* The user details username is mandatory: */
1322 if (entry_is_empty(account_wizard->entry_user_username))
1323 enable_next = FALSE;
1325 /* The user details email address is mandatory: */
1326 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1327 enable_next = FALSE;
1329 else if (current_page == account_wizard->page_custom_incoming) {
1330 /* The custom incoming server is mandatory: */
1331 if (entry_is_empty(account_wizard->entry_incomingserver))
1332 enable_next = FALSE;
1335 /* Enable the buttons,
1336 * identifying them via their associated response codes: */
1338 /* Disable the Finish button until we are on the last page,
1339 * because HildonWizardDialog enables this for all but the first page: */
1340 GtkNotebook *notebook = NULL;
1341 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1342 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1344 gint current = gtk_notebook_get_current_page (notebook);
1345 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1346 const gboolean is_last = (current == last);
1349 gtk_dialog_set_response_sensitive (dialog_base,
1350 MODEST_WIZARD_DIALOG_FINISH,
1354 /* Disable Next on the last page: */
1355 enable_next = FALSE;
1358 gtk_dialog_set_response_sensitive (dialog_base,
1359 MODEST_WIZARD_DIALOG_NEXT,
1364 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1366 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1367 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1370 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1371 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1372 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1373 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1375 /* Provide a vfunc implementation so we can decide
1376 * when to enable/disable the prev/next buttons.
1378 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1379 base_klass->before_next = on_before_next;
1380 base_klass->enable_buttons = on_enable_buttons;
1384 show_error (GtkWindow *parent_window, const gchar* text)
1386 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1388 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1395 gtk_dialog_run (dialog);
1396 gtk_widget_destroy (GTK_WIDGET (dialog));
1399 /** Attempt to create the account from the information that the user has entered.
1400 * @result: TRUE if the account was successfully created.
1403 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1405 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1407 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1413 /* We should have checked for this already,
1414 * and changed that name accordingly,
1415 * but let's check again just in case:
1417 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1420 /* Increment the non-user visible name if necessary,
1421 * based on the display name: */
1422 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1423 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1424 account_name_start, FALSE /* not a server account */);
1425 g_free (account_name_start);
1427 /* username and password (for both incoming and outgoing): */
1428 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1429 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1430 /* Incoming server: */
1431 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1432 * or modest_account_mgr_add_server_account will fail. */
1433 gchar* servername_incoming = NULL;
1434 guint serverport_incoming = 0;
1435 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1436 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1437 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1439 /* Get details from the specified presets: */
1440 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1441 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1444 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1445 TRUE /* incoming */);
1447 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1449 TRUE /* incoming */);
1450 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1452 TRUE /* incoming */);
1454 g_warning ("security incoming: %x", security_incoming);
1456 /* We don't check for SMTP here as that is impossible for an incoming server. */
1457 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1458 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1459 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1460 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1462 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1464 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1465 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1467 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1468 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1471 /* Use custom pages because no preset was specified: */
1472 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1474 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1475 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1477 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1478 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1480 /* The UI spec says:
1481 * If secure authentication is unchecked, allow sending username and password also as plain text.
1482 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1485 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1486 !modest_protocol_info_is_secure(protocol_security_incoming))
1488 GList* methods = check_for_supported_auth_methods(self);
1492 protocol_authentication_incoming = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
1495 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1498 /* First we add the 2 server accounts, and then we add the account that uses them.
1499 * If we don't do it in this order then we will experience a crash. */
1501 /* Add a (incoming) server account, to be used by the account: */
1502 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1503 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1504 store_name_start, TRUE /* server account */);
1505 g_free (store_name_start);
1506 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1508 servername_incoming,
1509 serverport_incoming,
1512 protocol_security_incoming,
1513 protocol_authentication_incoming);
1515 g_free (servername_incoming);
1518 /* TODO: Provide a Logical ID for the text: */
1519 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1523 /* Outgoing server: */
1524 gchar* servername_outgoing = NULL;
1525 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1526 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1527 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1528 guint serverport_outgoing = 0;
1532 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1533 FALSE /* incoming */);
1535 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1537 FALSE /* incoming */);
1539 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1540 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1541 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1542 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1544 ModestPresetsSecurity security_outgoing =
1545 modest_presets_get_info_server_security (priv->presets, provider_id,
1546 FALSE /* incoming */);
1548 /* TODO: There is no SMTP authentication enum for presets,
1549 so we should probably check what the server supports. */
1550 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1551 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1552 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1553 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1554 serverport_outgoing = 465;
1555 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1557 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1558 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1562 /* Use custom pages because no preset was specified: */
1563 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1565 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1567 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1568 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1570 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1571 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1574 /* Add a (outgoing) server account to be used by the account: */
1575 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1576 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1577 transport_name_start, TRUE /* server account */);
1578 g_free (transport_name_start);
1579 created = modest_account_mgr_add_server_account (self->account_manager,
1581 servername_outgoing,
1582 serverport_outgoing,
1585 protocol_security_outgoing,
1586 protocol_authentication_outgoing);
1588 g_free (servername_outgoing);
1591 /* TODO: Provide a Logical ID for the text: */
1592 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1597 /* Create the account, which will contain the two "server accounts": */
1598 created = modest_account_mgr_add_account (self->account_manager, account_name,
1599 store_name, /* The name of our POP/IMAP server account. */
1600 transport_name, /* The name of our SMTP server account. */
1602 g_free (store_name);
1603 g_free (transport_name);
1606 /* TODO: Provide a Logical ID for the text: */
1607 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1612 /* There must be at least one account now: */
1613 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1614 * fixed in versions after 3.1. */
1615 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1616 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1618 /* The user name and email address must be set additionally: */
1619 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1620 modest_account_mgr_set_string (self->account_manager, account_name,
1621 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1623 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1624 modest_account_mgr_set_string (self->account_manager, account_name,
1625 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1627 /* Set the display name: */
1628 modest_account_mgr_set_string (self->account_manager, account_name,
1629 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1631 /* Set retrieve type */
1632 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1633 modest_account_mgr_set_string (self->account_manager, account_name,
1634 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1636 /* Save the connection-specific SMTP server accounts. */
1637 gboolean result = TRUE;
1638 if (self->specific_window)
1639 result = modest_connection_specific_smtp_window_save_server_accounts (
1640 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1642 g_free (self->saved_account_name);
1643 self->saved_account_name = g_strdup (account_name);
1645 g_free (account_name);