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 gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
598 g_signal_connect (G_OBJECT (window), "hide",
599 G_CALLBACK (on_smtp_servers_window_hide), self);
600 gtk_widget_show (window);
603 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
605 GtkWidget *box = gtk_vbox_new (FALSE, 2);
607 /* Create a size group to be used by all captions.
608 * Note that HildonCaption does not create a default size group if we do not specify one.
609 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
610 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
612 /* The outgoing server widgets: */
613 if (!self->entry_outgoingserver)
614 self->entry_outgoingserver = gtk_entry_new ();
615 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
616 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
617 gtk_widget_show (self->entry_outgoingserver);
618 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
619 gtk_widget_show (caption);
620 set_default_custom_servernames (self);
622 /* The secure connection widgets: */
623 if (!self->combo_outgoing_security)
624 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
625 easysetup_serversecurity_combo_box_fill (
626 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
627 easysetup_serversecurity_combo_box_set_active_serversecurity (
628 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
629 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
630 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
631 gtk_widget_show (self->combo_outgoing_security);
632 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
633 gtk_widget_show (caption);
635 /* The secure authentication widgets: */
636 if (!self->combo_outgoing_auth)
637 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
638 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
639 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
640 gtk_widget_show (self->combo_outgoing_auth);
641 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
642 gtk_widget_show (caption);
644 /* connection-specific checkbox: */
645 if (!self->checkbox_outgoing_smtp_specific) {
646 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
647 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
650 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
651 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
653 /* Connection-specific SMTP-Severs Edit button: */
654 if (!self->button_outgoing_smtp_servers)
655 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
656 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
657 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
658 gtk_widget_show (self->button_outgoing_smtp_servers);
659 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
660 gtk_widget_show (caption);
662 /* Only enable the button when the checkbox is checked: */
663 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
664 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
666 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
667 G_CALLBACK (on_button_outgoing_smtp_servers), self);
670 gtk_widget_show (GTK_WIDGET (box));
672 return GTK_WIDGET (box);
675 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
677 GtkWidget *box = gtk_vbox_new (FALSE, 2);
678 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
679 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
680 gtk_widget_show (label);
682 if (!self->button_edit)
683 self->button_edit = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
684 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
685 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
686 gtk_widget_show (self->button_edit);
687 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
688 gtk_widget_show (caption);
690 gtk_widget_show (GTK_WIDGET (box));
691 return GTK_WIDGET (box);
698 on_response (ModestWizardDialog *wizard_dialog,
702 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
703 invoke_enable_buttons_vfunc (self);
707 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
709 /* Create the notebook to be used by the ModestWizardDialog base class:
710 * Each page of the notebook will be a page of the wizard: */
711 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
713 /* Set the notebook used by the ModestWizardDialog base class: */
714 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
716 /* Set the wizard title:
717 * The actual window title will be a combination of this and the page's tab label title. */
718 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
720 /* Read in the information about known service providers: */
721 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
723 const gchar* filepath = "/usr/share/operator-wizard/provider-data.keyfile";
724 priv->presets = modest_presets_new (filepath); /* TODO: the actual filepath. */
725 if (!(priv->presets))
727 const gchar* filepath_hack = "./src/maemo/easysetup/provider-data-test.keyfile";
728 g_warning ("Could not locate the official provider data keyfile from %s, "
729 "so attempting to load it instead from %s", filepath, filepath_hack);
730 priv->presets = modest_presets_new (filepath_hack); /* TODO: the actual filepath. */
733 g_assert(priv->presets);
736 /* Get the account manager object,
737 * so we can check for existing accounts,
738 * and create new accounts: */
739 self->account_manager = modest_runtime_get_account_mgr ();
740 g_assert (self->account_manager);
741 g_object_ref (self->account_manager);
743 /* Create the common pages,
745 self->page_welcome = create_page_welcome (self);
746 self->page_account_details = create_page_account_details (self);
747 self->page_user_details = create_page_user_details (self);
749 /* Add the common pages: */
750 gtk_notebook_append_page (notebook, self->page_welcome,
751 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
752 gtk_notebook_append_page (notebook, self->page_account_details,
753 gtk_label_new (_("mcen_ti_accountdetails")));
754 gtk_notebook_append_page (notebook, self->page_user_details,
755 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
757 /* Create and add the easysetup-specific pages,
758 * because we need _some_ final page to enable the Next and Finish buttons: */
759 create_subsequent_easysetup_pages (self);
762 /* Connect to the dialog's response signal so we can enable/disable buttons
763 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
764 * Note that we use g_signal_connect_after() instead of g_signal_connect()
765 * so that we can be enable/disable after ModestWizardDialog has done its own
766 * enabling/disabling of buttons.
768 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
769 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
771 * It's not enough to connect to the notebook's switch-page signal, because
772 * ModestWizardDialog's "response" signal handler enables the buttons itself,
773 * _after_ switching the page (understandably).
774 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
775 * then gtk_notebook_get_current_page() would return an incorrect value.)
777 g_signal_connect_after (G_OBJECT (self), "response",
778 G_CALLBACK (on_response), self);
781 ModestEasysetupWizardDialog*
782 modest_easysetup_wizard_dialog_new (void)
784 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
787 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
789 GtkNotebook *notebook = NULL;
790 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
793 /* Create the custom pages: */
794 if(!(self->page_custom_incoming)) {
795 self->page_custom_incoming = create_page_custom_incoming (self);
798 if(!(self->page_custom_outgoing)) {
799 self->page_custom_outgoing = create_page_custom_outgoing (self);
802 if(!(self->page_complete_customsetup)) {
803 self->page_complete_customsetup = create_page_complete_custom (self);
806 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
807 gtk_notebook_append_page (notebook, self->page_custom_incoming,
808 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
810 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
811 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
812 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
814 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
815 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
816 gtk_label_new (_("mcen_ti_emailsetup_complete")));
819 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
821 GtkNotebook *notebook = NULL;
822 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
825 /* Create the easysetup-specific pages: */
826 if(!self->page_complete_easysetup)
827 self->page_complete_easysetup = create_page_complete_easysetup (self);
829 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
830 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
831 gtk_label_new (_("mcen_ti_emailsetup_complete")));
834 /* After the user details page,
835 * the following pages depend on whether "Other" was chosen
836 * in the provider combobox on the account page
838 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
840 if (easysetup_provider_combo_box_get_active_provider_id (
841 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
842 /* "Other..." was selected: */
844 /* Make sure that the easysetup pages do not exist: */
845 if(self->page_complete_easysetup) {
846 gtk_widget_destroy (self->page_complete_easysetup);
847 self->page_complete_easysetup = NULL;
850 create_subsequent_customsetup_pages (self);
853 /* A specific provider was selected: */
855 /* Make sure that the custom pages do not exist:
856 * Because they will be used if they exist, when creating the account. */
857 if(self->page_custom_incoming) {
858 gtk_widget_destroy (self->page_custom_incoming);
859 self->page_custom_incoming = NULL;
862 if(self->page_custom_outgoing) {
863 gtk_widget_destroy (self->page_custom_outgoing);
864 self->page_custom_outgoing = NULL;
867 if(self->page_complete_customsetup) {
868 gtk_widget_destroy (self->page_complete_customsetup);
869 self->page_complete_customsetup = NULL;
873 /* Create the easysetup pages: */
874 create_subsequent_easysetup_pages (self);
879 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
884 gchar* at = g_utf8_strchr (email_address, -1, '@');
885 if (!at || (g_utf8_strlen (at, -1) < 2))
888 gchar* domain = g_utf8_next_char (at);
892 const gchar* hostname = NULL;
893 if (servertype == MODEST_PROTOCOL_STORE_POP)
895 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
897 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
903 return g_strdup_printf ("%s.%s", hostname, domain);
906 /* Add a number to the end of the text, or increment a number that is already there.
909 util_increment_name (const gchar* text)
911 /* Get the end character,
912 * also doing a UTF-8 validation which is required for using g_utf8_prev_char().
914 const gchar* end = NULL;
915 if (!g_utf8_validate (text, -1, &end))
921 --end; /* Go to before the null-termination. */
923 /* Look at each UTF-8 characer, starting at the end: */
924 const gchar* p = end;
925 const gchar* alpha_end = NULL;
928 /* Stop when we reach the first character that is not a numeric digit: */
929 const gunichar ch = g_utf8_get_char (p);
930 if (!g_unichar_isdigit (ch)) {
935 p = g_utf8_prev_char (p);
939 /* The text must consist completely of numeric digits. */
945 /* Intepret and increment the number, if any: */
946 gint num = atol (alpha_end);
949 /* Get the name part: */
950 gint name_len = alpha_end - text;
951 gchar *name_without_number = g_malloc(name_len + 1);
952 memcpy (name_without_number, text, name_len);
953 name_without_number[name_len] = 0;\
955 /* Concatenate the text part and the new number: */
956 gchar *result = g_strdup_printf("%s%d", name_without_number, num);
957 g_free (name_without_number);
962 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
964 if (!account_wizard->entry_incomingserver)
967 /* Set a default domain for the server, based on the email address,
968 * if no server name was already specified.
970 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
971 if ((!incoming_existing || (strlen(incoming_existing) == 0))
972 && account_wizard->entry_user_email) {
973 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
974 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
975 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
977 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
978 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
982 /* Set a default domain for the server, based on the email address,
983 * if no server name was already specified.
985 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
986 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
987 && account_wizard->entry_user_email) {
988 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
990 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
991 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
997 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
999 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1001 /* Do extra validation that couldn't be done for every key press,
1002 * either because it was too slow,
1003 * or because it requires interaction:
1005 if (current_page == account_wizard->page_account_details) {
1006 /* Check that the title is not already in use: */
1007 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
1008 if ((!account_name) || (strlen(account_name) == 0))
1011 gboolean name_in_use = FALSE;
1012 name_in_use = modest_account_mgr_account_exists (account_wizard->account_manager,
1013 account_name, TRUE /* server_account */);
1016 /* Warn the user via a dialog: */
1017 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing."));
1022 else if (current_page == account_wizard->page_user_details) {
1023 /* Check that the email address is valud: */
1024 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
1025 if ((!email_address) || (strlen(email_address) == 0))
1028 if (!modest_text_utils_validate_email_address (email_address)) {
1029 /* Warn the user via a dialog: */
1030 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1032 /* Return focus to the email address entry: */
1033 gtk_widget_grab_focus (account_wizard->entry_user_email);
1038 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1039 create_subsequent_pages (account_wizard);
1042 /* TODO: The UI Spec wants us to check that the servernames are valid,
1043 * but does not specify how.
1046 if(next_page == account_wizard->page_custom_incoming) {
1047 set_default_custom_servernames (account_wizard);
1049 else if (next_page == account_wizard->page_custom_outgoing) {
1050 set_default_custom_servernames (account_wizard);
1053 /* If this is the last page, and this is a click on Finish,
1054 * then attempt to create the dialog.
1056 if(!next_page) /* This is NULL when this is a click on Finish. */
1058 create_account (account_wizard);
1065 static gboolean entry_is_empty (GtkWidget *entry)
1070 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1071 if ((!text) || (strlen(text) == 0))
1078 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1080 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1082 gboolean enable_next = TRUE;
1083 if (current_page == account_wizard->page_welcome) {
1086 else if (current_page == account_wizard->page_account_details) {
1087 /* The account details title is mandatory: */
1088 if (entry_is_empty(account_wizard->entry_account_title))
1089 enable_next = FALSE;
1091 else if (current_page == account_wizard->page_user_details) {
1092 /* The user details username is mandatory: */
1093 if (entry_is_empty(account_wizard->entry_user_username))
1094 enable_next = FALSE;
1096 /* The user details email address is mandatory: */
1097 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1098 enable_next = FALSE;
1100 else if (current_page == account_wizard->page_custom_incoming) {
1101 /* The custom incoming server is mandatory: */
1102 if (entry_is_empty(account_wizard->entry_incomingserver))
1103 enable_next = FALSE;
1106 /* Enable the buttons,
1107 * identifying them via their associated response codes:
1109 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1110 gtk_dialog_set_response_sensitive (dialog_base,
1111 MODEST_WIZARD_DIALOG_NEXT,
1114 /* Disable the Finish button until we are on the last page,
1115 * because HildonWizardDialog enables this for all but the first page: */
1116 GtkNotebook *notebook = NULL;
1117 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1119 gint current = gtk_notebook_get_current_page (notebook);
1120 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1121 gboolean is_last = (current == last);
1124 gtk_dialog_set_response_sensitive (dialog_base,
1125 MODEST_WIZARD_DIALOG_FINISH,
1131 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1133 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1134 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1137 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1138 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1139 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1140 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1142 /* Provide a vfunc implementation so we can decide
1143 * when to enable/disable the prev/next buttons.
1145 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1146 base_klass->before_next = on_before_next;
1147 base_klass->enable_buttons = on_enable_buttons;
1151 show_error (GtkWindow *parent_window, const gchar* text)
1153 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1159 gtk_dialog_run (dialog);
1160 gtk_widget_destroy (GTK_WIDGET (dialog));
1163 /** Attempt to create the account from the information that the user has entered.
1164 * @result: TRUE if the account was successfully created.
1167 create_account (ModestEasysetupWizardDialog *self)
1169 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1171 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1177 /* We should have checked for this already,
1178 * and changed that name accordingly,
1179 * but let's check again just in case:
1181 if (modest_account_mgr_account_exists (self->account_manager, account_name, FALSE))
1184 /* username and password (for both incoming and outgoing): */
1185 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1186 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1188 /* Incoming server: */
1189 /* Note: We need something as default for the ModestProtocol values,
1190 * or modest_account_mgr_add_server_account will fail. */
1191 gchar* servername_incoming = NULL;
1192 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1193 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1194 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1196 /* Get details from the specified presets: */
1197 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1198 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1202 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1203 TRUE /* incoming */);
1205 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1206 TRUE /* incoming */);
1209 /* We don't check for SMTP here as that is impossible for an incoming server. */
1210 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1211 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1212 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1213 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1215 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1216 TRUE /* incoming */);
1219 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1220 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1222 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1223 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1226 /* Use custom pages because no preset was specified: */
1227 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1229 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1230 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1232 protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
1233 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1235 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1236 ? MODEST_PROTOCOL_AUTH_PASSWORD
1237 : MODEST_PROTOCOL_AUTH_NONE;
1241 /* First we add the 2 server accounts, and then we add the account that uses them.
1242 * If we don't do it in this order then we will experience a crash. */
1244 /* Add a (incoming) server account, to be used by the account: */
1245 gchar *store_name = g_strconcat (account_name, "_store", NULL);
1246 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1248 servername_incoming,
1251 protocol_security_incoming,
1252 protocol_authentication_incoming);
1254 g_free (servername_incoming);
1257 /* TODO: Provide a Logical ID for the text: */
1258 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1263 /* There must be at least one account now: */
1264 GSList *account_names = modest_account_mgr_account_names (self->account_manager);
1265 if(account_names != NULL)
1267 g_warning ("modest_account_mgr_account_names() returned NULL after adding an account.");
1269 g_slist_free (account_names);
1272 /* Outgoing server: */
1273 gchar* servername_outgoing = NULL;
1274 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1275 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1276 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1280 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1281 FALSE /* incoming */);
1283 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1284 FALSE /* incoming */);
1286 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1287 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1288 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1289 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1291 ModestPresetsSecurity security_outgoing =
1292 modest_presets_get_info_server_security (priv->presets, provider_id,
1293 FALSE /* incoming */);
1295 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1296 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1297 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1299 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1300 /* TODO: There is no SMTP authentication enum for presets. */
1303 /* Use custom pages because no preset was specified: */
1304 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1306 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1308 protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
1309 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1311 protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
1312 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1315 gboolean specific = gtk_toggle_button_get_active (
1316 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1321 /* Add a (outgoing) server account to be used by the account: */
1322 gchar *transport_name = g_strconcat (account_name, "_transport", NULL); /* What is this good for? */
1323 created = modest_account_mgr_add_server_account (self->account_manager,
1325 servername_outgoing,
1328 protocol_security_outgoing,
1329 protocol_authentication_outgoing);
1331 g_free (servername_outgoing);
1334 /* TODO: Provide a Logical ID for the text: */
1335 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));
1340 /* Create the account, which will contain the two "server accounts": */
1341 created = modest_account_mgr_add_account (self->account_manager, account_name,
1342 store_name, /* The name of our POP/IMAP server account. */
1343 transport_name /* The name of our SMTP server account. */);
1344 g_free (store_name);
1345 g_free (transport_name);
1348 /* TODO: Provide a Logical ID for the text: */
1349 show_error (GTK_WINDOW (self), _("An error occurred while creating the account."));