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 <hildon-widgets/hildon-number-editor.h>
20 #include "widgets/modest-serversecurity-combo-box.h"
21 #include "widgets/modest-secureauth-combo-box.h"
22 #include "widgets/modest-validating-entry.h"
23 #include "widgets/modest-retrieve-combo-box.h"
24 #include "widgets/modest-limit-retrieve-combo-box.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 "maemo/modest-signature-editor-dialog.h"
31 #include <maemo/modest-maemo-ui-constants.h>
32 #include <gconf/gconf-client.h>
33 #include <string.h> /* For strlen(). */
35 /* Include config.h so that _() works: */
40 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
42 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
44 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
45 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
47 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
49 struct _ModestAccountSettingsDialogPrivate
54 enable_buttons (ModestAccountSettingsDialog *self);
57 save_configuration (ModestAccountSettingsDialog *dialog);
60 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
61 GValue *value, GParamSpec *pspec)
63 switch (property_id) {
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
70 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
71 const GValue *value, GParamSpec *pspec)
73 switch (property_id) {
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
80 modest_account_settings_dialog_dispose (GObject *object)
82 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
83 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
87 modest_account_settings_dialog_finalize (GObject *object)
89 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
91 if (self->account_name)
92 g_free (self->account_name);
94 if (self->original_account_title)
95 g_free (self->original_account_title);
97 if (self->account_manager)
98 g_object_unref (G_OBJECT (self->account_manager));
100 if (self->specific_window)
101 gtk_widget_destroy (self->specific_window);
103 if (self->signature_dialog)
104 gtk_widget_destroy (self->signature_dialog);
106 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
110 show_error (GtkWindow *parent_window, const gchar* text);
113 show_ok (GtkWindow *parent_window, const gchar* text);
116 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
119 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
122 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
124 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
125 self->modified = TRUE;
129 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
131 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
132 self->modified = TRUE;
136 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
138 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
139 self->modified = TRUE;
142 /* Set a modified boolean whenever the widget is changed,
143 * so we can check for it later.
146 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
148 if (GTK_IS_ENTRY (widget)) {
149 g_signal_connect (G_OBJECT (widget), "changed",
150 G_CALLBACK (on_modified_entry_changed), self);
151 } else if (GTK_IS_COMBO_BOX (widget)) {
152 g_signal_connect (G_OBJECT (widget), "changed",
153 G_CALLBACK (on_modified_combobox_changed), self);
154 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
155 g_signal_connect (G_OBJECT (widget), "toggled",
156 G_CALLBACK (on_modified_checkbox_toggled), self);
161 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
163 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
165 enable_buttons(self);
169 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
171 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
173 enable_buttons(self);
176 /** This is a convenience function to create a caption containing a mandatory widget.
177 * When the widget is edited, the enable_buttons() vfunc will be called.
179 static GtkWidget* create_caption_new_with_asterix(ModestAccountSettingsDialog *self,
184 HildonCaptionStatus flag)
186 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
188 /* The translated strings seem to already contain the *,
189 * but this code can be used if that is not true in future.
192 /* Add a * character to indicate mandatory fields,
193 * as specified in our "Email UI Specification": */
194 if (flag == HILDON_CAPTION_MANDATORY) {
195 gchar* title = g_strdup_printf("%s*", value);
196 caption = hildon_caption_new (group, title, control, icon, flag);
200 caption = hildon_caption_new (group, value, control, icon, flag);
203 /* Connect to the appropriate changed signal for the widget,
204 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
206 if (GTK_IS_ENTRY (control)) {
207 g_signal_connect (G_OBJECT (control), "changed",
208 G_CALLBACK (on_caption_entry_changed), self);
211 else if (GTK_IS_COMBO_BOX (control)) {
212 g_signal_connect (G_OBJECT (control), "changed",
213 G_CALLBACK (on_caption_combobox_changed), self);
220 create_page_account_details (ModestAccountSettingsDialog *self)
222 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
223 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
224 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
225 gtk_widget_show (label);
227 /* Create a size group to be used by all captions.
228 * Note that HildonCaption does not create a default size group if we do not specify one.
229 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
230 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
232 /* The description widgets: */
233 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
234 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
235 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
236 gtk_widget_show (self->entry_account_title);
237 connect_for_modified (self, self->entry_account_title);
238 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
239 gtk_widget_show (caption);
241 /* Prevent the use of some characters in the account title,
242 * as required by our UI specification: */
243 GList *list_prevent = NULL;
244 list_prevent = g_list_append (list_prevent, "\\");
245 list_prevent = g_list_append (list_prevent, "/");
246 list_prevent = g_list_append (list_prevent, ":");
247 list_prevent = g_list_append (list_prevent, "*");
248 list_prevent = g_list_append (list_prevent, "?");
249 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
250 list_prevent = g_list_append (list_prevent, "“");
251 list_prevent = g_list_append (list_prevent, "<");
252 list_prevent = g_list_append (list_prevent, ">");
253 list_prevent = g_list_append (list_prevent, "|");
254 list_prevent = g_list_append (list_prevent, "^");
255 easysetup_validating_entry_set_unallowed_characters (
256 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
257 g_list_free (list_prevent);
259 /* Set max length as in the UI spec:
260 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
261 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
263 /* The retrieve combobox: */
264 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
265 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
266 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
267 gtk_widget_show (self->combo_retrieve);
268 connect_for_modified (self, self->combo_retrieve);
269 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
270 gtk_widget_show (caption);
272 /* The limit-retrieve combobox: */
273 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
274 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
275 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
276 gtk_widget_show (self->combo_limit_retrieve);
277 connect_for_modified (self, self->combo_limit_retrieve);
278 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
279 gtk_widget_show (caption);
281 /* The leave-messages widgets: */
282 if(!self->checkbox_leave_messages)
283 self->checkbox_leave_messages =
284 gtk_check_button_new_with_label (_("mcen_fi_advsetup_leave_on_server"));
285 gtk_box_pack_start (GTK_BOX (box), self->checkbox_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
286 gtk_widget_show (self->checkbox_leave_messages);
287 connect_for_modified (self, self->checkbox_leave_messages);
289 gtk_widget_show (GTK_WIDGET (box));
291 return GTK_WIDGET (box);
295 on_button_signature (GtkButton *button, gpointer user_data)
297 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
299 /* Create the window, if necessary: */
300 if (!(self->signature_dialog)) {
301 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
303 gboolean use_signature = FALSE;
304 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
306 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
307 modest_signature_editor_dialog_set_settings (
308 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
309 use_signature, signature, account_title);
314 /* Show the window: */
315 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
316 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
317 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
318 gtk_widget_hide (self->signature_dialog);
319 if (response != GTK_RESPONSE_OK) {
320 /* Destroy the widget now, and its data: */
321 gtk_widget_destroy (self->signature_dialog);
322 self->signature_dialog = NULL;
325 /* Mark modified, so we use the dialog's data later: */
326 self->modified = TRUE;
331 create_page_user_details (ModestAccountSettingsDialog *self)
333 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
335 /* Create a size group to be used by all captions.
336 * Note that HildonCaption does not create a default size group if we do not specify one.
337 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
338 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
340 /* The name widgets: */
341 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
342 /* Auto-capitalization is the default, so let's turn it off: */
343 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
344 /* Set max length as in the UI spec:
345 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
346 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
347 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
348 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
349 gtk_widget_show (self->entry_user_name);
350 connect_for_modified (self, self->entry_user_name);
351 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
352 gtk_widget_show (caption);
354 /* Prevent the use of some characters in the name,
355 * as required by our UI specification: */
356 GList *list_prevent = NULL;
357 list_prevent = g_list_append (list_prevent, "<");
358 list_prevent = g_list_append (list_prevent, ">");
359 easysetup_validating_entry_set_unallowed_characters (
360 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
361 g_list_free (list_prevent);
363 /* The username widgets: */
364 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
365 /* Auto-capitalization is the default, so let's turn it off: */
366 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
367 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
368 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
369 gtk_widget_show (self->entry_user_username);
370 connect_for_modified (self, self->entry_user_username);
371 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
372 gtk_widget_show (caption);
374 /* Prevent the use of some characters in the username,
375 * as required by our UI specification: */
376 easysetup_validating_entry_set_unallowed_characters_whitespace (
377 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
379 /* Set max length as in the UI spec:
380 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
381 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
383 /* The password widgets: */
384 self->entry_user_password = gtk_entry_new ();
385 /* Auto-capitalization is the default, so let's turn it off: */
386 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password), HILDON_GTK_INPUT_MODE_FULL);
387 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
388 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
389 caption = create_caption_new_with_asterix (self, sizegroup,
390 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
391 gtk_widget_show (self->entry_user_password);
392 connect_for_modified (self, self->entry_user_password);
393 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
394 gtk_widget_show (caption);
396 /* The email address widgets: */
397 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
398 /* Auto-capitalization is the default, so let's turn it off: */
399 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
400 caption = create_caption_new_with_asterix (self, sizegroup,
401 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
402 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
403 gtk_widget_show (self->entry_user_email);
404 connect_for_modified (self, self->entry_user_email);
405 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
406 gtk_widget_show (caption);
408 /* Set max length as in the UI spec:
409 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
410 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
413 /* Signature button: */
414 if (!self->button_signature)
415 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
416 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
417 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
418 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
419 gtk_widget_show (self->button_signature);
420 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
421 gtk_widget_show (caption);
423 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
424 G_CALLBACK (on_button_signature), self);
426 gtk_widget_show (GTK_WIDGET (box));
428 return GTK_WIDGET (box);
431 /** Change the caption title for the incoming server,
432 * as specified in the UI spec:
434 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
437 (protocol == MODEST_PROTOCOL_STORE_POP ?
438 _("mail_fi_emailtype_pop3") :
439 _("mail_fi_emailtype_imap") );
442 /* Note that this produces a compiler warning,
443 * because the compiler does not know that the translated string will have a %s in it.
444 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
445 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
446 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
447 g_free(incomingserver_title);
450 /** Change the caption title for the incoming server,
451 * as specified in the UI spec:
453 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
455 /* Fill the combo with appropriately titled choices for POP or IMAP. */
456 /* The choices are the same, but the titles are different, as in the UI spec. */
457 modest_serversecurity_combo_box_fill (
458 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
461 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
463 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
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 incoming server widgets: */
471 if(!self->entry_incomingserver)
472 self->entry_incomingserver = gtk_entry_new ();
473 /* Auto-capitalization is the default, so let's turn it off: */
474 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
476 if (self->caption_incoming)
477 gtk_widget_destroy (self->caption_incoming);
479 /* The caption title will be updated in update_incoming_server_title().
480 * so this default text will never be seen: */
481 /* (Note: Changing the title seems pointless. murrayc) */
482 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
483 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
484 gtk_widget_show (self->entry_incomingserver);
485 connect_for_modified (self, self->entry_incomingserver);
486 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
487 gtk_widget_show (self->caption_incoming);
489 /* The secure connection widgets: */
490 /* This will be filled by update_incoming_server_security_choices(). */
491 if (!self->combo_incoming_security)
492 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
493 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
494 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
495 gtk_widget_show (self->combo_incoming_security);
496 connect_for_modified (self, self->combo_incoming_security);
497 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
498 gtk_widget_show (caption);
500 /* Show a default port number when the security method changes, as per the UI spec: */
501 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
504 /* The port widgets: */
505 /* TODO: There are various rules about this in the UI spec. */
506 if (!self->entry_incoming_port)
507 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
508 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
509 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
510 gtk_widget_show (self->entry_incoming_port);
511 connect_for_modified (self, self->entry_incoming_port);
512 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
513 gtk_widget_show (caption);
515 /* The secure authentication widgets: */
516 if(!self->checkbox_incoming_auth)
517 self->checkbox_incoming_auth =
518 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
519 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, MODEST_MARGIN_HALF);
520 gtk_widget_show (self->checkbox_incoming_auth);
521 connect_for_modified (self, self->checkbox_incoming_auth);
523 gtk_widget_show (GTK_WIDGET (box));
525 return GTK_WIDGET (box);
529 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
531 GtkWidget *widget = GTK_WIDGET (user_data);
533 /* Enable the widget only if the toggle button is active: */
534 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
535 gtk_widget_set_sensitive (widget, enable);
538 /* Make the sensitivity of a widget depend on a toggle button.
541 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
543 g_signal_connect (G_OBJECT (button), "toggled",
544 G_CALLBACK (on_toggle_button_changed), widget);
546 /* Set the starting sensitivity: */
547 on_toggle_button_changed (button, widget);
551 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
553 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
555 /* Create the window if necessary: */
556 if (!(self->specific_window)) {
557 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
558 modest_connection_specific_smtp_window_fill_with_connections (
559 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
563 /* Show the window: */
564 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
565 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
566 gtk_widget_show (self->specific_window);
570 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
572 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
574 ModestProtocol protocol_security =
575 modest_secureauth_combo_box_get_active_secureauth (
576 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
577 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
579 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
580 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
584 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
586 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
588 const gint port_number =
589 modest_serversecurity_combo_box_get_active_serversecurity_port (
590 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
592 if(port_number != 0) {
593 hildon_number_editor_set_value (
594 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
599 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
601 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
603 const gint port_number =
604 modest_serversecurity_combo_box_get_active_serversecurity_port (
605 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
607 if(port_number != 0) {
608 hildon_number_editor_set_value (
609 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
614 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
616 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
618 /* Create a size group to be used by all captions.
619 * Note that HildonCaption does not create a default size group if we do not specify one.
620 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
621 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
623 /* The outgoing server widgets: */
624 if (!self->entry_outgoingserver)
625 self->entry_outgoingserver = gtk_entry_new ();
626 /* Auto-capitalization is the default, so let's turn it off: */
627 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
628 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
629 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
630 gtk_widget_show (self->entry_outgoingserver);
631 connect_for_modified (self, self->entry_outgoingserver);
632 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
633 gtk_widget_show (caption);
635 /* The secure authentication widgets: */
636 if (!self->combo_outgoing_auth)
637 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
638 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
639 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
640 gtk_widget_show (self->combo_outgoing_auth);
641 connect_for_modified (self, self->combo_outgoing_auth);
642 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
643 gtk_widget_show (caption);
645 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
646 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
648 /* The username widgets: */
649 self->entry_outgoing_username = GTK_WIDGET (easysetup_validating_entry_new ());
650 /* Auto-capitalization is the default, so let's turn it off: */
651 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
652 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
653 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
654 gtk_widget_show (self->entry_outgoing_username);
655 connect_for_modified (self, self->entry_outgoing_username);
656 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
657 gtk_widget_show (self->caption_outgoing_username);
659 /* Prevent the use of some characters in the username,
660 * as required by our UI specification: */
661 easysetup_validating_entry_set_unallowed_characters_whitespace (
662 EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
664 /* Set max length as in the UI spec:
665 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
666 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
668 /* The password widgets: */
669 self->entry_outgoing_password = gtk_entry_new ();
670 /* Auto-capitalization is the default, so let's turn it off: */
671 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password), HILDON_GTK_INPUT_MODE_FULL);
672 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
673 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
674 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
675 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
676 gtk_widget_show (self->entry_outgoing_password);
677 connect_for_modified (self, self->entry_outgoing_password);
678 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
679 gtk_widget_show (self->caption_outgoing_password);
681 /* The secure connection widgets: */
682 /* This will be filled and set with modest_serversecurity_combo_box_fill()
683 * and modest_serversecurity_combo_box_set_active_serversecurity().
685 if (!self->combo_outgoing_security)
686 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
687 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
688 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
689 gtk_widget_show (self->combo_outgoing_security);
690 connect_for_modified (self, self->combo_outgoing_security);
691 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
692 gtk_widget_show (caption);
694 /* Show a default port number when the security method changes, as per the UI spec: */
695 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
697 /* The port widgets: */
698 if (!self->entry_outgoing_port)
699 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
700 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
701 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
702 gtk_widget_show (self->entry_outgoing_port);
703 connect_for_modified (self, self->entry_outgoing_port);
704 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
705 gtk_widget_show (caption);
707 GtkWidget *separator = gtk_hseparator_new ();
708 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
709 gtk_widget_show (separator);
711 /* connection-specific checkbox: */
712 if (!self->checkbox_outgoing_smtp_specific) {
713 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
714 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
717 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, MODEST_MARGIN_HALF);
718 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
719 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
721 /* Connection-specific SMTP-Severs Edit button: */
722 if (!self->button_outgoing_smtp_servers)
723 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
724 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
725 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
726 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
727 gtk_widget_show (self->button_outgoing_smtp_servers);
728 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
729 gtk_widget_show (caption);
731 /* Only enable the button when the checkbox is checked: */
732 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
733 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
735 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
736 G_CALLBACK (on_button_outgoing_smtp_servers), self);
739 gtk_widget_show (GTK_WIDGET (box));
741 return GTK_WIDGET (box);
745 check_data (ModestAccountSettingsDialog *self)
747 /* Check that the title is not already in use: */
748 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
749 if ((!account_title) || (strlen(account_title) == 0))
750 return FALSE; /* Should be prevented already anyway. */
752 if (strcmp(account_title, self->original_account_title) != 0) {
753 /* Check the changed title: */
754 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
758 /* Warn the user via a dialog: */
759 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
765 /* Check that the email address is valud: */
766 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
767 if ((!email_address) || (strlen(email_address) == 0))
770 if (!modest_text_utils_validate_email_address (email_address)) {
771 /* Warn the user via a dialog: */
772 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
774 /* Return focus to the email address entry: */
775 gtk_widget_grab_focus (self->entry_user_email);
780 /* TODO: The UI Spec wants us to check that the servernames are valid,
781 * but does not specify how.
789 on_response (GtkDialog *wizard_dialog,
793 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
794 enable_buttons (self);
796 gboolean prevent_response = FALSE;
798 /* Warn about unsaved changes: */
799 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
800 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
803 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
804 _("imum_nc_wizard_confirm_lose_changes") ));
806 const gint dialog_response = gtk_dialog_run (dialog);
807 gtk_widget_destroy (GTK_WIDGET (dialog));
809 if (dialog_response != GTK_RESPONSE_OK)
810 prevent_response = TRUE;
812 /* Check for invalid input: */
813 else if (!check_data (self)) {
814 prevent_response = TRUE;
817 if (prevent_response) {
818 /* This is a nasty hack. murrayc. */
819 /* Don't let the dialog close */
820 g_signal_stop_emission_by_name (wizard_dialog, "response");
825 if (response_id == GTK_RESPONSE_OK) {
826 /* Try to save the changes: */
827 const gboolean saved = save_configuration (self);
829 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
831 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
836 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
838 /* Create the notebook to be used by the GtkDialog base class:
839 * Each page of the notebook will be a page of the wizard: */
840 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
843 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
845 /* Get the account manager object,
846 * so we can check for existing accounts,
847 * and create new accounts: */
848 self->account_manager = modest_runtime_get_account_mgr ();
849 g_assert (self->account_manager);
850 g_object_ref (self->account_manager);
852 /* Create the common pages,
854 self->page_account_details = create_page_account_details (self);
855 self->page_user_details = create_page_user_details (self);
856 self->page_incoming = create_page_incoming (self);
857 self->page_outgoing = create_page_outgoing (self);
859 /* Add the notebook pages: */
860 gtk_notebook_append_page (notebook, self->page_account_details,
861 gtk_label_new (_("mcen_ti_account_settings_account")));
862 gtk_notebook_append_page (notebook, self->page_user_details,
863 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
864 gtk_notebook_append_page (notebook, self->page_incoming,
865 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
866 gtk_notebook_append_page (notebook, self->page_outgoing,
867 gtk_label_new (_("mcen_ti_advsetup_sending")));
869 GtkDialog *dialog = GTK_DIALOG (self);
870 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
871 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
872 gtk_widget_show (GTK_WIDGET (notebook));
874 /* Add the buttons: */
875 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
876 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
878 /* Connect to the dialog's response signal: */
879 /* We use connect-before
880 * so we can stop the signal emission,
881 * to stop the default signal handler from closing the dialog.
883 g_signal_connect (G_OBJECT (self), "response",
884 G_CALLBACK (on_response), self);
886 self->modified = FALSE;
889 ModestAccountSettingsDialog*
890 modest_account_settings_dialog_new (void)
892 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
895 /** Update the UI with the stored account details, so they can be edited.
896 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
898 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
903 /* Save the account name so we can refer to it later: */
904 if (dialog->account_name)
905 g_free (dialog->account_name);
906 dialog->account_name = g_strdup (account_name);
909 /* Get the account data for this account name: */
910 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
913 g_printerr ("modest: failed to get account data for %s\n", account_name);
917 /* Save the account title so we can refer to it if the user changes it: */
918 if (dialog->original_account_title)
919 g_free (dialog->original_account_title);
920 dialog->original_account_title = g_strdup (account_data->display_name);
923 if (!(account_data->store_account)) {
924 g_printerr ("modest: account has no stores: %s\n", account_name);
928 /* Show the account data in the widgets: */
930 /* Note that we never show the non-display name in the UI.
931 * (Though the display name defaults to the non-display name at the start.) */
932 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
933 account_data->display_name ? account_data->display_name : "");
935 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
936 account_data->fullname ? account_data->fullname : "");
937 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
938 account_data->email ? account_data->email : "");
940 ModestServerAccountData *incoming_account = account_data->store_account;
942 if (incoming_account)
943 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
944 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
945 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
947 /* Default to something, though no default is specified in the UI spec: */
948 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
950 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
953 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
954 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
955 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
958 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
959 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
960 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
962 /* Only show the leave-on-server checkbox for POP,
963 * as per the UI spec: */
964 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
965 gtk_widget_hide (dialog->checkbox_leave_messages);
967 gtk_widget_show (dialog->checkbox_leave_messages);
970 if (incoming_account) {
971 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
972 incoming_account->username ? incoming_account->username : "");
973 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
974 incoming_account->password ? incoming_account->password : "");
976 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
977 incoming_account->hostname ? incoming_account->hostname : "");
979 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
980 dialog->account_manager, incoming_account->account_name);
981 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
982 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
984 update_incoming_server_title (dialog, incoming_account->proto);
985 update_incoming_server_security_choices (dialog, incoming_account->proto);
987 const ModestProtocol security = modest_server_account_get_security (
988 dialog->account_manager, incoming_account->account_name);
989 modest_serversecurity_combo_box_set_active_serversecurity (
990 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
992 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
993 MODEST_ACCOUNT_PORT, TRUE /* server account */);
994 hildon_number_editor_set_value (
995 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
999 ModestServerAccountData *outgoing_account = account_data->transport_account;
1000 if (outgoing_account) {
1001 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1002 outgoing_account->hostname ? outgoing_account->hostname : "");
1004 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1005 outgoing_account->username ? outgoing_account->username : "");
1006 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1007 outgoing_account->password ? outgoing_account->password : "");
1009 /* Get the secure-auth setting: */
1010 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
1011 dialog->account_manager, outgoing_account->account_name);
1012 modest_secureauth_combo_box_set_active_secureauth (
1013 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1014 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1016 modest_serversecurity_combo_box_fill (
1017 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1019 /* Get the security setting: */
1020 const ModestProtocol security = modest_server_account_get_security (
1021 dialog->account_manager, outgoing_account->account_name);
1022 modest_serversecurity_combo_box_set_active_serversecurity (
1023 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1025 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1026 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1027 hildon_number_editor_set_value (
1028 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1031 /* account_data->is_enabled, */
1032 /*account_data->is_default, */
1034 /* account_data->store_account->proto */
1036 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1038 /* Unset the modified flag so we can detect changes later: */
1039 dialog->modified = FALSE;
1043 save_configuration (ModestAccountSettingsDialog *dialog)
1045 g_assert (dialog->account_name);
1047 const gchar* account_name = dialog->account_name;
1049 /* Set the account data from the widgets: */
1050 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1051 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1052 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1056 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1057 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1058 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1063 if (dialog->signature_dialog) {
1064 gboolean use_signature = FALSE;
1065 gchar *signature = modest_signature_editor_dialog_get_settings (
1066 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1069 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1070 signature, use_signature);
1074 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1075 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1076 modest_account_mgr_set_string (dialog->account_manager, account_name,
1077 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1080 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1081 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1082 modest_account_mgr_set_int (dialog->account_manager, account_name,
1083 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1085 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1086 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1087 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1092 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1093 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1094 g_assert (incoming_account_name);
1096 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1097 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1098 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1102 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1103 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1104 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1108 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1109 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1110 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1114 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1115 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1116 ? MODEST_PROTOCOL_AUTH_PASSWORD
1117 : MODEST_PROTOCOL_AUTH_NONE;
1118 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1120 const ModestProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1121 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1122 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1125 gint port_num = hildon_number_editor_get_value (
1126 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1127 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1128 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1130 g_free (incoming_account_name);
1133 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1134 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1135 g_assert (outgoing_account_name);
1137 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1138 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1139 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1143 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1144 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1145 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1149 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1150 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1151 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1155 const ModestProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1156 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1157 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1159 const ModestProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1160 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1161 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1164 port_num = hildon_number_editor_get_value (
1165 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1166 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1167 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1169 g_free (outgoing_account_name);
1172 /* Set the changed account title last, to simplify the previous code: */
1173 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1174 if ((!account_title) || (strlen(account_title) == 0))
1175 return FALSE; /* Should be prevented already anyway. */
1177 if (strcmp(account_title, account_name) != 0) {
1178 /* Change the title: */
1179 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1180 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1185 /* Save connection-specific SMTP server accounts: */
1186 if (dialog->specific_window)
1187 return modest_connection_specific_smtp_window_save_server_accounts (
1188 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1193 static gboolean entry_is_empty (GtkWidget *entry)
1198 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1199 if ((!text) || (strlen(text) == 0))
1206 enable_buttons (ModestAccountSettingsDialog *self)
1208 gboolean enable_ok = TRUE;
1210 /* The account details title is mandatory: */
1211 if (entry_is_empty(self->entry_account_title))
1214 /* The user details username is mandatory: */
1215 if (entry_is_empty(self->entry_user_username))
1218 /* The user details email address is mandatory: */
1219 if (enable_ok && entry_is_empty (self->entry_user_email))
1222 /* The custom incoming server is mandatory: */
1223 if (entry_is_empty(self->entry_incomingserver))
1226 /* Enable the buttons,
1227 * identifying them via their associated response codes:
1229 GtkDialog *dialog_base = GTK_DIALOG (self);
1230 gtk_dialog_set_response_sensitive (dialog_base,
1236 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1238 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1239 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1242 object_class->get_property = modest_account_settings_dialog_get_property;
1243 object_class->set_property = modest_account_settings_dialog_set_property;
1244 object_class->dispose = modest_account_settings_dialog_dispose;
1245 object_class->finalize = modest_account_settings_dialog_finalize;
1249 show_error (GtkWindow *parent_window, const gchar* text)
1251 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1257 gtk_dialog_run (dialog);
1258 gtk_widget_destroy (GTK_WIDGET (dialog));
1262 show_ok (GtkWindow *parent_window, const gchar* text)
1264 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1270 gtk_dialog_run (dialog);
1271 gtk_widget_destroy (GTK_WIDGET (dialog));