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;
72 struct _ModestEasysetupWizardDialogPrivate
74 ModestPresets *presets;
78 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
79 GValue *value, GParamSpec *pspec)
81 switch (property_id) {
83 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
88 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
89 const GValue *value, GParamSpec *pspec)
91 switch (property_id) {
93 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
98 modest_easysetup_wizard_dialog_dispose (GObject *object)
100 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
101 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
105 modest_easysetup_wizard_dialog_finalize (GObject *object)
107 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
108 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
110 if (self->account_manager)
111 g_object_unref (G_OBJECT (self->account_manager));
114 modest_presets_destroy (priv->presets);
116 if (self->specific_window)
117 gtk_widget_destroy (self->specific_window);
119 g_free (self->saved_account_name);
121 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
125 show_error (GtkWindow *parent_window, const gchar* text);
128 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
131 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
134 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
136 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
139 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
141 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
143 /* Call the vfunc, which may be overridden by derived classes: */
144 if (klass->enable_buttons) {
145 GtkNotebook *notebook = NULL;
146 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
148 const gint current_page_num = gtk_notebook_get_current_page (notebook);
149 if (current_page_num == -1)
152 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
153 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
158 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
160 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
162 invoke_enable_buttons_vfunc(self);
166 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
168 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
170 invoke_enable_buttons_vfunc(self);
173 /** This is a convenience function to create a caption containing a mandatory widget.
174 * When the widget is edited, the enable_buttons() vfunc will be called.
176 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
181 HildonCaptionStatus flag)
183 GtkWidget *caption = NULL;
185 /* Note: Previously, the translated strings already contained the "*",
186 * Comment out this code if they do again.
188 /* Add a * character to indicate mandatory fields,
189 * as specified in our "Email UI Specification": */
190 if (flag == HILDON_CAPTION_MANDATORY) {
191 gchar* title = g_strdup_printf("%s*", value);
192 caption = hildon_caption_new (group, title, control, icon, flag);
196 caption = hildon_caption_new (group, value, control, icon, flag);
198 /* Connect to the appropriate changed signal for the widget,
199 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
201 if (GTK_IS_ENTRY (control)) {
202 g_signal_connect (G_OBJECT (control), "changed",
203 G_CALLBACK (on_caption_entry_changed), self);
206 else if (GTK_IS_COMBO_BOX (control)) {
207 g_signal_connect (G_OBJECT (control), "changed",
208 G_CALLBACK (on_caption_combobox_changed), self);
215 create_page_welcome (ModestEasysetupWizardDialog *self)
217 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
218 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
219 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
220 gtk_widget_show (label);
221 gtk_widget_show (GTK_WIDGET (box));
222 return GTK_WIDGET (box);
226 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
228 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
230 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
232 /* Fill the providers combo, based on the selected country: */
233 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
234 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
235 easysetup_provider_combo_box_fill (
236 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
240 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
242 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
244 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
246 /* Fill the providers combo, based on the selected country: */
247 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
248 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
250 gchar* domain_name = NULL;
252 domain_name = modest_presets_get_domain (priv->presets, provider_id);
255 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
257 if (self->entry_user_email)
258 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
260 g_free (domain_name);
262 g_free (provider_id);
266 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
268 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
269 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
273 create_page_account_details (ModestEasysetupWizardDialog *self)
275 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
276 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
277 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
278 gtk_widget_show (label);
280 /* Create a size group to be used by all captions.
281 * Note that HildonCaption does not create a default size group if we do not specify one.
282 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
283 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
285 /* The country widgets: */
286 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
287 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
288 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
289 gtk_widget_show (self->combo_account_country);
290 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
291 gtk_widget_show (caption);
293 /* connect to country combo's changed signal, so we can fill the provider combo: */
294 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
295 G_CALLBACK (on_combo_account_country), self);
297 GtkWidget *separator = gtk_hseparator_new ();
298 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
299 gtk_widget_show (separator);
301 /* The service provider widgets: */
302 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
304 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
305 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
306 gtk_widget_show (self->combo_account_serviceprovider);
307 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
308 gtk_widget_show (caption);
310 /* connect to providers combo's changed signal, so we can fill the email address: */
311 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
312 G_CALLBACK (on_combo_account_serviceprovider), self);
314 /* TODO: Default to the current country somehow.
315 * But I don't know how to get the information that is specified in the
316 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
318 * This is probably not the best choice of gconf key:
319 * This is the "mcc used in the last pairing", ie. the last connection you made.
320 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
323 GConfClient *client = gconf_client_get_default ();
324 GError *error = NULL;
325 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
326 gint mcc_id = gconf_client_get_int(client, key, &error);
332 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
333 g_error_free (error);
339 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
340 * This might just be a Maemo bug.
344 /* For now, we default to Finland when there is nothing better: */
348 easysetup_country_combo_box_set_active_country_id (
349 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
352 /* The description widgets: */
353 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
354 /* Do use auto-capitalization: */
355 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
356 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
358 /* Set a default account title, choosing one that does not already exist: */
359 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
360 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
361 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
362 self->account_manager, default_account_name_start);
363 g_free (default_account_name_start);
364 default_account_name_start = NULL;
366 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
367 g_free (default_account_name);
368 default_account_name = NULL;
370 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
371 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
372 gtk_widget_show (self->entry_account_title);
373 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
374 gtk_widget_show (caption);
376 /* Prevent the use of some characters in the account title,
377 * as required by our UI specification: */
378 GList *list_prevent = NULL;
379 list_prevent = g_list_append (list_prevent, "\\");
380 list_prevent = g_list_append (list_prevent, "/");
381 list_prevent = g_list_append (list_prevent, ":");
382 list_prevent = g_list_append (list_prevent, "*");
383 list_prevent = g_list_append (list_prevent, "?");
384 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
385 list_prevent = g_list_append (list_prevent, "“");
386 list_prevent = g_list_append (list_prevent, "<");
387 list_prevent = g_list_append (list_prevent, ">");
388 list_prevent = g_list_append (list_prevent, "|");
389 list_prevent = g_list_append (list_prevent, "^");
390 modest_validating_entry_set_unallowed_characters (
391 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
392 g_list_free (list_prevent);
394 /* Set max length as in the UI spec:
395 * The UI spec seems to want us to show a dialog if we hit the maximum. */
396 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
397 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
400 gtk_widget_show (GTK_WIDGET (box));
402 return GTK_WIDGET (box);
406 create_page_user_details (ModestEasysetupWizardDialog *self)
408 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
410 /* Create a size group to be used by all captions.
411 * Note that HildonCaption does not create a default size group if we do not specify one.
412 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
413 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
415 /* The name widgets: */
416 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
417 /* Auto-capitalization is the default, so let's turn it off: */
418 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
419 /* Set max length as in the UI spec:
420 * The UI spec seems to want us to show a dialog if we hit the maximum. */
421 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
422 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
424 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
425 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
426 gtk_widget_show (self->entry_user_name);
427 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
428 gtk_widget_show (caption);
430 /* Prevent the use of some characters in the name,
431 * as required by our UI specification: */
432 GList *list_prevent = NULL;
433 list_prevent = g_list_append (list_prevent, "<");
434 list_prevent = g_list_append (list_prevent, ">");
435 modest_validating_entry_set_unallowed_characters (
436 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
437 g_list_free (list_prevent);
439 /* The username widgets: */
440 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
441 /* Auto-capitalization is the default, so let's turn it off: */
442 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
443 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
444 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
445 gtk_widget_show (self->entry_user_username);
446 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
447 gtk_widget_show (caption);
449 /* Prevent the use of some characters in the username,
450 * as required by our UI specification: */
451 modest_validating_entry_set_unallowed_characters_whitespace (
452 MODEST_VALIDATING_ENTRY (self->entry_user_username));
454 /* Set max length as in the UI spec:
455 * The UI spec seems to want us to show a dialog if we hit the maximum. */
456 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
457 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
460 /* The password widgets: */
461 self->entry_user_password = gtk_entry_new ();
462 /* Auto-capitalization is the default, so let's turn it off: */
463 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
464 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
465 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
466 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
467 caption = create_caption_new_with_asterisk (self, sizegroup,
468 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
469 gtk_widget_show (self->entry_user_password);
470 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
471 gtk_widget_show (caption);
473 /* The email address widgets: */
474 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
475 /* Auto-capitalization is the default, so let's turn it off: */
476 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
477 caption = create_caption_new_with_asterisk (self, sizegroup,
478 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
479 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
480 gtk_widget_show (self->entry_user_email);
481 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
482 gtk_widget_show (caption);
484 /* Set max length as in the UI spec:
485 * The UI spec seems to want us to show a dialog if we hit the maximum. */
486 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
487 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
491 gtk_widget_show (GTK_WIDGET (box));
493 return GTK_WIDGET (box);
496 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
498 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
500 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
501 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
502 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
503 gtk_widget_show (label);
505 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
506 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
507 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
508 gtk_widget_show (label);
510 gtk_widget_show (GTK_WIDGET (box));
511 return GTK_WIDGET (box);
514 /** Change the caption title for the incoming server,
515 * as specified in the UI spec:
517 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
519 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
520 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
522 (protocol == MODEST_PROTOCOL_STORE_POP ?
523 _("mail_fi_emailtype_pop3") :
524 _("mail_fi_emailtype_imap") );
527 /* Note that this produces a compiler warning,
528 * because the compiler does not know that the translated string will have a %s in it.
529 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
530 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
531 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
532 g_free(incomingserver_title);
535 /** Change the caption title for the incoming server,
536 * as specified in the UI spec:
538 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
540 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
541 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
543 /* Fill the combo with appropriately titled choices for POP or IMAP. */
544 /* The choices are the same, but the titles are different, as in the UI spec. */
545 modest_serversecurity_combo_box_fill (
546 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
549 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
551 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
552 update_incoming_server_title (self);
553 update_incoming_server_security_choices (self);
556 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
558 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
560 /* Create a size group to be used by all captions.
561 * Note that HildonCaption does not create a default size group if we do not specify one.
562 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
563 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
565 /* The incoming server widgets: */
566 if (!self->combo_incoming_servertype)
567 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
568 easysetup_servertype_combo_box_set_active_servertype (
569 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
570 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
571 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
572 gtk_widget_show (self->combo_incoming_servertype);
573 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
574 gtk_widget_show (caption);
576 if(!self->entry_incomingserver)
577 self->entry_incomingserver = gtk_entry_new ();
578 /* Auto-capitalization is the default, so let's turn it off: */
579 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
580 set_default_custom_servernames (self);
582 if (self->caption_incoming)
583 gtk_widget_destroy (self->caption_incoming);
585 /* The caption title will be updated in update_incoming_server_title().
586 * so this default text will never be seen: */
587 /* (Note: Changing the title seems pointless. murrayc) */
588 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
589 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
590 update_incoming_server_title (self);
591 gtk_widget_show (self->entry_incomingserver);
592 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
593 gtk_widget_show (self->caption_incoming);
595 /* Change the caption title when the servertype changes,
596 * as in the UI spec: */
597 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
598 G_CALLBACK (on_combo_servertype_changed), self);
600 /* The secure connection widgets: */
601 if (!self->combo_incoming_security)
602 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
603 update_incoming_server_security_choices (self);
604 modest_serversecurity_combo_box_set_active_serversecurity (
605 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
606 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
607 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
608 gtk_widget_show (self->combo_incoming_security);
609 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
610 gtk_widget_show (caption);
612 if(!self->checkbox_incoming_auth)
613 self->checkbox_incoming_auth = gtk_check_button_new ();
614 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
615 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
616 gtk_widget_show (self->checkbox_incoming_auth);
617 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
618 gtk_widget_show (caption);
620 gtk_widget_show (GTK_WIDGET (box));
622 return GTK_WIDGET (box);
626 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
628 GtkWidget *widget = GTK_WIDGET (user_data);
630 /* Enable the widget only if the toggle button is active: */
631 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
632 gtk_widget_set_sensitive (widget, enable);
635 /* Make the sensitivity of a widget depend on a toggle button.
638 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
640 g_signal_connect (G_OBJECT (button), "toggled",
641 G_CALLBACK (on_toggle_button_changed), widget);
643 /* Set the starting sensitivity: */
644 on_toggle_button_changed (button, widget);
648 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
650 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
652 /* Create the window, if necessary: */
653 if (!(self->specific_window)) {
654 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
655 modest_connection_specific_smtp_window_fill_with_connections (
656 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
657 NULL /* account_name, not known yet. */);
660 /* Show the window: */
661 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
662 gtk_widget_show (self->specific_window);
665 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
667 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
669 /* Create a size group to be used by all captions.
670 * Note that HildonCaption does not create a default size group if we do not specify one.
671 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
672 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
674 /* The outgoing server widgets: */
675 if (!self->entry_outgoingserver)
676 self->entry_outgoingserver = gtk_entry_new ();
677 /* Auto-capitalization is the default, so let's turn it off: */
678 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
679 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
680 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
681 gtk_widget_show (self->entry_outgoingserver);
682 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
683 gtk_widget_show (caption);
684 set_default_custom_servernames (self);
686 /* The secure connection widgets: */
687 if (!self->combo_outgoing_security)
688 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
689 modest_serversecurity_combo_box_fill (
690 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
691 modest_serversecurity_combo_box_set_active_serversecurity (
692 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
693 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
694 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
695 gtk_widget_show (self->combo_outgoing_security);
696 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
697 gtk_widget_show (caption);
699 /* The secure authentication widgets: */
700 if (!self->combo_outgoing_auth)
701 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
702 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
703 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
704 gtk_widget_show (self->combo_outgoing_auth);
705 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
706 gtk_widget_show (caption);
708 GtkWidget *separator = gtk_hseparator_new ();
709 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
710 gtk_widget_show (separator);
712 /* connection-specific checkbox: */
713 if (!self->checkbox_outgoing_smtp_specific) {
714 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
715 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
718 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
719 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
720 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
721 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
722 gtk_widget_show (caption);
724 /* Connection-specific SMTP-Severs Edit button: */
725 if (!self->button_outgoing_smtp_servers)
726 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
727 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
728 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
729 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
730 gtk_widget_show (self->button_outgoing_smtp_servers);
731 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
732 gtk_widget_show (caption);
734 /* Only enable the button when the checkbox is checked: */
735 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
736 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
738 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
739 G_CALLBACK (on_button_outgoing_smtp_servers), self);
742 gtk_widget_show (GTK_WIDGET (box));
744 return GTK_WIDGET (box);
748 on_timeout_show_advanced_edit(gpointer user_data)
750 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
752 if (!(self->saved_account_name))
755 /* Show the Account Settings window: */
756 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
757 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
759 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
761 gtk_dialog_run (GTK_DIALOG (dialog));
763 /* TODO: The hide() is not necessary.
764 * It is just here to show that it doesn't work,
765 * just as destroy doesn't work.
767 gtk_widget_hide (GTK_WIDGET(dialog));
769 /* TODO: The dialog remains on screen, not allowing any interaction.
770 * But gtk_widget_destroy() should always destroy.
772 printf("debug: destroying settings dialog\n");
773 gtk_widget_destroy (GTK_WIDGET (dialog));
774 printf("debug: after destroying settings dialog (doesn't seem to work).\n");
776 return FALSE; /* Do not call this timeout callback again. */
780 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
782 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
784 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
785 * without recoding it to use non-gconf information.
786 * This account will be deleted if Finish is never actually clicked. */
788 gboolean saved = TRUE;
789 gboolean was_already_saved = TRUE;
790 if (!(self->saved_account_name)) {
791 saved = create_account (self, FALSE);
792 was_already_saved = FALSE;
798 if (!(self->saved_account_name))
801 /* Show the Account Settings window: */
802 if (was_already_saved) {
803 /* Just show the dialog immediately: */
804 on_timeout_show_advanced_edit(self);
808 printf ("debug: waiting for gconf to update its local cache. "
809 "This is a hack to work around a maemo gconf bug in maemo bora.\n");
811 g_timeout_add (5000, on_timeout_show_advanced_edit, self);
814 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
816 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
817 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
818 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
819 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
820 gtk_widget_show (label);
822 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
823 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
824 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
825 gtk_widget_show (label);
827 if (!self->button_edit)
828 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
829 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
830 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
831 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
832 gtk_widget_show (self->button_edit);
833 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
834 gtk_widget_show (caption);
836 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
837 G_CALLBACK (on_button_edit_advanced_settings), self);
839 gtk_widget_show (GTK_WIDGET (box));
840 return GTK_WIDGET (box);
847 on_response (ModestWizardDialog *wizard_dialog,
851 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
853 if (response_id == GTK_RESPONSE_CANCEL) {
854 /* Remove any temporarily-saved account that will not actually be needed: */
855 if (self->saved_account_name) {
856 modest_account_mgr_remove_account (self->account_manager,
857 self->saved_account_name, FALSE);
861 invoke_enable_buttons_vfunc (self);
865 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
867 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
869 /* Create the notebook to be used by the ModestWizardDialog base class:
870 * Each page of the notebook will be a page of the wizard: */
871 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
873 /* Set the notebook used by the ModestWizardDialog base class: */
874 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
876 /* Set the wizard title:
877 * The actual window title will be a combination of this and the page's tab label title. */
878 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
880 /* Read in the information about known service providers: */
881 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
883 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
884 priv->presets = modest_presets_new (filepath);
885 if (!(priv->presets)) {
886 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
889 g_assert(priv->presets);
892 /* Get the account manager object,
893 * so we can check for existing accounts,
894 * and create new accounts: */
895 self->account_manager = modest_runtime_get_account_mgr ();
896 g_assert (self->account_manager);
897 g_object_ref (self->account_manager);
899 /* Create the common pages,
901 self->page_welcome = create_page_welcome (self);
902 self->page_account_details = create_page_account_details (self);
903 self->page_user_details = create_page_user_details (self);
905 /* Add the common pages: */
906 gtk_notebook_append_page (notebook, self->page_welcome,
907 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
908 gtk_notebook_append_page (notebook, self->page_account_details,
909 gtk_label_new (_("mcen_ti_accountdetails")));
910 gtk_notebook_append_page (notebook, self->page_user_details,
911 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
913 /* Create and add the easysetup-specific pages,
914 * because we need _some_ final page to enable the Next and Finish buttons: */
915 create_subsequent_easysetup_pages (self);
918 /* Connect to the dialog's response signal so we can enable/disable buttons
919 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
920 * Note that we use g_signal_connect_after() instead of g_signal_connect()
921 * so that we can be enable/disable after ModestWizardDialog has done its own
922 * enabling/disabling of buttons.
924 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
925 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
927 * It's not enough to connect to the notebook's switch-page signal, because
928 * ModestWizardDialog's "response" signal handler enables the buttons itself,
929 * _after_ switching the page (understandably).
930 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
931 * then gtk_notebook_get_current_page() would return an incorrect value.)
933 g_signal_connect_after (G_OBJECT (self), "response",
934 G_CALLBACK (on_response), self);
936 /* When this window is shown, hibernation should not be possible,
937 * because there is no sensible way to save the state: */
938 modest_window_mgr_prevent_hibernation_while_window_is_shown (
939 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
942 ModestEasysetupWizardDialog*
943 modest_easysetup_wizard_dialog_new (void)
945 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
948 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
950 GtkNotebook *notebook = NULL;
951 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
954 /* Create the custom pages: */
955 if(!(self->page_custom_incoming)) {
956 self->page_custom_incoming = create_page_custom_incoming (self);
959 if(!(self->page_custom_outgoing)) {
960 self->page_custom_outgoing = create_page_custom_outgoing (self);
963 if(!(self->page_complete_customsetup)) {
964 self->page_complete_customsetup = create_page_complete_custom (self);
967 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
968 gtk_notebook_append_page (notebook, self->page_custom_incoming,
969 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
971 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
972 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
973 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
975 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
976 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
977 gtk_label_new (_("mcen_ti_emailsetup_complete")));
979 /* This is unnecessary with GTK+ 2.10: */
980 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
983 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
985 GtkNotebook *notebook = NULL;
986 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
989 /* Create the easysetup-specific pages: */
990 if(!self->page_complete_easysetup)
991 self->page_complete_easysetup = create_page_complete_easysetup (self);
993 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
994 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
995 gtk_label_new (_("mcen_ti_emailsetup_complete")));
997 /* This is unnecessary with GTK+ 2.10: */
998 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1000 /* After the user details page,
1001 * the following pages depend on whether "Other" was chosen
1002 * in the provider combobox on the account page
1004 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1006 if (easysetup_provider_combo_box_get_active_provider_id (
1007 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1008 /* "Other..." was selected: */
1010 /* Make sure that the easysetup pages do not exist: */
1011 if(self->page_complete_easysetup) {
1012 gtk_widget_destroy (self->page_complete_easysetup);
1013 self->page_complete_easysetup = NULL;
1016 create_subsequent_customsetup_pages (self);
1019 /* A specific provider was selected: */
1021 /* Make sure that the custom pages do not exist:
1022 * Because they will be used if they exist, when creating the account. */
1023 if(self->page_custom_incoming) {
1024 gtk_widget_destroy (self->page_custom_incoming);
1025 self->page_custom_incoming = NULL;
1028 if(self->page_custom_outgoing) {
1029 gtk_widget_destroy (self->page_custom_outgoing);
1030 self->page_custom_outgoing = NULL;
1033 if(self->page_complete_customsetup) {
1034 gtk_widget_destroy (self->page_complete_customsetup);
1035 self->page_complete_customsetup = NULL;
1039 /* Create the easysetup pages: */
1040 create_subsequent_easysetup_pages (self);
1046 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1051 gchar* at = g_utf8_strchr (email_address, -1, '@');
1052 if (!at || (g_utf8_strlen (at, -1) < 2))
1055 gchar* domain = g_utf8_next_char (at);
1059 const gchar* hostname = NULL;
1060 if (servertype == MODEST_PROTOCOL_STORE_POP)
1062 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1064 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1070 return g_strdup_printf ("%s.%s", hostname, domain);
1073 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1075 if (!account_wizard->entry_incomingserver)
1078 /* Set a default domain for the server, based on the email address,
1079 * if no server name was already specified.
1081 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
1082 if ((!incoming_existing || (strlen(incoming_existing) == 0))
1083 && account_wizard->entry_user_email) {
1084 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1085 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1086 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1088 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1089 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1090 g_free (servername);
1093 /* Set a default domain for the server, based on the email address,
1094 * if no server name was already specified.
1096 if (!account_wizard->entry_outgoingserver)
1099 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
1100 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
1101 && account_wizard->entry_user_email) {
1102 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1104 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1105 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1106 g_free (servername);
1111 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1113 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1115 /* Do extra validation that couldn't be done for every key press,
1116 * either because it was too slow,
1117 * or because it requires interaction:
1119 if (current_page == account_wizard->page_account_details) {
1120 /* Check that the title is not already in use: */
1121 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1122 if ((!account_title) || (strlen(account_title) == 0))
1125 /* Aavoid a clash with an existing display name: */
1126 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1127 account_wizard->account_manager, account_title);
1130 /* Warn the user via a dialog: */
1131 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1136 else if (current_page == account_wizard->page_user_details) {
1137 /* Check that the email address is valud: */
1138 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1139 if ((!email_address) || (strlen(email_address) == 0))
1142 if (!modest_text_utils_validate_email_address (email_address)) {
1143 /* Warn the user via a dialog: */
1144 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1146 /* Return focus to the email address entry: */
1147 gtk_widget_grab_focus (account_wizard->entry_user_email);
1152 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1153 create_subsequent_pages (account_wizard);
1156 /* TODO: The UI Spec wants us to check that the servernames are valid,
1157 * but does not specify how.
1160 if(next_page == account_wizard->page_custom_incoming) {
1161 set_default_custom_servernames (account_wizard);
1163 else if (next_page == account_wizard->page_custom_outgoing) {
1164 set_default_custom_servernames (account_wizard);
1167 /* If this is the last page, and this is a click on Finish,
1168 * then attempt to create the dialog.
1170 if(!next_page) /* This is NULL when this is a click on Finish. */
1172 if (account_wizard->saved_account_name) {
1173 /* Just enable the already-saved account (temporarily created when
1174 * editing advanced settings): */
1175 modest_account_mgr_set_enabled (account_wizard->account_manager,
1176 account_wizard->saved_account_name, TRUE);
1178 create_account (account_wizard, TRUE /* enabled */);
1186 static gboolean entry_is_empty (GtkWidget *entry)
1191 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1192 if ((!text) || (strlen(text) == 0))
1199 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1201 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1203 gboolean enable_next = TRUE;
1204 if (current_page == account_wizard->page_welcome) {
1207 else if (current_page == account_wizard->page_account_details) {
1208 /* The account details title is mandatory: */
1209 if (entry_is_empty(account_wizard->entry_account_title))
1210 enable_next = FALSE;
1212 else if (current_page == account_wizard->page_user_details) {
1213 /* The user details username is mandatory: */
1214 if (entry_is_empty(account_wizard->entry_user_username))
1215 enable_next = FALSE;
1217 /* The user details email address is mandatory: */
1218 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1219 enable_next = FALSE;
1221 else if (current_page == account_wizard->page_custom_incoming) {
1222 /* The custom incoming server is mandatory: */
1223 if (entry_is_empty(account_wizard->entry_incomingserver))
1224 enable_next = FALSE;
1227 /* Enable the buttons,
1228 * identifying them via their associated response codes: */
1230 /* Disable the Finish button until we are on the last page,
1231 * because HildonWizardDialog enables this for all but the first page: */
1232 GtkNotebook *notebook = NULL;
1233 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1234 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1236 gint current = gtk_notebook_get_current_page (notebook);
1237 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1238 const gboolean is_last = (current == last);
1241 gtk_dialog_set_response_sensitive (dialog_base,
1242 MODEST_WIZARD_DIALOG_FINISH,
1246 /* Disable Next on the last page: */
1247 enable_next = FALSE;
1250 gtk_dialog_set_response_sensitive (dialog_base,
1251 MODEST_WIZARD_DIALOG_NEXT,
1256 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1258 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1259 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1262 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1263 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1264 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1265 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1267 /* Provide a vfunc implementation so we can decide
1268 * when to enable/disable the prev/next buttons.
1270 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1271 base_klass->before_next = on_before_next;
1272 base_klass->enable_buttons = on_enable_buttons;
1276 show_error (GtkWindow *parent_window, const gchar* text)
1278 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1280 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1287 gtk_dialog_run (dialog);
1288 gtk_widget_destroy (GTK_WIDGET (dialog));
1291 /** Attempt to create the account from the information that the user has entered.
1292 * @result: TRUE if the account was successfully created.
1295 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1297 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1299 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1305 /* We should have checked for this already,
1306 * and changed that name accordingly,
1307 * but let's check again just in case:
1309 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1312 /* Increment the non-user visible name if necessary,
1313 * based on the display name: */
1314 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1315 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1316 account_name_start, FALSE /* not a server account */);
1317 g_free (account_name_start);
1319 /* username and password (for both incoming and outgoing): */
1320 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1321 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1323 /* Incoming server: */
1324 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1325 * or modest_account_mgr_add_server_account will fail. */
1326 gchar* servername_incoming = NULL;
1327 guint serverport_incoming = 0;
1328 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1329 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1330 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1332 /* Get details from the specified presets: */
1333 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1334 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1337 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1338 TRUE /* incoming */);
1340 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1342 TRUE /* incoming */);
1343 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1345 TRUE /* incoming */);
1347 g_warning ("security incoming: %x", security_incoming);
1349 /* We don't check for SMTP here as that is impossible for an incoming server. */
1350 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1351 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1352 serverport_incoming =
1353 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
1354 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1355 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1356 serverport_incoming =
1357 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
1360 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1361 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1363 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1364 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1367 /* Use custom pages because no preset was specified: */
1368 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1370 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1371 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1373 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1374 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1376 /* The UI spec says:
1377 * If secure authentication is unchecked, allow sending username and password also as plain text.
1378 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1379 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1381 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1382 ? MODEST_PROTOCOL_AUTH_CRAMMD5
1383 : MODEST_PROTOCOL_AUTH_PASSWORD;
1386 /* First we add the 2 server accounts, and then we add the account that uses them.
1387 * If we don't do it in this order then we will experience a crash. */
1389 /* Add a (incoming) server account, to be used by the account: */
1390 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1391 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1392 store_name_start, TRUE /* server account */);
1393 g_free (store_name_start);
1394 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1396 servername_incoming,
1397 serverport_incoming,
1400 protocol_security_incoming,
1401 protocol_authentication_incoming);
1403 g_free (servername_incoming);
1406 /* TODO: Provide a Logical ID for the text: */
1407 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1412 /* There must be at least one account now: */
1413 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1414 * fixed in versions after 3.1. */
1415 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1418 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1420 g_slist_free (account_names);
1423 /* Outgoing server: */
1424 gchar* servername_outgoing = NULL;
1425 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1426 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1427 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1428 guint serverport_outgoing = 0;
1432 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1433 FALSE /* incoming */);
1435 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1437 FALSE /* incoming */);
1439 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1440 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1441 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1442 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1444 ModestPresetsSecurity security_outgoing =
1445 modest_presets_get_info_server_security (priv->presets, provider_id,
1446 FALSE /* incoming */);
1448 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1449 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1450 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1451 serverport_outgoing = 465;
1452 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1454 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1455 /* TODO: There is no SMTP authentication enum for presets. */
1458 /* Use custom pages because no preset was specified: */
1459 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1461 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1463 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1464 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1466 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1467 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1470 /* Add a (outgoing) server account to be used by the account: */
1471 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1472 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1473 transport_name_start, TRUE /* server account */);
1474 g_free (transport_name_start);
1475 created = modest_account_mgr_add_server_account (self->account_manager,
1477 servername_outgoing,
1478 serverport_outgoing,
1481 protocol_security_outgoing,
1482 protocol_authentication_outgoing);
1484 g_free (servername_outgoing);
1487 /* TODO: Provide a Logical ID for the text: */
1488 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1493 /* Create the account, which will contain the two "server accounts": */
1494 created = modest_account_mgr_add_account (self->account_manager, account_name,
1495 store_name, /* The name of our POP/IMAP server account. */
1496 transport_name, /* The name of our SMTP server account. */
1498 g_free (store_name);
1499 g_free (transport_name);
1502 /* TODO: Provide a Logical ID for the text: */
1503 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1507 /* The user name and email address must be set additionally: */
1508 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1509 modest_account_mgr_set_string (self->account_manager, account_name,
1510 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1512 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1513 modest_account_mgr_set_string (self->account_manager, account_name,
1514 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1516 /* Set the display name: */
1517 modest_account_mgr_set_string (self->account_manager, account_name,
1518 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1520 /* Set retrieve type */
1521 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1522 modest_account_mgr_set_string (self->account_manager, account_name,
1523 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1525 /* Save the connection-specific SMTP server accounts. */
1526 gboolean result = TRUE;
1527 if (self->specific_window)
1528 result = modest_connection_specific_smtp_window_save_server_accounts (
1529 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1531 g_free (self->saved_account_name);
1532 self->saved_account_name = g_strdup (account_name);
1534 g_free (account_name);