1 /* Copyright (c) 2007, Nokia Corporation
7 #include "modest-account-settings-dialog.h"
8 #include <glib/gi18n.h>
9 #include <gtk/gtknotebook.h>
10 #include <gtk/gtkvbox.h>
11 #include <gtk/gtklabel.h>
12 #include <gtk/gtkcombobox.h>
13 #include <gtk/gtkentry.h>
14 #include <gtk/gtkbutton.h>
15 #include <gtk/gtkcheckbutton.h>
16 #include <gtk/gtkmessagedialog.h>
17 #include <gtk/gtkstock.h>
18 #include <hildon-widgets/hildon-caption.h>
19 #include <hildon-widgets/hildon-number-editor.h>
20 #include "widgets/modest-serversecurity-combo-box.h"
21 #include "widgets/modest-secureauth-combo-box.h"
22 #include "widgets/modest-validating-entry.h"
23 #include "widgets/modest-retrieve-combo-box.h"
24 #include "widgets/modest-limit-retrieve-combo-box.h"
25 #include "modest-text-utils.h"
26 #include "modest-account-mgr.h"
27 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
28 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
29 #include "maemo/modest-connection-specific-smtp-window.h"
30 #include <gconf/gconf-client.h>
31 #include <string.h> /* For strlen(). */
33 /* Include config.h so that _() works: */
38 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
40 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
42 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
43 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
45 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
47 struct _ModestAccountSettingsDialogPrivate
52 enable_buttons (ModestAccountSettingsDialog *self);
55 save_configuration (ModestAccountSettingsDialog *dialog);
58 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
59 GValue *value, GParamSpec *pspec)
61 switch (property_id) {
63 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
68 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
69 const GValue *value, GParamSpec *pspec)
71 switch (property_id) {
73 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
78 modest_account_settings_dialog_dispose (GObject *object)
80 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
81 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
85 modest_account_settings_dialog_finalize (GObject *object)
87 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
89 if (self->account_name)
90 g_free (self->account_name);
92 if (self->original_account_title)
93 g_free (self->original_account_title);
95 if (self->account_manager)
96 g_object_unref (G_OBJECT (self->account_manager));
98 if (self->specific_window)
99 gtk_widget_destroy (self->specific_window);
101 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
105 show_error (GtkWindow *parent_window, const gchar* text);
108 show_ok (GtkWindow *parent_window, const gchar* text);
111 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
114 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
117 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
119 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
120 self->modified = TRUE;
124 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
126 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
127 self->modified = TRUE;
131 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
133 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
134 self->modified = TRUE;
137 /* Set a modified boolean whenever the widget is changed,
138 * so we can check for it later.
141 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
143 if (GTK_IS_ENTRY (widget)) {
144 g_signal_connect (G_OBJECT (widget), "changed",
145 G_CALLBACK (on_modified_entry_changed), self);
146 } else if (GTK_IS_COMBO_BOX (widget)) {
147 g_signal_connect (G_OBJECT (widget), "changed",
148 G_CALLBACK (on_modified_combobox_changed), self);
149 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
150 g_signal_connect (G_OBJECT (widget), "toggled",
151 G_CALLBACK (on_modified_checkbox_toggled), self);
156 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
158 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
160 enable_buttons(self);
164 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
166 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
168 enable_buttons(self);
171 /** This is a convenience function to create a caption containing a mandatory widget.
172 * When the widget is edited, the enable_buttons() vfunc will be called.
174 static GtkWidget* create_caption_new_with_asterix(ModestAccountSettingsDialog *self,
179 HildonCaptionStatus flag)
181 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
183 /* The translated strings seem to already contain the *,
184 * but this code can be used if that is not true in future.
187 /* Add a * character to indicate mandatory fields,
188 * as specified in our "Email UI Specification": */
189 if (flag == HILDON_CAPTION_MANDATORY) {
190 gchar* title = g_strdup_printf("%s*", value);
191 caption = hildon_caption_new (group, title, control, icon, flag);
195 caption = hildon_caption_new (group, value, control, icon, flag);
198 /* Connect to the appropriate changed signal for the widget,
199 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
201 if (GTK_IS_ENTRY (control)) {
202 g_signal_connect (G_OBJECT (control), "changed",
203 G_CALLBACK (on_caption_entry_changed), self);
206 else if (GTK_IS_COMBO_BOX (control)) {
207 g_signal_connect (G_OBJECT (control), "changed",
208 G_CALLBACK (on_caption_combobox_changed), self);
215 create_page_account_details (ModestAccountSettingsDialog *self)
217 GtkWidget *box = gtk_vbox_new (FALSE, 2);
218 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
219 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 2);
220 gtk_widget_show (label);
222 /* Create a size group to be used by all captions.
223 * Note that HildonCaption does not create a default size group if we do not specify one.
224 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
225 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
227 /* The description widgets: */
228 self->entry_account_title = GTK_WIDGET (easysetup_validating_entry_new ());
229 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
230 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
231 gtk_widget_show (self->entry_account_title);
232 connect_for_modified (self, self->entry_account_title);
233 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
234 gtk_widget_show (caption);
236 /* Prevent the use of some characters in the account title,
237 * as required by our UI specification: */
238 GList *list_prevent = NULL;
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, "?");
244 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
245 list_prevent = g_list_append (list_prevent, "“");
246 list_prevent = g_list_append (list_prevent, "<");
247 list_prevent = g_list_append (list_prevent, ">");
248 list_prevent = g_list_append (list_prevent, "|");
249 list_prevent = g_list_append (list_prevent, "^");
250 easysetup_validating_entry_set_unallowed_characters (
251 EASYSETUP_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
252 g_list_free (list_prevent);
254 /* Set max length as in the UI spec:
255 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
256 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
258 /* The retrieve combobox: */
259 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
260 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
261 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
262 gtk_widget_show (self->combo_retrieve);
263 connect_for_modified (self, self->combo_retrieve);
264 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
265 gtk_widget_show (caption);
267 /* The limit-retrieve combobox: */
268 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
269 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
270 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
271 gtk_widget_show (self->combo_limit_retrieve);
272 connect_for_modified (self, self->combo_limit_retrieve);
273 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
274 gtk_widget_show (caption);
276 /* The leave-messages widgets: */
277 if(!self->checkbox_leave_messages)
278 self->checkbox_leave_messages =
279 gtk_check_button_new_with_label (_("mcen_fi_advsetup_leave_on_server"));
280 gtk_box_pack_start (GTK_BOX (box), self->checkbox_leave_messages, FALSE, FALSE, 2);
281 gtk_widget_show (self->checkbox_leave_messages);
282 connect_for_modified (self, self->checkbox_leave_messages);
284 gtk_widget_show (GTK_WIDGET (box));
286 return GTK_WIDGET (box);
290 on_button_signature (GtkButton *button, gpointer user_data)
296 create_page_user_details (ModestAccountSettingsDialog *self)
298 GtkWidget *box = gtk_vbox_new (FALSE, 2);
300 /* Create a size group to be used by all captions.
301 * Note that HildonCaption does not create a default size group if we do not specify one.
302 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
303 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
305 /* The name widgets: */
306 self->entry_user_name = GTK_WIDGET (easysetup_validating_entry_new ());
307 /* Set max length as in the UI spec:
308 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
309 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
310 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
311 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
312 gtk_widget_show (self->entry_user_name);
313 connect_for_modified (self, self->entry_user_name);
314 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
315 gtk_widget_show (caption);
317 /* Prevent the use of some characters in the name,
318 * as required by our UI specification: */
319 GList *list_prevent = NULL;
320 list_prevent = g_list_append (list_prevent, "<");
321 list_prevent = g_list_append (list_prevent, ">");
322 easysetup_validating_entry_set_unallowed_characters (
323 EASYSETUP_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
324 g_list_free (list_prevent);
326 /* The username widgets: */
327 self->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
328 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
329 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
330 gtk_widget_show (self->entry_user_username);
331 connect_for_modified (self, self->entry_user_username);
332 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
333 gtk_widget_show (caption);
335 /* Prevent the use of some characters in the username,
336 * as required by our UI specification: */
337 easysetup_validating_entry_set_unallowed_characters_whitespace (
338 EASYSETUP_VALIDATING_ENTRY (self->entry_user_username));
340 /* Set max length as in the UI spec:
341 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
342 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
344 /* The password widgets: */
345 self->entry_user_password = gtk_entry_new ();
346 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
347 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
348 caption = create_caption_new_with_asterix (self, sizegroup,
349 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
350 gtk_widget_show (self->entry_user_password);
351 connect_for_modified (self, self->entry_user_password);
352 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
353 gtk_widget_show (caption);
355 /* The email address widgets: */
356 self->entry_user_email = GTK_WIDGET (easysetup_validating_entry_new ());
357 caption = create_caption_new_with_asterix (self, sizegroup,
358 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
359 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
360 gtk_widget_show (self->entry_user_email);
361 connect_for_modified (self, self->entry_user_email);
362 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
363 gtk_widget_show (caption);
365 /* Set max length as in the UI spec:
366 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
367 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
370 /* Signature button: */
371 if (!self->button_signature)
372 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
373 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
374 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
375 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
376 gtk_widget_show (self->button_signature);
377 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
378 gtk_widget_show (caption);
380 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
381 G_CALLBACK (on_button_signature), self);
383 gtk_widget_show (GTK_WIDGET (box));
385 return GTK_WIDGET (box);
388 /** Change the caption title for the incoming server,
389 * as specified in the UI spec:
391 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
394 (protocol == MODEST_PROTOCOL_STORE_POP ?
395 _("mail_fi_emailtype_pop3") :
396 _("mail_fi_emailtype_imap") );
399 /* Note that this produces a compiler warning,
400 * because the compiler does not know that the translated string will have a %s in it.
401 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
402 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
403 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
404 g_free(incomingserver_title);
407 /** Change the caption title for the incoming server,
408 * as specified in the UI spec:
410 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
412 /* Fill the combo with appropriately titled choices for POP or IMAP. */
413 /* The choices are the same, but the titles are different, as in the UI spec. */
414 modest_serversecurity_combo_box_fill (
415 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
418 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
420 GtkWidget *box = gtk_vbox_new (FALSE, 2);
422 /* Create a size group to be used by all captions.
423 * Note that HildonCaption does not create a default size group if we do not specify one.
424 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
425 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
427 /* The incoming server widgets: */
428 if(!self->entry_incomingserver)
429 self->entry_incomingserver = gtk_entry_new ();
431 if (self->caption_incoming)
432 gtk_widget_destroy (self->caption_incoming);
434 /* The caption title will be updated in update_incoming_server_title().
435 * so this default text will never be seen: */
436 /* (Note: Changing the title seems pointless. murrayc) */
437 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
438 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
439 gtk_widget_show (self->entry_incomingserver);
440 connect_for_modified (self, self->entry_incomingserver);
441 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
442 gtk_widget_show (self->caption_incoming);
444 /* The secure connection widgets: */
445 /* This will be filled by update_incoming_server_security_choices(). */
446 if (!self->combo_incoming_security)
447 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
448 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
449 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
450 gtk_widget_show (self->combo_incoming_security);
451 connect_for_modified (self, self->combo_incoming_security);
452 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
453 gtk_widget_show (caption);
455 /* Show a default port number when the security method changes, as per the UI spec: */
456 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
459 /* The port widgets: */
460 /* TODO: There are various rules about this in the UI spec. */
461 if (!self->entry_incoming_port)
462 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
463 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
464 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
465 gtk_widget_show (self->entry_incoming_port);
466 connect_for_modified (self, self->entry_incoming_port);
467 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
468 gtk_widget_show (caption);
470 /* The secure authentication widgets: */
471 if(!self->checkbox_incoming_auth)
472 self->checkbox_incoming_auth =
473 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
474 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
475 gtk_widget_show (self->checkbox_incoming_auth);
476 connect_for_modified (self, self->checkbox_incoming_auth);
478 gtk_widget_show (GTK_WIDGET (box));
480 return GTK_WIDGET (box);
484 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
486 GtkWidget *widget = GTK_WIDGET (user_data);
488 /* Enable the widget only if the toggle button is active: */
489 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
490 gtk_widget_set_sensitive (widget, enable);
493 /* Make the sensitivity of a widget depend on a toggle button.
496 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
498 g_signal_connect (G_OBJECT (button), "toggled",
499 G_CALLBACK (on_toggle_button_changed), widget);
501 /* Set the starting sensitivity: */
502 on_toggle_button_changed (button, widget);
506 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
508 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
510 /* Create the window if necessary: */
511 if (!(self->specific_window)) {
512 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
513 modest_connection_specific_smtp_window_fill_with_connections (
514 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
518 /* Show the window: */
519 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
520 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
521 gtk_widget_show (self->specific_window);
525 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
527 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
529 ModestProtocol protocol_security =
530 modest_secureauth_combo_box_get_active_secureauth (
531 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
532 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
534 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
535 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
539 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
541 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
543 const gint port_number =
544 modest_serversecurity_combo_box_get_active_serversecurity_port (
545 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
547 if(port_number != 0) {
548 hildon_number_editor_set_value (
549 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
554 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
556 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
558 const gint port_number =
559 modest_serversecurity_combo_box_get_active_serversecurity_port (
560 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
562 if(port_number != 0) {
563 hildon_number_editor_set_value (
564 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
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 (hildon_number_editor_new (0, 65535));
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 GtkWidget *separator = gtk_hseparator_new ();
657 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 2);
658 gtk_widget_show (separator);
660 /* connection-specific checkbox: */
661 if (!self->checkbox_outgoing_smtp_specific) {
662 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
663 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
666 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
667 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
668 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
670 /* Connection-specific SMTP-Severs Edit button: */
671 if (!self->button_outgoing_smtp_servers)
672 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
673 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
674 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
675 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
676 gtk_widget_show (self->button_outgoing_smtp_servers);
677 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
678 gtk_widget_show (caption);
680 /* Only enable the button when the checkbox is checked: */
681 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
682 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
684 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
685 G_CALLBACK (on_button_outgoing_smtp_servers), self);
688 gtk_widget_show (GTK_WIDGET (box));
690 return GTK_WIDGET (box);
694 check_data (ModestAccountSettingsDialog *self)
696 /* Check that the title is not already in use: */
697 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
698 if ((!account_title) || (strlen(account_title) == 0))
699 return FALSE; /* Should be prevented already anyway. */
701 if (strcmp(account_title, self->original_account_title) != 0) {
702 /* Check the changed title: */
703 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
707 /* Warn the user via a dialog: */
708 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
714 /* Check that the email address is valud: */
715 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
716 if ((!email_address) || (strlen(email_address) == 0))
719 if (!modest_text_utils_validate_email_address (email_address)) {
720 /* Warn the user via a dialog: */
721 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
723 /* Return focus to the email address entry: */
724 gtk_widget_grab_focus (self->entry_user_email);
729 /* TODO: The UI Spec wants us to check that the servernames are valid,
730 * but does not specify how.
738 on_response (GtkDialog *wizard_dialog,
742 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
743 enable_buttons (self);
745 gboolean prevent_response = FALSE;
747 /* Warn about unsaved changes: */
748 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
749 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
752 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
753 _("imum_nc_wizard_confirm_lose_changes") ));
755 const gint dialog_response = gtk_dialog_run (dialog);
756 gtk_widget_destroy (GTK_WIDGET (dialog));
758 if (dialog_response != GTK_RESPONSE_OK)
759 prevent_response = TRUE;
761 /* Check for invalid input: */
762 else if (!check_data (self)) {
763 prevent_response = TRUE;
766 if (prevent_response) {
767 /* This is a nasty hack. murrayc. */
768 /* Don't let the dialog close */
769 g_signal_stop_emission_by_name (wizard_dialog, "response");
774 if (response_id == GTK_RESPONSE_OK) {
775 /* Try to save the changes: */
776 const gboolean saved = save_configuration (self);
778 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
780 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
785 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
787 /* Create the notebook to be used by the GtkDialog base class:
788 * Each page of the notebook will be a page of the wizard: */
789 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
792 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
794 /* Get the account manager object,
795 * so we can check for existing accounts,
796 * and create new accounts: */
797 self->account_manager = modest_runtime_get_account_mgr ();
798 g_assert (self->account_manager);
799 g_object_ref (self->account_manager);
801 /* Create the common pages,
803 self->page_account_details = create_page_account_details (self);
804 self->page_user_details = create_page_user_details (self);
805 self->page_incoming = create_page_incoming (self);
806 self->page_outgoing = create_page_outgoing (self);
808 /* Add the notebook pages: */
809 gtk_notebook_append_page (notebook, self->page_account_details,
810 gtk_label_new (_("mcen_ti_account_settings_account")));
811 gtk_notebook_append_page (notebook, self->page_user_details,
812 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
813 gtk_notebook_append_page (notebook, self->page_incoming,
814 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
815 gtk_notebook_append_page (notebook, self->page_outgoing,
816 gtk_label_new (_("mcen_ti_advsetup_sending")));
818 GtkDialog *dialog = GTK_DIALOG (self);
819 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
820 gtk_widget_show (GTK_WIDGET (notebook));
822 /* Add the buttons: */
823 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
824 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
826 /* Connect to the dialog's response signal: */
827 /* We use connect-before
828 * so we can stop the signal emission,
829 * to stop the default signal handler from closing the dialog.
831 g_signal_connect (G_OBJECT (self), "response",
832 G_CALLBACK (on_response), self);
834 self->modified = FALSE;
837 ModestAccountSettingsDialog*
838 modest_account_settings_dialog_new (void)
840 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
843 /** Update the UI with the stored account details, so they can be edited.
844 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
846 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
851 /* Save the account name so we can refer to it later: */
852 if (dialog->account_name)
853 g_free (dialog->account_name);
854 dialog->account_name = g_strdup (account_name);
857 /* Get the account data for this account name: */
858 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
861 g_printerr ("modest: failed to get account data for %s\n", account_name);
865 /* Save the account title so we can refer to it if the user changes it: */
866 if (dialog->original_account_title)
867 g_free (dialog->original_account_title);
868 dialog->original_account_title = g_strdup (account_data->display_name);
871 if (!(account_data->store_account)) {
872 g_printerr ("modest: account has no stores: %s\n", account_name);
876 /* Show the account data in the widgets: */
878 /* Note that we never show the non-display name in the UI.
879 * (Though the display name defaults to the non-display name at the start.) */
880 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
881 account_data->display_name ? account_data->display_name : "");
883 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
884 account_data->fullname ? account_data->fullname : "");
885 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
886 account_data->email ? account_data->email : "");
888 ModestServerAccountData *incoming_account = account_data->store_account;
890 if (incoming_account)
891 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
892 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
893 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
895 /* Default to something, though no default is specified in the UI spec: */
896 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
898 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
901 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
902 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
903 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
906 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
907 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
908 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
910 /* Only show the leave-on-server checkbox for POP,
911 * as per the UI spec: */
912 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
913 gtk_widget_hide (dialog->checkbox_leave_messages);
915 gtk_widget_show (dialog->checkbox_leave_messages);
918 if (incoming_account) {
919 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
920 incoming_account->username ? incoming_account->username : "");
921 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
922 incoming_account->password ? incoming_account->password : "");
924 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
925 incoming_account->hostname ? incoming_account->hostname : "");
927 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
928 dialog->account_manager, incoming_account->account_name);
929 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
930 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
932 update_incoming_server_title (dialog, incoming_account->proto);
933 update_incoming_server_security_choices (dialog, incoming_account->proto);
935 const ModestProtocol security = modest_server_account_get_security (
936 dialog->account_manager, incoming_account->account_name);
937 modest_serversecurity_combo_box_set_active_serversecurity (
938 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
940 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
941 MODEST_ACCOUNT_PORT, TRUE /* server account */);
942 hildon_number_editor_set_value (
943 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
947 ModestServerAccountData *outgoing_account = account_data->transport_account;
948 if (outgoing_account) {
949 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
950 outgoing_account->hostname ? outgoing_account->hostname : "");
952 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
953 outgoing_account->username ? outgoing_account->username : "");
954 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
955 outgoing_account->password ? outgoing_account->password : "");
957 /* Get the secure-auth setting: */
958 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
959 dialog->account_manager, outgoing_account->account_name);
960 modest_secureauth_combo_box_set_active_secureauth (
961 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
962 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
964 modest_serversecurity_combo_box_fill (
965 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
967 /* Get the security setting: */
968 const ModestProtocol security = modest_server_account_get_security (
969 dialog->account_manager, outgoing_account->account_name);
970 modest_serversecurity_combo_box_set_active_serversecurity (
971 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
973 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
974 MODEST_ACCOUNT_PORT, TRUE /* server account */);
975 hildon_number_editor_set_value (
976 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
979 /* account_data->is_enabled, */
980 /*account_data->is_default, */
982 /* account_data->store_account->proto */
984 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
986 /* Unset the modified flag so we can detect changes later: */
987 dialog->modified = FALSE;
991 save_configuration (ModestAccountSettingsDialog *dialog)
993 g_assert (dialog->account_name);
995 const gchar* account_name = dialog->account_name;
997 /* Set the account data from the widgets: */
998 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
999 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1000 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1004 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1005 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1006 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1010 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1011 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1012 modest_account_mgr_set_string (dialog->account_manager, account_name,
1013 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1016 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1017 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1018 modest_account_mgr_set_int (dialog->account_manager, account_name,
1019 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1021 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1022 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1023 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1028 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1029 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1030 g_assert (incoming_account_name);
1032 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1033 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1034 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1038 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1039 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1040 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1044 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1045 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1046 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1050 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1051 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1052 ? MODEST_PROTOCOL_AUTH_PASSWORD
1053 : MODEST_PROTOCOL_AUTH_NONE;
1054 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1056 const ModestProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1057 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1058 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1061 gint port_num = hildon_number_editor_get_value (
1062 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1063 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1064 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1066 g_free (incoming_account_name);
1069 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1070 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1071 g_assert (outgoing_account_name);
1073 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1074 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1075 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1079 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1080 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1081 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1085 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1086 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1087 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1091 const ModestProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1092 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1093 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1095 const ModestProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1096 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1097 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1100 port_num = hildon_number_editor_get_value (
1101 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1102 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1103 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1105 g_free (outgoing_account_name);
1108 /* Set the changed account title last, to simplify the previous code: */
1109 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1110 if ((!account_title) || (strlen(account_title) == 0))
1111 return FALSE; /* Should be prevented already anyway. */
1113 if (strcmp(account_title, account_name) != 0) {
1114 /* Change the title: */
1115 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1116 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1121 /* Save connection-specific SMTP server accounts: */
1122 if (dialog->specific_window)
1123 return modest_connection_specific_smtp_window_save_server_accounts (
1124 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1129 static gboolean entry_is_empty (GtkWidget *entry)
1134 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1135 if ((!text) || (strlen(text) == 0))
1142 enable_buttons (ModestAccountSettingsDialog *self)
1144 gboolean enable_ok = TRUE;
1146 /* The account details title is mandatory: */
1147 if (entry_is_empty(self->entry_account_title))
1150 /* The user details username is mandatory: */
1151 if (entry_is_empty(self->entry_user_username))
1154 /* The user details email address is mandatory: */
1155 if (enable_ok && entry_is_empty (self->entry_user_email))
1158 /* The custom incoming server is mandatory: */
1159 if (entry_is_empty(self->entry_incomingserver))
1162 /* Enable the buttons,
1163 * identifying them via their associated response codes:
1165 GtkDialog *dialog_base = GTK_DIALOG (self);
1166 gtk_dialog_set_response_sensitive (dialog_base,
1172 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1174 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1175 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1178 object_class->get_property = modest_account_settings_dialog_get_property;
1179 object_class->set_property = modest_account_settings_dialog_set_property;
1180 object_class->dispose = modest_account_settings_dialog_dispose;
1181 object_class->finalize = modest_account_settings_dialog_finalize;
1185 show_error (GtkWindow *parent_window, const gchar* text)
1187 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1193 gtk_dialog_run (dialog);
1194 gtk_widget_destroy (GTK_WIDGET (dialog));
1198 show_ok (GtkWindow *parent_window, const gchar* text)
1200 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1206 gtk_dialog_run (dialog);
1207 gtk_widget_destroy (GTK_WIDGET (dialog));