1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "modest-easysetup-wizard.h"
32 #include <glib/gi18n.h>
33 #include <gtk/gtknotebook.h>
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkcombobox.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkseparator.h>
42 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
43 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
44 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
45 #include "widgets/modest-serversecurity-combo-box.h"
46 #include "widgets/modest-secureauth-combo-box.h"
47 #include "widgets/modest-validating-entry.h"
48 #include "modest-text-utils.h"
49 #include "modest-account-mgr.h"
50 #include "modest-account-mgr-helpers.h"
51 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
52 #include "maemo/modest-connection-specific-smtp-window.h"
53 #include "widgets/modest-ui-constants.h"
54 #include "maemo/modest-account-settings-dialog.h"
55 #include <gconf/gconf-client.h>
56 #include <string.h> /* For strlen(). */
58 /* Include config.h so that _() works: */
63 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
65 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
67 #define WIZARD_DIALOG_GET_PRIVATE(o) \
68 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
70 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
73 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
74 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
75 } ModestEasysetupWizardDialogServerChanges;
77 struct _ModestEasysetupWizardDialogPrivate
79 ModestPresets *presets;
81 /* Remember what fields the user edited manually to not prefill them
83 ModestEasysetupWizardDialogServerChanges server_changes;
87 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
88 GValue *value, GParamSpec *pspec)
90 switch (property_id) {
92 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
97 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
98 const GValue *value, GParamSpec *pspec)
100 switch (property_id) {
102 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
107 modest_easysetup_wizard_dialog_dispose (GObject *object)
109 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
110 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
114 modest_easysetup_wizard_dialog_finalize (GObject *object)
116 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
117 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
119 if (self->account_manager)
120 g_object_unref (G_OBJECT (self->account_manager));
123 modest_presets_destroy (priv->presets);
125 if (self->specific_window)
126 gtk_widget_destroy (self->specific_window);
128 g_free (self->saved_account_name);
130 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
134 show_error (GtkWindow *parent_window, const gchar* text);
137 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
140 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
143 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
145 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
148 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
150 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
152 /* Call the vfunc, which may be overridden by derived classes: */
153 if (klass->enable_buttons) {
154 GtkNotebook *notebook = NULL;
155 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
157 const gint current_page_num = gtk_notebook_get_current_page (notebook);
158 if (current_page_num == -1)
161 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
162 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
167 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
169 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
171 invoke_enable_buttons_vfunc(self);
175 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
177 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
179 invoke_enable_buttons_vfunc(self);
182 /** This is a convenience function to create a caption containing a mandatory widget.
183 * When the widget is edited, the enable_buttons() vfunc will be called.
185 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
190 HildonCaptionStatus flag)
192 GtkWidget *caption = NULL;
194 /* Note: Previously, the translated strings already contained the "*",
195 * Comment out this code if they do again.
197 /* Add a * character to indicate mandatory fields,
198 * as specified in our "Email UI Specification": */
199 if (flag == HILDON_CAPTION_MANDATORY) {
200 gchar* title = g_strdup_printf("%s*", value);
201 caption = hildon_caption_new (group, title, control, icon, flag);
205 caption = hildon_caption_new (group, value, control, icon, flag);
207 /* Connect to the appropriate changed signal for the widget,
208 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
210 if (GTK_IS_ENTRY (control)) {
211 g_signal_connect (G_OBJECT (control), "changed",
212 G_CALLBACK (on_caption_entry_changed), self);
215 else if (GTK_IS_COMBO_BOX (control)) {
216 g_signal_connect (G_OBJECT (control), "changed",
217 G_CALLBACK (on_caption_combobox_changed), self);
224 create_page_welcome (ModestEasysetupWizardDialog *self)
226 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
227 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
228 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
229 /* So that it is not truncated: */
230 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
231 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
232 gtk_widget_show (label);
233 gtk_widget_show (GTK_WIDGET (box));
234 return GTK_WIDGET (box);
238 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
240 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
242 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
244 /* Fill the providers combo, based on the selected country: */
245 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
246 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
247 easysetup_provider_combo_box_fill (
248 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
252 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
254 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
256 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
258 /* Fill the providers combo, based on the selected country: */
259 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
260 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
262 gchar* domain_name = NULL;
264 domain_name = modest_presets_get_domain (priv->presets, provider_id);
267 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
269 if (self->entry_user_email)
270 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
272 g_free (domain_name);
274 g_free (provider_id);
278 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
280 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
281 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
285 create_page_account_details (ModestEasysetupWizardDialog *self)
287 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
288 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
289 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
290 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
291 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
292 gtk_widget_show (label);
294 /* Create a size group to be used by all captions.
295 * Note that HildonCaption does not create a default size group if we do not specify one.
296 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
297 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
299 /* The country widgets: */
300 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
301 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
302 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
303 gtk_widget_show (self->combo_account_country);
304 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
305 gtk_widget_show (caption);
307 /* connect to country combo's changed signal, so we can fill the provider combo: */
308 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
309 G_CALLBACK (on_combo_account_country), self);
311 GtkWidget *separator = gtk_hseparator_new ();
312 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
313 gtk_widget_show (separator);
315 /* The service provider widgets: */
316 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
318 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
319 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
320 gtk_widget_show (self->combo_account_serviceprovider);
321 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
322 gtk_widget_show (caption);
324 /* connect to providers combo's changed signal, so we can fill the email address: */
325 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
326 G_CALLBACK (on_combo_account_serviceprovider), self);
328 /* TODO: Default to the current country somehow.
329 * But I don't know how to get the information that is specified in the
330 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
332 * This is probably not the best choice of gconf key:
333 * This is the "mcc used in the last pairing", ie. the last connection you made.
334 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
337 GConfClient *client = gconf_client_get_default ();
338 GError *error = NULL;
339 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
340 gint mcc_id = gconf_client_get_int(client, key, &error);
346 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
347 g_error_free (error);
353 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
354 * This might just be a Maemo bug.
358 /* For now, we default to Finland when there is nothing better: */
362 easysetup_country_combo_box_set_active_country_id (
363 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
366 /* The description widgets: */
367 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
368 /* Do use auto-capitalization: */
369 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
370 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
372 /* Set a default account title, choosing one that does not already exist: */
373 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
374 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
375 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
376 self->account_manager, default_account_name_start);
377 g_free (default_account_name_start);
378 default_account_name_start = NULL;
380 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
381 g_free (default_account_name);
382 default_account_name = NULL;
384 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
385 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
386 gtk_widget_show (self->entry_account_title);
387 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
388 gtk_widget_show (caption);
390 /* Prevent the use of some characters in the account title,
391 * as required by our UI specification: */
392 GList *list_prevent = NULL;
393 list_prevent = g_list_append (list_prevent, "\\");
394 list_prevent = g_list_append (list_prevent, "/");
395 list_prevent = g_list_append (list_prevent, ":");
396 list_prevent = g_list_append (list_prevent, "*");
397 list_prevent = g_list_append (list_prevent, "?");
398 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
399 list_prevent = g_list_append (list_prevent, "“");
400 list_prevent = g_list_append (list_prevent, "<");
401 list_prevent = g_list_append (list_prevent, ">");
402 list_prevent = g_list_append (list_prevent, "|");
403 list_prevent = g_list_append (list_prevent, "^");
404 modest_validating_entry_set_unallowed_characters (
405 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
406 g_list_free (list_prevent);
408 /* Set max length as in the UI spec:
409 * The UI spec seems to want us to show a dialog if we hit the maximum. */
410 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
411 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
414 gtk_widget_show (GTK_WIDGET (box));
416 return GTK_WIDGET (box);
420 create_page_user_details (ModestEasysetupWizardDialog *self)
422 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
424 /* Create a size group to be used by all captions.
425 * Note that HildonCaption does not create a default size group if we do not specify one.
426 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
427 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
429 /* The name widgets: */
430 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
431 /* Auto-capitalization is the default, so let's turn it off: */
432 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
433 /* Set max length as in the UI spec:
434 * The UI spec seems to want us to show a dialog if we hit the maximum. */
435 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
436 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
438 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
439 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
440 gtk_widget_show (self->entry_user_name);
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 name,
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 modest_validating_entry_set_unallowed_characters (
450 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
451 g_list_free (list_prevent);
453 /* The username widgets: */
454 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
455 /* Auto-capitalization is the default, so let's turn it off: */
456 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
457 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
458 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
459 gtk_widget_show (self->entry_user_username);
460 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
461 gtk_widget_show (caption);
463 /* Prevent the use of some characters in the username,
464 * as required by our UI specification: */
465 modest_validating_entry_set_unallowed_characters_whitespace (
466 MODEST_VALIDATING_ENTRY (self->entry_user_username));
468 /* Set max length as in the UI spec:
469 * The UI spec seems to want us to show a dialog if we hit the maximum. */
470 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
471 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
474 /* The password widgets: */
475 self->entry_user_password = gtk_entry_new ();
476 /* Auto-capitalization is the default, so let's turn it off: */
477 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
478 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
479 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
480 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
481 caption = create_caption_new_with_asterisk (self, sizegroup,
482 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
483 gtk_widget_show (self->entry_user_password);
484 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
485 gtk_widget_show (caption);
487 /* The email address widgets: */
488 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
489 /* Auto-capitalization is the default, so let's turn it off: */
490 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
491 caption = create_caption_new_with_asterisk (self, sizegroup,
492 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
493 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
494 gtk_widget_show (self->entry_user_email);
495 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
496 gtk_widget_show (caption);
498 /* Set max length as in the UI spec:
499 * The UI spec seems to want us to show a dialog if we hit the maximum. */
500 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
501 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
505 gtk_widget_show (GTK_WIDGET (box));
507 return GTK_WIDGET (box);
510 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
512 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
514 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
515 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
516 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
517 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
518 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
519 gtk_widget_show (label);
521 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
522 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
523 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
524 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
525 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
526 gtk_widget_show (label);
528 gtk_widget_show (GTK_WIDGET (box));
529 return GTK_WIDGET (box);
532 /** Change the caption title for the incoming server,
533 * as specified in the UI spec:
535 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
537 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
538 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
540 (protocol == MODEST_PROTOCOL_STORE_POP ?
541 _("mail_fi_emailtype_pop3") :
542 _("mail_fi_emailtype_imap") );
545 /* Note that this produces a compiler warning,
546 * because the compiler does not know that the translated string will have a %s in it.
547 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
548 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
549 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
550 g_free(incomingserver_title);
553 /** Change the caption title for the incoming server,
554 * as specified in the UI spec:
556 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
558 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
559 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
561 /* Fill the combo with appropriately titled choices for POP or IMAP. */
562 /* The choices are the same, but the titles are different, as in the UI spec. */
563 modest_serversecurity_combo_box_fill (
564 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
567 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
569 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
570 update_incoming_server_title (self);
571 update_incoming_server_security_choices (self);
573 set_default_custom_servernames (self);
576 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
578 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
579 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
580 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
583 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
585 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
587 /* Show note that account type cannot be changed in future: */
588 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
589 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
590 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
591 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
592 gtk_widget_show (label);
594 /* Create a size group to be used by all captions.
595 * Note that HildonCaption does not create a default size group if we do not specify one.
596 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
597 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
599 /* The incoming server widgets: */
600 if (!self->combo_incoming_servertype)
601 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
602 easysetup_servertype_combo_box_set_active_servertype (
603 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
604 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
605 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
606 gtk_widget_show (self->combo_incoming_servertype);
607 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
608 gtk_widget_show (caption);
610 if(!self->entry_incomingserver)
611 self->entry_incomingserver = gtk_entry_new ();
612 /* Auto-capitalization is the default, so let's turn it off: */
613 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
614 set_default_custom_servernames (self);
616 if (self->caption_incoming)
617 gtk_widget_destroy (self->caption_incoming);
619 /* The caption title will be updated in update_incoming_server_title().
620 * so this default text will never be seen: */
621 /* (Note: Changing the title seems pointless. murrayc) */
622 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
623 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
624 update_incoming_server_title (self);
625 gtk_widget_show (self->entry_incomingserver);
626 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
627 gtk_widget_show (self->caption_incoming);
629 /* Change the caption title when the servertype changes,
630 * as in the UI spec: */
631 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
632 G_CALLBACK (on_combo_servertype_changed), self);
634 /* Remember when the servername was changed manually: */
635 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
636 G_CALLBACK (on_entry_incoming_servername_changed), self);
638 /* The secure connection widgets: */
639 if (!self->combo_incoming_security)
640 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
641 update_incoming_server_security_choices (self);
642 modest_serversecurity_combo_box_set_active_serversecurity (
643 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
644 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
645 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
646 gtk_widget_show (self->combo_incoming_security);
647 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
648 gtk_widget_show (caption);
650 if(!self->checkbox_incoming_auth)
651 self->checkbox_incoming_auth = gtk_check_button_new ();
652 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
653 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
654 gtk_widget_show (self->checkbox_incoming_auth);
655 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
656 gtk_widget_show (caption);
658 gtk_widget_show (GTK_WIDGET (box));
660 return GTK_WIDGET (box);
664 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
666 GtkWidget *widget = GTK_WIDGET (user_data);
668 /* Enable the widget only if the toggle button is active: */
669 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
670 gtk_widget_set_sensitive (widget, enable);
673 /* Make the sensitivity of a widget depend on a toggle button.
676 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
678 g_signal_connect (G_OBJECT (button), "toggled",
679 G_CALLBACK (on_toggle_button_changed), widget);
681 /* Set the starting sensitivity: */
682 on_toggle_button_changed (button, widget);
686 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
688 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
690 /* Create the window, if necessary: */
691 if (!(self->specific_window)) {
692 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
693 modest_connection_specific_smtp_window_fill_with_connections (
694 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
695 NULL /* account_name, not known yet. */);
698 /* Show the window: */
699 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
700 gtk_widget_show (self->specific_window);
703 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
705 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
706 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
707 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
710 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
712 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
714 /* Create a size group to be used by all captions.
715 * Note that HildonCaption does not create a default size group if we do not specify one.
716 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
717 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
719 /* The outgoing server widgets: */
720 if (!self->entry_outgoingserver)
721 self->entry_outgoingserver = gtk_entry_new ();
722 /* Auto-capitalization is the default, so let's turn it off: */
723 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
724 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
725 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
726 gtk_widget_show (self->entry_outgoingserver);
727 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
728 gtk_widget_show (caption);
729 set_default_custom_servernames (self);
731 /* The secure connection widgets: */
732 if (!self->combo_outgoing_security)
733 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
734 modest_serversecurity_combo_box_fill (
735 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
736 modest_serversecurity_combo_box_set_active_serversecurity (
737 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
738 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
739 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
740 gtk_widget_show (self->combo_outgoing_security);
741 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
742 gtk_widget_show (caption);
744 /* The secure authentication widgets: */
745 if (!self->combo_outgoing_auth)
746 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
747 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
748 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
749 gtk_widget_show (self->combo_outgoing_auth);
750 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
751 gtk_widget_show (caption);
753 GtkWidget *separator = gtk_hseparator_new ();
754 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
755 gtk_widget_show (separator);
757 /* connection-specific checkbox: */
758 if (!self->checkbox_outgoing_smtp_specific) {
759 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
760 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
763 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
764 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
765 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
766 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
767 gtk_widget_show (caption);
769 /* Connection-specific SMTP-Severs Edit button: */
770 if (!self->button_outgoing_smtp_servers)
771 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
772 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
773 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
774 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
775 gtk_widget_show (self->button_outgoing_smtp_servers);
776 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
777 gtk_widget_show (caption);
779 /* Only enable the button when the checkbox is checked: */
780 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
781 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
783 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
784 G_CALLBACK (on_button_outgoing_smtp_servers), self);
786 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
787 G_CALLBACK (on_entry_outgoing_servername_changed), self);
790 gtk_widget_show (GTK_WIDGET (box));
792 return GTK_WIDGET (box);
796 on_timeout_show_advanced_edit(gpointer user_data)
798 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
800 if (!(self->saved_account_name))
803 /* Show the Account Settings window: */
804 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
805 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
807 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
809 gtk_dialog_run (GTK_DIALOG (dialog));
811 /* TODO: The hide() is not necessary.
812 * It is just here to show that it doesn't work,
813 * just as destroy doesn't work.
815 gtk_widget_hide (GTK_WIDGET(dialog));
817 /* TODO: The dialog remains on screen, not allowing any interaction.
818 * But gtk_widget_destroy() should always destroy.
820 printf("debug: destroying settings dialog\n");
821 gtk_widget_destroy (GTK_WIDGET (dialog));
822 printf("debug: after destroying settings dialog (doesn't seem to work).\n");
824 return FALSE; /* Do not call this timeout callback again. */
828 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
830 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
832 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
833 * without recoding it to use non-gconf information.
834 * This account will be deleted if Finish is never actually clicked. */
836 gboolean saved = TRUE;
837 gboolean was_already_saved = TRUE;
838 if (!(self->saved_account_name)) {
839 saved = create_account (self, FALSE);
840 was_already_saved = FALSE;
846 if (!(self->saved_account_name))
849 /* Show the Account Settings window: */
850 if (was_already_saved) {
851 /* Just show the dialog immediately: */
852 on_timeout_show_advanced_edit(self);
856 printf ("debug: waiting for gconf to update its local cache. "
857 "This is a hack to work around a maemo gconf bug in maemo bora.\n");
859 g_timeout_add (5000, on_timeout_show_advanced_edit, self);
862 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
864 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
865 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
866 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
867 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
868 gtk_widget_show (label);
870 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
871 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
872 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
873 gtk_widget_show (label);
875 if (!self->button_edit)
876 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
877 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
878 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
879 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
880 gtk_widget_show (self->button_edit);
881 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
882 gtk_widget_show (caption);
884 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
885 G_CALLBACK (on_button_edit_advanced_settings), self);
887 gtk_widget_show (GTK_WIDGET (box));
888 return GTK_WIDGET (box);
895 on_response (ModestWizardDialog *wizard_dialog,
899 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
901 if (response_id == GTK_RESPONSE_CANCEL) {
902 /* Remove any temporarily-saved account that will not actually be needed: */
903 if (self->saved_account_name) {
904 modest_account_mgr_remove_account (self->account_manager,
905 self->saved_account_name, FALSE);
909 invoke_enable_buttons_vfunc (self);
913 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
915 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
917 /* Create the notebook to be used by the ModestWizardDialog base class:
918 * Each page of the notebook will be a page of the wizard: */
919 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
921 /* Set the notebook used by the ModestWizardDialog base class: */
922 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
924 /* Set the wizard title:
925 * The actual window title will be a combination of this and the page's tab label title. */
926 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
928 /* Read in the information about known service providers: */
929 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
931 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
932 priv->presets = modest_presets_new (filepath);
933 if (!(priv->presets)) {
934 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
937 g_assert(priv->presets);
939 /* The server fields did not have been manually changed yet */
940 priv->server_changes = 0;
942 /* Get the account manager object,
943 * so we can check for existing accounts,
944 * and create new accounts: */
945 self->account_manager = modest_runtime_get_account_mgr ();
946 g_assert (self->account_manager);
947 g_object_ref (self->account_manager);
949 /* Create the common pages,
951 self->page_welcome = create_page_welcome (self);
952 self->page_account_details = create_page_account_details (self);
953 self->page_user_details = create_page_user_details (self);
955 /* Add the common pages: */
956 gtk_notebook_append_page (notebook, self->page_welcome,
957 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
958 gtk_notebook_append_page (notebook, self->page_account_details,
959 gtk_label_new (_("mcen_ti_accountdetails")));
960 gtk_notebook_append_page (notebook, self->page_user_details,
961 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
963 /* Create and add the easysetup-specific pages,
964 * because we need _some_ final page to enable the Next and Finish buttons: */
965 create_subsequent_easysetup_pages (self);
967 /* Connect to the dialog's response signal so we can enable/disable buttons
968 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
969 * Note that we use g_signal_connect_after() instead of g_signal_connect()
970 * so that we can be enable/disable after ModestWizardDialog has done its own
971 * enabling/disabling of buttons.
973 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
974 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
976 * It's not enough to connect to the notebook's switch-page signal, because
977 * ModestWizardDialog's "response" signal handler enables the buttons itself,
978 * _after_ switching the page (understandably).
979 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
980 * then gtk_notebook_get_current_page() would return an incorrect value.)
982 g_signal_connect_after (G_OBJECT (self), "response",
983 G_CALLBACK (on_response), self);
985 /* When this window is shown, hibernation should not be possible,
986 * because there is no sensible way to save the state: */
987 modest_window_mgr_prevent_hibernation_while_window_is_shown (
988 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
991 ModestEasysetupWizardDialog*
992 modest_easysetup_wizard_dialog_new (void)
994 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
997 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
999 GtkNotebook *notebook = NULL;
1000 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1003 /* Create the custom pages: */
1004 if(!(self->page_custom_incoming)) {
1005 self->page_custom_incoming = create_page_custom_incoming (self);
1008 if(!(self->page_custom_outgoing)) {
1009 self->page_custom_outgoing = create_page_custom_outgoing (self);
1012 if(!(self->page_complete_customsetup)) {
1013 self->page_complete_customsetup = create_page_complete_custom (self);
1016 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1017 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1018 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1020 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1021 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1022 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1024 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1025 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1026 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1028 /* This is unnecessary with GTK+ 2.10: */
1029 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1032 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1034 GtkNotebook *notebook = NULL;
1035 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1038 /* Create the easysetup-specific pages: */
1039 if(!self->page_complete_easysetup)
1040 self->page_complete_easysetup = create_page_complete_easysetup (self);
1042 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1043 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1044 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1046 /* This is unnecessary with GTK+ 2.10: */
1047 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1049 /* After the user details page,
1050 * the following pages depend on whether "Other" was chosen
1051 * in the provider combobox on the account page
1053 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1055 if (easysetup_provider_combo_box_get_active_provider_id (
1056 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1057 /* "Other..." was selected: */
1059 /* Make sure that the easysetup pages do not exist: */
1060 if(self->page_complete_easysetup) {
1061 gtk_widget_destroy (self->page_complete_easysetup);
1062 self->page_complete_easysetup = NULL;
1065 create_subsequent_customsetup_pages (self);
1068 /* A specific provider was selected: */
1070 /* Make sure that the custom pages do not exist:
1071 * Because they will be used if they exist, when creating the account. */
1072 if(self->page_custom_incoming) {
1073 gtk_widget_destroy (self->page_custom_incoming);
1074 self->page_custom_incoming = NULL;
1077 if(self->page_custom_outgoing) {
1078 gtk_widget_destroy (self->page_custom_outgoing);
1079 self->page_custom_outgoing = NULL;
1082 if(self->page_complete_customsetup) {
1083 gtk_widget_destroy (self->page_complete_customsetup);
1084 self->page_complete_customsetup = NULL;
1088 /* Create the easysetup pages: */
1089 create_subsequent_easysetup_pages (self);
1095 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1100 gchar* at = g_utf8_strchr (email_address, -1, '@');
1101 if (!at || (g_utf8_strlen (at, -1) < 2))
1104 gchar* domain = g_utf8_next_char (at);
1108 const gchar* hostname = NULL;
1109 if (servertype == MODEST_PROTOCOL_STORE_POP)
1111 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1113 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1119 return g_strdup_printf ("%s.%s", hostname, domain);
1122 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1124 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1126 if (!account_wizard->entry_incomingserver)
1129 /* Set a default domain for the server, based on the email address,
1130 * if no server name was already specified.
1132 if (account_wizard->entry_user_email
1133 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1134 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1135 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1136 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1138 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1140 /* Do not set the INCOMING_CHANGED flag because of this edit */
1141 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1142 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1143 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1145 g_free (servername);
1148 /* Set a default domain for the server, based on the email address,
1149 * if no server name was already specified.
1151 if (!account_wizard->entry_outgoingserver)
1154 if (account_wizard->entry_user_email
1155 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1156 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1158 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1160 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1161 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1162 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1163 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1165 g_free (servername);
1170 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1172 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1174 /* Do extra validation that couldn't be done for every key press,
1175 * either because it was too slow,
1176 * or because it requires interaction:
1178 if (current_page == account_wizard->page_account_details) {
1179 /* Check that the title is not already in use: */
1180 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1181 if ((!account_title) || (strlen(account_title) == 0))
1184 /* Aavoid a clash with an existing display name: */
1185 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1186 account_wizard->account_manager, account_title);
1189 /* Warn the user via a dialog: */
1190 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1195 else if (current_page == account_wizard->page_user_details) {
1196 /* Check that the email address is valud: */
1197 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1198 if ((!email_address) || (strlen(email_address) == 0))
1201 if (!modest_text_utils_validate_email_address (email_address)) {
1202 /* Warn the user via a dialog: */
1203 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1205 /* Return focus to the email address entry: */
1206 gtk_widget_grab_focus (account_wizard->entry_user_email);
1211 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1212 create_subsequent_pages (account_wizard);
1215 /* TODO: The UI Spec wants us to check that the servernames are valid,
1216 * but does not specify how.
1219 if(next_page == account_wizard->page_custom_incoming) {
1220 set_default_custom_servernames (account_wizard);
1222 else if (next_page == account_wizard->page_custom_outgoing) {
1223 set_default_custom_servernames (account_wizard);
1226 /* If this is the last page, and this is a click on Finish,
1227 * then attempt to create the dialog.
1229 if(!next_page) /* This is NULL when this is a click on Finish. */
1231 if (account_wizard->saved_account_name) {
1232 /* Just enable the already-saved account (temporarily created when
1233 * editing advanced settings): */
1234 modest_account_mgr_set_enabled (account_wizard->account_manager,
1235 account_wizard->saved_account_name, TRUE);
1237 create_account (account_wizard, TRUE /* enabled */);
1245 static gboolean entry_is_empty (GtkWidget *entry)
1250 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1251 if ((!text) || (strlen(text) == 0))
1258 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1260 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1262 gboolean enable_next = TRUE;
1263 if (current_page == account_wizard->page_welcome) {
1266 else if (current_page == account_wizard->page_account_details) {
1267 /* The account details title is mandatory: */
1268 if (entry_is_empty(account_wizard->entry_account_title))
1269 enable_next = FALSE;
1271 else if (current_page == account_wizard->page_user_details) {
1272 /* The user details username is mandatory: */
1273 if (entry_is_empty(account_wizard->entry_user_username))
1274 enable_next = FALSE;
1276 /* The user details email address is mandatory: */
1277 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1278 enable_next = FALSE;
1280 else if (current_page == account_wizard->page_custom_incoming) {
1281 /* The custom incoming server is mandatory: */
1282 if (entry_is_empty(account_wizard->entry_incomingserver))
1283 enable_next = FALSE;
1286 /* Enable the buttons,
1287 * identifying them via their associated response codes: */
1289 /* Disable the Finish button until we are on the last page,
1290 * because HildonWizardDialog enables this for all but the first page: */
1291 GtkNotebook *notebook = NULL;
1292 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1293 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1295 gint current = gtk_notebook_get_current_page (notebook);
1296 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1297 const gboolean is_last = (current == last);
1300 gtk_dialog_set_response_sensitive (dialog_base,
1301 MODEST_WIZARD_DIALOG_FINISH,
1305 /* Disable Next on the last page: */
1306 enable_next = FALSE;
1309 gtk_dialog_set_response_sensitive (dialog_base,
1310 MODEST_WIZARD_DIALOG_NEXT,
1315 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1317 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1318 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1321 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1322 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1323 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1324 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1326 /* Provide a vfunc implementation so we can decide
1327 * when to enable/disable the prev/next buttons.
1329 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1330 base_klass->before_next = on_before_next;
1331 base_klass->enable_buttons = on_enable_buttons;
1335 show_error (GtkWindow *parent_window, const gchar* text)
1337 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1339 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1346 gtk_dialog_run (dialog);
1347 gtk_widget_destroy (GTK_WIDGET (dialog));
1350 /** Attempt to create the account from the information that the user has entered.
1351 * @result: TRUE if the account was successfully created.
1354 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1356 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1358 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1364 /* We should have checked for this already,
1365 * and changed that name accordingly,
1366 * but let's check again just in case:
1368 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1371 /* Increment the non-user visible name if necessary,
1372 * based on the display name: */
1373 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1374 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1375 account_name_start, FALSE /* not a server account */);
1376 g_free (account_name_start);
1378 /* username and password (for both incoming and outgoing): */
1379 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1380 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1382 /* Incoming server: */
1383 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1384 * or modest_account_mgr_add_server_account will fail. */
1385 gchar* servername_incoming = NULL;
1386 guint serverport_incoming = 0;
1387 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1388 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1389 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1391 /* Get details from the specified presets: */
1392 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1393 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1396 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1397 TRUE /* incoming */);
1399 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1401 TRUE /* incoming */);
1402 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1404 TRUE /* incoming */);
1406 g_warning ("security incoming: %x", security_incoming);
1408 /* We don't check for SMTP here as that is impossible for an incoming server. */
1409 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1410 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1411 serverport_incoming =
1412 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
1413 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1414 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1415 serverport_incoming =
1416 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
1419 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1420 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1422 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1423 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1426 /* Use custom pages because no preset was specified: */
1427 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1429 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1430 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1432 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1433 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1435 /* The UI spec says:
1436 * If secure authentication is unchecked, allow sending username and password also as plain text.
1437 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1438 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1440 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1441 ? MODEST_PROTOCOL_AUTH_CRAMMD5
1442 : MODEST_PROTOCOL_AUTH_PASSWORD;
1445 /* First we add the 2 server accounts, and then we add the account that uses them.
1446 * If we don't do it in this order then we will experience a crash. */
1448 /* Add a (incoming) server account, to be used by the account: */
1449 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1450 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1451 store_name_start, TRUE /* server account */);
1452 g_free (store_name_start);
1453 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1455 servername_incoming,
1456 serverport_incoming,
1459 protocol_security_incoming,
1460 protocol_authentication_incoming);
1462 g_free (servername_incoming);
1465 /* TODO: Provide a Logical ID for the text: */
1466 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1471 /* There must be at least one account now: */
1472 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1473 * fixed in versions after 3.1. */
1474 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1477 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1479 g_slist_free (account_names);
1482 /* Outgoing server: */
1483 gchar* servername_outgoing = NULL;
1484 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1485 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1486 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1487 guint serverport_outgoing = 0;
1491 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1492 FALSE /* incoming */);
1494 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1496 FALSE /* incoming */);
1498 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1499 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1500 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1501 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1503 ModestPresetsSecurity security_outgoing =
1504 modest_presets_get_info_server_security (priv->presets, provider_id,
1505 FALSE /* incoming */);
1507 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1508 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1509 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1510 serverport_outgoing = 465;
1511 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1513 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1514 /* TODO: There is no SMTP authentication enum for presets. */
1517 /* Use custom pages because no preset was specified: */
1518 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1520 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1522 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1523 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1525 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1526 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1529 /* Add a (outgoing) server account to be used by the account: */
1530 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1531 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1532 transport_name_start, TRUE /* server account */);
1533 g_free (transport_name_start);
1534 created = modest_account_mgr_add_server_account (self->account_manager,
1536 servername_outgoing,
1537 serverport_outgoing,
1540 protocol_security_outgoing,
1541 protocol_authentication_outgoing);
1543 g_free (servername_outgoing);
1546 /* TODO: Provide a Logical ID for the text: */
1547 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1552 /* Create the account, which will contain the two "server accounts": */
1553 created = modest_account_mgr_add_account (self->account_manager, account_name,
1554 store_name, /* The name of our POP/IMAP server account. */
1555 transport_name, /* The name of our SMTP server account. */
1557 g_free (store_name);
1558 g_free (transport_name);
1561 /* TODO: Provide a Logical ID for the text: */
1562 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1566 /* The user name and email address must be set additionally: */
1567 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1568 modest_account_mgr_set_string (self->account_manager, account_name,
1569 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1571 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1572 modest_account_mgr_set_string (self->account_manager, account_name,
1573 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1575 /* Set the display name: */
1576 modest_account_mgr_set_string (self->account_manager, account_name,
1577 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1579 /* Set retrieve type */
1580 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1581 modest_account_mgr_set_string (self->account_manager, account_name,
1582 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1584 /* Save the connection-specific SMTP server accounts. */
1585 gboolean result = TRUE;
1586 if (self->specific_window)
1587 result = modest_connection_specific_smtp_window_save_server_accounts (
1588 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1590 g_free (self->saved_account_name);
1591 self->saved_account_name = g_strdup (account_name);
1593 g_free (account_name);