1 /* Copyright (c) 2007, Nokia Corporation
7 #include "modest-account-settings-dialog.h"
8 #include <glib/gi18n.h>
9 #include <gtk/gtknotebook.h>
10 #include <gtk/gtkvbox.h>
11 #include <gtk/gtklabel.h>
12 #include <gtk/gtkcombobox.h>
13 #include <gtk/gtkentry.h>
14 #include <gtk/gtkbutton.h>
15 #include <gtk/gtkcheckbutton.h>
16 #include <gtk/gtkmessagedialog.h>
17 #include <gtk/gtkstock.h>
18 #include <hildon-widgets/hildon-caption.h>
19 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
20 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
21 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
22 #include "maemo/easysetup/modest-easysetup-serversecurity-combo-box.h"
23 #include "maemo/easysetup/modest-easysetup-secureauth-combo-box.h"
24 #include "maemo/easysetup/modest-validating-entry.h"
25 #include "widgets/modest-retrieve-combo-box.h"
26 #include "widgets/modest-limit-retrieve-combo-box.h"
27 #include "modest-text-utils.h"
28 #include "modest-account-mgr.h"
29 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
30 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
31 #include "maemo/modest-connection-specific-smtp-window.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 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
104 show_error (GtkWindow *parent_window, const gchar* text);
107 show_ok (GtkWindow *parent_window, const gchar* text);
110 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
113 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
116 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
118 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
119 self->modified = TRUE;
123 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
125 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
126 self->modified = TRUE;
130 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
132 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
133 self->modified = TRUE;
136 /* Set a modified boolean whenever the widget is changed,
137 * so we can check for it later.
140 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
142 if (GTK_IS_ENTRY (widget)) {
143 g_signal_connect (G_OBJECT (widget), "changed",
144 G_CALLBACK (on_modified_entry_changed), self);
145 } else if (GTK_IS_COMBO_BOX (widget)) {
146 g_signal_connect (G_OBJECT (widget), "changed",
147 G_CALLBACK (on_modified_combobox_changed), self);
148 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
149 g_signal_connect (G_OBJECT (widget), "toggled",
150 G_CALLBACK (on_modified_checkbox_toggled), self);
155 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
157 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
159 enable_buttons(self);
163 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
165 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
167 enable_buttons(self);
170 /** This is a convenience function to create a caption containing a mandatory widget.
171 * When the widget is edited, the enable_buttons() vfunc will be called.
173 static GtkWidget* create_caption_new_with_asterix(ModestAccountSettingsDialog *self,
178 HildonCaptionStatus flag)
180 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
182 /* The translated strings seem to already contain the *,
183 * but this code can be used if that is not true in future.
186 /* Add a * character to indicate mandatory fields,
187 * as specified in our "Email UI Specification": */
188 if (flag == HILDON_CAPTION_MANDATORY) {
189 gchar* title = g_strdup_printf("%s*", value);
190 caption = hildon_caption_new (group, title, control, icon, flag);
194 caption = hildon_caption_new (group, value, control, icon, flag);
197 /* Connect to the appropriate changed signal for the widget,
198 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
200 if (GTK_IS_ENTRY (control)) {
201 g_signal_connect (G_OBJECT (control), "changed",
202 G_CALLBACK (on_caption_entry_changed), self);
205 else if (GTK_IS_COMBO_BOX (control)) {
206 g_signal_connect (G_OBJECT (control), "changed",
207 G_CALLBACK (on_caption_combobox_changed), self);
214 create_page_account_details (ModestAccountSettingsDialog *self)
216 GtkWidget *box = gtk_vbox_new (FALSE, 2);
217 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
218 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
219 gtk_widget_show (label);
221 /* Create a size group to be used by all captions.
222 * Note that HildonCaption does not create a default size group if we do not specify one.
223 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
224 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
226 /* The description widgets: */
227 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
228 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
229 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
230 gtk_widget_show (self->entry_account_title);
231 connect_for_modified (self, self->entry_account_title);
232 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
233 gtk_widget_show (caption);
235 /* Prevent the use of some characters in the account title,
236 * as required by our UI specification: */
237 GList *list_prevent = NULL;
238 list_prevent = g_list_append (list_prevent, "\\");
239 list_prevent = g_list_append (list_prevent, "/");
240 list_prevent = g_list_append (list_prevent, ":");
241 list_prevent = g_list_append (list_prevent, "*");
242 list_prevent = g_list_append (list_prevent, "?");
243 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
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 easysetup_validating_entry_set_unallowed_characters (
250 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
251 g_list_free (list_prevent);
253 /* Set max length as in the UI spec:
254 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
255 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
257 /* The retrieve combobox: */
258 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
259 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
260 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
261 gtk_widget_show (self->combo_retrieve);
262 connect_for_modified (self, self->combo_retrieve);
263 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
264 gtk_widget_show (caption);
266 /* The limit-retrieve combobox: */
267 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
268 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
269 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
270 gtk_widget_show (self->combo_limit_retrieve);
271 connect_for_modified (self, self->combo_limit_retrieve);
272 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
273 gtk_widget_show (caption);
275 /* The leave-messages widgets: */
276 if(!self->checkbox_leave_messages)
277 self->checkbox_leave_messages =
278 gtk_check_button_new_with_label (_("mcen_fi_advsetup_leave_on_server"));
279 gtk_box_pack_start (GTK_BOX (box), self->checkbox_leave_messages, FALSE, FALSE, 2);
280 gtk_widget_show (self->checkbox_leave_messages);
281 connect_for_modified (self, self->checkbox_leave_messages);
283 gtk_widget_show (GTK_WIDGET (box));
285 return GTK_WIDGET (box);
289 on_button_signature (GtkButton *button, gpointer user_data)
295 create_page_user_details (ModestAccountSettingsDialog *self)
297 GtkWidget *box = gtk_vbox_new (FALSE, 2);
299 /* Create a size group to be used by all captions.
300 * Note that HildonCaption does not create a default size group if we do not specify one.
301 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
302 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
304 /* The name widgets: */
305 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
306 /* Set max length as in the UI spec:
307 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
308 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
309 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
310 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
311 gtk_widget_show (self->entry_user_name);
312 connect_for_modified (self, self->entry_user_name);
313 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
314 gtk_widget_show (caption);
316 /* Prevent the use of some characters in the name,
317 * as required by our UI specification: */
318 GList *list_prevent = NULL;
319 list_prevent = g_list_append (list_prevent, "<");
320 list_prevent = g_list_append (list_prevent, ">");
321 easysetup_validating_entry_set_unallowed_characters (
322 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
323 g_list_free (list_prevent);
325 /* The username widgets: */
326 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
327 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
328 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
329 gtk_widget_show (self->entry_user_username);
330 connect_for_modified (self, self->entry_user_username);
331 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
332 gtk_widget_show (caption);
334 /* Prevent the use of some characters in the username,
335 * as required by our UI specification: */
336 easysetup_validating_entry_set_unallowed_characters_whitespace (
337 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
339 /* Set max length as in the UI spec:
340 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
341 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
343 /* The password widgets: */
344 self->entry_user_password = gtk_entry_new ();
345 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
346 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
347 caption = create_caption_new_with_asterix (self, sizegroup,
348 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
349 gtk_widget_show (self->entry_user_password);
350 connect_for_modified (self, self->entry_user_password);
351 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
352 gtk_widget_show (caption);
354 /* The email address widgets: */
355 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
356 caption = create_caption_new_with_asterix (self, sizegroup,
357 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
358 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
359 gtk_widget_show (self->entry_user_email);
360 connect_for_modified (self, self->entry_user_email);
361 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
362 gtk_widget_show (caption);
364 /* Set max length as in the UI spec:
365 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
366 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
369 /* Signature button: */
370 if (!self->button_signature)
371 self->button_signature = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
372 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
373 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
374 gtk_widget_show (self->button_signature);
375 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
376 gtk_widget_show (caption);
378 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
379 G_CALLBACK (on_button_signature), self);
381 gtk_widget_show (GTK_WIDGET (box));
383 return GTK_WIDGET (box);
386 /** Change the caption title for the incoming server,
387 * as specified in the UI spec:
389 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
392 (protocol == MODEST_PROTOCOL_STORE_POP ?
393 _("mail_fi_emailtype_pop3") :
394 _("mail_fi_emailtype_imap") );
397 /* Note that this produces a compiler warning,
398 * because the compiler does not know that the translated string will have a %s in it.
399 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
400 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
401 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
402 g_free(incomingserver_title);
405 /** Change the caption title for the incoming server,
406 * as specified in the UI spec:
408 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
410 /* Fill the combo with appropriately titled choices for POP or IMAP. */
411 /* The choices are the same, but the titles are different, as in the UI spec. */
412 easysetup_serversecurity_combo_box_fill (
413 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
416 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
418 GtkWidget *box = gtk_vbox_new (FALSE, 2);
420 /* Create a size group to be used by all captions.
421 * Note that HildonCaption does not create a default size group if we do not specify one.
422 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
423 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
425 /* The incoming server widgets: */
426 if(!self->entry_incomingserver)
427 self->entry_incomingserver = gtk_entry_new ();
429 if (self->caption_incoming)
430 gtk_widget_destroy (self->caption_incoming);
432 /* The caption title will be updated in update_incoming_server_title().
433 * so this default text will never be seen: */
434 /* (Note: Changing the title seems pointless. murrayc) */
435 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
436 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
437 gtk_widget_show (self->entry_incomingserver);
438 connect_for_modified (self, self->entry_incomingserver);
439 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
440 gtk_widget_show (self->caption_incoming);
442 /* The secure connection widgets: */
443 /* This will be filled by update_incoming_server_security_choices(). */
444 if (!self->combo_incoming_security)
445 self->combo_incoming_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
446 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
447 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
448 gtk_widget_show (self->combo_incoming_security);
449 connect_for_modified (self, self->combo_incoming_security);
450 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
451 gtk_widget_show (caption);
453 /* Show a default port number when the security method changes, as per the UI spec: */
454 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
457 /* The port widgets: */
458 /* TODO: There are various rules about this in the UI spec. */
459 if (!self->entry_incoming_port)
460 self->entry_incoming_port = GTK_WIDGET (gtk_entry_new ());
461 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
462 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
463 gtk_widget_show (self->entry_incoming_port);
464 connect_for_modified (self, self->entry_incoming_port);
465 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
466 gtk_widget_show (caption);
468 /* The secure authentication widgets: */
469 if(!self->checkbox_incoming_auth)
470 self->checkbox_incoming_auth =
471 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
472 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
473 gtk_widget_show (self->checkbox_incoming_auth);
474 connect_for_modified (self, self->checkbox_incoming_auth);
476 gtk_widget_show (GTK_WIDGET (box));
478 return GTK_WIDGET (box);
482 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
484 GtkWidget *widget = GTK_WIDGET (user_data);
486 /* Enable the widget only if the toggle button is active: */
487 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
488 gtk_widget_set_sensitive (widget, enable);
491 /* Make the sensitivity of a widget depend on a toggle button.
494 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
496 g_signal_connect (G_OBJECT (button), "toggled",
497 G_CALLBACK (on_toggle_button_changed), widget);
499 /* Set the starting sensitivity: */
500 on_toggle_button_changed (button, widget);
504 on_smtp_servers_window_hide (GtkWindow *window, gpointer user_data)
506 /* Destroy the window when it is closed: */
507 gtk_widget_destroy (GTK_WIDGET (window));
511 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
514 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
516 /* Show the window: */
517 /* TODO: Retrieve the chosen settings,
518 * so we can supply them when creating the connection somehow.
520 GtkWidget *window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
521 gtk_window_set_transient_for (GTK_WINDOW (self), GTK_WINDOW (window));
522 g_signal_connect (G_OBJECT (window), "hide",
523 G_CALLBACK (on_smtp_servers_window_hide), self);
524 gtk_widget_show (window);
528 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
530 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
532 ModestProtocol protocol_security =
533 easysetup_secureauth_combo_box_get_active_secureauth (
534 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
535 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
537 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
538 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
542 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
544 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
546 const gint port_number =
547 easysetup_serversecurity_combo_box_get_active_serversecurity_port (
548 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
550 if(port_number != 0) {
551 gchar* str = g_strdup_printf ("%d", port_number);
552 gtk_entry_set_text (GTK_ENTRY (self->entry_outgoing_port), str);
558 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
560 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
562 const gint port_number =
563 easysetup_serversecurity_combo_box_get_active_serversecurity_port (
564 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
566 if(port_number != 0) {
567 gchar* str = g_strdup_printf ("%d", port_number);
568 gtk_entry_set_text (GTK_ENTRY (self->entry_incoming_port), str);
574 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
576 GtkWidget *box = gtk_vbox_new (FALSE, 2);
578 /* Create a size group to be used by all captions.
579 * Note that HildonCaption does not create a default size group if we do not specify one.
580 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
581 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
583 /* The outgoing server widgets: */
584 if (!self->entry_outgoingserver)
585 self->entry_outgoingserver = gtk_entry_new ();
586 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
587 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
588 gtk_widget_show (self->entry_outgoingserver);
589 connect_for_modified (self, self->entry_outgoingserver);
590 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
591 gtk_widget_show (caption);
593 /* The secure authentication widgets: */
594 if (!self->combo_outgoing_auth)
595 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
596 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
597 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
598 gtk_widget_show (self->combo_outgoing_auth);
599 connect_for_modified (self, self->combo_outgoing_auth);
600 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
601 gtk_widget_show (caption);
603 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
604 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
606 /* The username widgets: */
607 self->entry_outgoing_username = GTK_WIDGET (easysetup_validating_entry_new ());
608 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
609 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
610 gtk_widget_show (self->entry_outgoing_username);
611 connect_for_modified (self, self->entry_outgoing_username);
612 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, 2);
613 gtk_widget_show (self->caption_outgoing_username);
615 /* Prevent the use of some characters in the username,
616 * as required by our UI specification: */
617 easysetup_validating_entry_set_unallowed_characters_whitespace (
618 EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
620 /* Set max length as in the UI spec:
621 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
622 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
624 /* The password widgets: */
625 self->entry_outgoing_password = gtk_entry_new ();
626 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
627 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
628 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
629 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
630 gtk_widget_show (self->entry_outgoing_password);
631 connect_for_modified (self, self->entry_outgoing_password);
632 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, 2);
633 gtk_widget_show (self->caption_outgoing_password);
635 /* The secure connection widgets: */
636 /* This will be filled and set with easysetup_serversecurity_combo_box_fill()
637 * and easysetup_serversecurity_combo_box_set_active_serversecurity().
639 if (!self->combo_outgoing_security)
640 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
641 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
642 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
643 gtk_widget_show (self->combo_outgoing_security);
644 connect_for_modified (self, self->combo_outgoing_security);
645 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
646 gtk_widget_show (caption);
648 /* Show a default port number when the security method changes, as per the UI spec: */
649 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
651 /* The port widgets: */
652 if (!self->entry_outgoing_port)
653 self->entry_outgoing_port = GTK_WIDGET (gtk_entry_new ());
654 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
655 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
656 gtk_widget_show (self->entry_outgoing_port);
657 connect_for_modified (self, self->entry_outgoing_port);
658 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
659 gtk_widget_show (caption);
661 /* connection-specific checkbox: */
662 if (!self->checkbox_outgoing_smtp_specific) {
663 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
664 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
667 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
668 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
669 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
671 /* Connection-specific SMTP-Severs Edit button: */
672 if (!self->button_outgoing_smtp_servers)
673 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
674 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
675 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
676 gtk_widget_show (self->button_outgoing_smtp_servers);
677 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
678 gtk_widget_show (caption);
680 /* Only enable the button when the checkbox is checked: */
681 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
682 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
684 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
685 G_CALLBACK (on_button_outgoing_smtp_servers), self);
688 gtk_widget_show (GTK_WIDGET (box));
690 return GTK_WIDGET (box);
694 check_data (ModestAccountSettingsDialog *self)
696 /* Check that the title is not already in use: */
697 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
698 if ((!account_title) || (strlen(account_title) == 0))
699 return FALSE; /* Should be prevented already anyway. */
701 if (strcmp(account_title, self->original_account_title) != 0) {
702 /* Check the changed title: */
703 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
707 /* Warn the user via a dialog: */
708 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
714 /* Check that the email address is valud: */
715 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
716 if ((!email_address) || (strlen(email_address) == 0))
719 if (!modest_text_utils_validate_email_address (email_address)) {
720 /* Warn the user via a dialog: */
721 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
723 /* Return focus to the email address entry: */
724 gtk_widget_grab_focus (self->entry_user_email);
729 /* TODO: The UI Spec wants us to check that the servernames are valid,
730 * but does not specify how.
738 on_response (GtkDialog *wizard_dialog,
742 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
743 enable_buttons (self);
745 gboolean prevent_response = FALSE;
747 /* Warn about unsaved changes: */
748 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
749 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
752 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
753 _("imum_nc_wizard_confirm_lose_changes") ));
755 const gint dialog_response = gtk_dialog_run (dialog);
756 gtk_widget_destroy (GTK_WIDGET (dialog));
758 if (dialog_response != GTK_RESPONSE_OK)
759 prevent_response = TRUE;
761 /* Check for invalid input: */
762 else if (!check_data (self)) {
763 prevent_response = TRUE;
766 if (prevent_response) {
767 /* This is a nasty hack. murrayc. */
768 /* Don't let the dialog close */
769 g_signal_stop_emission_by_name (wizard_dialog, "response");
774 if (response_id == GTK_RESPONSE_OK) {
775 /* Try to save the changes: */
776 const gboolean saved = save_configuration (self);
778 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
780 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
785 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
787 /* Create the notebook to be used by the GtkDialog base class:
788 * Each page of the notebook will be a page of the wizard: */
789 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
792 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
794 /* Get the account manager object,
795 * so we can check for existing accounts,
796 * and create new accounts: */
797 self->account_manager = modest_runtime_get_account_mgr ();
798 g_assert (self->account_manager);
799 g_object_ref (self->account_manager);
801 /* Create the common pages,
803 self->page_account_details = create_page_account_details (self);
804 self->page_user_details = create_page_user_details (self);
805 self->page_incoming = create_page_incoming (self);
806 self->page_outgoing = create_page_outgoing (self);
808 /* Add the notebook pages: */
809 gtk_notebook_append_page (notebook, self->page_account_details,
810 gtk_label_new (_("mcen_ti_account_settings_account")));
811 gtk_notebook_append_page (notebook, self->page_user_details,
812 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
813 gtk_notebook_append_page (notebook, self->page_incoming,
814 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
815 gtk_notebook_append_page (notebook, self->page_outgoing,
816 gtk_label_new (_("mcen_ti_advsetup_sending")));
818 GtkDialog *dialog = GTK_DIALOG (self);
819 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
820 gtk_widget_show (GTK_WIDGET (notebook));
822 /* Add the buttons: */
823 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
824 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
826 /* Connect to the dialog's response signal: */
827 /* We use connect-before
828 * so we can stop the signal emission,
829 * to stop the default signal handler from closing the dialog.
831 g_signal_connect (G_OBJECT (self), "response",
832 G_CALLBACK (on_response), self);
834 self->modified = FALSE;
837 ModestAccountSettingsDialog*
838 modest_account_settings_dialog_new (void)
840 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
843 /** Update the UI with the stored account details, so they can be edited.
844 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
846 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
851 /* Save the account name so we can refer to it later: */
852 if (dialog->account_name)
853 g_free (dialog->account_name);
854 dialog->account_name = g_strdup (account_name);
857 /* Get the account data for this account name: */
858 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
861 g_printerr ("modest: failed to get account data for %s\n", account_name);
865 /* Save the account title so we can refer to it if the user changes it: */
866 if (dialog->original_account_title)
867 g_free (dialog->original_account_title);
868 dialog->original_account_title = g_strdup (account_data->display_name);
871 if (!(account_data->store_account)) {
872 g_printerr ("modest: account has no stores: %s\n", account_name);
876 /* Show the account data in the widgets: */
878 /* Note that we never show the non-display name in the UI.
879 * (Though the display name defaults to the non-display name at the start.) */
880 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
881 account_data->display_name ? account_data->display_name : "");
883 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
884 account_data->fullname ? account_data->fullname : "");
885 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
886 account_data->email ? account_data->email : "");
888 ModestServerAccountData *incoming_account = account_data->store_account;
890 if (incoming_account)
891 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
892 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
893 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
895 /* Default to something, though no default is specified in the UI spec: */
896 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
898 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
901 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
902 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
903 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
906 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
907 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
908 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
910 /* Only show the leave-on-server checkbox for POP,
911 * as per the UI spec: */
912 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
913 gtk_widget_hide (dialog->checkbox_leave_messages);
915 gtk_widget_show (dialog->checkbox_leave_messages);
918 if (incoming_account) {
919 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
920 incoming_account->username ? incoming_account->username : "");
921 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
922 incoming_account->password ? incoming_account->password : "");
924 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
925 incoming_account->hostname ? incoming_account->hostname : "");
927 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
928 dialog->account_manager, incoming_account->account_name);
929 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
930 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
932 update_incoming_server_title (dialog, incoming_account->proto);
933 update_incoming_server_security_choices (dialog, incoming_account->proto);
935 const ModestProtocol security = modest_server_account_get_security (
936 dialog->account_manager, incoming_account->account_name);
937 easysetup_serversecurity_combo_box_set_active_serversecurity (
938 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
940 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
941 MODEST_ACCOUNT_PORT, TRUE /* server account */);
942 gchar *port_str = g_strdup_printf ("%d", port_num);
943 gtk_entry_set_text (GTK_ENTRY (dialog->entry_incoming_port), port_str);
948 ModestProtocol proto;
956 ModestServerAccountData *outgoing_account = account_data->transport_account;
957 if (outgoing_account) {
958 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
959 outgoing_account->hostname ? outgoing_account->hostname : "");
961 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
962 outgoing_account->username ? outgoing_account->username : "");
963 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
964 outgoing_account->password ? outgoing_account->password : "");
966 /* Get the secure-auth setting: */
967 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
968 dialog->account_manager, outgoing_account->account_name);
969 easysetup_secureauth_combo_box_set_active_secureauth (
970 EASYSETUP_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
971 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
973 easysetup_serversecurity_combo_box_fill (
974 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
976 /* Get the security setting: */
977 const ModestProtocol security = modest_server_account_get_security (
978 dialog->account_manager, outgoing_account->account_name);
979 easysetup_serversecurity_combo_box_set_active_serversecurity (
980 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
982 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
983 MODEST_ACCOUNT_PORT, TRUE /* server account */);
984 gchar *port_str = g_strdup_printf ("%d", port_num);
985 gtk_entry_set_text (GTK_ENTRY (dialog->entry_outgoing_port), port_str);
989 /* account_data->is_enabled, */
990 /*account_data->is_default, */
992 /* account_data->store_account->proto */
994 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
996 /* Unset the modified flag so we can detect changes later: */
997 dialog->modified = FALSE;
1001 save_configuration (ModestAccountSettingsDialog *dialog)
1003 g_assert (dialog->account_name);
1005 const gchar* account_name = dialog->account_name;
1007 /* Set the account data from the widgets: */
1008 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1009 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1010 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1014 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1015 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1016 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1020 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1021 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1022 modest_account_mgr_set_string (dialog->account_manager, account_name,
1023 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1026 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1027 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1028 modest_account_mgr_set_int (dialog->account_manager, account_name,
1029 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1031 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1032 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1033 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1038 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1039 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1040 g_assert (incoming_account_name);
1042 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1043 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1044 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1048 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1049 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1050 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1054 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1055 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1056 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1060 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1061 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1062 ? MODEST_PROTOCOL_AUTH_PASSWORD
1063 : MODEST_PROTOCOL_AUTH_NONE;
1064 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1066 const ModestProtocol protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
1067 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1068 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1071 const gchar* port_str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incoming_port));
1074 port_num = atoi (port_str);
1075 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1076 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1078 g_free (incoming_account_name);
1081 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1082 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1083 g_assert (outgoing_account_name);
1085 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1086 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1087 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1091 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1092 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1093 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1097 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1098 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1099 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1103 const ModestProtocol protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
1104 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1105 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1107 const ModestProtocol protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
1108 EASYSETUP_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1109 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1112 port_str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_port));
1115 port_num = atoi (port_str);
1116 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1117 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1119 g_free (outgoing_account_name);
1122 /* Set the changed account title last, to simplify the previous code: */
1123 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1124 if ((!account_title) || (strlen(account_title) == 0))
1125 return FALSE; /* Should be prevented already anyway. */
1127 if (strcmp(account_title, account_name) != 0) {
1128 /* Change the title: */
1129 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1130 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1138 static gboolean entry_is_empty (GtkWidget *entry)
1143 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1144 if ((!text) || (strlen(text) == 0))
1151 enable_buttons (ModestAccountSettingsDialog *self)
1153 gboolean enable_ok = TRUE;
1155 /* The account details title is mandatory: */
1156 if (entry_is_empty(self->entry_account_title))
1159 /* The user details username is mandatory: */
1160 if (entry_is_empty(self->entry_user_username))
1163 /* The user details email address is mandatory: */
1164 if (enable_ok && entry_is_empty (self->entry_user_email))
1167 /* The custom incoming server is mandatory: */
1168 if (entry_is_empty(self->entry_incomingserver))
1171 /* Enable the buttons,
1172 * identifying them via their associated response codes:
1174 GtkDialog *dialog_base = GTK_DIALOG (self);
1175 gtk_dialog_set_response_sensitive (dialog_base,
1181 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1183 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1184 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1187 object_class->get_property = modest_account_settings_dialog_get_property;
1188 object_class->set_property = modest_account_settings_dialog_set_property;
1189 object_class->dispose = modest_account_settings_dialog_dispose;
1190 object_class->finalize = modest_account_settings_dialog_finalize;
1194 show_error (GtkWindow *parent_window, const gchar* text)
1196 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1202 gtk_dialog_run (dialog);
1203 gtk_widget_destroy (GTK_WIDGET (dialog));
1207 show_ok (GtkWindow *parent_window, const gchar* text)
1209 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1215 gtk_dialog_run (dialog);
1216 gtk_widget_destroy (GTK_WIDGET (dialog));