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 "widgets/modest-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),
406 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
407 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
408 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
409 caption = create_caption_new_with_asterix (self, sizegroup,
410 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
411 gtk_widget_show (self->entry_user_password);
412 connect_for_modified (self, self->entry_user_password);
413 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
414 gtk_widget_show (caption);
416 /* The email address widgets: */
417 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
418 /* Auto-capitalization is the default, so let's turn it off: */
419 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
420 caption = create_caption_new_with_asterix (self, sizegroup,
421 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
422 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
423 gtk_widget_show (self->entry_user_email);
424 connect_for_modified (self, self->entry_user_email);
425 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
426 gtk_widget_show (caption);
428 /* Set max length as in the UI spec:
429 * The UI spec seems to want us to show a dialog if we hit the maximum. */
430 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
431 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
434 /* Signature button: */
435 if (!self->button_signature)
436 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
437 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
438 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
439 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
440 gtk_widget_show (self->button_signature);
441 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
442 gtk_widget_show (caption);
444 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
445 G_CALLBACK (on_button_signature), self);
447 gtk_widget_show (GTK_WIDGET (box));
449 return GTK_WIDGET (box);
452 /** Change the caption title for the incoming server,
453 * as specified in the UI spec:
455 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestProtocol protocol)
458 (protocol == MODEST_PROTOCOL_STORE_POP ?
459 _("mail_fi_emailtype_pop3") :
460 _("mail_fi_emailtype_imap") );
463 /* Note that this produces a compiler warning,
464 * because the compiler does not know that the translated string will have a %s in it.
465 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
466 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
467 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
468 g_free(incomingserver_title);
471 /** Change the caption title for the incoming server,
472 * as specified in the UI spec:
474 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestProtocol protocol)
476 /* Fill the combo with appropriately titled choices for POP or IMAP. */
477 /* The choices are the same, but the titles are different, as in the UI spec. */
478 modest_serversecurity_combo_box_fill (
479 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
482 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
484 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
486 /* Create a size group to be used by all captions.
487 * Note that HildonCaption does not create a default size group if we do not specify one.
488 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
489 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
491 /* The incoming server widgets: */
492 if(!self->entry_incomingserver)
493 self->entry_incomingserver = gtk_entry_new ();
494 /* Auto-capitalization is the default, so let's turn it off: */
495 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
497 if (self->caption_incoming)
498 gtk_widget_destroy (self->caption_incoming);
500 /* The caption title will be updated in update_incoming_server_title().
501 * so this default text will never be seen: */
502 /* (Note: Changing the title seems pointless. murrayc) */
503 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
504 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
505 gtk_widget_show (self->entry_incomingserver);
506 connect_for_modified (self, self->entry_incomingserver);
507 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
508 gtk_widget_show (self->caption_incoming);
510 /* The secure connection widgets: */
511 /* This will be filled by update_incoming_server_security_choices(). */
512 if (!self->combo_incoming_security)
513 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
514 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
515 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
516 gtk_widget_show (self->combo_incoming_security);
517 connect_for_modified (self, self->combo_incoming_security);
518 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
519 gtk_widget_show (caption);
521 /* Show a default port number when the security method changes, as per the UI spec: */
522 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
525 /* The port widgets: */
526 /* TODO: There are various rules about this in the UI spec. */
527 if (!self->entry_incoming_port)
528 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
529 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
530 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
531 gtk_widget_show (self->entry_incoming_port);
532 connect_for_modified (self, self->entry_incoming_port);
533 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
534 gtk_widget_show (caption);
536 /* The secure authentication widgets: */
537 if(!self->checkbox_incoming_auth)
538 self->checkbox_incoming_auth = gtk_check_button_new ();
539 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
540 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
541 gtk_widget_show (self->checkbox_incoming_auth);
542 connect_for_modified (self, self->checkbox_incoming_auth);
543 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
544 gtk_widget_show (caption);
546 gtk_widget_show (GTK_WIDGET (box));
548 return GTK_WIDGET (box);
552 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
554 GtkWidget *widget = GTK_WIDGET (user_data);
556 /* Enable the widget only if the toggle button is active: */
557 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
558 gtk_widget_set_sensitive (widget, enable);
561 /* Make the sensitivity of a widget depend on a toggle button.
564 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
566 g_signal_connect (G_OBJECT (button), "toggled",
567 G_CALLBACK (on_toggle_button_changed), widget);
569 /* Set the starting sensitivity: */
570 on_toggle_button_changed (button, widget);
574 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
576 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
578 /* Create the window if necessary: */
579 if (!(self->specific_window)) {
580 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
581 modest_connection_specific_smtp_window_fill_with_connections (
582 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
586 /* Show the window: */
587 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
588 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
589 gtk_widget_show (self->specific_window);
593 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
595 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
597 ModestProtocol protocol_security =
598 modest_secureauth_combo_box_get_active_secureauth (
599 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
600 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
602 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
603 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
607 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
609 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
611 const gint port_number =
612 modest_serversecurity_combo_box_get_active_serversecurity_port (
613 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
615 if(port_number != 0) {
616 hildon_number_editor_set_value (
617 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
622 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
624 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
626 const gint port_number =
627 modest_serversecurity_combo_box_get_active_serversecurity_port (
628 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
630 if(port_number != 0) {
631 hildon_number_editor_set_value (
632 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
637 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
639 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
641 /* Create a size group to be used by all captions.
642 * Note that HildonCaption does not create a default size group if we do not specify one.
643 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
644 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
646 /* The outgoing server widgets: */
647 if (!self->entry_outgoingserver)
648 self->entry_outgoingserver = gtk_entry_new ();
649 /* Auto-capitalization is the default, so let's turn it off: */
650 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
651 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
652 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
653 gtk_widget_show (self->entry_outgoingserver);
654 connect_for_modified (self, self->entry_outgoingserver);
655 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
656 gtk_widget_show (caption);
658 /* The secure authentication widgets: */
659 if (!self->combo_outgoing_auth)
660 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
661 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
662 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
663 gtk_widget_show (self->combo_outgoing_auth);
664 connect_for_modified (self, self->combo_outgoing_auth);
665 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
666 gtk_widget_show (caption);
668 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
669 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
671 /* The username widgets: */
672 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
673 /* Auto-capitalization is the default, so let's turn it off: */
674 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
675 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
676 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
677 gtk_widget_show (self->entry_outgoing_username);
678 connect_for_modified (self, self->entry_outgoing_username);
679 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
680 gtk_widget_show (self->caption_outgoing_username);
682 /* Prevent the use of some characters in the username,
683 * as required by our UI specification: */
684 modest_validating_entry_set_unallowed_characters_whitespace (
685 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
687 /* Set max length as in the UI spec:
688 * The UI spec seems to want us to show a dialog if we hit the maximum. */
689 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
690 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
693 /* The password widgets: */
694 self->entry_outgoing_password = gtk_entry_new ();
695 /* Auto-capitalization is the default, so let's turn it off: */
696 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
697 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
698 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
699 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
700 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
701 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
702 gtk_widget_show (self->entry_outgoing_password);
703 connect_for_modified (self, self->entry_outgoing_password);
704 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
705 gtk_widget_show (self->caption_outgoing_password);
707 /* The secure connection widgets: */
708 /* This will be filled and set with modest_serversecurity_combo_box_fill()
709 * and modest_serversecurity_combo_box_set_active_serversecurity().
711 if (!self->combo_outgoing_security)
712 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
713 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
714 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
715 gtk_widget_show (self->combo_outgoing_security);
716 connect_for_modified (self, self->combo_outgoing_security);
717 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
718 gtk_widget_show (caption);
720 /* Show a default port number when the security method changes, as per the UI spec: */
721 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
723 /* The port widgets: */
724 if (!self->entry_outgoing_port)
725 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
726 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
727 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
728 gtk_widget_show (self->entry_outgoing_port);
729 connect_for_modified (self, self->entry_outgoing_port);
730 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
731 gtk_widget_show (caption);
733 GtkWidget *separator = gtk_hseparator_new ();
734 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
735 gtk_widget_show (separator);
737 /* connection-specific checkbox: */
738 if (!self->checkbox_outgoing_smtp_specific) {
739 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
740 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
743 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
744 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
745 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
746 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
747 gtk_widget_show (caption);
748 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
750 /* Connection-specific SMTP-Severs Edit button: */
751 if (!self->button_outgoing_smtp_servers)
752 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
753 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
754 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
755 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
756 gtk_widget_show (self->button_outgoing_smtp_servers);
757 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
758 gtk_widget_show (caption);
760 /* Only enable the button when the checkbox is checked: */
761 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
762 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
764 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
765 G_CALLBACK (on_button_outgoing_smtp_servers), self);
768 gtk_widget_show (GTK_WIDGET (box));
770 return GTK_WIDGET (box);
774 check_data (ModestAccountSettingsDialog *self)
776 /* Check that the title is not already in use: */
777 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
778 if ((!account_title) || (strlen(account_title) == 0))
779 return FALSE; /* Should be prevented already anyway. */
781 if (strcmp(account_title, self->original_account_title) != 0) {
782 /* Check the changed title: */
783 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
787 /* Warn the user via a dialog: */
788 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
794 /* Check that the email address is valud: */
795 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
796 if ((!email_address) || (strlen(email_address) == 0))
799 if (!modest_text_utils_validate_email_address (email_address)) {
800 /* Warn the user via a dialog: */
801 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
803 /* Return focus to the email address entry: */
804 gtk_widget_grab_focus (self->entry_user_email);
809 /* TODO: The UI Spec wants us to check that the servernames are valid,
810 * but does not specify how.
818 on_response (GtkDialog *wizard_dialog,
822 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
823 enable_buttons (self);
825 gboolean prevent_response = FALSE;
827 /* Warn about unsaved changes: */
828 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
829 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
830 _("imum_nc_wizard_confirm_lose_changes")));
831 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
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 (response_id != GTK_RESPONSE_CANCEL && !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");
851 if (response_id == GTK_RESPONSE_OK) {
852 /* Try to save the changes: */
853 const gboolean saved = save_configuration (self);
855 /* Do not show the account-saved dialog if we are just saving this
856 * temporarily, because from the user's point of view it will not
857 * really be saved (saved + enabled) until later.
859 const gboolean enabled =
860 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
862 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
865 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
870 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
872 /* Create the notebook to be used by the GtkDialog base class:
873 * Each page of the notebook will be a page of the wizard: */
874 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
877 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
879 /* Get the account manager object,
880 * so we can check for existing accounts,
881 * and create new accounts: */
882 self->account_manager = modest_runtime_get_account_mgr ();
883 g_assert (self->account_manager);
884 g_object_ref (self->account_manager);
886 /* Create the common pages,
888 self->page_account_details = create_page_account_details (self);
889 self->page_user_details = create_page_user_details (self);
890 self->page_incoming = create_page_incoming (self);
891 self->page_outgoing = create_page_outgoing (self);
893 /* Add the notebook pages: */
894 gtk_notebook_append_page (notebook, self->page_account_details,
895 gtk_label_new (_("mcen_ti_account_settings_account")));
896 gtk_notebook_append_page (notebook, self->page_user_details,
897 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
898 gtk_notebook_append_page (notebook, self->page_incoming,
899 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
900 gtk_notebook_append_page (notebook, self->page_outgoing,
901 gtk_label_new (_("mcen_ti_advsetup_sending")));
903 GtkDialog *dialog = GTK_DIALOG (self);
904 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
905 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
906 gtk_widget_show (GTK_WIDGET (notebook));
908 /* Add the buttons: */
909 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
910 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
912 /* Connect to the dialog's response signal: */
913 /* We use connect-before
914 * so we can stop the signal emission,
915 * to stop the default signal handler from closing the dialog.
917 g_signal_connect (G_OBJECT (self), "response",
918 G_CALLBACK (on_response), self);
920 self->modified = FALSE;
922 /* When this window is shown, hibernation should not be possible,
923 * because there is no sensible way to save the state: */
924 modest_window_mgr_prevent_hibernation_while_window_is_shown (
925 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
928 ModestAccountSettingsDialog*
929 modest_account_settings_dialog_new (void)
931 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
934 /** Update the UI with the stored account details, so they can be edited.
935 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
937 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
942 /* Save the account name so we can refer to it later: */
943 if (dialog->account_name)
944 g_free (dialog->account_name);
945 dialog->account_name = g_strdup (account_name);
948 /* Get the account data for this account name: */
949 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
952 g_printerr ("modest: failed to get account data for %s\n", account_name);
956 /* Save the account title so we can refer to it if the user changes it: */
957 if (dialog->original_account_title)
958 g_free (dialog->original_account_title);
959 dialog->original_account_title = g_strdup (account_data->display_name);
962 if (!(account_data->store_account)) {
963 g_printerr ("modest: account has no stores: %s\n", account_name);
967 /* Show the account data in the widgets: */
969 /* Note that we never show the non-display name in the UI.
970 * (Though the display name defaults to the non-display name at the start.) */
971 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
972 account_data->display_name ? account_data->display_name : "");
974 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
975 account_data->fullname ? account_data->fullname : "");
976 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
977 account_data->email ? account_data->email : "");
979 ModestServerAccountData *incoming_account = account_data->store_account;
981 if (incoming_account)
982 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
983 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
984 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
986 /* Default to something, though no default is specified in the UI spec: */
987 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
989 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
992 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
993 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
994 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
997 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
998 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
999 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1001 /* Only show the leave-on-server checkbox for POP,
1002 * as per the UI spec: */
1003 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1004 gtk_widget_hide (dialog->checkbox_leave_messages);
1006 gtk_widget_show (dialog->checkbox_leave_messages);
1009 if (incoming_account) {
1010 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1011 incoming_account->username ? incoming_account->username : "");
1012 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1013 incoming_account->password ? incoming_account->password : "");
1015 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1016 incoming_account->hostname ? incoming_account->hostname : "");
1018 /* The UI spec says:
1019 * If secure authentication is unchecked, allow sending username and password also as plain text.
1020 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1021 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1023 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
1024 dialog->account_manager, incoming_account->account_name);
1025 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1026 secure_auth != MODEST_PROTOCOL_AUTH_PASSWORD);
1027 /* Note that MODEST_PROTOCOL_AUTH_PLAIN should probably never be used. */
1029 update_incoming_server_title (dialog, incoming_account->proto);
1030 update_incoming_server_security_choices (dialog, incoming_account->proto);
1032 const ModestProtocol security = modest_server_account_get_security (
1033 dialog->account_manager, incoming_account->account_name);
1034 modest_serversecurity_combo_box_set_active_serversecurity (
1035 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1037 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1038 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1039 hildon_number_editor_set_value (
1040 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1044 ModestServerAccountData *outgoing_account = account_data->transport_account;
1045 if (outgoing_account) {
1046 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1047 outgoing_account->hostname ? outgoing_account->hostname : "");
1049 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1050 outgoing_account->username ? outgoing_account->username : "");
1051 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1052 outgoing_account->password ? outgoing_account->password : "");
1054 /* Get the secure-auth setting: */
1055 const ModestProtocol secure_auth = modest_server_account_get_secure_auth(
1056 dialog->account_manager, outgoing_account->account_name);
1057 modest_secureauth_combo_box_set_active_secureauth (
1058 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1059 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1061 modest_serversecurity_combo_box_fill (
1062 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1064 /* Get the security setting: */
1065 const ModestProtocol security = modest_server_account_get_security (
1066 dialog->account_manager, outgoing_account->account_name);
1067 modest_serversecurity_combo_box_set_active_serversecurity (
1068 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1070 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1071 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1072 hildon_number_editor_set_value (
1073 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1076 /* account_data->is_enabled, */
1077 /*account_data->is_default, */
1079 /* account_data->store_account->proto */
1081 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1083 /* Unset the modified flag so we can detect changes later: */
1084 dialog->modified = FALSE;
1088 save_configuration (ModestAccountSettingsDialog *dialog)
1090 g_assert (dialog->account_name);
1092 const gchar* account_name = dialog->account_name;
1094 /* Set the account data from the widgets: */
1095 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1096 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1097 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1101 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1102 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1103 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1108 if (dialog->signature_dialog) {
1109 gboolean use_signature = FALSE;
1110 gchar *signature = modest_signature_editor_dialog_get_settings (
1111 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1114 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1115 signature, use_signature);
1119 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1120 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1121 modest_account_mgr_set_string (dialog->account_manager, account_name,
1122 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1125 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1126 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1127 modest_account_mgr_set_int (dialog->account_manager, account_name,
1128 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1130 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1131 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1132 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1137 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1138 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1139 g_assert (incoming_account_name);
1141 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1142 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1143 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1147 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1148 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1150 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1151 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1153 /* The UI spec says:
1154 * If secure authentication is unchecked, allow sending username and password also as plain text.
1155 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1156 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1158 const ModestProtocol protocol_authentication_incoming = gtk_toggle_button_get_active
1159 (GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))
1160 ? MODEST_PROTOCOL_AUTH_CRAMMD5
1161 : MODEST_PROTOCOL_AUTH_PASSWORD;
1162 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1164 const ModestProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1165 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1166 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1169 gint port_num = hildon_number_editor_get_value (
1170 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1171 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1172 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1174 g_free (incoming_account_name);
1177 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1178 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1179 g_assert (outgoing_account_name);
1181 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1182 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1183 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1187 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1188 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1191 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1192 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1195 const ModestProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1196 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1197 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1199 const ModestProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1200 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1201 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1204 port_num = hildon_number_editor_get_value (
1205 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1206 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1207 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1209 g_free (outgoing_account_name);
1212 /* Set the changed account title last, to simplify the previous code: */
1213 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1214 if ((!account_title) || (strlen(account_title) == 0))
1215 return FALSE; /* Should be prevented already anyway. */
1217 if (strcmp(account_title, account_name) != 0) {
1218 /* Change the title: */
1219 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1220 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1225 /* Save connection-specific SMTP server accounts: */
1226 if (dialog->specific_window)
1227 return modest_connection_specific_smtp_window_save_server_accounts (
1228 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1233 static gboolean entry_is_empty (GtkWidget *entry)
1238 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1239 if ((!text) || (strlen(text) == 0))
1246 enable_buttons (ModestAccountSettingsDialog *self)
1248 gboolean enable_ok = TRUE;
1250 /* The account details title is mandatory: */
1251 if (entry_is_empty(self->entry_account_title))
1254 /* The user details username is mandatory: */
1255 if (entry_is_empty(self->entry_user_username))
1258 /* The user details email address is mandatory: */
1259 if (enable_ok && entry_is_empty (self->entry_user_email))
1262 /* The custom incoming server is mandatory: */
1263 if (entry_is_empty(self->entry_incomingserver))
1266 /* Enable the buttons,
1267 * identifying them via their associated response codes:
1269 GtkDialog *dialog_base = GTK_DIALOG (self);
1270 gtk_dialog_set_response_sensitive (dialog_base,
1276 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1278 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1279 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1282 object_class->get_property = modest_account_settings_dialog_get_property;
1283 object_class->set_property = modest_account_settings_dialog_set_property;
1284 object_class->dispose = modest_account_settings_dialog_dispose;
1285 object_class->finalize = modest_account_settings_dialog_finalize;
1289 show_error (GtkWindow *parent_window, const gchar* text)
1291 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1293 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1300 gtk_dialog_run (dialog);
1301 gtk_widget_destroy (GTK_WIDGET (dialog));
1305 show_ok (GtkWindow *parent_window, const gchar* text)
1307 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1309 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1316 gtk_dialog_run (dialog);
1317 gtk_widget_destroy (GTK_WIDGET (dialog));