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;
74 MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED = 0x01,
75 MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED = 0x02
76 } ModestEasysetupWizardDialogServerChanges;
78 struct _ModestEasysetupWizardDialogPrivate
80 ModestPresets *presets;
82 /* Remember what fields the user edited manually to not prefill them
84 ModestEasysetupWizardDialogServerChanges server_changes;
86 /* Check if the user changes a field to show a confirmation dialog */
91 on_easysetup_changed(GtkWidget* widget, ModestEasysetupWizardDialog* wizard)
93 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(wizard);
94 g_return_if_fail (priv != NULL);
99 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
100 GValue *value, GParamSpec *pspec)
102 switch (property_id) {
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
109 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
110 const GValue *value, GParamSpec *pspec)
112 switch (property_id) {
114 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
119 modest_easysetup_wizard_dialog_dispose (GObject *object)
121 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
122 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
126 modest_easysetup_wizard_dialog_finalize (GObject *object)
128 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
129 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
131 if (self->account_manager)
132 g_object_unref (G_OBJECT (self->account_manager));
135 modest_presets_destroy (priv->presets);
137 if (self->specific_window)
138 gtk_widget_destroy (self->specific_window);
140 g_free (self->saved_account_name);
142 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
146 show_error (GtkWidget *parent_widget, const gchar* text);
149 create_account (ModestEasysetupWizardDialog *self, gboolean enabled);
152 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
155 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
157 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
159 static gint get_serverport_incoming(ModestPresetsServerType servertype_incoming,
160 ModestPresetsSecurity security_incoming)
162 int serverport_incoming = 0;
163 /* We don't check for SMTP here as that is impossible for an incoming server. */
164 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
165 serverport_incoming =
166 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 993 : 143;
167 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
168 serverport_incoming =
169 (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING_ALTERNATE_PORT) ? 995 : 110;
171 return serverport_incoming;
174 static GList* check_for_supported_auth_methods(ModestEasysetupWizardDialog* account_wizard)
176 GError *error = NULL;
177 const ModestTransportStoreProtocol protocol =
178 easysetup_servertype_combo_box_get_active_servertype (
179 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
180 const gchar* hostname = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_incomingserver));
181 const gchar* username = gtk_entry_get_text(GTK_ENTRY(account_wizard->entry_user_username));
182 const ModestConnectionProtocol protocol_security_incoming =
183 modest_serversecurity_combo_box_get_active_serversecurity (
184 MODEST_SERVERSECURITY_COMBO_BOX (
185 account_wizard->combo_incoming_security));
186 int port_num = get_serverport_incoming(protocol, protocol_security_incoming);
187 GList *list_auth_methods =
188 modest_maemo_utils_get_supported_secure_authentication_methods (
190 hostname, port_num, username, GTK_WINDOW (account_wizard), &error);
191 if (list_auth_methods) {
192 /* TODO: Select the correct method */
195 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
196 ModestAuthProtocol auth = (ModestAuthProtocol) (GPOINTER_TO_INT(method->data));
197 if (modest_protocol_info_auth_is_secure(auth)) {
198 list = g_list_append(list, GINT_TO_POINTER(auth));
201 g_list_free(list_auth_methods);
206 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
207 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
209 show_error (GTK_WIDGET(account_wizard), _("Could not discover supported secure authentication methods."));
212 if(error != NULL) g_error_free(error);
217 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
219 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
221 /* Call the vfunc, which may be overridden by derived classes: */
222 if (klass->enable_buttons) {
223 GtkNotebook *notebook = NULL;
224 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
226 const gint current_page_num = gtk_notebook_get_current_page (notebook);
227 if (current_page_num == -1)
230 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
231 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
236 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
238 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
240 invoke_enable_buttons_vfunc(self);
244 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
246 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
248 invoke_enable_buttons_vfunc(self);
251 /** This is a convenience function to create a caption containing a mandatory widget.
252 * When the widget is edited, the enable_buttons() vfunc will be called.
254 static GtkWidget* create_caption_new_with_asterisk(ModestEasysetupWizardDialog *self,
259 HildonCaptionStatus flag)
261 GtkWidget *caption = NULL;
263 /* Note: Previously, the translated strings already contained the "*",
264 * Comment out this code if they do again.
266 /* Add a * character to indicate mandatory fields,
267 * as specified in our "Email UI Specification": */
268 if (flag == HILDON_CAPTION_MANDATORY) {
269 gchar* title = g_strdup_printf("%s*", value);
270 caption = hildon_caption_new (group, title, control, icon, flag);
274 caption = hildon_caption_new (group, value, control, icon, flag);
276 /* Connect to the appropriate changed signal for the widget,
277 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
279 if (GTK_IS_ENTRY (control)) {
280 g_signal_connect (G_OBJECT (control), "changed",
281 G_CALLBACK (on_caption_entry_changed), self);
284 else if (GTK_IS_COMBO_BOX (control)) {
285 g_signal_connect (G_OBJECT (control), "changed",
286 G_CALLBACK (on_caption_combobox_changed), self);
293 create_page_welcome (ModestEasysetupWizardDialog *self)
295 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
296 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
297 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
298 /* So that it is not truncated: */
299 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
300 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
301 gtk_widget_show (label);
302 gtk_widget_show (GTK_WIDGET (box));
303 return GTK_WIDGET (box);
307 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
309 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
311 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
315 /* Fill the providers combo, based on the selected country: */
316 GSList *list_mcc_ids = easysetup_country_combo_box_get_active_country_ids (
317 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
318 easysetup_provider_combo_box_fill (
319 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, list_mcc_ids);
323 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
325 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
327 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
331 /* Fill the providers combo, based on the selected country: */
332 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
333 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
335 gchar* domain_name = NULL;
337 domain_name = modest_presets_get_domain (priv->presets, provider_id);
340 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
342 if (self->entry_user_email)
343 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
345 g_free (domain_name);
347 g_free (provider_id);
351 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
353 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
354 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
358 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
360 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
361 /* We could add a special case for whitespace here
362 if (character == NULL) ...
364 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
365 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), character);
366 show_error (GTK_WIDGET (self), message);
370 create_page_account_details (ModestEasysetupWizardDialog *self)
372 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
373 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
374 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
375 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
376 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
377 gtk_widget_show (label);
379 /* Create a size group to be used by all captions.
380 * Note that HildonCaption does not create a default size group if we do not specify one.
381 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
382 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
384 /* The country widgets: */
385 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
386 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
387 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
388 gtk_widget_show (self->combo_account_country);
389 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
390 gtk_widget_show (caption);
392 /* connect to country combo's changed signal, so we can fill the provider combo: */
393 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
394 G_CALLBACK (on_combo_account_country), self);
396 GtkWidget *separator = gtk_hseparator_new ();
397 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
398 gtk_widget_show (separator);
400 /* The service provider widgets: */
401 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
403 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
404 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
405 gtk_widget_show (self->combo_account_serviceprovider);
406 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
407 gtk_widget_show (caption);
409 /* connect to providers combo's changed signal, so we can fill the email address: */
410 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
411 G_CALLBACK (on_combo_account_serviceprovider), self);
413 /* TODO: Default to the current country somehow.
414 * But I don't know how to get the information that is specified in the
415 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
417 * This is probably not the best choice of gconf key:
418 * This is the "mcc used in the last pairing", ie. the last connection you made.
419 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
422 GConfClient *client = gconf_client_get_default ();
423 GError *error = NULL;
424 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
425 gint mcc_id = gconf_client_get_int(client, key, &error);
431 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
432 g_error_free (error);
438 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
439 * This might just be a Maemo bug.
443 /* For now, we default to Finland when there is nothing better: */
447 easysetup_country_combo_box_set_active_country_id (
448 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
451 /* The description widgets: */
452 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
453 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
454 G_CALLBACK(on_easysetup_changed), self);
455 /* Do use auto-capitalization: */
456 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
457 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
459 /* Set a default account title, choosing one that does not already exist: */
460 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
461 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
462 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
463 self->account_manager, default_account_name_start);
464 g_free (default_account_name_start);
465 default_account_name_start = NULL;
467 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
468 g_free (default_account_name);
469 default_account_name = NULL;
471 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
472 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
473 gtk_widget_show (self->entry_account_title);
474 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
475 gtk_widget_show (caption);
477 /* Prevent the use of some characters in the account title,
478 * as required by our UI specification: */
479 GList *list_prevent = NULL;
480 list_prevent = g_list_append (list_prevent, "\\");
481 list_prevent = g_list_append (list_prevent, "/");
482 list_prevent = g_list_append (list_prevent, ":");
483 list_prevent = g_list_append (list_prevent, "*");
484 list_prevent = g_list_append (list_prevent, "?");
485 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
486 list_prevent = g_list_append (list_prevent, "“");
487 list_prevent = g_list_append (list_prevent, "<");
488 list_prevent = g_list_append (list_prevent, ">");
489 list_prevent = g_list_append (list_prevent, "|");
490 list_prevent = g_list_append (list_prevent, "^");
491 modest_validating_entry_set_unallowed_characters (
492 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
493 g_list_free (list_prevent);
495 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
496 on_entry_invalid_character, self);
498 /* Set max length as in the UI spec:
499 * The UI spec seems to want us to show a dialog if we hit the maximum. */
500 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
501 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
504 gtk_widget_show (GTK_WIDGET (box));
506 return GTK_WIDGET (box);
510 create_page_user_details (ModestEasysetupWizardDialog *self)
512 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
514 /* Create a size group to be used by all captions.
515 * Note that HildonCaption does not create a default size group if we do not specify one.
516 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
517 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
519 /* The name widgets: */
520 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
521 /* Auto-capitalization is the default, so let's turn it off: */
522 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
523 /* Set max length as in the UI spec:
524 * The UI spec seems to want us to show a dialog if we hit the maximum. */
525 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
526 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
528 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
529 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
530 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
531 G_CALLBACK(on_easysetup_changed), self);
532 gtk_widget_show (self->entry_user_name);
533 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
534 gtk_widget_show (caption);
536 /* Prevent the use of some characters in the name,
537 * as required by our UI specification: */
538 GList *list_prevent = NULL;
539 list_prevent = g_list_append (list_prevent, "<");
540 list_prevent = g_list_append (list_prevent, ">");
541 modest_validating_entry_set_unallowed_characters (
542 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
543 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
544 on_entry_invalid_character, self);
545 g_list_free (list_prevent);
547 /* The username widgets: */
548 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
549 /* Auto-capitalization is the default, so let's turn it off: */
550 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
551 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
552 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
553 gtk_widget_show (self->entry_user_username);
554 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
555 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
556 G_CALLBACK(on_easysetup_changed), self);
557 gtk_widget_show (caption);
559 /* Prevent the use of some characters in the username,
560 * as required by our UI specification: */
561 modest_validating_entry_set_unallowed_characters_whitespace (
562 MODEST_VALIDATING_ENTRY (self->entry_user_username));
563 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_username),
564 on_entry_invalid_character, self);
566 /* Set max length as in the UI spec:
567 * The UI spec seems to want us to show a dialog if we hit the maximum. */
568 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
569 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
572 /* The password widgets: */
573 self->entry_user_password = gtk_entry_new ();
574 /* Auto-capitalization is the default, so let's turn it off: */
575 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
576 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
577 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
578 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
579 caption = create_caption_new_with_asterisk (self, sizegroup,
580 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
581 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
582 G_CALLBACK(on_easysetup_changed), self);
583 gtk_widget_show (self->entry_user_password);
584 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
585 gtk_widget_show (caption);
587 /* The email address widgets: */
588 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
589 /* Auto-capitalization is the default, so let's turn it off: */
590 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
591 caption = create_caption_new_with_asterisk (self, sizegroup,
592 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
593 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
594 gtk_widget_show (self->entry_user_email);
595 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
596 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
597 G_CALLBACK(on_easysetup_changed), self);
598 gtk_widget_show (caption);
600 /* Set max length as in the UI spec:
601 * The UI spec seems to want us to show a dialog if we hit the maximum. */
602 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
603 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
607 gtk_widget_show (GTK_WIDGET (box));
609 return GTK_WIDGET (box);
612 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
614 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
616 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
617 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
618 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
619 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
620 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
621 gtk_widget_show (label);
623 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
624 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
625 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
627 /* The documentation for gtk_label_set_line_wrap() says that we must
628 * call gtk_widget_set_size_request() with a hard-coded width,
629 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
630 gtk_widget_set_size_request (label, 400, -1);
632 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
633 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
634 gtk_widget_show (label);
636 gtk_widget_show (GTK_WIDGET (box));
637 return GTK_WIDGET (box);
640 /** Change the caption title for the incoming server,
641 * as specified in the UI spec:
643 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
645 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
646 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
648 (protocol == MODEST_PROTOCOL_STORE_POP ?
649 _("mail_fi_emailtype_pop3") :
650 _("mail_fi_emailtype_imap") );
653 /* Note that this produces a compiler warning,
654 * because the compiler does not know that the translated string will have a %s in it.
655 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
656 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
657 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
658 g_free(incomingserver_title);
661 /** Change the caption title for the incoming server,
662 * as specified in the UI spec:
664 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
666 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
667 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
669 /* Fill the combo with appropriately titled choices for POP or IMAP. */
670 /* The choices are the same, but the titles are different, as in the UI spec. */
671 modest_serversecurity_combo_box_fill (
672 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
675 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
677 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
678 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
682 update_incoming_server_title (self);
683 update_incoming_server_security_choices (self);
685 set_default_custom_servernames (self);
688 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
690 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
691 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
693 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
696 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
698 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
700 /* Show note that account type cannot be changed in future: */
701 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
702 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
703 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
704 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
705 gtk_widget_show (label);
707 /* Create a size group to be used by all captions.
708 * Note that HildonCaption does not create a default size group if we do not specify one.
709 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
710 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
712 /* The incoming server widgets: */
713 if (!self->combo_incoming_servertype)
714 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
715 easysetup_servertype_combo_box_set_active_servertype (
716 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
717 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
718 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
719 gtk_widget_show (self->combo_incoming_servertype);
720 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
721 gtk_widget_show (caption);
723 if(!self->entry_incomingserver)
725 self->entry_incomingserver = gtk_entry_new ();
726 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed",
727 G_CALLBACK(on_easysetup_changed), self);
729 /* Auto-capitalization is the default, so let's turn it off: */
730 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
731 set_default_custom_servernames (self);
733 if (self->caption_incoming)
734 gtk_widget_destroy (self->caption_incoming);
736 /* The caption title will be updated in update_incoming_server_title().
737 * so this default text will never be seen: */
738 /* (Note: Changing the title seems pointless. murrayc) */
739 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
740 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
741 update_incoming_server_title (self);
742 gtk_widget_show (self->entry_incomingserver);
743 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
744 gtk_widget_show (self->caption_incoming);
746 /* Change the caption title when the servertype changes,
747 * as in the UI spec: */
748 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
749 G_CALLBACK (on_combo_servertype_changed), self);
751 /* Remember when the servername was changed manually: */
752 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
753 G_CALLBACK (on_entry_incoming_servername_changed), self);
755 /* The secure connection widgets: */
756 if (!self->combo_incoming_security)
757 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
758 update_incoming_server_security_choices (self);
759 modest_serversecurity_combo_box_set_active_serversecurity (
760 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
761 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
762 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
763 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
764 G_CALLBACK (on_easysetup_changed), self);
765 gtk_widget_show (self->combo_incoming_security);
766 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
767 gtk_widget_show (caption);
769 if(!self->checkbox_incoming_auth)
771 self->checkbox_incoming_auth = gtk_check_button_new ();
772 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
773 G_CALLBACK (on_easysetup_changed), self);
775 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
776 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
778 gtk_widget_show (self->checkbox_incoming_auth);
779 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
780 gtk_widget_show (caption);
782 gtk_widget_show (GTK_WIDGET (box));
784 return GTK_WIDGET (box);
788 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
790 GtkWidget *widget = GTK_WIDGET (user_data);
792 /* Enable the widget only if the toggle button is active: */
793 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
794 gtk_widget_set_sensitive (widget, enable);
797 /* Make the sensitivity of a widget depend on a toggle button.
800 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
802 g_signal_connect (G_OBJECT (button), "toggled",
803 G_CALLBACK (on_toggle_button_changed), widget);
805 /* Set the starting sensitivity: */
806 on_toggle_button_changed (button, widget);
810 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
812 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
813 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
815 /* We set dirty here because setting it depending on the connection specific dialog
819 /* Create the window, if necessary: */
820 if (!(self->specific_window)) {
821 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
822 modest_connection_specific_smtp_window_fill_with_connections (
823 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
824 NULL /* account_name, not known yet. */);
827 /* Show the window: */
828 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
829 gtk_widget_show (self->specific_window);
832 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
834 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
835 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
836 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
839 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
841 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
843 /* Create a size group to be used by all captions.
844 * Note that HildonCaption does not create a default size group if we do not specify one.
845 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
846 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
848 /* The outgoing server widgets: */
849 if (!self->entry_outgoingserver)
851 self->entry_outgoingserver = gtk_entry_new ();
852 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
853 G_CALLBACK (on_easysetup_changed), self);
855 /* Auto-capitalization is the default, so let's turn it off: */
856 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
857 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
858 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
859 gtk_widget_show (self->entry_outgoingserver);
860 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
861 gtk_widget_show (caption);
862 set_default_custom_servernames (self);
864 /* The secure connection widgets: */
865 if (!self->combo_outgoing_security)
867 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
868 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
869 G_CALLBACK (on_easysetup_changed), self);
871 modest_serversecurity_combo_box_fill (
872 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
873 modest_serversecurity_combo_box_set_active_serversecurity (
874 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
875 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
876 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
877 gtk_widget_show (self->combo_outgoing_security);
878 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
879 gtk_widget_show (caption);
881 /* The secure authentication widgets: */
882 if (!self->combo_outgoing_auth)
884 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
885 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
886 G_CALLBACK (on_easysetup_changed), self);
888 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
889 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
890 gtk_widget_show (self->combo_outgoing_auth);
891 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
892 gtk_widget_show (caption);
894 GtkWidget *separator = gtk_hseparator_new ();
895 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
896 gtk_widget_show (separator);
898 /* connection-specific checkbox: */
899 if (!self->checkbox_outgoing_smtp_specific) {
900 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
901 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
903 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
904 G_CALLBACK (on_easysetup_changed), self);
907 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
908 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
909 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
910 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
911 gtk_widget_show (caption);
913 /* Connection-specific SMTP-Severs Edit button: */
914 if (!self->button_outgoing_smtp_servers)
915 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
916 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
917 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
918 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
919 gtk_widget_show (self->button_outgoing_smtp_servers);
920 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
921 gtk_widget_show (caption);
923 /* Only enable the button when the checkbox is checked: */
924 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
925 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
927 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
928 G_CALLBACK (on_button_outgoing_smtp_servers), self);
930 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
931 G_CALLBACK (on_entry_outgoing_servername_changed), self);
934 gtk_widget_show (GTK_WIDGET (box));
936 return GTK_WIDGET (box);
940 show_advanced_edit(gpointer user_data)
942 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
944 if (!(self->saved_account_name))
947 /* Show the Account Settings window: */
948 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
949 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
951 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
953 gtk_dialog_run (GTK_DIALOG (dialog));
955 gtk_widget_destroy (GTK_WIDGET (dialog));
957 return FALSE; /* Do not call this timeout callback again. */
961 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
963 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
965 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
966 * without recoding it to use non-gconf information.
967 * This account will be deleted if Finish is never actually clicked. */
969 gboolean saved = TRUE;
970 if (!(self->saved_account_name)) {
971 saved = create_account (self, FALSE);
977 if (!(self->saved_account_name))
980 /* Show the Account Settings window: */
981 show_advanced_edit(self);
983 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
985 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
986 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
987 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
988 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
989 gtk_widget_show (label);
991 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
992 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
993 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
994 gtk_widget_show (label);
996 if (!self->button_edit)
997 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
998 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
999 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
1000 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
1001 gtk_widget_show (self->button_edit);
1002 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1003 gtk_widget_show (caption);
1005 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
1006 G_CALLBACK (on_button_edit_advanced_settings), self);
1008 gtk_widget_show (GTK_WIDGET (box));
1009 return GTK_WIDGET (box);
1016 on_response (ModestWizardDialog *wizard_dialog,
1020 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1021 if (response_id == GTK_RESPONSE_CANCEL) {
1022 /* Remove any temporarily-saved account that will not actually be needed: */
1023 if (self->saved_account_name) {
1024 modest_account_mgr_remove_account (self->account_manager,
1025 self->saved_account_name, FALSE);
1029 invoke_enable_buttons_vfunc (self);
1033 on_response_before (ModestWizardDialog *wizard_dialog,
1037 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1038 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1039 if (response_id == GTK_RESPONSE_CANCEL) {
1040 /* This is mostly copied from
1041 * src/maemo/modest-account-settings-dialog.c */
1044 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1045 _("imum_nc_wizard_confirm_lose_changes")));
1046 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1048 const gint dialog_response = gtk_dialog_run (dialog);
1049 gtk_widget_destroy (GTK_WIDGET (dialog));
1051 if (dialog_response != GTK_RESPONSE_OK)
1053 /* This is a nasty hack. murrayc. */
1054 /* Don't let the dialog close */
1055 g_signal_stop_emission_by_name (wizard_dialog, "response");
1062 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1064 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1066 /* Create the notebook to be used by the ModestWizardDialog base class:
1067 * Each page of the notebook will be a page of the wizard: */
1068 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1070 /* Set the notebook used by the ModestWizardDialog base class: */
1071 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1073 /* Set the wizard title:
1074 * The actual window title will be a combination of this and the page's tab label title. */
1075 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1077 /* Read in the information about known service providers: */
1078 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1080 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
1081 priv->presets = modest_presets_new (filepath);
1082 if (!(priv->presets)) {
1083 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
1086 g_assert(priv->presets);
1088 /* The server fields did not have been manually changed yet */
1089 priv->server_changes = 0;
1091 /* Get the account manager object,
1092 * so we can check for existing accounts,
1093 * and create new accounts: */
1094 self->account_manager = modest_runtime_get_account_mgr ();
1095 g_assert (self->account_manager);
1096 g_object_ref (self->account_manager);
1098 /* Create the common pages,
1100 self->page_welcome = create_page_welcome (self);
1101 self->page_account_details = create_page_account_details (self);
1102 self->page_user_details = create_page_user_details (self);
1104 /* Add the common pages: */
1105 gtk_notebook_append_page (notebook, self->page_welcome,
1106 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1107 gtk_notebook_append_page (notebook, self->page_account_details,
1108 gtk_label_new (_("mcen_ti_accountdetails")));
1109 gtk_notebook_append_page (notebook, self->page_user_details,
1110 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1112 /* Create and add the easysetup-specific pages,
1113 * because we need _some_ final page to enable the Next and Finish buttons: */
1114 create_subsequent_easysetup_pages (self);
1116 /* Connect to the dialog's response signal so we can enable/disable buttons
1117 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1118 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1119 * so that we can be enable/disable after ModestWizardDialog has done its own
1120 * enabling/disabling of buttons.
1122 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1123 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1125 * It's not enough to connect to the notebook's switch-page signal, because
1126 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1127 * _after_ switching the page (understandably).
1128 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1129 * then gtk_notebook_get_current_page() would return an incorrect value.)
1131 g_signal_connect_after (G_OBJECT (self), "response",
1132 G_CALLBACK (on_response), self);
1134 /* This is to show a confirmation dialog when the user hits cancel */
1135 g_signal_connect (G_OBJECT (self), "response",
1136 G_CALLBACK (on_response_before), self);
1138 /* Reset dirty, because there was no user input until now */
1139 priv->dirty = FALSE;
1141 /* When this window is shown, hibernation should not be possible,
1142 * because there is no sensible way to save the state: */
1143 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1144 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1147 ModestEasysetupWizardDialog*
1148 modest_easysetup_wizard_dialog_new (void)
1150 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1153 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1155 GtkNotebook *notebook = NULL;
1156 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1159 /* Create the custom pages: */
1160 if(!(self->page_custom_incoming)) {
1161 self->page_custom_incoming = create_page_custom_incoming (self);
1164 if(!(self->page_custom_outgoing)) {
1165 self->page_custom_outgoing = create_page_custom_outgoing (self);
1168 if(!(self->page_complete_customsetup)) {
1169 self->page_complete_customsetup = create_page_complete_custom (self);
1172 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1173 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1174 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1176 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1177 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1178 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1180 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1181 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1182 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1184 /* This is unnecessary with GTK+ 2.10: */
1185 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1188 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1190 GtkNotebook *notebook = NULL;
1191 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1194 /* Create the easysetup-specific pages: */
1195 if(!self->page_complete_easysetup)
1196 self->page_complete_easysetup = create_page_complete_easysetup (self);
1198 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1199 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1200 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1202 /* This is unnecessary with GTK+ 2.10: */
1203 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1205 /* After the user details page,
1206 * the following pages depend on whether "Other" was chosen
1207 * in the provider combobox on the account page
1209 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1211 if (easysetup_provider_combo_box_get_active_provider_id (
1212 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1213 /* "Other..." was selected: */
1215 /* Make sure that the easysetup pages do not exist: */
1216 if(self->page_complete_easysetup) {
1217 gtk_widget_destroy (self->page_complete_easysetup);
1218 self->page_complete_easysetup = NULL;
1221 create_subsequent_customsetup_pages (self);
1224 /* A specific provider was selected: */
1226 /* Make sure that the custom pages do not exist:
1227 * Because they will be used if they exist, when creating the account. */
1228 if(self->page_custom_incoming) {
1229 gtk_widget_destroy (self->page_custom_incoming);
1230 self->page_custom_incoming = NULL;
1233 if(self->page_custom_outgoing) {
1234 gtk_widget_destroy (self->page_custom_outgoing);
1235 self->page_custom_outgoing = NULL;
1238 if(self->page_complete_customsetup) {
1239 gtk_widget_destroy (self->page_complete_customsetup);
1240 self->page_complete_customsetup = NULL;
1244 /* Create the easysetup pages: */
1245 create_subsequent_easysetup_pages (self);
1251 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1256 gchar* at = g_utf8_strchr (email_address, -1, '@');
1257 if (!at || (g_utf8_strlen (at, -1) < 2))
1260 gchar* domain = g_utf8_next_char (at);
1264 const gchar* hostname = NULL;
1265 if (servertype == MODEST_PROTOCOL_STORE_POP)
1267 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1269 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1275 return g_strdup_printf ("%s.%s", hostname, domain);
1278 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1280 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1282 if (!account_wizard->entry_incomingserver)
1285 /* Set a default domain for the server, based on the email address,
1286 * if no server name was already specified.
1288 if (account_wizard->entry_user_email
1289 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1290 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1291 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1292 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1294 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1296 /* Do not set the INCOMING_CHANGED flag because of this edit */
1297 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1298 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1299 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1301 g_free (servername);
1304 /* Set a default domain for the server, based on the email address,
1305 * if no server name was already specified.
1307 if (!account_wizard->entry_outgoingserver)
1310 if (account_wizard->entry_user_email
1311 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1312 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1314 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1316 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1317 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1318 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1319 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1321 g_free (servername);
1326 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1328 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1330 /* Do extra validation that couldn't be done for every key press,
1331 * either because it was too slow,
1332 * or because it requires interaction:
1334 if (current_page == account_wizard->page_account_details) {
1335 /* Check that the title is not already in use: */
1336 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1337 if ((!account_title) || (strlen(account_title) == 0))
1340 /* Aavoid a clash with an existing display name: */
1341 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1342 account_wizard->account_manager, account_title);
1345 /* Warn the user via a dialog: */
1346 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1351 else if (current_page == account_wizard->page_user_details) {
1352 /* Check that the email address is valud: */
1353 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1354 if ((!email_address) || (strlen(email_address) == 0))
1357 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1358 /* Warn the user via a dialog: */
1359 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1361 /* Return focus to the email address entry: */
1362 gtk_widget_grab_focus (account_wizard->entry_user_email);
1363 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1368 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1369 create_subsequent_pages (account_wizard);
1372 /* TODO: The UI Spec wants us to check that the servernames are valid,
1373 * but does not specify how.
1376 if(next_page == account_wizard->page_custom_incoming) {
1377 set_default_custom_servernames (account_wizard);
1379 else if (next_page == account_wizard->page_custom_outgoing) {
1380 set_default_custom_servernames (account_wizard);
1381 /* Check if the server supports secure authentication */
1382 const ModestConnectionProtocol security_incoming =
1383 modest_serversecurity_combo_box_get_active_serversecurity (
1384 MODEST_SERVERSECURITY_COMBO_BOX (
1385 account_wizard->combo_incoming_security));
1386 if (gtk_toggle_button_get_active (
1387 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1388 && !modest_protocol_info_is_secure(security_incoming))
1390 GList* methods = check_for_supported_auth_methods(account_wizard);
1393 g_list_free(methods);
1396 g_list_free(methods);
1400 /* If this is the last page, and this is a click on Finish,
1401 * then attempt to create the dialog.
1403 if(!next_page) /* This is NULL when this is a click on Finish. */
1405 if (account_wizard->saved_account_name) {
1406 /* Just enable the already-saved account (temporarily created when
1407 * editing advanced settings): */
1408 modest_account_mgr_set_enabled (account_wizard->account_manager,
1409 account_wizard->saved_account_name, TRUE);
1411 create_account (account_wizard, TRUE /* enabled */);
1419 static gboolean entry_is_empty (GtkWidget *entry)
1424 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1425 if ((!text) || (strlen(text) == 0))
1432 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1434 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1436 gboolean enable_next = TRUE;
1437 if (current_page == account_wizard->page_welcome) {
1440 else if (current_page == account_wizard->page_account_details) {
1441 /* The account details title is mandatory: */
1442 if (entry_is_empty(account_wizard->entry_account_title))
1443 enable_next = FALSE;
1445 else if (current_page == account_wizard->page_user_details) {
1446 /* The user details username is mandatory: */
1447 if (entry_is_empty(account_wizard->entry_user_username))
1448 enable_next = FALSE;
1450 /* The user details email address is mandatory: */
1451 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1452 enable_next = FALSE;
1454 else if (current_page == account_wizard->page_custom_incoming) {
1455 /* The custom incoming server is mandatory: */
1456 if (entry_is_empty(account_wizard->entry_incomingserver))
1457 enable_next = FALSE;
1460 /* Enable the buttons,
1461 * identifying them via their associated response codes: */
1463 /* Disable the Finish button until we are on the last page,
1464 * because HildonWizardDialog enables this for all but the first page: */
1465 GtkNotebook *notebook = NULL;
1466 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1467 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1469 gint current = gtk_notebook_get_current_page (notebook);
1470 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1471 const gboolean is_last = (current == last);
1474 gtk_dialog_set_response_sensitive (dialog_base,
1475 MODEST_WIZARD_DIALOG_FINISH,
1479 /* Disable Next on the last page: */
1480 enable_next = FALSE;
1483 gtk_dialog_set_response_sensitive (dialog_base,
1484 MODEST_WIZARD_DIALOG_NEXT,
1489 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1491 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1492 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1495 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1496 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1497 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1498 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1500 /* Provide a vfunc implementation so we can decide
1501 * when to enable/disable the prev/next buttons.
1503 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1504 base_klass->before_next = on_before_next;
1505 base_klass->enable_buttons = on_enable_buttons;
1509 show_error (GtkWidget *parent_widget, const gchar* text)
1511 hildon_banner_show_information(parent_widget, NULL, text);
1514 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
1516 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1523 gtk_dialog_run (dialog);
1524 gtk_widget_destroy (GTK_WIDGET (dialog));
1528 /** Attempt to create the account from the information that the user has entered.
1529 * @result: TRUE if the account was successfully created.
1532 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1534 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1536 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1542 /* We should have checked for this already,
1543 * and changed that name accordingly,
1544 * but let's check again just in case:
1546 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1549 /* Increment the non-user visible name if necessary,
1550 * based on the display name: */
1551 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1552 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1553 account_name_start, FALSE /* not a server account */);
1554 g_free (account_name_start);
1556 /* username and password (for both incoming and outgoing): */
1557 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1558 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1559 /* Incoming server: */
1560 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1561 * or modest_account_mgr_add_server_account will fail. */
1562 gchar* servername_incoming = NULL;
1563 guint serverport_incoming = 0;
1564 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1565 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1566 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1568 /* Get details from the specified presets: */
1569 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1570 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1573 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1574 TRUE /* incoming */);
1576 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1578 TRUE /* incoming */);
1579 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1581 TRUE /* incoming */);
1583 g_warning ("security incoming: %x", security_incoming);
1585 /* We don't check for SMTP here as that is impossible for an incoming server. */
1586 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1587 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1588 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1589 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1591 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1593 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1594 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1596 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1597 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1600 /* Use custom pages because no preset was specified: */
1601 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1603 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1604 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1606 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1607 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1609 /* The UI spec says:
1610 * If secure authentication is unchecked, allow sending username and password also as plain text.
1611 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1614 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1615 !modest_protocol_info_is_secure(protocol_security_incoming))
1617 GList* methods = check_for_supported_auth_methods(self);
1621 protocol_authentication_incoming = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
1624 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1627 /* First we add the 2 server accounts, and then we add the account that uses them.
1628 * If we don't do it in this order then we will experience a crash. */
1630 /* Add a (incoming) server account, to be used by the account: */
1631 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1632 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1633 store_name_start, TRUE /* server account */);
1634 g_free (store_name_start);
1635 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1637 servername_incoming,
1638 serverport_incoming,
1641 protocol_security_incoming,
1642 protocol_authentication_incoming);
1644 g_free (servername_incoming);
1647 /* TODO: Provide a Logical ID for the text: */
1648 show_error (GTK_WIDGET (self), _("An error occurred while creating the incoming account."));
1652 /* Outgoing server: */
1653 gchar* servername_outgoing = NULL;
1654 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1655 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1656 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1657 guint serverport_outgoing = 0;
1661 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1662 FALSE /* incoming */);
1664 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1666 FALSE /* incoming */);
1668 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1669 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1670 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1671 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1673 ModestPresetsSecurity security_outgoing =
1674 modest_presets_get_info_server_security (priv->presets, provider_id,
1675 FALSE /* incoming */);
1677 /* TODO: There is no SMTP authentication enum for presets,
1678 so we should probably check what the server supports. */
1679 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1680 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1681 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1682 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1683 serverport_outgoing = 465;
1684 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1686 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1687 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1691 /* Use custom pages because no preset was specified: */
1692 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1694 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1696 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1697 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1699 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1700 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1703 /* Add a (outgoing) server account to be used by the account: */
1704 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1705 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1706 transport_name_start, TRUE /* server account */);
1707 g_free (transport_name_start);
1708 created = modest_account_mgr_add_server_account (self->account_manager,
1710 servername_outgoing,
1711 serverport_outgoing,
1714 protocol_security_outgoing,
1715 protocol_authentication_outgoing);
1717 g_free (servername_outgoing);
1720 /* TODO: Provide a Logical ID for the text: */
1721 show_error (GTK_WIDGET (self), _("An error occurred while creating the outgoing account."));
1726 /* Create the account, which will contain the two "server accounts": */
1727 created = modest_account_mgr_add_account (self->account_manager, account_name,
1728 store_name, /* The name of our POP/IMAP server account. */
1729 transport_name, /* The name of our SMTP server account. */
1731 g_free (store_name);
1732 g_free (transport_name);
1735 /* TODO: Provide a Logical ID for the text: */
1736 show_error (GTK_WIDGET (self), _("An error occurred while creating the account."));
1741 /* There must be at least one account now: */
1742 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1743 * fixed in versions after 3.1. */
1744 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1745 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1747 /* The user name and email address must be set additionally: */
1748 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1749 modest_account_mgr_set_string (self->account_manager, account_name,
1750 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1752 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1753 modest_account_mgr_set_string (self->account_manager, account_name,
1754 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1756 /* Set the display name: */
1757 modest_account_mgr_set_string (self->account_manager, account_name,
1758 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1760 /* Set retrieve type */
1761 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1762 modest_account_mgr_set_string (self->account_manager, account_name,
1763 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1765 /* Save the connection-specific SMTP server accounts. */
1766 gboolean result = TRUE;
1767 if (self->specific_window)
1768 result = modest_connection_specific_smtp_window_save_server_accounts (
1769 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1771 g_free (self->saved_account_name);
1772 self->saved_account_name = g_strdup (account_name);
1774 g_free (account_name);