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 "widgets/modest-easysetup-serversecurity-combo-box.h"
23 #include "widgets/modest-easysetup-secureauth-combo-box.h"
24 #include "widgets/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 if (self->specific_window)
101 gtk_widget_destroy (self->specific_window);
103 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
107 show_error (GtkWindow *parent_window, const gchar* text);
110 show_ok (GtkWindow *parent_window, const gchar* text);
113 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
116 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
119 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
121 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
122 self->modified = TRUE;
126 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
128 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
129 self->modified = TRUE;
133 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
135 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
136 self->modified = TRUE;
139 /* Set a modified boolean whenever the widget is changed,
140 * so we can check for it later.
143 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
145 if (GTK_IS_ENTRY (widget)) {
146 g_signal_connect (G_OBJECT (widget), "changed",
147 G_CALLBACK (on_modified_entry_changed), self);
148 } else if (GTK_IS_COMBO_BOX (widget)) {
149 g_signal_connect (G_OBJECT (widget), "changed",
150 G_CALLBACK (on_modified_combobox_changed), self);
151 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
152 g_signal_connect (G_OBJECT (widget), "toggled",
153 G_CALLBACK (on_modified_checkbox_toggled), self);
158 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
160 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
162 enable_buttons(self);
166 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
168 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
170 enable_buttons(self);
173 /** This is a convenience function to create a caption containing a mandatory widget.
174 * When the widget is edited, the enable_buttons() vfunc will be called.
176 static GtkWidget* create_caption_new_with_asterix(ModestAccountSettingsDialog *self,
181 HildonCaptionStatus flag)
183 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
185 /* The translated strings seem to already contain the *,
186 * but this code can be used if that is not true in future.
189 /* Add a * character to indicate mandatory fields,
190 * as specified in our "Email UI Specification": */
191 if (flag == HILDON_CAPTION_MANDATORY) {
192 gchar* title = g_strdup_printf("%s*", value);
193 caption = hildon_caption_new (group, title, control, icon, flag);
197 caption = hildon_caption_new (group, value, control, icon, flag);
200 /* Connect to the appropriate changed signal for the widget,
201 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
203 if (GTK_IS_ENTRY (control)) {
204 g_signal_connect (G_OBJECT (control), "changed",
205 G_CALLBACK (on_caption_entry_changed), self);
208 else if (GTK_IS_COMBO_BOX (control)) {
209 g_signal_connect (G_OBJECT (control), "changed",
210 G_CALLBACK (on_caption_combobox_changed), self);
217 create_page_account_details (ModestAccountSettingsDialog *self)
219 GtkWidget *box = gtk_vbox_new (FALSE, 2);
220 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
221 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
222 gtk_widget_show (label);
224 /* Create a size group to be used by all captions.
225 * Note that HildonCaption does not create a default size group if we do not specify one.
226 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
227 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
229 /* The description widgets: */
230 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
231 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
232 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
233 gtk_widget_show (self->entry_account_title);
234 connect_for_modified (self, self->entry_account_title);
235 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
236 gtk_widget_show (caption);
238 /* Prevent the use of some characters in the account title,
239 * as required by our UI specification: */
240 GList *list_prevent = NULL;
241 list_prevent = g_list_append (list_prevent, "\\");
242 list_prevent = g_list_append (list_prevent, "/");
243 list_prevent = g_list_append (list_prevent, ":");
244 list_prevent = g_list_append (list_prevent, "*");
245 list_prevent = g_list_append (list_prevent, "?");
246 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
247 list_prevent = g_list_append (list_prevent, "“");
248 list_prevent = g_list_append (list_prevent, "<");
249 list_prevent = g_list_append (list_prevent, ">");
250 list_prevent = g_list_append (list_prevent, "|");
251 list_prevent = g_list_append (list_prevent, "^");
252 easysetup_validating_entry_set_unallowed_characters (
253 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
254 g_list_free (list_prevent);
256 /* Set max length as in the UI spec:
257 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
258 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
260 /* The retrieve combobox: */
261 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
262 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
263 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
264 gtk_widget_show (self->combo_retrieve);
265 connect_for_modified (self, self->combo_retrieve);
266 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
267 gtk_widget_show (caption);
269 /* The limit-retrieve combobox: */
270 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
271 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
272 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
273 gtk_widget_show (self->combo_limit_retrieve);
274 connect_for_modified (self, self->combo_limit_retrieve);
275 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
276 gtk_widget_show (caption);
278 /* The leave-messages widgets: */
279 if(!self->checkbox_leave_messages)
280 self->checkbox_leave_messages =
281 gtk_check_button_new_with_label (_("mcen_fi_advsetup_leave_on_server"));
282 gtk_box_pack_start (GTK_BOX (box), self->checkbox_leave_messages, FALSE, FALSE, 2);
283 gtk_widget_show (self->checkbox_leave_messages);
284 connect_for_modified (self, self->checkbox_leave_messages);
286 gtk_widget_show (GTK_WIDGET (box));
288 return GTK_WIDGET (box);
292 on_button_signature (GtkButton *button, gpointer user_data)
298 create_page_user_details (ModestAccountSettingsDialog *self)
300 GtkWidget *box = gtk_vbox_new (FALSE, 2);
302 /* Create a size group to be used by all captions.
303 * Note that HildonCaption does not create a default size group if we do not specify one.
304 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
305 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
307 /* The name widgets: */
308 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
309 /* Set max length as in the UI spec:
310 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
311 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
312 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
313 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
314 gtk_widget_show (self->entry_user_name);
315 connect_for_modified (self, self->entry_user_name);
316 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
317 gtk_widget_show (caption);
319 /* Prevent the use of some characters in the name,
320 * as required by our UI specification: */
321 GList *list_prevent = NULL;
322 list_prevent = g_list_append (list_prevent, "<");
323 list_prevent = g_list_append (list_prevent, ">");
324 easysetup_validating_entry_set_unallowed_characters (
325 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
326 g_list_free (list_prevent);
328 /* The username widgets: */
329 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
330 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
331 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
332 gtk_widget_show (self->entry_user_username);
333 connect_for_modified (self, self->entry_user_username);
334 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
335 gtk_widget_show (caption);
337 /* Prevent the use of some characters in the username,
338 * as required by our UI specification: */
339 easysetup_validating_entry_set_unallowed_characters_whitespace (
340 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
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_username), 64);
346 /* The password widgets: */
347 self->entry_user_password = gtk_entry_new ();
348 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
349 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
350 caption = create_caption_new_with_asterix (self, sizegroup,
351 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
352 gtk_widget_show (self->entry_user_password);
353 connect_for_modified (self, self->entry_user_password);
354 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
355 gtk_widget_show (caption);
357 /* The email address widgets: */
358 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
359 caption = create_caption_new_with_asterix (self, sizegroup,
360 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
361 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
362 gtk_widget_show (self->entry_user_email);
363 connect_for_modified (self, self->entry_user_email);
364 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
365 gtk_widget_show (caption);
367 /* Set max length as in the UI spec:
368 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
369 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
372 /* Signature button: */
373 if (!self->button_signature)
374 self->button_signature = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
375 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
376 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
377 gtk_widget_show (self->button_signature);
378 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
379 gtk_widget_show (caption);
381 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
382 G_CALLBACK (on_button_signature), self);
384 gtk_widget_show (GTK_WIDGET (box));
386 return GTK_WIDGET (box);
389 /** Change the caption title for the incoming server,
390 * as specified in the UI spec:
392 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
395 (protocol == MODEST_PROTOCOL_STORE_POP ?
396 _("mail_fi_emailtype_pop3") :
397 _("mail_fi_emailtype_imap") );
400 /* Note that this produces a compiler warning,
401 * because the compiler does not know that the translated string will have a %s in it.
402 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
403 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
404 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
405 g_free(incomingserver_title);
408 /** Change the caption title for the incoming server,
409 * as specified in the UI spec:
411 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
413 /* Fill the combo with appropriately titled choices for POP or IMAP. */
414 /* The choices are the same, but the titles are different, as in the UI spec. */
415 easysetup_serversecurity_combo_box_fill (
416 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
419 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
421 GtkWidget *box = gtk_vbox_new (FALSE, 2);
423 /* Create a size group to be used by all captions.
424 * Note that HildonCaption does not create a default size group if we do not specify one.
425 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
426 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
428 /* The incoming server widgets: */
429 if(!self->entry_incomingserver)
430 self->entry_incomingserver = gtk_entry_new ();
432 if (self->caption_incoming)
433 gtk_widget_destroy (self->caption_incoming);
435 /* The caption title will be updated in update_incoming_server_title().
436 * so this default text will never be seen: */
437 /* (Note: Changing the title seems pointless. murrayc) */
438 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
439 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
440 gtk_widget_show (self->entry_incomingserver);
441 connect_for_modified (self, self->entry_incomingserver);
442 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
443 gtk_widget_show (self->caption_incoming);
445 /* The secure connection widgets: */
446 /* This will be filled by update_incoming_server_security_choices(). */
447 if (!self->combo_incoming_security)
448 self->combo_incoming_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
449 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
450 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
451 gtk_widget_show (self->combo_incoming_security);
452 connect_for_modified (self, self->combo_incoming_security);
453 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
454 gtk_widget_show (caption);
456 /* Show a default port number when the security method changes, as per the UI spec: */
457 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
460 /* The port widgets: */
461 /* TODO: There are various rules about this in the UI spec. */
462 if (!self->entry_incoming_port)
463 self->entry_incoming_port = GTK_WIDGET (gtk_entry_new ());
464 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
465 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
466 gtk_widget_show (self->entry_incoming_port);
467 connect_for_modified (self, self->entry_incoming_port);
468 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
469 gtk_widget_show (caption);
471 /* The secure authentication widgets: */
472 if(!self->checkbox_incoming_auth)
473 self->checkbox_incoming_auth =
474 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
475 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
476 gtk_widget_show (self->checkbox_incoming_auth);
477 connect_for_modified (self, self->checkbox_incoming_auth);
479 gtk_widget_show (GTK_WIDGET (box));
481 return GTK_WIDGET (box);
485 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
487 GtkWidget *widget = GTK_WIDGET (user_data);
489 /* Enable the widget only if the toggle button is active: */
490 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
491 gtk_widget_set_sensitive (widget, enable);
494 /* Make the sensitivity of a widget depend on a toggle button.
497 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
499 g_signal_connect (G_OBJECT (button), "toggled",
500 G_CALLBACK (on_toggle_button_changed), widget);
502 /* Set the starting sensitivity: */
503 on_toggle_button_changed (button, widget);
507 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
509 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
511 /* Create the window if necessary: */
512 if (!(self->specific_window)) {
513 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
514 modest_connection_specific_smtp_window_fill_with_connections (
515 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
519 /* Show the window: */
520 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
521 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
522 gtk_widget_show (self->specific_window);
526 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
528 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
530 ModestProtocol protocol_security =
531 easysetup_secureauth_combo_box_get_active_secureauth (
532 EASYSETUP_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
533 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
535 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
536 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
540 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
542 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
544 const gint port_number =
545 easysetup_serversecurity_combo_box_get_active_serversecurity_port (
546 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
548 if(port_number != 0) {
549 gchar* str = g_strdup_printf ("%d", port_number);
550 gtk_entry_set_text (GTK_ENTRY (self->entry_outgoing_port), str);
556 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
558 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
560 const gint port_number =
561 easysetup_serversecurity_combo_box_get_active_serversecurity_port (
562 EASYSETUP_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
564 if(port_number != 0) {
565 gchar* str = g_strdup_printf ("%d", port_number);
566 gtk_entry_set_text (GTK_ENTRY (self->entry_incoming_port), str);
572 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
574 GtkWidget *box = gtk_vbox_new (FALSE, 2);
576 /* Create a size group to be used by all captions.
577 * Note that HildonCaption does not create a default size group if we do not specify one.
578 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
579 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
581 /* The outgoing server widgets: */
582 if (!self->entry_outgoingserver)
583 self->entry_outgoingserver = gtk_entry_new ();
584 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
585 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
586 gtk_widget_show (self->entry_outgoingserver);
587 connect_for_modified (self, self->entry_outgoingserver);
588 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
589 gtk_widget_show (caption);
591 /* The secure authentication widgets: */
592 if (!self->combo_outgoing_auth)
593 self->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
594 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
595 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
596 gtk_widget_show (self->combo_outgoing_auth);
597 connect_for_modified (self, self->combo_outgoing_auth);
598 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
599 gtk_widget_show (caption);
601 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
602 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
604 /* The username widgets: */
605 self->entry_outgoing_username = GTK_WIDGET (easysetup_validating_entry_new ());
606 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
607 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
608 gtk_widget_show (self->entry_outgoing_username);
609 connect_for_modified (self, self->entry_outgoing_username);
610 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, 2);
611 gtk_widget_show (self->caption_outgoing_username);
613 /* Prevent the use of some characters in the username,
614 * as required by our UI specification: */
615 easysetup_validating_entry_set_unallowed_characters_whitespace (
616 EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
618 /* Set max length as in the UI spec:
619 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
620 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
622 /* The password widgets: */
623 self->entry_outgoing_password = gtk_entry_new ();
624 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
625 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
626 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
627 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
628 gtk_widget_show (self->entry_outgoing_password);
629 connect_for_modified (self, self->entry_outgoing_password);
630 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, 2);
631 gtk_widget_show (self->caption_outgoing_password);
633 /* The secure connection widgets: */
634 /* This will be filled and set with easysetup_serversecurity_combo_box_fill()
635 * and easysetup_serversecurity_combo_box_set_active_serversecurity().
637 if (!self->combo_outgoing_security)
638 self->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
639 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
640 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
641 gtk_widget_show (self->combo_outgoing_security);
642 connect_for_modified (self, self->combo_outgoing_security);
643 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
644 gtk_widget_show (caption);
646 /* Show a default port number when the security method changes, as per the UI spec: */
647 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
649 /* The port widgets: */
650 if (!self->entry_outgoing_port)
651 self->entry_outgoing_port = GTK_WIDGET (gtk_entry_new ());
652 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
653 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
654 gtk_widget_show (self->entry_outgoing_port);
655 connect_for_modified (self, self->entry_outgoing_port);
656 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
657 gtk_widget_show (caption);
659 /* connection-specific checkbox: */
660 if (!self->checkbox_outgoing_smtp_specific) {
661 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
662 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
665 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
666 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
667 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
669 /* Connection-specific SMTP-Severs Edit button: */
670 if (!self->button_outgoing_smtp_servers)
671 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
672 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
673 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
674 gtk_widget_show (self->button_outgoing_smtp_servers);
675 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
676 gtk_widget_show (caption);
678 /* Only enable the button when the checkbox is checked: */
679 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
680 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
682 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
683 G_CALLBACK (on_button_outgoing_smtp_servers), self);
686 gtk_widget_show (GTK_WIDGET (box));
688 return GTK_WIDGET (box);
692 check_data (ModestAccountSettingsDialog *self)
694 /* Check that the title is not already in use: */
695 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
696 if ((!account_title) || (strlen(account_title) == 0))
697 return FALSE; /* Should be prevented already anyway. */
699 if (strcmp(account_title, self->original_account_title) != 0) {
700 /* Check the changed title: */
701 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
705 /* Warn the user via a dialog: */
706 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
712 /* Check that the email address is valud: */
713 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
714 if ((!email_address) || (strlen(email_address) == 0))
717 if (!modest_text_utils_validate_email_address (email_address)) {
718 /* Warn the user via a dialog: */
719 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
721 /* Return focus to the email address entry: */
722 gtk_widget_grab_focus (self->entry_user_email);
727 /* TODO: The UI Spec wants us to check that the servernames are valid,
728 * but does not specify how.
736 on_response (GtkDialog *wizard_dialog,
740 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
741 enable_buttons (self);
743 gboolean prevent_response = FALSE;
745 /* Warn about unsaved changes: */
746 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
747 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
750 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
751 _("imum_nc_wizard_confirm_lose_changes") ));
753 const gint dialog_response = gtk_dialog_run (dialog);
754 gtk_widget_destroy (GTK_WIDGET (dialog));
756 if (dialog_response != GTK_RESPONSE_OK)
757 prevent_response = TRUE;
759 /* Check for invalid input: */
760 else if (!check_data (self)) {
761 prevent_response = TRUE;
764 if (prevent_response) {
765 /* This is a nasty hack. murrayc. */
766 /* Don't let the dialog close */
767 g_signal_stop_emission_by_name (wizard_dialog, "response");
772 if (response_id == GTK_RESPONSE_OK) {
773 /* Try to save the changes: */
774 const gboolean saved = save_configuration (self);
776 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
778 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
783 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
785 /* Create the notebook to be used by the GtkDialog base class:
786 * Each page of the notebook will be a page of the wizard: */
787 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
790 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
792 /* Get the account manager object,
793 * so we can check for existing accounts,
794 * and create new accounts: */
795 self->account_manager = modest_runtime_get_account_mgr ();
796 g_assert (self->account_manager);
797 g_object_ref (self->account_manager);
799 /* Create the common pages,
801 self->page_account_details = create_page_account_details (self);
802 self->page_user_details = create_page_user_details (self);
803 self->page_incoming = create_page_incoming (self);
804 self->page_outgoing = create_page_outgoing (self);
806 /* Add the notebook pages: */
807 gtk_notebook_append_page (notebook, self->page_account_details,
808 gtk_label_new (_("mcen_ti_account_settings_account")));
809 gtk_notebook_append_page (notebook, self->page_user_details,
810 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
811 gtk_notebook_append_page (notebook, self->page_incoming,
812 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
813 gtk_notebook_append_page (notebook, self->page_outgoing,
814 gtk_label_new (_("mcen_ti_advsetup_sending")));
816 GtkDialog *dialog = GTK_DIALOG (self);
817 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
818 gtk_widget_show (GTK_WIDGET (notebook));
820 /* Add the buttons: */
821 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
822 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
824 /* Connect to the dialog's response signal: */
825 /* We use connect-before
826 * so we can stop the signal emission,
827 * to stop the default signal handler from closing the dialog.
829 g_signal_connect (G_OBJECT (self), "response",
830 G_CALLBACK (on_response), self);
832 self->modified = FALSE;
835 ModestAccountSettingsDialog*
836 modest_account_settings_dialog_new (void)
838 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
841 /** Update the UI with the stored account details, so they can be edited.
842 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
844 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
849 /* Save the account name so we can refer to it later: */
850 if (dialog->account_name)
851 g_free (dialog->account_name);
852 dialog->account_name = g_strdup (account_name);
855 /* Get the account data for this account name: */
856 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
859 g_printerr ("modest: failed to get account data for %s\n", account_name);
863 /* Save the account title so we can refer to it if the user changes it: */
864 if (dialog->original_account_title)
865 g_free (dialog->original_account_title);
866 dialog->original_account_title = g_strdup (account_data->display_name);
869 if (!(account_data->store_account)) {
870 g_printerr ("modest: account has no stores: %s\n", account_name);
874 /* Show the account data in the widgets: */
876 /* Note that we never show the non-display name in the UI.
877 * (Though the display name defaults to the non-display name at the start.) */
878 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
879 account_data->display_name ? account_data->display_name : "");
881 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
882 account_data->fullname ? account_data->fullname : "");
883 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
884 account_data->email ? account_data->email : "");
886 ModestServerAccountData *incoming_account = account_data->store_account;
888 if (incoming_account)
889 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
890 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
891 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
893 /* Default to something, though no default is specified in the UI spec: */
894 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
896 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
899 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
900 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
901 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
904 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
905 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
906 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
908 /* Only show the leave-on-server checkbox for POP,
909 * as per the UI spec: */
910 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
911 gtk_widget_hide (dialog->checkbox_leave_messages);
913 gtk_widget_show (dialog->checkbox_leave_messages);
916 if (incoming_account) {
917 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
918 incoming_account->username ? incoming_account->username : "");
919 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
920 incoming_account->password ? incoming_account->password : "");
922 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
923 incoming_account->hostname ? incoming_account->hostname : "");
925 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
926 dialog->account_manager, incoming_account->account_name);
927 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
928 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
930 update_incoming_server_title (dialog, incoming_account->proto);
931 update_incoming_server_security_choices (dialog, incoming_account->proto);
933 const ModestProtocol security = modest_server_account_get_security (
934 dialog->account_manager, incoming_account->account_name);
935 easysetup_serversecurity_combo_box_set_active_serversecurity (
936 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
938 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
939 MODEST_ACCOUNT_PORT, TRUE /* server account */);
940 gchar *port_str = g_strdup_printf ("%d", port_num);
941 gtk_entry_set_text (GTK_ENTRY (dialog->entry_incoming_port), port_str);
946 ModestProtocol proto;
954 ModestServerAccountData *outgoing_account = account_data->transport_account;
955 if (outgoing_account) {
956 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
957 outgoing_account->hostname ? outgoing_account->hostname : "");
959 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
960 outgoing_account->username ? outgoing_account->username : "");
961 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
962 outgoing_account->password ? outgoing_account->password : "");
964 /* Get the secure-auth setting: */
965 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
966 dialog->account_manager, outgoing_account->account_name);
967 easysetup_secureauth_combo_box_set_active_secureauth (
968 EASYSETUP_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
969 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
971 easysetup_serversecurity_combo_box_fill (
972 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
974 /* Get the security setting: */
975 const ModestProtocol security = modest_server_account_get_security (
976 dialog->account_manager, outgoing_account->account_name);
977 easysetup_serversecurity_combo_box_set_active_serversecurity (
978 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
980 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
981 MODEST_ACCOUNT_PORT, TRUE /* server account */);
982 gchar *port_str = g_strdup_printf ("%d", port_num);
983 gtk_entry_set_text (GTK_ENTRY (dialog->entry_outgoing_port), port_str);
987 /* account_data->is_enabled, */
988 /*account_data->is_default, */
990 /* account_data->store_account->proto */
992 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
994 /* Unset the modified flag so we can detect changes later: */
995 dialog->modified = FALSE;
999 save_configuration (ModestAccountSettingsDialog *dialog)
1001 g_assert (dialog->account_name);
1003 const gchar* account_name = dialog->account_name;
1005 /* Set the account data from the widgets: */
1006 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1007 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1008 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1012 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1013 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1014 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1018 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1019 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1020 modest_account_mgr_set_string (dialog->account_manager, account_name,
1021 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1024 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1025 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1026 modest_account_mgr_set_int (dialog->account_manager, account_name,
1027 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1029 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1030 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1031 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1036 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1037 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1038 g_assert (incoming_account_name);
1040 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1041 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1042 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1046 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1047 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1048 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1052 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1053 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1054 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1058 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1059 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1060 ? MODEST_PROTOCOL_AUTH_PASSWORD
1061 : MODEST_PROTOCOL_AUTH_NONE;
1062 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1064 const ModestProtocol protocol_security_incoming = easysetup_serversecurity_combo_box_get_active_serversecurity (
1065 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1066 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1069 const gchar* port_str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incoming_port));
1072 port_num = atoi (port_str);
1073 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1074 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1076 g_free (incoming_account_name);
1079 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1080 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1081 g_assert (outgoing_account_name);
1083 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1084 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1085 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1089 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1090 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1091 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1095 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1096 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1097 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1101 const ModestProtocol protocol_security_outgoing = easysetup_serversecurity_combo_box_get_active_serversecurity (
1102 EASYSETUP_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1103 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1105 const ModestProtocol protocol_authentication_outgoing = easysetup_secureauth_combo_box_get_active_secureauth (
1106 EASYSETUP_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1107 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1110 port_str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_port));
1113 port_num = atoi (port_str);
1114 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1115 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1117 g_free (outgoing_account_name);
1120 /* Set the changed account title last, to simplify the previous code: */
1121 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1122 if ((!account_title) || (strlen(account_title) == 0))
1123 return FALSE; /* Should be prevented already anyway. */
1125 if (strcmp(account_title, account_name) != 0) {
1126 /* Change the title: */
1127 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1128 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1133 /* Save connection-specific SMTP server accounts: */
1134 if (dialog->specific_window)
1135 return modest_connection_specific_smtp_window_save_server_accounts (
1136 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1141 static gboolean entry_is_empty (GtkWidget *entry)
1146 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1147 if ((!text) || (strlen(text) == 0))
1154 enable_buttons (ModestAccountSettingsDialog *self)
1156 gboolean enable_ok = TRUE;
1158 /* The account details title is mandatory: */
1159 if (entry_is_empty(self->entry_account_title))
1162 /* The user details username is mandatory: */
1163 if (entry_is_empty(self->entry_user_username))
1166 /* The user details email address is mandatory: */
1167 if (enable_ok && entry_is_empty (self->entry_user_email))
1170 /* The custom incoming server is mandatory: */
1171 if (entry_is_empty(self->entry_incomingserver))
1174 /* Enable the buttons,
1175 * identifying them via their associated response codes:
1177 GtkDialog *dialog_base = GTK_DIALOG (self);
1178 gtk_dialog_set_response_sensitive (dialog_base,
1184 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1186 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1187 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1190 object_class->get_property = modest_account_settings_dialog_get_property;
1191 object_class->set_property = modest_account_settings_dialog_set_property;
1192 object_class->dispose = modest_account_settings_dialog_dispose;
1193 object_class->finalize = modest_account_settings_dialog_finalize;
1197 show_error (GtkWindow *parent_window, const gchar* text)
1199 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1205 gtk_dialog_run (dialog);
1206 gtk_widget_destroy (GTK_WIDGET (dialog));
1210 show_ok (GtkWindow *parent_window, const gchar* text)
1212 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1218 gtk_dialog_run (dialog);
1219 gtk_widget_destroy (GTK_WIDGET (dialog));