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 /* Set max length as in the UI spec:
343 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
344 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
345 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
346 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
347 gtk_widget_show (self->entry_user_name);
348 connect_for_modified (self, self->entry_user_name);
349 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
350 gtk_widget_show (caption);
352 /* Prevent the use of some characters in the name,
353 * as required by our UI specification: */
354 GList *list_prevent = NULL;
355 list_prevent = g_list_append (list_prevent, "<");
356 list_prevent = g_list_append (list_prevent, ">");
357 easysetup_validating_entry_set_unallowed_characters (
358 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
359 g_list_free (list_prevent);
361 /* The username widgets: */
362 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
363 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
364 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
365 gtk_widget_show (self->entry_user_username);
366 connect_for_modified (self, self->entry_user_username);
367 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
368 gtk_widget_show (caption);
370 /* Prevent the use of some characters in the username,
371 * as required by our UI specification: */
372 easysetup_validating_entry_set_unallowed_characters_whitespace (
373 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
375 /* Set max length as in the UI spec:
376 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
377 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
379 /* The password widgets: */
380 self->entry_user_password = gtk_entry_new ();
381 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
382 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
383 caption = create_caption_new_with_asterix (self, sizegroup,
384 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
385 gtk_widget_show (self->entry_user_password);
386 connect_for_modified (self, self->entry_user_password);
387 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
388 gtk_widget_show (caption);
390 /* The email address widgets: */
391 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
392 caption = create_caption_new_with_asterix (self, sizegroup,
393 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
394 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
395 gtk_widget_show (self->entry_user_email);
396 connect_for_modified (self, self->entry_user_email);
397 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
398 gtk_widget_show (caption);
400 /* Set max length as in the UI spec:
401 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
402 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
405 /* Signature button: */
406 if (!self->button_signature)
407 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
408 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
409 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
410 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
411 gtk_widget_show (self->button_signature);
412 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
413 gtk_widget_show (caption);
415 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
416 G_CALLBACK (on_button_signature), self);
418 gtk_widget_show (GTK_WIDGET (box));
420 return GTK_WIDGET (box);
423 /** Change the caption title for the incoming server,
424 * as specified in the UI spec:
426 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
429 (protocol == MODEST_PROTOCOL_STORE_POP ?
430 _("mail_fi_emailtype_pop3") :
431 _("mail_fi_emailtype_imap") );
434 /* Note that this produces a compiler warning,
435 * because the compiler does not know that the translated string will have a %s in it.
436 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
437 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
438 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
439 g_free(incomingserver_title);
442 /** Change the caption title for the incoming server,
443 * as specified in the UI spec:
445 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
447 /* Fill the combo with appropriately titled choices for POP or IMAP. */
448 /* The choices are the same, but the titles are different, as in the UI spec. */
449 modest_serversecurity_combo_box_fill (
450 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
453 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
455 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
457 /* Create a size group to be used by all captions.
458 * Note that HildonCaption does not create a default size group if we do not specify one.
459 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
460 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
462 /* The incoming server widgets: */
463 if(!self->entry_incomingserver)
464 self->entry_incomingserver = gtk_entry_new ();
466 if (self->caption_incoming)
467 gtk_widget_destroy (self->caption_incoming);
469 /* The caption title will be updated in update_incoming_server_title().
470 * so this default text will never be seen: */
471 /* (Note: Changing the title seems pointless. murrayc) */
472 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
473 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
474 gtk_widget_show (self->entry_incomingserver);
475 connect_for_modified (self, self->entry_incomingserver);
476 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
477 gtk_widget_show (self->caption_incoming);
479 /* The secure connection widgets: */
480 /* This will be filled by update_incoming_server_security_choices(). */
481 if (!self->combo_incoming_security)
482 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
483 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
484 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
485 gtk_widget_show (self->combo_incoming_security);
486 connect_for_modified (self, self->combo_incoming_security);
487 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
488 gtk_widget_show (caption);
490 /* Show a default port number when the security method changes, as per the UI spec: */
491 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
494 /* The port widgets: */
495 /* TODO: There are various rules about this in the UI spec. */
496 if (!self->entry_incoming_port)
497 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
498 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
499 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
500 gtk_widget_show (self->entry_incoming_port);
501 connect_for_modified (self, self->entry_incoming_port);
502 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
503 gtk_widget_show (caption);
505 /* The secure authentication widgets: */
506 if(!self->checkbox_incoming_auth)
507 self->checkbox_incoming_auth =
508 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
509 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, MODEST_MARGIN_HALF);
510 gtk_widget_show (self->checkbox_incoming_auth);
511 connect_for_modified (self, self->checkbox_incoming_auth);
513 gtk_widget_show (GTK_WIDGET (box));
515 return GTK_WIDGET (box);
519 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
521 GtkWidget *widget = GTK_WIDGET (user_data);
523 /* Enable the widget only if the toggle button is active: */
524 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
525 gtk_widget_set_sensitive (widget, enable);
528 /* Make the sensitivity of a widget depend on a toggle button.
531 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
533 g_signal_connect (G_OBJECT (button), "toggled",
534 G_CALLBACK (on_toggle_button_changed), widget);
536 /* Set the starting sensitivity: */
537 on_toggle_button_changed (button, widget);
541 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
543 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
545 /* Create the window if necessary: */
546 if (!(self->specific_window)) {
547 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
548 modest_connection_specific_smtp_window_fill_with_connections (
549 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
553 /* Show the window: */
554 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
555 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
556 gtk_widget_show (self->specific_window);
560 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
562 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
564 ModestProtocol protocol_security =
565 modest_secureauth_combo_box_get_active_secureauth (
566 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
567 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
569 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
570 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
574 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
576 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
578 const gint port_number =
579 modest_serversecurity_combo_box_get_active_serversecurity_port (
580 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
582 if(port_number != 0) {
583 hildon_number_editor_set_value (
584 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
589 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
591 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
593 const gint port_number =
594 modest_serversecurity_combo_box_get_active_serversecurity_port (
595 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
597 if(port_number != 0) {
598 hildon_number_editor_set_value (
599 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
604 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
606 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_HALF);
608 /* Create a size group to be used by all captions.
609 * Note that HildonCaption does not create a default size group if we do not specify one.
610 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
611 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
613 /* The outgoing server widgets: */
614 if (!self->entry_outgoingserver)
615 self->entry_outgoingserver = gtk_entry_new ();
616 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
617 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
618 gtk_widget_show (self->entry_outgoingserver);
619 connect_for_modified (self, self->entry_outgoingserver);
620 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
621 gtk_widget_show (caption);
623 /* The secure authentication widgets: */
624 if (!self->combo_outgoing_auth)
625 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
626 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
627 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
628 gtk_widget_show (self->combo_outgoing_auth);
629 connect_for_modified (self, self->combo_outgoing_auth);
630 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
631 gtk_widget_show (caption);
633 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
634 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
636 /* The username widgets: */
637 self->entry_outgoing_username = GTK_WIDGET (easysetup_validating_entry_new ());
638 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
639 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
640 gtk_widget_show (self->entry_outgoing_username);
641 connect_for_modified (self, self->entry_outgoing_username);
642 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
643 gtk_widget_show (self->caption_outgoing_username);
645 /* Prevent the use of some characters in the username,
646 * as required by our UI specification: */
647 easysetup_validating_entry_set_unallowed_characters_whitespace (
648 EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
650 /* Set max length as in the UI spec:
651 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
652 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
654 /* The password widgets: */
655 self->entry_outgoing_password = gtk_entry_new ();
656 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
657 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
658 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
659 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
660 gtk_widget_show (self->entry_outgoing_password);
661 connect_for_modified (self, self->entry_outgoing_password);
662 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
663 gtk_widget_show (self->caption_outgoing_password);
665 /* The secure connection widgets: */
666 /* This will be filled and set with modest_serversecurity_combo_box_fill()
667 * and modest_serversecurity_combo_box_set_active_serversecurity().
669 if (!self->combo_outgoing_security)
670 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
671 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
672 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
673 gtk_widget_show (self->combo_outgoing_security);
674 connect_for_modified (self, self->combo_outgoing_security);
675 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
676 gtk_widget_show (caption);
678 /* Show a default port number when the security method changes, as per the UI spec: */
679 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
681 /* The port widgets: */
682 if (!self->entry_outgoing_port)
683 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
684 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
685 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
686 gtk_widget_show (self->entry_outgoing_port);
687 connect_for_modified (self, self->entry_outgoing_port);
688 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
689 gtk_widget_show (caption);
691 GtkWidget *separator = gtk_hseparator_new ();
692 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
693 gtk_widget_show (separator);
695 /* connection-specific checkbox: */
696 if (!self->checkbox_outgoing_smtp_specific) {
697 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
698 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
701 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, MODEST_MARGIN_HALF);
702 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
703 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
705 /* Connection-specific SMTP-Severs Edit button: */
706 if (!self->button_outgoing_smtp_servers)
707 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
708 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
709 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
710 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
711 gtk_widget_show (self->button_outgoing_smtp_servers);
712 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
713 gtk_widget_show (caption);
715 /* Only enable the button when the checkbox is checked: */
716 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
717 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
719 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
720 G_CALLBACK (on_button_outgoing_smtp_servers), self);
723 gtk_widget_show (GTK_WIDGET (box));
725 return GTK_WIDGET (box);
729 check_data (ModestAccountSettingsDialog *self)
731 /* Check that the title is not already in use: */
732 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
733 if ((!account_title) || (strlen(account_title) == 0))
734 return FALSE; /* Should be prevented already anyway. */
736 if (strcmp(account_title, self->original_account_title) != 0) {
737 /* Check the changed title: */
738 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
742 /* Warn the user via a dialog: */
743 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
749 /* Check that the email address is valud: */
750 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
751 if ((!email_address) || (strlen(email_address) == 0))
754 if (!modest_text_utils_validate_email_address (email_address)) {
755 /* Warn the user via a dialog: */
756 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
758 /* Return focus to the email address entry: */
759 gtk_widget_grab_focus (self->entry_user_email);
764 /* TODO: The UI Spec wants us to check that the servernames are valid,
765 * but does not specify how.
773 on_response (GtkDialog *wizard_dialog,
777 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
778 enable_buttons (self);
780 gboolean prevent_response = FALSE;
782 /* Warn about unsaved changes: */
783 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
784 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
787 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
788 _("imum_nc_wizard_confirm_lose_changes") ));
790 const gint dialog_response = gtk_dialog_run (dialog);
791 gtk_widget_destroy (GTK_WIDGET (dialog));
793 if (dialog_response != GTK_RESPONSE_OK)
794 prevent_response = TRUE;
796 /* Check for invalid input: */
797 else if (!check_data (self)) {
798 prevent_response = TRUE;
801 if (prevent_response) {
802 /* This is a nasty hack. murrayc. */
803 /* Don't let the dialog close */
804 g_signal_stop_emission_by_name (wizard_dialog, "response");
809 if (response_id == GTK_RESPONSE_OK) {
810 /* Try to save the changes: */
811 const gboolean saved = save_configuration (self);
813 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
815 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
820 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
822 /* Create the notebook to be used by the GtkDialog base class:
823 * Each page of the notebook will be a page of the wizard: */
824 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
827 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
829 /* Get the account manager object,
830 * so we can check for existing accounts,
831 * and create new accounts: */
832 self->account_manager = modest_runtime_get_account_mgr ();
833 g_assert (self->account_manager);
834 g_object_ref (self->account_manager);
836 /* Create the common pages,
838 self->page_account_details = create_page_account_details (self);
839 self->page_user_details = create_page_user_details (self);
840 self->page_incoming = create_page_incoming (self);
841 self->page_outgoing = create_page_outgoing (self);
843 /* Add the notebook pages: */
844 gtk_notebook_append_page (notebook, self->page_account_details,
845 gtk_label_new (_("mcen_ti_account_settings_account")));
846 gtk_notebook_append_page (notebook, self->page_user_details,
847 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
848 gtk_notebook_append_page (notebook, self->page_incoming,
849 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
850 gtk_notebook_append_page (notebook, self->page_outgoing,
851 gtk_label_new (_("mcen_ti_advsetup_sending")));
853 GtkDialog *dialog = GTK_DIALOG (self);
854 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
855 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
856 gtk_widget_show (GTK_WIDGET (notebook));
858 /* Add the buttons: */
859 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
860 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
862 /* Connect to the dialog's response signal: */
863 /* We use connect-before
864 * so we can stop the signal emission,
865 * to stop the default signal handler from closing the dialog.
867 g_signal_connect (G_OBJECT (self), "response",
868 G_CALLBACK (on_response), self);
870 self->modified = FALSE;
873 ModestAccountSettingsDialog*
874 modest_account_settings_dialog_new (void)
876 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
879 /** Update the UI with the stored account details, so they can be edited.
880 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
882 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
887 /* Save the account name so we can refer to it later: */
888 if (dialog->account_name)
889 g_free (dialog->account_name);
890 dialog->account_name = g_strdup (account_name);
893 /* Get the account data for this account name: */
894 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
897 g_printerr ("modest: failed to get account data for %s\n", account_name);
901 /* Save the account title so we can refer to it if the user changes it: */
902 if (dialog->original_account_title)
903 g_free (dialog->original_account_title);
904 dialog->original_account_title = g_strdup (account_data->display_name);
907 if (!(account_data->store_account)) {
908 g_printerr ("modest: account has no stores: %s\n", account_name);
912 /* Show the account data in the widgets: */
914 /* Note that we never show the non-display name in the UI.
915 * (Though the display name defaults to the non-display name at the start.) */
916 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
917 account_data->display_name ? account_data->display_name : "");
919 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
920 account_data->fullname ? account_data->fullname : "");
921 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
922 account_data->email ? account_data->email : "");
924 ModestServerAccountData *incoming_account = account_data->store_account;
926 if (incoming_account)
927 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
928 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
929 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
931 /* Default to something, though no default is specified in the UI spec: */
932 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
934 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
937 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
938 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
939 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
942 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
943 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
944 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
946 /* Only show the leave-on-server checkbox for POP,
947 * as per the UI spec: */
948 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
949 gtk_widget_hide (dialog->checkbox_leave_messages);
951 gtk_widget_show (dialog->checkbox_leave_messages);
954 if (incoming_account) {
955 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
956 incoming_account->username ? incoming_account->username : "");
957 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
958 incoming_account->password ? incoming_account->password : "");
960 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
961 incoming_account->hostname ? incoming_account->hostname : "");
963 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
964 dialog->account_manager, incoming_account->account_name);
965 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
966 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
968 update_incoming_server_title (dialog, incoming_account->proto);
969 update_incoming_server_security_choices (dialog, incoming_account->proto);
971 const ModestProtocol security = modest_server_account_get_security (
972 dialog->account_manager, incoming_account->account_name);
973 modest_serversecurity_combo_box_set_active_serversecurity (
974 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
976 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
977 MODEST_ACCOUNT_PORT, TRUE /* server account */);
978 hildon_number_editor_set_value (
979 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
983 ModestServerAccountData *outgoing_account = account_data->transport_account;
984 if (outgoing_account) {
985 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
986 outgoing_account->hostname ? outgoing_account->hostname : "");
988 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
989 outgoing_account->username ? outgoing_account->username : "");
990 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
991 outgoing_account->password ? outgoing_account->password : "");
993 /* Get the secure-auth setting: */
994 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
995 dialog->account_manager, outgoing_account->account_name);
996 modest_secureauth_combo_box_set_active_secureauth (
997 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
998 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1000 modest_serversecurity_combo_box_fill (
1001 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1003 /* Get the security setting: */
1004 const ModestProtocol security = modest_server_account_get_security (
1005 dialog->account_manager, outgoing_account->account_name);
1006 modest_serversecurity_combo_box_set_active_serversecurity (
1007 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1009 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1010 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1011 hildon_number_editor_set_value (
1012 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1015 /* account_data->is_enabled, */
1016 /*account_data->is_default, */
1018 /* account_data->store_account->proto */
1020 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1022 /* Unset the modified flag so we can detect changes later: */
1023 dialog->modified = FALSE;
1027 save_configuration (ModestAccountSettingsDialog *dialog)
1029 g_assert (dialog->account_name);
1031 const gchar* account_name = dialog->account_name;
1033 /* Set the account data from the widgets: */
1034 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1035 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1036 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1040 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1041 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1042 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1047 if (dialog->signature_dialog) {
1048 gboolean use_signature = FALSE;
1049 gchar *signature = modest_signature_editor_dialog_get_settings (
1050 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1053 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1054 signature, use_signature);
1058 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1059 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1060 modest_account_mgr_set_string (dialog->account_manager, account_name,
1061 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1064 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1065 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1066 modest_account_mgr_set_int (dialog->account_manager, account_name,
1067 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1069 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1070 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1071 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1076 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1077 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1078 g_assert (incoming_account_name);
1080 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1081 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1082 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1086 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1087 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1088 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1092 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1093 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1094 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1098 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1099 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1100 ? MODEST_PROTOCOL_AUTH_PASSWORD
1101 : MODEST_PROTOCOL_AUTH_NONE;
1102 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1104 const ModestProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1105 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1106 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1109 gint port_num = hildon_number_editor_get_value (
1110 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1111 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1112 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1114 g_free (incoming_account_name);
1117 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1118 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1119 g_assert (outgoing_account_name);
1121 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1122 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1123 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1127 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1128 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1129 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1133 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1134 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1135 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1139 const ModestProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1140 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1141 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1143 const ModestProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1144 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1145 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1148 port_num = hildon_number_editor_get_value (
1149 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1150 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1151 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1153 g_free (outgoing_account_name);
1156 /* Set the changed account title last, to simplify the previous code: */
1157 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1158 if ((!account_title) || (strlen(account_title) == 0))
1159 return FALSE; /* Should be prevented already anyway. */
1161 if (strcmp(account_title, account_name) != 0) {
1162 /* Change the title: */
1163 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1164 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1169 /* Save connection-specific SMTP server accounts: */
1170 if (dialog->specific_window)
1171 return modest_connection_specific_smtp_window_save_server_accounts (
1172 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1177 static gboolean entry_is_empty (GtkWidget *entry)
1182 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1183 if ((!text) || (strlen(text) == 0))
1190 enable_buttons (ModestAccountSettingsDialog *self)
1192 gboolean enable_ok = TRUE;
1194 /* The account details title is mandatory: */
1195 if (entry_is_empty(self->entry_account_title))
1198 /* The user details username is mandatory: */
1199 if (entry_is_empty(self->entry_user_username))
1202 /* The user details email address is mandatory: */
1203 if (enable_ok && entry_is_empty (self->entry_user_email))
1206 /* The custom incoming server is mandatory: */
1207 if (entry_is_empty(self->entry_incomingserver))
1210 /* Enable the buttons,
1211 * identifying them via their associated response codes:
1213 GtkDialog *dialog_base = GTK_DIALOG (self);
1214 gtk_dialog_set_response_sensitive (dialog_base,
1220 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1222 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1223 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1226 object_class->get_property = modest_account_settings_dialog_get_property;
1227 object_class->set_property = modest_account_settings_dialog_set_property;
1228 object_class->dispose = modest_account_settings_dialog_dispose;
1229 object_class->finalize = modest_account_settings_dialog_finalize;
1233 show_error (GtkWindow *parent_window, const gchar* text)
1235 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1241 gtk_dialog_run (dialog);
1242 gtk_widget_destroy (GTK_WIDGET (dialog));
1246 show_ok (GtkWindow *parent_window, const gchar* text)
1248 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1254 gtk_dialog_run (dialog);
1255 gtk_widget_destroy (GTK_WIDGET (dialog));