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_asterix(ModestEasysetupWizardDialog *self,
181 HildonCaptionStatus flag)
183 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
185 /* The translated strings seem to already contain the *,
186 * but this code can be used if that is not true in future.
189 /* Add a * character to indicate mandatory fields,
190 * as specified in our "Email UI Specification": */
191 if (flag == HILDON_CAPTION_MANDATORY) {
192 gchar* title = g_strdup_printf("%s*", value);
193 caption = hildon_caption_new (group, title, control, icon, flag);
197 caption = hildon_caption_new (group, value, control, icon, flag);
200 /* Connect to the appropriate changed signal for the widget,
201 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
203 if (GTK_IS_ENTRY (control)) {
204 g_signal_connect (G_OBJECT (control), "changed",
205 G_CALLBACK (on_caption_entry_changed), self);
208 else if (GTK_IS_COMBO_BOX (control)) {
209 g_signal_connect (G_OBJECT (control), "changed",
210 G_CALLBACK (on_caption_combobox_changed), self);
217 create_page_welcome (ModestEasysetupWizardDialog *self)
219 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
220 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
221 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
222 gtk_widget_show (label);
223 gtk_widget_show (GTK_WIDGET (box));
224 return GTK_WIDGET (box);
228 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
230 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
232 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
234 /* Fill the providers combo, based on the selected country: */
235 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
236 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
237 easysetup_provider_combo_box_fill (
238 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
242 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
244 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
246 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
248 /* Fill the providers combo, based on the selected country: */
249 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
250 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
252 gchar* domain_name = NULL;
254 domain_name = modest_presets_get_domain (priv->presets, provider_id);
257 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
259 if (self->entry_user_email)
260 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
262 g_free (domain_name);
264 g_free (provider_id);
268 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
270 ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
271 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
275 create_page_account_details (ModestEasysetupWizardDialog *self)
277 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
278 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
279 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
280 gtk_widget_show (label);
282 /* Create a size group to be used by all captions.
283 * Note that HildonCaption does not create a default size group if we do not specify one.
284 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
285 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
287 /* The country widgets: */
288 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
289 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
290 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
291 gtk_widget_show (self->combo_account_country);
292 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
293 gtk_widget_show (caption);
295 /* connect to country combo's changed signal, so we can fill the provider combo: */
296 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
297 G_CALLBACK (on_combo_account_country), self);
299 GtkWidget *separator = gtk_hseparator_new ();
300 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
301 gtk_widget_show (separator);
303 /* The service provider widgets: */
304 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
306 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
307 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
308 gtk_widget_show (self->combo_account_serviceprovider);
309 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
310 gtk_widget_show (caption);
312 /* connect to providers combo's changed signal, so we can fill the email address: */
313 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
314 G_CALLBACK (on_combo_account_serviceprovider), self);
316 /* TODO: Default to the current country somehow.
317 * But I don't know how to get the information that is specified in the
318 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
320 * This is probably not the best choice of gconf key:
321 * This is the "mcc used in the last pairing", ie. the last connection you made.
322 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
325 GConfClient *client = gconf_client_get_default ();
326 GError *error = NULL;
327 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
328 gint mcc_id = gconf_client_get_int(client, key, &error);
334 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
335 g_error_free (error);
341 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
342 * This might just be a Maemo bug.
346 /* For now, we default to Finland when there is nothing better: */
350 easysetup_country_combo_box_set_active_country_id (
351 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
354 /* The description widgets: */
355 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
356 /* Do use auto-capitalization: */
357 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
358 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
360 /* Set a default account title, choosing one that does not already exist: */
361 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
362 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
363 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
364 self->account_manager, default_account_name_start);
365 g_free (default_account_name_start);
366 default_account_name_start = NULL;
368 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
369 g_free (default_account_name);
370 default_account_name = NULL;
372 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
373 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
374 gtk_widget_show (self->entry_account_title);
375 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
376 gtk_widget_show (caption);
378 /* Prevent the use of some characters in the account title,
379 * as required by our UI specification: */
380 GList *list_prevent = NULL;
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, "*");
385 list_prevent = g_list_append (list_prevent, "?");
386 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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 list_prevent = g_list_append (list_prevent, "|");
391 list_prevent = g_list_append (list_prevent, "^");
392 modest_validating_entry_set_unallowed_characters (
393 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
394 g_list_free (list_prevent);
396 /* Set max length as in the UI spec:
397 * The UI spec seems to want us to show a dialog if we hit the maximum. */
398 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
399 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
402 gtk_widget_show (GTK_WIDGET (box));
404 return GTK_WIDGET (box);
408 create_page_user_details (ModestEasysetupWizardDialog *self)
410 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
412 /* Create a size group to be used by all captions.
413 * Note that HildonCaption does not create a default size group if we do not specify one.
414 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
415 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
417 /* The name widgets: */
418 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
419 /* Auto-capitalization is the default, so let's turn it off: */
420 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
421 /* Set max length as in the UI spec:
422 * The UI spec seems to want us to show a dialog if we hit the maximum. */
423 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
424 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
426 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
427 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
428 gtk_widget_show (self->entry_user_name);
429 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
430 gtk_widget_show (caption);
432 /* Prevent the use of some characters in the name,
433 * as required by our UI specification: */
434 GList *list_prevent = NULL;
435 list_prevent = g_list_append (list_prevent, "<");
436 list_prevent = g_list_append (list_prevent, ">");
437 modest_validating_entry_set_unallowed_characters (
438 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
439 g_list_free (list_prevent);
441 /* The username widgets: */
442 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
443 /* Auto-capitalization is the default, so let's turn it off: */
444 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
445 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
446 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
447 gtk_widget_show (self->entry_user_username);
448 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
449 gtk_widget_show (caption);
451 /* Prevent the use of some characters in the username,
452 * as required by our UI specification: */
453 modest_validating_entry_set_unallowed_characters_whitespace (
454 MODEST_VALIDATING_ENTRY (self->entry_user_username));
456 /* Set max length as in the UI spec:
457 * The UI spec seems to want us to show a dialog if we hit the maximum. */
458 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
459 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
462 /* The password widgets: */
463 self->entry_user_password = gtk_entry_new ();
464 /* Auto-capitalization is the default, so let's turn it off: */
465 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
466 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
467 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
468 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
469 caption = create_caption_new_with_asterix (self, sizegroup,
470 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
471 gtk_widget_show (self->entry_user_password);
472 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
473 gtk_widget_show (caption);
475 /* The email address widgets: */
476 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
477 /* Auto-capitalization is the default, so let's turn it off: */
478 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
479 caption = create_caption_new_with_asterix (self, sizegroup,
480 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
481 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
482 gtk_widget_show (self->entry_user_email);
483 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
484 gtk_widget_show (caption);
486 /* Set max length as in the UI spec:
487 * The UI spec seems to want us to show a dialog if we hit the maximum. */
488 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
489 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
493 gtk_widget_show (GTK_WIDGET (box));
495 return GTK_WIDGET (box);
498 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
500 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
501 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
502 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
503 gtk_widget_show (label);
504 gtk_widget_show (GTK_WIDGET (box));
505 return GTK_WIDGET (box);
508 /** Change the caption title for the incoming server,
509 * as specified in the UI spec:
511 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
513 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
514 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
516 (protocol == MODEST_PROTOCOL_STORE_POP ?
517 _("mail_fi_emailtype_pop3") :
518 _("mail_fi_emailtype_imap") );
521 /* Note that this produces a compiler warning,
522 * because the compiler does not know that the translated string will have a %s in it.
523 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
524 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
525 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
526 g_free(incomingserver_title);
529 /** Change the caption title for the incoming server,
530 * as specified in the UI spec:
532 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
534 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
535 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
537 /* Fill the combo with appropriately titled choices for POP or IMAP. */
538 /* The choices are the same, but the titles are different, as in the UI spec. */
539 modest_serversecurity_combo_box_fill (
540 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
543 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
545 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
546 update_incoming_server_title (self);
547 update_incoming_server_security_choices (self);
550 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
552 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
554 /* Create a size group to be used by all captions.
555 * Note that HildonCaption does not create a default size group if we do not specify one.
556 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
557 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
559 /* The incoming server widgets: */
560 if (!self->combo_incoming_servertype)
561 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
562 easysetup_servertype_combo_box_set_active_servertype (
563 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
564 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
565 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
566 gtk_widget_show (self->combo_incoming_servertype);
567 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
568 gtk_widget_show (caption);
570 if(!self->entry_incomingserver)
571 self->entry_incomingserver = gtk_entry_new ();
572 /* Auto-capitalization is the default, so let's turn it off: */
573 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
574 set_default_custom_servernames (self);
576 if (self->caption_incoming)
577 gtk_widget_destroy (self->caption_incoming);
579 /* The caption title will be updated in update_incoming_server_title().
580 * so this default text will never be seen: */
581 /* (Note: Changing the title seems pointless. murrayc) */
582 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
583 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
584 update_incoming_server_title (self);
585 gtk_widget_show (self->entry_incomingserver);
586 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
587 gtk_widget_show (self->caption_incoming);
589 /* Change the caption title when the servertype changes,
590 * as in the UI spec: */
591 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
592 G_CALLBACK (on_combo_servertype_changed), self);
594 /* The secure connection widgets: */
595 if (!self->combo_incoming_security)
596 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
597 update_incoming_server_security_choices (self);
598 modest_serversecurity_combo_box_set_active_serversecurity (
599 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
600 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
601 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
602 gtk_widget_show (self->combo_incoming_security);
603 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
604 gtk_widget_show (caption);
606 if(!self->checkbox_incoming_auth)
607 self->checkbox_incoming_auth = gtk_check_button_new ();
608 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
609 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
610 gtk_widget_show (self->checkbox_incoming_auth);
611 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
612 gtk_widget_show (caption);
614 gtk_widget_show (GTK_WIDGET (box));
616 return GTK_WIDGET (box);
620 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
622 GtkWidget *widget = GTK_WIDGET (user_data);
624 /* Enable the widget only if the toggle button is active: */
625 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
626 gtk_widget_set_sensitive (widget, enable);
629 /* Make the sensitivity of a widget depend on a toggle button.
632 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
634 g_signal_connect (G_OBJECT (button), "toggled",
635 G_CALLBACK (on_toggle_button_changed), widget);
637 /* Set the starting sensitivity: */
638 on_toggle_button_changed (button, widget);
642 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
644 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
646 /* Create the window, if necessary: */
647 if (!(self->specific_window)) {
648 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
649 modest_connection_specific_smtp_window_fill_with_connections (
650 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
651 NULL /* account_name, not known yet. */);
654 /* Show the window: */
655 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
656 gtk_widget_show (self->specific_window);
659 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
661 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
663 /* Create a size group to be used by all captions.
664 * Note that HildonCaption does not create a default size group if we do not specify one.
665 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
666 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
668 /* The outgoing server widgets: */
669 if (!self->entry_outgoingserver)
670 self->entry_outgoingserver = gtk_entry_new ();
671 /* Auto-capitalization is the default, so let's turn it off: */
672 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
673 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
674 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
675 gtk_widget_show (self->entry_outgoingserver);
676 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
677 gtk_widget_show (caption);
678 set_default_custom_servernames (self);
680 /* The secure connection widgets: */
681 if (!self->combo_outgoing_security)
682 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
683 modest_serversecurity_combo_box_fill (
684 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
685 modest_serversecurity_combo_box_set_active_serversecurity (
686 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
687 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
688 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
689 gtk_widget_show (self->combo_outgoing_security);
690 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
691 gtk_widget_show (caption);
693 /* The secure authentication widgets: */
694 if (!self->combo_outgoing_auth)
695 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
696 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
697 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
698 gtk_widget_show (self->combo_outgoing_auth);
699 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
700 gtk_widget_show (caption);
702 GtkWidget *separator = gtk_hseparator_new ();
703 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
704 gtk_widget_show (separator);
706 /* connection-specific checkbox: */
707 if (!self->checkbox_outgoing_smtp_specific) {
708 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
709 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
712 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
713 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
714 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
715 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
716 gtk_widget_show (caption);
718 /* Connection-specific SMTP-Severs Edit button: */
719 if (!self->button_outgoing_smtp_servers)
720 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
721 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
722 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
723 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
724 gtk_widget_show (self->button_outgoing_smtp_servers);
725 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
726 gtk_widget_show (caption);
728 /* Only enable the button when the checkbox is checked: */
729 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
730 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
732 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
733 G_CALLBACK (on_button_outgoing_smtp_servers), self);
736 gtk_widget_show (GTK_WIDGET (box));
738 return GTK_WIDGET (box);
742 on_timeout_show_advanced_edit(gpointer user_data)
744 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
746 if (!(self->saved_account_name))
749 /* Show the Account Settings window: */
750 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
751 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
753 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
755 gtk_dialog_run (GTK_DIALOG (dialog));
757 /* TODO: The hide() is not necessary.
758 * It is just here to show that it doesn't work,
759 * just as destroy doesn't work.
761 gtk_widget_hide (GTK_WIDGET(dialog));
763 /* TODO: The dialog remains on screen, not allowing any interaction.
764 * But gtk_widget_destroy() should always destroy.
766 printf("debug: destroying settings dialog\n");
767 gtk_widget_destroy (GTK_WIDGET (dialog));
768 printf("debug: after destroying settings dialog (doesn't seem to work).\n");
770 return FALSE; /* Do not call this timeout callback again. */
774 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
776 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
778 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
779 * without recoding it to use non-gconf information.
780 * This account will be deleted if Finish is never actually clicked. */
782 gboolean saved = TRUE;
783 gboolean was_already_saved = TRUE;
784 if (!(self->saved_account_name)) {
785 saved = create_account (self, FALSE);
786 was_already_saved = FALSE;
792 if (!(self->saved_account_name))
795 /* Show the Account Settings window: */
796 if (was_already_saved) {
797 /* Just show the dialog immediately: */
798 on_timeout_show_advanced_edit(self);
802 printf ("debug: waiting for gconf to update its local cache. "
803 "This is a hack to work around a maemo gconf bug in maemo bora.\n");
805 g_timeout_add (5000, on_timeout_show_advanced_edit, self);
808 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
810 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
811 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
812 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
813 gtk_widget_show (label);
815 if (!self->button_edit)
816 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
817 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
818 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
819 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
820 gtk_widget_show (self->button_edit);
821 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
822 gtk_widget_show (caption);
824 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
825 G_CALLBACK (on_button_edit_advanced_settings), self);
827 gtk_widget_show (GTK_WIDGET (box));
828 return GTK_WIDGET (box);
835 on_response (ModestWizardDialog *wizard_dialog,
839 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
841 if (response_id == GTK_RESPONSE_CANCEL) {
842 /* Remove any temporarily-saved account that will not actually be needed: */
843 if (self->saved_account_name) {
844 modest_account_mgr_remove_account (self->account_manager,
845 self->saved_account_name, FALSE);
849 invoke_enable_buttons_vfunc (self);
853 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
855 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
857 /* Create the notebook to be used by the ModestWizardDialog base class:
858 * Each page of the notebook will be a page of the wizard: */
859 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
861 /* Set the notebook used by the ModestWizardDialog base class: */
862 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
864 /* Set the wizard title:
865 * The actual window title will be a combination of this and the page's tab label title. */
866 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
868 /* Read in the information about known service providers: */
869 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
871 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
872 priv->presets = modest_presets_new (filepath);
873 if (!(priv->presets)) {
874 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
877 g_assert(priv->presets);
880 /* Get the account manager object,
881 * so we can check for existing accounts,
882 * and create new accounts: */
883 self->account_manager = modest_runtime_get_account_mgr ();
884 g_assert (self->account_manager);
885 g_object_ref (self->account_manager);
887 /* Create the common pages,
889 self->page_welcome = create_page_welcome (self);
890 self->page_account_details = create_page_account_details (self);
891 self->page_user_details = create_page_user_details (self);
893 /* Add the common pages: */
894 gtk_notebook_append_page (notebook, self->page_welcome,
895 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
896 gtk_notebook_append_page (notebook, self->page_account_details,
897 gtk_label_new (_("mcen_ti_accountdetails")));
898 gtk_notebook_append_page (notebook, self->page_user_details,
899 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
901 /* Create and add the easysetup-specific pages,
902 * because we need _some_ final page to enable the Next and Finish buttons: */
903 create_subsequent_easysetup_pages (self);
906 /* Connect to the dialog's response signal so we can enable/disable buttons
907 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
908 * Note that we use g_signal_connect_after() instead of g_signal_connect()
909 * so that we can be enable/disable after ModestWizardDialog has done its own
910 * enabling/disabling of buttons.
912 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
913 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
915 * It's not enough to connect to the notebook's switch-page signal, because
916 * ModestWizardDialog's "response" signal handler enables the buttons itself,
917 * _after_ switching the page (understandably).
918 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
919 * then gtk_notebook_get_current_page() would return an incorrect value.)
921 g_signal_connect_after (G_OBJECT (self), "response",
922 G_CALLBACK (on_response), self);
924 /* When this window is shown, hibernation should not be possible,
925 * because there is no sensible way to save the state: */
926 modest_window_mgr_prevent_hibernation_while_window_is_shown (
927 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
930 ModestEasysetupWizardDialog*
931 modest_easysetup_wizard_dialog_new (void)
933 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
936 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
938 GtkNotebook *notebook = NULL;
939 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
942 /* Create the custom pages: */
943 if(!(self->page_custom_incoming)) {
944 self->page_custom_incoming = create_page_custom_incoming (self);
947 if(!(self->page_custom_outgoing)) {
948 self->page_custom_outgoing = create_page_custom_outgoing (self);
951 if(!(self->page_complete_customsetup)) {
952 self->page_complete_customsetup = create_page_complete_custom (self);
955 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
956 gtk_notebook_append_page (notebook, self->page_custom_incoming,
957 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
959 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
960 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
961 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
963 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
964 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
965 gtk_label_new (_("mcen_ti_emailsetup_complete")));
967 /* This is unnecessary with GTK+ 2.10: */
968 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
971 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
973 GtkNotebook *notebook = NULL;
974 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
977 /* Create the easysetup-specific pages: */
978 if(!self->page_complete_easysetup)
979 self->page_complete_easysetup = create_page_complete_easysetup (self);
981 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
982 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
983 gtk_label_new (_("mcen_ti_emailsetup_complete")));
985 /* This is unnecessary with GTK+ 2.10: */
986 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
988 /* After the user details page,
989 * the following pages depend on whether "Other" was chosen
990 * in the provider combobox on the account page
992 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
994 if (easysetup_provider_combo_box_get_active_provider_id (
995 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
996 /* "Other..." was selected: */
998 /* Make sure that the easysetup pages do not exist: */
999 if(self->page_complete_easysetup) {
1000 gtk_widget_destroy (self->page_complete_easysetup);
1001 self->page_complete_easysetup = NULL;
1004 create_subsequent_customsetup_pages (self);
1007 /* A specific provider was selected: */
1009 /* Make sure that the custom pages do not exist:
1010 * Because they will be used if they exist, when creating the account. */
1011 if(self->page_custom_incoming) {
1012 gtk_widget_destroy (self->page_custom_incoming);
1013 self->page_custom_incoming = NULL;
1016 if(self->page_custom_outgoing) {
1017 gtk_widget_destroy (self->page_custom_outgoing);
1018 self->page_custom_outgoing = NULL;
1021 if(self->page_complete_customsetup) {
1022 gtk_widget_destroy (self->page_complete_customsetup);
1023 self->page_complete_customsetup = NULL;
1027 /* Create the easysetup pages: */
1028 create_subsequent_easysetup_pages (self);
1034 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1039 gchar* at = g_utf8_strchr (email_address, -1, '@');
1040 if (!at || (g_utf8_strlen (at, -1) < 2))
1043 gchar* domain = g_utf8_next_char (at);
1047 const gchar* hostname = NULL;
1048 if (servertype == MODEST_PROTOCOL_STORE_POP)
1050 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1052 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1058 return g_strdup_printf ("%s.%s", hostname, domain);
1061 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1063 if (!account_wizard->entry_incomingserver)
1066 /* Set a default domain for the server, based on the email address,
1067 * if no server name was already specified.
1069 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
1070 if ((!incoming_existing || (strlen(incoming_existing) == 0))
1071 && account_wizard->entry_user_email) {
1072 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1073 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1074 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1076 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1077 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1078 g_free (servername);
1081 /* Set a default domain for the server, based on the email address,
1082 * if no server name was already specified.
1084 if (!account_wizard->entry_outgoingserver)
1087 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
1088 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
1089 && account_wizard->entry_user_email) {
1090 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1092 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1093 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1094 g_free (servername);
1099 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1101 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1103 /* Do extra validation that couldn't be done for every key press,
1104 * either because it was too slow,
1105 * or because it requires interaction:
1107 if (current_page == account_wizard->page_account_details) {
1108 /* Check that the title is not already in use: */
1109 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1110 if ((!account_title) || (strlen(account_title) == 0))
1113 /* Aavoid a clash with an existing display name: */
1114 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1115 account_wizard->account_manager, account_title);
1118 /* Warn the user via a dialog: */
1119 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1124 else if (current_page == account_wizard->page_user_details) {
1125 /* Check that the email address is valud: */
1126 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1127 if ((!email_address) || (strlen(email_address) == 0))
1130 if (!modest_text_utils_validate_email_address (email_address)) {
1131 /* Warn the user via a dialog: */
1132 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1134 /* Return focus to the email address entry: */
1135 gtk_widget_grab_focus (account_wizard->entry_user_email);
1140 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1141 create_subsequent_pages (account_wizard);
1144 /* TODO: The UI Spec wants us to check that the servernames are valid,
1145 * but does not specify how.
1148 if(next_page == account_wizard->page_custom_incoming) {
1149 set_default_custom_servernames (account_wizard);
1151 else if (next_page == account_wizard->page_custom_outgoing) {
1152 set_default_custom_servernames (account_wizard);
1155 /* If this is the last page, and this is a click on Finish,
1156 * then attempt to create the dialog.
1158 if(!next_page) /* This is NULL when this is a click on Finish. */
1160 if (account_wizard->saved_account_name) {
1161 /* Just enable the already-saved account (temporarily created when
1162 * editing advanced settings): */
1163 modest_account_mgr_set_enabled (account_wizard->account_manager,
1164 account_wizard->saved_account_name, TRUE);
1166 create_account (account_wizard, TRUE /* enabled */);
1174 static gboolean entry_is_empty (GtkWidget *entry)
1179 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1180 if ((!text) || (strlen(text) == 0))
1187 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1189 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1191 gboolean enable_next = TRUE;
1192 if (current_page == account_wizard->page_welcome) {
1195 else if (current_page == account_wizard->page_account_details) {
1196 /* The account details title is mandatory: */
1197 if (entry_is_empty(account_wizard->entry_account_title))
1198 enable_next = FALSE;
1200 else if (current_page == account_wizard->page_user_details) {
1201 /* The user details username is mandatory: */
1202 if (entry_is_empty(account_wizard->entry_user_username))
1203 enable_next = FALSE;
1205 /* The user details email address is mandatory: */
1206 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1207 enable_next = FALSE;
1209 else if (current_page == account_wizard->page_custom_incoming) {
1210 /* The custom incoming server is mandatory: */
1211 if (entry_is_empty(account_wizard->entry_incomingserver))
1212 enable_next = FALSE;
1215 /* Enable the buttons,
1216 * identifying them via their associated response codes: */
1218 /* Disable the Finish button until we are on the last page,
1219 * because HildonWizardDialog enables this for all but the first page: */
1220 GtkNotebook *notebook = NULL;
1221 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1222 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1224 gint current = gtk_notebook_get_current_page (notebook);
1225 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1226 const gboolean is_last = (current == last);
1229 gtk_dialog_set_response_sensitive (dialog_base,
1230 MODEST_WIZARD_DIALOG_FINISH,
1234 /* Disable Next on the last page: */
1235 enable_next = FALSE;
1238 gtk_dialog_set_response_sensitive (dialog_base,
1239 MODEST_WIZARD_DIALOG_NEXT,
1244 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1246 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1247 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1250 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1251 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1252 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1253 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1255 /* Provide a vfunc implementation so we can decide
1256 * when to enable/disable the prev/next buttons.
1258 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1259 base_klass->before_next = on_before_next;
1260 base_klass->enable_buttons = on_enable_buttons;
1264 show_error (GtkWindow *parent_window, const gchar* text)
1266 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1268 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1275 gtk_dialog_run (dialog);
1276 gtk_widget_destroy (GTK_WIDGET (dialog));
1279 /** Attempt to create the account from the information that the user has entered.
1280 * @result: TRUE if the account was successfully created.
1283 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1285 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1287 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1293 /* We should have checked for this already,
1294 * and changed that name accordingly,
1295 * but let's check again just in case:
1297 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1300 /* Increment the non-user visible name if necessary,
1301 * based on the display name: */
1302 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1303 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1304 account_name_start, FALSE /* not a server account */);
1305 g_free (account_name_start);
1307 /* username and password (for both incoming and outgoing): */
1308 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1309 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1311 /* Incoming server: */
1312 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1313 * or modest_account_mgr_add_server_account will fail. */
1314 gchar* servername_incoming = NULL;
1315 guint serverport_incoming = 0;
1316 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1317 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1318 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1320 /* Get details from the specified presets: */
1321 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1322 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1325 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1326 TRUE /* incoming */);
1328 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1330 TRUE /* incoming */);
1331 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1333 TRUE /* incoming */);
1335 g_warning ("security incoming: %x", security_incoming);
1337 /* We don't check for SMTP here as that is impossible for an incoming server. */
1338 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1339 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1340 serverport_incoming =
1341 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
1342 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1343 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1344 serverport_incoming =
1345 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
1348 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1349 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1351 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1352 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1355 /* Use custom pages because no preset was specified: */
1356 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1358 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1359 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1361 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1362 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1364 /* The UI spec says:
1365 * If secure authentication is unchecked, allow sending username and password also as plain text.
1366 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1367 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1369 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1370 ? MODEST_PROTOCOL_AUTH_CRAMMD5
1371 : MODEST_PROTOCOL_AUTH_PASSWORD;
1374 /* First we add the 2 server accounts, and then we add the account that uses them.
1375 * If we don't do it in this order then we will experience a crash. */
1377 /* Add a (incoming) server account, to be used by the account: */
1378 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1379 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1380 store_name_start, TRUE /* server account */);
1381 g_free (store_name_start);
1382 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1384 servername_incoming,
1385 serverport_incoming,
1388 protocol_security_incoming,
1389 protocol_authentication_incoming);
1391 g_free (servername_incoming);
1394 /* TODO: Provide a Logical ID for the text: */
1395 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1400 /* There must be at least one account now: */
1401 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1402 * fixed in versions after 3.1. */
1403 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1406 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1408 g_slist_free (account_names);
1411 /* Outgoing server: */
1412 gchar* servername_outgoing = NULL;
1413 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1414 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1415 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1416 guint serverport_outgoing = 0;
1420 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1421 FALSE /* incoming */);
1423 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1425 FALSE /* incoming */);
1427 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1428 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1429 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1430 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1432 ModestPresetsSecurity security_outgoing =
1433 modest_presets_get_info_server_security (priv->presets, provider_id,
1434 FALSE /* incoming */);
1436 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1437 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1438 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1439 serverport_outgoing = 465;
1440 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1442 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1443 /* TODO: There is no SMTP authentication enum for presets. */
1446 /* Use custom pages because no preset was specified: */
1447 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1449 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1451 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1452 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1454 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1455 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1458 /* Add a (outgoing) server account to be used by the account: */
1459 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1460 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1461 transport_name_start, TRUE /* server account */);
1462 g_free (transport_name_start);
1463 created = modest_account_mgr_add_server_account (self->account_manager,
1465 servername_outgoing,
1466 serverport_outgoing,
1469 protocol_security_outgoing,
1470 protocol_authentication_outgoing);
1472 g_free (servername_outgoing);
1475 /* TODO: Provide a Logical ID for the text: */
1476 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1481 /* Create the account, which will contain the two "server accounts": */
1482 created = modest_account_mgr_add_account (self->account_manager, account_name,
1483 store_name, /* The name of our POP/IMAP server account. */
1484 transport_name, /* The name of our SMTP server account. */
1486 g_free (store_name);
1487 g_free (transport_name);
1490 /* TODO: Provide a Logical ID for the text: */
1491 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1495 /* The user name and email address must be set additionally: */
1496 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1497 modest_account_mgr_set_string (self->account_manager, account_name,
1498 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1500 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1501 modest_account_mgr_set_string (self->account_manager, account_name,
1502 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1504 /* Set the display name: */
1505 modest_account_mgr_set_string (self->account_manager, account_name,
1506 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1508 /* Set retrieve type */
1509 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1510 modest_account_mgr_set_string (self->account_manager, account_name,
1511 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1513 /* Save the connection-specific SMTP server accounts. */
1514 gboolean result = TRUE;
1515 if (self->specific_window)
1516 result = modest_connection_specific_smtp_window_save_server_accounts (
1517 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1519 g_free (self->saved_account_name);
1520 self->saved_account_name = g_strdup (account_name);
1522 g_free (account_name);