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 easysetup_serversecurity_combo_box_set_active_serversecurity (
375 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), MODEST_PROTOCOL_SECURITY_NONE);
376 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
377 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
378 gtk_widget_show (self->combo_incoming_security);
379 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
380 gtk_widget_show (caption);
382 /* The port widgets: */
383 if (!self->entry_incoming_port)
384 self->entry_incoming_port = GTK_WIDGET (gtk_entry_new ());
385 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
386 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
387 gtk_widget_show (self->entry_incoming_port);
388 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
389 gtk_widget_show (caption);
391 /* The secure authentication widgets: */
392 if(!self->checkbox_incoming_auth)
393 self->checkbox_incoming_auth =
394 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
395 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
396 gtk_widget_show (self->checkbox_incoming_auth);
398 gtk_widget_show (GTK_WIDGET (box));
400 return GTK_WIDGET (box);
404 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
406 GtkWidget *widget = GTK_WIDGET (user_data);
408 /* Enable the widget only if the toggle button is active: */
409 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
410 gtk_widget_set_sensitive (widget, enable);
413 /* Make the sensitivity of a widget depend on a toggle button.
416 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
418 g_signal_connect (G_OBJECT (button), "toggled",
419 G_CALLBACK (on_toggle_button_changed), widget);
421 /* Set the starting sensitivity: */
422 on_toggle_button_changed (button, widget);
426 on_smtp_servers_window_hide (GtkWindow *window, gpointer user_data)
428 /* Destroy the window when it is closed: */
429 gtk_widget_destroy (GTK_WIDGET (window));
433 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
436 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
438 /* Show the window: */
439 /* TODO: Retrieve the chosen settings,
440 * so we can supply them when creating the connection somehow.
442 GtkWidget *window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
443 gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
444 g_signal_connect (G_OBJECT (window), "hide",
445 G_CALLBACK (on_smtp_servers_window_hide), self);
446 gtk_widget_show (window);
450 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
452 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
454 ModestProtocol protocol_security =
455 easysetup_secureauth_combo_box_get_active_secureauth (
456 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
457 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
459 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
460 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
463 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
465 GtkWidget *box = gtk_vbox_new (FALSE, 2);
467 /* Create a size group to be used by all captions.
468 * Note that HildonCaption does not create a default size group if we do not specify one.
469 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
470 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
472 /* The outgoing server widgets: */
473 if (!self->entry_outgoingserver)
474 self->entry_outgoingserver = gtk_entry_new ();
475 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
476 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
477 gtk_widget_show (self->entry_outgoingserver);
478 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
479 gtk_widget_show (caption);
481 /* The secure authentication widgets: */
482 if (!self->combo_outgoing_auth)
483 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
484 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
485 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
486 gtk_widget_show (self->combo_outgoing_auth);
487 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
488 gtk_widget_show (caption);
490 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
491 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
493 /* The username widgets: */
494 self->entry_outgoing_username = GTK_WIDGET (easysetup_validating_entry_new ());
495 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
496 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
497 gtk_widget_show (self->entry_outgoing_username);
498 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, 2);
499 gtk_widget_show (self->caption_outgoing_username);
501 /* Prevent the use of some characters in the username,
502 * as required by our UI specification: */
503 easysetup_validating_entry_set_unallowed_characters_whitespace (
504 EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
506 /* Set max length as in the UI spec:
507 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
508 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
510 /* The password widgets: */
511 self->entry_outgoing_password = gtk_entry_new ();
512 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
513 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
514 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
515 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
516 gtk_widget_show (self->entry_outgoing_password);
517 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, 2);
518 gtk_widget_show (self->caption_outgoing_password);
520 /* The secure connection widgets: */
521 /* This will be filled and set with easysetup_serversecurity_combo_box_fill()
522 * and easysetup_serversecurity_combo_box_set_active_serversecurity().
524 if (!self->combo_outgoing_security)
525 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
526 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
527 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
528 gtk_widget_show (self->combo_outgoing_security);
529 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
530 gtk_widget_show (caption);
532 /* The port widgets: */
533 if (!self->entry_outgoing_port)
534 self->entry_outgoing_port = GTK_WIDGET (gtk_entry_new ());
535 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
536 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
537 gtk_widget_show (self->entry_outgoing_port);
538 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
539 gtk_widget_show (caption);
541 /* connection-specific checkbox: */
542 if (!self->checkbox_outgoing_smtp_specific) {
543 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
544 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
547 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
548 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
550 /* Connection-specific SMTP-Severs Edit button: */
551 if (!self->button_outgoing_smtp_servers)
552 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
553 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
554 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
555 gtk_widget_show (self->button_outgoing_smtp_servers);
556 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
557 gtk_widget_show (caption);
559 /* Only enable the button when the checkbox is checked: */
560 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
561 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
563 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
564 G_CALLBACK (on_button_outgoing_smtp_servers), self);
567 gtk_widget_show (GTK_WIDGET (box));
569 return GTK_WIDGET (box);
575 on_response (GtkDialog *wizard_dialog,
579 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
580 enable_buttons (self);
582 /* TODO: Prevent the OK response if the data is invalid. */
584 if (response_id == GTK_RESPONSE_OK)
585 save_configuration (self);
589 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
591 /* Create the notebook to be used by the GtkDialog base class:
592 * Each page of the notebook will be a page of the wizard: */
593 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
596 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
598 /* Get the account manager object,
599 * so we can check for existing accounts,
600 * and create new accounts: */
601 self->account_manager = modest_runtime_get_account_mgr ();
602 g_assert (self->account_manager);
603 g_object_ref (self->account_manager);
605 /* Create the common pages,
607 self->page_account_details = create_page_account_details (self);
608 self->page_user_details = create_page_user_details (self);
609 self->page_incoming = create_page_incoming (self);
610 self->page_outgoing = create_page_outgoing (self);
612 /* Add the notebook pages: */
613 gtk_notebook_append_page (notebook, self->page_account_details,
614 gtk_label_new (_("mcen_ti_account_settings_account")));
615 gtk_notebook_append_page (notebook, self->page_user_details,
616 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
617 gtk_notebook_append_page (notebook, self->page_incoming,
618 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
619 gtk_notebook_append_page (notebook, self->page_outgoing,
620 gtk_label_new (_("mcen_ti_advsetup_sending")));
622 GtkDialog *dialog = GTK_DIALOG (self);
623 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
624 gtk_widget_show (GTK_WIDGET (notebook));
626 /* Add the buttons: */
627 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
628 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
630 /* Connect to the dialog's response signal: */
631 g_signal_connect_after (G_OBJECT (self), "response",
632 G_CALLBACK (on_response), self);
635 ModestAccountSettingsDialog*
636 modest_account_settings_dialog_new (void)
638 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
641 /** Update the UI with the stored account details, so they can be edited.
642 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
644 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
649 /* Save the account name so we can refer to it if the user changes it: */
650 if (dialog->original_account_name)
651 g_free (dialog->original_account_name);
652 dialog->original_account_name = g_strdup (account_name);
654 /* Get the account data for this account name: */
655 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
658 g_printerr ("modest: failed to get account data for %s\n", account_name);
662 if (!(account_data->store_account)) {
663 g_printerr ("modest: account has no stores: %s\n", account_name);
667 /* Show the account data in the widgets: */
668 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
669 account_name ? account_name : "");
670 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
671 account_data->fullname ? account_data->fullname : "");
672 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
673 account_data->email ? account_data->email : "");
675 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
676 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
677 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
680 ModestServerAccountData *incoming_account = account_data->store_account;
681 if (incoming_account) {
682 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
683 incoming_account->username ? incoming_account->username : "");
684 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
685 incoming_account->password ? incoming_account->password : "");
687 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
688 incoming_account->hostname ? incoming_account->hostname : "");
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 /* How do we get the auth setting from the server account struct?: */
715 easysetup_secureauth_combo_box_set_active_secureauth (
716 EASYSETUP_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), MODEST_PROTOCOL_AUTH_NONE);
717 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
719 easysetup_serversecurity_combo_box_fill (
720 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
724 /* TODO: set port. */
727 /* TODO: account_data->display_name */
728 /* account_data->is_enabled, */
729 /*account_data->is_default, */
731 /* account_data->store_account->proto */
733 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
737 save_configuration (ModestAccountSettingsDialog *dialog)
739 g_assert (dialog->original_account_name);
741 const gchar* account_name = dialog->original_account_name;
743 /* Set the account data from the widgets: */
744 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
745 modest_account_mgr_set_string (dialog->account_manager, account_name,
746 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
748 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
749 modest_account_mgr_set_string (dialog->account_manager, account_name,
750 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
752 /* TODO: Change name: */
753 /* Possibly the account name may never change, but that should be hidden,
754 * and the display name may change, defaulting to the account name.
757 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
758 modest_account_mgr_set_bool (dialog->account_manager, account_name,
759 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
762 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
763 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
764 g_assert (incoming_account_name);
766 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
767 modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
768 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
770 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
771 modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
772 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
774 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
775 modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
776 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
778 /* TODO: How can we set these in the server account?:
779 ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))
780 ? MODEST_PROTOCOL_AUTH_PASSWORD
781 : MODEST_PROTOCOL_AUTH_NONE;
783 ModestProtocol protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
784 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
788 g_free (incoming_account_name);
791 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
792 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
793 g_assert (outgoing_account_name);
795 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
796 modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
797 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
799 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
800 modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
801 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
803 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
804 modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
805 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
807 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
808 modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
809 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
811 /* TODO: How do we set these in the account data?:
812 ModestProtocol protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
813 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
815 ModestProtocol protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
816 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
819 g_free (outgoing_account_name);
826 on_before_next (GtkDialog *dialog, GtkWidget *current_page, GtkWidget *next_page)
828 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (dialog);
830 /* Do extra validation that couldn't be done for every key press,
831 * either because it was too slow,
832 * or because it requires interaction:
834 if (current_page == self->page_account_details) {
835 /* Check that the title is not already in use: */
836 const gchar* account_name = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
837 if ((!account_name) || (strlen(account_name) == 0))
840 gboolean name_in_use = FALSE;
841 name_in_use = modest_account_mgr_account_exists (self->account_manager,
842 account_name, FALSE /* server_account */);
845 /* Warn the user via a dialog: */
846 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing."));
851 else if (current_page == self->page_user_details) {
852 /* Check that the email address is valud: */
853 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
854 if ((!email_address) || (strlen(email_address) == 0))
857 if (!modest_text_utils_validate_email_address (email_address)) {
858 /* Warn the user via a dialog: */
859 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
861 /* Return focus to the email address entry: */
862 gtk_widget_grab_focus (self->entry_user_email);
867 /* Make sure that the subsequent pages are appropriate for the provider choice. */
868 create_subsequent_pages (self);
871 /* TODO: The UI Spec wants us to check that the servernames are valid,
872 * but does not specify how.
875 if(next_page == self->page_incoming) {
876 set_default_custom_servernames (self);
878 else if (next_page == self->page_outgoing) {
879 set_default_custom_servernames (self);
882 /* If this is the last page, and this is a click on Finish,
883 * then attempt to create the dialog.
885 if(!next_page) /* This is NULL when this is a click on Finish. */
887 create_account (self);
895 static gboolean entry_is_empty (GtkWidget *entry)
900 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
901 if ((!text) || (strlen(text) == 0))
908 enable_buttons (ModestAccountSettingsDialog *self)
910 gboolean enable_ok = TRUE;
912 /* The account details title is mandatory: */
913 if (entry_is_empty(self->entry_account_title))
916 /* The user details username is mandatory: */
917 if (entry_is_empty(self->entry_user_username))
920 /* The user details email address is mandatory: */
921 if (enable_ok && entry_is_empty (self->entry_user_email))
924 /* The custom incoming server is mandatory: */
925 if (entry_is_empty(self->entry_incomingserver))
928 /* Enable the buttons,
929 * identifying them via their associated response codes:
931 GtkDialog *dialog_base = GTK_DIALOG (self);
932 gtk_dialog_set_response_sensitive (dialog_base,
938 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
940 GObjectClass *object_class = G_OBJECT_CLASS (klass);
941 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
944 object_class->get_property = modest_account_settings_dialog_get_property;
945 object_class->set_property = modest_account_settings_dialog_set_property;
946 object_class->dispose = modest_account_settings_dialog_dispose;
947 object_class->finalize = modest_account_settings_dialog_finalize;
952 show_error (GtkWindow *parent_window, const gchar* text)
954 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
960 gtk_dialog_run (dialog);
961 gtk_widget_destroy (GTK_WIDGET (dialog));