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);
499 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
500 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
501 gtk_widget_show (label);
502 gtk_widget_show (GTK_WIDGET (box));
503 return GTK_WIDGET (box);
506 /** Change the caption title for the incoming server,
507 * as specified in the UI spec:
509 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
511 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
512 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
514 (protocol == MODEST_PROTOCOL_STORE_POP ?
515 _("mail_fi_emailtype_pop3") :
516 _("mail_fi_emailtype_imap") );
519 /* Note that this produces a compiler warning,
520 * because the compiler does not know that the translated string will have a %s in it.
521 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
522 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
523 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
524 g_free(incomingserver_title);
527 /** Change the caption title for the incoming server,
528 * as specified in the UI spec:
530 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
532 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
533 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
535 /* Fill the combo with appropriately titled choices for POP or IMAP. */
536 /* The choices are the same, but the titles are different, as in the UI spec. */
537 modest_serversecurity_combo_box_fill (
538 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
541 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
543 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
544 update_incoming_server_title (self);
545 update_incoming_server_security_choices (self);
548 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
550 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
552 /* Create a size group to be used by all captions.
553 * Note that HildonCaption does not create a default size group if we do not specify one.
554 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
555 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
557 /* The incoming server widgets: */
558 if (!self->combo_incoming_servertype)
559 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
560 easysetup_servertype_combo_box_set_active_servertype (
561 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
562 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
563 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
564 gtk_widget_show (self->combo_incoming_servertype);
565 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
566 gtk_widget_show (caption);
568 if(!self->entry_incomingserver)
569 self->entry_incomingserver = gtk_entry_new ();
570 /* Auto-capitalization is the default, so let's turn it off: */
571 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
572 set_default_custom_servernames (self);
574 if (self->caption_incoming)
575 gtk_widget_destroy (self->caption_incoming);
577 /* The caption title will be updated in update_incoming_server_title().
578 * so this default text will never be seen: */
579 /* (Note: Changing the title seems pointless. murrayc) */
580 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
581 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
582 update_incoming_server_title (self);
583 gtk_widget_show (self->entry_incomingserver);
584 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
585 gtk_widget_show (self->caption_incoming);
587 /* Change the caption title when the servertype changes,
588 * as in the UI spec: */
589 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
590 G_CALLBACK (on_combo_servertype_changed), self);
592 /* The secure connection widgets: */
593 if (!self->combo_incoming_security)
594 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
595 update_incoming_server_security_choices (self);
596 modest_serversecurity_combo_box_set_active_serversecurity (
597 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
598 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
599 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
600 gtk_widget_show (self->combo_incoming_security);
601 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
602 gtk_widget_show (caption);
604 if(!self->checkbox_incoming_auth)
605 self->checkbox_incoming_auth = gtk_check_button_new ();
606 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
607 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
608 gtk_widget_show (self->checkbox_incoming_auth);
609 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
610 gtk_widget_show (caption);
612 gtk_widget_show (GTK_WIDGET (box));
614 return GTK_WIDGET (box);
618 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
620 GtkWidget *widget = GTK_WIDGET (user_data);
622 /* Enable the widget only if the toggle button is active: */
623 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
624 gtk_widget_set_sensitive (widget, enable);
627 /* Make the sensitivity of a widget depend on a toggle button.
630 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
632 g_signal_connect (G_OBJECT (button), "toggled",
633 G_CALLBACK (on_toggle_button_changed), widget);
635 /* Set the starting sensitivity: */
636 on_toggle_button_changed (button, widget);
640 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
642 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
644 /* Create the window, if necessary: */
645 if (!(self->specific_window)) {
646 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
647 modest_connection_specific_smtp_window_fill_with_connections (
648 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
649 NULL /* account_name, not known yet. */);
652 /* Show the window: */
653 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
654 gtk_widget_show (self->specific_window);
657 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
659 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
661 /* Create a size group to be used by all captions.
662 * Note that HildonCaption does not create a default size group if we do not specify one.
663 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
664 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
666 /* The outgoing server widgets: */
667 if (!self->entry_outgoingserver)
668 self->entry_outgoingserver = gtk_entry_new ();
669 /* Auto-capitalization is the default, so let's turn it off: */
670 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
671 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
672 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
673 gtk_widget_show (self->entry_outgoingserver);
674 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
675 gtk_widget_show (caption);
676 set_default_custom_servernames (self);
678 /* The secure connection widgets: */
679 if (!self->combo_outgoing_security)
680 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
681 modest_serversecurity_combo_box_fill (
682 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
683 modest_serversecurity_combo_box_set_active_serversecurity (
684 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
685 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
686 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
687 gtk_widget_show (self->combo_outgoing_security);
688 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
689 gtk_widget_show (caption);
691 /* The secure authentication widgets: */
692 if (!self->combo_outgoing_auth)
693 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
694 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
695 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
696 gtk_widget_show (self->combo_outgoing_auth);
697 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
698 gtk_widget_show (caption);
700 GtkWidget *separator = gtk_hseparator_new ();
701 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
702 gtk_widget_show (separator);
704 /* connection-specific checkbox: */
705 if (!self->checkbox_outgoing_smtp_specific) {
706 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
707 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
710 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
711 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
712 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
713 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
714 gtk_widget_show (caption);
716 /* Connection-specific SMTP-Severs Edit button: */
717 if (!self->button_outgoing_smtp_servers)
718 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
719 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
720 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
721 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
722 gtk_widget_show (self->button_outgoing_smtp_servers);
723 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
724 gtk_widget_show (caption);
726 /* Only enable the button when the checkbox is checked: */
727 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
728 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
730 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
731 G_CALLBACK (on_button_outgoing_smtp_servers), self);
734 gtk_widget_show (GTK_WIDGET (box));
736 return GTK_WIDGET (box);
740 on_timeout_show_advanced_edit(gpointer user_data)
742 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
744 if (!(self->saved_account_name))
747 /* Show the Account Settings window: */
748 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
749 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
751 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
753 gtk_dialog_run (GTK_DIALOG (dialog));
755 /* TODO: The hide() is not necessary.
756 * It is just here to show that it doesn't work,
757 * just as destroy doesn't work.
759 gtk_widget_hide (GTK_WIDGET(dialog));
761 /* TODO: The dialog remains on screen, not allowing any interaction.
762 * But gtk_widget_destroy() should always destroy.
764 printf("debug: destroying settings dialog\n");
765 gtk_widget_destroy (GTK_WIDGET (dialog));
766 printf("debug: after destroying settings dialog (doesn't seem to work).\n");
768 return FALSE; /* Do not call this timeout callback again. */
772 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
774 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
776 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
777 * without recoding it to use non-gconf information.
778 * This account will be deleted if Finish is never actually clicked. */
780 gboolean saved = TRUE;
781 gboolean was_already_saved = TRUE;
782 if (!(self->saved_account_name)) {
783 saved = create_account (self, FALSE);
784 was_already_saved = FALSE;
790 if (!(self->saved_account_name))
793 /* Show the Account Settings window: */
794 if (was_already_saved) {
795 /* Just show the dialog immediately: */
796 on_timeout_show_advanced_edit(self);
800 printf ("debug: waiting for gconf to update its local cache. "
801 "This is a hack to work around a maemo gconf bug in maemo bora.\n");
803 g_timeout_add (5000, on_timeout_show_advanced_edit, self);
806 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
808 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
809 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
810 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
811 gtk_widget_show (label);
813 if (!self->button_edit)
814 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
815 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
816 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
817 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
818 gtk_widget_show (self->button_edit);
819 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
820 gtk_widget_show (caption);
822 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
823 G_CALLBACK (on_button_edit_advanced_settings), self);
825 gtk_widget_show (GTK_WIDGET (box));
826 return GTK_WIDGET (box);
833 on_response (ModestWizardDialog *wizard_dialog,
837 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
839 if (response_id == GTK_RESPONSE_CANCEL) {
840 /* Remove any temporarily-saved account that will not actually be needed: */
841 if (self->saved_account_name) {
842 modest_account_mgr_remove_account (self->account_manager,
843 self->saved_account_name, FALSE);
847 invoke_enable_buttons_vfunc (self);
851 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
853 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
855 /* Create the notebook to be used by the ModestWizardDialog base class:
856 * Each page of the notebook will be a page of the wizard: */
857 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
859 /* Set the notebook used by the ModestWizardDialog base class: */
860 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
862 /* Set the wizard title:
863 * The actual window title will be a combination of this and the page's tab label title. */
864 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
866 /* Read in the information about known service providers: */
867 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
869 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
870 priv->presets = modest_presets_new (filepath);
871 if (!(priv->presets)) {
872 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
875 g_assert(priv->presets);
878 /* Get the account manager object,
879 * so we can check for existing accounts,
880 * and create new accounts: */
881 self->account_manager = modest_runtime_get_account_mgr ();
882 g_assert (self->account_manager);
883 g_object_ref (self->account_manager);
885 /* Create the common pages,
887 self->page_welcome = create_page_welcome (self);
888 self->page_account_details = create_page_account_details (self);
889 self->page_user_details = create_page_user_details (self);
891 /* Add the common pages: */
892 gtk_notebook_append_page (notebook, self->page_welcome,
893 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
894 gtk_notebook_append_page (notebook, self->page_account_details,
895 gtk_label_new (_("mcen_ti_accountdetails")));
896 gtk_notebook_append_page (notebook, self->page_user_details,
897 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
899 /* Create and add the easysetup-specific pages,
900 * because we need _some_ final page to enable the Next and Finish buttons: */
901 create_subsequent_easysetup_pages (self);
904 /* Connect to the dialog's response signal so we can enable/disable buttons
905 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
906 * Note that we use g_signal_connect_after() instead of g_signal_connect()
907 * so that we can be enable/disable after ModestWizardDialog has done its own
908 * enabling/disabling of buttons.
910 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
911 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
913 * It's not enough to connect to the notebook's switch-page signal, because
914 * ModestWizardDialog's "response" signal handler enables the buttons itself,
915 * _after_ switching the page (understandably).
916 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
917 * then gtk_notebook_get_current_page() would return an incorrect value.)
919 g_signal_connect_after (G_OBJECT (self), "response",
920 G_CALLBACK (on_response), self);
922 /* When this window is shown, hibernation should not be possible,
923 * because there is no sensible way to save the state: */
924 modest_window_mgr_prevent_hibernation_while_window_is_shown (
925 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
928 ModestEasysetupWizardDialog*
929 modest_easysetup_wizard_dialog_new (void)
931 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
934 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
936 GtkNotebook *notebook = NULL;
937 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
940 /* Create the custom pages: */
941 if(!(self->page_custom_incoming)) {
942 self->page_custom_incoming = create_page_custom_incoming (self);
945 if(!(self->page_custom_outgoing)) {
946 self->page_custom_outgoing = create_page_custom_outgoing (self);
949 if(!(self->page_complete_customsetup)) {
950 self->page_complete_customsetup = create_page_complete_custom (self);
953 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
954 gtk_notebook_append_page (notebook, self->page_custom_incoming,
955 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
957 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
958 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
959 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
961 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
962 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
963 gtk_label_new (_("mcen_ti_emailsetup_complete")));
965 /* This is unnecessary with GTK+ 2.10: */
966 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
969 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
971 GtkNotebook *notebook = NULL;
972 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
975 /* Create the easysetup-specific pages: */
976 if(!self->page_complete_easysetup)
977 self->page_complete_easysetup = create_page_complete_easysetup (self);
979 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
980 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
981 gtk_label_new (_("mcen_ti_emailsetup_complete")));
983 /* This is unnecessary with GTK+ 2.10: */
984 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
986 /* After the user details page,
987 * the following pages depend on whether "Other" was chosen
988 * in the provider combobox on the account page
990 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
992 if (easysetup_provider_combo_box_get_active_provider_id (
993 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
994 /* "Other..." was selected: */
996 /* Make sure that the easysetup pages do not exist: */
997 if(self->page_complete_easysetup) {
998 gtk_widget_destroy (self->page_complete_easysetup);
999 self->page_complete_easysetup = NULL;
1002 create_subsequent_customsetup_pages (self);
1005 /* A specific provider was selected: */
1007 /* Make sure that the custom pages do not exist:
1008 * Because they will be used if they exist, when creating the account. */
1009 if(self->page_custom_incoming) {
1010 gtk_widget_destroy (self->page_custom_incoming);
1011 self->page_custom_incoming = NULL;
1014 if(self->page_custom_outgoing) {
1015 gtk_widget_destroy (self->page_custom_outgoing);
1016 self->page_custom_outgoing = NULL;
1019 if(self->page_complete_customsetup) {
1020 gtk_widget_destroy (self->page_complete_customsetup);
1021 self->page_complete_customsetup = NULL;
1025 /* Create the easysetup pages: */
1026 create_subsequent_easysetup_pages (self);
1032 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1037 gchar* at = g_utf8_strchr (email_address, -1, '@');
1038 if (!at || (g_utf8_strlen (at, -1) < 2))
1041 gchar* domain = g_utf8_next_char (at);
1045 const gchar* hostname = NULL;
1046 if (servertype == MODEST_PROTOCOL_STORE_POP)
1048 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1050 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1056 return g_strdup_printf ("%s.%s", hostname, domain);
1059 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1061 if (!account_wizard->entry_incomingserver)
1064 /* Set a default domain for the server, based on the email address,
1065 * if no server name was already specified.
1067 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
1068 if ((!incoming_existing || (strlen(incoming_existing) == 0))
1069 && account_wizard->entry_user_email) {
1070 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1071 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1072 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1074 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1075 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1076 g_free (servername);
1079 /* Set a default domain for the server, based on the email address,
1080 * if no server name was already specified.
1082 if (!account_wizard->entry_outgoingserver)
1085 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
1086 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
1087 && account_wizard->entry_user_email) {
1088 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1090 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1091 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1092 g_free (servername);
1097 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1099 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1101 /* Do extra validation that couldn't be done for every key press,
1102 * either because it was too slow,
1103 * or because it requires interaction:
1105 if (current_page == account_wizard->page_account_details) {
1106 /* Check that the title is not already in use: */
1107 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1108 if ((!account_title) || (strlen(account_title) == 0))
1111 /* Aavoid a clash with an existing display name: */
1112 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1113 account_wizard->account_manager, account_title);
1116 /* Warn the user via a dialog: */
1117 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing"));
1122 else if (current_page == account_wizard->page_user_details) {
1123 /* Check that the email address is valud: */
1124 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1125 if ((!email_address) || (strlen(email_address) == 0))
1128 if (!modest_text_utils_validate_email_address (email_address)) {
1129 /* Warn the user via a dialog: */
1130 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1132 /* Return focus to the email address entry: */
1133 gtk_widget_grab_focus (account_wizard->entry_user_email);
1138 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1139 create_subsequent_pages (account_wizard);
1142 /* TODO: The UI Spec wants us to check that the servernames are valid,
1143 * but does not specify how.
1146 if(next_page == account_wizard->page_custom_incoming) {
1147 set_default_custom_servernames (account_wizard);
1149 else if (next_page == account_wizard->page_custom_outgoing) {
1150 set_default_custom_servernames (account_wizard);
1153 /* If this is the last page, and this is a click on Finish,
1154 * then attempt to create the dialog.
1156 if(!next_page) /* This is NULL when this is a click on Finish. */
1158 if (account_wizard->saved_account_name) {
1159 /* Just enable the already-saved account (temporarily created when
1160 * editing advanced settings): */
1161 modest_account_mgr_set_enabled (account_wizard->account_manager,
1162 account_wizard->saved_account_name, TRUE);
1164 create_account (account_wizard, TRUE /* enabled */);
1172 static gboolean entry_is_empty (GtkWidget *entry)
1177 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1178 if ((!text) || (strlen(text) == 0))
1185 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1187 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1189 gboolean enable_next = TRUE;
1190 if (current_page == account_wizard->page_welcome) {
1193 else if (current_page == account_wizard->page_account_details) {
1194 /* The account details title is mandatory: */
1195 if (entry_is_empty(account_wizard->entry_account_title))
1196 enable_next = FALSE;
1198 else if (current_page == account_wizard->page_user_details) {
1199 /* The user details username is mandatory: */
1200 if (entry_is_empty(account_wizard->entry_user_username))
1201 enable_next = FALSE;
1203 /* The user details email address is mandatory: */
1204 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1205 enable_next = FALSE;
1207 else if (current_page == account_wizard->page_custom_incoming) {
1208 /* The custom incoming server is mandatory: */
1209 if (entry_is_empty(account_wizard->entry_incomingserver))
1210 enable_next = FALSE;
1213 /* Enable the buttons,
1214 * identifying them via their associated response codes: */
1216 /* Disable the Finish button until we are on the last page,
1217 * because HildonWizardDialog enables this for all but the first page: */
1218 GtkNotebook *notebook = NULL;
1219 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1220 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1222 gint current = gtk_notebook_get_current_page (notebook);
1223 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1224 const gboolean is_last = (current == last);
1227 gtk_dialog_set_response_sensitive (dialog_base,
1228 MODEST_WIZARD_DIALOG_FINISH,
1232 /* Disable Next on the last page: */
1233 enable_next = FALSE;
1236 gtk_dialog_set_response_sensitive (dialog_base,
1237 MODEST_WIZARD_DIALOG_NEXT,
1242 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1244 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1245 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1248 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1249 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1250 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1251 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1253 /* Provide a vfunc implementation so we can decide
1254 * when to enable/disable the prev/next buttons.
1256 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1257 base_klass->before_next = on_before_next;
1258 base_klass->enable_buttons = on_enable_buttons;
1262 show_error (GtkWindow *parent_window, const gchar* text)
1264 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1266 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1273 gtk_dialog_run (dialog);
1274 gtk_widget_destroy (GTK_WIDGET (dialog));
1277 /** Attempt to create the account from the information that the user has entered.
1278 * @result: TRUE if the account was successfully created.
1281 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1283 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1285 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1291 /* We should have checked for this already,
1292 * and changed that name accordingly,
1293 * but let's check again just in case:
1295 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1298 /* Increment the non-user visible name if necessary,
1299 * based on the display name: */
1300 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1301 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1302 account_name_start, FALSE /* not a server account */);
1303 g_free (account_name_start);
1305 /* username and password (for both incoming and outgoing): */
1306 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1307 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1309 /* Incoming server: */
1310 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1311 * or modest_account_mgr_add_server_account will fail. */
1312 gchar* servername_incoming = NULL;
1313 guint serverport_incoming = 0;
1314 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1315 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1316 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1318 /* Get details from the specified presets: */
1319 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1320 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1323 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1324 TRUE /* incoming */);
1326 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1328 TRUE /* incoming */);
1329 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1331 TRUE /* incoming */);
1333 g_warning ("security incoming: %x", security_incoming);
1335 /* We don't check for SMTP here as that is impossible for an incoming server. */
1336 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1337 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1338 serverport_incoming =
1339 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
1340 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1341 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1342 serverport_incoming =
1343 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
1346 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1347 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1349 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1350 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1353 /* Use custom pages because no preset was specified: */
1354 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1356 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1357 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1359 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1360 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1362 /* The UI spec says:
1363 * If secure authentication is unchecked, allow sending username and password also as plain text.
1364 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1365 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1367 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1368 ? MODEST_PROTOCOL_AUTH_CRAMMD5
1369 : MODEST_PROTOCOL_AUTH_PASSWORD;
1372 /* First we add the 2 server accounts, and then we add the account that uses them.
1373 * If we don't do it in this order then we will experience a crash. */
1375 /* Add a (incoming) server account, to be used by the account: */
1376 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1377 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1378 store_name_start, TRUE /* server account */);
1379 g_free (store_name_start);
1380 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1382 servername_incoming,
1383 serverport_incoming,
1386 protocol_security_incoming,
1387 protocol_authentication_incoming);
1389 g_free (servername_incoming);
1392 /* TODO: Provide a Logical ID for the text: */
1393 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1398 /* There must be at least one account now: */
1399 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1400 * fixed in versions after 3.1. */
1401 GSList *account_names = modest_account_mgr_account_names (self->account_manager, FALSE);
1404 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1406 g_slist_free (account_names);
1409 /* Outgoing server: */
1410 gchar* servername_outgoing = NULL;
1411 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1412 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1413 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1414 guint serverport_outgoing = 0;
1418 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1419 FALSE /* incoming */);
1421 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1423 FALSE /* incoming */);
1425 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1426 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1427 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1428 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1430 ModestPresetsSecurity security_outgoing =
1431 modest_presets_get_info_server_security (priv->presets, provider_id,
1432 FALSE /* incoming */);
1434 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1435 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1436 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1437 serverport_outgoing = 465;
1438 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1440 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1441 /* TODO: There is no SMTP authentication enum for presets. */
1444 /* Use custom pages because no preset was specified: */
1445 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1447 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1449 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1450 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1452 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1453 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1456 /* Add a (outgoing) server account to be used by the account: */
1457 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1458 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1459 transport_name_start, TRUE /* server account */);
1460 g_free (transport_name_start);
1461 created = modest_account_mgr_add_server_account (self->account_manager,
1463 servername_outgoing,
1464 serverport_outgoing,
1467 protocol_security_outgoing,
1468 protocol_authentication_outgoing);
1470 g_free (servername_outgoing);
1473 /* TODO: Provide a Logical ID for the text: */
1474 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1479 /* Create the account, which will contain the two "server accounts": */
1480 created = modest_account_mgr_add_account (self->account_manager, account_name,
1481 store_name, /* The name of our POP/IMAP server account. */
1482 transport_name, /* The name of our SMTP server account. */
1484 g_free (store_name);
1485 g_free (transport_name);
1488 /* TODO: Provide a Logical ID for the text: */
1489 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1493 /* The user name and email address must be set additionally: */
1494 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1495 modest_account_mgr_set_string (self->account_manager, account_name,
1496 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1498 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1499 modest_account_mgr_set_string (self->account_manager, account_name,
1500 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1502 /* Set the display name: */
1503 modest_account_mgr_set_string (self->account_manager, account_name,
1504 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1506 /* Set retrieve type */
1507 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1508 modest_account_mgr_set_string (self->account_manager, account_name,
1509 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1511 /* Save the connection-specific SMTP server accounts. */
1512 gboolean result = TRUE;
1513 if (self->specific_window)
1514 result = modest_connection_specific_smtp_window_save_server_accounts (
1515 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1517 g_free (self->saved_account_name);
1518 self->saved_account_name = g_strdup (account_name);
1520 g_free (account_name);