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 show_error (GTK_WIDGET (self), _CS("ckdg_ib_illegal_characters_entered"));
368 create_page_account_details (ModestEasysetupWizardDialog *self)
370 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
371 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
372 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
373 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
374 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
375 gtk_widget_show (label);
377 /* Create a size group to be used by all captions.
378 * Note that HildonCaption does not create a default size group if we do not specify one.
379 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
380 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
382 /* The country widgets: */
383 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
384 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_country"),
385 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
386 gtk_widget_show (self->combo_account_country);
387 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
388 gtk_widget_show (caption);
390 /* connect to country combo's changed signal, so we can fill the provider combo: */
391 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
392 G_CALLBACK (on_combo_account_country), self);
394 GtkWidget *separator = gtk_hseparator_new ();
395 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
396 gtk_widget_show (separator);
398 /* The service provider widgets: */
399 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
401 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_serviceprovider"),
402 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
403 gtk_widget_show (self->combo_account_serviceprovider);
404 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
405 gtk_widget_show (caption);
407 /* connect to providers combo's changed signal, so we can fill the email address: */
408 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
409 G_CALLBACK (on_combo_account_serviceprovider), self);
411 /* TODO: Default to the current country somehow.
412 * But I don't know how to get the information that is specified in the
413 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
415 * This is probably not the best choice of gconf key:
416 * This is the "mcc used in the last pairing", ie. the last connection you made.
417 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
420 GConfClient *client = gconf_client_get_default ();
421 GError *error = NULL;
422 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
423 gint mcc_id = gconf_client_get_int(client, key, &error);
429 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
430 g_error_free (error);
436 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
437 * This might just be a Maemo bug.
441 /* For now, we default to Finland when there is nothing better: */
445 easysetup_country_combo_box_set_active_country_id (
446 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
449 /* The description widgets: */
450 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
451 g_signal_connect(G_OBJECT(self->entry_account_title), "changed",
452 G_CALLBACK(on_easysetup_changed), self);
453 /* Do use auto-capitalization: */
454 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
455 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
457 /* Set a default account title, choosing one that does not already exist: */
458 /* Note that this is irrelevant to the non-user visible name, which we will create later. */
459 gchar* default_account_name_start = g_strdup (_("mcen_ia_emailsetup_defaultname"));
460 gchar* default_account_name = modest_account_mgr_get_unused_account_display_name (
461 self->account_manager, default_account_name_start);
462 g_free (default_account_name_start);
463 default_account_name_start = NULL;
465 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_account_name);
466 g_free (default_account_name);
467 default_account_name = NULL;
469 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
470 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
471 gtk_widget_show (self->entry_account_title);
472 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
473 gtk_widget_show (caption);
475 /* Prevent the use of some characters in the account title,
476 * as required by our UI specification: */
477 GList *list_prevent = NULL;
478 list_prevent = g_list_append (list_prevent, "\\");
479 list_prevent = g_list_append (list_prevent, "/");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
484 list_prevent = g_list_append (list_prevent, "“");
485 list_prevent = g_list_append (list_prevent, "<");
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 modest_validating_entry_set_unallowed_characters (
490 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
491 g_list_free (list_prevent);
492 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
493 on_entry_invalid_character, self);
495 /* Set max length as in the UI spec:
496 * The UI spec seems to want us to show a dialog if we hit the maximum. */
497 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
498 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
501 gtk_widget_show (GTK_WIDGET (box));
503 return GTK_WIDGET (box);
507 create_page_user_details (ModestEasysetupWizardDialog *self)
509 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
511 /* Create a size group to be used by all captions.
512 * Note that HildonCaption does not create a default size group if we do not specify one.
513 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
514 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
516 /* The name widgets: */
517 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
518 /* Auto-capitalization is the default, so let's turn it off: */
519 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
520 /* Set max length as in the UI spec:
521 * The UI spec seems to want us to show a dialog if we hit the maximum. */
522 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
523 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
525 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
526 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
527 g_signal_connect(G_OBJECT(self->entry_user_name), "changed",
528 G_CALLBACK(on_easysetup_changed), self);
529 gtk_widget_show (self->entry_user_name);
530 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
531 gtk_widget_show (caption);
533 /* Prevent the use of some characters in the name,
534 * as required by our UI specification: */
535 GList *list_prevent = NULL;
536 list_prevent = g_list_append (list_prevent, "<");
537 list_prevent = g_list_append (list_prevent, ">");
538 modest_validating_entry_set_unallowed_characters (
539 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
540 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
541 on_entry_invalid_character, self);
542 g_list_free (list_prevent);
544 /* The username widgets: */
545 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
546 /* Auto-capitalization is the default, so let's turn it off: */
547 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
548 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
549 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
550 gtk_widget_show (self->entry_user_username);
551 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
552 g_signal_connect(G_OBJECT(self->entry_user_username), "changed",
553 G_CALLBACK(on_easysetup_changed), self);
554 gtk_widget_show (caption);
556 /* Prevent the use of some characters in the username,
557 * as required by our UI specification: */
558 modest_validating_entry_set_unallowed_characters_whitespace (
559 MODEST_VALIDATING_ENTRY (self->entry_user_username));
560 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
561 on_entry_invalid_character, self);
563 /* Set max length as in the UI spec:
564 * The UI spec seems to want us to show a dialog if we hit the maximum. */
565 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
566 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
569 /* The password widgets: */
570 self->entry_user_password = gtk_entry_new ();
571 /* Auto-capitalization is the default, so let's turn it off: */
572 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
573 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
574 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
575 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
576 caption = create_caption_new_with_asterisk (self, sizegroup,
577 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
578 g_signal_connect(G_OBJECT(self->entry_user_password), "changed",
579 G_CALLBACK(on_easysetup_changed), self);
580 gtk_widget_show (self->entry_user_password);
581 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
582 gtk_widget_show (caption);
584 /* The email address widgets: */
585 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
586 /* Auto-capitalization is the default, so let's turn it off: */
587 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
588 caption = create_caption_new_with_asterisk (self, sizegroup,
589 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
590 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
591 gtk_widget_show (self->entry_user_email);
592 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
593 g_signal_connect(G_OBJECT(self->entry_user_email), "changed",
594 G_CALLBACK(on_easysetup_changed), self);
595 gtk_widget_show (caption);
597 /* Set max length as in the UI spec:
598 * The UI spec seems to want us to show a dialog if we hit the maximum. */
599 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
600 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
604 gtk_widget_show (GTK_WIDGET (box));
606 return GTK_WIDGET (box);
609 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
611 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
613 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
614 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
615 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
616 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
617 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
618 gtk_widget_show (label);
620 label = gtk_label_new (_("mcen_ia_easysetup_complete"));
621 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
622 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
624 /* The documentation for gtk_label_set_line_wrap() says that we must
625 * call gtk_widget_set_size_request() with a hard-coded width,
626 * though I wonder why gtk_label_set_max_width_chars() isn't enough. */
627 gtk_widget_set_size_request (label, 400, -1);
629 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
630 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
631 gtk_widget_show (label);
633 gtk_widget_show (GTK_WIDGET (box));
634 return GTK_WIDGET (box);
637 /** Change the caption title for the incoming server,
638 * as specified in the UI spec:
640 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
642 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
643 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
645 (protocol == MODEST_PROTOCOL_STORE_POP ?
646 _("mail_fi_emailtype_pop3") :
647 _("mail_fi_emailtype_imap") );
650 /* Note that this produces a compiler warning,
651 * because the compiler does not know that the translated string will have a %s in it.
652 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
653 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
654 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
655 g_free(incomingserver_title);
658 /** Change the caption title for the incoming server,
659 * as specified in the UI spec:
661 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
663 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
664 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
666 /* Fill the combo with appropriately titled choices for POP or IMAP. */
667 /* The choices are the same, but the titles are different, as in the UI spec. */
668 modest_serversecurity_combo_box_fill (
669 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
672 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
674 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
675 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(self);
679 update_incoming_server_title (self);
680 update_incoming_server_security_choices (self);
682 set_default_custom_servernames (self);
685 static void on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
687 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
688 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
690 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED;
693 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
695 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
697 /* Show note that account type cannot be changed in future: */
698 GtkWidget *label = gtk_label_new (_("mcen_ia_emailsetup_account_type"));
699 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
700 gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
701 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
702 gtk_widget_show (label);
704 /* Create a size group to be used by all captions.
705 * Note that HildonCaption does not create a default size group if we do not specify one.
706 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
707 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
709 /* The incoming server widgets: */
710 if (!self->combo_incoming_servertype)
711 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
712 easysetup_servertype_combo_box_set_active_servertype (
713 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
714 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
715 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
716 gtk_widget_show (self->combo_incoming_servertype);
717 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
718 gtk_widget_show (caption);
720 if(!self->entry_incomingserver)
722 self->entry_incomingserver = gtk_entry_new ();
723 g_signal_connect(G_OBJECT(self->entry_incomingserver), "changed",
724 G_CALLBACK(on_easysetup_changed), self);
726 /* Auto-capitalization is the default, so let's turn it off: */
727 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
728 set_default_custom_servernames (self);
730 if (self->caption_incoming)
731 gtk_widget_destroy (self->caption_incoming);
733 /* The caption title will be updated in update_incoming_server_title().
734 * so this default text will never be seen: */
735 /* (Note: Changing the title seems pointless. murrayc) */
736 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
737 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
738 update_incoming_server_title (self);
739 gtk_widget_show (self->entry_incomingserver);
740 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
741 gtk_widget_show (self->caption_incoming);
743 /* Change the caption title when the servertype changes,
744 * as in the UI spec: */
745 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
746 G_CALLBACK (on_combo_servertype_changed), self);
748 /* Remember when the servername was changed manually: */
749 g_signal_connect (G_OBJECT (self->entry_incomingserver), "changed",
750 G_CALLBACK (on_entry_incoming_servername_changed), self);
752 /* The secure connection widgets: */
753 if (!self->combo_incoming_security)
754 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
755 update_incoming_server_security_choices (self);
756 modest_serversecurity_combo_box_set_active_serversecurity (
757 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
758 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
759 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
760 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed",
761 G_CALLBACK (on_easysetup_changed), self);
762 gtk_widget_show (self->combo_incoming_security);
763 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
764 gtk_widget_show (caption);
766 if(!self->checkbox_incoming_auth)
768 self->checkbox_incoming_auth = gtk_check_button_new ();
769 g_signal_connect (G_OBJECT (self->checkbox_incoming_auth), "toggled",
770 G_CALLBACK (on_easysetup_changed), self);
772 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
773 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
775 gtk_widget_show (self->checkbox_incoming_auth);
776 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
777 gtk_widget_show (caption);
779 gtk_widget_show (GTK_WIDGET (box));
781 return GTK_WIDGET (box);
785 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
787 GtkWidget *widget = GTK_WIDGET (user_data);
789 /* Enable the widget only if the toggle button is active: */
790 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
791 gtk_widget_set_sensitive (widget, enable);
794 /* Make the sensitivity of a widget depend on a toggle button.
797 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
799 g_signal_connect (G_OBJECT (button), "toggled",
800 G_CALLBACK (on_toggle_button_changed), widget);
802 /* Set the starting sensitivity: */
803 on_toggle_button_changed (button, widget);
807 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
809 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
810 ModestEasysetupWizardDialogPrivate* priv = WIZARD_DIALOG_GET_PRIVATE(self);
812 /* We set dirty here because setting it depending on the connection specific dialog
816 /* Create the window, if necessary: */
817 if (!(self->specific_window)) {
818 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
819 modest_connection_specific_smtp_window_fill_with_connections (
820 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
821 NULL /* account_name, not known yet. */);
824 /* Show the window: */
825 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
826 gtk_widget_show (self->specific_window);
829 static void on_entry_outgoing_servername_changed (GtkEntry *entry, gpointer user_data)
831 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
832 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
833 priv->server_changes |= MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED;
836 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
838 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
840 /* Create a size group to be used by all captions.
841 * Note that HildonCaption does not create a default size group if we do not specify one.
842 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
843 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
845 /* The outgoing server widgets: */
846 if (!self->entry_outgoingserver)
848 self->entry_outgoingserver = gtk_entry_new ();
849 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
850 G_CALLBACK (on_easysetup_changed), self);
852 /* Auto-capitalization is the default, so let's turn it off: */
853 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
854 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
855 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
856 gtk_widget_show (self->entry_outgoingserver);
857 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
858 gtk_widget_show (caption);
859 set_default_custom_servernames (self);
861 /* The secure connection widgets: */
862 if (!self->combo_outgoing_security)
864 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
865 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed",
866 G_CALLBACK (on_easysetup_changed), self);
868 modest_serversecurity_combo_box_fill (
869 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
870 modest_serversecurity_combo_box_set_active_serversecurity (
871 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
872 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
873 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
874 gtk_widget_show (self->combo_outgoing_security);
875 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
876 gtk_widget_show (caption);
878 /* The secure authentication widgets: */
879 if (!self->combo_outgoing_auth)
881 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
882 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed",
883 G_CALLBACK (on_easysetup_changed), self);
885 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
886 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
887 gtk_widget_show (self->combo_outgoing_auth);
888 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
889 gtk_widget_show (caption);
891 GtkWidget *separator = gtk_hseparator_new ();
892 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
893 gtk_widget_show (separator);
895 /* connection-specific checkbox: */
896 if (!self->checkbox_outgoing_smtp_specific) {
897 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
898 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
900 g_signal_connect (G_OBJECT (self->checkbox_outgoing_smtp_specific), "toggled",
901 G_CALLBACK (on_easysetup_changed), self);
904 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
905 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
906 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
907 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
908 gtk_widget_show (caption);
910 /* Connection-specific SMTP-Severs Edit button: */
911 if (!self->button_outgoing_smtp_servers)
912 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
913 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
914 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
915 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
916 gtk_widget_show (self->button_outgoing_smtp_servers);
917 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
918 gtk_widget_show (caption);
920 /* Only enable the button when the checkbox is checked: */
921 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
922 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
924 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
925 G_CALLBACK (on_button_outgoing_smtp_servers), self);
927 g_signal_connect (G_OBJECT (self->entry_outgoingserver), "changed",
928 G_CALLBACK (on_entry_outgoing_servername_changed), self);
931 gtk_widget_show (GTK_WIDGET (box));
933 return GTK_WIDGET (box);
937 show_advanced_edit(gpointer user_data)
939 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
941 if (!(self->saved_account_name))
944 /* Show the Account Settings window: */
945 ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
946 modest_account_settings_dialog_set_account_name (dialog, self->saved_account_name);
948 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
950 gtk_dialog_run (GTK_DIALOG (dialog));
952 gtk_widget_destroy (GTK_WIDGET (dialog));
954 return FALSE; /* Do not call this timeout callback again. */
958 on_button_edit_advanced_settings (GtkButton *button, gpointer user_data)
960 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
962 /* Save the new account, so we can edit it with ModestAccountSettingsDialog,
963 * without recoding it to use non-gconf information.
964 * This account will be deleted if Finish is never actually clicked. */
966 gboolean saved = TRUE;
967 if (!(self->saved_account_name)) {
968 saved = create_account (self, FALSE);
974 if (!(self->saved_account_name))
977 /* Show the Account Settings window: */
978 show_advanced_edit(self);
980 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
982 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
983 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
984 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
985 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
986 gtk_widget_show (label);
988 label = gtk_label_new (_("mcen_ia_customsetup_complete"));
989 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
990 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
991 gtk_widget_show (label);
993 if (!self->button_edit)
994 self->button_edit = gtk_button_new_with_label (_("mcen_bd_edit"));
995 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
996 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
997 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
998 gtk_widget_show (self->button_edit);
999 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
1000 gtk_widget_show (caption);
1002 g_signal_connect (G_OBJECT (self->button_edit), "clicked",
1003 G_CALLBACK (on_button_edit_advanced_settings), self);
1005 gtk_widget_show (GTK_WIDGET (box));
1006 return GTK_WIDGET (box);
1013 on_response (ModestWizardDialog *wizard_dialog,
1017 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1018 if (response_id == GTK_RESPONSE_CANCEL) {
1019 /* Remove any temporarily-saved account that will not actually be needed: */
1020 if (self->saved_account_name) {
1021 modest_account_mgr_remove_account (self->account_manager,
1022 self->saved_account_name, FALSE);
1026 invoke_enable_buttons_vfunc (self);
1030 on_response_before (ModestWizardDialog *wizard_dialog,
1034 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
1035 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(wizard_dialog);
1036 if (response_id == GTK_RESPONSE_CANCEL) {
1037 /* This is mostly copied from
1038 * src/maemo/modest-account-settings-dialog.c */
1041 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1042 _("imum_nc_wizard_confirm_lose_changes")));
1043 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1045 const gint dialog_response = gtk_dialog_run (dialog);
1046 gtk_widget_destroy (GTK_WIDGET (dialog));
1048 if (dialog_response != GTK_RESPONSE_OK)
1050 /* This is a nasty hack. murrayc. */
1051 /* Don't let the dialog close */
1052 g_signal_stop_emission_by_name (wizard_dialog, "response");
1059 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
1061 gtk_container_set_border_width (GTK_CONTAINER (self), MODEST_MARGIN_HALF);
1063 /* Create the notebook to be used by the ModestWizardDialog base class:
1064 * Each page of the notebook will be a page of the wizard: */
1065 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
1067 /* Set the notebook used by the ModestWizardDialog base class: */
1068 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
1070 /* Set the wizard title:
1071 * The actual window title will be a combination of this and the page's tab label title. */
1072 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
1074 /* Read in the information about known service providers: */
1075 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1077 const gchar* filepath = MODEST_PROVIDERS_DATA_PATH; /* Defined in config.h */
1078 priv->presets = modest_presets_new (filepath);
1079 if (!(priv->presets)) {
1080 g_warning ("Could not locate the official provider data keyfile from %s", filepath);
1083 g_assert(priv->presets);
1085 /* The server fields did not have been manually changed yet */
1086 priv->server_changes = 0;
1088 /* Get the account manager object,
1089 * so we can check for existing accounts,
1090 * and create new accounts: */
1091 self->account_manager = modest_runtime_get_account_mgr ();
1092 g_assert (self->account_manager);
1093 g_object_ref (self->account_manager);
1095 /* Create the common pages,
1097 self->page_welcome = create_page_welcome (self);
1098 self->page_account_details = create_page_account_details (self);
1099 self->page_user_details = create_page_user_details (self);
1101 /* Add the common pages: */
1102 gtk_notebook_append_page (notebook, self->page_welcome,
1103 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
1104 gtk_notebook_append_page (notebook, self->page_account_details,
1105 gtk_label_new (_("mcen_ti_accountdetails")));
1106 gtk_notebook_append_page (notebook, self->page_user_details,
1107 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
1109 /* Create and add the easysetup-specific pages,
1110 * because we need _some_ final page to enable the Next and Finish buttons: */
1111 create_subsequent_easysetup_pages (self);
1113 /* Connect to the dialog's response signal so we can enable/disable buttons
1114 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
1115 * Note that we use g_signal_connect_after() instead of g_signal_connect()
1116 * so that we can be enable/disable after ModestWizardDialog has done its own
1117 * enabling/disabling of buttons.
1119 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
1120 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
1122 * It's not enough to connect to the notebook's switch-page signal, because
1123 * ModestWizardDialog's "response" signal handler enables the buttons itself,
1124 * _after_ switching the page (understandably).
1125 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
1126 * then gtk_notebook_get_current_page() would return an incorrect value.)
1128 g_signal_connect_after (G_OBJECT (self), "response",
1129 G_CALLBACK (on_response), self);
1131 /* This is to show a confirmation dialog when the user hits cancel */
1132 g_signal_connect (G_OBJECT (self), "response",
1133 G_CALLBACK (on_response_before), self);
1135 /* Reset dirty, because there was no user input until now */
1136 priv->dirty = FALSE;
1138 /* When this window is shown, hibernation should not be possible,
1139 * because there is no sensible way to save the state: */
1140 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1141 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1144 ModestEasysetupWizardDialog*
1145 modest_easysetup_wizard_dialog_new (void)
1147 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
1150 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
1152 GtkNotebook *notebook = NULL;
1153 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1156 /* Create the custom pages: */
1157 if(!(self->page_custom_incoming)) {
1158 self->page_custom_incoming = create_page_custom_incoming (self);
1161 if(!(self->page_custom_outgoing)) {
1162 self->page_custom_outgoing = create_page_custom_outgoing (self);
1165 if(!(self->page_complete_customsetup)) {
1166 self->page_complete_customsetup = create_page_complete_custom (self);
1169 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
1170 gtk_notebook_append_page (notebook, self->page_custom_incoming,
1171 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
1173 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
1174 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
1175 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
1177 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
1178 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
1179 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1181 /* This is unnecessary with GTK+ 2.10: */
1182 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1185 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
1187 GtkNotebook *notebook = NULL;
1188 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
1191 /* Create the easysetup-specific pages: */
1192 if(!self->page_complete_easysetup)
1193 self->page_complete_easysetup = create_page_complete_easysetup (self);
1195 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
1196 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
1197 gtk_label_new (_("mcen_ti_emailsetup_complete")));
1199 /* This is unnecessary with GTK+ 2.10: */
1200 modest_wizard_dialog_force_title_update (MODEST_WIZARD_DIALOG(self));
1202 /* After the user details page,
1203 * the following pages depend on whether "Other" was chosen
1204 * in the provider combobox on the account page
1206 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
1208 if (easysetup_provider_combo_box_get_active_provider_id (
1209 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
1210 /* "Other..." was selected: */
1212 /* Make sure that the easysetup pages do not exist: */
1213 if(self->page_complete_easysetup) {
1214 gtk_widget_destroy (self->page_complete_easysetup);
1215 self->page_complete_easysetup = NULL;
1218 create_subsequent_customsetup_pages (self);
1221 /* A specific provider was selected: */
1223 /* Make sure that the custom pages do not exist:
1224 * Because they will be used if they exist, when creating the account. */
1225 if(self->page_custom_incoming) {
1226 gtk_widget_destroy (self->page_custom_incoming);
1227 self->page_custom_incoming = NULL;
1230 if(self->page_custom_outgoing) {
1231 gtk_widget_destroy (self->page_custom_outgoing);
1232 self->page_custom_outgoing = NULL;
1235 if(self->page_complete_customsetup) {
1236 gtk_widget_destroy (self->page_complete_customsetup);
1237 self->page_complete_customsetup = NULL;
1241 /* Create the easysetup pages: */
1242 create_subsequent_easysetup_pages (self);
1248 util_get_default_servername_from_email_address (const gchar* email_address, ModestTransportStoreProtocol servertype)
1253 gchar* at = g_utf8_strchr (email_address, -1, '@');
1254 if (!at || (g_utf8_strlen (at, -1) < 2))
1257 gchar* domain = g_utf8_next_char (at);
1261 const gchar* hostname = NULL;
1262 if (servertype == MODEST_PROTOCOL_STORE_POP)
1264 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
1266 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
1272 return g_strdup_printf ("%s.%s", hostname, domain);
1275 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
1277 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE(account_wizard);
1279 if (!account_wizard->entry_incomingserver)
1282 /* Set a default domain for the server, based on the email address,
1283 * if no server name was already specified.
1285 if (account_wizard->entry_user_email
1286 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
1287 const ModestTransportStoreProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
1288 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
1289 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1291 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
1293 /* Do not set the INCOMING_CHANGED flag because of this edit */
1294 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1295 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
1296 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_incomingserver), G_CALLBACK (on_entry_incoming_servername_changed), account_wizard);
1298 g_free (servername);
1301 /* Set a default domain for the server, based on the email address,
1302 * if no server name was already specified.
1304 if (!account_wizard->entry_outgoingserver)
1307 if (account_wizard->entry_user_email
1308 && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_OUTGOING_CHANGED) == 0)) {
1309 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
1311 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
1313 /* Do not set the OUTGOING_CHANGED flag because of this edit */
1314 g_signal_handlers_block_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1315 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1316 g_signal_handlers_unblock_by_func (G_OBJECT (account_wizard->entry_outgoingserver), G_CALLBACK (on_entry_outgoing_servername_changed), account_wizard);
1318 g_free (servername);
1323 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1325 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1327 /* Do extra validation that couldn't be done for every key press,
1328 * either because it was too slow,
1329 * or because it requires interaction:
1331 if (current_page == account_wizard->page_account_details) {
1332 /* Check that the title is not already in use: */
1333 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1334 if ((!account_title) || (strlen(account_title) == 0))
1337 /* Aavoid a clash with an existing display name: */
1338 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (
1339 account_wizard->account_manager, account_title);
1342 /* Warn the user via a dialog: */
1343 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
1348 else if (current_page == account_wizard->page_user_details) {
1349 /* Check that the email address is valud: */
1350 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1351 if ((!email_address) || (strlen(email_address) == 0))
1354 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
1355 /* Warn the user via a dialog: */
1356 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
1358 /* Return focus to the email address entry: */
1359 gtk_widget_grab_focus (account_wizard->entry_user_email);
1360 gtk_editable_select_region (GTK_EDITABLE (account_wizard->entry_user_email), 0, -1);
1365 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1366 create_subsequent_pages (account_wizard);
1369 /* TODO: The UI Spec wants us to check that the servernames are valid,
1370 * but does not specify how.
1373 if(next_page == account_wizard->page_custom_incoming) {
1374 set_default_custom_servernames (account_wizard);
1376 else if (next_page == account_wizard->page_custom_outgoing) {
1377 set_default_custom_servernames (account_wizard);
1378 /* Check if the server supports secure authentication */
1379 const ModestConnectionProtocol security_incoming =
1380 modest_serversecurity_combo_box_get_active_serversecurity (
1381 MODEST_SERVERSECURITY_COMBO_BOX (
1382 account_wizard->combo_incoming_security));
1383 if (gtk_toggle_button_get_active (
1384 GTK_TOGGLE_BUTTON (account_wizard->checkbox_incoming_auth))
1385 && !modest_protocol_info_is_secure(security_incoming))
1387 GList* methods = check_for_supported_auth_methods(account_wizard);
1390 g_list_free(methods);
1393 g_list_free(methods);
1397 /* If this is the last page, and this is a click on Finish,
1398 * then attempt to create the dialog.
1400 if(!next_page) /* This is NULL when this is a click on Finish. */
1402 if (account_wizard->saved_account_name) {
1403 /* Just enable the already-saved account (temporarily created when
1404 * editing advanced settings): */
1405 modest_account_mgr_set_enabled (account_wizard->account_manager,
1406 account_wizard->saved_account_name, TRUE);
1408 create_account (account_wizard, TRUE /* enabled */);
1416 static gboolean entry_is_empty (GtkWidget *entry)
1421 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1422 if ((!text) || (strlen(text) == 0))
1429 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1431 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1433 gboolean enable_next = TRUE;
1434 if (current_page == account_wizard->page_welcome) {
1437 else if (current_page == account_wizard->page_account_details) {
1438 /* The account details title is mandatory: */
1439 if (entry_is_empty(account_wizard->entry_account_title))
1440 enable_next = FALSE;
1442 else if (current_page == account_wizard->page_user_details) {
1443 /* The user details username is mandatory: */
1444 if (entry_is_empty(account_wizard->entry_user_username))
1445 enable_next = FALSE;
1447 /* The user details email address is mandatory: */
1448 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1449 enable_next = FALSE;
1451 else if (current_page == account_wizard->page_custom_incoming) {
1452 /* The custom incoming server is mandatory: */
1453 if (entry_is_empty(account_wizard->entry_incomingserver))
1454 enable_next = FALSE;
1457 /* Enable the buttons,
1458 * identifying them via their associated response codes: */
1460 /* Disable the Finish button until we are on the last page,
1461 * because HildonWizardDialog enables this for all but the first page: */
1462 GtkNotebook *notebook = NULL;
1463 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1464 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1466 gint current = gtk_notebook_get_current_page (notebook);
1467 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1468 const gboolean is_last = (current == last);
1471 gtk_dialog_set_response_sensitive (dialog_base,
1472 MODEST_WIZARD_DIALOG_FINISH,
1476 /* Disable Next on the last page: */
1477 enable_next = FALSE;
1480 gtk_dialog_set_response_sensitive (dialog_base,
1481 MODEST_WIZARD_DIALOG_NEXT,
1486 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1488 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1489 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1492 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1493 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1494 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1495 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1497 /* Provide a vfunc implementation so we can decide
1498 * when to enable/disable the prev/next buttons.
1500 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1501 base_klass->before_next = on_before_next;
1502 base_klass->enable_buttons = on_enable_buttons;
1506 show_error (GtkWidget *parent_widget, const gchar* text)
1508 hildon_banner_show_information(parent_widget, NULL, text);
1511 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1513 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1520 gtk_dialog_run (dialog);
1521 gtk_widget_destroy (GTK_WIDGET (dialog));
1525 /** Attempt to create the account from the information that the user has entered.
1526 * @result: TRUE if the account was successfully created.
1529 create_account (ModestEasysetupWizardDialog *self, gboolean enabled)
1531 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1533 const gchar* display_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1539 /* We should have checked for this already,
1540 * and changed that name accordingly,
1541 * but let's check again just in case:
1543 if (modest_account_mgr_account_with_display_name_exists (self->account_manager, display_name))
1546 /* Increment the non-user visible name if necessary,
1547 * based on the display name: */
1548 gchar *account_name_start = g_strdup_printf ("%sID", display_name);
1549 gchar* account_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1550 account_name_start, FALSE /* not a server account */);
1551 g_free (account_name_start);
1553 /* username and password (for both incoming and outgoing): */
1554 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1555 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1556 /* Incoming server: */
1557 /* Note: We need something as default for the ModestTransportStoreProtocol* values,
1558 * or modest_account_mgr_add_server_account will fail. */
1559 gchar* servername_incoming = NULL;
1560 guint serverport_incoming = 0;
1561 ModestTransportStoreProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1562 ModestConnectionProtocol protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_NORMAL;
1563 ModestAuthProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1565 /* Get details from the specified presets: */
1566 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1567 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1570 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1571 TRUE /* incoming */);
1573 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets,
1575 TRUE /* incoming */);
1576 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets,
1578 TRUE /* incoming */);
1580 g_warning ("security incoming: %x", security_incoming);
1582 /* We don't check for SMTP here as that is impossible for an incoming server. */
1583 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP) {
1584 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1585 } else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP) {
1586 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1588 serverport_incoming = get_serverport_incoming(servertype_incoming, security_incoming);
1590 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1591 protocol_security_incoming = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1593 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1594 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1597 /* Use custom pages because no preset was specified: */
1598 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1600 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1601 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1603 protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1604 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1606 /* The UI spec says:
1607 * If secure authentication is unchecked, allow sending username and password also as plain text.
1608 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1611 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth)) &&
1612 !modest_protocol_info_is_secure(protocol_security_incoming))
1614 GList* methods = check_for_supported_auth_methods(self);
1618 protocol_authentication_incoming = (ModestAuthProtocol) (GPOINTER_TO_INT(methods->data));
1621 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1624 /* First we add the 2 server accounts, and then we add the account that uses them.
1625 * If we don't do it in this order then we will experience a crash. */
1627 /* Add a (incoming) server account, to be used by the account: */
1628 gchar *store_name_start = g_strconcat (account_name, "_store", NULL);
1629 gchar *store_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1630 store_name_start, TRUE /* server account */);
1631 g_free (store_name_start);
1632 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1634 servername_incoming,
1635 serverport_incoming,
1638 protocol_security_incoming,
1639 protocol_authentication_incoming);
1641 g_free (servername_incoming);
1644 /* TODO: Provide a Logical ID for the text: */
1645 show_error (GTK_WIDGET (self), _("An error occurred while creating the incoming account."));
1649 /* Outgoing server: */
1650 gchar* servername_outgoing = NULL;
1651 ModestTransportStoreProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1652 ModestConnectionProtocol protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1653 ModestAuthProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1654 guint serverport_outgoing = 0;
1658 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1659 FALSE /* incoming */);
1661 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets,
1663 FALSE /* incoming */);
1665 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1666 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1667 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1668 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP;
1670 ModestPresetsSecurity security_outgoing =
1671 modest_presets_get_info_server_security (priv->presets, provider_id,
1672 FALSE /* incoming */);
1674 /* TODO: There is no SMTP authentication enum for presets,
1675 so we should probably check what the server supports. */
1676 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_NORMAL;
1677 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP) {
1678 /* printf("DEBUG: %s: using secure SMTP\n", __FUNCTION__); */
1679 protocol_security_outgoing = MODEST_PROTOCOL_CONNECTION_SSL; /* TODO: Is this what we want? */
1680 serverport_outgoing = 465;
1681 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_PASSWORD;
1683 /* printf("DEBUG: %s: using non-secure SMTP\n", __FUNCTION__); */
1684 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1688 /* Use custom pages because no preset was specified: */
1689 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1691 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1693 protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1694 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1696 protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1697 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1700 /* Add a (outgoing) server account to be used by the account: */
1701 gchar *transport_name_start = g_strconcat (account_name, "_transport", NULL);
1702 gchar *transport_name = modest_account_mgr_get_unused_account_name (self->account_manager,
1703 transport_name_start, TRUE /* server account */);
1704 g_free (transport_name_start);
1705 created = modest_account_mgr_add_server_account (self->account_manager,
1707 servername_outgoing,
1708 serverport_outgoing,
1711 protocol_security_outgoing,
1712 protocol_authentication_outgoing);
1714 g_free (servername_outgoing);
1717 /* TODO: Provide a Logical ID for the text: */
1718 show_error (GTK_WIDGET (self), _("An error occurred while creating the outgoing account."));
1723 /* Create the account, which will contain the two "server accounts": */
1724 created = modest_account_mgr_add_account (self->account_manager, account_name,
1725 store_name, /* The name of our POP/IMAP server account. */
1726 transport_name, /* The name of our SMTP server account. */
1728 g_free (store_name);
1729 g_free (transport_name);
1732 /* TODO: Provide a Logical ID for the text: */
1733 show_error (GTK_WIDGET (self), _("An error occurred while creating the account."));
1738 /* There must be at least one account now: */
1739 /* Note, when this fails is is caused by a Maemo gconf bug that has been
1740 * fixed in versions after 3.1. */
1741 if(!modest_account_mgr_has_accounts (self->account_manager, FALSE))
1742 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1744 /* The user name and email address must be set additionally: */
1745 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1746 modest_account_mgr_set_string (self->account_manager, account_name,
1747 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1749 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1750 modest_account_mgr_set_string (self->account_manager, account_name,
1751 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1753 /* Set the display name: */
1754 modest_account_mgr_set_string (self->account_manager, account_name,
1755 MODEST_ACCOUNT_DISPLAY_NAME, display_name, FALSE /* not server account */);
1757 /* Set retrieve type */
1758 const gchar *retrieve = MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY;
1759 modest_account_mgr_set_string (self->account_manager, account_name,
1760 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1762 /* Save the connection-specific SMTP server accounts. */
1763 gboolean result = TRUE;
1764 if (self->specific_window)
1765 result = modest_connection_specific_smtp_window_save_server_accounts (
1766 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), account_name);
1768 g_free (self->saved_account_name);
1769 self->saved_account_name = g_strdup (account_name);
1771 g_free (account_name);