1 /* Copyright (c) 2007, Nokia Corporation
7 #include "modest-easysetup-wizard.h"
8 #include <glib/gi18n.h>
9 #include <gtk/gtknotebook.h>
10 #include <gtk/gtkvbox.h>
11 #include <gtk/gtklabel.h>
12 #include <gtk/gtkcombobox.h>
13 #include <gtk/gtkentry.h>
14 #include <gtk/gtkbutton.h>
15 #include <gtk/gtkcheckbutton.h>
16 #include <gtk/gtkmessagedialog.h>
17 #include <hildon-widgets/hildon-caption.h>
18 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
19 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
20 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
21 #include "maemo/easysetup/modest-easysetup-serversecurity-combo-box.h"
22 #include "maemo/easysetup/modest-easysetup-secureauth-combo-box.h"
23 #include "maemo/easysetup/modest-validating-entry.h"
24 #include "modest-text-utils.h"
25 #include "modest-account-mgr.h"
26 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
27 #include "maemo/modest-connection-specific-smtp-window.h"
28 #include <gconf/gconf-client.h>
29 #include <string.h> /* For strlen(). */
31 /* Include config.h so that _() works: */
36 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
38 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
40 #define WIZARD_DIALOG_GET_PRIVATE(o) \
41 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
43 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
45 struct _ModestEasysetupWizardDialogPrivate
47 ModestPresets *presets;
51 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
52 GValue *value, GParamSpec *pspec)
54 switch (property_id) {
56 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
61 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
62 const GValue *value, GParamSpec *pspec)
64 switch (property_id) {
66 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
71 modest_easysetup_wizard_dialog_dispose (GObject *object)
73 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
74 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
78 modest_easysetup_wizard_dialog_finalize (GObject *object)
80 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
81 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
83 if (self->account_manager)
84 g_object_unref (G_OBJECT (self->account_manager));
87 modest_presets_destroy (priv->presets);
89 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
93 show_error (GtkWindow *parent_window, const gchar* text);
96 create_account (ModestEasysetupWizardDialog *self);
99 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
102 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
105 util_increment_name (const gchar* text);
108 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
110 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
112 /* Call the vfunc, which may be overridden by derived classes: */
113 if (klass->enable_buttons) {
114 GtkNotebook *notebook = NULL;
115 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
117 const gint current_page_num = gtk_notebook_get_current_page (notebook);
118 if (current_page_num == -1)
121 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
122 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
127 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
129 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
131 invoke_enable_buttons_vfunc(self);
135 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
137 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
139 invoke_enable_buttons_vfunc(self);
142 /** This is a convenience function to create a caption containing a mandatory widget.
143 * When the widget is edited, the enable_buttons() vfunc will be called.
145 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
150 HildonCaptionStatus flag)
152 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
154 /* The translated strings seem to already contain the *,
155 * but this code can be used if that is not true in future.
158 /* Add a * character to indicate mandatory fields,
159 * as specified in our "Email UI Specification": */
160 if (flag == HILDON_CAPTION_MANDATORY) {
161 gchar* title = g_strdup_printf("%s*", value);
162 caption = hildon_caption_new (group, title, control, icon, flag);
166 caption = hildon_caption_new (group, value, control, icon, flag);
169 /* Connect to the appropriate changed signal for the widget,
170 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
172 if (GTK_IS_ENTRY (control)) {
173 g_signal_connect (G_OBJECT (control), "changed",
174 G_CALLBACK (on_caption_entry_changed), self);
177 else if (GTK_IS_COMBO_BOX (control)) {
178 g_signal_connect (G_OBJECT (control), "changed",
179 G_CALLBACK (on_caption_combobox_changed), self);
186 create_page_welcome (ModestEasysetupWizardDialog *self)
188 GtkWidget *box = gtk_vbox_new (FALSE, 2);
189 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
190 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
191 gtk_widget_show (label);
192 gtk_widget_show (GTK_WIDGET (box));
193 return GTK_WIDGET (box);
197 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
199 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
201 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
203 /* Fill the providers combo, based on the selected country: */
204 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
205 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
206 easysetup_provider_combo_box_fill (
207 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
211 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
213 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
215 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
217 /* Fill the providers combo, based on the selected country: */
218 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
219 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
221 gchar* domain_name = NULL;
223 domain_name = modest_presets_get_domain (priv->presets, provider_id);
226 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
228 if (self->entry_user_email)
229 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
231 g_free (domain_name);
233 g_free (provider_id);
238 create_page_account_details (ModestEasysetupWizardDialog *self)
240 GtkWidget *box = gtk_vbox_new (FALSE, 2);
241 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
242 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
243 gtk_widget_show (label);
245 /* Create a size group to be used by all captions.
246 * Note that HildonCaption does not create a default size group if we do not specify one.
247 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
248 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
250 /* The country widgets: */
251 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
252 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
253 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
254 gtk_widget_show (self->combo_account_country);
255 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
256 gtk_widget_show (caption);
258 /* connect to country combo's changed signal, so we can fill the provider combo: */
259 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
260 G_CALLBACK (on_combo_account_country), self);
263 /* The service provider widgets: */
264 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
266 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
267 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
268 gtk_widget_show (self->combo_account_serviceprovider);
269 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
270 gtk_widget_show (caption);
272 /* connect to providers combo's changed signal, so we can fill the email address: */
273 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
274 G_CALLBACK (on_combo_account_serviceprovider), self);
276 /* TODO: Default to the current country somehow.
277 * But I don't know how to get the information that is specified in the
278 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
280 * This is probably not the best choice of gconf key:
281 * This is the "mcc used in the last pairing", ie. the last connection you made.
282 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
285 GConfClient *client = gconf_client_get_default ();
286 GError *error = NULL;
287 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
288 gint mcc_id = gconf_client_get_int(client, key, &error);
294 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
295 g_error_free (error);
301 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
302 * This might just be a Maemo bug.
306 /* For now, we default to Finland when there is nothing better: */
310 easysetup_country_combo_box_set_active_country_id (
311 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
314 /* The description widgets: */
315 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
317 /* Set a default account title, choosing one that does not already exist: */
318 gchar* default_acount_name = g_strdup (_("mcen_ia_emailsetup_defaultname"));
319 while (modest_account_mgr_account_exists (self->account_manager,
320 default_acount_name, TRUE /* server_account */)) {
322 gchar * default_account_name2 = util_increment_name (default_acount_name);
323 g_free (default_acount_name);
324 default_acount_name = default_account_name2;
327 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_acount_name);
328 g_free (default_acount_name);
329 default_acount_name = NULL;
331 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
332 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
333 gtk_widget_show (self->entry_account_title);
334 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
335 gtk_widget_show (caption);
337 /* Prevent the use of some characters in the account title,
338 * as required by our UI specification: */
339 GList *list_prevent = NULL;
340 list_prevent = g_list_append (list_prevent, "\\");
341 list_prevent = g_list_append (list_prevent, "/");
342 list_prevent = g_list_append (list_prevent, ":");
343 list_prevent = g_list_append (list_prevent, "*");
344 list_prevent = g_list_append (list_prevent, "?");
345 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
346 list_prevent = g_list_append (list_prevent, "“");
347 list_prevent = g_list_append (list_prevent, "<");
348 list_prevent = g_list_append (list_prevent, ">");
349 list_prevent = g_list_append (list_prevent, "|");
350 list_prevent = g_list_append (list_prevent, "^");
351 easysetup_validating_entry_set_unallowed_characters (
352 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
353 g_list_free (list_prevent);
355 /* Set max length as in the UI spec:
356 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
357 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
359 gtk_widget_show (GTK_WIDGET (box));
361 return GTK_WIDGET (box);
365 create_page_user_details (ModestEasysetupWizardDialog *self)
367 GtkWidget *box = gtk_vbox_new (FALSE, 2);
369 /* Create a size group to be used by all captions.
370 * Note that HildonCaption does not create a default size group if we do not specify one.
371 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
372 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
374 /* The name widgets: */
375 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
376 /* Set max length as in the UI spec:
377 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
378 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
379 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
380 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
381 gtk_widget_show (self->entry_user_name);
382 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
383 gtk_widget_show (caption);
385 /* Prevent the use of some characters in the name,
386 * as required by our UI specification: */
387 GList *list_prevent = NULL;
388 list_prevent = g_list_append (list_prevent, "<");
389 list_prevent = g_list_append (list_prevent, ">");
390 easysetup_validating_entry_set_unallowed_characters (
391 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
392 g_list_free (list_prevent);
394 /* The username widgets: */
395 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
396 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
397 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
398 gtk_widget_show (self->entry_user_username);
399 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
400 gtk_widget_show (caption);
402 /* Prevent the use of some characters in the username,
403 * as required by our UI specification: */
404 easysetup_validating_entry_set_unallowed_characters_whitespace (
405 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
407 /* Set max length as in the UI spec:
408 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
409 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
411 /* The password widgets: */
412 self->entry_user_password = gtk_entry_new ();
413 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
414 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
415 caption = create_caption_new_with_asterix (self, sizegroup,
416 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
417 gtk_widget_show (self->entry_user_password);
418 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
419 gtk_widget_show (caption);
421 /* The email address widgets: */
422 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
423 caption = create_caption_new_with_asterix (self, sizegroup,
424 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
425 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
426 gtk_widget_show (self->entry_user_email);
427 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
428 gtk_widget_show (caption);
430 /* Set max length as in the UI spec:
431 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
432 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
435 gtk_widget_show (GTK_WIDGET (box));
437 return GTK_WIDGET (box);
440 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
442 GtkWidget *box = gtk_vbox_new (FALSE, 2);
443 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
444 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
445 gtk_widget_show (label);
446 gtk_widget_show (GTK_WIDGET (box));
447 return GTK_WIDGET (box);
450 /** Change the caption title for the incoming server,
451 * as specified in the UI spec:
453 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
455 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
456 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
458 (protocol == MODEST_PROTOCOL_STORE_POP ?
459 _("mail_fi_emailtype_pop3") :
460 _("mail_fi_emailtype_imap") );
463 /* Note that this produces a compiler warning,
464 * because the compiler does not know that the translated string will have a %s in it.
465 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
466 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
467 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
468 g_free(incomingserver_title);
471 /** Change the caption title for the incoming server,
472 * as specified in the UI spec:
474 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
476 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
477 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
479 /* Fill the combo with appropriately titled choices for POP or IMAP. */
480 /* The choices are the same, but the titles are different, as in the UI spec. */
481 easysetup_serversecurity_combo_box_fill (
482 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
485 void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
487 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
488 update_incoming_server_title (self);
489 update_incoming_server_security_choices (self);
492 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
494 GtkWidget *box = gtk_vbox_new (FALSE, 2);
496 /* Create a size group to be used by all captions.
497 * Note that HildonCaption does not create a default size group if we do not specify one.
498 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
499 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
501 /* The incoming server widgets: */
502 if (!self->combo_incoming_servertype)
503 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
504 easysetup_servertype_combo_box_set_active_servertype (
505 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
506 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
507 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
508 gtk_widget_show (self->combo_incoming_servertype);
509 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
510 gtk_widget_show (caption);
512 if(!self->entry_incomingserver)
513 self->entry_incomingserver = gtk_entry_new ();
514 set_default_custom_servernames (self);
516 if (self->caption_incoming)
517 gtk_widget_destroy (self->caption_incoming);
519 /* The caption title will be updated in update_incoming_server_title().
520 * so this default text will never be seen: */
521 /* (Note: Changing the title seems pointless. murrayc) */
522 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
523 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
524 update_incoming_server_title (self);
525 gtk_widget_show (self->entry_incomingserver);
526 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
527 gtk_widget_show (self->caption_incoming);
529 /* Change the caption title when the servertype changes,
530 * as in the UI spec: */
531 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
532 G_CALLBACK (on_combo_servertype_changed), self);
534 /* The secure connection widgets: */
535 if (!self->combo_incoming_security)
536 self->combo_incoming_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
537 update_incoming_server_security_choices (self);
538 easysetup_serversecurity_combo_box_set_active_serversecurity (
539 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
540 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
541 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
542 gtk_widget_show (self->combo_incoming_security);
543 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
544 gtk_widget_show (caption);
546 if(!self->checkbox_incoming_auth)
547 self->checkbox_incoming_auth =
548 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
549 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
550 gtk_widget_show (self->checkbox_incoming_auth);
552 gtk_widget_show (GTK_WIDGET (box));
554 return GTK_WIDGET (box);
558 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
560 GtkWidget *widget = GTK_WIDGET (user_data);
562 /* Enable the widget only if the toggle button is active: */
563 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
564 gtk_widget_set_sensitive (widget, enable);
567 /* Make the sensitivity of a widget depend on a toggle button.
570 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
572 g_signal_connect (G_OBJECT (button), "toggled",
573 G_CALLBACK (on_toggle_button_changed), widget);
575 /* Set the starting sensitivity: */
576 on_toggle_button_changed (button, widget);
580 on_smtp_servers_window_hide (GtkWindow *window, gpointer user_data)
582 /* Destroy the window when it is closed: */
583 gtk_widget_destroy (GTK_WIDGET (window));
587 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
590 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
592 /* Show the window: */
593 /* TODO: Retrieve the chosen settings,
594 * so we can supply them when creating the connection somehow.
596 GtkWidget *window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
597 g_signal_connect (G_OBJECT (window), "hide",
598 G_CALLBACK (on_smtp_servers_window_hide), self);
599 gtk_widget_show (window);
602 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
604 GtkWidget *box = gtk_vbox_new (FALSE, 2);
606 /* Create a size group to be used by all captions.
607 * Note that HildonCaption does not create a default size group if we do not specify one.
608 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
609 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
611 /* The outgoing server widgets: */
612 if (!self->entry_outgoingserver)
613 self->entry_outgoingserver = gtk_entry_new ();
614 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
615 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
616 gtk_widget_show (self->entry_outgoingserver);
617 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
618 gtk_widget_show (caption);
619 set_default_custom_servernames (self);
621 /* The secure connection widgets: */
622 if (!self->combo_outgoing_security)
623 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
624 easysetup_serversecurity_combo_box_fill (
625 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
626 easysetup_serversecurity_combo_box_set_active_serversecurity (
627 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
628 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
629 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
630 gtk_widget_show (self->combo_outgoing_security);
631 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
632 gtk_widget_show (caption);
634 /* The secure authentication widgets: */
635 if (!self->combo_outgoing_auth)
636 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
637 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
638 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
639 gtk_widget_show (self->combo_outgoing_auth);
640 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
641 gtk_widget_show (caption);
643 /* connection-specific checkbox: */
644 if (!self->checkbox_outgoing_smtp_specific) {
645 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
646 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
649 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
650 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
652 /* Connection-specific SMTP-Severs Edit button: */
653 if (!self->button_outgoing_smtp_servers)
654 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
655 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
656 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
657 gtk_widget_show (self->button_outgoing_smtp_servers);
658 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
659 gtk_widget_show (caption);
661 /* Only enable the button when the checkbox is checked: */
662 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
663 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
665 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
666 G_CALLBACK (on_button_outgoing_smtp_servers), self);
669 gtk_widget_show (GTK_WIDGET (box));
671 return GTK_WIDGET (box);
674 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
676 GtkWidget *box = gtk_vbox_new (FALSE, 2);
677 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
678 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
679 gtk_widget_show (label);
681 if (!self->button_edit)
682 self->button_edit = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
683 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
684 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
685 gtk_widget_show (self->button_edit);
686 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
687 gtk_widget_show (caption);
689 gtk_widget_show (GTK_WIDGET (box));
690 return GTK_WIDGET (box);
697 on_response (ModestWizardDialog *wizard_dialog,
701 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
702 invoke_enable_buttons_vfunc (self);
706 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
708 /* Create the notebook to be used by the ModestWizardDialog base class:
709 * Each page of the notebook will be a page of the wizard: */
710 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
712 /* Set the notebook used by the ModestWizardDialog base class: */
713 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
715 /* Set the wizard title:
716 * The actual window title will be a combination of this and the page's tab label title. */
717 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
719 /* Read in the information about known service providers: */
720 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
722 const gchar* filepath = "/usr/share/operator-wizard/provider-data.keyfile";
723 priv->presets = modest_presets_new (filepath); /* TODO: the actual filepath. */
724 if (!(priv->presets))
726 const gchar* filepath_hack = "./src/maemo/easysetup/provider-data-test.keyfile";
727 g_warning ("Could not locate the official provider data keyfile from %s, "
728 "so attempting to load it instead from %s", filepath, filepath_hack);
729 priv->presets = modest_presets_new (filepath_hack); /* TODO: the actual filepath. */
732 g_assert(priv->presets);
735 /* Get the account manager object,
736 * so we can check for existing accounts,
737 * and create new accounts: */
738 self->account_manager = modest_runtime_get_account_mgr ();
739 g_assert (self->account_manager);
740 g_object_ref (self->account_manager);
742 /* Create the common pages,
744 self->page_welcome = create_page_welcome (self);
745 self->page_account_details = create_page_account_details (self);
746 self->page_user_details = create_page_user_details (self);
748 /* Add the common pages: */
749 gtk_notebook_append_page (notebook, self->page_welcome,
750 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
751 gtk_notebook_append_page (notebook, self->page_account_details,
752 gtk_label_new (_("mcen_ti_accountdetails")));
753 gtk_notebook_append_page (notebook, self->page_user_details,
754 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
756 /* Create and add the easysetup-specific pages,
757 * because we need _some_ final page to enable the Next and Finish buttons: */
758 create_subsequent_easysetup_pages (self);
761 /* Connect to the dialog's response signal so we can enable/disable buttons
762 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
763 * Note that we use g_signal_connect_after() instead of g_signal_connect()
764 * so that we can be enable/disable after ModestWizardDialog has done its own
765 * enabling/disabling of buttons.
767 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
768 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
770 * It's not enough to connect to the notebook's switch-page signal, because
771 * ModestWizardDialog's "response" signal handler enables the buttons itself,
772 * _after_ switching the page (understandably).
773 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
774 * then gtk_notebook_get_current_page() would return an incorrect value.)
776 g_signal_connect_after (G_OBJECT (self), "response",
777 G_CALLBACK (on_response), self);
780 ModestEasysetupWizardDialog*
781 modest_easysetup_wizard_dialog_new (void)
783 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
786 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
788 GtkNotebook *notebook = NULL;
789 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
792 /* Create the custom pages: */
793 if(!(self->page_custom_incoming)) {
794 self->page_custom_incoming = create_page_custom_incoming (self);
797 if(!(self->page_custom_outgoing)) {
798 self->page_custom_outgoing = create_page_custom_outgoing (self);
801 if(!(self->page_complete_customsetup)) {
802 self->page_complete_customsetup = create_page_complete_custom (self);
805 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
806 gtk_notebook_append_page (notebook, self->page_custom_incoming,
807 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
809 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
810 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
811 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
813 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
814 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
815 gtk_label_new (_("mcen_ti_emailsetup_complete")));
818 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
820 GtkNotebook *notebook = NULL;
821 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
824 /* Create the easysetup-specific pages: */
825 if(!self->page_complete_easysetup)
826 self->page_complete_easysetup = create_page_complete_easysetup (self);
828 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
829 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
830 gtk_label_new (_("mcen_ti_emailsetup_complete")));
833 /* After the user details page,
834 * the following pages depend on whether "Other" was chosen
835 * in the provider combobox on the account page
837 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
839 if (easysetup_provider_combo_box_get_active_provider_id (
840 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
841 /* "Other..." was selected: */
843 /* Make sure that the easysetup pages do not exist: */
844 if(self->page_complete_easysetup) {
845 gtk_widget_destroy (self->page_complete_easysetup);
846 self->page_complete_easysetup = NULL;
849 create_subsequent_customsetup_pages (self);
852 /* A specific provider was selected: */
854 /* Make sure that the custom pages do not exist:
855 * Because they will be used if they exist, when creating the account. */
856 if(self->page_custom_incoming) {
857 gtk_widget_destroy (self->page_custom_incoming);
858 self->page_custom_incoming = NULL;
861 if(self->page_custom_outgoing) {
862 gtk_widget_destroy (self->page_custom_outgoing);
863 self->page_custom_outgoing = NULL;
866 if(self->page_complete_customsetup) {
867 gtk_widget_destroy (self->page_complete_customsetup);
868 self->page_complete_customsetup = NULL;
872 /* Create the easysetup pages: */
873 create_subsequent_easysetup_pages (self);
878 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
883 gchar* at = g_utf8_strchr (email_address, -1, '@');
884 if (!at || (g_utf8_strlen (at, -1) < 2))
887 gchar* domain = g_utf8_next_char (at);
891 const gchar* hostname = NULL;
892 if (servertype == MODEST_PROTOCOL_STORE_POP)
894 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
896 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
902 return g_strdup_printf ("%s.%s", hostname, domain);
905 /* Add a number to the end of the text, or increment a number that is already there.
908 util_increment_name (const gchar* text)
910 /* Get the end character,
911 * also doing a UTF-8 validation which is required for using g_utf8_prev_char().
913 const gchar* end = NULL;
914 if (!g_utf8_validate (text, -1, &end))
920 --end; /* Go to before the null-termination. */
922 /* Look at each UTF-8 characer, starting at the end: */
923 const gchar* p = end;
924 const gchar* alpha_end = NULL;
927 /* Stop when we reach the first character that is not a numeric digit: */
928 const gunichar ch = g_utf8_get_char (p);
929 if (!g_unichar_isdigit (ch)) {
934 p = g_utf8_prev_char (p);
938 /* The text must consist completely of numeric digits. */
944 /* Intepret and increment the number, if any: */
945 gint num = atol (alpha_end);
948 /* Get the name part: */
949 gint name_len = alpha_end - text;
950 gchar *name_without_number = g_malloc(name_len + 1);
951 memcpy (name_without_number, text, name_len);
952 name_without_number[name_len] = 0;\
954 /* Concatenate the text part and the new number: */
955 gchar *result = g_strdup_printf("%s%d", name_without_number, num);
956 g_free (name_without_number);
961 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
963 /* Set a default domain for the server, based on the email address,
964 * if no server name was already specified.
966 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
967 if ((!incoming_existing || (strlen(incoming_existing) == 0))
968 && account_wizard->entry_user_email) {
969 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
970 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
971 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
973 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
974 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
978 /* Set a default domain for the server, based on the email address,
979 * if no server name was already specified.
981 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
982 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
983 && account_wizard->entry_user_email) {
984 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
986 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
987 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
993 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
995 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
997 /* Do extra validation that couldn't be done for every key press,
998 * either because it was too slow,
999 * or because it requires interaction:
1001 if (current_page == account_wizard->page_account_details) {
1002 /* Check that the title is not already in use: */
1003 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1004 if ((!account_name) || (strlen(account_name) == 0))
1007 gboolean name_in_use = FALSE;
1008 name_in_use = modest_account_mgr_account_exists (account_wizard->account_manager,
1009 account_name, TRUE /* server_account */);
1012 /* Warn the user via a dialog: */
1013 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing."));
1018 else if (current_page == account_wizard->page_user_details) {
1019 /* Check that the email address is valud: */
1020 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1021 if ((!email_address) || (strlen(email_address) == 0))
1024 if (!modest_text_utils_validate_email_address (email_address)) {
1025 /* Warn the user via a dialog: */
1026 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1028 /* Return focus to the email address entry: */
1029 gtk_widget_grab_focus (account_wizard->entry_user_email);
1034 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1035 create_subsequent_pages (account_wizard);
1038 /* TODO: The UI Spec wants us to check that the servernames are valid,
1039 * but does not specify how.
1042 if(next_page == account_wizard->page_custom_incoming) {
1043 set_default_custom_servernames (account_wizard);
1045 else if (next_page == account_wizard->page_custom_outgoing) {
1046 set_default_custom_servernames (account_wizard);
1049 /* If this is the last page, and this is a click on Finish,
1050 * then attempt to create the dialog.
1052 if(!next_page) /* This is NULL when this is a click on Finish. */
1054 create_account (account_wizard);
1061 static gboolean entry_is_empty (GtkWidget *entry)
1066 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1067 if ((!text) || (strlen(text) == 0))
1074 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1076 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1078 gboolean enable_next = TRUE;
1079 if (current_page == account_wizard->page_welcome) {
1082 else if (current_page == account_wizard->page_account_details) {
1083 /* The account details title is mandatory: */
1084 if (entry_is_empty(account_wizard->entry_account_title))
1085 enable_next = FALSE;
1087 else if (current_page == account_wizard->page_user_details) {
1088 /* The user details username is mandatory: */
1089 if (entry_is_empty(account_wizard->entry_user_username))
1090 enable_next = FALSE;
1092 /* The user details email address is mandatory: */
1093 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1094 enable_next = FALSE;
1096 else if (current_page == account_wizard->page_custom_incoming) {
1097 /* The custom incoming server is mandatory: */
1098 if (entry_is_empty(account_wizard->entry_incomingserver))
1099 enable_next = FALSE;
1102 /* Enable the buttons,
1103 * identifying them via their associated response codes:
1105 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1106 gtk_dialog_set_response_sensitive (dialog_base,
1107 MODEST_WIZARD_DIALOG_NEXT,
1110 /* Disable the Finish button until we are on the last page,
1111 * because HildonWizardDialog enables this for all but the first page: */
1112 GtkNotebook *notebook = NULL;
1113 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1115 gint current = gtk_notebook_get_current_page (notebook);
1116 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1117 gboolean is_last = (current == last);
1120 gtk_dialog_set_response_sensitive (dialog_base,
1121 MODEST_WIZARD_DIALOG_FINISH,
1127 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1129 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1130 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1133 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1134 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1135 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1136 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1138 /* Provide a vfunc implementation so we can decide
1139 * when to enable/disable the prev/next buttons.
1141 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1142 base_klass->before_next = on_before_next;
1143 base_klass->enable_buttons = on_enable_buttons;
1147 show_error (GtkWindow *parent_window, const gchar* text)
1149 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1155 gtk_dialog_run (dialog);
1156 gtk_widget_destroy (GTK_WIDGET (dialog));
1159 /** Attempt to create the account from the information that the user has entered.
1160 * @result: TRUE if the account was successfully created.
1163 create_account (ModestEasysetupWizardDialog *self)
1165 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1167 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1173 /* We should have checked for this already,
1174 * and changed that name accordingly,
1175 * but let's check again just in case:
1177 if (modest_account_mgr_account_exists (self->account_manager, account_name, FALSE))
1180 /* username and password (for both incoming and outgoing): */
1181 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1182 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1184 /* Incoming server: */
1185 /* Note: We need something as default for the ModestProtocol values,
1186 * or modest_account_mgr_add_server_account will fail. */
1187 gchar* servername_incoming = NULL;
1188 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1189 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1190 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1192 /* Get details from the specified presets: */
1193 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1194 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1198 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1199 TRUE /* incoming */);
1201 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1202 TRUE /* incoming */);
1205 /* We don't check for SMTP here as that is impossible for an incoming server. */
1206 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1207 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1208 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1209 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1211 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1212 TRUE /* incoming */);
1215 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1216 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1218 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1219 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1222 /* Use custom pages because no preset was specified: */
1223 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1225 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1226 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1228 protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
1229 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1231 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1232 ? MODEST_PROTOCOL_AUTH_PASSWORD
1233 : MODEST_PROTOCOL_AUTH_NONE;
1237 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1239 servername_incoming,
1242 protocol_security_incoming,
1243 protocol_authentication_incoming);
1245 g_free (servername_incoming);
1248 /* TODO: Provide a Logical ID for the text: */
1249 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1253 /* Outgoing server: */
1254 gchar* servername_outgoing = NULL;
1255 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1256 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1257 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1261 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1262 FALSE /* incoming */);
1264 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1265 FALSE /* incoming */);
1267 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1268 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1269 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1270 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1272 ModestPresetsSecurity security_outgoing =
1273 modest_presets_get_info_server_security (priv->presets, provider_id,
1274 FALSE /* incoming */);
1276 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1277 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1278 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1280 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1281 /* TODO: There is no SMTP authentication enum for presets. */
1284 /* Use custom pages because no preset was specified: */
1285 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1287 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1289 protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
1290 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1292 protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
1293 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1296 gboolean specific = gtk_toggle_button_get_active (
1297 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1302 created = modest_account_mgr_add_server_account (self->account_manager,
1304 servername_outgoing,
1307 protocol_security_outgoing,
1308 protocol_authentication_outgoing);
1310 g_free (servername_outgoing);
1313 /* TODO: Provide a Logical ID for the text: */
1314 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));