1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "modest-easysetup-wizard.h"
32 #include <glib/gi18n.h>
33 #include <gtk/gtknotebook.h>
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkcombobox.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkseparator.h>
42 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
43 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
44 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
45 #include "widgets/modest-serversecurity-combo-box.h"
46 #include "widgets/modest-secureauth-combo-box.h"
47 #include "widgets/modest-validating-entry.h"
48 #include "modest-text-utils.h"
49 #include "modest-account-mgr.h"
50 #include "modest-account-mgr-helpers.h"
51 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
52 #include "maemo/modest-connection-specific-smtp-window.h"
53 #include "widgets/modest-ui-constants.h"
54 #include "maemo/modest-account-settings-dialog.h"
55 #include "maemo/modest-maemo-utils.h"
56 #include <gconf/gconf-client.h>
57 #include <string.h> /* For strlen(). */
59 /* Include config.h so that _() works: */
64 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
66 #define WIZARD_DIALOG_GET_PRIVATE(o) \
67 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
69 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
73 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
74 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
75 } ModestEasysetupWizardDialogServerChanges;
77 struct _ModestEasysetupWizardDialogPrivate
79 ModestPresets *presets;
81 /* Remember what fields the user edited manually to not prefill them
83 ModestEasysetupWizardDialogServerChanges server_changes;
85 /* Check if the user changes a field to show a confirmation dialog */
90 on_delete_event (GtkWidget *widget,
92 ModestEasysetupWizardDialog *wizard)
94 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
99 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
101 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(wizard);
102 g_return_if_fail (priv != NULL);
107 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
108 GValue *value, GParamSpec *pspec)
110 switch (property_id) {
112 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
117 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
118 const GValue *value, GParamSpec *pspec)
120 switch (property_id) {
122 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
127 modest_easysetup_wizard_dialog_dispose (GObject *object)
129 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
130 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
134 modest_easysetup_wizard_dialog_finalize (GObject *object)
136 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
137 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
139 if (self->account_manager)
140 g_object_unref (G_OBJECT (self->account_manager));
143 modest_presets_destroy (priv->presets);
145 if (self->specific_window)
146 gtk_widget_destroy (self->specific_window);
148 g_free (self->saved_account_name);
150 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
154 show_error (GtkWidget *parent_widget, const gchar* text);
157 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
160 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
163 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
165 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
167 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
168 ModestPresetsSecurity security_incoming)
170 int serverport_incoming = 0;
171 /* We don't check for SMTP here as that is impossible for an incoming server. */
172 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
173 serverport_incoming =
174 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
175 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
176 serverport_incoming =
177 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
179 return serverport_incoming;
182 static GList* check_for_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
184 GError *error = NULL;
185 const ModestTransportStoreProtocol protocol =
186 easysetup_servertype_combo_box_get_active_servertype (
187 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
188 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
189 const gchar* username = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_user_username));
190 const ModestConnectionProtocol protocol_security_incoming =
191 modest_serversecurity_combo_box_get_active_serversecurity (
192 MODEST_SERVERSECURITY_COMBO_BOX (
193 account_wizard->combo_incoming_security));
194 const int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
195 GList *list_auth_methods =
196 modest_maemo_utils_get_supported_secure_authentication_methods (
198 hostname, port_num, username, GTK_WINDOW (account_wizard), &error);
199 if (list_auth_methods) {
200 /* TODO: Select the correct method */
203 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
204 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
205 if (modest_protocol_info_auth_is_secure(auth)) {
206 list = g_list_append(list, GINT_TO_POINTER(auth));
210 g_list_free(list_auth_methods);
216 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
217 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
219 show_error (GTK_WIDGET(account_wizard), _("Could not discover supported secure authentication methods."));
228 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
230 GList* methods = check_for_supported_auth_methods(account_wizard);
236 g_list_free(methods);
240 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* account_wizard)
242 ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
244 GList* methods = check_for_supported_auth_methods(account_wizard);
247 /* Use the first one: */
248 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
249 g_list_free(methods);
256 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
258 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
260 /* Call the vfunc, which may be overridden by derived classes: */
261 if (klass->enable_buttons) {
262 GtkNotebook *notebook = NULL;
263 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
265 const gint current_page_num = gtk_notebook_get_current_page (notebook);
266 if (current_page_num == -1)
269 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
270 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
275 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
277 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
279 invoke_enable_buttons_vfunc(self);
283 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
285 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
287 invoke_enable_buttons_vfunc(self);
290 /** This is a convenience function to create a caption containing a mandatory widget.
291 * When the widget is edited, the enable_buttons() vfunc will be called.
293 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
298 HildonCaptionStatus flag)
300 GtkWidget *caption = NULL;
302 /* Note: Previously, the translated strings already contained the "*",
303 * Comment out this code if they do again.
305 /* Add a * character to indicate mandatory fields,
306 * as specified in our "Email UI Specification": */
307 if (flag == HILDON_CAPTION_MANDATORY) {
308 gchar* title = g_strdup_printf("%s*", value);
309 caption = hildon_caption_new (group, title, control, icon, flag);
313 caption = hildon_caption_new (group, value, control, icon, flag);
315 /* Connect to the appropriate changed signal for the widget,
316 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
318 if (GTK_IS_ENTRY (control)) {
319 g_signal_connect (G_OBJECT (control), "changed",
320 G_CALLBACK (on_caption_entry_changed), self);
323 else if (GTK_IS_COMBO_BOX (control)) {
324 g_signal_connect (G_OBJECT (control), "changed",
325 G_CALLBACK (on_caption_combobox_changed), self);
332 create_page_welcome (ModestEasysetupWizardDialog *self)
334 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
335 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
336 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
337 /* So that it is not truncated: */
338 gtk_widget_set_size_request (label, 600, -1);
339 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
340 gtk_widget_show (label);
341 gtk_widget_show (GTK_WIDGET (box));
342 return GTK_WIDGET (box);
346 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
348 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
350 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
354 /* Fill the providers combo, based on the selected country: */
355 if (priv->presets != NULL) {
356 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
357 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
358 easysetup_provider_combo_box_fill (
359 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc);
364 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
366 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
368 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
372 /* Fill the providers combo, based on the selected country: */
373 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
374 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
376 gchar* domain_name = NULL;
378 domain_name = modest_presets_get_domain (priv->presets, provider_id);
381 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
383 if (self->entry_user_email)
384 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
386 g_free (domain_name);
388 g_free (provider_id);
392 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
394 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
395 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
399 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
401 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
403 const gchar *show_char = NULL;
405 show_char = character;
407 /* TODO: We need a logical ID for this: */
408 show_char = _("whitespace");
411 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
412 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
413 show_error (GTK_WIDGET (self), message);
417 create_page_account_details (ModestEasysetupWizardDialog *self)
419 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
420 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
421 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
422 gtk_widget_set_size_request (label, 600, -1);
423 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
424 gtk_widget_show (label);
426 /* Create a size group to be used by all captions.
427 * Note that HildonCaption does not create a default size group if we do not specify one.
428 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
429 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
431 /* The country widgets: */
432 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
433 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
434 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
435 gtk_widget_show (self->combo_account_country);
436 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
437 gtk_widget_show (caption);
439 /* connect to country combo's changed signal, so we can fill the provider combo: */
440 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
441 G_CALLBACK (on_combo_account_country), self);
443 GtkWidget *separator = gtk_hseparator_new ();
444 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
445 gtk_widget_show (separator);
447 /* The service provider widgets: */
448 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
449 gtk_widget_set_size_request (self->combo_account_serviceprovider, 320, -1);
451 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
452 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
453 gtk_widget_show (self->combo_account_serviceprovider);
454 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
455 gtk_widget_show (caption);
457 /* connect to providers combo's changed signal, so we can fill the email address: */
458 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
459 G_CALLBACK (on_combo_account_serviceprovider), self);
461 /* TODO: Default to the current country somehow.
462 * But I don't know how to get the information that is specified in the
463 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
465 * This is probably not the best choice of gconf key:
466 * This is the "mcc used in the last pairing", ie. the last connection you made.
467 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
470 GError *error = NULL;
471 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
472 gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
478 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
479 g_error_free (error);
485 /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
486 * This might just be a Maemo bug.
490 /* For now, we default to Finland when there is nothing better: */
494 easysetup_country_combo_box_set_active_country_mcc (
495 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
498 /* The description widgets: */
499 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
500 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
501 G_CALLBACK(on_easysetup_changed), self);
502 /* Do use auto-capitalization: */
503 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
504 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
506 /* Set a default account title, choosing one that does not already exist: */
507 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
508 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
509 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
510 self->account_manager, default_account_name_start);
511 g_free (default_account_name_start);
512 default_account_name_start = NULL;
514 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
515 g_free (default_account_name);
516 default_account_name = NULL;
518 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
519 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
520 gtk_widget_show (self->entry_account_title);
521 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
522 gtk_widget_show (caption);
524 /* Prevent the use of some characters in the account title,
525 * as required by our UI specification: */
526 GList *list_prevent = NULL;
527 list_prevent = g_list_append (list_prevent, "\\");
528 list_prevent = g_list_append (list_prevent, "/");
529 list_prevent = g_list_append (list_prevent, ":");
530 list_prevent = g_list_append (list_prevent, "*");
531 list_prevent = g_list_append (list_prevent, "?");
532 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
533 list_prevent = g_list_append (list_prevent, "“");
534 list_prevent = g_list_append (list_prevent, "<");
535 list_prevent = g_list_append (list_prevent, ">");
536 list_prevent = g_list_append (list_prevent, "|");
537 list_prevent = g_list_append (list_prevent, "^");
538 modest_validating_entry_set_unallowed_characters (
539 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
540 g_list_free (list_prevent);
542 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
543 on_entry_invalid_character, self);
545 /* Set max length as in the UI spec:
546 * The UI spec seems to want us to show a dialog if we hit the maximum. */
547 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
548 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
551 gtk_widget_show (GTK_WIDGET (box));
553 return GTK_WIDGET (box);
557 create_page_user_details (ModestEasysetupWizardDialog *self)
559 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
561 /* Create a size group to be used by all captions.
562 * Note that HildonCaption does not create a default size group if we do not specify one.
563 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
564 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
566 /* The name widgets: (use auto cap) */
567 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
568 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name),
569 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
571 /* Set max length as in the UI spec:
572 * The UI spec seems to want us to show a dialog if we hit the maximum. */
573 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
574 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
576 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
577 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
578 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
579 G_CALLBACK(on_easysetup_changed), self);
580 gtk_widget_show (self->entry_user_name);
581 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
582 gtk_widget_show (caption);
584 /* Prevent the use of some characters in the name,
585 * as required by our UI specification: */
586 GList *list_prevent = NULL;
587 list_prevent = g_list_append (list_prevent, "<");
588 list_prevent = g_list_append (list_prevent, ">");
589 modest_validating_entry_set_unallowed_characters (
590 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
591 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
592 on_entry_invalid_character, self);
593 g_list_free (list_prevent);
595 /* The username widgets: */
596 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
597 /* Auto-capitalization is the default, so let's turn it off: */
598 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
599 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
600 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
601 gtk_widget_show (self->entry_user_username);
602 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
603 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
604 G_CALLBACK(on_easysetup_changed), self);
605 gtk_widget_show (caption);
607 /* Prevent the use of some characters in the username,
608 * as required by our UI specification: */
609 modest_validating_entry_set_unallowed_characters_whitespace (
610 MODEST_VALIDATING_ENTRY (self->entry_user_username));
611 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_username),
612 on_entry_invalid_character, self);
614 /* Set max length as in the UI spec:
615 * The UI spec seems to want us to show a dialog if we hit the maximum. */
616 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
617 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
620 /* The password widgets: */
621 self->entry_user_password = gtk_entry_new ();
622 /* Auto-capitalization is the default, so let's turn it off: */
623 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
624 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
625 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
626 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
627 caption = create_caption_new_with_asterisk (self, sizegroup,
628 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
629 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
630 G_CALLBACK(on_easysetup_changed), self);
631 gtk_widget_show (self->entry_user_password);
632 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
633 gtk_widget_show (caption);
635 /* The email address widgets: */
636 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
637 /* Auto-capitalization is the default, so let's turn it off: */
638 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
639 caption = create_caption_new_with_asterisk (self, sizegroup,
640 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
641 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
642 gtk_widget_show (self->entry_user_email);
643 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
644 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
645 G_CALLBACK(on_easysetup_changed), self);
646 gtk_widget_show (caption);
648 /* Set max length as in the UI spec:
649 * The UI spec seems to want us to show a dialog if we hit the maximum. */
650 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
651 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
655 gtk_widget_show (GTK_WIDGET (box));
657 return GTK_WIDGET (box);
660 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
662 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
664 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
665 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
666 gtk_widget_set_size_request (label, 600, -1);
667 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
668 /* The documentation for gtk_label_set_line_wrap() says that we must
669 * call gtk_widget_set_size_request() with a hard-coded width,
670 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
671 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
672 gtk_widget_show (label);
674 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
675 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
676 gtk_widget_set_size_request (label, 600, -1);
678 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
679 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
680 gtk_widget_show (label);
682 gtk_widget_show (GTK_WIDGET (box));
683 return GTK_WIDGET (box);
686 /** Change the caption title for the incoming server,
687 * as specified in the UI spec:
689 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
691 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
692 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
694 (protocol == MODEST_PROTOCOL_STORE_POP ?
695 _("mail_fi_emailtype_pop3") :
696 _("mail_fi_emailtype_imap") );
699 /* Note that this produces a compiler warning,
700 * because the compiler does not know that the translated string will have a %s in it.
701 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
702 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
703 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
704 g_free(incomingserver_title);
707 /** Change the caption title for the incoming server,
708 * as specified in the UI spec:
710 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
712 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
713 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
715 /* Fill the combo with appropriately titled choices for POP or IMAP. */
716 /* The choices are the same, but the titles are different, as in the UI spec. */
717 modest_serversecurity_combo_box_fill (
718 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
721 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
723 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
724 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
728 update_incoming_server_title (self);
729 update_incoming_server_security_choices (self);
731 set_default_custom_servernames (self);
734 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
736 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
737 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
739 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
742 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
744 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
745 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
747 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
749 GTK_POLICY_AUTOMATIC);
751 /* Show note that account type cannot be changed in future: */
752 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
753 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
754 gtk_widget_set_size_request (label, 600, -1);
755 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
756 gtk_widget_show (label);
758 /* Create a size group to be used by all captions.
759 * Note that HildonCaption does not create a default size group if we do not specify one.
760 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
761 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
763 /* The incoming server widgets: */
764 if (!self->combo_incoming_servertype)
765 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
766 easysetup_servertype_combo_box_set_active_servertype (
767 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
768 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
769 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
770 gtk_widget_show (self->combo_incoming_servertype);
771 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
772 gtk_widget_show (caption);
774 if(!self->entry_incomingserver)
776 self->entry_incomingserver = gtk_entry_new ();
777 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed",
778 G_CALLBACK(on_easysetup_changed), self);
780 /* Auto-capitalization is the default, so let's turn it off: */
781 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
782 set_default_custom_servernames (self);
784 if (self->caption_incoming)
785 gtk_widget_destroy (self->caption_incoming);
787 /* The caption title will be updated in update_incoming_server_title().
788 * so this default text will never be seen: */
789 /* (Note: Changing the title seems pointless. murrayc) */
790 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
791 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
792 update_incoming_server_title (self);
793 gtk_widget_show (self->entry_incomingserver);
794 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
795 gtk_widget_show (self->caption_incoming);
797 /* Change the caption title when the servertype changes,
798 * as in the UI spec: */
799 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
800 G_CALLBACK (on_combo_servertype_changed), self);
802 /* Remember when the servername was changed manually: */
803 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
804 G_CALLBACK (on_entry_incoming_servername_changed), self);
806 /* The secure connection widgets: */
807 if (!self->combo_incoming_security)
808 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
809 update_incoming_server_security_choices (self);
810 modest_serversecurity_combo_box_set_active_serversecurity (
811 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
812 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
813 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
814 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
815 G_CALLBACK (on_easysetup_changed), self);
816 gtk_widget_show (self->combo_incoming_security);
817 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
818 gtk_widget_show (caption);
820 if(!self->checkbox_incoming_auth)
822 self->checkbox_incoming_auth = gtk_check_button_new ();
823 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
824 G_CALLBACK (on_easysetup_changed), self);
826 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
827 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
829 gtk_widget_show (self->checkbox_incoming_auth);
830 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
831 gtk_widget_show (caption);
833 gtk_widget_show (GTK_WIDGET (box));
835 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
836 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
837 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
838 gtk_widget_show (scrolled_window);
840 return GTK_WIDGET (scrolled_window);
844 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
846 GtkWidget *widget = GTK_WIDGET (user_data);
848 /* Enable the widget only if the toggle button is active: */
849 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
850 gtk_widget_set_sensitive (widget, enable);
853 /* Make the sensitivity of a widget depend on a toggle button.
856 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
858 g_signal_connect (G_OBJECT (button), "toggled",
859 G_CALLBACK (on_toggle_button_changed), widget);
861 /* Set the starting sensitivity: */
862 on_toggle_button_changed (button, widget);
866 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
868 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
869 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
871 /* We set dirty here because setting it depending on the connection specific dialog
875 /* Create the window, if necessary: */
876 if (!(self->specific_window)) {
877 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
878 modest_connection_specific_smtp_window_fill_with_connections (
879 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager);
882 /* Show the window: */
883 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
884 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
885 gtk_widget_show (self->specific_window);
888 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
890 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
891 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
892 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
895 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
897 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
899 /* Create a size group to be used by all captions.
900 * Note that HildonCaption does not create a default size group if we do not specify one.
901 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
902 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
904 /* The outgoing server widgets: */
905 if (!self->entry_outgoingserver)
907 self->entry_outgoingserver = gtk_entry_new ();
908 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
909 G_CALLBACK (on_easysetup_changed), self);
911 /* Auto-capitalization is the default, so let's turn it off: */
912 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
913 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
914 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
915 gtk_widget_show (self->entry_outgoingserver);
916 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
917 gtk_widget_show (caption);
918 set_default_custom_servernames (self);
920 /* The secure connection widgets: */
921 if (!self->combo_outgoing_security)
923 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
924 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
925 G_CALLBACK (on_easysetup_changed), self);
927 modest_serversecurity_combo_box_fill (
928 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
929 modest_serversecurity_combo_box_set_active_serversecurity (
930 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
931 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
932 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
933 gtk_widget_show (self->combo_outgoing_security);
934 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
935 gtk_widget_show (caption);
937 /* The secure authentication widgets: */
938 if (!self->combo_outgoing_auth)
940 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
941 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
942 G_CALLBACK (on_easysetup_changed), self);
944 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
945 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
946 gtk_widget_show (self->combo_outgoing_auth);
947 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
948 gtk_widget_show (caption);
950 GtkWidget *separator = gtk_hseparator_new ();
951 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
952 gtk_widget_show (separator);
954 /* connection-specific checkbox: */
955 if (!self->checkbox_outgoing_smtp_specific) {
956 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
957 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
959 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
960 G_CALLBACK (on_easysetup_changed), self);
963 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
964 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
965 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
966 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
967 gtk_widget_show (caption);
969 /* Connection-specific SMTP-Severs Edit button: */
970 if (!self->button_outgoing_smtp_servers)
971 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
972 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
973 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
974 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
975 gtk_widget_show (self->button_outgoing_smtp_servers);
976 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
977 gtk_widget_show (caption);
979 /* Only enable the button when the checkbox is checked: */
980 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
981 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
983 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
984 G_CALLBACK (on_button_outgoing_smtp_servers), self);
986 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
987 G_CALLBACK (on_entry_outgoing_servername_changed), self);
990 gtk_widget_show (GTK_WIDGET (box));
992 return GTK_WIDGET (box);
996 show_advanced_edit(gpointer user_data)
998 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1000 if (!(self->saved_account_name))
1003 /* Show the Account Settings window: */
1004 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
1005 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
1007 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
1009 gtk_dialog_run (GTK_DIALOG (dialog));
1011 gtk_widget_destroy (GTK_WIDGET (dialog));
1013 return FALSE; /* Do not call this timeout callback again. */
1017 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
1019 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
1021 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
1022 * without recoding it to use non-gconf information.
1023 * This account will be deleted if Finish is never actually clicked. */
1025 gboolean saved = TRUE;
1026 if (!(self->saved_account_name)) {
1027 saved = create_account (self, FALSE);
1033 if (!(self->saved_account_name))
1036 /* Show the Account Settings window: */
1037 show_advanced_edit(self);
1039 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1041 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1042 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1043 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1044 gtk_widget_set_size_request (label, 600, -1);
1045 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1046 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1047 gtk_widget_show (label);
1049 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1050 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1051 gtk_widget_set_size_request (label, 600, -1);
1052 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1053 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1054 gtk_widget_show (label);
1056 if (!self->button_edit)
1057 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1058 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1059 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1060 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1061 gtk_widget_show (self->button_edit);
1062 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1063 gtk_widget_show (caption);
1065 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
1066 G_CALLBACK (on_button_edit_advanced_settings), self);
1068 gtk_widget_show (GTK_WIDGET (box));
1069 return GTK_WIDGET (box);
1076 on_response (ModestWizardDialog *wizard_dialog,
1080 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1081 if (response_id == GTK_RESPONSE_CANCEL) {
1082 /* Remove any temporarily-saved account that will not actually be needed: */
1083 if (self->saved_account_name) {
1084 modest_account_mgr_remove_account (self->account_manager,
1085 self->saved_account_name);
1089 invoke_enable_buttons_vfunc (self);
1093 on_response_before (ModestWizardDialog *wizard_dialog,
1097 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1098 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1099 if (response_id == GTK_RESPONSE_CANCEL) {
1100 /* This is mostly copied from
1101 * src/maemo/modest-account-settings-dialog.c */
1103 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1104 _("imum_nc_wizard_confirm_lose_changes")));
1105 /* TODO: These button names will be ambiguous, and not
1106 * specified in the UI specification. */
1108 const gint dialog_response = gtk_dialog_run (dialog);
1109 self->combo_account_country = NULL;
1110 gtk_widget_destroy (GTK_WIDGET (dialog));
1112 if (dialog_response != GTK_RESPONSE_OK) {
1113 /* Don't let the dialog close */
1114 g_signal_stop_emission_by_name (wizard_dialog, "response");
1120 typedef struct IdleData {
1121 ModestEasysetupWizardDialog *dialog;
1122 ModestPresets *presets;
1126 presets_idle (gpointer userdata)
1128 IdleData *idle_data = (IdleData *) userdata;
1129 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1130 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1132 g_assert (idle_data->presets);
1134 gdk_threads_enter ();
1136 priv->presets = idle_data->presets;
1138 if (self->combo_account_country) {
1139 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
1140 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
1141 easysetup_provider_combo_box_fill (
1142 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider),
1143 priv->presets, mcc);
1146 priv->dirty = FALSE;
1148 g_object_unref (idle_data->dialog);
1151 gdk_threads_leave ();
1157 presets_loader (gpointer userdata)
1159 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1160 ModestPresets *presets = NULL;
1161 IdleData *idle_data;
1163 const gchar* path = NULL;
1164 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1165 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1167 if (access(path1, R_OK) == 0)
1169 else if (access(path2, R_OK) == 0)
1172 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1173 __FUNCTION__, path1, path2);
1177 presets = modest_presets_new (path);
1179 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1183 idle_data = g_new0 (IdleData, 1);
1184 idle_data->dialog = self;
1185 idle_data->presets = presets;
1187 g_idle_add (presets_idle, idle_data);
1193 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1195 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1197 /* Create the notebook to be used by the ModestWizardDialog base class:
1198 * Each page of the notebook will be a page of the wizard: */
1199 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1201 /* Set the notebook used by the ModestWizardDialog base class: */
1202 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1204 /* Set the wizard title:
1205 * The actual window title will be a combination of this and the page's tab label title. */
1206 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1208 /* Read in the information about known service providers: */
1209 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1211 /* The server fields did not have been manually changed yet */
1212 priv->server_changes = 0;
1214 /* Get the account manager object,
1215 * so we can check for existing accounts,
1216 * and create new accounts: */
1217 self->account_manager = modest_runtime_get_account_mgr ();
1218 g_assert (self->account_manager);
1219 g_object_ref (self->account_manager);
1221 /* Create the common pages,
1223 self->page_welcome = create_page_welcome (self);
1224 self->page_account_details = create_page_account_details (self);
1225 self->page_user_details = create_page_user_details (self);
1227 /* Add the common pages: */
1228 gtk_notebook_append_page (notebook, self->page_welcome,
1229 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1230 gtk_container_child_set (GTK_CONTAINER (notebook),
1236 gtk_notebook_append_page (notebook, self->page_account_details,
1237 gtk_label_new (_("mcen_ti_accountdetails")));
1238 gtk_container_child_set (GTK_CONTAINER (notebook),
1239 self->page_account_details,
1244 gtk_notebook_append_page (notebook, self->page_user_details,
1245 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1246 gtk_container_child_set (GTK_CONTAINER (notebook),
1247 self->page_user_details,
1252 /* Create and add the easysetup-specific pages,
1253 * because we need _some_ final page to enable the Next and Finish buttons: */
1254 create_subsequent_easysetup_pages (self);
1256 /* Connect to the dialog's response signal so we can enable/disable buttons
1257 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1258 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1259 * so that we can be enable/disable after ModestWizardDialog has done its own
1260 * enabling/disabling of buttons.
1262 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1263 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1265 * It's not enough to connect to the notebook's switch-page signal, because
1266 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1267 * _after_ switching the page (understandably).
1268 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1269 * then gtk_notebook_get_current_page() would return an incorrect value.)
1271 g_signal_connect_after (G_OBJECT (self), "response",
1272 G_CALLBACK (on_response), self);
1274 /* This is to show a confirmation dialog when the user hits cancel */
1275 g_signal_connect (G_OBJECT (self), "response",
1276 G_CALLBACK (on_response_before), self);
1278 g_signal_connect (G_OBJECT (self), "delete-event",
1279 G_CALLBACK (on_delete_event), self);
1281 /* Reset dirty, because there was no user input until now */
1282 priv->dirty = FALSE;
1284 /* When this window is shown, hibernation should not be possible,
1285 * because there is no sensible way to save the state: */
1286 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1287 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1289 /* Load provider presets */
1290 g_object_ref (self);
1291 g_thread_create (presets_loader, self, FALSE, NULL);
1293 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1294 modest_maemo_utils_get_osso_context());
1297 ModestEasysetupWizardDialog*
1298 modest_easysetup_wizard_dialog_new (void)
1301 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1304 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1306 GtkNotebook *notebook = NULL;
1307 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1310 /* Create the custom pages: */
1311 if(!(self->page_custom_incoming)) {
1312 self->page_custom_incoming = create_page_custom_incoming (self);
1315 if(!(self->page_custom_outgoing)) {
1316 self->page_custom_outgoing = create_page_custom_outgoing (self);
1319 if(!(self->page_complete_customsetup)) {
1320 self->page_complete_customsetup = create_page_complete_custom (self);
1323 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1324 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1325 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1327 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1328 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1329 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1331 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup))) {
1332 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1333 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1334 gtk_container_child_set (GTK_CONTAINER (notebook),
1335 self->page_complete_customsetup,
1341 /* This is unnecessary with GTK+ 2.10: */
1342 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1345 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1347 GtkNotebook *notebook = NULL;
1348 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1351 /* Create the easysetup-specific pages: */
1352 if(!self->page_complete_easysetup)
1353 self->page_complete_easysetup = create_page_complete_easysetup (self);
1355 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup))) {
1356 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1357 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1358 gtk_container_child_set (GTK_CONTAINER (notebook),
1359 self->page_complete_easysetup,
1365 /* This is unnecessary with GTK+ 2.10: */
1366 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1368 /* After the user details page,
1369 * the following pages depend on whether "Other" was chosen
1370 * in the provider combobox on the account page
1372 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1374 if (easysetup_provider_combo_box_get_active_provider_id (
1375 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1376 /* "Other..." was selected: */
1378 /* Make sure that the easysetup pages do not exist: */
1379 if(self->page_complete_easysetup) {
1380 gtk_widget_destroy (self->page_complete_easysetup);
1381 self->page_complete_easysetup = NULL;
1384 create_subsequent_customsetup_pages (self);
1387 /* A specific provider was selected: */
1389 /* Make sure that the custom pages do not exist:
1390 * Because they will be used if they exist, when creating the account. */
1391 if(self->page_custom_incoming) {
1392 gtk_widget_destroy (self->page_custom_incoming);
1393 self->page_custom_incoming = NULL;
1396 if(self->page_custom_outgoing) {
1397 gtk_widget_destroy (self->page_custom_outgoing);
1398 self->page_custom_outgoing = NULL;
1401 if(self->page_complete_customsetup) {
1402 gtk_widget_destroy (self->page_complete_customsetup);
1403 self->page_complete_customsetup = NULL;
1407 /* Create the easysetup pages: */
1408 create_subsequent_easysetup_pages (self);
1414 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1419 gchar* at = g_utf8_strchr (email_address, -1, '@');
1420 if (!at || (g_utf8_strlen (at, -1) < 2))
1423 gchar* domain = g_utf8_next_char (at);
1427 const gchar* hostname = NULL;
1428 if (servertype == MODEST_PROTOCOL_STORE_POP)
1430 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1432 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1438 return g_strdup_printf ("%s.%s", hostname, domain);
1441 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1443 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1445 if (!account_wizard->entry_incomingserver)
1448 /* Set a default domain for the server, based on the email address,
1449 * if no server name was already specified.
1451 if (account_wizard->entry_user_email
1452 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1453 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1454 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1455 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1457 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1459 /* Do not set the INCOMING_CHANGED flag because of this edit */
1460 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1461 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1462 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1464 g_free (servername);
1467 /* Set a default domain for the server, based on the email address,
1468 * if no server name was already specified.
1470 if (!account_wizard->entry_outgoingserver)
1473 if (account_wizard->entry_user_email
1474 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1475 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1477 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1479 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1480 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1481 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1482 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1484 g_free (servername);
1489 get_entered_account_title (ModestEasysetupWizardDialog *account_wizard)
1491 const gchar* account_title =
1492 gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1493 if (!account_title || (strlen (account_title) == 0))
1496 /* Strip it of whitespace at the start and end: */
1497 gchar *result = g_strdup (account_title);
1498 result = g_strstrip (result);
1503 if (strlen (result) == 0) {
1513 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1515 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1517 /* Do extra validation that couldn't be done for every key press,
1518 * either because it was too slow,
1519 * or because it requires interaction:
1521 if (current_page == account_wizard->page_account_details) {
1522 /* Check that the title is not already in use: */
1523 gchar* account_title = get_entered_account_title (account_wizard);
1527 /* Aavoid a clash with an existing display name: */
1528 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1529 account_wizard->account_manager, account_title);
1532 /* Warn the user via a dialog: */
1533 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1538 else if (current_page == account_wizard->page_user_details) {
1539 /* Check that the email address is valud: */
1540 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1541 if ((!email_address) || (strlen(email_address) == 0))
1544 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1545 /* Warn the user via a dialog: */
1546 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1548 /* Return focus to the email address entry: */
1549 gtk_widget_grab_focus (account_wizard->entry_user_email);
1550 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1555 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1556 create_subsequent_pages (account_wizard);
1559 /* TODO: The UI Spec wants us to check that the servernames are valid,
1560 * but does not specify how.
1563 if(next_page == account_wizard->page_custom_incoming) {
1564 set_default_custom_servernames (account_wizard);
1566 else if (next_page == account_wizard->page_custom_outgoing) {
1567 set_default_custom_servernames (account_wizard);
1569 /* Check if the server supports secure authentication */
1570 const ModestConnectionProtocol security_incoming =
1571 modest_serversecurity_combo_box_get_active_serversecurity (
1572 MODEST_SERVERSECURITY_COMBO_BOX (
1573 account_wizard->combo_incoming_security));
1574 if (gtk_toggle_button_get_active (
1575 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1576 && !modest_protocol_info_is_secure(security_incoming))
1578 if (!check_has_supported_auth_methods (account_wizard))
1583 /* If this is the last page, and this is a click on Finish,
1584 * then attempt to create the dialog.
1586 if(!next_page) /* This is NULL when this is a click on Finish. */
1588 if (account_wizard->saved_account_name) {
1589 /* Just enable the already-saved account (temporarily created when
1590 * editing advanced settings): */
1591 modest_account_mgr_set_enabled (account_wizard->account_manager,
1592 account_wizard->saved_account_name, TRUE);
1594 create_account (account_wizard, TRUE /* enabled */);
1602 static gboolean entry_is_empty (GtkWidget *entry)
1607 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1608 if ((!text) || (strlen(text) == 0))
1611 /* Strip it of whitespace at the start and end: */
1612 gchar *stripped = g_strdup (text);
1613 stripped = g_strstrip (stripped);
1618 const gboolean result = (strlen (stripped) == 0);
1626 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1628 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1630 gboolean enable_next = TRUE;
1631 if (current_page == account_wizard->page_welcome) {
1634 else if (current_page == account_wizard->page_account_details) {
1635 /* The account details title is mandatory: */
1636 if (entry_is_empty(account_wizard->entry_account_title))
1637 enable_next = FALSE;
1639 else if (current_page == account_wizard->page_user_details) {
1640 /* The user details username is mandatory: */
1641 if (entry_is_empty(account_wizard->entry_user_username))
1642 enable_next = FALSE;
1644 /* The user details email address is mandatory: */
1645 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1646 enable_next = FALSE;
1648 else if (current_page == account_wizard->page_custom_incoming) {
1649 /* The custom incoming server is mandatory: */
1650 if (entry_is_empty(account_wizard->entry_incomingserver))
1651 enable_next = FALSE;
1654 /* Enable the buttons,
1655 * identifying them via their associated response codes: */
1657 /* Disable the Finish button until we are on the last page,
1658 * because HildonWizardDialog enables this for all but the first page: */
1659 GtkNotebook *notebook = NULL;
1660 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1661 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1663 gint current = gtk_notebook_get_current_page (notebook);
1664 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1665 const gboolean is_last = (current == last);
1668 gtk_dialog_set_response_sensitive (dialog_base,
1669 MODEST_WIZARD_DIALOG_FINISH,
1673 /* Disable Next on the last page: */
1674 enable_next = FALSE;
1677 gtk_dialog_set_response_sensitive (dialog_base,
1678 MODEST_WIZARD_DIALOG_NEXT,
1683 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1685 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1686 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1689 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1690 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1691 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1692 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1694 /* Provide a vfunc implementation so we can decide
1695 * when to enable/disable the prev/next buttons.
1697 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1698 base_klass->before_next = on_before_next;
1699 base_klass->enable_buttons = on_enable_buttons;
1703 show_error (GtkWidget *parent_widget, const gchar* text)
1705 //TODO: Apparently this doesn't show anything in Maemo Bora:
1706 hildon_banner_show_information(parent_widget, NULL, text);
1709 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
1711 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1718 gtk_dialog_run (dialog);
1719 gtk_widget_destroy (GTK_WIDGET (dialog));
1723 /** Attempt to create the account from the information that the user has entered.
1724 * @result: TRUE if the account was successfully created.
1727 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1729 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1731 gchar* display_name = get_entered_account_title (self);
1737 /* We should have checked for this already,
1738 * and changed that name accordingly,
1739 * but let's check again just in case:
1741 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name)) {
1742 g_free (display_name);
1746 /* Increment the non-user visible name if necessary,
1747 * based on the display name: */
1748 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1749 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1750 account_name_start, FALSE /* not a server account */);
1751 g_free (account_name_start);
1753 /* username and password (for both incoming and outgoing): */
1754 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1755 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1756 /* Incoming server: */
1757 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1758 * or modest_account_mgr_add_server_account will fail. */
1759 gchar* servername_incoming = NULL;
1760 guint serverport_incoming = 0;
1761 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1762 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1763 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1765 /* Get details from the specified presets: */
1766 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1767 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1770 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1771 TRUE /* incoming */);
1773 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1775 TRUE /* incoming */);
1776 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1778 TRUE /* incoming */);
1781 /* We don't check for SMTP here as that is impossible for an incoming server. */
1782 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1783 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1784 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1785 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1787 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1789 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1790 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1792 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1793 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1796 /* Use custom pages because no preset was specified: */
1797 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1799 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1800 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1802 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1803 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1805 /* The UI spec says:
1806 * If secure authentication is unchecked, allow sending username and password also as plain text.
1807 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1810 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1811 !modest_protocol_info_is_secure(protocol_security_incoming)) {
1812 protocol_authentication_incoming = check_first_supported_auth_method (self);
1815 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1819 /* First we add the 2 server accounts, and then we add the account that uses them.
1820 * If we don't do it in this order then we will experience a crash. */
1822 /* Add a (incoming) server account, to be used by the account: */
1823 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1824 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1825 store_name_start, TRUE /* server account */);
1826 g_free (store_name_start);
1828 /* we check if there is a *special* port */
1829 special_port = modest_presets_get_port (priv->presets, provider_id,
1830 TRUE /* incoming */);
1831 if (special_port != 0)
1832 serverport_incoming = special_port;
1834 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1836 servername_incoming,
1837 serverport_incoming,
1840 protocol_security_incoming,
1841 protocol_authentication_incoming);
1843 g_free (servername_incoming);
1846 /* TODO: Provide a Logical ID for the text: */
1847 show_error (GTK_WIDGET (self), _("An error occurred while creating the incoming account."));
1848 g_free (display_name);
1852 /* Outgoing server: */
1853 gchar* servername_outgoing = NULL;
1854 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1855 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1856 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1857 guint serverport_outgoing = 0;
1861 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1862 FALSE /* incoming */);
1864 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1866 FALSE /* incoming */);
1868 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1869 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1870 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1871 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1873 ModestPresetsSecurity security_outgoing =
1874 modest_presets_get_info_server_security (priv->presets, provider_id,
1875 FALSE /* incoming */);
1877 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1878 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1879 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1880 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1881 serverport_outgoing = 465;
1882 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1884 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1885 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1888 /* Use custom pages because no preset was specified: */
1889 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1891 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1893 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1894 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1896 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1897 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1900 /* Add a (outgoing) server account to be used by the account: */
1901 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1902 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1903 transport_name_start, TRUE /* server account */);
1904 g_free (transport_name_start);
1906 /* we check if there is a *special* port */
1907 special_port = modest_presets_get_port (priv->presets, provider_id,
1908 FALSE /* incoming */);
1909 if (special_port != 0)
1910 serverport_outgoing = special_port;
1912 created = modest_account_mgr_add_server_account (self->account_manager,
1914 servername_outgoing,
1915 serverport_outgoing,
1918 protocol_security_outgoing,
1919 protocol_authentication_outgoing);
1921 g_free (servername_outgoing);
1924 /* TODO: Provide a Logical ID for the text: */
1925 show_error (GTK_WIDGET (self), _("An error occurred while creating the outgoing account."));
1926 g_free (display_name);
1930 const gchar* user_fullname = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1931 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1932 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1934 /* Create the account, which will contain the two "server accounts": */
1935 created = modest_account_mgr_add_account (self->account_manager,
1944 g_free (store_name);
1945 g_free (transport_name);
1948 /* TODO: Provide a Logical ID for the text: */
1949 show_error (GTK_WIDGET (self), _("An error occurred while creating the account."));
1950 g_free (display_name);
1955 /* There must be at least one account now: */
1956 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1957 * fixed in versions after 3.1. */
1958 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1959 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1961 /* Save the connection-specific SMTP server accounts. */
1962 modest_account_mgr_set_use_connection_specific_smtp(self->account_manager, account_name,
1963 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->checkbox_outgoing_smtp_specific)));
1964 gboolean result = TRUE;
1965 if (self->specific_window)
1966 result = modest_connection_specific_smtp_window_save_server_accounts (
1967 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window));
1970 g_free (self->saved_account_name);
1971 self->saved_account_name = g_strdup (account_name);
1973 g_free (account_name);
1974 g_free (display_name);