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);
221 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
223 ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
224 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
228 create_page_account_details (ModestAccountSettingsDialog *self)
230 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
231 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
232 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
233 gtk_widget_show (label);
235 /* Create a size group to be used by all captions.
236 * Note that HildonCaption does not create a default size group if we do not specify one.
237 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
238 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
240 /* The description widgets: */
241 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
242 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
243 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
244 gtk_widget_show (self->entry_account_title);
245 connect_for_modified (self, self->entry_account_title);
246 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
247 gtk_widget_show (caption);
249 /* Prevent the use of some characters in the account title,
250 * as required by our UI specification: */
251 GList *list_prevent = NULL;
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 list_prevent = g_list_append (list_prevent, "*");
256 list_prevent = g_list_append (list_prevent, "?");
257 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
258 list_prevent = g_list_append (list_prevent, "“");
259 list_prevent = g_list_append (list_prevent, "<");
260 list_prevent = g_list_append (list_prevent, ">");
261 list_prevent = g_list_append (list_prevent, "|");
262 list_prevent = g_list_append (list_prevent, "^");
263 modest_validating_entry_set_unallowed_characters (
264 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
265 g_list_free (list_prevent);
267 /* Set max length as in the UI spec:
268 * The UI spec seems to want us to show a dialog if we hit the maximum. */
269 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
270 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
273 /* The retrieve combobox: */
274 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
275 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
276 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
277 gtk_widget_show (self->combo_retrieve);
278 connect_for_modified (self, self->combo_retrieve);
279 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
280 gtk_widget_show (caption);
282 /* The limit-retrieve combobox: */
283 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
284 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
285 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
286 gtk_widget_show (self->combo_limit_retrieve);
287 connect_for_modified (self, self->combo_limit_retrieve);
288 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
289 gtk_widget_show (caption);
291 /* The leave-messages widgets: */
292 if(!self->checkbox_leave_messages)
293 self->checkbox_leave_messages =
294 gtk_check_button_new_with_label (_("mcen_fi_advsetup_leave_on_server"));
295 gtk_box_pack_start (GTK_BOX (box), self->checkbox_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
296 gtk_widget_show (self->checkbox_leave_messages);
297 connect_for_modified (self, self->checkbox_leave_messages);
299 gtk_widget_show (GTK_WIDGET (box));
301 return GTK_WIDGET (box);
305 on_button_signature (GtkButton *button, gpointer user_data)
307 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
309 /* Create the window, if necessary: */
310 if (!(self->signature_dialog)) {
311 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
313 gboolean use_signature = FALSE;
314 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
316 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
317 modest_signature_editor_dialog_set_settings (
318 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
319 use_signature, signature, account_title);
324 /* Show the window: */
325 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
326 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
327 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
328 gtk_widget_hide (self->signature_dialog);
329 if (response != GTK_RESPONSE_OK) {
330 /* Destroy the widget now, and its data: */
331 gtk_widget_destroy (self->signature_dialog);
332 self->signature_dialog = NULL;
335 /* Mark modified, so we use the dialog's data later: */
336 self->modified = TRUE;
341 create_page_user_details (ModestAccountSettingsDialog *self)
343 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
345 /* Create a size group to be used by all captions.
346 * Note that HildonCaption does not create a default size group if we do not specify one.
347 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
348 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
350 /* The name widgets: */
351 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
352 /* Auto-capitalization is the default, so let's turn it off: */
353 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
354 /* Set max length as in the UI spec:
355 * The UI spec seems to want us to show a dialog if we hit the maximum. */
356 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
357 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
359 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
360 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
361 gtk_widget_show (self->entry_user_name);
362 connect_for_modified (self, self->entry_user_name);
363 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
364 gtk_widget_show (caption);
366 /* Prevent the use of some characters in the name,
367 * as required by our UI specification: */
368 GList *list_prevent = NULL;
369 list_prevent = g_list_append (list_prevent, "<");
370 list_prevent = g_list_append (list_prevent, ">");
371 modest_validating_entry_set_unallowed_characters (
372 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
373 g_list_free (list_prevent);
375 /* The username widgets: */
376 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
377 /* Auto-capitalization is the default, so let's turn it off: */
378 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
379 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
380 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
381 gtk_widget_show (self->entry_user_username);
382 connect_for_modified (self, self->entry_user_username);
383 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
384 gtk_widget_show (caption);
386 /* Prevent the use of some characters in the username,
387 * as required by our UI specification: */
388 modest_validating_entry_set_unallowed_characters_whitespace (
389 MODEST_VALIDATING_ENTRY (self->entry_user_username));
391 /* Set max length as in the UI spec:
392 * The UI spec seems to want us to show a dialog if we hit the maximum. */
393 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
394 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
397 /* The password widgets: */
398 self->entry_user_password = gtk_entry_new ();
399 /* Auto-capitalization is the default, so let's turn it off: */
400 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password), HILDON_GTK_INPUT_MODE_FULL);
401 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
402 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
403 caption = create_caption_new_with_asterix (self, sizegroup,
404 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
405 gtk_widget_show (self->entry_user_password);
406 connect_for_modified (self, self->entry_user_password);
407 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
408 gtk_widget_show (caption);
410 /* The email address widgets: */
411 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
412 /* Auto-capitalization is the default, so let's turn it off: */
413 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
414 caption = create_caption_new_with_asterix (self, sizegroup,
415 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
416 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
417 gtk_widget_show (self->entry_user_email);
418 connect_for_modified (self, self->entry_user_email);
419 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
420 gtk_widget_show (caption);
422 /* Set max length as in the UI spec:
423 * The UI spec seems to want us to show a dialog if we hit the maximum. */
424 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
425 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
428 /* Signature button: */
429 if (!self->button_signature)
430 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
431 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
432 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
433 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
434 gtk_widget_show (self->button_signature);
435 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
436 gtk_widget_show (caption);
438 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
439 G_CALLBACK (on_button_signature), self);
441 gtk_widget_show (GTK_WIDGET (box));
443 return GTK_WIDGET (box);
446 /** Change the caption title for the incoming server,
447 * as specified in the UI spec:
449 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
452 (protocol == MODEST_PROTOCOL_STORE_POP ?
453 _("mail_fi_emailtype_pop3") :
454 _("mail_fi_emailtype_imap") );
457 /* Note that this produces a compiler warning,
458 * because the compiler does not know that the translated string will have a %s in it.
459 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
460 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
461 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
462 g_free(incomingserver_title);
465 /** Change the caption title for the incoming server,
466 * as specified in the UI spec:
468 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
470 /* Fill the combo with appropriately titled choices for POP or IMAP. */
471 /* The choices are the same, but the titles are different, as in the UI spec. */
472 modest_serversecurity_combo_box_fill (
473 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
476 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
478 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
480 /* Create a size group to be used by all captions.
481 * Note that HildonCaption does not create a default size group if we do not specify one.
482 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
483 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
485 /* The incoming server widgets: */
486 if(!self->entry_incomingserver)
487 self->entry_incomingserver = gtk_entry_new ();
488 /* Auto-capitalization is the default, so let's turn it off: */
489 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
491 if (self->caption_incoming)
492 gtk_widget_destroy (self->caption_incoming);
494 /* The caption title will be updated in update_incoming_server_title().
495 * so this default text will never be seen: */
496 /* (Note: Changing the title seems pointless. murrayc) */
497 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
498 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
499 gtk_widget_show (self->entry_incomingserver);
500 connect_for_modified (self, self->entry_incomingserver);
501 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
502 gtk_widget_show (self->caption_incoming);
504 /* The secure connection widgets: */
505 /* This will be filled by update_incoming_server_security_choices(). */
506 if (!self->combo_incoming_security)
507 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
508 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
509 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
510 gtk_widget_show (self->combo_incoming_security);
511 connect_for_modified (self, self->combo_incoming_security);
512 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
513 gtk_widget_show (caption);
515 /* Show a default port number when the security method changes, as per the UI spec: */
516 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
519 /* The port widgets: */
520 /* TODO: There are various rules about this in the UI spec. */
521 if (!self->entry_incoming_port)
522 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
523 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
524 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
525 gtk_widget_show (self->entry_incoming_port);
526 connect_for_modified (self, self->entry_incoming_port);
527 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
528 gtk_widget_show (caption);
530 /* The secure authentication widgets: */
531 if(!self->checkbox_incoming_auth)
532 self->checkbox_incoming_auth =
533 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
534 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, MODEST_MARGIN_HALF);
535 gtk_widget_show (self->checkbox_incoming_auth);
536 connect_for_modified (self, self->checkbox_incoming_auth);
538 gtk_widget_show (GTK_WIDGET (box));
540 return GTK_WIDGET (box);
544 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
546 GtkWidget *widget = GTK_WIDGET (user_data);
548 /* Enable the widget only if the toggle button is active: */
549 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
550 gtk_widget_set_sensitive (widget, enable);
553 /* Make the sensitivity of a widget depend on a toggle button.
556 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
558 g_signal_connect (G_OBJECT (button), "toggled",
559 G_CALLBACK (on_toggle_button_changed), widget);
561 /* Set the starting sensitivity: */
562 on_toggle_button_changed (button, widget);
566 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
568 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
570 /* Create the window if necessary: */
571 if (!(self->specific_window)) {
572 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
573 modest_connection_specific_smtp_window_fill_with_connections (
574 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
578 /* Show the window: */
579 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
580 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
581 gtk_widget_show (self->specific_window);
585 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
587 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
589 ModestProtocol protocol_security =
590 modest_secureauth_combo_box_get_active_secureauth (
591 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
592 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
594 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
595 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
599 on_combo_outgoing_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_outgoing_security));
607 if(port_number != 0) {
608 hildon_number_editor_set_value (
609 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
614 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
616 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
618 const gint port_number =
619 modest_serversecurity_combo_box_get_active_serversecurity_port (
620 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
622 if(port_number != 0) {
623 hildon_number_editor_set_value (
624 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
629 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
631 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
633 /* Create a size group to be used by all captions.
634 * Note that HildonCaption does not create a default size group if we do not specify one.
635 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
636 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
638 /* The outgoing server widgets: */
639 if (!self->entry_outgoingserver)
640 self->entry_outgoingserver = gtk_entry_new ();
641 /* Auto-capitalization is the default, so let's turn it off: */
642 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
643 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
644 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
645 gtk_widget_show (self->entry_outgoingserver);
646 connect_for_modified (self, self->entry_outgoingserver);
647 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
648 gtk_widget_show (caption);
650 /* The secure authentication widgets: */
651 if (!self->combo_outgoing_auth)
652 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
653 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
654 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
655 gtk_widget_show (self->combo_outgoing_auth);
656 connect_for_modified (self, self->combo_outgoing_auth);
657 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
658 gtk_widget_show (caption);
660 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
661 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
663 /* The username widgets: */
664 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
665 /* Auto-capitalization is the default, so let's turn it off: */
666 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
667 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
668 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
669 gtk_widget_show (self->entry_outgoing_username);
670 connect_for_modified (self, self->entry_outgoing_username);
671 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
672 gtk_widget_show (self->caption_outgoing_username);
674 /* Prevent the use of some characters in the username,
675 * as required by our UI specification: */
676 modest_validating_entry_set_unallowed_characters_whitespace (
677 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
679 /* Set max length as in the UI spec:
680 * The UI spec seems to want us to show a dialog if we hit the maximum. */
681 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
682 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
685 /* The password widgets: */
686 self->entry_outgoing_password = gtk_entry_new ();
687 /* Auto-capitalization is the default, so let's turn it off: */
688 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password), HILDON_GTK_INPUT_MODE_FULL);
689 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
690 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
691 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
692 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
693 gtk_widget_show (self->entry_outgoing_password);
694 connect_for_modified (self, self->entry_outgoing_password);
695 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
696 gtk_widget_show (self->caption_outgoing_password);
698 /* The secure connection widgets: */
699 /* This will be filled and set with modest_serversecurity_combo_box_fill()
700 * and modest_serversecurity_combo_box_set_active_serversecurity().
702 if (!self->combo_outgoing_security)
703 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
704 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
705 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
706 gtk_widget_show (self->combo_outgoing_security);
707 connect_for_modified (self, self->combo_outgoing_security);
708 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
709 gtk_widget_show (caption);
711 /* Show a default port number when the security method changes, as per the UI spec: */
712 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
714 /* The port widgets: */
715 if (!self->entry_outgoing_port)
716 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
717 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
718 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
719 gtk_widget_show (self->entry_outgoing_port);
720 connect_for_modified (self, self->entry_outgoing_port);
721 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
722 gtk_widget_show (caption);
724 GtkWidget *separator = gtk_hseparator_new ();
725 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
726 gtk_widget_show (separator);
728 /* connection-specific checkbox: */
729 if (!self->checkbox_outgoing_smtp_specific) {
730 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
731 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
734 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, MODEST_MARGIN_HALF);
735 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
736 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
738 /* Connection-specific SMTP-Severs Edit button: */
739 if (!self->button_outgoing_smtp_servers)
740 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
741 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
742 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
743 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
744 gtk_widget_show (self->button_outgoing_smtp_servers);
745 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
746 gtk_widget_show (caption);
748 /* Only enable the button when the checkbox is checked: */
749 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
750 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
752 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
753 G_CALLBACK (on_button_outgoing_smtp_servers), self);
756 gtk_widget_show (GTK_WIDGET (box));
758 return GTK_WIDGET (box);
762 check_data (ModestAccountSettingsDialog *self)
764 /* Check that the title is not already in use: */
765 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
766 if ((!account_title) || (strlen(account_title) == 0))
767 return FALSE; /* Should be prevented already anyway. */
769 if (strcmp(account_title, self->original_account_title) != 0) {
770 /* Check the changed title: */
771 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
775 /* Warn the user via a dialog: */
776 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
782 /* Check that the email address is valud: */
783 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
784 if ((!email_address) || (strlen(email_address) == 0))
787 if (!modest_text_utils_validate_email_address (email_address)) {
788 /* Warn the user via a dialog: */
789 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
791 /* Return focus to the email address entry: */
792 gtk_widget_grab_focus (self->entry_user_email);
797 /* TODO: The UI Spec wants us to check that the servernames are valid,
798 * but does not specify how.
806 on_response (GtkDialog *wizard_dialog,
810 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
811 enable_buttons (self);
813 gboolean prevent_response = FALSE;
815 /* Warn about unsaved changes: */
816 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
817 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
820 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
821 _("imum_nc_wizard_confirm_lose_changes") ));
823 const gint dialog_response = gtk_dialog_run (dialog);
824 gtk_widget_destroy (GTK_WIDGET (dialog));
826 if (dialog_response != GTK_RESPONSE_OK)
827 prevent_response = TRUE;
829 /* Check for invalid input: */
830 else if (!check_data (self)) {
831 prevent_response = TRUE;
834 if (prevent_response) {
835 /* This is a nasty hack. murrayc. */
836 /* Don't let the dialog close */
837 g_signal_stop_emission_by_name (wizard_dialog, "response");
842 if (response_id == GTK_RESPONSE_OK) {
843 /* Try to save the changes: */
844 const gboolean saved = save_configuration (self);
846 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
848 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
853 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
855 /* Create the notebook to be used by the GtkDialog base class:
856 * Each page of the notebook will be a page of the wizard: */
857 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
860 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
862 /* Get the account manager object,
863 * so we can check for existing accounts,
864 * and create new accounts: */
865 self->account_manager = modest_runtime_get_account_mgr ();
866 g_assert (self->account_manager);
867 g_object_ref (self->account_manager);
869 /* Create the common pages,
871 self->page_account_details = create_page_account_details (self);
872 self->page_user_details = create_page_user_details (self);
873 self->page_incoming = create_page_incoming (self);
874 self->page_outgoing = create_page_outgoing (self);
876 /* Add the notebook pages: */
877 gtk_notebook_append_page (notebook, self->page_account_details,
878 gtk_label_new (_("mcen_ti_account_settings_account")));
879 gtk_notebook_append_page (notebook, self->page_user_details,
880 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
881 gtk_notebook_append_page (notebook, self->page_incoming,
882 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
883 gtk_notebook_append_page (notebook, self->page_outgoing,
884 gtk_label_new (_("mcen_ti_advsetup_sending")));
886 GtkDialog *dialog = GTK_DIALOG (self);
887 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
888 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
889 gtk_widget_show (GTK_WIDGET (notebook));
891 /* Add the buttons: */
892 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
893 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
895 /* Connect to the dialog's response signal: */
896 /* We use connect-before
897 * so we can stop the signal emission,
898 * to stop the default signal handler from closing the dialog.
900 g_signal_connect (G_OBJECT (self), "response",
901 G_CALLBACK (on_response), self);
903 self->modified = FALSE;
906 ModestAccountSettingsDialog*
907 modest_account_settings_dialog_new (void)
909 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
912 /** Update the UI with the stored account details, so they can be edited.
913 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
915 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
920 /* Save the account name so we can refer to it later: */
921 if (dialog->account_name)
922 g_free (dialog->account_name);
923 dialog->account_name = g_strdup (account_name);
926 /* Get the account data for this account name: */
927 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
930 g_printerr ("modest: failed to get account data for %s\n", account_name);
934 /* Save the account title so we can refer to it if the user changes it: */
935 if (dialog->original_account_title)
936 g_free (dialog->original_account_title);
937 dialog->original_account_title = g_strdup (account_data->display_name);
940 if (!(account_data->store_account)) {
941 g_printerr ("modest: account has no stores: %s\n", account_name);
945 /* Show the account data in the widgets: */
947 /* Note that we never show the non-display name in the UI.
948 * (Though the display name defaults to the non-display name at the start.) */
949 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
950 account_data->display_name ? account_data->display_name : "");
952 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
953 account_data->fullname ? account_data->fullname : "");
954 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
955 account_data->email ? account_data->email : "");
957 ModestServerAccountData *incoming_account = account_data->store_account;
959 if (incoming_account)
960 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
961 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
962 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
964 /* Default to something, though no default is specified in the UI spec: */
965 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
967 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
970 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
971 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
972 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
975 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
976 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
977 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
979 /* Only show the leave-on-server checkbox for POP,
980 * as per the UI spec: */
981 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
982 gtk_widget_hide (dialog->checkbox_leave_messages);
984 gtk_widget_show (dialog->checkbox_leave_messages);
987 if (incoming_account) {
988 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
989 incoming_account->username ? incoming_account->username : "");
990 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
991 incoming_account->password ? incoming_account->password : "");
993 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
994 incoming_account->hostname ? incoming_account->hostname : "");
996 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
997 dialog->account_manager, incoming_account->account_name);
998 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
999 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
1001 update_incoming_server_title (dialog, incoming_account->proto);
1002 update_incoming_server_security_choices (dialog, incoming_account->proto);
1004 const ModestProtocol security = modest_server_account_get_security (
1005 dialog->account_manager, incoming_account->account_name);
1006 modest_serversecurity_combo_box_set_active_serversecurity (
1007 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1009 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1010 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1011 hildon_number_editor_set_value (
1012 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1016 ModestServerAccountData *outgoing_account = account_data->transport_account;
1017 if (outgoing_account) {
1018 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1019 outgoing_account->hostname ? outgoing_account->hostname : "");
1021 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1022 outgoing_account->username ? outgoing_account->username : "");
1023 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1024 outgoing_account->password ? outgoing_account->password : "");
1026 /* Get the secure-auth setting: */
1027 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
1028 dialog->account_manager, outgoing_account->account_name);
1029 modest_secureauth_combo_box_set_active_secureauth (
1030 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1031 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1033 modest_serversecurity_combo_box_fill (
1034 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1036 /* Get the security setting: */
1037 const ModestProtocol security = modest_server_account_get_security (
1038 dialog->account_manager, outgoing_account->account_name);
1039 modest_serversecurity_combo_box_set_active_serversecurity (
1040 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1042 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1043 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1044 hildon_number_editor_set_value (
1045 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1048 /* account_data->is_enabled, */
1049 /*account_data->is_default, */
1051 /* account_data->store_account->proto */
1053 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1055 /* Unset the modified flag so we can detect changes later: */
1056 dialog->modified = FALSE;
1060 save_configuration (ModestAccountSettingsDialog *dialog)
1062 g_assert (dialog->account_name);
1064 const gchar* account_name = dialog->account_name;
1066 /* Set the account data from the widgets: */
1067 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1068 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1069 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1073 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1074 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1075 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1080 if (dialog->signature_dialog) {
1081 gboolean use_signature = FALSE;
1082 gchar *signature = modest_signature_editor_dialog_get_settings (
1083 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1086 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1087 signature, use_signature);
1091 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1092 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1093 modest_account_mgr_set_string (dialog->account_manager, account_name,
1094 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1097 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1098 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1099 modest_account_mgr_set_int (dialog->account_manager, account_name,
1100 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1102 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1103 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1104 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1109 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1110 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1111 g_assert (incoming_account_name);
1113 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1114 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1115 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1119 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1120 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1121 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1125 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1126 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1127 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1131 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1132 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1133 ? MODEST_PROTOCOL_AUTH_PASSWORD
1134 : MODEST_PROTOCOL_AUTH_NONE;
1135 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1137 const ModestProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1138 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1139 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1142 gint port_num = hildon_number_editor_get_value (
1143 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1144 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1145 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1147 g_free (incoming_account_name);
1150 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1151 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1152 g_assert (outgoing_account_name);
1154 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1155 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1156 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1160 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1161 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1162 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1166 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1167 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1168 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1172 const ModestProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1173 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1174 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1176 const ModestProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1177 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1178 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1181 port_num = hildon_number_editor_get_value (
1182 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1183 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1184 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1186 g_free (outgoing_account_name);
1189 /* Set the changed account title last, to simplify the previous code: */
1190 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1191 if ((!account_title) || (strlen(account_title) == 0))
1192 return FALSE; /* Should be prevented already anyway. */
1194 if (strcmp(account_title, account_name) != 0) {
1195 /* Change the title: */
1196 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1197 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1202 /* Save connection-specific SMTP server accounts: */
1203 if (dialog->specific_window)
1204 return modest_connection_specific_smtp_window_save_server_accounts (
1205 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1210 static gboolean entry_is_empty (GtkWidget *entry)
1215 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1216 if ((!text) || (strlen(text) == 0))
1223 enable_buttons (ModestAccountSettingsDialog *self)
1225 gboolean enable_ok = TRUE;
1227 /* The account details title is mandatory: */
1228 if (entry_is_empty(self->entry_account_title))
1231 /* The user details username is mandatory: */
1232 if (entry_is_empty(self->entry_user_username))
1235 /* The user details email address is mandatory: */
1236 if (enable_ok && entry_is_empty (self->entry_user_email))
1239 /* The custom incoming server is mandatory: */
1240 if (entry_is_empty(self->entry_incomingserver))
1243 /* Enable the buttons,
1244 * identifying them via their associated response codes:
1246 GtkDialog *dialog_base = GTK_DIALOG (self);
1247 gtk_dialog_set_response_sensitive (dialog_base,
1253 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1255 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1256 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1259 object_class->get_property = modest_account_settings_dialog_get_property;
1260 object_class->set_property = modest_account_settings_dialog_set_property;
1261 object_class->dispose = modest_account_settings_dialog_dispose;
1262 object_class->finalize = modest_account_settings_dialog_finalize;
1266 show_error (GtkWindow *parent_window, const gchar* text)
1268 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1274 gtk_dialog_run (dialog);
1275 gtk_widget_destroy (GTK_WIDGET (dialog));
1279 show_ok (GtkWindow *parent_window, const gchar* text)
1281 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1287 gtk_dialog_run (dialog);
1288 gtk_widget_destroy (GTK_WIDGET (dialog));