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 gtk_widget_show (self->button_signature);
376 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
377 gtk_widget_show (caption);
379 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
380 G_CALLBACK (on_button_signature), self);
382 gtk_widget_show (GTK_WIDGET (box));
384 return GTK_WIDGET (box);
387 /** Change the caption title for the incoming server,
388 * as specified in the UI spec:
390 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
393 (protocol == MODEST_PROTOCOL_STORE_POP ?
394 _("mail_fi_emailtype_pop3") :
395 _("mail_fi_emailtype_imap") );
398 /* Note that this produces a compiler warning,
399 * because the compiler does not know that the translated string will have a %s in it.
400 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
401 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
402 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
403 g_free(incomingserver_title);
406 /** Change the caption title for the incoming server,
407 * as specified in the UI spec:
409 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
411 /* Fill the combo with appropriately titled choices for POP or IMAP. */
412 /* The choices are the same, but the titles are different, as in the UI spec. */
413 modest_serversecurity_combo_box_fill (
414 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
417 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
419 GtkWidget *box = gtk_vbox_new (FALSE, 2);
421 /* Create a size group to be used by all captions.
422 * Note that HildonCaption does not create a default size group if we do not specify one.
423 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
424 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
426 /* The incoming server widgets: */
427 if(!self->entry_incomingserver)
428 self->entry_incomingserver = gtk_entry_new ();
430 if (self->caption_incoming)
431 gtk_widget_destroy (self->caption_incoming);
433 /* The caption title will be updated in update_incoming_server_title().
434 * so this default text will never be seen: */
435 /* (Note: Changing the title seems pointless. murrayc) */
436 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
437 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
438 gtk_widget_show (self->entry_incomingserver);
439 connect_for_modified (self, self->entry_incomingserver);
440 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, 2);
441 gtk_widget_show (self->caption_incoming);
443 /* The secure connection widgets: */
444 /* This will be filled by update_incoming_server_security_choices(). */
445 if (!self->combo_incoming_security)
446 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
447 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
448 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
449 gtk_widget_show (self->combo_incoming_security);
450 connect_for_modified (self, self->combo_incoming_security);
451 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
452 gtk_widget_show (caption);
454 /* Show a default port number when the security method changes, as per the UI spec: */
455 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
458 /* The port widgets: */
459 /* TODO: There are various rules about this in the UI spec. */
460 if (!self->entry_incoming_port)
461 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 10000 /* arbitrary min and max */));
462 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
463 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
464 gtk_widget_show (self->entry_incoming_port);
465 connect_for_modified (self, self->entry_incoming_port);
466 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
467 gtk_widget_show (caption);
469 /* The secure authentication widgets: */
470 if(!self->checkbox_incoming_auth)
471 self->checkbox_incoming_auth =
472 gtk_check_button_new_with_label (_("mcen_li_emailsetup_secure_authentication"));
473 gtk_box_pack_start (GTK_BOX (box), self->checkbox_incoming_auth, FALSE, FALSE, 2);
474 gtk_widget_show (self->checkbox_incoming_auth);
475 connect_for_modified (self, self->checkbox_incoming_auth);
477 gtk_widget_show (GTK_WIDGET (box));
479 return GTK_WIDGET (box);
483 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
485 GtkWidget *widget = GTK_WIDGET (user_data);
487 /* Enable the widget only if the toggle button is active: */
488 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
489 gtk_widget_set_sensitive (widget, enable);
492 /* Make the sensitivity of a widget depend on a toggle button.
495 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
497 g_signal_connect (G_OBJECT (button), "toggled",
498 G_CALLBACK (on_toggle_button_changed), widget);
500 /* Set the starting sensitivity: */
501 on_toggle_button_changed (button, widget);
505 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
507 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
509 /* Create the window if necessary: */
510 if (!(self->specific_window)) {
511 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
512 modest_connection_specific_smtp_window_fill_with_connections (
513 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
517 /* Show the window: */
518 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
519 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
520 gtk_widget_show (self->specific_window);
524 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
526 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
528 ModestProtocol protocol_security =
529 modest_secureauth_combo_box_get_active_secureauth (
530 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
531 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
533 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
534 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
538 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
540 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
542 const gint port_number =
543 modest_serversecurity_combo_box_get_active_serversecurity_port (
544 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
546 if(port_number != 0) {
547 hildon_number_editor_set_value (
548 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
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 hildon_number_editor_set_value (
563 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
568 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
570 GtkWidget *box = gtk_vbox_new (FALSE, 2);
572 /* Create a size group to be used by all captions.
573 * Note that HildonCaption does not create a default size group if we do not specify one.
574 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
575 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
577 /* The outgoing server widgets: */
578 if (!self->entry_outgoingserver)
579 self->entry_outgoingserver = gtk_entry_new ();
580 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
581 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
582 gtk_widget_show (self->entry_outgoingserver);
583 connect_for_modified (self, self->entry_outgoingserver);
584 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
585 gtk_widget_show (caption);
587 /* The secure authentication widgets: */
588 if (!self->combo_outgoing_auth)
589 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
590 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
591 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
592 gtk_widget_show (self->combo_outgoing_auth);
593 connect_for_modified (self, self->combo_outgoing_auth);
594 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
595 gtk_widget_show (caption);
597 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
598 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
600 /* The username widgets: */
601 self->entry_outgoing_username = GTK_WIDGET (easysetup_validating_entry_new ());
602 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
603 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
604 gtk_widget_show (self->entry_outgoing_username);
605 connect_for_modified (self, self->entry_outgoing_username);
606 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, 2);
607 gtk_widget_show (self->caption_outgoing_username);
609 /* Prevent the use of some characters in the username,
610 * as required by our UI specification: */
611 easysetup_validating_entry_set_unallowed_characters_whitespace (
612 EASYSETUP_VALIDATING_ENTRY (self->entry_outgoing_username));
614 /* Set max length as in the UI spec:
615 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
616 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
618 /* The password widgets: */
619 self->entry_outgoing_password = gtk_entry_new ();
620 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
621 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
622 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
623 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
624 gtk_widget_show (self->entry_outgoing_password);
625 connect_for_modified (self, self->entry_outgoing_password);
626 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, 2);
627 gtk_widget_show (self->caption_outgoing_password);
629 /* The secure connection widgets: */
630 /* This will be filled and set with modest_serversecurity_combo_box_fill()
631 * and modest_serversecurity_combo_box_set_active_serversecurity().
633 if (!self->combo_outgoing_security)
634 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
635 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
636 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
637 gtk_widget_show (self->combo_outgoing_security);
638 connect_for_modified (self, self->combo_outgoing_security);
639 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
640 gtk_widget_show (caption);
642 /* Show a default port number when the security method changes, as per the UI spec: */
643 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
645 /* The port widgets: */
646 if (!self->entry_outgoing_port)
647 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 10000 /* arbitrary min and max */));
648 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
649 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
650 gtk_widget_show (self->entry_outgoing_port);
651 connect_for_modified (self, self->entry_outgoing_port);
652 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
653 gtk_widget_show (caption);
655 /* connection-specific checkbox: */
656 if (!self->checkbox_outgoing_smtp_specific) {
657 self->checkbox_outgoing_smtp_specific = gtk_check_button_new_with_label (_("mcen_fi_advsetup_connection_smtp"));
658 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
661 gtk_box_pack_start (GTK_BOX (box), self->checkbox_outgoing_smtp_specific, FALSE, FALSE, 2);
662 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
663 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
665 /* Connection-specific SMTP-Severs Edit button: */
666 if (!self->button_outgoing_smtp_servers)
667 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
668 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
669 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
670 gtk_widget_show (self->button_outgoing_smtp_servers);
671 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
672 gtk_widget_show (caption);
674 /* Only enable the button when the checkbox is checked: */
675 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
676 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
678 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
679 G_CALLBACK (on_button_outgoing_smtp_servers), self);
682 gtk_widget_show (GTK_WIDGET (box));
684 return GTK_WIDGET (box);
688 check_data (ModestAccountSettingsDialog *self)
690 /* Check that the title is not already in use: */
691 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
692 if ((!account_title) || (strlen(account_title) == 0))
693 return FALSE; /* Should be prevented already anyway. */
695 if (strcmp(account_title, self->original_account_title) != 0) {
696 /* Check the changed title: */
697 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
701 /* Warn the user via a dialog: */
702 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
708 /* Check that the email address is valud: */
709 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
710 if ((!email_address) || (strlen(email_address) == 0))
713 if (!modest_text_utils_validate_email_address (email_address)) {
714 /* Warn the user via a dialog: */
715 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
717 /* Return focus to the email address entry: */
718 gtk_widget_grab_focus (self->entry_user_email);
723 /* TODO: The UI Spec wants us to check that the servernames are valid,
724 * but does not specify how.
732 on_response (GtkDialog *wizard_dialog,
736 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
737 enable_buttons (self);
739 gboolean prevent_response = FALSE;
741 /* Warn about unsaved changes: */
742 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
743 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
746 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
747 _("imum_nc_wizard_confirm_lose_changes") ));
749 const gint dialog_response = gtk_dialog_run (dialog);
750 gtk_widget_destroy (GTK_WIDGET (dialog));
752 if (dialog_response != GTK_RESPONSE_OK)
753 prevent_response = TRUE;
755 /* Check for invalid input: */
756 else if (!check_data (self)) {
757 prevent_response = TRUE;
760 if (prevent_response) {
761 /* This is a nasty hack. murrayc. */
762 /* Don't let the dialog close */
763 g_signal_stop_emission_by_name (wizard_dialog, "response");
768 if (response_id == GTK_RESPONSE_OK) {
769 /* Try to save the changes: */
770 const gboolean saved = save_configuration (self);
772 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
774 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
779 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
781 /* Create the notebook to be used by the GtkDialog base class:
782 * Each page of the notebook will be a page of the wizard: */
783 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
786 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
788 /* Get the account manager object,
789 * so we can check for existing accounts,
790 * and create new accounts: */
791 self->account_manager = modest_runtime_get_account_mgr ();
792 g_assert (self->account_manager);
793 g_object_ref (self->account_manager);
795 /* Create the common pages,
797 self->page_account_details = create_page_account_details (self);
798 self->page_user_details = create_page_user_details (self);
799 self->page_incoming = create_page_incoming (self);
800 self->page_outgoing = create_page_outgoing (self);
802 /* Add the notebook pages: */
803 gtk_notebook_append_page (notebook, self->page_account_details,
804 gtk_label_new (_("mcen_ti_account_settings_account")));
805 gtk_notebook_append_page (notebook, self->page_user_details,
806 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
807 gtk_notebook_append_page (notebook, self->page_incoming,
808 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
809 gtk_notebook_append_page (notebook, self->page_outgoing,
810 gtk_label_new (_("mcen_ti_advsetup_sending")));
812 GtkDialog *dialog = GTK_DIALOG (self);
813 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
814 gtk_widget_show (GTK_WIDGET (notebook));
816 /* Add the buttons: */
817 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
818 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
820 /* Connect to the dialog's response signal: */
821 /* We use connect-before
822 * so we can stop the signal emission,
823 * to stop the default signal handler from closing the dialog.
825 g_signal_connect (G_OBJECT (self), "response",
826 G_CALLBACK (on_response), self);
828 self->modified = FALSE;
831 ModestAccountSettingsDialog*
832 modest_account_settings_dialog_new (void)
834 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
837 /** Update the UI with the stored account details, so they can be edited.
838 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
840 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
845 /* Save the account name so we can refer to it later: */
846 if (dialog->account_name)
847 g_free (dialog->account_name);
848 dialog->account_name = g_strdup (account_name);
851 /* Get the account data for this account name: */
852 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
855 g_printerr ("modest: failed to get account data for %s\n", account_name);
859 /* Save the account title so we can refer to it if the user changes it: */
860 if (dialog->original_account_title)
861 g_free (dialog->original_account_title);
862 dialog->original_account_title = g_strdup (account_data->display_name);
865 if (!(account_data->store_account)) {
866 g_printerr ("modest: account has no stores: %s\n", account_name);
870 /* Show the account data in the widgets: */
872 /* Note that we never show the non-display name in the UI.
873 * (Though the display name defaults to the non-display name at the start.) */
874 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
875 account_data->display_name ? account_data->display_name : "");
877 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
878 account_data->fullname ? account_data->fullname : "");
879 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
880 account_data->email ? account_data->email : "");
882 ModestServerAccountData *incoming_account = account_data->store_account;
884 if (incoming_account)
885 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
886 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
887 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
889 /* Default to something, though no default is specified in the UI spec: */
890 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
892 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
895 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
896 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
897 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
900 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
901 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
902 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
904 /* Only show the leave-on-server checkbox for POP,
905 * as per the UI spec: */
906 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
907 gtk_widget_hide (dialog->checkbox_leave_messages);
909 gtk_widget_show (dialog->checkbox_leave_messages);
912 if (incoming_account) {
913 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
914 incoming_account->username ? incoming_account->username : "");
915 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
916 incoming_account->password ? incoming_account->password : "");
918 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
919 incoming_account->hostname ? incoming_account->hostname : "");
921 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
922 dialog->account_manager, incoming_account->account_name);
923 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
924 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
926 update_incoming_server_title (dialog, incoming_account->proto);
927 update_incoming_server_security_choices (dialog, incoming_account->proto);
929 const ModestProtocol security = modest_server_account_get_security (
930 dialog->account_manager, incoming_account->account_name);
931 modest_serversecurity_combo_box_set_active_serversecurity (
932 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
934 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
935 MODEST_ACCOUNT_PORT, TRUE /* server account */);
936 hildon_number_editor_set_value (
937 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
941 ModestServerAccountData *outgoing_account = account_data->transport_account;
942 if (outgoing_account) {
943 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
944 outgoing_account->hostname ? outgoing_account->hostname : "");
946 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
947 outgoing_account->username ? outgoing_account->username : "");
948 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
949 outgoing_account->password ? outgoing_account->password : "");
951 /* Get the secure-auth setting: */
952 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
953 dialog->account_manager, outgoing_account->account_name);
954 modest_secureauth_combo_box_set_active_secureauth (
955 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
956 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
958 modest_serversecurity_combo_box_fill (
959 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
961 /* Get the security setting: */
962 const ModestProtocol security = modest_server_account_get_security (
963 dialog->account_manager, outgoing_account->account_name);
964 modest_serversecurity_combo_box_set_active_serversecurity (
965 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
967 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
968 MODEST_ACCOUNT_PORT, TRUE /* server account */);
969 hildon_number_editor_set_value (
970 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
973 /* account_data->is_enabled, */
974 /*account_data->is_default, */
976 /* account_data->store_account->proto */
978 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
980 /* Unset the modified flag so we can detect changes later: */
981 dialog->modified = FALSE;
985 save_configuration (ModestAccountSettingsDialog *dialog)
987 g_assert (dialog->account_name);
989 const gchar* account_name = dialog->account_name;
991 /* Set the account data from the widgets: */
992 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
993 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
994 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
998 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
999 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1000 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1004 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1005 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1006 modest_account_mgr_set_string (dialog->account_manager, account_name,
1007 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1010 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1011 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1012 modest_account_mgr_set_int (dialog->account_manager, account_name,
1013 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1015 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1016 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1017 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1022 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1023 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1024 g_assert (incoming_account_name);
1026 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1027 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1028 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1032 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1033 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1034 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1038 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1039 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1040 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1044 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1045 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1046 ? MODEST_PROTOCOL_AUTH_PASSWORD
1047 : MODEST_PROTOCOL_AUTH_NONE;
1048 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1050 const ModestProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1051 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1052 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1055 gint port_num = hildon_number_editor_get_value (
1056 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1057 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1058 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1060 g_free (incoming_account_name);
1063 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1064 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1065 g_assert (outgoing_account_name);
1067 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1068 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1069 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1073 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1074 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1075 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1079 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1080 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1081 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1085 const ModestProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1086 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1087 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1089 const ModestProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1090 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1091 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1094 port_num = hildon_number_editor_get_value (
1095 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1096 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1097 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1099 g_free (outgoing_account_name);
1102 /* Set the changed account title last, to simplify the previous code: */
1103 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1104 if ((!account_title) || (strlen(account_title) == 0))
1105 return FALSE; /* Should be prevented already anyway. */
1107 if (strcmp(account_title, account_name) != 0) {
1108 /* Change the title: */
1109 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1110 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1115 /* Save connection-specific SMTP server accounts: */
1116 if (dialog->specific_window)
1117 return modest_connection_specific_smtp_window_save_server_accounts (
1118 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1123 static gboolean entry_is_empty (GtkWidget *entry)
1128 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1129 if ((!text) || (strlen(text) == 0))
1136 enable_buttons (ModestAccountSettingsDialog *self)
1138 gboolean enable_ok = TRUE;
1140 /* The account details title is mandatory: */
1141 if (entry_is_empty(self->entry_account_title))
1144 /* The user details username is mandatory: */
1145 if (entry_is_empty(self->entry_user_username))
1148 /* The user details email address is mandatory: */
1149 if (enable_ok && entry_is_empty (self->entry_user_email))
1152 /* The custom incoming server is mandatory: */
1153 if (entry_is_empty(self->entry_incomingserver))
1156 /* Enable the buttons,
1157 * identifying them via their associated response codes:
1159 GtkDialog *dialog_base = GTK_DIALOG (self);
1160 gtk_dialog_set_response_sensitive (dialog_base,
1166 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1168 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1169 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1172 object_class->get_property = modest_account_settings_dialog_get_property;
1173 object_class->set_property = modest_account_settings_dialog_set_property;
1174 object_class->dispose = modest_account_settings_dialog_dispose;
1175 object_class->finalize = modest_account_settings_dialog_finalize;
1179 show_error (GtkWindow *parent_window, const gchar* text)
1181 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1187 gtk_dialog_run (dialog);
1188 gtk_widget_destroy (GTK_WIDGET (dialog));
1192 show_ok (GtkWindow *parent_window, const gchar* text)
1194 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1200 gtk_dialog_run (dialog);
1201 gtk_widget_destroy (GTK_WIDGET (dialog));