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 "widgets/modest-serversecurity-combo-box.h"
20 #include "widgets/modest-secureauth-combo-box.h"
21 #include "widgets/modest-validating-entry.h"
22 #include "widgets/modest-retrieve-combo-box.h"
23 #include "widgets/modest-limit-retrieve-combo-box.h"
24 #include "modest-text-utils.h"
25 #include "modest-account-mgr.h"
26 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
27 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
28 #include "maemo/modest-connection-specific-smtp-window.h"
29 #include <gconf/gconf-client.h>
30 #include <string.h> /* For strlen(). */
32 /* Include config.h so that _() works: */
37 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
39 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
41 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
42 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
44 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
46 struct _ModestAccountSettingsDialogPrivate
51 enable_buttons (ModestAccountSettingsDialog *self);
54 save_configuration (ModestAccountSettingsDialog *dialog);
57 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
58 GValue *value, GParamSpec *pspec)
60 switch (property_id) {
62 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
67 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
68 const GValue *value, GParamSpec *pspec)
70 switch (property_id) {
72 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
77 modest_account_settings_dialog_dispose (GObject *object)
79 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
80 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
84 modest_account_settings_dialog_finalize (GObject *object)
86 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
88 if (self->account_name)
89 g_free (self->account_name);
91 if (self->original_account_title)
92 g_free (self->original_account_title);
94 if (self->account_manager)
95 g_object_unref (G_OBJECT (self->account_manager));
97 if (self->specific_window)
98 gtk_widget_destroy (self->specific_window);
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 modest_serversecurity_combo_box_fill (
413 MODEST_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 (modest_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_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
506 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
508 /* Create the window if necessary: */
509 if (!(self->specific_window)) {
510 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
511 modest_connection_specific_smtp_window_fill_with_connections (
512 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
516 /* Show the window: */
517 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
518 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
519 gtk_widget_show (self->specific_window);
523 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
525 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
527 ModestProtocol protocol_security =
528 modest_secureauth_combo_box_get_active_secureauth (
529 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
530 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
532 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
533 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
537 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
539 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
541 const gint port_number =
542 modest_serversecurity_combo_box_get_active_serversecurity_port (
543 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
545 if(port_number != 0) {
546 gchar* str = g_strdup_printf ("%d", port_number);
547 gtk_entry_set_text (GTK_ENTRY (self->entry_outgoing_port), str);
553 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
555 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
557 const gint port_number =
558 modest_serversecurity_combo_box_get_active_serversecurity_port (
559 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
561 if(port_number != 0) {
562 gchar* str = g_strdup_printf ("%d", port_number);
563 gtk_entry_set_text (GTK_ENTRY (self->entry_incoming_port), str);
569 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
571 GtkWidget *box = gtk_vbox_new (FALSE, 2);
573 /* Create a size group to be used by all captions.
574 * Note that HildonCaption does not create a default size group if we do not specify one.
575 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
576 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
578 /* The outgoing server widgets: */
579 if (!self->entry_outgoingserver)
580 self->entry_outgoingserver = gtk_entry_new ();
581 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
582 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
583 gtk_widget_show (self->entry_outgoingserver);
584 connect_for_modified (self, self->entry_outgoingserver);
585 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
586 gtk_widget_show (caption);
588 /* The secure authentication widgets: */
589 if (!self->combo_outgoing_auth)
590 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
591 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
592 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
593 gtk_widget_show (self->combo_outgoing_auth);
594 connect_for_modified (self, self->combo_outgoing_auth);
595 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
596 gtk_widget_show (caption);
598 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
599 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
601 /* The username widgets: */
602 self->entry_outgoing_username = GTK_WIDGET (easysetup_validating_entry_new ());
603 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
604 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
605 gtk_widget_show (self->entry_outgoing_username);
606 connect_for_modified (self, self->entry_outgoing_username);
607 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, 2);
608 gtk_widget_show (self->caption_outgoing_username);
610 /* Prevent the use of some characters in the username,
611 * as required by our UI specification: */
612 easysetup_validating_entry_set_unallowed_characters_whitespace (
613 EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
615 /* Set max length as in the UI spec:
616 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
617 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
619 /* The password widgets: */
620 self->entry_outgoing_password = gtk_entry_new ();
621 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
622 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
623 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
624 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
625 gtk_widget_show (self->entry_outgoing_password);
626 connect_for_modified (self, self->entry_outgoing_password);
627 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, 2);
628 gtk_widget_show (self->caption_outgoing_password);
630 /* The secure connection widgets: */
631 /* This will be filled and set with modest_serversecurity_combo_box_fill()
632 * and modest_serversecurity_combo_box_set_active_serversecurity().
634 if (!self->combo_outgoing_security)
635 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
636 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
637 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
638 gtk_widget_show (self->combo_outgoing_security);
639 connect_for_modified (self, self->combo_outgoing_security);
640 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
641 gtk_widget_show (caption);
643 /* Show a default port number when the security method changes, as per the UI spec: */
644 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
646 /* The port widgets: */
647 if (!self->entry_outgoing_port)
648 self->entry_outgoing_port = GTK_WIDGET (gtk_entry_new ());
649 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
650 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
651 gtk_widget_show (self->entry_outgoing_port);
652 connect_for_modified (self, self->entry_outgoing_port);
653 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
654 gtk_widget_show (caption);
656 /* connection-specific checkbox: */
657 if (!self->checkbox_outgoing_smtp_specific) {
658 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
659 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
662 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
663 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
664 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
666 /* Connection-specific SMTP-Severs Edit button: */
667 if (!self->button_outgoing_smtp_servers)
668 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_emailsetup_edit"));
669 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
670 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
671 gtk_widget_show (self->button_outgoing_smtp_servers);
672 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
673 gtk_widget_show (caption);
675 /* Only enable the button when the checkbox is checked: */
676 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
677 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
679 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
680 G_CALLBACK (on_button_outgoing_smtp_servers), self);
683 gtk_widget_show (GTK_WIDGET (box));
685 return GTK_WIDGET (box);
689 check_data (ModestAccountSettingsDialog *self)
691 /* Check that the title is not already in use: */
692 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
693 if ((!account_title) || (strlen(account_title) == 0))
694 return FALSE; /* Should be prevented already anyway. */
696 if (strcmp(account_title, self->original_account_title) != 0) {
697 /* Check the changed title: */
698 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
702 /* Warn the user via a dialog: */
703 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
709 /* Check that the email address is valud: */
710 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
711 if ((!email_address) || (strlen(email_address) == 0))
714 if (!modest_text_utils_validate_email_address (email_address)) {
715 /* Warn the user via a dialog: */
716 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
718 /* Return focus to the email address entry: */
719 gtk_widget_grab_focus (self->entry_user_email);
724 /* TODO: The UI Spec wants us to check that the servernames are valid,
725 * but does not specify how.
733 on_response (GtkDialog *wizard_dialog,
737 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
738 enable_buttons (self);
740 gboolean prevent_response = FALSE;
742 /* Warn about unsaved changes: */
743 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
744 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
747 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
748 _("imum_nc_wizard_confirm_lose_changes") ));
750 const gint dialog_response = gtk_dialog_run (dialog);
751 gtk_widget_destroy (GTK_WIDGET (dialog));
753 if (dialog_response != GTK_RESPONSE_OK)
754 prevent_response = TRUE;
756 /* Check for invalid input: */
757 else if (!check_data (self)) {
758 prevent_response = TRUE;
761 if (prevent_response) {
762 /* This is a nasty hack. murrayc. */
763 /* Don't let the dialog close */
764 g_signal_stop_emission_by_name (wizard_dialog, "response");
769 if (response_id == GTK_RESPONSE_OK) {
770 /* Try to save the changes: */
771 const gboolean saved = save_configuration (self);
773 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
775 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
780 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
782 /* Create the notebook to be used by the GtkDialog base class:
783 * Each page of the notebook will be a page of the wizard: */
784 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
787 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
789 /* Get the account manager object,
790 * so we can check for existing accounts,
791 * and create new accounts: */
792 self->account_manager = modest_runtime_get_account_mgr ();
793 g_assert (self->account_manager);
794 g_object_ref (self->account_manager);
796 /* Create the common pages,
798 self->page_account_details = create_page_account_details (self);
799 self->page_user_details = create_page_user_details (self);
800 self->page_incoming = create_page_incoming (self);
801 self->page_outgoing = create_page_outgoing (self);
803 /* Add the notebook pages: */
804 gtk_notebook_append_page (notebook, self->page_account_details,
805 gtk_label_new (_("mcen_ti_account_settings_account")));
806 gtk_notebook_append_page (notebook, self->page_user_details,
807 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
808 gtk_notebook_append_page (notebook, self->page_incoming,
809 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
810 gtk_notebook_append_page (notebook, self->page_outgoing,
811 gtk_label_new (_("mcen_ti_advsetup_sending")));
813 GtkDialog *dialog = GTK_DIALOG (self);
814 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
815 gtk_widget_show (GTK_WIDGET (notebook));
817 /* Add the buttons: */
818 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
819 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
821 /* Connect to the dialog's response signal: */
822 /* We use connect-before
823 * so we can stop the signal emission,
824 * to stop the default signal handler from closing the dialog.
826 g_signal_connect (G_OBJECT (self), "response",
827 G_CALLBACK (on_response), self);
829 self->modified = FALSE;
832 ModestAccountSettingsDialog*
833 modest_account_settings_dialog_new (void)
835 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
838 /** Update the UI with the stored account details, so they can be edited.
839 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
841 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
846 /* Save the account name so we can refer to it later: */
847 if (dialog->account_name)
848 g_free (dialog->account_name);
849 dialog->account_name = g_strdup (account_name);
852 /* Get the account data for this account name: */
853 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
856 g_printerr ("modest: failed to get account data for %s\n", account_name);
860 /* Save the account title so we can refer to it if the user changes it: */
861 if (dialog->original_account_title)
862 g_free (dialog->original_account_title);
863 dialog->original_account_title = g_strdup (account_data->display_name);
866 if (!(account_data->store_account)) {
867 g_printerr ("modest: account has no stores: %s\n", account_name);
871 /* Show the account data in the widgets: */
873 /* Note that we never show the non-display name in the UI.
874 * (Though the display name defaults to the non-display name at the start.) */
875 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
876 account_data->display_name ? account_data->display_name : "");
878 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
879 account_data->fullname ? account_data->fullname : "");
880 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
881 account_data->email ? account_data->email : "");
883 ModestServerAccountData *incoming_account = account_data->store_account;
885 if (incoming_account)
886 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
887 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
888 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
890 /* Default to something, though no default is specified in the UI spec: */
891 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
893 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
896 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
897 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
898 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
901 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
902 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
903 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
905 /* Only show the leave-on-server checkbox for POP,
906 * as per the UI spec: */
907 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
908 gtk_widget_hide (dialog->checkbox_leave_messages);
910 gtk_widget_show (dialog->checkbox_leave_messages);
913 if (incoming_account) {
914 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
915 incoming_account->username ? incoming_account->username : "");
916 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
917 incoming_account->password ? incoming_account->password : "");
919 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
920 incoming_account->hostname ? incoming_account->hostname : "");
922 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
923 dialog->account_manager, incoming_account->account_name);
924 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
925 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
927 update_incoming_server_title (dialog, incoming_account->proto);
928 update_incoming_server_security_choices (dialog, incoming_account->proto);
930 const ModestProtocol security = modest_server_account_get_security (
931 dialog->account_manager, incoming_account->account_name);
932 modest_serversecurity_combo_box_set_active_serversecurity (
933 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
935 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
936 MODEST_ACCOUNT_PORT, TRUE /* server account */);
937 gchar *port_str = g_strdup_printf ("%d", port_num);
938 gtk_entry_set_text (GTK_ENTRY (dialog->entry_incoming_port), port_str);
943 ModestProtocol proto;
951 ModestServerAccountData *outgoing_account = account_data->transport_account;
952 if (outgoing_account) {
953 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
954 outgoing_account->hostname ? outgoing_account->hostname : "");
956 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
957 outgoing_account->username ? outgoing_account->username : "");
958 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
959 outgoing_account->password ? outgoing_account->password : "");
961 /* Get the secure-auth setting: */
962 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
963 dialog->account_manager, outgoing_account->account_name);
964 modest_secureauth_combo_box_set_active_secureauth (
965 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
966 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
968 modest_serversecurity_combo_box_fill (
969 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
971 /* Get the security setting: */
972 const ModestProtocol security = modest_server_account_get_security (
973 dialog->account_manager, outgoing_account->account_name);
974 modest_serversecurity_combo_box_set_active_serversecurity (
975 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
977 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
978 MODEST_ACCOUNT_PORT, TRUE /* server account */);
979 gchar *port_str = g_strdup_printf ("%d", port_num);
980 gtk_entry_set_text (GTK_ENTRY (dialog->entry_outgoing_port), port_str);
984 /* account_data->is_enabled, */
985 /*account_data->is_default, */
987 /* account_data->store_account->proto */
989 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
991 /* Unset the modified flag so we can detect changes later: */
992 dialog->modified = FALSE;
996 save_configuration (ModestAccountSettingsDialog *dialog)
998 g_assert (dialog->account_name);
1000 const gchar* account_name = dialog->account_name;
1002 /* Set the account data from the widgets: */
1003 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1004 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1005 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1009 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1010 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1011 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1015 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1016 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1017 modest_account_mgr_set_string (dialog->account_manager, account_name,
1018 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1021 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1022 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1023 modest_account_mgr_set_int (dialog->account_manager, account_name,
1024 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1026 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1027 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1028 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1033 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1034 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1035 g_assert (incoming_account_name);
1037 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1038 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1039 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1043 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1044 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1045 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1049 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1050 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1051 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1055 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1056 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1057 ? MODEST_PROTOCOL_AUTH_PASSWORD
1058 : MODEST_PROTOCOL_AUTH_NONE;
1059 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1061 const ModestProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1062 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1063 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1066 const gchar* port_str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incoming_port));
1069 port_num = atoi (port_str);
1070 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1071 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1073 g_free (incoming_account_name);
1076 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1077 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1078 g_assert (outgoing_account_name);
1080 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1081 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1082 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1086 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1087 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1088 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1092 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1093 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1094 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1098 const ModestProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1099 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1100 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1102 const ModestProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1103 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1104 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1107 port_str = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_port));
1110 port_num = atoi (port_str);
1111 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1112 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1114 g_free (outgoing_account_name);
1117 /* Set the changed account title last, to simplify the previous code: */
1118 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1119 if ((!account_title) || (strlen(account_title) == 0))
1120 return FALSE; /* Should be prevented already anyway. */
1122 if (strcmp(account_title, account_name) != 0) {
1123 /* Change the title: */
1124 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1125 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1130 /* Save connection-specific SMTP server accounts: */
1131 if (dialog->specific_window)
1132 return modest_connection_specific_smtp_window_save_server_accounts (
1133 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
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));