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 "modest-easysetup-country-combo-box.h"
19 #include "modest-easysetup-provider-combo-box.h"
20 #include "modest-easysetup-servertype-combo-box.h"
21 #include "modest-easysetup-serversecurity-combo-box.h"
22 #include "modest-easysetup-secureauth-combo-box.h"
23 #include "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 <gconf/gconf-client.h>
28 #include <string.h> /* For strlen(). */
30 /* Include config.h so that _() works: */
35 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
37 G_DEFINE_TYPE (ModestEasysetupWizardDialog, modest_easysetup_wizard_dialog, MODEST_TYPE_WIZARD_DIALOG);
39 #define WIZARD_DIALOG_GET_PRIVATE(o) \
40 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, ModestEasysetupWizardDialogPrivate))
42 typedef struct _ModestEasysetupWizardDialogPrivate ModestEasysetupWizardDialogPrivate;
44 struct _ModestEasysetupWizardDialogPrivate
46 ModestPresets *presets;
50 modest_easysetup_wizard_dialog_get_property (GObject *object, guint property_id,
51 GValue *value, GParamSpec *pspec)
53 switch (property_id) {
55 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
60 modest_easysetup_wizard_dialog_set_property (GObject *object, guint property_id,
61 const GValue *value, GParamSpec *pspec)
63 switch (property_id) {
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
70 modest_easysetup_wizard_dialog_dispose (GObject *object)
72 if (G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose)
73 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->dispose (object);
77 modest_easysetup_wizard_dialog_finalize (GObject *object)
79 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (object);
80 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
82 if (self->account_manager)
83 g_object_unref (G_OBJECT (self->account_manager));
86 modest_presets_destroy (priv->presets);
88 G_OBJECT_CLASS (modest_easysetup_wizard_dialog_parent_class)->finalize (object);
92 show_error (GtkWindow *parent_window, const gchar* text);
95 create_account (ModestEasysetupWizardDialog *self);
98 create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
101 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
104 util_increment_name (const gchar* text);
107 invoke_enable_buttons_vfunc (ModestEasysetupWizardDialog *wizard_dialog)
109 ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
111 /* Call the vfunc, which may be overridden by derived classes: */
112 if (klass->enable_buttons) {
113 GtkNotebook *notebook = NULL;
114 g_object_get (wizard_dialog, "wizard-notebook", ¬ebook, NULL);
116 const gint current_page_num = gtk_notebook_get_current_page (notebook);
117 if (current_page_num == -1)
120 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (notebook, current_page_num);
121 (*(klass->enable_buttons))(MODEST_WIZARD_DIALOG (wizard_dialog), current_page_widget);
126 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
128 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
130 invoke_enable_buttons_vfunc(self);
134 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
136 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
138 invoke_enable_buttons_vfunc(self);
141 /** This is a convenience function to create a caption containing a mandatory widget.
142 * When the widget is edited, the enable_buttons() vfunc will be called.
144 static GtkWidget* create_caption_new_with_asterix(ModestEasysetupWizardDialog *self,
149 HildonCaptionStatus flag)
151 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
153 /* The translated strings seem to already contain the *,
154 * but this code can be used if that is not true in future.
157 /* Add a * character to indicate mandatory fields,
158 * as specified in our "Email UI Specification": */
159 if (flag == HILDON_CAPTION_MANDATORY) {
160 gchar* title = g_strdup_printf("%s*", value);
161 caption = hildon_caption_new (group, title, control, icon, flag);
165 caption = hildon_caption_new (group, value, control, icon, flag);
168 /* Connect to the appropriate changed signal for the widget,
169 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
171 if (GTK_IS_ENTRY (control)) {
172 g_signal_connect (G_OBJECT (control), "changed",
173 G_CALLBACK (on_caption_entry_changed), self);
176 else if (GTK_IS_COMBO_BOX (control)) {
177 g_signal_connect (G_OBJECT (control), "changed",
178 G_CALLBACK (on_caption_combobox_changed), self);
185 create_page_welcome (ModestEasysetupWizardDialog *self)
187 GtkWidget *box = gtk_vbox_new (FALSE, 2);
188 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_intro"));
189 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
190 gtk_widget_show (label);
191 gtk_widget_show (GTK_WIDGET (box));
192 return GTK_WIDGET (box);
196 on_combo_account_country (GtkComboBox *widget, gpointer user_data)
198 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
200 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
202 /* Fill the providers combo, based on the selected country: */
203 gint mcc_id = easysetup_country_combo_box_get_active_country_id (
204 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country));
205 easysetup_provider_combo_box_fill (
206 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider), priv->presets, mcc_id);
210 on_combo_account_serviceprovider (GtkComboBox *widget, gpointer user_data)
212 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
214 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
216 /* Fill the providers combo, based on the selected country: */
217 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
218 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
220 gchar* domain_name = NULL;
222 domain_name = modest_presets_get_domain (priv->presets, provider_id);
225 domain_name = g_strdup (EXAMPLE_EMAIL_ADDRESS);
227 if (self->entry_user_email)
228 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), domain_name);
230 g_free (domain_name);
232 g_free (provider_id);
237 create_page_account_details (ModestEasysetupWizardDialog *self)
239 GtkWidget *box = gtk_vbox_new (FALSE, 2);
240 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
241 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
242 gtk_widget_show (label);
244 /* Create a size group to be used by all captions.
245 * Note that HildonCaption does not create a default size group if we do not specify one.
246 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
247 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
249 /* The country widgets: */
250 self->combo_account_country = GTK_WIDGET (easysetup_country_combo_box_new ());
251 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_country"),
252 self->combo_account_country, NULL, HILDON_CAPTION_OPTIONAL);
253 gtk_widget_show (self->combo_account_country);
254 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
255 gtk_widget_show (caption);
257 /* connect to country combo's changed signal, so we can fill the provider combo: */
258 g_signal_connect (G_OBJECT (self->combo_account_country), "changed",
259 G_CALLBACK (on_combo_account_country), self);
262 /* The service provider widgets: */
263 self->combo_account_serviceprovider = GTK_WIDGET (easysetup_provider_combo_box_new ());
265 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_serviceprovider"),
266 self->combo_account_serviceprovider, NULL, HILDON_CAPTION_OPTIONAL);
267 gtk_widget_show (self->combo_account_serviceprovider);
268 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
269 gtk_widget_show (caption);
271 /* connect to providers combo's changed signal, so we can fill the email address: */
272 g_signal_connect (G_OBJECT (self->combo_account_serviceprovider), "changed",
273 G_CALLBACK (on_combo_account_serviceprovider), self);
275 /* TODO: Default to the current country somehow.
276 * But I don't know how to get the information that is specified in the
277 * "Language and region" control panel. It does not seem be anywhere in gconf. murrayc.
279 * This is probably not the best choice of gconf key:
280 * This is the "mcc used in the last pairing", ie. the last connection you made.
281 * set by the osso-operator-wizard package, suggested by Dirk-Jan Binnema.
284 GConfClient *client = gconf_client_get_default ();
285 GError *error = NULL;
286 const gchar* key = "/apps/osso/operator-wizard/last_mcc";
287 gint mcc_id = gconf_client_get_int(client, key, &error);
293 g_warning ("Error getting gconf key %s:\n%s", key, error->message);
294 g_error_free (error);
300 /* Note that gconf_client_get_int() seems to return 0 without an error if the key is not there
301 * This might just be a Maemo bug.
305 /* For now, we default to Finland when there is nothing better: */
309 easysetup_country_combo_box_set_active_country_id (
310 EASYSETUP_COUNTRY_COMBO_BOX (self->combo_account_country), mcc_id);
313 /* The description widgets: */
314 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
316 /* Set a default account title, choosing one that does not already exist: */
317 gchar* default_acount_name = g_strdup (_("mcen_ia_emailsetup_defaultname"));
318 while (modest_account_mgr_account_exists (self->account_manager,
319 default_acount_name, TRUE /* server_account */)) {
321 gchar * default_account_name2 = util_increment_name (default_acount_name);
322 g_free (default_acount_name);
323 default_acount_name = default_account_name2;
326 gtk_entry_set_text( GTK_ENTRY (self->entry_account_title), default_acount_name);
327 g_free (default_acount_name);
328 default_acount_name = NULL;
330 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
331 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
332 gtk_widget_show (self->entry_account_title);
333 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
334 gtk_widget_show (caption);
336 /* Prevent the use of some characters in the account title,
337 * as required by our UI specification: */
338 GList *list_prevent = NULL;
339 list_prevent = g_list_append (list_prevent, "\\");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
345 list_prevent = g_list_append (list_prevent, "“");
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 easysetup_validating_entry_set_unallowed_characters (
351 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
352 g_list_free (list_prevent);
354 /* Set max length as in the UI spec:
355 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
356 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
358 gtk_widget_show (GTK_WIDGET (box));
360 return GTK_WIDGET (box);
364 create_page_user_details (ModestEasysetupWizardDialog *self)
366 GtkWidget *box = gtk_vbox_new (FALSE, 2);
368 /* Create a size group to be used by all captions.
369 * Note that HildonCaption does not create a default size group if we do not specify one.
370 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
371 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
373 /* The name widgets: */
374 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
375 /* Set max length as in the UI spec:
376 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
377 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
378 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
379 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
380 gtk_widget_show (self->entry_user_name);
381 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
382 gtk_widget_show (caption);
384 /* Prevent the use of some characters in the name,
385 * as required by our UI specification: */
386 GList *list_prevent = NULL;
387 list_prevent = g_list_append (list_prevent, "<");
388 list_prevent = g_list_append (list_prevent, ">");
389 easysetup_validating_entry_set_unallowed_characters (
390 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
391 g_list_free (list_prevent);
393 /* The username widgets: */
394 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
395 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
396 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
397 gtk_widget_show (self->entry_user_username);
398 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
399 gtk_widget_show (caption);
401 /* Prevent the use of some characters in the username,
402 * as required by our UI specification: */
403 easysetup_validating_entry_set_unallowed_characters_whitespace (
404 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
406 /* Set max length as in the UI spec:
407 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
408 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
410 /* The password widgets: */
411 self->entry_user_password = gtk_entry_new ();
412 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
413 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
414 caption = create_caption_new_with_asterix (self, sizegroup,
415 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
416 gtk_widget_show (self->entry_user_password);
417 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
418 gtk_widget_show (caption);
420 /* The email address widgets: */
421 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
422 caption = create_caption_new_with_asterix (self, sizegroup,
423 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
424 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
425 gtk_widget_show (self->entry_user_email);
426 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
427 gtk_widget_show (caption);
429 /* Set max length as in the UI spec:
430 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
431 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
434 gtk_widget_show (GTK_WIDGET (box));
436 return GTK_WIDGET (box);
439 static GtkWidget* create_page_complete_easysetup (ModestEasysetupWizardDialog *self)
441 GtkWidget *box = gtk_vbox_new (FALSE, 2);
442 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
443 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
444 gtk_widget_show (label);
445 gtk_widget_show (GTK_WIDGET (box));
446 return GTK_WIDGET (box);
449 /** Change the caption title for the incoming server,
450 * as specified in the UI spec:
452 static void update_incoming_server_title (ModestEasysetupWizardDialog *self)
454 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
455 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
457 (protocol == MODEST_PROTOCOL_STORE_POP ?
458 _("mail_fi_emailtype_pop3") :
459 _("mail_fi_emailtype_imap") );
462 /* Note that this produces a compiler warning,
463 * because the compiler does not know that the translated string will have a %s in it.
464 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
465 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
466 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
467 g_free(incomingserver_title);
470 /** Change the caption title for the incoming server,
471 * as specified in the UI spec:
473 static void update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
475 ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
476 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
478 /* Fill the combo with appropriately titled choices for POP or IMAP. */
479 /* The choices are the same, but the titles are different, as in the UI spec. */
480 easysetup_serversecurity_combo_box_fill (
481 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
484 void on_combo_servertype_changed(GtkComboBox *combobox, gpointer user_data)
486 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
487 update_incoming_server_title (self);
488 update_incoming_server_security_choices (self);
491 static GtkWidget* create_page_custom_incoming (ModestEasysetupWizardDialog *self)
493 GtkWidget *box = gtk_vbox_new (FALSE, 2);
495 /* Create a size group to be used by all captions.
496 * Note that HildonCaption does not create a default size group if we do not specify one.
497 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
498 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
500 /* The incoming server widgets: */
501 if (!self->combo_incoming_servertype)
502 self->combo_incoming_servertype = GTK_WIDGET (easysetup_servertype_combo_box_new ());
503 easysetup_servertype_combo_box_set_active_servertype (
504 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype), MODEST_PROTOCOL_STORE_POP);
505 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
506 _("mcen_li_emailsetup_type"), self->combo_incoming_servertype, NULL, HILDON_CAPTION_MANDATORY);
507 gtk_widget_show (self->combo_incoming_servertype);
508 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
509 gtk_widget_show (caption);
511 if(!self->entry_incomingserver)
512 self->entry_incomingserver = gtk_entry_new ();
513 set_default_custom_servernames (self);
515 if (self->caption_incoming)
516 gtk_widget_destroy (self->caption_incoming);
518 /* The caption title will be updated in update_incoming_server_title().
519 * so this default text will never be seen: */
520 /* (Note: Changing the title seems pointless. murrayc) */
521 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
522 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
523 update_incoming_server_title (self);
524 gtk_widget_show (self->entry_incomingserver);
525 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
526 gtk_widget_show (self->caption_incoming);
528 /* Change the caption title when the servertype changes,
529 * as in the UI spec: */
530 g_signal_connect (G_OBJECT (self->combo_incoming_servertype), "changed",
531 G_CALLBACK (on_combo_servertype_changed), self);
533 /* The secure connection widgets: */
534 if (!self->combo_incoming_security)
535 self->combo_incoming_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
536 update_incoming_server_security_choices (self);
537 easysetup_serversecurity_combo_box_set_active_serversecurity (
538 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
539 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
540 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
541 gtk_widget_show (self->combo_incoming_security);
542 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
543 gtk_widget_show (caption);
545 if(!self->checkbox_incoming_auth)
546 self->checkbox_incoming_auth =
547 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
548 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
549 gtk_widget_show (self->checkbox_incoming_auth);
551 gtk_widget_show (GTK_WIDGET (box));
553 return GTK_WIDGET (box);
557 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
559 GtkWidget *widget = GTK_WIDGET (user_data);
561 /* Enable the widget only if the toggle button is active: */
562 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
563 gtk_widget_set_sensitive (widget, enable);
566 /* Make the sensitivity of a widget depend on a toggle button.
569 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
571 g_signal_connect (G_OBJECT (button), "toggled",
572 G_CALLBACK (on_toggle_button_changed), widget);
574 /* Set the starting sensitivity: */
575 on_toggle_button_changed (button, widget);
578 static GtkWidget* create_page_custom_outgoing (ModestEasysetupWizardDialog *self)
580 GtkWidget *box = gtk_vbox_new (FALSE, 2);
582 /* Create a size group to be used by all captions.
583 * Note that HildonCaption does not create a default size group if we do not specify one.
584 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
585 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
587 /* The outgoing server widgets: */
588 if (!self->entry_outgoingserver)
589 self->entry_outgoingserver = gtk_entry_new ();
590 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
591 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
592 gtk_widget_show (self->entry_outgoingserver);
593 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
594 gtk_widget_show (caption);
595 set_default_custom_servernames (self);
597 /* The secure connection widgets: */
598 if (!self->combo_outgoing_security)
599 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
600 easysetup_serversecurity_combo_box_fill (
601 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
602 easysetup_serversecurity_combo_box_set_active_serversecurity (
603 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
604 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
605 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
606 gtk_widget_show (self->combo_outgoing_security);
607 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
608 gtk_widget_show (caption);
610 /* The secure authentication widgets: */
611 if (!self->combo_outgoing_auth)
612 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
613 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
614 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
615 gtk_widget_show (self->combo_outgoing_auth);
616 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
617 gtk_widget_show (caption);
619 /* connection-specific checkbox: */
620 if (!self->checkbox_outgoing_smtp_specific) {
621 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
622 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
625 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
626 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
628 /* Connection-specific SMTP-Severs Edit button: */
629 if (!self->button_outgoing_smtp_servers)
630 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
631 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
632 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
633 gtk_widget_show (self->button_outgoing_smtp_servers);
634 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
635 gtk_widget_show (caption);
637 /* Only enable the button when the checkbox is checked: */
638 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
639 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
642 gtk_widget_show (GTK_WIDGET (box));
644 return GTK_WIDGET (box);
647 static GtkWidget* create_page_complete_custom (ModestEasysetupWizardDialog *self)
649 GtkWidget *box = gtk_vbox_new (FALSE, 2);
650 GtkWidget *label = gtk_label_new(_("mcen_ia_emailsetup_setup_complete"));
651 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
652 gtk_widget_show (label);
654 if (!self->button_edit)
655 self->button_edit = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
656 GtkWidget *caption = hildon_caption_new (NULL, _("mcen_fi_advanced_settings"),
657 self->button_edit, NULL, HILDON_CAPTION_OPTIONAL);
658 gtk_widget_show (self->button_edit);
659 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
660 gtk_widget_show (caption);
662 gtk_widget_show (GTK_WIDGET (box));
663 return GTK_WIDGET (box);
670 on_response (ModestWizardDialog *wizard_dialog,
674 ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (wizard_dialog);
675 invoke_enable_buttons_vfunc (self);
679 modest_easysetup_wizard_dialog_init (ModestEasysetupWizardDialog *self)
681 /* Create the notebook to be used by the ModestWizardDialog base class:
682 * Each page of the notebook will be a page of the wizard: */
683 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
685 /* Set the notebook used by the ModestWizardDialog base class: */
686 g_object_set (G_OBJECT(self), "wizard-notebook", notebook, NULL);
688 /* Set the wizard title:
689 * The actual window title will be a combination of this and the page's tab label title. */
690 g_object_set (G_OBJECT(self), "wizard-name", _("mcen_ti_emailsetup"), NULL);
692 /* Read in the information about known service providers: */
693 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
695 const gchar* filepath = "/usr/share/operator-wizard/provider-data.keyfile";
696 priv->presets = modest_presets_new (filepath); /* TODO: the actual filepath. */
697 if (!(priv->presets))
699 const gchar* filepath_hack = "./src/maemo/easysetup/provider-data-test.keyfile";
700 g_warning ("Could not locate the official provider data keyfile from %s, "
701 "so attempting to load it instead from %s", filepath, filepath_hack);
702 priv->presets = modest_presets_new (filepath_hack); /* TODO: the actual filepath. */
705 g_assert(priv->presets);
708 /* Get the account manager object,
709 * so we can check for existing accounts,
710 * and create new accounts: */
711 self->account_manager = modest_runtime_get_account_mgr ();
712 g_assert (self->account_manager);
713 g_object_ref (self->account_manager);
715 /* Create the common pages,
717 self->page_welcome = create_page_welcome (self);
718 self->page_account_details = create_page_account_details (self);
719 self->page_user_details = create_page_user_details (self);
721 /* Add the common pages: */
722 gtk_notebook_append_page (notebook, self->page_welcome,
723 gtk_label_new (_("mcen_ti_emailsetup_welcome")));
724 gtk_notebook_append_page (notebook, self->page_account_details,
725 gtk_label_new (_("mcen_ti_accountdetails")));
726 gtk_notebook_append_page (notebook, self->page_user_details,
727 gtk_label_new (_("mcen_ti_emailsetup_userdetails")));
729 /* Create and add the easysetup-specific pages,
730 * because we need _some_ final page to enable the Next and Finish buttons: */
731 create_subsequent_easysetup_pages (self);
734 /* Connect to the dialog's response signal so we can enable/disable buttons
735 * for the newly-selected page, because the prev/next buttons cause response to be emitted.
736 * Note that we use g_signal_connect_after() instead of g_signal_connect()
737 * so that we can be enable/disable after ModestWizardDialog has done its own
738 * enabling/disabling of buttons.
740 * HOWEVER, this doesn't work because ModestWizardDialog's response signal handler
741 * does g_signal_stop_emission_by_name(), stopping our signal handler from running.
743 * It's not enough to connect to the notebook's switch-page signal, because
744 * ModestWizardDialog's "response" signal handler enables the buttons itself,
745 * _after_ switching the page (understandably).
746 * (Note that if we had, if we used g_signal_connect() instead of g_signal_connect_after()
747 * then gtk_notebook_get_current_page() would return an incorrect value.)
749 g_signal_connect_after (G_OBJECT (self), "response",
750 G_CALLBACK (on_response), self);
753 ModestEasysetupWizardDialog*
754 modest_easysetup_wizard_dialog_new (void)
756 return g_object_new (MODEST_TYPE_EASYSETUP_WIZARD_DIALOG, NULL);
759 static void create_subsequent_customsetup_pages (ModestEasysetupWizardDialog *self)
761 GtkNotebook *notebook = NULL;
762 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
765 /* Create the custom pages: */
766 if(!(self->page_custom_incoming)) {
767 self->page_custom_incoming = create_page_custom_incoming (self);
770 if(!(self->page_custom_outgoing)) {
771 self->page_custom_outgoing = create_page_custom_outgoing (self);
774 if(!(self->page_complete_customsetup)) {
775 self->page_complete_customsetup = create_page_complete_custom (self);
778 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_incoming)))
779 gtk_notebook_append_page (notebook, self->page_custom_incoming,
780 gtk_label_new (_("mcen_ti_emailsetup_incomingdetails")));
782 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_custom_outgoing)))
783 gtk_notebook_append_page (notebook, self->page_custom_outgoing,
784 gtk_label_new (_("mcen_ti_emailsetup_outgoingdetails")));
786 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_customsetup)))
787 gtk_notebook_append_page (notebook, self->page_complete_customsetup,
788 gtk_label_new (_("mcen_ti_emailsetup_complete")));
791 static void create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self)
793 GtkNotebook *notebook = NULL;
794 g_object_get (self, "wizard-notebook", ¬ebook, NULL);
797 /* Create the easysetup-specific pages: */
798 if(!self->page_complete_easysetup)
799 self->page_complete_easysetup = create_page_complete_easysetup (self);
801 if (!gtk_widget_get_parent (GTK_WIDGET (self->page_complete_easysetup)))
802 gtk_notebook_append_page (notebook, self->page_complete_easysetup,
803 gtk_label_new (_("mcen_ti_emailsetup_complete")));
806 /* After the user details page,
807 * the following pages depend on whether "Other" was chosen
808 * in the provider combobox on the account page
810 static void create_subsequent_pages (ModestEasysetupWizardDialog *self)
812 if (easysetup_provider_combo_box_get_active_provider_id (
813 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider)) == 0) {
814 /* "Other..." was selected: */
816 /* Make sure that the easysetup pages do not exist: */
817 if(self->page_complete_easysetup) {
818 gtk_widget_destroy (self->page_complete_easysetup);
819 self->page_complete_easysetup = NULL;
822 create_subsequent_customsetup_pages (self);
825 /* A specific provider was selected: */
827 /* Make sure that the custom pages do not exist:
828 * Because they will be used if they exist, when creating the account. */
829 if(self->page_custom_incoming) {
830 gtk_widget_destroy (self->page_custom_incoming);
831 self->page_custom_incoming = NULL;
834 if(self->page_custom_outgoing) {
835 gtk_widget_destroy (self->page_custom_outgoing);
836 self->page_custom_outgoing = NULL;
839 if(self->page_complete_customsetup) {
840 gtk_widget_destroy (self->page_complete_customsetup);
841 self->page_complete_customsetup = NULL;
845 /* Create the easysetup pages: */
846 create_subsequent_easysetup_pages (self);
851 util_get_default_servername_from_email_address (const gchar* email_address, ModestProtocol servertype)
856 gchar* at = g_utf8_strchr (email_address, -1, '@');
857 if (!at || (g_utf8_strlen (at, -1) < 2))
860 gchar* domain = g_utf8_next_char (at);
864 const gchar* hostname = NULL;
865 if (servertype == MODEST_PROTOCOL_STORE_POP)
867 else if (servertype == MODEST_PROTOCOL_STORE_IMAP)
869 else if (servertype == MODEST_PROTOCOL_TRANSPORT_SMTP)
875 return g_strdup_printf ("%s.%s", hostname, domain);
878 /* Add a number to the end of the text, or increment a number that is already there.
881 util_increment_name (const gchar* text)
883 /* Get the end character,
884 * also doing a UTF-8 validation which is required for using g_utf8_prev_char().
886 const gchar* end = NULL;
887 if (!g_utf8_validate (text, -1, &end))
893 --end; /* Go to before the null-termination. */
895 /* Look at each UTF-8 characer, starting at the end: */
896 const gchar* p = end;
897 const gchar* alpha_end = NULL;
900 /* Stop when we reach the first character that is not a numeric digit: */
901 const gunichar ch = g_utf8_get_char (p);
902 if (!g_unichar_isdigit (ch)) {
907 p = g_utf8_prev_char (p);
911 /* The text must consist completely of numeric digits. */
917 /* Intepret and increment the number, if any: */
918 gint num = atol (alpha_end);
921 /* Get the name part: */
922 gint name_len = alpha_end - text;
923 gchar *name_without_number = g_malloc(name_len + 1);
924 memcpy (name_without_number, text, name_len);
925 name_without_number[name_len] = 0;\
927 /* Concatenate the text part and the new number: */
928 gchar *result = g_strdup_printf("%s%d", name_without_number, num);
929 g_free (name_without_number);
934 static void set_default_custom_servernames (ModestEasysetupWizardDialog *account_wizard)
936 /* Set a default domain for the server, based on the email address,
937 * if no server name was already specified.
939 const gchar* incoming_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_incomingserver));
940 if ((!incoming_existing || (strlen(incoming_existing) == 0))
941 && account_wizard->entry_user_email) {
942 const ModestProtocol protocol = easysetup_servertype_combo_box_get_active_servertype (
943 EASYSETUP_SERVERTYPE_COMBO_BOX (account_wizard->combo_incoming_servertype));
944 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
946 gchar* servername = util_get_default_servername_from_email_address (email_address, protocol);
947 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_incomingserver), servername);
951 /* Set a default domain for the server, based on the email address,
952 * if no server name was already specified.
954 const gchar* outgoing_existing = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_outgoingserver));
955 if ((!outgoing_existing || (strlen(outgoing_existing) == 0))
956 && account_wizard->entry_user_email) {
957 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY(account_wizard->entry_user_email));
959 gchar* servername = util_get_default_servername_from_email_address (email_address, MODEST_PROTOCOL_TRANSPORT_SMTP);
960 gtk_entry_set_text (GTK_ENTRY (account_wizard->entry_outgoingserver), servername);
966 on_before_next (ModestWizardDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
968 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
970 /* Do extra validation that couldn't be done for every key press,
971 * either because it was too slow,
972 * or because it requires interaction:
974 if (current_page == account_wizard->page_account_details) {
975 /* Check that the title is not already in use: */
976 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_account_title));
977 if ((!account_name) || (strlen(account_name) == 0))
980 gboolean name_in_use = FALSE;
981 name_in_use = modest_account_mgr_account_exists (account_wizard->account_manager,
982 account_name, TRUE /* server_account */);
985 /* Warn the user via a dialog: */
986 show_error (GTK_WINDOW (account_wizard), _("mail_ib_account_name_already_existing."));
991 else if (current_page == account_wizard->page_user_details) {
992 /* Check that the email address is valud: */
993 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (account_wizard->entry_user_email));
994 if ((!email_address) || (strlen(email_address) == 0))
997 if (!modest_text_utils_validate_email_address (email_address)) {
998 /* Warn the user via a dialog: */
999 show_error (GTK_WINDOW (account_wizard), _("mcen_ib_invalid_email"));
1001 /* Return focus to the email address entry: */
1002 gtk_widget_grab_focus (account_wizard->entry_user_email);
1007 /* Make sure that the subsequent pages are appropriate for the provider choice. */
1008 create_subsequent_pages (account_wizard);
1011 /* TODO: The UI Spec wants us to check that the servernames are valid,
1012 * but does not specify how.
1015 if(next_page == account_wizard->page_custom_incoming) {
1016 set_default_custom_servernames (account_wizard);
1018 else if (next_page == account_wizard->page_custom_outgoing) {
1019 set_default_custom_servernames (account_wizard);
1022 /* If this is the last page, and this is a click on Finish,
1023 * then attempt to create the dialog.
1025 if(!next_page) /* This is NULL when this is a click on Finish. */
1027 create_account (account_wizard);
1034 static gboolean entry_is_empty (GtkWidget *entry)
1039 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1040 if ((!text) || (strlen(text) == 0))
1047 on_enable_buttons (ModestWizardDialog *dialog, GtkWidget *current_page)
1049 ModestEasysetupWizardDialog *account_wizard = MODEST_EASYSETUP_WIZARD_DIALOG (dialog);
1051 gboolean enable_next = TRUE;
1052 if (current_page == account_wizard->page_welcome) {
1055 else if (current_page == account_wizard->page_account_details) {
1056 /* The account details title is mandatory: */
1057 if (entry_is_empty(account_wizard->entry_account_title))
1058 enable_next = FALSE;
1060 else if (current_page == account_wizard->page_user_details) {
1061 /* The user details username is mandatory: */
1062 if (entry_is_empty(account_wizard->entry_user_username))
1063 enable_next = FALSE;
1065 /* The user details email address is mandatory: */
1066 if (enable_next && entry_is_empty (account_wizard->entry_user_email))
1067 enable_next = FALSE;
1069 else if (current_page == account_wizard->page_custom_incoming) {
1070 /* The custom incoming server is mandatory: */
1071 if (entry_is_empty(account_wizard->entry_incomingserver))
1072 enable_next = FALSE;
1075 /* Enable the buttons,
1076 * identifying them via their associated response codes:
1078 GtkDialog *dialog_base = GTK_DIALOG (dialog);
1079 gtk_dialog_set_response_sensitive (dialog_base,
1080 MODEST_WIZARD_DIALOG_NEXT,
1083 /* Disable the Finish button until we are on the last page,
1084 * because HildonWizardDialog enables this for all but the first page: */
1085 GtkNotebook *notebook = NULL;
1086 g_object_get (dialog_base, "wizard-notebook", ¬ebook, NULL);
1088 gint current = gtk_notebook_get_current_page (notebook);
1089 gint last = gtk_notebook_get_n_pages (notebook) - 1;
1090 gboolean is_last = (current == last);
1093 gtk_dialog_set_response_sensitive (dialog_base,
1094 MODEST_WIZARD_DIALOG_FINISH,
1100 modest_easysetup_wizard_dialog_class_init (ModestEasysetupWizardDialogClass *klass)
1102 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1103 g_type_class_add_private (klass, sizeof (ModestEasysetupWizardDialogPrivate));
1106 object_class->get_property = modest_easysetup_wizard_dialog_get_property;
1107 object_class->set_property = modest_easysetup_wizard_dialog_set_property;
1108 object_class->dispose = modest_easysetup_wizard_dialog_dispose;
1109 object_class->finalize = modest_easysetup_wizard_dialog_finalize;
1111 /* Provide a vfunc implementation so we can decide
1112 * when to enable/disable the prev/next buttons.
1114 ModestWizardDialogClass *base_klass = (ModestWizardDialogClass*)(klass);
1115 base_klass->before_next = on_before_next;
1116 base_klass->enable_buttons = on_enable_buttons;
1120 show_error (GtkWindow *parent_window, const gchar* text)
1122 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1128 gtk_dialog_run (dialog);
1129 gtk_widget_destroy (GTK_WIDGET (dialog));
1132 /** Attempt to create the account from the information that the user has entered.
1133 * @result: TRUE if the account was successfully created.
1136 create_account (ModestEasysetupWizardDialog *self)
1138 ModestEasysetupWizardDialogPrivate *priv = WIZARD_DIALOG_GET_PRIVATE (self);
1140 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
1146 /* We should have checked for this already,
1147 * and changed that name accordingly,
1148 * but let's check again just in case:
1150 if (modest_account_mgr_account_exists (self->account_manager, account_name, FALSE))
1153 /* username and password (for both incoming and outgoing): */
1154 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1155 const gchar* password = gtk_entry_get_text (GTK_ENTRY (self->entry_user_password));
1157 /* Incoming server: */
1158 /* Note: We need something as default for the ModestProtocol values,
1159 * or modest_account_mgr_add_server_account will fail. */
1160 gchar* servername_incoming = NULL;
1161 ModestProtocol protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1162 ModestProtocol protocol_security_incoming = MODEST_PROTOCOL_SECURITY_NONE;
1163 ModestProtocol protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_NONE;
1165 /* Get details from the specified presets: */
1166 gchar* provider_id = easysetup_provider_combo_box_get_active_provider_id (
1167 EASYSETUP_PROVIDER_COMBO_BOX (self->combo_account_serviceprovider));
1171 servername_incoming = modest_presets_get_server (priv->presets, provider_id,
1172 TRUE /* incoming */);
1174 ModestPresetsServerType servertype_incoming = modest_presets_get_info_server_type (priv->presets, provider_id,
1175 TRUE /* incoming */);
1178 /* We don't check for SMTP here as that is impossible for an incoming server. */
1179 if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_IMAP)
1180 protocol_incoming = MODEST_PROTOCOL_STORE_IMAP;
1181 else if (servertype_incoming == MODEST_PRESETS_SERVER_TYPE_POP)
1182 protocol_incoming = MODEST_PROTOCOL_STORE_POP;
1184 ModestPresetsSecurity security_incoming = modest_presets_get_info_server_security (priv->presets, provider_id,
1185 TRUE /* incoming */);
1188 if (security_incoming & MODEST_PRESETS_SECURITY_SECURE_INCOMING)
1189 protocol_security_incoming = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1191 if (security_incoming & MODEST_PRESETS_SECURITY_APOP)
1192 protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD; /* TODO: Is this what we want? */
1195 /* Use custom pages because no preset was specified: */
1196 servername_incoming = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver) ));
1198 protocol_incoming = easysetup_servertype_combo_box_get_active_servertype (
1199 EASYSETUP_SERVERTYPE_COMBO_BOX (self->combo_incoming_servertype));
1201 protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
1202 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1204 protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
1205 ? MODEST_PROTOCOL_AUTH_PASSWORD
1206 : MODEST_PROTOCOL_AUTH_NONE;
1210 gboolean created = modest_account_mgr_add_server_account (self->account_manager,
1212 servername_incoming,
1215 protocol_security_incoming,
1216 protocol_authentication_incoming);
1218 g_free (servername_incoming);
1221 /* TODO: Provide a Logical ID for the text: */
1222 show_error (GTK_WINDOW (self), _("An error occurred while creating the incoming account."));
1226 /* Outgoing server: */
1227 gchar* servername_outgoing = NULL;
1228 ModestProtocol protocol_outgoing = MODEST_PROTOCOL_STORE_POP;
1229 ModestProtocol protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1230 ModestProtocol protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1234 servername_outgoing = modest_presets_get_server (priv->presets, provider_id,
1235 FALSE /* incoming */);
1237 ModestPresetsServerType servertype_outgoing = modest_presets_get_info_server_type (priv->presets, provider_id,
1238 FALSE /* incoming */);
1240 /* Note: We need something as default, or modest_account_mgr_add_server_account will fail. */
1241 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SENDMAIL;
1242 if (servertype_outgoing == MODEST_PRESETS_SERVER_TYPE_SMTP)
1243 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* TODO: Is this what we want? */
1245 ModestPresetsSecurity security_outgoing =
1246 modest_presets_get_info_server_security (priv->presets, provider_id,
1247 FALSE /* incoming */);
1249 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_NONE;
1250 if (security_outgoing & MODEST_PRESETS_SECURITY_SECURE_SMTP)
1251 protocol_security_outgoing = MODEST_PROTOCOL_SECURITY_SSL; /* TODO: Is this what we want? */
1253 protocol_authentication_outgoing = MODEST_PROTOCOL_AUTH_NONE;
1254 /* TODO: There is no SMTP authentication enum for presets. */
1257 /* Use custom pages because no preset was specified: */
1258 servername_outgoing = g_strdup (gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver) ));
1260 protocol_outgoing = MODEST_PROTOCOL_TRANSPORT_SMTP; /* It's always SMTP for outgoing. */
1262 protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
1263 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
1265 protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
1266 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
1269 gboolean specific = gtk_toggle_button_get_active (
1270 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
1275 created = modest_account_mgr_add_server_account (self->account_manager,
1277 servername_outgoing,
1280 protocol_security_outgoing,
1281 protocol_authentication_outgoing);
1283 g_free (servername_outgoing);
1286 /* TODO: Provide a Logical ID for the text: */
1287 show_error (GTK_WINDOW (self), _("An error occurred while creating the outgoing account."));