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);
104 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data);
107 util_increment_name (const gchar* text);
110 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
112 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
114 /* Call the vfunc, which may be overridden by derived classes: */
115 if (klass->enable_buttons) {
116 GtkNotebook *notebook = NULL;
117 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
119 const gint current_page_num = gtk_notebook_get_current_page (notebook);
120 if (current_page_num == -1)
123 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
124 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
129 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
131 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
133 invoke_enable_buttons_vfunc(self);
137 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
139 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
141 invoke_enable_buttons_vfunc(self);
144 /** This is a convenience function to create a caption containing a mandatory widget.
145 * When the widget is edited, the enable_buttons() vfunc will be called.
147 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
152 HildonCaptionStatus flag)
154 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
156 /* The translated strings seem to already contain the *,
157 * but this code can be used if that is not true in future.
160 /* Add a * character to indicate mandatory fields,
161 * as specified in our "Email UI Specification": */
162 if (flag == HILDON_CAPTION_MANDATORY) {
163 gchar* title = g_strdup_printf("%s*", value);
164 caption = hildon_caption_new (group, title, control, icon, flag);
168 caption = hildon_caption_new (group, value, control, icon, flag);
171 /* Connect to the appropriate changed signal for the widget,
172 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
174 if (GTK_IS_ENTRY (control)) {
175 g_signal_connect (G_OBJECT (control), "changed",
176 G_CALLBACK (on_caption_entry_changed), self);
179 else if (GTK_IS_COMBO_BOX (control)) {
180 g_signal_connect (G_OBJECT (control), "changed",
181 G_CALLBACK (on_caption_combobox_changed), self);
188 create_page_welcome (ModestEasysetupWizardDialog *self)
190 GtkWidget *box = gtk_vbox_new (FALSE, 2);
191 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
192 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
193 gtk_widget_show (label);
194 gtk_widget_show (GTK_WIDGET (box));
195 return GTK_WIDGET (box);
199 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
201 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
203 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
205 /* Fill the providers combo, based on the selected country: */
206 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
207 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
208 easysetup_provider_combo_box_fill (
209 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
213 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
215 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
217 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
219 /* Fill the providers combo, based on the selected country: */
220 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
221 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
223 gchar* domain_name = NULL;
225 domain_name = modest_presets_get_domain (priv->presets, provider_id);
228 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
230 if (self->entry_user_email)
231 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
233 g_free (domain_name);
235 g_free (provider_id);
240 create_page_account_details (ModestEasysetupWizardDialog *self)
242 GtkWidget *box = gtk_vbox_new (FALSE, 2);
243 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
244 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
245 gtk_widget_show (label);
247 /* Create a size group to be used by all captions.
248 * Note that HildonCaption does not create a default size group if we do not specify one.
249 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
250 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
252 /* The country widgets: */
253 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
254 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
255 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
256 gtk_widget_show (self->combo_account_country);
257 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
258 gtk_widget_show (caption);
260 /* connect to country combo's changed signal, so we can fill the provider combo: */
261 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
262 G_CALLBACK (on_combo_account_country), self);
265 /* The service provider widgets: */
266 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
268 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
269 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
270 gtk_widget_show (self->combo_account_serviceprovider);
271 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
272 gtk_widget_show (caption);
274 /* connect to providers combo's changed signal, so we can fill the email address: */
275 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
276 G_CALLBACK (on_combo_account_serviceprovider), self);
278 /* TODO: Default to the current country somehow.
279 * But I don't know how to get the information that is specified in the
280 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
282 * This is probably not the best choice of gconf key:
283 * This is the "mcc used in the last pairing", ie. the last connection you made.
284 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
287 GConfClient *client = gconf_client_get_default ();
288 GError *error = NULL;
289 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
290 gint mcc_id = gconf_client_get_int(client, key, &error);
296 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
297 g_error_free (error);
303 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
304 * This might just be a Maemo bug.
308 /* For now, we default to Finland when there is nothing better: */
312 easysetup_country_combo_box_set_active_country_id (
313 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
316 /* The description widgets: */
317 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
319 /* Set a default account title, choosing one that does not already exist: */
320 gchar* default_acount_name = g_strdup (_("mcen_ia_emailsetup_defaultname"));
321 while (modest_account_mgr_account_exists (self->account_manager,
322 default_acount_name, FALSE /* server_account */)) {
324 gchar * default_account_name2 = util_increment_name (default_acount_name);
325 g_free (default_acount_name);
326 default_acount_name = default_account_name2;
329 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_acount_name);
330 g_free (default_acount_name);
331 default_acount_name = NULL;
333 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
334 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
335 gtk_widget_show (self->entry_account_title);
336 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
337 gtk_widget_show (caption);
339 /* Prevent the use of some characters in the account title,
340 * as required by our UI specification: */
341 GList *list_prevent = NULL;
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, "*");
346 list_prevent = g_list_append (list_prevent, "?");
347 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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 list_prevent = g_list_append (list_prevent, "|");
352 list_prevent = g_list_append (list_prevent, "^");
353 easysetup_validating_entry_set_unallowed_characters (
354 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
355 g_list_free (list_prevent);
357 /* Set max length as in the UI spec:
358 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
359 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
361 gtk_widget_show (GTK_WIDGET (box));
363 return GTK_WIDGET (box);
367 create_page_user_details (ModestEasysetupWizardDialog *self)
369 GtkWidget *box = gtk_vbox_new (FALSE, 2);
371 /* Create a size group to be used by all captions.
372 * Note that HildonCaption does not create a default size group if we do not specify one.
373 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
374 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
376 /* The name widgets: */
377 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
378 /* Set max length as in the UI spec:
379 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
380 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
381 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
382 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
383 gtk_widget_show (self->entry_user_name);
384 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
385 gtk_widget_show (caption);
387 /* Prevent the use of some characters in the name,
388 * as required by our UI specification: */
389 GList *list_prevent = NULL;
390 list_prevent = g_list_append (list_prevent, "<");
391 list_prevent = g_list_append (list_prevent, ">");
392 easysetup_validating_entry_set_unallowed_characters (
393 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
394 g_list_free (list_prevent);
396 /* The username widgets: */
397 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
398 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
399 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
400 gtk_widget_show (self->entry_user_username);
401 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
402 gtk_widget_show (caption);
404 /* Prevent the use of some characters in the username,
405 * as required by our UI specification: */
406 easysetup_validating_entry_set_unallowed_characters_whitespace (
407 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
409 /* Set max length as in the UI spec:
410 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
411 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
413 /* The password widgets: */
414 self->entry_user_password = gtk_entry_new ();
415 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
416 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
417 caption = create_caption_new_with_asterix (self, sizegroup,
418 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
419 gtk_widget_show (self->entry_user_password);
420 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
421 gtk_widget_show (caption);
423 /* The email address widgets: */
424 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
425 caption = create_caption_new_with_asterix (self, sizegroup,
426 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
427 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
428 gtk_widget_show (self->entry_user_email);
429 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
430 gtk_widget_show (caption);
432 /* Set max length as in the UI spec:
433 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
434 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
437 gtk_widget_show (GTK_WIDGET (box));
439 return GTK_WIDGET (box);
442 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
444 GtkWidget *box = gtk_vbox_new (FALSE, 2);
445 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
446 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
447 gtk_widget_show (label);
448 gtk_widget_show (GTK_WIDGET (box));
449 return GTK_WIDGET (box);
452 /** Change the caption title for the incoming server,
453 * as specified in the UI spec:
455 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
457 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
458 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
460 (protocol == MODEST_PROTOCOL_STORE_POP ?
461 _("mail_fi_emailtype_pop3") :
462 _("mail_fi_emailtype_imap") );
465 /* Note that this produces a compiler warning,
466 * because the compiler does not know that the translated string will have a %s in it.
467 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
468 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
469 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
470 g_free(incomingserver_title);
473 /** Change the caption title for the incoming server,
474 * as specified in the UI spec:
476 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
478 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
479 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
481 /* Fill the combo with appropriately titled choices for POP or IMAP. */
482 /* The choices are the same, but the titles are different, as in the UI spec. */
483 easysetup_serversecurity_combo_box_fill (
484 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
487 static void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
489 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
490 update_incoming_server_title (self);
491 update_incoming_server_security_choices (self);
494 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
496 GtkWidget *box = gtk_vbox_new (FALSE, 2);
498 /* Create a size group to be used by all captions.
499 * Note that HildonCaption does not create a default size group if we do not specify one.
500 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
501 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
503 /* The incoming server widgets: */
504 if (!self->combo_incoming_servertype)
505 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
506 easysetup_servertype_combo_box_set_active_servertype (
507 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
508 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
509 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
510 gtk_widget_show (self->combo_incoming_servertype);
511 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
512 gtk_widget_show (caption);
514 if(!self->entry_incomingserver)
515 self->entry_incomingserver = gtk_entry_new ();
516 set_default_custom_servernames (self);
518 if (self->caption_incoming)
519 gtk_widget_destroy (self->caption_incoming);
521 /* The caption title will be updated in update_incoming_server_title().
522 * so this default text will never be seen: */
523 /* (Note: Changing the title seems pointless. murrayc) */
524 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
525 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
526 update_incoming_server_title (self);
527 gtk_widget_show (self->entry_incomingserver);
528 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
529 gtk_widget_show (self->caption_incoming);
531 /* Change the caption title when the servertype changes,
532 * as in the UI spec: */
533 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
534 G_CALLBACK (on_combo_servertype_changed), self);
536 /* The secure connection widgets: */
537 if (!self->combo_incoming_security)
538 self->combo_incoming_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
539 update_incoming_server_security_choices (self);
540 easysetup_serversecurity_combo_box_set_active_serversecurity (
541 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
542 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
543 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
544 gtk_widget_show (self->combo_incoming_security);
545 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
546 gtk_widget_show (caption);
548 if(!self->checkbox_incoming_auth)
549 self->checkbox_incoming_auth =
550 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
551 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
552 gtk_widget_show (self->checkbox_incoming_auth);
554 gtk_widget_show (GTK_WIDGET (box));
556 return GTK_WIDGET (box);
560 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
562 GtkWidget *widget = GTK_WIDGET (user_data);
564 /* Enable the widget only if the toggle button is active: */
565 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
566 gtk_widget_set_sensitive (widget, enable);
569 /* Make the sensitivity of a widget depend on a toggle button.
572 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
574 g_signal_connect (G_OBJECT (button), "toggled",
575 G_CALLBACK (on_toggle_button_changed), widget);
577 /* Set the starting sensitivity: */
578 on_toggle_button_changed (button, widget);
582 on_smtp_servers_window_hide (GtkWindow *window, gpointer user_data)
584 /* Destroy the window when it is closed: */
585 gtk_widget_destroy (GTK_WIDGET (window));
589 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
592 ModestEasysetupWizardDialog * self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
594 /* Show the window: */
595 /* TODO: Retrieve the chosen settings,
596 * so we can supply them when creating the connection somehow.
598 GtkWidget *window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
600 gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
601 g_signal_connect (G_OBJECT (window), "hide",
602 G_CALLBACK (on_smtp_servers_window_hide), self);
603 gtk_widget_show (window);
606 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
608 GtkWidget *box = gtk_vbox_new (FALSE, 2);
610 /* Create a size group to be used by all captions.
611 * Note that HildonCaption does not create a default size group if we do not specify one.
612 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
613 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
615 /* The outgoing server widgets: */
616 if (!self->entry_outgoingserver)
617 self->entry_outgoingserver = gtk_entry_new ();
618 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
619 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
620 gtk_widget_show (self->entry_outgoingserver);
621 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
622 gtk_widget_show (caption);
623 set_default_custom_servernames (self);
625 /* The secure connection widgets: */
626 if (!self->combo_outgoing_security)
627 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
628 easysetup_serversecurity_combo_box_fill (
629 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
630 easysetup_serversecurity_combo_box_set_active_serversecurity (
631 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
632 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
633 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
634 gtk_widget_show (self->combo_outgoing_security);
635 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
636 gtk_widget_show (caption);
638 /* The secure authentication widgets: */
639 if (!self->combo_outgoing_auth)
640 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
641 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
642 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
643 gtk_widget_show (self->combo_outgoing_auth);
644 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
645 gtk_widget_show (caption);
647 /* connection-specific checkbox: */
648 if (!self->checkbox_outgoing_smtp_specific) {
649 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
650 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
653 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
654 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
656 /* Connection-specific SMTP-Severs Edit button: */
657 if (!self->button_outgoing_smtp_servers)
658 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
659 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
660 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
661 gtk_widget_show (self->button_outgoing_smtp_servers);
662 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
663 gtk_widget_show (caption);
665 /* Only enable the button when the checkbox is checked: */
666 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
667 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
669 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
670 G_CALLBACK (on_button_outgoing_smtp_servers), self);
673 gtk_widget_show (GTK_WIDGET (box));
675 return GTK_WIDGET (box);
678 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
680 GtkWidget *box = gtk_vbox_new (FALSE, 2);
681 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
682 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
683 gtk_widget_show (label);
685 if (!self->button_edit)
686 self->button_edit = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
687 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
688 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
689 gtk_widget_show (self->button_edit);
690 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
691 gtk_widget_show (caption);
693 gtk_widget_show (GTK_WIDGET (box));
694 return GTK_WIDGET (box);
701 on_response (ModestWizardDialog *wizard_dialog,
705 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
706 invoke_enable_buttons_vfunc (self);
710 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
712 /* Create the notebook to be used by the ModestWizardDialog base class:
713 * Each page of the notebook will be a page of the wizard: */
714 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
716 /* Set the notebook used by the ModestWizardDialog base class: */
717 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
719 /* Set the wizard title:
720 * The actual window title will be a combination of this and the page's tab label title. */
721 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
723 /* Read in the information about known service providers: */
724 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
726 const gchar* filepath = PROVIDER_DATA_DIR "/provider-data.keyfile";
727 priv->presets = modest_presets_new (filepath); /* TODO: the actual filepath. */
728 if (!(priv->presets))
730 const gchar* filepath_hack = HACK_TOP_SRCDIR "src/maemo/easysetup/provider-data.keyfile";
731 g_warning ("Could not locate the official provider data keyfile from %s, "
732 "so attempting to load it instead from %s", filepath, filepath_hack);
733 priv->presets = modest_presets_new (filepath_hack); /* TODO: the actual filepath. */
736 g_assert(priv->presets);
739 /* Get the account manager object,
740 * so we can check for existing accounts,
741 * and create new accounts: */
742 self->account_manager = modest_runtime_get_account_mgr ();
743 g_assert (self->account_manager);
744 g_object_ref (self->account_manager);
746 /* Create the common pages,
748 self->page_welcome = create_page_welcome (self);
749 self->page_account_details = create_page_account_details (self);
750 self->page_user_details = create_page_user_details (self);
752 /* Add the common pages: */
753 gtk_notebook_append_page (notebook, self->page_welcome,
754 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
755 gtk_notebook_append_page (notebook, self->page_account_details,
756 gtk_label_new (_("mcen_ti_accountdetails")));
757 gtk_notebook_append_page (notebook, self->page_user_details,
758 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
760 /* Create and add the easysetup-specific pages,
761 * because we need _some_ final page to enable the Next and Finish buttons: */
762 create_subsequent_easysetup_pages (self);
765 /* Connect to the dialog's response signal so we can enable/disable buttons
766 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
767 * Note that we use g_signal_connect_after() instead of g_signal_connect()
768 * so that we can be enable/disable after ModestWizardDialog has done its own
769 * enabling/disabling of buttons.
771 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
772 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
774 * It's not enough to connect to the notebook's switch-page signal, because
775 * ModestWizardDialog's "response" signal handler enables the buttons itself,
776 * _after_ switching the page (understandably).
777 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
778 * then gtk_notebook_get_current_page() would return an incorrect value.)
780 g_signal_connect_after (G_OBJECT (self), "response",
781 G_CALLBACK (on_response), self);
784 ModestEasysetupWizardDialog*
785 modest_easysetup_wizard_dialog_new (void)
787 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
790 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
792 GtkNotebook *notebook = NULL;
793 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
796 /* Create the custom pages: */
797 if(!(self->page_custom_incoming)) {
798 self->page_custom_incoming = create_page_custom_incoming (self);
801 if(!(self->page_custom_outgoing)) {
802 self->page_custom_outgoing = create_page_custom_outgoing (self);
805 if(!(self->page_complete_customsetup)) {
806 self->page_complete_customsetup = create_page_complete_custom (self);
809 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
810 gtk_notebook_append_page (notebook, self->page_custom_incoming,
811 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
813 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
814 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
815 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
817 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
818 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
819 gtk_label_new (_("mcen_ti_emailsetup_complete")));
822 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
824 GtkNotebook *notebook = NULL;
825 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
828 /* Create the easysetup-specific pages: */
829 if(!self->page_complete_easysetup)
830 self->page_complete_easysetup = create_page_complete_easysetup (self);
832 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
833 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
834 gtk_label_new (_("mcen_ti_emailsetup_complete")));
837 /* After the user details page,
838 * the following pages depend on whether "Other" was chosen
839 * in the provider combobox on the account page
841 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
843 if (easysetup_provider_combo_box_get_active_provider_id (
844 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
845 /* "Other..." was selected: */
847 /* Make sure that the easysetup pages do not exist: */
848 if(self->page_complete_easysetup) {
849 gtk_widget_destroy (self->page_complete_easysetup);
850 self->page_complete_easysetup = NULL;
853 create_subsequent_customsetup_pages (self);
856 /* A specific provider was selected: */
858 /* Make sure that the custom pages do not exist:
859 * Because they will be used if they exist, when creating the account. */
860 if(self->page_custom_incoming) {
861 gtk_widget_destroy (self->page_custom_incoming);
862 self->page_custom_incoming = NULL;
865 if(self->page_custom_outgoing) {
866 gtk_widget_destroy (self->page_custom_outgoing);
867 self->page_custom_outgoing = NULL;
870 if(self->page_complete_customsetup) {
871 gtk_widget_destroy (self->page_complete_customsetup);
872 self->page_complete_customsetup = NULL;
876 /* Create the easysetup pages: */
877 create_subsequent_easysetup_pages (self);
882 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
887 gchar* at = g_utf8_strchr (email_address, -1, '@');
888 if (!at || (g_utf8_strlen (at, -1) < 2))
891 gchar* domain = g_utf8_next_char (at);
895 const gchar* hostname = NULL;
896 if (servertype == MODEST_PROTOCOL_STORE_POP)
898 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
900 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
906 return g_strdup_printf ("%s.%s", hostname, domain);
909 /* Add a number to the end of the text, or increment a number that is already there.
912 util_increment_name (const gchar* text)
914 /* Get the end character,
915 * also doing a UTF-8 validation which is required for using g_utf8_prev_char().
917 const gchar* end = NULL;
918 if (!g_utf8_validate (text, -1, &end))
924 --end; /* Go to before the null-termination. */
926 /* Look at each UTF-8 characer, starting at the end: */
927 const gchar* p = end;
928 const gchar* alpha_end = NULL;
931 /* Stop when we reach the first character that is not a numeric digit: */
932 const gunichar ch = g_utf8_get_char (p);
933 if (!g_unichar_isdigit (ch)) {
938 p = g_utf8_prev_char (p);
942 /* The text must consist completely of numeric digits. */
948 /* Intepret and increment the number, if any: */
949 gint num = atol (alpha_end);
952 /* Get the name part: */
953 gint name_len = alpha_end - text;
954 gchar *name_without_number = g_malloc(name_len + 1);
955 memcpy (name_without_number, text, name_len);
956 name_without_number[name_len] = 0;\
958 /* Concatenate the text part and the new number: */
959 gchar *result = g_strdup_printf("%s%d", name_without_number, num);
960 g_free (name_without_number);
965 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
967 if (!account_wizard->entry_incomingserver)
970 /* Set a default domain for the server, based on the email address,
971 * if no server name was already specified.
973 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
974 if ((!incoming_existing || (strlen(incoming_existing) == 0))
975 && account_wizard->entry_user_email) {
976 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
977 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
978 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
980 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
981 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
985 /* Set a default domain for the server, based on the email address,
986 * if no server name was already specified.
988 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
989 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
990 && account_wizard->entry_user_email) {
991 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
993 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
994 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
1000 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
1002 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1004 /* Do extra validation that couldn't be done for every key press,
1005 * either because it was too slow,
1006 * or because it requires interaction:
1008 if (current_page == account_wizard->page_account_details) {
1009 /* Check that the title is not already in use: */
1010 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1011 if ((!account_name) || (strlen(account_name) == 0))
1014 gboolean name_in_use = FALSE;
1015 name_in_use = modest_account_mgr_account_exists (account_wizard->account_manager,
1016 account_name, FALSE /* server_account */);
1019 /* Warn the user via a dialog: */
1020 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing."));
1025 else if (current_page == account_wizard->page_user_details) {
1026 /* Check that the email address is valud: */
1027 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1028 if ((!email_address) || (strlen(email_address) == 0))
1031 if (!modest_text_utils_validate_email_address (email_address)) {
1032 /* Warn the user via a dialog: */
1033 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1035 /* Return focus to the email address entry: */
1036 gtk_widget_grab_focus (account_wizard->entry_user_email);
1041 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1042 create_subsequent_pages (account_wizard);
1045 /* TODO: The UI Spec wants us to check that the servernames are valid,
1046 * but does not specify how.
1049 if(next_page == account_wizard->page_custom_incoming) {
1050 set_default_custom_servernames (account_wizard);
1052 else if (next_page == account_wizard->page_custom_outgoing) {
1053 set_default_custom_servernames (account_wizard);
1056 /* If this is the last page, and this is a click on Finish,
1057 * then attempt to create the dialog.
1059 if(!next_page) /* This is NULL when this is a click on Finish. */
1061 create_account (account_wizard);
1068 static gboolean entry_is_empty (GtkWidget *entry)
1073 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1074 if ((!text) || (strlen(text) == 0))
1081 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1083 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1085 gboolean enable_next = TRUE;
1086 if (current_page == account_wizard->page_welcome) {
1089 else if (current_page == account_wizard->page_account_details) {
1090 /* The account details title is mandatory: */
1091 if (entry_is_empty(account_wizard->entry_account_title))
1092 enable_next = FALSE;
1094 else if (current_page == account_wizard->page_user_details) {
1095 /* The user details username is mandatory: */
1096 if (entry_is_empty(account_wizard->entry_user_username))
1097 enable_next = FALSE;
1099 /* The user details email address is mandatory: */
1100 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1101 enable_next = FALSE;
1103 else if (current_page == account_wizard->page_custom_incoming) {
1104 /* The custom incoming server is mandatory: */
1105 if (entry_is_empty(account_wizard->entry_incomingserver))
1106 enable_next = FALSE;
1109 /* Enable the buttons,
1110 * identifying them via their associated response codes:
1112 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1113 gtk_dialog_set_response_sensitive (dialog_base,
1114 MODEST_WIZARD_DIALOG_NEXT,
1117 /* Disable the Finish button until we are on the last page,
1118 * because HildonWizardDialog enables this for all but the first page: */
1119 GtkNotebook *notebook = NULL;
1120 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1122 gint current = gtk_notebook_get_current_page (notebook);
1123 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1124 gboolean is_last = (current == last);
1127 gtk_dialog_set_response_sensitive (dialog_base,
1128 MODEST_WIZARD_DIALOG_FINISH,
1134 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1136 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1137 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1140 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1141 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1142 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1143 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1145 /* Provide a vfunc implementation so we can decide
1146 * when to enable/disable the prev/next buttons.
1148 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1149 base_klass->before_next = on_before_next;
1150 base_klass->enable_buttons = on_enable_buttons;
1154 show_error (GtkWindow *parent_window, const gchar* text)
1156 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1162 gtk_dialog_run (dialog);
1163 gtk_widget_destroy (GTK_WIDGET (dialog));
1166 /** Attempt to create the account from the information that the user has entered.
1167 * @result: TRUE if the account was successfully created.
1170 create_account (ModestEasysetupWizardDialog *self)
1172 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1174 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1180 /* We should have checked for this already,
1181 * and changed that name accordingly,
1182 * but let's check again just in case:
1184 if (modest_account_mgr_account_exists (self->account_manager, account_name, FALSE))
1187 /* username and password (for both incoming and outgoing): */
1188 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1189 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1191 /* Incoming server: */
1192 /* Note: We need something as default for the ModestProtocol values,
1193 * or modest_account_mgr_add_server_account will fail. */
1194 gchar* servername_incoming = NULL;
1195 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1196 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1197 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1199 /* Get details from the specified presets: */
1200 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1201 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1205 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1206 TRUE /* incoming */);
1208 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1209 TRUE /* incoming */);
1212 /* We don't check for SMTP here as that is impossible for an incoming server. */
1213 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1214 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1215 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1216 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1218 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1219 TRUE /* incoming */);
1222 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1223 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1225 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1226 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1229 /* Use custom pages because no preset was specified: */
1230 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1232 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1233 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1235 protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
1236 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1238 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1239 ? MODEST_PROTOCOL_AUTH_PASSWORD
1240 : MODEST_PROTOCOL_AUTH_NONE;
1244 /* First we add the 2 server accounts, and then we add the account that uses them.
1245 * If we don't do it in this order then we will experience a crash. */
1247 /* Add a (incoming) server account, to be used by the account: */
1248 gchar *store_name = g_strconcat (account_name, "_store", NULL);
1249 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1251 servername_incoming,
1254 protocol_security_incoming,
1255 protocol_authentication_incoming);
1257 g_free (servername_incoming);
1260 /* TODO: Provide a Logical ID for the text: */
1261 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1266 /* There must be at least one account now: */
1267 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1268 if(account_names != NULL)
1270 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1272 g_slist_free (account_names);
1275 /* Outgoing server: */
1276 gchar* servername_outgoing = NULL;
1277 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1278 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1279 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1283 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1284 FALSE /* incoming */);
1286 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1287 FALSE /* incoming */);
1289 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1290 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1291 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1292 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1294 ModestPresetsSecurity security_outgoing =
1295 modest_presets_get_info_server_security (priv->presets, provider_id,
1296 FALSE /* incoming */);
1298 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1299 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1300 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1302 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1303 /* TODO: There is no SMTP authentication enum for presets. */
1306 /* Use custom pages because no preset was specified: */
1307 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1309 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1311 protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
1312 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1314 protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
1315 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1318 gboolean specific = gtk_toggle_button_get_active (
1319 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1324 /* Add a (outgoing) server account to be used by the account: */
1325 gchar *transport_name = g_strconcat (account_name, "_transport", NULL); /* What is this good for? */
1326 created = modest_account_mgr_add_server_account (self->account_manager,
1328 servername_outgoing,
1331 protocol_security_outgoing,
1332 protocol_authentication_outgoing);
1334 g_free (servername_outgoing);
1337 /* TODO: Provide a Logical ID for the text: */
1338 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1343 /* Create the account, which will contain the two "server accounts": */
1344 created = modest_account_mgr_add_account (self->account_manager, account_name,
1345 store_name, /* The name of our POP/IMAP server account. */
1346 transport_name /* The name of our SMTP server account. */);
1347 g_free (store_name);
1348 g_free (transport_name);
1351 /* TODO: Provide a Logical ID for the text: */
1352 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));
1356 /* The user name and email address must be set additionally: */
1357 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (self->entry_user_name));
1358 modest_account_mgr_set_string (self->account_manager, account_name,
1359 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1361 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
1362 modest_account_mgr_set_string (self->account_manager, account_name,
1363 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1365 /* TODO: Should we set MODEST_ACCOUNT_DISPLAY_NAME? It's not clear what it is. */