2 /* Copyright (c) 2006, Nokia Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * * Neither the name of the Nokia Corporation nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
19 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "modest-easysetup-wizard.h"
33 #include <glib/gi18n.h>
34 #include <gtk/gtknotebook.h>
35 #include <gtk/gtkvbox.h>
36 #include <gtk/gtklabel.h>
37 #include <gtk/gtkcombobox.h>
38 #include <gtk/gtkentry.h>
39 #include <gtk/gtkbutton.h>
40 #include <gtk/gtkcheckbutton.h>
41 #include <gtk/gtkmessagedialog.h>
42 #include <gtk/gtkseparator.h>
43 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
44 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
45 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
46 #include "widgets/modest-serversecurity-combo-box.h"
47 #include "widgets/modest-secureauth-combo-box.h"
48 #include "widgets/modest-validating-entry.h"
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-account-mgr-helpers.h"
52 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "maemo/modest-connection-specific-smtp-window.h"
54 #include "widgets/modest-ui-constants.h"
55 #include "maemo/modest-account-settings-dialog.h"
56 #include "maemo/modest-maemo-utils.h"
57 #include <gconf/gconf-client.h>
58 #include <string.h> /* For strlen(). */
59 #include "maemo/modest-hildon-includes.h"
61 /* Include config.h so that _() works: */
66 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
68 #define WIZARD_DIALOG_GET_PRIVATE(o) \
69 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
71 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
75 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
76 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
77 } ModestEasysetupWizardDialogServerChanges;
79 struct _ModestEasysetupWizardDialogPrivate
81 ModestPresets *presets;
83 /* Remember what fields the user edited manually to not prefill them
85 ModestEasysetupWizardDialogServerChanges server_changes;
87 /* Check if the user changes a field to show a confirmation dialog */
92 on_delete_event (GtkWidget *widget,
94 ModestEasysetupWizardDialog *wizard)
96 gtk_dialog_response (GTK_DIALOG (wizard), GTK_RESPONSE_CANCEL);
101 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
103 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(wizard);
104 g_return_if_fail (priv != NULL);
109 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
110 GValue *value, GParamSpec *pspec)
112 switch (property_id) {
114 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
119 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
120 const GValue *value, GParamSpec *pspec)
122 switch (property_id) {
124 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
129 modest_easysetup_wizard_dialog_dispose (GObject *object)
131 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
132 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
136 modest_easysetup_wizard_dialog_finalize (GObject *object)
138 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
139 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
141 if (self->account_manager)
142 g_object_unref (G_OBJECT (self->account_manager));
145 modest_presets_destroy (priv->presets);
147 if (self->specific_window)
148 gtk_widget_destroy (self->specific_window);
150 g_free (self->saved_account_name);
152 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
156 show_error (GtkWidget *parent_widget, const gchar* text);
159 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
162 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
165 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
167 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
169 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
170 ModestPresetsSecurity security_incoming)
172 int serverport_incoming = 0;
173 /* We don't check for SMTP here as that is impossible for an incoming server. */
174 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
175 serverport_incoming =
176 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
177 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
178 serverport_incoming =
179 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
181 return serverport_incoming;
184 static GList* check_for_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
186 GError *error = NULL;
187 const ModestTransportStoreProtocol protocol =
188 easysetup_servertype_combo_box_get_active_servertype (
189 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
190 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
191 const gchar* username = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_user_username));
192 const ModestConnectionProtocol protocol_security_incoming =
193 modest_serversecurity_combo_box_get_active_serversecurity (
194 MODEST_SERVERSECURITY_COMBO_BOX (
195 account_wizard->combo_incoming_security));
196 const int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
197 GList *list_auth_methods =
198 modest_maemo_utils_get_supported_secure_authentication_methods (
200 hostname, port_num, username, GTK_WINDOW (account_wizard), &error);
201 if (list_auth_methods) {
202 /* TODO: Select the correct method */
205 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
206 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
207 if (modest_protocol_info_auth_is_secure(auth)) {
208 list = g_list_append(list, GINT_TO_POINTER(auth));
212 g_list_free(list_auth_methods);
218 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
219 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
221 show_error (GTK_WIDGET(account_wizard), _("Could not discover supported secure authentication methods."));
230 static gboolean check_has_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
232 GList* methods = check_for_supported_auth_methods(account_wizard);
238 g_list_free(methods);
242 static ModestAuthProtocol check_first_supported_auth_method(ModestEasysetupWizardDialog* account_wizard)
244 ModestAuthProtocol result = MODEST_PROTOCOL_AUTH_PASSWORD;
246 GList* methods = check_for_supported_auth_methods(account_wizard);
249 /* Use the first one: */
250 result = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
251 g_list_free(methods);
258 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
260 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
262 /* Call the vfunc, which may be overridden by derived classes: */
263 if (klass->enable_buttons) {
264 GtkNotebook *notebook = NULL;
265 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
267 const gint current_page_num = gtk_notebook_get_current_page (notebook);
268 if (current_page_num == -1)
271 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
272 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
277 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
279 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
281 invoke_enable_buttons_vfunc(self);
285 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
287 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
289 invoke_enable_buttons_vfunc(self);
292 /** This is a convenience function to create a caption containing a mandatory widget.
293 * When the widget is edited, the enable_buttons() vfunc will be called.
295 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
300 HildonCaptionStatus flag)
302 GtkWidget *caption = NULL;
304 /* Note: Previously, the translated strings already contained the "*",
305 * Comment out this code if they do again.
307 /* Add a * character to indicate mandatory fields,
308 * as specified in our "Email UI Specification": */
309 if (flag == HILDON_CAPTION_MANDATORY) {
310 gchar* title = g_strdup_printf("%s*", value);
311 caption = hildon_caption_new (group, title, control, icon, flag);
315 caption = hildon_caption_new (group, value, control, icon, flag);
317 /* Connect to the appropriate changed signal for the widget,
318 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
320 if (GTK_IS_ENTRY (control)) {
321 g_signal_connect (G_OBJECT (control), "changed",
322 G_CALLBACK (on_caption_entry_changed), self);
325 else if (GTK_IS_COMBO_BOX (control)) {
326 g_signal_connect (G_OBJECT (control), "changed",
327 G_CALLBACK (on_caption_combobox_changed), self);
334 create_page_welcome (ModestEasysetupWizardDialog *self)
336 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
337 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
338 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
339 /* So that it is not truncated: */
340 gtk_widget_set_size_request (label, 600, -1);
341 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
342 gtk_widget_show (label);
343 gtk_widget_show (GTK_WIDGET (box));
344 return GTK_WIDGET (box);
348 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
350 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
352 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
356 /* Fill the providers combo, based on the selected country: */
357 if (priv->presets != NULL) {
358 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
359 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
360 easysetup_provider_combo_box_fill (
361 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc);
366 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
368 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
370 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
374 /* Fill the providers combo, based on the selected country: */
375 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
376 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
378 gchar* domain_name = NULL;
380 domain_name = modest_presets_get_domain (priv->presets, provider_id);
383 domain_name = g_strdup (MODEST_EXAMPLE_EMAIL_ADDRESS);
385 if (self->entry_user_email)
386 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
388 g_free (domain_name);
390 g_free (provider_id);
394 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
396 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
397 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
401 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
403 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
405 const gchar *show_char = NULL;
407 show_char = character;
409 /* TODO: We need a logical ID for this: */
410 show_char = _("whitespace");
413 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
414 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
415 show_error (GTK_WIDGET (self), message);
419 create_page_account_details (ModestEasysetupWizardDialog *self)
421 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
422 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
423 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
424 gtk_widget_set_size_request (label, 600, -1);
425 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
426 gtk_widget_show (label);
428 /* Create a size group to be used by all captions.
429 * Note that HildonCaption does not create a default size group if we do not specify one.
430 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
431 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
433 /* The country widgets: */
434 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
435 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
436 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
437 gtk_widget_show (self->combo_account_country);
438 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
439 gtk_widget_show (caption);
441 /* connect to country combo's changed signal, so we can fill the provider combo: */
442 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
443 G_CALLBACK (on_combo_account_country), self);
445 GtkWidget *separator = gtk_hseparator_new ();
446 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
447 gtk_widget_show (separator);
449 /* The service provider widgets: */
450 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
451 gtk_widget_set_size_request (self->combo_account_serviceprovider, 320, -1);
453 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
454 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
455 gtk_widget_show (self->combo_account_serviceprovider);
456 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
457 gtk_widget_show (caption);
459 /* connect to providers combo's changed signal, so we can fill the email address: */
460 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
461 G_CALLBACK (on_combo_account_serviceprovider), self);
463 /* TODO: Default to the current country somehow.
464 * But I don't know how to get the information that is specified in the
465 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
467 * This is probably not the best choice of gconf key:
468 * This is the "mcc used in the last pairing", ie. the last connection you made.
469 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
472 GError *error = NULL;
473 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
474 gint mcc_id = modest_conf_get_int(modest_runtime_get_conf (), key, &error);
480 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
481 g_error_free (error);
487 /* Note that modest_conf_get_int() seems to return 0 without an error if the key is not there
488 * This might just be a Maemo bug.
492 /* For now, we default to Finland when there is nothing better: */
496 easysetup_country_combo_box_set_active_country_mcc (
497 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
500 /* The description widgets: */
501 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
502 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
503 G_CALLBACK(on_easysetup_changed), self);
504 /* Do use auto-capitalization: */
505 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
506 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
508 /* Set a default account title, choosing one that does not already exist: */
509 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
510 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
511 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
512 self->account_manager, default_account_name_start);
513 g_free (default_account_name_start);
514 default_account_name_start = NULL;
516 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
517 g_free (default_account_name);
518 default_account_name = NULL;
520 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
521 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
522 gtk_widget_show (self->entry_account_title);
523 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
524 gtk_widget_show (caption);
526 /* Prevent the use of some characters in the account title,
527 * as required by our UI specification: */
528 GList *list_prevent = NULL;
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, "*");
533 list_prevent = g_list_append (list_prevent, "?");
534 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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 list_prevent = g_list_append (list_prevent, "|");
539 list_prevent = g_list_append (list_prevent, "^");
540 modest_validating_entry_set_unallowed_characters (
541 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
542 g_list_free (list_prevent);
544 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
545 on_entry_invalid_character, self);
547 /* Set max length as in the UI spec:
548 * The UI spec seems to want us to show a dialog if we hit the maximum. */
549 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
550 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
553 gtk_widget_show (GTK_WIDGET (box));
555 return GTK_WIDGET (box);
559 create_page_user_details (ModestEasysetupWizardDialog *self)
561 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
563 /* Create a size group to be used by all captions.
564 * Note that HildonCaption does not create a default size group if we do not specify one.
565 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
566 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
568 /* The name widgets: (use auto cap) */
569 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
570 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name),
571 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
573 /* Set max length as in the UI spec:
574 * The UI spec seems to want us to show a dialog if we hit the maximum. */
575 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
576 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
578 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
579 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
580 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
581 G_CALLBACK(on_easysetup_changed), self);
582 gtk_widget_show (self->entry_user_name);
583 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
584 gtk_widget_show (caption);
586 /* Prevent the use of some characters in the name,
587 * as required by our UI specification: */
588 GList *list_prevent = NULL;
589 list_prevent = g_list_append (list_prevent, "<");
590 list_prevent = g_list_append (list_prevent, ">");
591 modest_validating_entry_set_unallowed_characters (
592 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
593 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
594 on_entry_invalid_character, self);
595 g_list_free (list_prevent);
597 /* The username widgets: */
598 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
599 /* Auto-capitalization is the default, so let's turn it off: */
600 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
601 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
602 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
603 gtk_widget_show (self->entry_user_username);
604 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
605 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
606 G_CALLBACK(on_easysetup_changed), self);
607 gtk_widget_show (caption);
609 /* Prevent the use of some characters in the username,
610 * as required by our UI specification: */
611 modest_validating_entry_set_unallowed_characters_whitespace (
612 MODEST_VALIDATING_ENTRY (self->entry_user_username));
613 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_username),
614 on_entry_invalid_character, self);
616 /* Set max length as in the UI spec:
617 * The UI spec seems to want us to show a dialog if we hit the maximum. */
618 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
619 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
622 /* The password widgets: */
623 self->entry_user_password = gtk_entry_new ();
624 /* Auto-capitalization is the default, so let's turn it off: */
625 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
626 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
627 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
628 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
629 caption = create_caption_new_with_asterisk (self, sizegroup,
630 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
631 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
632 G_CALLBACK(on_easysetup_changed), self);
633 gtk_widget_show (self->entry_user_password);
634 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
635 gtk_widget_show (caption);
637 /* The email address widgets: */
638 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
639 /* Auto-capitalization is the default, so let's turn it off: */
640 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
641 caption = create_caption_new_with_asterisk (self, sizegroup,
642 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
643 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
644 gtk_widget_show (self->entry_user_email);
645 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
646 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
647 G_CALLBACK(on_easysetup_changed), self);
648 gtk_widget_show (caption);
650 /* Set max length as in the UI spec:
651 * The UI spec seems to want us to show a dialog if we hit the maximum. */
652 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
653 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
657 gtk_widget_show (GTK_WIDGET (box));
659 return GTK_WIDGET (box);
662 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
664 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
666 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
667 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
668 gtk_widget_set_size_request (label, 600, -1);
669 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
670 /* The documentation for gtk_label_set_line_wrap() says that we must
671 * call gtk_widget_set_size_request() with a hard-coded width,
672 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
673 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
674 gtk_widget_show (label);
676 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
677 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
678 gtk_widget_set_size_request (label, 600, -1);
680 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
681 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
682 gtk_widget_show (label);
684 gtk_widget_show (GTK_WIDGET (box));
685 return GTK_WIDGET (box);
688 /** Change the caption title for the incoming server,
689 * as specified in the UI spec:
691 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
693 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
694 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
696 (protocol == MODEST_PROTOCOL_STORE_POP ?
697 _("mail_fi_emailtype_pop3") :
698 _("mail_fi_emailtype_imap") );
701 /* Note that this produces a compiler warning,
702 * because the compiler does not know that the translated string will have a %s in it.
703 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
704 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
705 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
706 g_free(incomingserver_title);
709 /** Change the caption title for the incoming server,
710 * as specified in the UI spec:
712 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
714 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
715 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
717 /* Fill the combo with appropriately titled choices for POP or IMAP. */
718 /* The choices are the same, but the titles are different, as in the UI spec. */
719 modest_serversecurity_combo_box_fill (
720 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
723 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
725 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
726 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
730 update_incoming_server_title (self);
731 update_incoming_server_security_choices (self);
733 set_default_custom_servernames (self);
736 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
738 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
739 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
741 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
744 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
746 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
747 GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
749 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
751 GTK_POLICY_AUTOMATIC);
753 /* Show note that account type cannot be changed in future: */
754 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
755 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
756 gtk_widget_set_size_request (label, 600, -1);
757 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
758 gtk_widget_show (label);
760 /* Create a size group to be used by all captions.
761 * Note that HildonCaption does not create a default size group if we do not specify one.
762 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
763 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
765 /* The incoming server widgets: */
766 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
767 easysetup_servertype_combo_box_set_active_servertype (
768 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
769 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
770 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
771 gtk_widget_show (self->combo_incoming_servertype);
772 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
773 gtk_widget_show (caption);
775 self->entry_incomingserver = gtk_entry_new ();
776 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed", G_CALLBACK(on_easysetup_changed), self);
777 /* Auto-capitalization is the default, so let's turn it off: */
778 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
779 set_default_custom_servernames (self);
781 /* The caption title will be updated in update_incoming_server_title().
782 * so this default text will never be seen: */
783 /* (Note: Changing the title seems pointless. murrayc) */
784 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
785 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
786 update_incoming_server_title (self);
787 gtk_widget_show (self->entry_incomingserver);
788 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
789 gtk_widget_show (self->caption_incoming);
791 /* Change the caption title when the servertype changes,
792 * as in the UI spec: */
793 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
794 G_CALLBACK (on_combo_servertype_changed), self);
796 /* Remember when the servername was changed manually: */
797 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
798 G_CALLBACK (on_entry_incoming_servername_changed), self);
800 /* The secure connection widgets: */
801 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
802 update_incoming_server_security_choices (self);
803 modest_serversecurity_combo_box_set_active_serversecurity (
804 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
805 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
806 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
807 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
808 G_CALLBACK (on_easysetup_changed), self);
809 gtk_widget_show (self->combo_incoming_security);
810 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
811 gtk_widget_show (caption);
813 self->checkbox_incoming_auth = gtk_check_button_new ();
814 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
815 G_CALLBACK (on_easysetup_changed), self);
816 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
817 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
819 gtk_widget_show (self->checkbox_incoming_auth);
820 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
821 gtk_widget_show (caption);
823 gtk_widget_show (GTK_WIDGET (box));
825 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
826 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
827 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window)));
828 gtk_widget_show (scrolled_window);
830 return GTK_WIDGET (scrolled_window);
834 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
836 GtkWidget *widget = GTK_WIDGET (user_data);
838 /* Enable the widget only if the toggle button is active: */
839 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
840 gtk_widget_set_sensitive (widget, enable);
843 /* Make the sensitivity of a widget depend on a toggle button.
846 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
848 g_signal_connect (G_OBJECT (button), "toggled",
849 G_CALLBACK (on_toggle_button_changed), widget);
851 /* Set the starting sensitivity: */
852 on_toggle_button_changed (button, widget);
856 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
858 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
859 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
861 /* We set dirty here because setting it depending on the connection specific dialog
865 /* Create the window, if necessary: */
866 if (!(self->specific_window)) {
867 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
868 modest_connection_specific_smtp_window_fill_with_connections (
869 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager);
872 /* Show the window: */
873 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
874 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
875 gtk_widget_show (self->specific_window);
878 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
880 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
881 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
882 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
885 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
887 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
889 /* Create a size group to be used by all captions.
890 * Note that HildonCaption does not create a default size group if we do not specify one.
891 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
892 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
894 /* The outgoing server widgets: */
895 self->entry_outgoingserver = gtk_entry_new ();
896 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
897 G_CALLBACK (on_easysetup_changed), self);
898 /* Auto-capitalization is the default, so let's turn it off: */
899 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
900 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
901 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
902 gtk_widget_show (self->entry_outgoingserver);
903 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
904 gtk_widget_show (caption);
905 set_default_custom_servernames (self);
907 /* The secure connection widgets: */
908 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
909 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
910 G_CALLBACK (on_easysetup_changed), self);
911 modest_serversecurity_combo_box_fill (
912 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
913 modest_serversecurity_combo_box_set_active_serversecurity (
914 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
915 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
916 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
917 gtk_widget_show (self->combo_outgoing_security);
918 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
919 gtk_widget_show (caption);
921 /* The secure authentication widgets: */
922 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
923 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
924 G_CALLBACK (on_easysetup_changed), self);
925 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
926 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
927 gtk_widget_show (self->combo_outgoing_auth);
928 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
929 gtk_widget_show (caption);
931 GtkWidget *separator = gtk_hseparator_new ();
932 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
933 gtk_widget_show (separator);
935 /* connection-specific checkbox: */
936 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
937 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
939 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
940 G_CALLBACK (on_easysetup_changed), self);
942 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
943 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
944 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
945 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
946 gtk_widget_show (caption);
948 /* Connection-specific SMTP-Severs Edit button: */
949 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
950 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
951 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
952 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
953 gtk_widget_show (self->button_outgoing_smtp_servers);
954 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
955 gtk_widget_show (caption);
957 /* Only enable the button when the checkbox is checked: */
958 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
959 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
961 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
962 G_CALLBACK (on_button_outgoing_smtp_servers), self);
964 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
965 G_CALLBACK (on_entry_outgoing_servername_changed), self);
968 gtk_widget_show (GTK_WIDGET (box));
970 return GTK_WIDGET (box);
974 show_advanced_edit(gpointer user_data)
976 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
978 if (!(self->saved_account_name))
981 /* Show the Account Settings window: */
982 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
983 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
985 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog));
987 gtk_dialog_run (GTK_DIALOG (dialog));
989 gtk_widget_destroy (GTK_WIDGET (dialog));
991 return FALSE; /* Do not call this timeout callback again. */
995 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
997 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
999 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
1000 * without recoding it to use non-gconf information.
1001 * This account will be deleted if Finish is never actually clicked. */
1003 gboolean saved = TRUE;
1004 if (!(self->saved_account_name)) {
1005 saved = create_account (self, FALSE);
1011 if (!(self->saved_account_name))
1014 /* Show the Account Settings window: */
1015 show_advanced_edit(self);
1017 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
1019 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1020 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1021 GtkWidget *button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1022 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1023 gtk_widget_set_size_request (label, 600, -1);
1024 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1025 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1026 gtk_widget_show (label);
1028 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1029 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1030 gtk_widget_set_size_request (label, 600, -1);
1031 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1032 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1033 gtk_widget_show (label);
1035 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1036 button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1037 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1038 gtk_widget_show (button_edit);
1039 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1040 gtk_widget_show (caption);
1042 g_signal_connect (G_OBJECT (button_edit), "clicked",
1043 G_CALLBACK (on_button_edit_advanced_settings), self);
1045 gtk_widget_show (GTK_WIDGET (box));
1046 return GTK_WIDGET (box);
1053 on_response (ModestWizardDialog *wizard_dialog,
1057 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1058 if (response_id == GTK_RESPONSE_CANCEL) {
1059 /* Remove any temporarily-saved account that will not actually be needed: */
1060 if (self->saved_account_name) {
1061 modest_account_mgr_remove_account (self->account_manager,
1062 self->saved_account_name);
1066 invoke_enable_buttons_vfunc (self);
1070 on_response_before (ModestWizardDialog *wizard_dialog,
1074 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1075 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1076 if (response_id == GTK_RESPONSE_CANCEL) {
1077 /* This is mostly copied from
1078 * src/maemo/modest-account-settings-dialog.c */
1080 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1081 _("imum_nc_wizard_confirm_lose_changes")));
1082 /* TODO: These button names will be ambiguous, and not
1083 * specified in the UI specification. */
1085 const gint dialog_response = gtk_dialog_run (dialog);
1086 self->combo_account_country = NULL;
1087 gtk_widget_destroy (GTK_WIDGET (dialog));
1089 if (dialog_response != GTK_RESPONSE_OK) {
1090 /* Don't let the dialog close */
1091 g_signal_stop_emission_by_name (wizard_dialog, "response");
1097 typedef struct IdleData {
1098 ModestEasysetupWizardDialog *dialog;
1099 ModestPresets *presets;
1103 presets_idle (gpointer userdata)
1105 IdleData *idle_data = (IdleData *) userdata;
1106 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (idle_data->dialog);
1107 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1109 g_assert (idle_data->presets);
1111 gdk_threads_enter ();
1113 priv->presets = idle_data->presets;
1115 if (self->combo_account_country) {
1116 gint mcc = easysetup_country_combo_box_get_active_country_mcc (
1117 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
1118 easysetup_provider_combo_box_fill (
1119 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider),
1120 priv->presets, mcc);
1123 priv->dirty = FALSE;
1125 g_object_unref (idle_data->dialog);
1128 gdk_threads_leave ();
1134 presets_loader (gpointer userdata)
1136 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (userdata);
1137 ModestPresets *presets = NULL;
1138 IdleData *idle_data;
1140 const gchar* path = NULL;
1141 const gchar* path1 = MODEST_PROVIDER_DATA_FILE;
1142 const gchar* path2 = MODEST_MAEMO_PROVIDER_DATA_FILE;
1144 if (access(path1, R_OK) == 0)
1146 else if (access(path2, R_OK) == 0)
1149 g_warning ("%s: neither '%s' nor '%s' is a readable provider data file",
1150 __FUNCTION__, path1, path2);
1154 presets = modest_presets_new (path);
1156 g_warning ("%s: failed to parse '%s'", __FUNCTION__, path);
1160 idle_data = g_new0 (IdleData, 1);
1161 idle_data->dialog = self;
1162 idle_data->presets = presets;
1164 g_idle_add (presets_idle, idle_data);
1170 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1172 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1174 /* Create the notebook to be used by the ModestWizardDialog base class:
1175 * Each page of the notebook will be a page of the wizard: */
1176 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1178 /* Set the notebook used by the ModestWizardDialog base class: */
1179 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1181 /* Set the wizard title:
1182 * The actual window title will be a combination of this and the page's tab label title. */
1183 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1185 /* Read in the information about known service providers: */
1186 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1188 /* The server fields did not have been manually changed yet */
1189 priv->server_changes = 0;
1191 /* Get the account manager object,
1192 * so we can check for existing accounts,
1193 * and create new accounts: */
1194 self->account_manager = modest_runtime_get_account_mgr ();
1195 g_assert (self->account_manager);
1196 g_object_ref (self->account_manager);
1198 /* Create the common pages,
1200 self->page_welcome = create_page_welcome (self);
1201 self->page_account_details = create_page_account_details (self);
1202 self->page_user_details = create_page_user_details (self);
1204 /* Add the common pages: */
1205 gtk_notebook_append_page (notebook, self->page_welcome,
1206 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1207 gtk_container_child_set (GTK_CONTAINER (notebook),
1213 gtk_notebook_append_page (notebook, self->page_account_details,
1214 gtk_label_new (_("mcen_ti_accountdetails")));
1215 gtk_container_child_set (GTK_CONTAINER (notebook),
1216 self->page_account_details,
1221 gtk_notebook_append_page (notebook, self->page_user_details,
1222 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1223 gtk_container_child_set (GTK_CONTAINER (notebook),
1224 self->page_user_details,
1229 /* Create and add the easysetup-specific pages,
1230 * because we need _some_ final page to enable the Next and Finish buttons: */
1231 create_subsequent_easysetup_pages (self);
1233 /* Connect to the dialog's response signal so we can enable/disable buttons
1234 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1235 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1236 * so that we can be enable/disable after ModestWizardDialog has done its own
1237 * enabling/disabling of buttons.
1239 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1240 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1242 * It's not enough to connect to the notebook's switch-page signal, because
1243 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1244 * _after_ switching the page (understandably).
1245 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1246 * then gtk_notebook_get_current_page() would return an incorrect value.)
1248 g_signal_connect_after (G_OBJECT (self), "response",
1249 G_CALLBACK (on_response), self);
1251 /* This is to show a confirmation dialog when the user hits cancel */
1252 g_signal_connect (G_OBJECT (self), "response",
1253 G_CALLBACK (on_response_before), self);
1255 g_signal_connect (G_OBJECT (self), "delete-event",
1256 G_CALLBACK (on_delete_event), self);
1258 /* Reset dirty, because there was no user input until now */
1259 priv->dirty = FALSE;
1261 /* When this window is shown, hibernation should not be possible,
1262 * because there is no sensible way to save the state: */
1263 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1264 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1266 /* Load provider presets */
1267 g_object_ref (self);
1268 g_thread_create (presets_loader, self, FALSE, NULL);
1270 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_wizardwelcome",
1271 modest_maemo_utils_get_osso_context());
1274 ModestEasysetupWizardDialog*
1275 modest_easysetup_wizard_dialog_new (void)
1278 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1281 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1283 GtkNotebook *notebook = NULL;
1284 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1287 /* Create the custom pages: */
1288 if(!(self->page_custom_incoming)) {
1289 self->page_custom_incoming = create_page_custom_incoming (self);
1292 if(!(self->page_custom_outgoing)) {
1293 self->page_custom_outgoing = create_page_custom_outgoing (self);
1296 if(!(self->page_complete_customsetup)) {
1297 self->page_complete_customsetup = create_page_complete_custom (self);
1300 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1301 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1302 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1304 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1305 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1306 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1308 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup))) {
1309 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1310 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1311 gtk_container_child_set (GTK_CONTAINER (notebook),
1312 self->page_complete_customsetup,
1318 /* This is unnecessary with GTK+ 2.10: */
1319 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1322 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1324 GtkNotebook *notebook = NULL;
1325 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1328 /* Create the easysetup-specific pages: */
1329 if(!self->page_complete_easysetup)
1330 self->page_complete_easysetup = create_page_complete_easysetup (self);
1332 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup))) {
1333 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1334 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1335 gtk_container_child_set (GTK_CONTAINER (notebook),
1336 self->page_complete_easysetup,
1342 /* This is unnecessary with GTK+ 2.10: */
1343 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1345 /* After the user details page,
1346 * the following pages depend on whether "Other" was chosen
1347 * in the provider combobox on the account page
1349 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1351 if (easysetup_provider_combo_box_get_active_provider_id (
1352 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1353 /* "Other..." was selected: */
1355 /* Make sure that the easysetup pages do not exist: */
1356 if(self->page_complete_easysetup) {
1357 gtk_widget_destroy (self->page_complete_easysetup);
1358 self->page_complete_easysetup = NULL;
1361 create_subsequent_customsetup_pages (self);
1364 /* A specific provider was selected: */
1366 /* Make sure that the custom pages do not exist:
1367 * Because they will be used if they exist, when creating the account. */
1368 if(self->page_custom_incoming) {
1369 gtk_widget_destroy (self->page_custom_incoming);
1370 self->page_custom_incoming = NULL;
1371 self->combo_incoming_servertype = NULL;
1372 self->caption_incoming = NULL;
1373 self->entry_incomingserver = NULL;
1374 self->combo_incoming_security = NULL;
1375 self->checkbox_incoming_auth = NULL;
1378 if(self->page_custom_outgoing) {
1379 gtk_widget_destroy (self->page_custom_outgoing);
1380 self->page_custom_outgoing = NULL;
1381 self->entry_outgoingserver = NULL;
1382 self->combo_outgoing_security = NULL;
1383 self->combo_outgoing_auth = NULL;
1384 self->checkbox_outgoing_smtp_specific = NULL;
1385 self->button_outgoing_smtp_servers = NULL;
1388 if(self->page_complete_customsetup) {
1389 gtk_widget_destroy (self->page_complete_customsetup);
1390 self->page_complete_customsetup = NULL;
1394 /* Create the easysetup pages: */
1395 create_subsequent_easysetup_pages (self);
1401 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1406 gchar* at = g_utf8_strchr (email_address, -1, '@');
1407 if (!at || (g_utf8_strlen (at, -1) < 2))
1410 gchar* domain = g_utf8_next_char (at);
1414 const gchar* hostname = NULL;
1415 if (servertype == MODEST_PROTOCOL_STORE_POP)
1417 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1419 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1425 return g_strdup_printf ("%s.%s", hostname, domain);
1428 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1430 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1432 if (!account_wizard->entry_incomingserver)
1435 /* Set a default domain for the server, based on the email address,
1436 * if no server name was already specified.
1438 if (account_wizard->entry_user_email
1439 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1440 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1441 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1442 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1444 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1446 /* Do not set the INCOMING_CHANGED flag because of this edit */
1447 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1448 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1449 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1451 g_free (servername);
1454 /* Set a default domain for the server, based on the email address,
1455 * if no server name was already specified.
1457 if (!account_wizard->entry_outgoingserver)
1460 if (account_wizard->entry_user_email
1461 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1462 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1464 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1466 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1467 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1468 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1469 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1471 g_free (servername);
1476 get_entered_account_title (ModestEasysetupWizardDialog *account_wizard)
1478 const gchar* account_title =
1479 gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1480 if (!account_title || (strlen (account_title) == 0))
1483 /* Strip it of whitespace at the start and end: */
1484 gchar *result = g_strdup (account_title);
1485 result = g_strstrip (result);
1490 if (strlen (result) == 0) {
1500 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1502 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1504 /* Do extra validation that couldn't be done for every key press,
1505 * either because it was too slow,
1506 * or because it requires interaction:
1508 if (current_page == account_wizard->page_account_details) {
1509 /* Check that the title is not already in use: */
1510 gchar* account_title = get_entered_account_title (account_wizard);
1514 /* Aavoid a clash with an existing display name: */
1515 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1516 account_wizard->account_manager, account_title);
1519 /* Warn the user via a dialog: */
1520 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1525 else if (current_page == account_wizard->page_user_details) {
1526 /* Check that the email address is valud: */
1527 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1528 if ((!email_address) || (strlen(email_address) == 0))
1531 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1532 /* Warn the user via a dialog: */
1533 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1535 /* Return focus to the email address entry: */
1536 gtk_widget_grab_focus (account_wizard->entry_user_email);
1537 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1542 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1543 create_subsequent_pages (account_wizard);
1546 /* TODO: The UI Spec wants us to check that the servernames are valid,
1547 * but does not specify how.
1550 if(next_page == account_wizard->page_custom_incoming) {
1551 set_default_custom_servernames (account_wizard);
1553 else if (next_page == account_wizard->page_custom_outgoing) {
1554 set_default_custom_servernames (account_wizard);
1556 /* Check if the server supports secure authentication */
1557 const ModestConnectionProtocol security_incoming =
1558 modest_serversecurity_combo_box_get_active_serversecurity (
1559 MODEST_SERVERSECURITY_COMBO_BOX (
1560 account_wizard->combo_incoming_security));
1561 if (gtk_toggle_button_get_active (
1562 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1563 && !modest_protocol_info_is_secure(security_incoming))
1565 if (!check_has_supported_auth_methods (account_wizard))
1570 /* If this is the last page, and this is a click on Finish,
1571 * then attempt to create the dialog.
1573 if(!next_page) /* This is NULL when this is a click on Finish. */
1575 if (account_wizard->saved_account_name) {
1576 /* Just enable the already-saved account (temporarily created when
1577 * editing advanced settings): */
1578 modest_account_mgr_set_enabled (account_wizard->account_manager,
1579 account_wizard->saved_account_name, TRUE);
1581 create_account (account_wizard, TRUE /* enabled */);
1589 static gboolean entry_is_empty (GtkWidget *entry)
1594 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1595 if ((!text) || (strlen(text) == 0))
1598 /* Strip it of whitespace at the start and end: */
1599 gchar *stripped = g_strdup (text);
1600 stripped = g_strstrip (stripped);
1605 const gboolean result = (strlen (stripped) == 0);
1613 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1615 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1617 gboolean enable_next = TRUE;
1618 if (current_page == account_wizard->page_welcome) {
1621 else if (current_page == account_wizard->page_account_details) {
1622 /* The account details title is mandatory: */
1623 if (entry_is_empty(account_wizard->entry_account_title))
1624 enable_next = FALSE;
1626 else if (current_page == account_wizard->page_user_details) {
1627 /* The user details username is mandatory: */
1628 if (entry_is_empty(account_wizard->entry_user_username))
1629 enable_next = FALSE;
1631 /* The user details email address is mandatory: */
1632 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1633 enable_next = FALSE;
1635 else if (current_page == account_wizard->page_custom_incoming) {
1636 /* The custom incoming server is mandatory: */
1637 if (entry_is_empty(account_wizard->entry_incomingserver))
1638 enable_next = FALSE;
1641 /* Enable the buttons,
1642 * identifying them via their associated response codes: */
1644 /* Disable the Finish button until we are on the last page,
1645 * because HildonWizardDialog enables this for all but the first page: */
1646 GtkNotebook *notebook = NULL;
1647 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1648 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1650 gint current = gtk_notebook_get_current_page (notebook);
1651 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1652 const gboolean is_last = (current == last);
1655 gtk_dialog_set_response_sensitive (dialog_base,
1656 MODEST_WIZARD_DIALOG_FINISH,
1660 /* Disable Next on the last page: */
1661 enable_next = FALSE;
1664 gtk_dialog_set_response_sensitive (dialog_base,
1665 MODEST_WIZARD_DIALOG_NEXT,
1670 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1672 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1673 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1676 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1677 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1678 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1679 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1681 /* Provide a vfunc implementation so we can decide
1682 * when to enable/disable the prev/next buttons.
1684 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1685 base_klass->before_next = on_before_next;
1686 base_klass->enable_buttons = on_enable_buttons;
1690 show_error (GtkWidget *parent_widget, const gchar* text)
1692 //TODO: Apparently this doesn't show anything in Maemo Bora:
1693 hildon_banner_show_information(parent_widget, NULL, text);
1696 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
1698 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1705 gtk_dialog_run (dialog);
1706 gtk_widget_destroy (GTK_WIDGET (dialog));
1710 /** Attempt to create the account from the information that the user has entered.
1711 * @result: TRUE if the account was successfully created.
1714 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1716 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1718 gchar* display_name = get_entered_account_title (self);
1724 /* We should have checked for this already,
1725 * and changed that name accordingly,
1726 * but let's check again just in case:
1728 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name)) {
1729 g_free (display_name);
1733 /* Increment the non-user visible name if necessary,
1734 * based on the display name: */
1735 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1736 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1737 account_name_start, FALSE /* not a server account */);
1738 g_free (account_name_start);
1740 /* username and password (for both incoming and outgoing): */
1741 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1742 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1743 /* Incoming server: */
1744 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1745 * or modest_account_mgr_add_server_account will fail. */
1746 gchar* servername_incoming = NULL;
1747 guint serverport_incoming = 0;
1748 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1749 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1750 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1752 /* Get details from the specified presets: */
1753 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1754 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1757 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1758 TRUE /* incoming */);
1760 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1762 TRUE /* incoming */);
1763 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1765 TRUE /* incoming */);
1768 /* We don't check for SMTP here as that is impossible for an incoming server. */
1769 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1770 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1771 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1772 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1774 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1776 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1777 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1779 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1780 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1783 /* Use custom pages because no preset was specified: */
1784 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1786 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1787 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1789 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1790 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1792 /* The UI spec says:
1793 * If secure authentication is unchecked, allow sending username and password also as plain text.
1794 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1797 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1798 !modest_protocol_info_is_secure(protocol_security_incoming)) {
1799 protocol_authentication_incoming = check_first_supported_auth_method (self);
1802 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1806 /* First we add the 2 server accounts, and then we add the account that uses them.
1807 * If we don't do it in this order then we will experience a crash. */
1809 /* Add a (incoming) server account, to be used by the account: */
1810 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1811 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1812 store_name_start, TRUE /* server account */);
1813 g_free (store_name_start);
1815 /* we check if there is a *special* port */
1816 special_port = modest_presets_get_port (priv->presets, provider_id,
1817 TRUE /* incoming */);
1818 if (special_port != 0)
1819 serverport_incoming = special_port;
1821 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1823 servername_incoming,
1824 serverport_incoming,
1827 protocol_security_incoming,
1828 protocol_authentication_incoming);
1830 g_free (servername_incoming);
1833 /* TODO: Provide a Logical ID for the text: */
1834 show_error (GTK_WIDGET (self), _("An error occurred while creating the incoming account."));
1835 g_free (display_name);
1839 /* Outgoing server: */
1840 gchar* servername_outgoing = NULL;
1841 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1842 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1843 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1844 guint serverport_outgoing = 0;
1848 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1849 FALSE /* incoming */);
1851 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1853 FALSE /* incoming */);
1855 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1856 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1857 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1858 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1860 ModestPresetsSecurity security_outgoing =
1861 modest_presets_get_info_server_security (priv->presets, provider_id,
1862 FALSE /* incoming */);
1864 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1865 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1866 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1867 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1868 serverport_outgoing = 465;
1869 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1871 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1872 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1875 /* Use custom pages because no preset was specified: */
1876 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1878 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1880 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1881 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1883 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1884 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1887 /* Add a (outgoing) server account to be used by the account: */
1888 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1889 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1890 transport_name_start, TRUE /* server account */);
1891 g_free (transport_name_start);
1893 /* we check if there is a *special* port */
1894 special_port = modest_presets_get_port (priv->presets, provider_id,
1895 FALSE /* incoming */);
1896 if (special_port != 0)
1897 serverport_outgoing = special_port;
1899 created = modest_account_mgr_add_server_account (self->account_manager,
1901 servername_outgoing,
1902 serverport_outgoing,
1905 protocol_security_outgoing,
1906 protocol_authentication_outgoing);
1908 g_free (servername_outgoing);
1911 /* TODO: Provide a Logical ID for the text: */
1912 show_error (GTK_WIDGET (self), _("An error occurred while creating the outgoing account."));
1913 g_free (display_name);
1917 const gchar* user_fullname = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1918 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1919 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1921 /* Create the account, which will contain the two "server accounts": */
1922 created = modest_account_mgr_add_account (self->account_manager,
1931 g_free (store_name);
1932 g_free (transport_name);
1935 /* TODO: Provide a Logical ID for the text: */
1936 show_error (GTK_WIDGET (self), _("An error occurred while creating the account."));
1937 g_free (display_name);
1942 /* There must be at least one account now: */
1943 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1944 * fixed in versions after 3.1. */
1945 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1946 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1948 /* Save the connection-specific SMTP server accounts. */
1949 modest_account_mgr_set_use_connection_specific_smtp(self->account_manager, account_name,
1950 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->checkbox_outgoing_smtp_specific)));
1951 gboolean result = TRUE;
1952 if (self->specific_window)
1953 result = modest_connection_specific_smtp_window_save_server_accounts (
1954 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window));
1957 g_free (self->saved_account_name);
1958 self->saved_account_name = g_strdup (account_name);
1960 g_free (account_name);
1961 g_free (display_name);