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 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
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;
73 /* global to make sure there is only one of this
76 static ModestEasysetupWizardDialog *_instance = NULL;
79 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
80 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
81 } ModestEasysetupWizardDialogServerChanges;
83 struct _ModestEasysetupWizardDialogPrivate
85 ModestPresets *presets;
87 /* Remember what fields the user edited manually to not prefill them
89 ModestEasysetupWizardDialogServerChanges server_changes;
91 /* Check if the user changes a field to show a confirmation dialog */
96 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
98 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(wizard);
99 g_return_if_fail (priv != NULL);
104 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
105 GValue *value, GParamSpec *pspec)
107 switch (property_id) {
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
114 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
115 const GValue *value, GParamSpec *pspec)
117 switch (property_id) {
119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
124 modest_easysetup_wizard_dialog_dispose (GObject *object)
126 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
127 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
131 modest_easysetup_wizard_dialog_finalize (GObject *object)
133 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
134 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
136 if (self->account_manager)
137 g_object_unref (G_OBJECT (self->account_manager));
140 modest_presets_destroy (priv->presets);
142 if (self->specific_window)
143 gtk_widget_destroy (self->specific_window);
145 g_free (self->saved_account_name);
147 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
153 show_error (GtkWidget *parent_widget, const gchar* text);
156 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
159 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
162 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
164 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
166 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
167 ModestPresetsSecurity security_incoming)
169 int serverport_incoming = 0;
170 /* We don't check for SMTP here as that is impossible for an incoming server. */
171 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
172 serverport_incoming =
173 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
174 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
175 serverport_incoming =
176 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
178 return serverport_incoming;
181 static GList* check_for_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
183 GError *error = NULL;
184 const ModestTransportStoreProtocol protocol =
185 easysetup_servertype_combo_box_get_active_servertype (
186 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
187 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
188 const gchar* username = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_user_username));
189 const ModestConnectionProtocol protocol_security_incoming =
190 modest_serversecurity_combo_box_get_active_serversecurity (
191 MODEST_SERVERSECURITY_COMBO_BOX (
192 account_wizard->combo_incoming_security));
193 int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
194 GList *list_auth_methods =
195 modest_maemo_utils_get_supported_secure_authentication_methods (
197 hostname, port_num, username, GTK_WINDOW (account_wizard), &error);
198 if (list_auth_methods) {
199 /* TODO: Select the correct method */
202 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
203 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
204 if (modest_protocol_info_auth_is_secure(auth)) {
205 list = g_list_append(list, GINT_TO_POINTER(auth));
208 g_list_free(list_auth_methods);
213 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
214 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
216 show_error (GTK_WIDGET(account_wizard), _("Could not discover supported secure authentication methods."));
219 if(error != NULL) g_error_free(error);
224 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
226 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
228 /* Call the vfunc, which may be overridden by derived classes: */
229 if (klass->enable_buttons) {
230 GtkNotebook *notebook = NULL;
231 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
233 const gint current_page_num = gtk_notebook_get_current_page (notebook);
234 if (current_page_num == -1)
237 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
238 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
243 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
245 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
247 invoke_enable_buttons_vfunc(self);
251 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
253 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
255 invoke_enable_buttons_vfunc(self);
258 /** This is a convenience function to create a caption containing a mandatory widget.
259 * When the widget is edited, the enable_buttons() vfunc will be called.
261 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
266 HildonCaptionStatus flag)
268 GtkWidget *caption = NULL;
270 /* Note: Previously, the translated strings already contained the "*",
271 * Comment out this code if they do again.
273 /* Add a * character to indicate mandatory fields,
274 * as specified in our "Email UI Specification": */
275 if (flag == HILDON_CAPTION_MANDATORY) {
276 gchar* title = g_strdup_printf("%s*", value);
277 caption = hildon_caption_new (group, title, control, icon, flag);
281 caption = hildon_caption_new (group, value, control, icon, flag);
283 /* Connect to the appropriate changed signal for the widget,
284 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
286 if (GTK_IS_ENTRY (control)) {
287 g_signal_connect (G_OBJECT (control), "changed",
288 G_CALLBACK (on_caption_entry_changed), self);
291 else if (GTK_IS_COMBO_BOX (control)) {
292 g_signal_connect (G_OBJECT (control), "changed",
293 G_CALLBACK (on_caption_combobox_changed), self);
300 create_page_welcome (ModestEasysetupWizardDialog *self)
302 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
303 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
304 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
305 /* So that it is not truncated: */
306 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
307 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
308 gtk_widget_show (label);
309 gtk_widget_show (GTK_WIDGET (box));
310 return GTK_WIDGET (box);
314 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
316 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
318 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
322 /* Fill the providers combo, based on the selected country: */
323 GSList *list_mcc_ids = easysetup_country_combo_box_get_active_country_ids (
324 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
325 easysetup_provider_combo_box_fill (
326 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, list_mcc_ids);
330 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
332 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
334 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
338 /* Fill the providers combo, based on the selected country: */
339 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
340 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
342 gchar* domain_name = NULL;
344 domain_name = modest_presets_get_domain (priv->presets, provider_id);
347 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
349 if (self->entry_user_email)
350 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
352 g_free (domain_name);
354 g_free (provider_id);
358 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
360 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
361 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
365 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
367 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
369 const gchar *show_char = NULL;
371 show_char = character;
373 /* TODO: We need a logical ID for this: */
374 show_char = _("whitespace");
377 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
378 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), show_char);
379 show_error (GTK_WIDGET (self), message);
383 create_page_account_details (ModestEasysetupWizardDialog *self)
385 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
386 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
387 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
388 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
389 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
390 gtk_widget_show (label);
392 /* Create a size group to be used by all captions.
393 * Note that HildonCaption does not create a default size group if we do not specify one.
394 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
395 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
397 /* The country widgets: */
398 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
399 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
400 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
401 gtk_widget_show (self->combo_account_country);
402 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
403 gtk_widget_show (caption);
405 /* connect to country combo's changed signal, so we can fill the provider combo: */
406 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
407 G_CALLBACK (on_combo_account_country), self);
409 GtkWidget *separator = gtk_hseparator_new ();
410 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
411 gtk_widget_show (separator);
413 /* The service provider widgets: */
414 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
416 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
417 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
418 gtk_widget_show (self->combo_account_serviceprovider);
419 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
420 gtk_widget_show (caption);
422 /* connect to providers combo's changed signal, so we can fill the email address: */
423 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
424 G_CALLBACK (on_combo_account_serviceprovider), self);
426 /* TODO: Default to the current country somehow.
427 * But I don't know how to get the information that is specified in the
428 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
430 * This is probably not the best choice of gconf key:
431 * This is the "mcc used in the last pairing", ie. the last connection you made.
432 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
435 GConfClient *client = gconf_client_get_default ();
436 GError *error = NULL;
437 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
438 gint mcc_id = gconf_client_get_int(client, key, &error);
444 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
445 g_error_free (error);
451 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
452 * This might just be a Maemo bug.
456 /* For now, we default to Finland when there is nothing better: */
460 easysetup_country_combo_box_set_active_country_id (
461 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
464 /* The description widgets: */
465 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
466 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
467 G_CALLBACK(on_easysetup_changed), self);
468 /* Do use auto-capitalization: */
469 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
470 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
472 /* Set a default account title, choosing one that does not already exist: */
473 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
474 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
475 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
476 self->account_manager, default_account_name_start);
477 g_free (default_account_name_start);
478 default_account_name_start = NULL;
480 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
481 g_free (default_account_name);
482 default_account_name = NULL;
484 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
485 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
486 gtk_widget_show (self->entry_account_title);
487 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
488 gtk_widget_show (caption);
490 /* Prevent the use of some characters in the account title,
491 * as required by our UI specification: */
492 GList *list_prevent = NULL;
493 list_prevent = g_list_append (list_prevent, "\\");
494 list_prevent = g_list_append (list_prevent, "/");
495 list_prevent = g_list_append (list_prevent, ":");
496 list_prevent = g_list_append (list_prevent, "*");
497 list_prevent = g_list_append (list_prevent, "?");
498 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
499 list_prevent = g_list_append (list_prevent, "“");
500 list_prevent = g_list_append (list_prevent, "<");
501 list_prevent = g_list_append (list_prevent, ">");
502 list_prevent = g_list_append (list_prevent, "|");
503 list_prevent = g_list_append (list_prevent, "^");
504 modest_validating_entry_set_unallowed_characters (
505 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
506 g_list_free (list_prevent);
508 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
509 on_entry_invalid_character, self);
511 /* Set max length as in the UI spec:
512 * The UI spec seems to want us to show a dialog if we hit the maximum. */
513 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
514 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
517 gtk_widget_show (GTK_WIDGET (box));
519 return GTK_WIDGET (box);
523 create_page_user_details (ModestEasysetupWizardDialog *self)
525 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
527 /* Create a size group to be used by all captions.
528 * Note that HildonCaption does not create a default size group if we do not specify one.
529 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
530 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
532 /* The name widgets: (use auto cap) */
533 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
534 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name),
535 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
537 /* Set max length as in the UI spec:
538 * The UI spec seems to want us to show a dialog if we hit the maximum. */
539 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
540 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
542 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
543 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
544 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
545 G_CALLBACK(on_easysetup_changed), self);
546 gtk_widget_show (self->entry_user_name);
547 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
548 gtk_widget_show (caption);
550 /* Prevent the use of some characters in the name,
551 * as required by our UI specification: */
552 GList *list_prevent = NULL;
553 list_prevent = g_list_append (list_prevent, "<");
554 list_prevent = g_list_append (list_prevent, ">");
555 modest_validating_entry_set_unallowed_characters (
556 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
557 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
558 on_entry_invalid_character, self);
559 g_list_free (list_prevent);
561 /* The username widgets: */
562 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
563 /* Auto-capitalization is the default, so let's turn it off: */
564 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
565 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
566 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
567 gtk_widget_show (self->entry_user_username);
568 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
569 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
570 G_CALLBACK(on_easysetup_changed), self);
571 gtk_widget_show (caption);
573 /* Prevent the use of some characters in the username,
574 * as required by our UI specification: */
575 modest_validating_entry_set_unallowed_characters_whitespace (
576 MODEST_VALIDATING_ENTRY (self->entry_user_username));
577 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_username),
578 on_entry_invalid_character, self);
580 /* Set max length as in the UI spec:
581 * The UI spec seems to want us to show a dialog if we hit the maximum. */
582 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
583 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
586 /* The password widgets: */
587 self->entry_user_password = gtk_entry_new ();
588 /* Auto-capitalization is the default, so let's turn it off: */
589 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
590 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
591 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
592 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
593 caption = create_caption_new_with_asterisk (self, sizegroup,
594 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
595 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
596 G_CALLBACK(on_easysetup_changed), self);
597 gtk_widget_show (self->entry_user_password);
598 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
599 gtk_widget_show (caption);
601 /* The email address widgets: */
602 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
603 /* Auto-capitalization is the default, so let's turn it off: */
604 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
605 caption = create_caption_new_with_asterisk (self, sizegroup,
606 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
607 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
608 gtk_widget_show (self->entry_user_email);
609 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
610 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
611 G_CALLBACK(on_easysetup_changed), self);
612 gtk_widget_show (caption);
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_email), 64);
617 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
621 gtk_widget_show (GTK_WIDGET (box));
623 return GTK_WIDGET (box);
626 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
628 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
630 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
631 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
632 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
633 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
634 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
635 gtk_widget_show (label);
637 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
638 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
639 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
641 /* The documentation for gtk_label_set_line_wrap() says that we must
642 * call gtk_widget_set_size_request() with a hard-coded width,
643 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
644 gtk_widget_set_size_request (label, 400, -1);
646 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
647 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
648 gtk_widget_show (label);
650 gtk_widget_show (GTK_WIDGET (box));
651 return GTK_WIDGET (box);
654 /** Change the caption title for the incoming server,
655 * as specified in the UI spec:
657 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
659 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
660 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
662 (protocol == MODEST_PROTOCOL_STORE_POP ?
663 _("mail_fi_emailtype_pop3") :
664 _("mail_fi_emailtype_imap") );
667 /* Note that this produces a compiler warning,
668 * because the compiler does not know that the translated string will have a %s in it.
669 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
670 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
671 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
672 g_free(incomingserver_title);
675 /** Change the caption title for the incoming server,
676 * as specified in the UI spec:
678 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
680 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
681 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
683 /* Fill the combo with appropriately titled choices for POP or IMAP. */
684 /* The choices are the same, but the titles are different, as in the UI spec. */
685 modest_serversecurity_combo_box_fill (
686 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
689 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
691 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
692 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
696 update_incoming_server_title (self);
697 update_incoming_server_security_choices (self);
699 set_default_custom_servernames (self);
702 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
704 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
705 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
707 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
710 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
712 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
714 /* Show note that account type cannot be changed in future: */
715 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
716 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
717 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
718 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
719 gtk_widget_show (label);
721 /* Create a size group to be used by all captions.
722 * Note that HildonCaption does not create a default size group if we do not specify one.
723 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
724 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
726 /* The incoming server widgets: */
727 if (!self->combo_incoming_servertype)
728 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
729 easysetup_servertype_combo_box_set_active_servertype (
730 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
731 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
732 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
733 gtk_widget_show (self->combo_incoming_servertype);
734 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
735 gtk_widget_show (caption);
737 if(!self->entry_incomingserver)
739 self->entry_incomingserver = gtk_entry_new ();
740 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed",
741 G_CALLBACK(on_easysetup_changed), self);
743 /* Auto-capitalization is the default, so let's turn it off: */
744 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
745 set_default_custom_servernames (self);
747 if (self->caption_incoming)
748 gtk_widget_destroy (self->caption_incoming);
750 /* The caption title will be updated in update_incoming_server_title().
751 * so this default text will never be seen: */
752 /* (Note: Changing the title seems pointless. murrayc) */
753 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
754 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
755 update_incoming_server_title (self);
756 gtk_widget_show (self->entry_incomingserver);
757 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
758 gtk_widget_show (self->caption_incoming);
760 /* Change the caption title when the servertype changes,
761 * as in the UI spec: */
762 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
763 G_CALLBACK (on_combo_servertype_changed), self);
765 /* Remember when the servername was changed manually: */
766 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
767 G_CALLBACK (on_entry_incoming_servername_changed), self);
769 /* The secure connection widgets: */
770 if (!self->combo_incoming_security)
771 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
772 update_incoming_server_security_choices (self);
773 modest_serversecurity_combo_box_set_active_serversecurity (
774 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
775 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
776 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
777 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
778 G_CALLBACK (on_easysetup_changed), self);
779 gtk_widget_show (self->combo_incoming_security);
780 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
781 gtk_widget_show (caption);
783 if(!self->checkbox_incoming_auth)
785 self->checkbox_incoming_auth = gtk_check_button_new ();
786 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
787 G_CALLBACK (on_easysetup_changed), self);
789 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
790 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
792 gtk_widget_show (self->checkbox_incoming_auth);
793 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
794 gtk_widget_show (caption);
796 gtk_widget_show (GTK_WIDGET (box));
798 return GTK_WIDGET (box);
802 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
804 GtkWidget *widget = GTK_WIDGET (user_data);
806 /* Enable the widget only if the toggle button is active: */
807 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
808 gtk_widget_set_sensitive (widget, enable);
811 /* Make the sensitivity of a widget depend on a toggle button.
814 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
816 g_signal_connect (G_OBJECT (button), "toggled",
817 G_CALLBACK (on_toggle_button_changed), widget);
819 /* Set the starting sensitivity: */
820 on_toggle_button_changed (button, widget);
824 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
826 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
827 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
829 /* We set dirty here because setting it depending on the connection specific dialog
833 /* Create the window, if necessary: */
834 if (!(self->specific_window)) {
835 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
836 modest_connection_specific_smtp_window_fill_with_connections (
837 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
838 NULL /* account_name, not known yet. */);
841 /* Show the window: */
842 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
843 gtk_widget_show (self->specific_window);
846 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
848 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
849 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
850 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
853 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
855 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
857 /* Create a size group to be used by all captions.
858 * Note that HildonCaption does not create a default size group if we do not specify one.
859 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
860 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
862 /* The outgoing server widgets: */
863 if (!self->entry_outgoingserver)
865 self->entry_outgoingserver = gtk_entry_new ();
866 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
867 G_CALLBACK (on_easysetup_changed), self);
869 /* Auto-capitalization is the default, so let's turn it off: */
870 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
871 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
872 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
873 gtk_widget_show (self->entry_outgoingserver);
874 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
875 gtk_widget_show (caption);
876 set_default_custom_servernames (self);
878 /* The secure connection widgets: */
879 if (!self->combo_outgoing_security)
881 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
882 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
883 G_CALLBACK (on_easysetup_changed), self);
885 modest_serversecurity_combo_box_fill (
886 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
887 modest_serversecurity_combo_box_set_active_serversecurity (
888 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
889 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
890 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
891 gtk_widget_show (self->combo_outgoing_security);
892 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
893 gtk_widget_show (caption);
895 /* The secure authentication widgets: */
896 if (!self->combo_outgoing_auth)
898 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
899 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
900 G_CALLBACK (on_easysetup_changed), self);
902 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
903 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
904 gtk_widget_show (self->combo_outgoing_auth);
905 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
906 gtk_widget_show (caption);
908 GtkWidget *separator = gtk_hseparator_new ();
909 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
910 gtk_widget_show (separator);
912 /* connection-specific checkbox: */
913 if (!self->checkbox_outgoing_smtp_specific) {
914 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
915 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
917 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
918 G_CALLBACK (on_easysetup_changed), self);
921 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
922 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
923 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
924 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
925 gtk_widget_show (caption);
927 /* Connection-specific SMTP-Severs Edit button: */
928 if (!self->button_outgoing_smtp_servers)
929 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
930 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
931 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
932 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
933 gtk_widget_show (self->button_outgoing_smtp_servers);
934 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
935 gtk_widget_show (caption);
937 /* Only enable the button when the checkbox is checked: */
938 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
939 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
941 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
942 G_CALLBACK (on_button_outgoing_smtp_servers), self);
944 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
945 G_CALLBACK (on_entry_outgoing_servername_changed), self);
948 gtk_widget_show (GTK_WIDGET (box));
950 return GTK_WIDGET (box);
954 show_advanced_edit(gpointer user_data)
956 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
958 if (!(self->saved_account_name))
961 /* Show the Account Settings window: */
962 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
963 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
965 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
967 gtk_dialog_run (GTK_DIALOG (dialog));
969 gtk_widget_destroy (GTK_WIDGET (dialog));
971 return FALSE; /* Do not call this timeout callback again. */
975 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
977 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
979 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
980 * without recoding it to use non-gconf information.
981 * This account will be deleted if Finish is never actually clicked. */
983 gboolean saved = TRUE;
984 if (!(self->saved_account_name)) {
985 saved = create_account (self, FALSE);
991 if (!(self->saved_account_name))
994 /* Show the Account Settings window: */
995 show_advanced_edit(self);
997 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
999 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
1000 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
1001 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1002 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1003 gtk_widget_show (label);
1005 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
1006 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
1007 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1008 gtk_widget_show (label);
1010 if (!self->button_edit)
1011 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
1012 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
1013 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1014 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1015 gtk_widget_show (self->button_edit);
1016 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1017 gtk_widget_show (caption);
1019 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
1020 G_CALLBACK (on_button_edit_advanced_settings), self);
1022 gtk_widget_show (GTK_WIDGET (box));
1023 return GTK_WIDGET (box);
1030 on_response (ModestWizardDialog *wizard_dialog,
1034 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1035 if (response_id == GTK_RESPONSE_CANCEL) {
1036 /* Remove any temporarily-saved account that will not actually be needed: */
1037 if (self->saved_account_name) {
1038 modest_account_mgr_remove_account (self->account_manager,
1039 self->saved_account_name);
1043 invoke_enable_buttons_vfunc (self);
1047 on_response_before (ModestWizardDialog *wizard_dialog,
1051 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1052 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1053 if (response_id == GTK_RESPONSE_CANCEL) {
1054 /* This is mostly copied from
1055 * src/maemo/modest-account-settings-dialog.c */
1058 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1059 _("imum_nc_wizard_confirm_lose_changes")));
1060 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1062 const gint dialog_response = gtk_dialog_run (dialog);
1063 gtk_widget_destroy (GTK_WIDGET (dialog));
1065 if (dialog_response != GTK_RESPONSE_OK)
1067 /* This is a nasty hack. murrayc. */
1068 /* Don't let the dialog close */
1069 g_signal_stop_emission_by_name (wizard_dialog, "response");
1076 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1078 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1080 /* Create the notebook to be used by the ModestWizardDialog base class:
1081 * Each page of the notebook will be a page of the wizard: */
1082 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1084 /* Set the notebook used by the ModestWizardDialog base class: */
1085 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1087 /* Set the wizard title:
1088 * The actual window title will be a combination of this and the page's tab label title. */
1089 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1091 /* Read in the information about known service providers: */
1092 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1094 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
1095 priv->presets = modest_presets_new (filepath);
1096 if (!(priv->presets)) {
1097 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
1100 g_assert(priv->presets);
1102 /* The server fields did not have been manually changed yet */
1103 priv->server_changes = 0;
1105 /* Get the account manager object,
1106 * so we can check for existing accounts,
1107 * and create new accounts: */
1108 self->account_manager = modest_runtime_get_account_mgr ();
1109 g_assert (self->account_manager);
1110 g_object_ref (self->account_manager);
1112 /* Create the common pages,
1114 self->page_welcome = create_page_welcome (self);
1115 self->page_account_details = create_page_account_details (self);
1116 self->page_user_details = create_page_user_details (self);
1118 /* Add the common pages: */
1119 gtk_notebook_append_page (notebook, self->page_welcome,
1120 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1121 gtk_notebook_append_page (notebook, self->page_account_details,
1122 gtk_label_new (_("mcen_ti_accountdetails")));
1123 gtk_notebook_append_page (notebook, self->page_user_details,
1124 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1126 /* Create and add the easysetup-specific pages,
1127 * because we need _some_ final page to enable the Next and Finish buttons: */
1128 create_subsequent_easysetup_pages (self);
1130 /* Connect to the dialog's response signal so we can enable/disable buttons
1131 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1132 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1133 * so that we can be enable/disable after ModestWizardDialog has done its own
1134 * enabling/disabling of buttons.
1136 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1137 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1139 * It's not enough to connect to the notebook's switch-page signal, because
1140 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1141 * _after_ switching the page (understandably).
1142 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1143 * then gtk_notebook_get_current_page() would return an incorrect value.)
1145 g_signal_connect_after (G_OBJECT (self), "response",
1146 G_CALLBACK (on_response), self);
1148 /* This is to show a confirmation dialog when the user hits cancel */
1149 g_signal_connect (G_OBJECT (self), "response",
1150 G_CALLBACK (on_response_before), self);
1152 /* Reset dirty, because there was no user input until now */
1153 priv->dirty = FALSE;
1155 /* When this window is shown, hibernation should not be possible,
1156 * because there is no sensible way to save the state: */
1157 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1158 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1161 ModestEasysetupWizardDialog*
1162 modest_easysetup_wizard_dialog_new_or_present (void)
1165 g_message ("%s: already instantiated; presenting\n",
1167 gtk_window_present (GTK_WINDOW(_instance));
1171 return _instance = g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1174 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1176 GtkNotebook *notebook = NULL;
1177 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1180 /* Create the custom pages: */
1181 if(!(self->page_custom_incoming)) {
1182 self->page_custom_incoming = create_page_custom_incoming (self);
1185 if(!(self->page_custom_outgoing)) {
1186 self->page_custom_outgoing = create_page_custom_outgoing (self);
1189 if(!(self->page_complete_customsetup)) {
1190 self->page_complete_customsetup = create_page_complete_custom (self);
1193 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1194 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1195 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1197 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1198 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1199 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1201 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1202 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1203 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1205 /* This is unnecessary with GTK+ 2.10: */
1206 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1209 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1211 GtkNotebook *notebook = NULL;
1212 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1215 /* Create the easysetup-specific pages: */
1216 if(!self->page_complete_easysetup)
1217 self->page_complete_easysetup = create_page_complete_easysetup (self);
1219 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1220 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1221 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1223 /* This is unnecessary with GTK+ 2.10: */
1224 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1226 /* After the user details page,
1227 * the following pages depend on whether "Other" was chosen
1228 * in the provider combobox on the account page
1230 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1232 if (easysetup_provider_combo_box_get_active_provider_id (
1233 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1234 /* "Other..." was selected: */
1236 /* Make sure that the easysetup pages do not exist: */
1237 if(self->page_complete_easysetup) {
1238 gtk_widget_destroy (self->page_complete_easysetup);
1239 self->page_complete_easysetup = NULL;
1242 create_subsequent_customsetup_pages (self);
1245 /* A specific provider was selected: */
1247 /* Make sure that the custom pages do not exist:
1248 * Because they will be used if they exist, when creating the account. */
1249 if(self->page_custom_incoming) {
1250 gtk_widget_destroy (self->page_custom_incoming);
1251 self->page_custom_incoming = NULL;
1254 if(self->page_custom_outgoing) {
1255 gtk_widget_destroy (self->page_custom_outgoing);
1256 self->page_custom_outgoing = NULL;
1259 if(self->page_complete_customsetup) {
1260 gtk_widget_destroy (self->page_complete_customsetup);
1261 self->page_complete_customsetup = NULL;
1265 /* Create the easysetup pages: */
1266 create_subsequent_easysetup_pages (self);
1272 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1277 gchar* at = g_utf8_strchr (email_address, -1, '@');
1278 if (!at || (g_utf8_strlen (at, -1) < 2))
1281 gchar* domain = g_utf8_next_char (at);
1285 const gchar* hostname = NULL;
1286 if (servertype == MODEST_PROTOCOL_STORE_POP)
1288 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1290 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1296 return g_strdup_printf ("%s.%s", hostname, domain);
1299 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1301 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1303 if (!account_wizard->entry_incomingserver)
1306 /* Set a default domain for the server, based on the email address,
1307 * if no server name was already specified.
1309 if (account_wizard->entry_user_email
1310 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1311 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1312 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1313 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1315 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1317 /* Do not set the INCOMING_CHANGED flag because of this edit */
1318 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1319 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1320 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1322 g_free (servername);
1325 /* Set a default domain for the server, based on the email address,
1326 * if no server name was already specified.
1328 if (!account_wizard->entry_outgoingserver)
1331 if (account_wizard->entry_user_email
1332 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1333 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1335 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1337 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1338 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1339 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1340 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1342 g_free (servername);
1347 get_entered_account_title (ModestEasysetupWizardDialog *account_wizard)
1349 const gchar* account_title =
1350 gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1351 if (!account_title || (strlen (account_title) == 0))
1354 /* Strip it of whitespace at the start and end: */
1355 gchar *result = g_strdup (account_title);
1356 result = g_strstrip (result);
1361 if (strlen (result) == 0) {
1371 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1373 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1375 /* Do extra validation that couldn't be done for every key press,
1376 * either because it was too slow,
1377 * or because it requires interaction:
1379 if (current_page == account_wizard->page_account_details) {
1380 /* Check that the title is not already in use: */
1381 gchar* account_title = get_entered_account_title (account_wizard);
1385 /* Aavoid a clash with an existing display name: */
1386 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1387 account_wizard->account_manager, account_title);
1390 /* Warn the user via a dialog: */
1391 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1396 else if (current_page == account_wizard->page_user_details) {
1397 /* Check that the email address is valud: */
1398 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1399 if ((!email_address) || (strlen(email_address) == 0))
1402 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1403 /* Warn the user via a dialog: */
1404 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1406 /* Return focus to the email address entry: */
1407 gtk_widget_grab_focus (account_wizard->entry_user_email);
1408 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1413 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1414 create_subsequent_pages (account_wizard);
1417 /* TODO: The UI Spec wants us to check that the servernames are valid,
1418 * but does not specify how.
1421 if(next_page == account_wizard->page_custom_incoming) {
1422 set_default_custom_servernames (account_wizard);
1424 else if (next_page == account_wizard->page_custom_outgoing) {
1425 set_default_custom_servernames (account_wizard);
1426 /* Check if the server supports secure authentication */
1427 const ModestConnectionProtocol security_incoming =
1428 modest_serversecurity_combo_box_get_active_serversecurity (
1429 MODEST_SERVERSECURITY_COMBO_BOX (
1430 account_wizard->combo_incoming_security));
1431 if (gtk_toggle_button_get_active (
1432 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1433 && !modest_protocol_info_is_secure(security_incoming))
1435 GList* methods = check_for_supported_auth_methods(account_wizard);
1438 g_list_free(methods);
1441 g_list_free(methods);
1445 /* If this is the last page, and this is a click on Finish,
1446 * then attempt to create the dialog.
1448 if(!next_page) /* This is NULL when this is a click on Finish. */
1450 if (account_wizard->saved_account_name) {
1451 /* Just enable the already-saved account (temporarily created when
1452 * editing advanced settings): */
1453 modest_account_mgr_set_enabled (account_wizard->account_manager,
1454 account_wizard->saved_account_name, TRUE);
1456 create_account (account_wizard, TRUE /* enabled */);
1464 static gboolean entry_is_empty (GtkWidget *entry)
1469 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1470 if ((!text) || (strlen(text) == 0))
1473 /* Strip it of whitespace at the start and end: */
1474 gchar *stripped = g_strdup (text);
1475 stripped = g_strstrip (stripped);
1480 const gboolean result = (strlen (stripped) == 0);
1488 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1490 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1492 gboolean enable_next = TRUE;
1493 if (current_page == account_wizard->page_welcome) {
1496 else if (current_page == account_wizard->page_account_details) {
1497 /* The account details title is mandatory: */
1498 if (entry_is_empty(account_wizard->entry_account_title))
1499 enable_next = FALSE;
1501 else if (current_page == account_wizard->page_user_details) {
1502 /* The user details username is mandatory: */
1503 if (entry_is_empty(account_wizard->entry_user_username))
1504 enable_next = FALSE;
1506 /* The user details email address is mandatory: */
1507 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1508 enable_next = FALSE;
1510 else if (current_page == account_wizard->page_custom_incoming) {
1511 /* The custom incoming server is mandatory: */
1512 if (entry_is_empty(account_wizard->entry_incomingserver))
1513 enable_next = FALSE;
1516 /* Enable the buttons,
1517 * identifying them via their associated response codes: */
1519 /* Disable the Finish button until we are on the last page,
1520 * because HildonWizardDialog enables this for all but the first page: */
1521 GtkNotebook *notebook = NULL;
1522 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1523 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1525 gint current = gtk_notebook_get_current_page (notebook);
1526 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1527 const gboolean is_last = (current == last);
1530 gtk_dialog_set_response_sensitive (dialog_base,
1531 MODEST_WIZARD_DIALOG_FINISH,
1535 /* Disable Next on the last page: */
1536 enable_next = FALSE;
1539 gtk_dialog_set_response_sensitive (dialog_base,
1540 MODEST_WIZARD_DIALOG_NEXT,
1545 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1547 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1548 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1551 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1552 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1553 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1554 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1556 /* Provide a vfunc implementation so we can decide
1557 * when to enable/disable the prev/next buttons.
1559 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1560 base_klass->before_next = on_before_next;
1561 base_klass->enable_buttons = on_enable_buttons;
1565 show_error (GtkWidget *parent_widget, const gchar* text)
1567 //TODO: Apparently this doesn't show anything in Maemo Bora:
1568 hildon_banner_show_information(parent_widget, NULL, text);
1571 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
1573 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1580 gtk_dialog_run (dialog);
1581 gtk_widget_destroy (GTK_WIDGET (dialog));
1585 /** Attempt to create the account from the information that the user has entered.
1586 * @result: TRUE if the account was successfully created.
1589 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1591 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1593 gchar* display_name = get_entered_account_title (self);
1599 /* We should have checked for this already,
1600 * and changed that name accordingly,
1601 * but let's check again just in case:
1603 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name)) {
1604 g_free (display_name);
1608 /* Increment the non-user visible name if necessary,
1609 * based on the display name: */
1610 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1611 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1612 account_name_start, FALSE /* not a server account */);
1613 g_free (account_name_start);
1615 /* username and password (for both incoming and outgoing): */
1616 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1617 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1618 /* Incoming server: */
1619 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1620 * or modest_account_mgr_add_server_account will fail. */
1621 gchar* servername_incoming = NULL;
1622 guint serverport_incoming = 0;
1623 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1624 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1625 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1627 /* Get details from the specified presets: */
1628 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1629 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1632 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1633 TRUE /* incoming */);
1635 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1637 TRUE /* incoming */);
1638 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1640 TRUE /* incoming */);
1642 g_warning ("security incoming: %x", security_incoming);
1644 /* We don't check for SMTP here as that is impossible for an incoming server. */
1645 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1646 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1647 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1648 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1650 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1652 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1653 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1655 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1656 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1659 /* Use custom pages because no preset was specified: */
1660 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1662 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1663 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1665 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1666 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1668 /* The UI spec says:
1669 * If secure authentication is unchecked, allow sending username and password also as plain text.
1670 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1673 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1674 !modest_protocol_info_is_secure(protocol_security_incoming))
1676 GList* methods = check_for_supported_auth_methods(self);
1678 g_free (display_name);
1682 protocol_authentication_incoming = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
1685 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1688 /* First we add the 2 server accounts, and then we add the account that uses them.
1689 * If we don't do it in this order then we will experience a crash. */
1691 /* Add a (incoming) server account, to be used by the account: */
1692 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1693 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1694 store_name_start, TRUE /* server account */);
1695 g_free (store_name_start);
1696 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1698 servername_incoming,
1699 serverport_incoming,
1702 protocol_security_incoming,
1703 protocol_authentication_incoming);
1705 g_free (servername_incoming);
1708 /* TODO: Provide a Logical ID for the text: */
1709 show_error (GTK_WIDGET (self), _("An error occurred while creating the incoming account."));
1710 g_free (display_name);
1714 /* Outgoing server: */
1715 gchar* servername_outgoing = NULL;
1716 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1717 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1718 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1719 guint serverport_outgoing = 0;
1723 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1724 FALSE /* incoming */);
1726 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1728 FALSE /* incoming */);
1730 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1731 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1732 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1733 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1735 ModestPresetsSecurity security_outgoing =
1736 modest_presets_get_info_server_security (priv->presets, provider_id,
1737 FALSE /* incoming */);
1739 /* TODO: The secure-smtp information in the presets data is currently wrong,
1740 * so we choose a reasonable default. Remove this when the presets data is corrected: */
1741 security_outgoing = security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP;
1743 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1744 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1745 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1746 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1747 serverport_outgoing = 465;
1748 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1750 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1751 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1755 /* Use custom pages because no preset was specified: */
1756 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1758 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1760 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1761 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1763 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1764 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1767 /* Add a (outgoing) server account to be used by the account: */
1768 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1769 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1770 transport_name_start, TRUE /* server account */);
1771 g_free (transport_name_start);
1772 created = modest_account_mgr_add_server_account (self->account_manager,
1774 servername_outgoing,
1775 serverport_outgoing,
1778 protocol_security_outgoing,
1779 protocol_authentication_outgoing);
1781 g_free (servername_outgoing);
1784 /* TODO: Provide a Logical ID for the text: */
1785 show_error (GTK_WIDGET (self), _("An error occurred while creating the outgoing account."));
1786 g_free (display_name);
1791 /* Create the account, which will contain the two "server accounts": */
1792 created = modest_account_mgr_add_account (self->account_manager, account_name,
1793 store_name, /* The name of our POP/IMAP server account. */
1794 transport_name, /* The name of our SMTP server account. */
1796 g_free (store_name);
1797 g_free (transport_name);
1800 /* TODO: Provide a Logical ID for the text: */
1801 show_error (GTK_WIDGET (self), _("An error occurred while creating the account."));
1802 g_free (display_name);
1807 /* There must be at least one account now: */
1808 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1809 * fixed in versions after 3.1. */
1810 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1811 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1813 /* The user name and email address must be set additionally: */
1814 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1815 modest_account_mgr_set_string (self->account_manager, account_name,
1816 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1818 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1819 modest_account_mgr_set_string (self->account_manager, account_name,
1820 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1822 /* Set the display name: */
1823 modest_account_mgr_set_string (self->account_manager, account_name,
1824 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1826 /* Set retrieve type */
1827 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1828 modest_account_mgr_set_string (self->account_manager, account_name,
1829 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1831 /* Save the connection-specific SMTP server accounts. */
1832 modest_account_mgr_set_use_connection_specific_smtp(self->account_manager, account_name,
1833 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self->checkbox_outgoing_smtp_specific)));
1834 gboolean result = TRUE;
1835 if (self->specific_window)
1836 result = modest_connection_specific_smtp_window_save_server_accounts (
1837 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1839 g_free (self->saved_account_name);
1840 self->saved_account_name = g_strdup (account_name);
1842 g_free (account_name);
1843 g_free (display_name);