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 "modest-hildon-includes.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 "maemo/modest-signature-editor-dialog.h"
31 #include <maemo/modest-maemo-ui-constants.h>
32 #include <gconf/gconf-client.h>
33 #include <string.h> /* For strlen(). */
35 /* Include config.h so that _() works: */
40 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
42 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
44 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
45 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
47 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
49 struct _ModestAccountSettingsDialogPrivate
54 enable_buttons (ModestAccountSettingsDialog *self);
57 save_configuration (ModestAccountSettingsDialog *dialog);
60 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
61 GValue *value, GParamSpec *pspec)
63 switch (property_id) {
65 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
70 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
71 const GValue *value, GParamSpec *pspec)
73 switch (property_id) {
75 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
80 modest_account_settings_dialog_dispose (GObject *object)
82 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
83 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
87 modest_account_settings_dialog_finalize (GObject *object)
89 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
91 if (self->account_name)
92 g_free (self->account_name);
94 if (self->original_account_title)
95 g_free (self->original_account_title);
97 if (self->account_manager)
98 g_object_unref (G_OBJECT (self->account_manager));
100 if (self->specific_window)
101 gtk_widget_destroy (self->specific_window);
103 if (self->signature_dialog)
104 gtk_widget_destroy (self->signature_dialog);
106 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
110 show_error (GtkWindow *parent_window, const gchar* text);
113 show_ok (GtkWindow *parent_window, const gchar* text);
116 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
119 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
122 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
124 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
125 self->modified = TRUE;
129 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
131 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
132 self->modified = TRUE;
136 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
138 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
139 self->modified = TRUE;
142 /* Set a modified boolean whenever the widget is changed,
143 * so we can check for it later.
146 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
148 if (GTK_IS_ENTRY (widget)) {
149 g_signal_connect (G_OBJECT (widget), "changed",
150 G_CALLBACK (on_modified_entry_changed), self);
151 } else if (GTK_IS_COMBO_BOX (widget)) {
152 g_signal_connect (G_OBJECT (widget), "changed",
153 G_CALLBACK (on_modified_combobox_changed), self);
154 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
155 g_signal_connect (G_OBJECT (widget), "toggled",
156 G_CALLBACK (on_modified_checkbox_toggled), self);
161 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
163 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
165 enable_buttons(self);
169 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
171 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
173 enable_buttons(self);
176 /** This is a convenience function to create a caption containing a mandatory widget.
177 * When the widget is edited, the enable_buttons() vfunc will be called.
179 static GtkWidget* create_caption_new_with_asterix(ModestAccountSettingsDialog *self,
184 HildonCaptionStatus flag)
186 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
188 /* The translated strings seem to already contain the *,
189 * but this code can be used if that is not true in future.
192 /* Add a * character to indicate mandatory fields,
193 * as specified in our "Email UI Specification": */
194 if (flag == HILDON_CAPTION_MANDATORY) {
195 gchar* title = g_strdup_printf("%s*", value);
196 caption = hildon_caption_new (group, title, control, icon, flag);
200 caption = hildon_caption_new (group, value, control, icon, flag);
203 /* Connect to the appropriate changed signal for the widget,
204 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
206 if (GTK_IS_ENTRY (control)) {
207 g_signal_connect (G_OBJECT (control), "changed",
208 G_CALLBACK (on_caption_entry_changed), self);
211 else if (GTK_IS_COMBO_BOX (control)) {
212 g_signal_connect (G_OBJECT (control), "changed",
213 G_CALLBACK (on_caption_combobox_changed), self);
221 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
223 ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
224 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
228 create_page_account_details (ModestAccountSettingsDialog *self)
230 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
231 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
232 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
233 gtk_widget_show (label);
235 /* Create a size group to be used by all captions.
236 * Note that HildonCaption does not create a default size group if we do not specify one.
237 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
238 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
240 /* The description widgets: */
241 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
242 /* Do use auto-capitalization: */
243 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
244 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
245 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
246 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
247 gtk_widget_show (self->entry_account_title);
248 connect_for_modified (self, self->entry_account_title);
249 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
250 gtk_widget_show (caption);
252 /* Prevent the use of some characters in the account title,
253 * as required by our UI specification: */
254 GList *list_prevent = NULL;
255 list_prevent = g_list_append (list_prevent, "\\");
256 list_prevent = g_list_append (list_prevent, "/");
257 list_prevent = g_list_append (list_prevent, ":");
258 list_prevent = g_list_append (list_prevent, "*");
259 list_prevent = g_list_append (list_prevent, "?");
260 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
261 list_prevent = g_list_append (list_prevent, "“");
262 list_prevent = g_list_append (list_prevent, "<");
263 list_prevent = g_list_append (list_prevent, ">");
264 list_prevent = g_list_append (list_prevent, "|");
265 list_prevent = g_list_append (list_prevent, "^");
266 modest_validating_entry_set_unallowed_characters (
267 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
268 g_list_free (list_prevent);
270 /* Set max length as in the UI spec:
271 * The UI spec seems to want us to show a dialog if we hit the maximum. */
272 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
273 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
276 /* The retrieve combobox: */
277 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
278 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
279 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
280 gtk_widget_show (self->combo_retrieve);
281 connect_for_modified (self, self->combo_retrieve);
282 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
283 gtk_widget_show (caption);
285 /* The limit-retrieve combobox: */
286 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
287 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
288 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
289 gtk_widget_show (self->combo_limit_retrieve);
290 connect_for_modified (self, self->combo_limit_retrieve);
291 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
292 gtk_widget_show (caption);
294 /* The leave-messages widgets: */
295 if(!self->checkbox_leave_messages)
296 self->checkbox_leave_messages = gtk_check_button_new ();
297 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
298 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
299 gtk_widget_show (self->checkbox_leave_messages);
300 connect_for_modified (self, self->checkbox_leave_messages);
301 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
302 gtk_widget_show (caption);
304 gtk_widget_show (GTK_WIDGET (box));
306 return GTK_WIDGET (box);
310 on_button_signature (GtkButton *button, gpointer user_data)
312 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
314 /* Create the window, if necessary: */
315 if (!(self->signature_dialog)) {
316 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
318 gboolean use_signature = FALSE;
319 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
321 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
322 modest_signature_editor_dialog_set_settings (
323 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
324 use_signature, signature, account_title);
329 /* Show the window: */
330 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
331 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
332 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
333 gtk_widget_hide (self->signature_dialog);
334 if (response != GTK_RESPONSE_OK) {
335 /* Destroy the widget now, and its data: */
336 gtk_widget_destroy (self->signature_dialog);
337 self->signature_dialog = NULL;
340 /* Mark modified, so we use the dialog's data later: */
341 self->modified = TRUE;
346 create_page_user_details (ModestAccountSettingsDialog *self)
348 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
350 /* Create a size group to be used by all captions.
351 * Note that HildonCaption does not create a default size group if we do not specify one.
352 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
353 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
355 /* The name widgets: */
356 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
357 /* Auto-capitalization is the default, so let's turn it off: */
358 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
359 /* Set max length as in the UI spec:
360 * The UI spec seems to want us to show a dialog if we hit the maximum. */
361 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
362 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
364 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
365 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
366 gtk_widget_show (self->entry_user_name);
367 connect_for_modified (self, self->entry_user_name);
368 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
369 gtk_widget_show (caption);
371 /* Prevent the use of some characters in the name,
372 * as required by our UI specification: */
373 GList *list_prevent = NULL;
374 list_prevent = g_list_append (list_prevent, "<");
375 list_prevent = g_list_append (list_prevent, ">");
376 modest_validating_entry_set_unallowed_characters (
377 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
378 g_list_free (list_prevent);
380 /* The username widgets: */
381 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
382 /* Auto-capitalization is the default, so let's turn it off: */
383 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
384 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
385 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
386 gtk_widget_show (self->entry_user_username);
387 connect_for_modified (self, self->entry_user_username);
388 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
389 gtk_widget_show (caption);
391 /* Prevent the use of some characters in the username,
392 * as required by our UI specification: */
393 modest_validating_entry_set_unallowed_characters_whitespace (
394 MODEST_VALIDATING_ENTRY (self->entry_user_username));
396 /* Set max length as in the UI spec:
397 * The UI spec seems to want us to show a dialog if we hit the maximum. */
398 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
399 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
402 /* The password widgets: */
403 self->entry_user_password = gtk_entry_new ();
404 /* Auto-capitalization is the default, so let's turn it off: */
405 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password), HILDON_GTK_INPUT_MODE_FULL);
406 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
407 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
408 caption = create_caption_new_with_asterix (self, sizegroup,
409 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
410 gtk_widget_show (self->entry_user_password);
411 connect_for_modified (self, self->entry_user_password);
412 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
413 gtk_widget_show (caption);
415 /* The email address widgets: */
416 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
417 /* Auto-capitalization is the default, so let's turn it off: */
418 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
419 caption = create_caption_new_with_asterix (self, sizegroup,
420 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
421 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
422 gtk_widget_show (self->entry_user_email);
423 connect_for_modified (self, self->entry_user_email);
424 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
425 gtk_widget_show (caption);
427 /* Set max length as in the UI spec:
428 * The UI spec seems to want us to show a dialog if we hit the maximum. */
429 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
430 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
433 /* Signature button: */
434 if (!self->button_signature)
435 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
436 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
437 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
438 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
439 gtk_widget_show (self->button_signature);
440 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
441 gtk_widget_show (caption);
443 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
444 G_CALLBACK (on_button_signature), self);
446 gtk_widget_show (GTK_WIDGET (box));
448 return GTK_WIDGET (box);
451 /** Change the caption title for the incoming server,
452 * as specified in the UI spec:
454 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
457 (protocol == MODEST_PROTOCOL_STORE_POP ?
458 _("mail_fi_emailtype_pop3") :
459 _("mail_fi_emailtype_imap") );
462 /* Note that this produces a compiler warning,
463 * because the compiler does not know that the translated string will have a %s in it.
464 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
465 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
466 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
467 g_free(incomingserver_title);
470 /** Change the caption title for the incoming server,
471 * as specified in the UI spec:
473 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
475 /* Fill the combo with appropriately titled choices for POP or IMAP. */
476 /* The choices are the same, but the titles are different, as in the UI spec. */
477 modest_serversecurity_combo_box_fill (
478 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
481 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
483 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
485 /* Create a size group to be used by all captions.
486 * Note that HildonCaption does not create a default size group if we do not specify one.
487 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
488 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
490 /* The incoming server widgets: */
491 if(!self->entry_incomingserver)
492 self->entry_incomingserver = gtk_entry_new ();
493 /* Auto-capitalization is the default, so let's turn it off: */
494 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
496 if (self->caption_incoming)
497 gtk_widget_destroy (self->caption_incoming);
499 /* The caption title will be updated in update_incoming_server_title().
500 * so this default text will never be seen: */
501 /* (Note: Changing the title seems pointless. murrayc) */
502 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
503 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
504 gtk_widget_show (self->entry_incomingserver);
505 connect_for_modified (self, self->entry_incomingserver);
506 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
507 gtk_widget_show (self->caption_incoming);
509 /* The secure connection widgets: */
510 /* This will be filled by update_incoming_server_security_choices(). */
511 if (!self->combo_incoming_security)
512 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
513 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
514 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
515 gtk_widget_show (self->combo_incoming_security);
516 connect_for_modified (self, self->combo_incoming_security);
517 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
518 gtk_widget_show (caption);
520 /* Show a default port number when the security method changes, as per the UI spec: */
521 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
524 /* The port widgets: */
525 /* TODO: There are various rules about this in the UI spec. */
526 if (!self->entry_incoming_port)
527 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
528 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
529 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
530 gtk_widget_show (self->entry_incoming_port);
531 connect_for_modified (self, self->entry_incoming_port);
532 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
533 gtk_widget_show (caption);
535 /* The secure authentication widgets: */
536 if(!self->checkbox_incoming_auth)
537 self->checkbox_incoming_auth = gtk_check_button_new ();
538 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
539 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
540 gtk_widget_show (self->checkbox_incoming_auth);
541 connect_for_modified (self, self->checkbox_incoming_auth);
542 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
543 gtk_widget_show (caption);
545 gtk_widget_show (GTK_WIDGET (box));
547 return GTK_WIDGET (box);
551 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
553 GtkWidget *widget = GTK_WIDGET (user_data);
555 /* Enable the widget only if the toggle button is active: */
556 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
557 gtk_widget_set_sensitive (widget, enable);
560 /* Make the sensitivity of a widget depend on a toggle button.
563 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
565 g_signal_connect (G_OBJECT (button), "toggled",
566 G_CALLBACK (on_toggle_button_changed), widget);
568 /* Set the starting sensitivity: */
569 on_toggle_button_changed (button, widget);
573 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
575 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
577 /* Create the window if necessary: */
578 if (!(self->specific_window)) {
579 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
580 modest_connection_specific_smtp_window_fill_with_connections (
581 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
585 /* Show the window: */
586 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
587 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
588 gtk_widget_show (self->specific_window);
592 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
594 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
596 ModestProtocol protocol_security =
597 modest_secureauth_combo_box_get_active_secureauth (
598 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
599 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
601 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
602 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
606 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
608 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
610 const gint port_number =
611 modest_serversecurity_combo_box_get_active_serversecurity_port (
612 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
614 if(port_number != 0) {
615 hildon_number_editor_set_value (
616 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
621 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
623 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
625 const gint port_number =
626 modest_serversecurity_combo_box_get_active_serversecurity_port (
627 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
629 if(port_number != 0) {
630 hildon_number_editor_set_value (
631 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
636 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
638 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
640 /* Create a size group to be used by all captions.
641 * Note that HildonCaption does not create a default size group if we do not specify one.
642 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
643 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
645 /* The outgoing server widgets: */
646 if (!self->entry_outgoingserver)
647 self->entry_outgoingserver = gtk_entry_new ();
648 /* Auto-capitalization is the default, so let's turn it off: */
649 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
650 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
651 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
652 gtk_widget_show (self->entry_outgoingserver);
653 connect_for_modified (self, self->entry_outgoingserver);
654 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
655 gtk_widget_show (caption);
657 /* The secure authentication widgets: */
658 if (!self->combo_outgoing_auth)
659 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
660 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
661 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
662 gtk_widget_show (self->combo_outgoing_auth);
663 connect_for_modified (self, self->combo_outgoing_auth);
664 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
665 gtk_widget_show (caption);
667 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
668 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
670 /* The username widgets: */
671 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
672 /* Auto-capitalization is the default, so let's turn it off: */
673 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
674 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
675 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
676 gtk_widget_show (self->entry_outgoing_username);
677 connect_for_modified (self, self->entry_outgoing_username);
678 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
679 gtk_widget_show (self->caption_outgoing_username);
681 /* Prevent the use of some characters in the username,
682 * as required by our UI specification: */
683 modest_validating_entry_set_unallowed_characters_whitespace (
684 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
686 /* Set max length as in the UI spec:
687 * The UI spec seems to want us to show a dialog if we hit the maximum. */
688 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
689 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
692 /* The password widgets: */
693 self->entry_outgoing_password = gtk_entry_new ();
694 /* Auto-capitalization is the default, so let's turn it off: */
695 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password), HILDON_GTK_INPUT_MODE_FULL);
696 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
697 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
698 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
699 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
700 gtk_widget_show (self->entry_outgoing_password);
701 connect_for_modified (self, self->entry_outgoing_password);
702 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
703 gtk_widget_show (self->caption_outgoing_password);
705 /* The secure connection widgets: */
706 /* This will be filled and set with modest_serversecurity_combo_box_fill()
707 * and modest_serversecurity_combo_box_set_active_serversecurity().
709 if (!self->combo_outgoing_security)
710 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
711 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
712 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
713 gtk_widget_show (self->combo_outgoing_security);
714 connect_for_modified (self, self->combo_outgoing_security);
715 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
716 gtk_widget_show (caption);
718 /* Show a default port number when the security method changes, as per the UI spec: */
719 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
721 /* The port widgets: */
722 if (!self->entry_outgoing_port)
723 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
724 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
725 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
726 gtk_widget_show (self->entry_outgoing_port);
727 connect_for_modified (self, self->entry_outgoing_port);
728 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
729 gtk_widget_show (caption);
731 GtkWidget *separator = gtk_hseparator_new ();
732 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
733 gtk_widget_show (separator);
735 /* connection-specific checkbox: */
736 if (!self->checkbox_outgoing_smtp_specific) {
737 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
738 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
741 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
742 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
743 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
744 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
745 gtk_widget_show (caption);
746 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
748 /* Connection-specific SMTP-Severs Edit button: */
749 if (!self->button_outgoing_smtp_servers)
750 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
751 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
752 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
753 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
754 gtk_widget_show (self->button_outgoing_smtp_servers);
755 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
756 gtk_widget_show (caption);
758 /* Only enable the button when the checkbox is checked: */
759 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
760 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
762 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
763 G_CALLBACK (on_button_outgoing_smtp_servers), self);
766 gtk_widget_show (GTK_WIDGET (box));
768 return GTK_WIDGET (box);
772 check_data (ModestAccountSettingsDialog *self)
774 /* Check that the title is not already in use: */
775 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
776 if ((!account_title) || (strlen(account_title) == 0))
777 return FALSE; /* Should be prevented already anyway. */
779 if (strcmp(account_title, self->original_account_title) != 0) {
780 /* Check the changed title: */
781 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
785 /* Warn the user via a dialog: */
786 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
792 /* Check that the email address is valud: */
793 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
794 if ((!email_address) || (strlen(email_address) == 0))
797 if (!modest_text_utils_validate_email_address (email_address)) {
798 /* Warn the user via a dialog: */
799 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
801 /* Return focus to the email address entry: */
802 gtk_widget_grab_focus (self->entry_user_email);
807 /* TODO: The UI Spec wants us to check that the servernames are valid,
808 * but does not specify how.
816 on_response (GtkDialog *wizard_dialog,
820 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
821 enable_buttons (self);
823 gboolean prevent_response = FALSE;
825 /* Warn about unsaved changes: */
826 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
827 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (GTK_WINDOW (self),
830 GTK_BUTTONS_OK_CANCEL, /* TODO: These button names are ambiguous, and not specified in the UI specification. */
831 _("imum_nc_wizard_confirm_lose_changes") ));
833 const gint dialog_response = gtk_dialog_run (dialog);
834 gtk_widget_destroy (GTK_WIDGET (dialog));
836 if (dialog_response != GTK_RESPONSE_OK)
837 prevent_response = TRUE;
839 /* Check for invalid input: */
840 else if (!check_data (self)) {
841 prevent_response = TRUE;
844 if (prevent_response) {
845 /* This is a nasty hack. murrayc. */
846 /* Don't let the dialog close */
847 g_signal_stop_emission_by_name (wizard_dialog, "response");
852 if (response_id == GTK_RESPONSE_OK) {
853 /* Try to save the changes: */
854 const gboolean saved = save_configuration (self);
856 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
858 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
863 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
865 /* Create the notebook to be used by the GtkDialog base class:
866 * Each page of the notebook will be a page of the wizard: */
867 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
870 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
872 /* Get the account manager object,
873 * so we can check for existing accounts,
874 * and create new accounts: */
875 self->account_manager = modest_runtime_get_account_mgr ();
876 g_assert (self->account_manager);
877 g_object_ref (self->account_manager);
879 /* Create the common pages,
881 self->page_account_details = create_page_account_details (self);
882 self->page_user_details = create_page_user_details (self);
883 self->page_incoming = create_page_incoming (self);
884 self->page_outgoing = create_page_outgoing (self);
886 /* Add the notebook pages: */
887 gtk_notebook_append_page (notebook, self->page_account_details,
888 gtk_label_new (_("mcen_ti_account_settings_account")));
889 gtk_notebook_append_page (notebook, self->page_user_details,
890 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
891 gtk_notebook_append_page (notebook, self->page_incoming,
892 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
893 gtk_notebook_append_page (notebook, self->page_outgoing,
894 gtk_label_new (_("mcen_ti_advsetup_sending")));
896 GtkDialog *dialog = GTK_DIALOG (self);
897 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
898 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
899 gtk_widget_show (GTK_WIDGET (notebook));
901 /* Add the buttons: */
902 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
903 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
905 /* Connect to the dialog's response signal: */
906 /* We use connect-before
907 * so we can stop the signal emission,
908 * to stop the default signal handler from closing the dialog.
910 g_signal_connect (G_OBJECT (self), "response",
911 G_CALLBACK (on_response), self);
913 self->modified = FALSE;
916 ModestAccountSettingsDialog*
917 modest_account_settings_dialog_new (void)
919 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
922 /** Update the UI with the stored account details, so they can be edited.
923 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
925 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
930 /* Save the account name so we can refer to it later: */
931 if (dialog->account_name)
932 g_free (dialog->account_name);
933 dialog->account_name = g_strdup (account_name);
936 /* Get the account data for this account name: */
937 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
940 g_printerr ("modest: failed to get account data for %s\n", account_name);
944 /* Save the account title so we can refer to it if the user changes it: */
945 if (dialog->original_account_title)
946 g_free (dialog->original_account_title);
947 dialog->original_account_title = g_strdup (account_data->display_name);
950 if (!(account_data->store_account)) {
951 g_printerr ("modest: account has no stores: %s\n", account_name);
955 /* Show the account data in the widgets: */
957 /* Note that we never show the non-display name in the UI.
958 * (Though the display name defaults to the non-display name at the start.) */
959 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
960 account_data->display_name ? account_data->display_name : "");
962 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
963 account_data->fullname ? account_data->fullname : "");
964 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
965 account_data->email ? account_data->email : "");
967 ModestServerAccountData *incoming_account = account_data->store_account;
969 if (incoming_account)
970 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
971 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
972 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
974 /* Default to something, though no default is specified in the UI spec: */
975 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
977 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
980 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
981 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
982 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
985 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
986 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
987 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
989 /* Only show the leave-on-server checkbox for POP,
990 * as per the UI spec: */
991 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
992 gtk_widget_hide (dialog->checkbox_leave_messages);
994 gtk_widget_show (dialog->checkbox_leave_messages);
997 if (incoming_account) {
998 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
999 incoming_account->username ? incoming_account->username : "");
1000 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1001 incoming_account->password ? incoming_account->password : "");
1003 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1004 incoming_account->hostname ? incoming_account->hostname : "");
1006 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
1007 dialog->account_manager, incoming_account->account_name);
1008 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1009 secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
1011 update_incoming_server_title (dialog, incoming_account->proto);
1012 update_incoming_server_security_choices (dialog, incoming_account->proto);
1014 const ModestProtocol security = modest_server_account_get_security (
1015 dialog->account_manager, incoming_account->account_name);
1016 modest_serversecurity_combo_box_set_active_serversecurity (
1017 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1019 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1020 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1021 hildon_number_editor_set_value (
1022 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1026 ModestServerAccountData *outgoing_account = account_data->transport_account;
1027 if (outgoing_account) {
1028 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1029 outgoing_account->hostname ? outgoing_account->hostname : "");
1031 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1032 outgoing_account->username ? outgoing_account->username : "");
1033 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1034 outgoing_account->password ? outgoing_account->password : "");
1036 /* Get the secure-auth setting: */
1037 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
1038 dialog->account_manager, outgoing_account->account_name);
1039 modest_secureauth_combo_box_set_active_secureauth (
1040 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1041 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1043 modest_serversecurity_combo_box_fill (
1044 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1046 /* Get the security setting: */
1047 const ModestProtocol security = modest_server_account_get_security (
1048 dialog->account_manager, outgoing_account->account_name);
1049 modest_serversecurity_combo_box_set_active_serversecurity (
1050 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1052 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1053 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1054 hildon_number_editor_set_value (
1055 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1058 /* account_data->is_enabled, */
1059 /*account_data->is_default, */
1061 /* account_data->store_account->proto */
1063 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1065 /* Unset the modified flag so we can detect changes later: */
1066 dialog->modified = FALSE;
1070 save_configuration (ModestAccountSettingsDialog *dialog)
1072 g_assert (dialog->account_name);
1074 const gchar* account_name = dialog->account_name;
1076 /* Set the account data from the widgets: */
1077 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1078 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1079 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1083 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1084 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1085 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1090 if (dialog->signature_dialog) {
1091 gboolean use_signature = FALSE;
1092 gchar *signature = modest_signature_editor_dialog_get_settings (
1093 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1096 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1097 signature, use_signature);
1101 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1102 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1103 modest_account_mgr_set_string (dialog->account_manager, account_name,
1104 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1107 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1108 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1109 modest_account_mgr_set_int (dialog->account_manager, account_name,
1110 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1112 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1113 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1114 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1119 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1120 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1121 g_assert (incoming_account_name);
1123 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1124 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1125 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1129 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1130 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1131 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1135 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1136 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1137 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1141 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1142 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1143 ? MODEST_PROTOCOL_AUTH_PASSWORD
1144 : MODEST_PROTOCOL_AUTH_NONE;
1145 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1147 const ModestProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1148 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1149 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1152 gint port_num = hildon_number_editor_get_value (
1153 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1154 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1155 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1157 g_free (incoming_account_name);
1160 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1161 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1162 g_assert (outgoing_account_name);
1164 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1165 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1166 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1170 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1171 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1172 MODEST_ACCOUNT_USERNAME, username, TRUE /* server account */);
1176 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1177 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1178 MODEST_ACCOUNT_PASSWORD, password, TRUE /* server account */);
1182 const ModestProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1183 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1184 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1186 const ModestProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1187 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1188 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1191 port_num = hildon_number_editor_get_value (
1192 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1193 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1194 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1196 g_free (outgoing_account_name);
1199 /* Set the changed account title last, to simplify the previous code: */
1200 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1201 if ((!account_title) || (strlen(account_title) == 0))
1202 return FALSE; /* Should be prevented already anyway. */
1204 if (strcmp(account_title, account_name) != 0) {
1205 /* Change the title: */
1206 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1207 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1212 /* Save connection-specific SMTP server accounts: */
1213 if (dialog->specific_window)
1214 return modest_connection_specific_smtp_window_save_server_accounts (
1215 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1220 static gboolean entry_is_empty (GtkWidget *entry)
1225 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1226 if ((!text) || (strlen(text) == 0))
1233 enable_buttons (ModestAccountSettingsDialog *self)
1235 gboolean enable_ok = TRUE;
1237 /* The account details title is mandatory: */
1238 if (entry_is_empty(self->entry_account_title))
1241 /* The user details username is mandatory: */
1242 if (entry_is_empty(self->entry_user_username))
1245 /* The user details email address is mandatory: */
1246 if (enable_ok && entry_is_empty (self->entry_user_email))
1249 /* The custom incoming server is mandatory: */
1250 if (entry_is_empty(self->entry_incomingserver))
1253 /* Enable the buttons,
1254 * identifying them via their associated response codes:
1256 GtkDialog *dialog_base = GTK_DIALOG (self);
1257 gtk_dialog_set_response_sensitive (dialog_base,
1263 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1265 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1266 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1269 object_class->get_property = modest_account_settings_dialog_get_property;
1270 object_class->set_property = modest_account_settings_dialog_set_property;
1271 object_class->dispose = modest_account_settings_dialog_dispose;
1272 object_class->finalize = modest_account_settings_dialog_finalize;
1276 show_error (GtkWindow *parent_window, const gchar* text)
1278 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1280 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1287 gtk_dialog_run (dialog);
1288 gtk_widget_destroy (GTK_WIDGET (dialog));
1292 show_ok (GtkWindow *parent_window, const gchar* text)
1294 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1296 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1303 gtk_dialog_run (dialog);
1304 gtk_widget_destroy (GTK_WIDGET (dialog));