1 /* Copyright (c) 2007, Nokia Corporation
7 #include "modest-account-settings-dialog.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 <gtk/gtkstock.h>
18 #include <hildon-widgets/hildon-caption.h>
19 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
20 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
21 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
22 #include "maemo/easysetup/modest-easysetup-serversecurity-combo-box.h"
23 #include "maemo/easysetup/modest-easysetup-secureauth-combo-box.h"
24 #include "maemo/easysetup/modest-validating-entry.h"
25 #include "modest-text-utils.h"
26 #include "modest-account-mgr.h"
27 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
28 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
29 #include "maemo/modest-connection-specific-smtp-window.h"
30 #include <gconf/gconf-client.h>
31 #include <string.h> /* For strlen(). */
33 /* Include config.h so that _() works: */
38 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
40 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
42 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
43 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
45 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
47 struct _ModestAccountSettingsDialogPrivate
52 enable_buttons (ModestAccountSettingsDialog *self);
55 save_configuration (ModestAccountSettingsDialog *dialog);
58 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
59 GValue *value, GParamSpec *pspec)
61 switch (property_id) {
63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
69 const GValue *value, GParamSpec *pspec)
71 switch (property_id) {
73 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
78 modest_account_settings_dialog_dispose (GObject *object)
80 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
81 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
85 modest_account_settings_dialog_finalize (GObject *object)
87 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
89 if (self->original_account_name)
90 g_free (self->original_account_name);
92 if (self->account_manager)
93 g_object_unref (G_OBJECT (self->account_manager));
95 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
100 show_error (GtkWindow *parent_window, const gchar* text);
105 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
107 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
109 enable_buttons(self);
113 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
115 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
117 enable_buttons(self);
120 /** This is a convenience function to create a caption containing a mandatory widget.
121 * When the widget is edited, the enable_buttons() vfunc will be called.
123 static GtkWidget* create_caption_new_with_asterix(ModestAccountSettingsDialog *self,
128 HildonCaptionStatus flag)
130 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
132 /* The translated strings seem to already contain the *,
133 * but this code can be used if that is not true in future.
136 /* Add a * character to indicate mandatory fields,
137 * as specified in our "Email UI Specification": */
138 if (flag == HILDON_CAPTION_MANDATORY) {
139 gchar* title = g_strdup_printf("%s*", value);
140 caption = hildon_caption_new (group, title, control, icon, flag);
144 caption = hildon_caption_new (group, value, control, icon, flag);
147 /* Connect to the appropriate changed signal for the widget,
148 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
150 if (GTK_IS_ENTRY (control)) {
151 g_signal_connect (G_OBJECT (control), "changed",
152 G_CALLBACK (on_caption_entry_changed), self);
155 else if (GTK_IS_COMBO_BOX (control)) {
156 g_signal_connect (G_OBJECT (control), "changed",
157 G_CALLBACK (on_caption_combobox_changed), self);
164 create_page_account_details (ModestAccountSettingsDialog *self)
166 GtkWidget *box = gtk_vbox_new (FALSE, 2);
167 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
168 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
169 gtk_widget_show (label);
171 /* Create a size group to be used by all captions.
172 * Note that HildonCaption does not create a default size group if we do not specify one.
173 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
174 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
176 /* The description widgets: */
177 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
178 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
179 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
180 gtk_widget_show (self->entry_account_title);
181 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
182 gtk_widget_show (caption);
184 /* Prevent the use of some characters in the account title,
185 * as required by our UI specification: */
186 GList *list_prevent = NULL;
187 list_prevent = g_list_append (list_prevent, "\\");
188 list_prevent = g_list_append (list_prevent, "/");
189 list_prevent = g_list_append (list_prevent, ":");
190 list_prevent = g_list_append (list_prevent, "*");
191 list_prevent = g_list_append (list_prevent, "?");
192 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
193 list_prevent = g_list_append (list_prevent, "“");
194 list_prevent = g_list_append (list_prevent, "<");
195 list_prevent = g_list_append (list_prevent, ">");
196 list_prevent = g_list_append (list_prevent, "|");
197 list_prevent = g_list_append (list_prevent, "^");
198 easysetup_validating_entry_set_unallowed_characters (
199 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
200 g_list_free (list_prevent);
202 /* Set max length as in the UI spec:
203 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
204 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
206 /* TODO: The Retrieve and Limit Retrieve combo boxes. */
208 /* The leave-messages widgets: */
209 if(!self->checkbox_leave_messages)
210 self->checkbox_leave_messages =
211 gtk_check_button_new_with_label (_("mcen_fi_advsetup_leave_on_server"));
212 gtk_box_pack_start (GTK_BOX (box), self->checkbox_leave_messages, FALSE, FALSE, 2);
213 gtk_widget_show (self->checkbox_leave_messages);
216 gtk_widget_show (GTK_WIDGET (box));
218 return GTK_WIDGET (box);
222 on_button_signature (GtkButton *button, gpointer user_data)
228 create_page_user_details (ModestAccountSettingsDialog *self)
230 GtkWidget *box = gtk_vbox_new (FALSE, 2);
232 /* Create a size group to be used by all captions.
233 * Note that HildonCaption does not create a default size group if we do not specify one.
234 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
235 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
237 /* The name widgets: */
238 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
239 /* Set max length as in the UI spec:
240 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
241 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
242 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
243 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
244 gtk_widget_show (self->entry_user_name);
245 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
246 gtk_widget_show (caption);
248 /* Prevent the use of some characters in the name,
249 * as required by our UI specification: */
250 GList *list_prevent = NULL;
251 list_prevent = g_list_append (list_prevent, "<");
252 list_prevent = g_list_append (list_prevent, ">");
253 easysetup_validating_entry_set_unallowed_characters (
254 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
255 g_list_free (list_prevent);
257 /* The username widgets: */
258 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
259 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
260 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
261 gtk_widget_show (self->entry_user_username);
262 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
263 gtk_widget_show (caption);
265 /* Prevent the use of some characters in the username,
266 * as required by our UI specification: */
267 easysetup_validating_entry_set_unallowed_characters_whitespace (
268 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
270 /* Set max length as in the UI spec:
271 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
272 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
274 /* The password widgets: */
275 self->entry_user_password = gtk_entry_new ();
276 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
277 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
278 caption = create_caption_new_with_asterix (self, sizegroup,
279 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
280 gtk_widget_show (self->entry_user_password);
281 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
282 gtk_widget_show (caption);
284 /* The email address widgets: */
285 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
286 caption = create_caption_new_with_asterix (self, sizegroup,
287 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
288 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
289 gtk_widget_show (self->entry_user_email);
290 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
291 gtk_widget_show (caption);
293 /* Set max length as in the UI spec:
294 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
295 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
298 /* Signature button: */
299 if (!self->button_signature)
300 self->button_signature = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
301 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
302 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
303 gtk_widget_show (self->button_signature);
304 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
305 gtk_widget_show (caption);
307 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
308 G_CALLBACK (on_button_signature), self);
310 gtk_widget_show (GTK_WIDGET (box));
312 return GTK_WIDGET (box);
315 /** Change the caption title for the incoming server,
316 * as specified in the UI spec:
318 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
321 (protocol == MODEST_PROTOCOL_STORE_POP ?
322 _("mail_fi_emailtype_pop3") :
323 _("mail_fi_emailtype_imap") );
326 /* Note that this produces a compiler warning,
327 * because the compiler does not know that the translated string will have a %s in it.
328 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
329 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
330 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
331 g_free(incomingserver_title);
334 /** Change the caption title for the incoming server,
335 * as specified in the UI spec:
337 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
339 /* Fill the combo with appropriately titled choices for POP or IMAP. */
340 /* The choices are the same, but the titles are different, as in the UI spec. */
341 easysetup_serversecurity_combo_box_fill (
342 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
345 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
347 GtkWidget *box = gtk_vbox_new (FALSE, 2);
349 /* Create a size group to be used by all captions.
350 * Note that HildonCaption does not create a default size group if we do not specify one.
351 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
352 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
354 /* The incoming server widgets: */
355 if(!self->entry_incomingserver)
356 self->entry_incomingserver = gtk_entry_new ();
358 if (self->caption_incoming)
359 gtk_widget_destroy (self->caption_incoming);
361 /* The caption title will be updated in update_incoming_server_title().
362 * so this default text will never be seen: */
363 /* (Note: Changing the title seems pointless. murrayc) */
364 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
365 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
366 gtk_widget_show (self->entry_incomingserver);
367 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
368 gtk_widget_show (self->caption_incoming);
370 /* The secure connection widgets: */
371 /* This will be filled by update_incoming_server_security_choices(). */
372 if (!self->combo_incoming_security)
373 self->combo_incoming_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
374 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
375 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
376 gtk_widget_show (self->combo_incoming_security);
377 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
378 gtk_widget_show (caption);
380 /* The port widgets: */
381 if (!self->entry_incoming_port)
382 self->entry_incoming_port = GTK_WIDGET (gtk_entry_new ());
383 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
384 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
385 gtk_widget_show (self->entry_incoming_port);
386 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
387 gtk_widget_show (caption);
389 /* The secure authentication widgets: */
390 if(!self->checkbox_incoming_auth)
391 self->checkbox_incoming_auth =
392 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
393 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
394 gtk_widget_show (self->checkbox_incoming_auth);
396 gtk_widget_show (GTK_WIDGET (box));
398 return GTK_WIDGET (box);
402 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
404 GtkWidget *widget = GTK_WIDGET (user_data);
406 /* Enable the widget only if the toggle button is active: */
407 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
408 gtk_widget_set_sensitive (widget, enable);
411 /* Make the sensitivity of a widget depend on a toggle button.
414 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
416 g_signal_connect (G_OBJECT (button), "toggled",
417 G_CALLBACK (on_toggle_button_changed), widget);
419 /* Set the starting sensitivity: */
420 on_toggle_button_changed (button, widget);
424 on_smtp_servers_window_hide (GtkWindow *window, gpointer user_data)
426 /* Destroy the window when it is closed: */
427 gtk_widget_destroy (GTK_WIDGET (window));
431 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
434 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
436 /* Show the window: */
437 /* TODO: Retrieve the chosen settings,
438 * so we can supply them when creating the connection somehow.
440 GtkWidget *window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
441 gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
442 g_signal_connect (G_OBJECT (window), "hide",
443 G_CALLBACK (on_smtp_servers_window_hide), self);
444 gtk_widget_show (window);
448 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
450 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
452 ModestProtocol protocol_security =
453 easysetup_secureauth_combo_box_get_active_secureauth (
454 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
455 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
457 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
458 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
461 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
463 GtkWidget *box = gtk_vbox_new (FALSE, 2);
465 /* Create a size group to be used by all captions.
466 * Note that HildonCaption does not create a default size group if we do not specify one.
467 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
468 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
470 /* The outgoing server widgets: */
471 if (!self->entry_outgoingserver)
472 self->entry_outgoingserver = gtk_entry_new ();
473 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
474 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
475 gtk_widget_show (self->entry_outgoingserver);
476 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
477 gtk_widget_show (caption);
479 /* The secure authentication widgets: */
480 if (!self->combo_outgoing_auth)
481 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
482 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
483 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
484 gtk_widget_show (self->combo_outgoing_auth);
485 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
486 gtk_widget_show (caption);
488 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
489 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
491 /* The username widgets: */
492 self->entry_outgoing_username = GTK_WIDGET (easysetup_validating_entry_new ());
493 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
494 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
495 gtk_widget_show (self->entry_outgoing_username);
496 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, 2);
497 gtk_widget_show (self->caption_outgoing_username);
499 /* Prevent the use of some characters in the username,
500 * as required by our UI specification: */
501 easysetup_validating_entry_set_unallowed_characters_whitespace (
502 EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
504 /* Set max length as in the UI spec:
505 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
506 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
508 /* The password widgets: */
509 self->entry_outgoing_password = gtk_entry_new ();
510 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
511 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
512 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
513 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
514 gtk_widget_show (self->entry_outgoing_password);
515 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, 2);
516 gtk_widget_show (self->caption_outgoing_password);
518 /* The secure connection widgets: */
519 /* This will be filled and set with easysetup_serversecurity_combo_box_fill()
520 * and easysetup_serversecurity_combo_box_set_active_serversecurity().
522 if (!self->combo_outgoing_security)
523 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
524 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
525 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
526 gtk_widget_show (self->combo_outgoing_security);
527 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
528 gtk_widget_show (caption);
530 /* The port widgets: */
531 if (!self->entry_outgoing_port)
532 self->entry_outgoing_port = GTK_WIDGET (gtk_entry_new ());
533 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
534 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
535 gtk_widget_show (self->entry_outgoing_port);
536 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
537 gtk_widget_show (caption);
539 /* connection-specific checkbox: */
540 if (!self->checkbox_outgoing_smtp_specific) {
541 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
542 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
545 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
546 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
548 /* Connection-specific SMTP-Severs Edit button: */
549 if (!self->button_outgoing_smtp_servers)
550 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
551 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
552 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
553 gtk_widget_show (self->button_outgoing_smtp_servers);
554 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
555 gtk_widget_show (caption);
557 /* Only enable the button when the checkbox is checked: */
558 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
559 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
561 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
562 G_CALLBACK (on_button_outgoing_smtp_servers), self);
565 gtk_widget_show (GTK_WIDGET (box));
567 return GTK_WIDGET (box);
573 on_response (GtkDialog *wizard_dialog,
577 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
578 enable_buttons (self);
580 /* TODO: Prevent the OK response if the data is invalid. */
582 if (response_id == GTK_RESPONSE_OK)
583 save_configuration (self);
587 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
589 /* Create the notebook to be used by the GtkDialog base class:
590 * Each page of the notebook will be a page of the wizard: */
591 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
594 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
596 /* Get the account manager object,
597 * so we can check for existing accounts,
598 * and create new accounts: */
599 self->account_manager = modest_runtime_get_account_mgr ();
600 g_assert (self->account_manager);
601 g_object_ref (self->account_manager);
603 /* Create the common pages,
605 self->page_account_details = create_page_account_details (self);
606 self->page_user_details = create_page_user_details (self);
607 self->page_incoming = create_page_incoming (self);
608 self->page_outgoing = create_page_outgoing (self);
610 /* Add the notebook pages: */
611 gtk_notebook_append_page (notebook, self->page_account_details,
612 gtk_label_new (_("mcen_ti_account_settings_account")));
613 gtk_notebook_append_page (notebook, self->page_user_details,
614 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
615 gtk_notebook_append_page (notebook, self->page_incoming,
616 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
617 gtk_notebook_append_page (notebook, self->page_outgoing,
618 gtk_label_new (_("mcen_ti_advsetup_sending")));
620 GtkDialog *dialog = GTK_DIALOG (self);
621 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
622 gtk_widget_show (GTK_WIDGET (notebook));
624 /* Add the buttons: */
625 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
626 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
628 /* Connect to the dialog's response signal: */
629 g_signal_connect_after (G_OBJECT (self), "response",
630 G_CALLBACK (on_response), self);
633 ModestAccountSettingsDialog*
634 modest_account_settings_dialog_new (void)
636 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
639 /** Update the UI with the stored account details, so they can be edited.
640 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
642 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
647 /* Save the account name so we can refer to it if the user changes it: */
648 if (dialog->original_account_name)
649 g_free (dialog->original_account_name);
650 dialog->original_account_name = g_strdup (account_name);
652 /* Get the account data for this account name: */
653 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
656 g_printerr ("modest: failed to get account data for %s\n", account_name);
660 if (!(account_data->store_account)) {
661 g_printerr ("modest: account has no stores: %s\n", account_name);
665 /* Show the account data in the widgets: */
666 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
667 account_name ? account_name : "");
668 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
669 account_data->fullname ? account_data->fullname : "");
670 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
671 account_data->email ? account_data->email : "");
673 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
674 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
675 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
678 ModestServerAccountData *incoming_account = account_data->store_account;
679 if (incoming_account) {
680 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
681 incoming_account->username ? incoming_account->username : "");
682 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
683 incoming_account->password ? incoming_account->password : "");
685 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
686 incoming_account->hostname ? incoming_account->hostname : "");
688 easysetup_serversecurity_combo_box_set_active_serversecurity (
689 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), incoming_account->proto);
690 update_incoming_server_title (dialog, incoming_account->proto);
691 update_incoming_server_security_choices (dialog, incoming_account->proto);
695 ModestProtocol proto;
703 ModestServerAccountData *outgoing_account = account_data->transport_account;
704 if (outgoing_account) {
705 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
706 outgoing_account->hostname ? outgoing_account->hostname : "");
708 /* TODO: Dim these if secure authentication is None, as per the UI spec: */
709 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
710 outgoing_account->username ? outgoing_account->username : "");
711 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
712 outgoing_account->password ? outgoing_account->password : "");
714 /* TODO: How do we get the auth setting from the server account struct?: */
715 /* This seems to be in ->options, with hard-coded option names.
716 * This will need new API in ModestAccountMgr. */
717 easysetup_secureauth_combo_box_set_active_secureauth (
718 EASYSETUP_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), MODEST_PROTOCOL_AUTH_NONE);
719 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
721 easysetup_serversecurity_combo_box_fill (
722 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
726 /* TODO: set port. */
729 /* TODO: account_data->display_name */
730 /* account_data->is_enabled, */
731 /*account_data->is_default, */
733 /* account_data->store_account->proto */
735 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
739 save_configuration (ModestAccountSettingsDialog *dialog)
741 g_assert (dialog->original_account_name);
743 const gchar* account_name = dialog->original_account_name;
745 /* Set the account data from the widgets: */
746 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
747 modest_account_mgr_set_string (dialog->account_manager, account_name,
748 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
750 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
751 modest_account_mgr_set_string (dialog->account_manager, account_name,
752 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
754 /* TODO: Change name: */
755 /* Possibly the account name may never change, but that should be hidden,
756 * and the display name may change, defaulting to the account name.
759 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
760 modest_account_mgr_set_bool (dialog->account_manager, account_name,
761 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
764 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
765 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
766 g_assert (incoming_account_name);
768 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
769 modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
770 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
772 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
773 modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
774 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
776 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
777 modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
778 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
780 /* TODO: How can we set these in the server account?:
781 ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
782 ? MODEST_PROTOCOL_AUTH_PASSWORD
783 : MODEST_PROTOCOL_AUTH_NONE;
785 ModestProtocol protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
786 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
790 g_free (incoming_account_name);
793 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
794 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
795 g_assert (outgoing_account_name);
797 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
798 modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
799 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
801 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
802 modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
803 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
805 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
806 modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
807 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
809 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
810 modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
811 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
813 /* TODO: How do we set these in the account data?:
814 ModestProtocol protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
815 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
817 ModestProtocol protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
818 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
821 g_free (outgoing_account_name);
828 on_before_next (GtkDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
830 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (dialog);
832 /* Do extra validation that couldn't be done for every key press,
833 * either because it was too slow,
834 * or because it requires interaction:
836 if (current_page == self->page_account_details) {
837 /* Check that the title is not already in use: */
838 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
839 if ((!account_name) || (strlen(account_name) == 0))
842 gboolean name_in_use = FALSE;
843 name_in_use = modest_account_mgr_account_exists (self->account_manager,
844 account_name, FALSE /* server_account */);
847 /* Warn the user via a dialog: */
848 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing."));
853 else if (current_page == self->page_user_details) {
854 /* Check that the email address is valud: */
855 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
856 if ((!email_address) || (strlen(email_address) == 0))
859 if (!modest_text_utils_validate_email_address (email_address)) {
860 /* Warn the user via a dialog: */
861 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
863 /* Return focus to the email address entry: */
864 gtk_widget_grab_focus (self->entry_user_email);
869 /* Make sure that the subsequent pages are appropriate for the provider choice. */
870 create_subsequent_pages (self);
873 /* TODO: The UI Spec wants us to check that the servernames are valid,
874 * but does not specify how.
877 if(next_page == self->page_incoming) {
878 set_default_custom_servernames (self);
880 else if (next_page == self->page_outgoing) {
881 set_default_custom_servernames (self);
884 /* If this is the last page, and this is a click on Finish,
885 * then attempt to create the dialog.
887 if(!next_page) /* This is NULL when this is a click on Finish. */
889 create_account (self);
897 static gboolean entry_is_empty (GtkWidget *entry)
902 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
903 if ((!text) || (strlen(text) == 0))
910 enable_buttons (ModestAccountSettingsDialog *self)
912 gboolean enable_ok = TRUE;
914 /* The account details title is mandatory: */
915 if (entry_is_empty(self->entry_account_title))
918 /* The user details username is mandatory: */
919 if (entry_is_empty(self->entry_user_username))
922 /* The user details email address is mandatory: */
923 if (enable_ok && entry_is_empty (self->entry_user_email))
926 /* The custom incoming server is mandatory: */
927 if (entry_is_empty(self->entry_incomingserver))
930 /* Enable the buttons,
931 * identifying them via their associated response codes:
933 GtkDialog *dialog_base = GTK_DIALOG (self);
934 gtk_dialog_set_response_sensitive (dialog_base,
940 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
942 GObjectClass *object_class = G_OBJECT_CLASS (klass);
943 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
946 object_class->get_property = modest_account_settings_dialog_get_property;
947 object_class->set_property = modest_account_settings_dialog_set_property;
948 object_class->dispose = modest_account_settings_dialog_dispose;
949 object_class->finalize = modest_account_settings_dialog_finalize;
954 show_error (GtkWindow *parent_window, const gchar* text)
956 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
962 gtk_dialog_run (dialog);
963 gtk_widget_destroy (GTK_WIDGET (dialog));