1 /* Copyright (c) 2008, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <glib/gi18n.h>
32 #include <gtk/gtkvbox.h>
33 #include <gtk/gtklabel.h>
34 #include <gtk/gtkentry.h>
35 #include <gtk/gtkbutton.h>
36 #include <gtk/gtkmessagedialog.h>
37 #include <gtk/gtkstock.h>
38 #include "modest-default-account-settings-dialog.h"
39 #include "modest-account-mgr.h"
40 #include "widgets/modest-validating-entry.h"
41 #include "modest-text-utils.h"
42 #include "modest-account-mgr.h"
43 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
44 #include <modest-server-account-settings.h>
45 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
46 #include "modest-connection-specific-smtp-window.h"
47 #include "modest-signature-editor-dialog.h"
48 #include <modest-utils.h>
49 #include <modest-defs.h>
50 #include "modest-ui-actions.h"
51 #include "widgets/modest-ui-constants.h"
52 #include <tny-account.h>
53 #include <tny-status.h>
54 #include <modest-scrollable.h>
55 #include <modest-toolkit-factory.h>
56 #include <modest-toolkit-utils.h>
58 #include <gconf/gconf-client.h>
59 #include <string.h> /* For strlen(). */
61 #ifdef MODEST_TOOLKIT_HILDON2
62 #include <hildon/hildon.h>
66 /* Include config.h so that _() works: */
72 #define PORT_MAX 65535
74 #define RESPONSE_DELETE_DUMMY 1
75 #define RESPONSE_SIGNATURE_DUMMY 2
77 static void modest_account_settings_dialog_init (gpointer g, gpointer iface_data);
79 G_DEFINE_TYPE_EXTENDED (ModestDefaultAccountSettingsDialog,
80 modest_default_account_settings_dialog,
83 G_IMPLEMENT_INTERFACE (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG,
84 modest_account_settings_dialog_init));
86 #define MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
87 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, ModestDefaultAccountSettingsDialogPrivate))
89 typedef struct _ModestDefaultAccountSettingsDialogPrivate ModestDefaultAccountSettingsDialogPrivate;
91 struct _ModestDefaultAccountSettingsDialogPrivate
93 /* Used by derived widgets to query existing accounts,
94 * and to create new accounts: */
95 ModestAccountMgr *account_manager;
96 ModestAccountSettings *settings;
99 gchar * account_name; /* This may not change. It is not user visible. */
100 ModestProtocolType incoming_protocol; /* This may not change. */
101 ModestProtocolType outgoing_protocol; /* This may not change. */
102 gchar * original_account_title;
104 ModestProtocolType protocol_authentication_incoming;
106 GtkWidget *main_container;
108 GtkWidget *page_account_details;
109 GtkWidget *entry_account_title;
110 GtkWidget *checkbox_leave_messages;
112 GtkWidget *page_user_details;
113 GtkWidget *entry_user_name;
114 GtkWidget *entry_user_username;
115 GtkWidget *entry_user_password;
116 GtkWidget *entry_user_email;
117 GtkWidget *button_signature;
118 GtkWidget *button_delete;
120 GtkWidget *page_complete_easysetup;
122 GtkWidget *page_incoming;
123 GtkWidget *caption_incoming;
124 GtkWidget *entry_incomingserver;
126 GtkWidget *page_outgoing;
127 GtkWidget *entry_outgoingserver;
128 GtkWidget *checkbox_outgoing_smtp_specific;
129 GtkWidget *button_outgoing_smtp_servers;
131 GtkWidget *signature_dialog;
133 GtkWidget *incoming_security;
134 GtkWidget *outgoing_security;
138 enable_buttons (ModestDefaultAccountSettingsDialog *self);
141 save_configuration (ModestDefaultAccountSettingsDialog *dialog);
143 static void on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
147 static const gchar * null_means_empty (const gchar * str);
150 null_means_empty (const gchar * str)
152 return str ? str : "";
156 modest_default_account_settings_dialog_dispose (GObject *object)
158 if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
159 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
163 modest_default_account_settings_dialog_finalize (GObject *object)
165 ModestDefaultAccountSettingsDialog *self;
166 ModestDefaultAccountSettingsDialogPrivate *priv;
168 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
169 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
171 if (priv->account_name)
172 g_free (priv->account_name);
174 if (priv->original_account_title)
175 g_free (priv->original_account_title);
177 if (priv->account_manager)
178 g_object_unref (G_OBJECT (priv->account_manager));
180 if (priv->settings) {
181 g_object_unref (priv->settings);
182 priv->settings = NULL;
185 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
189 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
191 ModestDefaultAccountSettingsDialogPrivate *priv;
193 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
194 priv->modified = modified;
197 #ifdef MODEST_TOOLKIT_HILDON2
199 on_modified_picker_changed (GtkWidget *widget, gpointer user_data)
201 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
206 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
208 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
212 on_modified_checkbutton_toggled (GtkWidget *button, gpointer user_data)
214 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
218 on_modified_number_entry_changed (GtkWidget *number_entry, gint new_value, gpointer user_data)
220 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
224 on_number_entry_notify (GtkWidget *entry, GParamSpec *arg1, gpointer user_data)
226 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
227 gint value = modest_number_entry_get_value (entry);
229 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
232 /* Set a modified boolean whenever the widget is changed,
233 * so we can check for it later.
236 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
238 if (modest_is_number_entry (widget)) {
239 g_signal_connect (G_OBJECT (widget), "notify::value",
240 G_CALLBACK (on_modified_number_entry_changed), self);
241 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_entry_notify), self);
243 else if (GTK_IS_ENTRY (widget)) {
244 g_signal_connect (G_OBJECT (widget), "changed",
245 G_CALLBACK (on_modified_entry_changed), self);
246 #ifdef MODEST_TOOLKIT_HILDON2
247 } else if (HILDON_IS_PICKER_BUTTON (widget)) {
248 g_signal_connect (G_OBJECT (widget), "value-changed",
249 G_CALLBACK (on_modified_picker_changed), self);
251 } else if (modest_is_togglable (widget)) {
252 g_signal_connect (G_OBJECT (widget), "toggled",
253 G_CALLBACK (on_modified_checkbutton_toggled), self);
258 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
260 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
262 enable_buttons(self);
266 create_captioned (ModestDefaultAccountSettingsDialog *self,
267 GtkSizeGroup *title_sizegroup,
268 GtkSizeGroup *value_sizegroup,
269 const gchar *label_text,
276 result = modest_toolkit_utils_create_captioned_with_size_type (title_sizegroup, value_sizegroup,
277 label_text, use_markup, control,
278 MODEST_EDITABLE_SIZE);
280 /* Connect to the appropriate changed signal for the widget,
281 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
283 if (GTK_IS_ENTRY (control)) {
284 g_signal_connect (G_OBJECT (control), "changed",
285 G_CALLBACK (on_caption_entry_changed), self);
293 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
297 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
298 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
300 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
307 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
311 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
312 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
314 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
322 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
324 modest_platform_information_banner (GTK_WIDGET (self), NULL,
325 _CS("ckdg_ib_maximum_characters_reached"));
329 create_page_account_details (ModestDefaultAccountSettingsDialog *self,
330 GtkSizeGroup *title_sizegroup,
331 GtkSizeGroup *value_sizegroup)
333 ModestDefaultAccountSettingsDialogPrivate *priv;
337 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
338 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
340 /* The description widgets: */
341 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
342 /* Do use auto-capitalization: */
344 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
345 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
347 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
348 _("mcen_fi_account_title"), FALSE,
349 priv->entry_account_title);
350 gtk_widget_show (priv->entry_account_title);
351 connect_for_modified (self, priv->entry_account_title);
352 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
353 gtk_widget_show (caption);
355 /* Prevent the use of some characters in the account title,
356 * as required by our UI specification: */
357 GList *list_prevent = NULL;
358 list_prevent = g_list_append (list_prevent, "\\");
359 list_prevent = g_list_append (list_prevent, "/");
360 list_prevent = g_list_append (list_prevent, ":");
361 list_prevent = g_list_append (list_prevent, "*");
362 list_prevent = g_list_append (list_prevent, "?");
363 list_prevent = g_list_append (list_prevent, "\"");
364 list_prevent = g_list_append (list_prevent, "<");
365 list_prevent = g_list_append (list_prevent, ">");
366 list_prevent = g_list_append (list_prevent, "|");
367 list_prevent = g_list_append (list_prevent, "^");
368 modest_validating_entry_set_unallowed_characters (
369 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
370 g_list_free (list_prevent);
371 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
372 on_entry_invalid_account_title_character, self);
374 /* Set max length as in the UI spec:
375 * The UI spec seems to want us to show a dialog if we hit the maximum. */
376 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
377 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
380 hbox = gtk_hbox_new (TRUE, 0);
382 /* The leave-messages widgets: */
383 if(!priv->checkbox_leave_messages) {
384 priv->checkbox_leave_messages =
385 modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
386 _("mcen_fi_advsetup_leave_on_server"));
388 connect_for_modified (self, priv->checkbox_leave_messages);
389 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_leave_messages, FALSE, FALSE, 0);
390 gtk_widget_show (priv->checkbox_leave_messages);
392 gtk_widget_show (GTK_WIDGET (box));
394 return GTK_WIDGET (box);
398 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
400 ModestDefaultAccountSettingsDialogPrivate *priv;
401 const gchar* account_title;
403 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
404 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
406 if (!account_title || (strlen (account_title) == 0))
409 /* Strip it of whitespace at the start and end: */
410 gchar *result = g_strdup (account_title);
411 result = g_strstrip (result);
416 if (strlen (result) == 0) {
427 signature_button_clicked (ModestDefaultAccountSettingsDialog *self)
430 ModestDefaultAccountSettingsDialogPrivate *priv;
432 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
434 /* Create the window, if necessary: */
435 if (!(priv->signature_dialog)) {
436 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
438 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
439 const gchar *signature = modest_account_settings_get_signature(priv->settings);
440 gchar* account_title = get_entered_account_title (self);
441 modest_signature_editor_dialog_set_settings (
442 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
443 use_signature, signature, account_title);
445 g_free (account_title);
446 account_title = NULL;
450 /* Show the window: */
451 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
452 GTK_WINDOW (priv->signature_dialog), GTK_WINDOW (self));
454 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
455 gtk_widget_hide (priv->signature_dialog);
456 if (response != GTK_RESPONSE_OK) {
457 /* Destroy the widget now, and its data: */
458 gtk_widget_destroy (priv->signature_dialog);
459 priv->signature_dialog = NULL;
461 /* Mark modified, so we use the dialog's data later: */
462 priv->modified = TRUE;
467 delete_button_clicked (ModestDefaultAccountSettingsDialog *self)
469 ModestDefaultAccountSettingsDialogPrivate *priv;
470 gchar *account_title;
473 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
476 account_title = g_strdup (priv->original_account_title);
478 account_title = get_entered_account_title (self);
480 removed = modest_ui_actions_on_delete_account (GTK_WINDOW (self),
482 (const gchar *) account_title);
483 g_free (account_title);
489 create_page_user_details (ModestDefaultAccountSettingsDialog *self,
490 GtkSizeGroup *title_sizegroup,
491 GtkSizeGroup *value_sizegroup)
493 ModestDefaultAccountSettingsDialogPrivate *priv;
496 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
498 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
500 /* The name widgets: */
501 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
503 /* Auto-capitalization is the default, so let's turn it off: */
505 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
506 HILDON_GTK_INPUT_MODE_FULL |
507 HILDON_GTK_INPUT_MODE_AUTOCAP);
509 /* Set max length as in the UI spec:
510 * The UI spec seems to want us to show a dialog if we hit the maximum. */
511 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
512 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
515 create_captioned (self, title_sizegroup, value_sizegroup,
516 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
517 gtk_widget_show (priv->entry_user_name);
518 connect_for_modified (self, priv->entry_user_name);
519 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
520 gtk_widget_show (caption);
523 /* Prevent the use of some characters in the name,
524 * as required by our UI specification: */
525 GList *list_prevent = NULL;
526 list_prevent = g_list_append (list_prevent, "<");
527 list_prevent = g_list_append (list_prevent, ">");
528 modest_validating_entry_set_unallowed_characters (
529 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
530 g_list_free (list_prevent);
531 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
532 on_entry_invalid_fullname_character, self);
534 /* The username widgets: */
535 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
536 /* Auto-capitalization is the default, so let's turn it off: */
538 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
540 caption = create_captioned (self, title_sizegroup, value_sizegroup,
541 _("mail_fi_username"), FALSE,
542 priv->entry_user_username);
543 gtk_widget_show (priv->entry_user_username);
544 connect_for_modified (self, priv->entry_user_username);
545 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
546 gtk_widget_show (caption);
548 /* Prevent the use of some characters in the username,
549 * as required by our UI specification: */
550 modest_validating_entry_set_unallowed_characters_whitespace (
551 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
552 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
553 modest_utils_on_entry_invalid_character,
556 /* Set max length as in the UI spec:
557 * The UI spec seems to want us to show a dialog if we hit the maximum. */
558 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
559 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
562 /* The password widgets: */
563 priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
564 /* Auto-capitalization is the default, so let's turn it off: */
566 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
567 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
569 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
570 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
571 caption = create_captioned (self, title_sizegroup, value_sizegroup,
572 _("mail_fi_password"), FALSE, priv->entry_user_password);
573 gtk_widget_show (priv->entry_user_password);
574 connect_for_modified (self, priv->entry_user_password);
575 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
576 gtk_widget_show (caption);
578 /* The email address widgets: */
579 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
580 /* Auto-capitalization is the default, so let's turn it off: */
582 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
584 caption = create_captioned (self, title_sizegroup, value_sizegroup,
585 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
586 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
587 gtk_widget_show (priv->entry_user_email);
588 connect_for_modified (self, priv->entry_user_email);
589 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
590 gtk_widget_show (caption);
592 /* Set max length as in the UI spec:
593 * The UI spec seems to want us to show a dialog if we hit the maximum. */
594 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
595 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
599 if (!priv->button_delete)
600 priv->button_delete = gtk_dialog_add_button (GTK_DIALOG (self),
602 RESPONSE_DELETE_DUMMY);
604 /* Signature button: */
605 if (!priv->button_signature)
606 priv->button_signature = gtk_dialog_add_button (GTK_DIALOG (self),
607 _("mcen_bd_email_signature"),
608 RESPONSE_SIGNATURE_DUMMY);
609 gtk_widget_show (priv->button_signature);
611 gtk_widget_show (GTK_WIDGET (box));
613 return GTK_WIDGET (box);
616 /* Change the caption title for the incoming server */
618 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
619 ModestProtocolType protocol_type)
621 ModestProtocolRegistry *protocol_registry;
622 ModestProtocol *protocol;
623 const gchar *protocol_display_name;
624 gchar* incomingserver_title;
625 ModestDefaultAccountSettingsDialogPrivate *priv;
627 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
629 protocol_registry = modest_runtime_get_protocol_registry ();
630 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
631 protocol_display_name = modest_protocol_get_display_name (protocol);
632 incomingserver_title = g_strconcat(_("mcen_li_emailsetup_servertype"), "*",
633 "\n<small>(", protocol_display_name, ")</small>", NULL);
635 modest_toolkit_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
636 g_free (incomingserver_title);
639 /* The size groups passed as arguments are only used by the security settings */
641 create_page_incoming (ModestDefaultAccountSettingsDialog *self,
642 GtkSizeGroup *security_title_sizegroup,
643 GtkSizeGroup *security_value_sizegroup)
645 ModestDefaultAccountSettingsDialogPrivate *priv;
648 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
650 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
652 /* The incoming server widgets: */
653 if(!priv->entry_incomingserver)
654 priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
655 /* Auto-capitalization is the default, so let's turn it off: */
657 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
660 if (priv->caption_incoming)
661 gtk_widget_destroy (priv->caption_incoming);
663 /* The caption title will be updated in update_incoming_server_title().
664 * so this default text will never be seen: */
665 /* (Note: Changing the title seems pointless. murrayc) */
666 priv->caption_incoming = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
667 "Incoming Server", FALSE, priv->entry_incomingserver);
668 gtk_widget_show (priv->entry_incomingserver);
669 connect_for_modified (self, priv->entry_incomingserver);
670 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
671 gtk_widget_show (priv->caption_incoming);
673 /* Incoming security widgets */
674 priv->incoming_security =
675 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
676 MODEST_SECURITY_OPTIONS_INCOMING,
677 TRUE, security_title_sizegroup,
678 security_value_sizegroup);
679 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
682 gtk_widget_show (priv->incoming_security);
683 gtk_widget_show (GTK_WIDGET (box));
684 g_signal_connect (priv->incoming_security, "missing-mandatory-data",
685 G_CALLBACK (on_missing_mandatory_data), self);
687 return GTK_WIDGET (box);
691 on_check_button_clicked (GtkWidget *button, gpointer user_data)
693 GtkWidget *widget = GTK_WIDGET (user_data);
695 /* Enable the widget only if the check button is active: */
696 const gboolean enable = modest_togglable_get_active (button);
697 gtk_widget_set_sensitive (widget, enable);
700 /* Make the sensitivity of a widget depend on a check button.
703 enable_widget_for_checkbutton (GtkWidget *widget, GtkWidget* button)
705 g_signal_connect (G_OBJECT (button), "clicked",
706 G_CALLBACK (on_check_button_clicked), widget);
708 /* Set the starting sensitivity: */
709 on_check_button_clicked (button, widget);
713 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
715 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
716 ModestConnectionSpecificSmtpWindow *smtp_win;
717 ModestDefaultAccountSettingsDialogPrivate *priv;
719 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
721 /* Create the window if necessary: */
722 smtp_win = modest_connection_specific_smtp_window_new ();
723 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
725 /* Show the window: */
726 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win), GTK_WINDOW (self));
727 gtk_widget_show (GTK_WIDGET (smtp_win));
731 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
735 /* Disable the OK button */
736 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
742 create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
743 GtkSizeGroup *security_title_sizegroup,
744 GtkSizeGroup *security_value_sizegroup)
746 ModestDefaultAccountSettingsDialogPrivate *priv;
747 gchar *smtp_caption_label;
748 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
750 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
752 /* The outgoing server widgets: */
753 if (!priv->entry_outgoingserver)
754 priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
755 /* Auto-capitalization is the default, so let's turn it off: */
757 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
759 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
760 GtkWidget *caption = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
761 smtp_caption_label, TRUE, priv->entry_outgoingserver);
762 g_free (smtp_caption_label);
763 gtk_widget_show (priv->entry_outgoingserver);
764 connect_for_modified (self, priv->entry_outgoingserver);
765 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
766 gtk_widget_show (caption);
768 /* Outgoing security widgets */
769 priv->outgoing_security =
770 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
771 MODEST_SECURITY_OPTIONS_OUTGOING,
772 TRUE, security_title_sizegroup,
773 security_value_sizegroup);
774 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
776 gtk_widget_show (priv->outgoing_security);
777 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
778 G_CALLBACK (on_missing_mandatory_data), self);
780 GtkWidget *separator = gtk_hseparator_new ();
781 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_DEFAULT);
783 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
785 gtk_widget_show (separator);
787 /* connection-specific checkbox: */
788 if (!priv->checkbox_outgoing_smtp_specific) {
789 priv->checkbox_outgoing_smtp_specific =
790 modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
791 _("mcen_fi_advsetup_connection_smtp"));
792 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
795 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
796 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
798 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
800 /* Connection-specific SMTP-Severs Edit button: */
801 if (!priv->button_outgoing_smtp_servers)
802 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
804 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
805 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
807 gtk_widget_show (priv->button_outgoing_smtp_servers);
808 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers, FALSE, FALSE, 0);
810 /* Only enable the button when the checkbox is checked: */
811 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
812 priv->checkbox_outgoing_smtp_specific);
814 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
815 G_CALLBACK (on_button_outgoing_smtp_servers), self);
817 gtk_widget_show (GTK_WIDGET (box));
819 return GTK_WIDGET (box);
823 check_data (ModestDefaultAccountSettingsDialog *self)
825 gchar* account_title;
826 const gchar* email_address;
827 const gchar* hostname;
828 const gchar* hostname2;
829 ModestDefaultAccountSettingsDialogPrivate *priv;
831 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
833 /* Check that the title is not already in use: */
834 account_title = get_entered_account_title (self);
836 return FALSE; /* Should be prevented already anyway. */
838 if (g_strcmp0 (account_title, priv->original_account_title) != 0) {
839 gboolean name_in_use;
841 /* Check the changed title: */
842 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
846 /* Warn the user via a dialog: */
847 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
849 g_free (account_title);
854 g_free (account_title);
855 account_title = NULL;
857 /* Check that the email address is valid: */
858 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
859 if ((!email_address) || (strlen(email_address) == 0)) {
863 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
864 /* Warn the user via a dialog: */
865 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
867 /* Return focus to the email address entry: */
868 gtk_widget_grab_focus (priv->entry_user_email);
869 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
873 /* make sure the domain name for the incoming server is valid */
874 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
875 if ((!hostname) || (strlen(hostname) == 0)) {
879 if (!modest_text_utils_validate_domain_name (hostname)) {
880 /* Warn the user via a dialog: */
881 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
883 /* Return focus to the email address entry: */
884 gtk_widget_grab_focus (priv->entry_incomingserver);
885 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
889 /* make sure the domain name for the outgoing server is valid */
890 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
891 if ((!hostname2) || (strlen(hostname2) == 0)) {
895 if (!modest_text_utils_validate_domain_name (hostname2)) {
896 /* Warn the user via a dialog: */
897 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
899 /* Return focus to the email address entry: */
900 gtk_widget_grab_focus (priv->entry_outgoingserver);
901 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
909 on_delete_event (GtkWidget *widget,
913 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
914 ModestDefaultAccountSettingsDialogPrivate *priv;
915 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
917 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
919 /* Check if security widgets changed */
920 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
921 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
923 return modest_security_options_view_changed (incoming_sec, priv->settings) ||
924 modest_security_options_view_changed (outgoing_sec, priv->settings) ||
929 on_response (GtkDialog *wizard_dialog,
933 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
934 ModestDefaultAccountSettingsDialogPrivate *priv;
935 gboolean prevent_response = FALSE, sec_changed;
936 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
938 /* Dummy and delete buttons have a response id because they're
939 added with gtk_dialog_add_button in order to get the proper
941 if (response_id == RESPONSE_SIGNATURE_DUMMY) {
942 signature_button_clicked (self);
943 g_signal_stop_emission_by_name (wizard_dialog, "response");
947 if (response_id == RESPONSE_DELETE_DUMMY) {
948 if (!delete_button_clicked (self))
949 g_signal_stop_emission_by_name (wizard_dialog, "response");
953 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
954 enable_buttons (self);
956 /* Check if security widgets changed */
957 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
958 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
960 modest_security_options_view_changed (incoming_sec, priv->settings) ||
961 modest_security_options_view_changed (outgoing_sec, priv->settings);
963 /* Warn about unsaved changes: */
964 if ((response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) &&
965 (priv->modified || sec_changed)) {
966 gint dialog_response = modest_platform_run_confirmation_dialog (GTK_WINDOW (self),
967 _("imum_nc_wizard_confirm_lose_changes"));
968 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
971 if (dialog_response != GTK_RESPONSE_OK)
972 prevent_response = TRUE;
974 /* Check for invalid input: */
975 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
976 prevent_response = TRUE;
979 if (prevent_response) {
980 /* Don't let the dialog close */
981 g_signal_stop_emission_by_name (wizard_dialog, "response");
984 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
987 if (response_id == GTK_RESPONSE_OK) {
988 /* Try to save the changes if modified (NB #59251): */
989 if (priv->modified || sec_changed) {
990 if (save_configuration (self)) {
991 /* Do not show the account-saved dialog if we are just saving this
992 * temporarily, because from the user's point of view it will not
993 * really be saved (saved + enabled) until later
995 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
996 ModestServerAccountSettings *store_settings;
997 ModestServerAccountSettings *transport_settings;
998 const gchar *store_account_name;
999 const gchar *transport_account_name;
1002 store_settings = modest_account_settings_get_store_settings (priv->settings);
1003 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1004 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1005 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1007 if (store_account_name) {
1008 modest_account_mgr_notify_account_update (priv->account_manager,
1009 store_account_name);
1011 if (transport_account_name) {
1012 modest_account_mgr_notify_account_update (priv->account_manager,
1013 transport_account_name);
1015 g_object_unref (store_settings);
1016 g_object_unref (transport_settings);
1018 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1021 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1028 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1030 ModestDefaultAccountSettingsDialogPrivate *priv;
1031 GtkWidget *scrollable;
1032 GtkWidget *separator;
1034 GtkSizeGroup* account_title_sizegroup;
1035 GtkSizeGroup* account_value_sizegroup;
1036 GtkSizeGroup *sec_title_sizegroup, *sec_value_sizegroup;
1038 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1040 priv->incoming_security = NULL;
1041 priv->outgoing_security = NULL;
1043 priv->main_container = gtk_vbox_new (FALSE, 0);
1044 priv->settings = modest_account_settings_new ();
1046 /* Get the account manager object,
1047 * so we can check for existing accounts,
1048 * and create new accounts: */
1049 priv->account_manager = modest_runtime_get_account_mgr ();
1050 g_assert (priv->account_manager);
1051 g_object_ref (priv->account_manager);
1053 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1055 /* Create the common pages */
1056 account_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1057 account_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1058 priv->page_account_details = create_page_account_details (self, account_title_sizegroup, account_value_sizegroup);
1059 priv->page_user_details = create_page_user_details (self, account_title_sizegroup, account_value_sizegroup);
1060 g_object_unref (account_title_sizegroup);
1061 g_object_unref (account_value_sizegroup);
1064 /* Create size groups for security settings */
1065 sec_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1066 sec_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1068 /* Create incoming and outgoing "pages" */
1069 priv->page_incoming = create_page_incoming (self, sec_title_sizegroup, sec_value_sizegroup);
1070 priv->page_outgoing = create_page_outgoing (self, sec_title_sizegroup, sec_value_sizegroup);
1071 g_object_unref (sec_title_sizegroup);
1072 g_object_unref (sec_value_sizegroup);
1074 /* Add the notebook pages: */
1075 gtk_box_pack_start (GTK_BOX (priv->main_container),
1076 priv->page_account_details,
1078 gtk_box_pack_start (GTK_BOX (priv->main_container),
1079 priv->page_user_details,
1082 separator = gtk_hseparator_new ();
1083 #ifdef MAEMO_CHANGES
1084 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
1086 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1087 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1088 gtk_widget_show (separator);
1089 gtk_box_pack_start (GTK_BOX (priv->main_container),
1090 priv->page_incoming,
1092 separator = gtk_hseparator_new ();
1093 #ifdef MAEMO_CHANGES
1094 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
1096 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1097 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1098 gtk_widget_show (separator);
1099 gtk_box_pack_start (GTK_BOX (priv->main_container),
1100 priv->page_outgoing,
1103 GtkDialog *dialog = GTK_DIALOG (self);
1104 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1106 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1107 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1108 gtk_widget_show (align);
1109 gtk_container_add (GTK_CONTAINER (align), priv->main_container);
1111 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1112 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (scrollable));
1113 gtk_widget_show (GTK_WIDGET (priv->main_container));
1114 gtk_widget_show (GTK_WIDGET (scrollable));
1116 /* Add the buttons: */
1117 gtk_dialog_add_button (GTK_DIALOG(self), _HL_SAVE, GTK_RESPONSE_OK);
1119 gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1121 /* Connect to the dialog's "response" and "delete-event" signals */
1122 g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self);
1123 g_signal_connect (G_OBJECT (self), "delete-event", G_CALLBACK (on_delete_event), self);
1125 priv->modified = FALSE;
1127 /* When this window is shown, hibernation should not be possible,
1128 * because there is no sensible way to save the state: */
1129 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1130 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1132 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1133 * while sending messages causes an error dialog and we have a lock */
1134 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1138 ModestAccountSettingsDialog*
1139 modest_default_account_settings_dialog_new (void)
1141 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1144 /** Update the UI with the stored account details, so they can be edited.
1145 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1148 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1149 ModestAccountSettings *settings)
1151 ModestServerAccountSettings *incoming_account;
1152 ModestServerAccountSettings *outgoing_account;
1153 ModestProtocolRegistry *protocol_registry;
1154 const gchar *account_name, *server_account_name;
1155 ModestDefaultAccountSettingsDialogPrivate *priv;
1157 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1158 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1160 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1161 protocol_registry = modest_runtime_get_protocol_registry ();
1163 account_name = modest_account_settings_get_account_name (settings);
1165 /* Save the account name so we can refer to it later: */
1166 if (priv->account_name)
1167 g_free (priv->account_name);
1168 priv->account_name = g_strdup (account_name);
1170 if (priv->account_name)
1171 gtk_widget_show (priv->button_delete);
1173 gtk_widget_hide (priv->button_delete);
1176 g_object_unref (priv->settings);
1177 priv->settings = g_object_ref (settings);
1179 /* Save the account title so we can refer to it if the user changes it: */
1180 if (priv->original_account_title)
1181 g_free (priv->original_account_title);
1182 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1184 /* Show the account data in the widgets: */
1186 /* Note that we never show the non-display name in the UI.
1187 * (Though the display name defaults to the non-display name at the start.) */
1188 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1189 null_means_empty (modest_account_settings_get_display_name (settings)));
1190 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1191 null_means_empty (modest_account_settings_get_fullname (settings)));
1192 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1193 null_means_empty (modest_account_settings_get_email_address (settings)));
1195 modest_togglable_set_active (priv->checkbox_leave_messages,
1196 modest_account_settings_get_leave_messages_on_server (settings));
1198 incoming_account = modest_account_settings_get_store_settings (settings);
1199 if (incoming_account) {
1200 const gchar *username, *password, *hostname, *proto_str, *account_title;
1201 gchar *proto_name, *title;
1202 ModestProtocolType incoming_protocol;
1204 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1205 modest_server_account_settings_get_protocol (incoming_account))) {
1206 gtk_widget_hide (priv->checkbox_leave_messages);
1208 gtk_widget_show (priv->checkbox_leave_messages);
1211 /* Remember this for later: */
1212 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1214 hostname = modest_server_account_settings_get_hostname (incoming_account);
1215 username = modest_server_account_settings_get_username (incoming_account);
1216 password = modest_server_account_settings_get_password (incoming_account);
1217 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1218 null_means_empty (username));
1219 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1220 null_means_empty (password));
1222 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1223 null_means_empty (hostname));
1225 /* Load security settings */
1226 modest_security_options_view_load_settings (
1227 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1229 gtk_widget_show (priv->incoming_security);
1231 /* Update the incoming label */
1232 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1235 /* Set window title according to account */
1236 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1237 proto_name = g_utf8_strup (proto_str, -1);
1238 account_title = modest_account_settings_get_display_name(settings);
1239 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1241 gtk_window_set_title (GTK_WINDOW (dialog), title);
1243 g_free (proto_name);
1245 g_object_unref (incoming_account);
1248 outgoing_account = modest_account_settings_get_transport_settings (settings);
1249 if (outgoing_account) {
1250 const gchar *hostname;
1251 const gchar *username;
1252 const gchar *password;
1253 ModestProtocolType outgoing_protocol;
1255 /* Remember this for later: */
1257 modest_server_account_settings_get_protocol (outgoing_account);
1259 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1260 username = modest_server_account_settings_get_username (outgoing_account);
1261 password = modest_server_account_settings_get_password (outgoing_account);
1262 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1263 null_means_empty (hostname));
1265 /* Load security settings */
1266 modest_security_options_view_load_settings (
1267 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1269 gtk_widget_show (priv->outgoing_security);
1271 const gboolean has_specific =
1272 modest_account_settings_get_use_connection_specific_smtp (settings);
1273 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
1275 g_object_unref (outgoing_account);
1278 /* Switch to user page */
1279 /* Check if we allow changes or not */
1280 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1281 if (server_account_name) {
1282 gboolean username_known;
1285 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1286 server_account_name);
1287 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1288 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1289 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1293 /* Unset the modified flag so we can detect changes later: */
1294 priv->modified = FALSE;
1298 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1300 const gchar* user_fullname;
1301 const gchar* emailaddress;
1302 ModestServerAccountSettings *store_settings;
1303 ModestServerAccountSettings *transport_settings;
1304 gboolean leave_on_server;
1305 const gchar* hostname;
1306 const gchar* username;
1307 const gchar* password;
1308 gchar* account_title;
1309 ModestDefaultAccountSettingsDialogPrivate *priv;
1310 const gchar* account_name;
1312 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1313 account_name = priv->account_name;
1315 /* Set the account data from the widgets: */
1316 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1317 modest_account_settings_set_fullname (priv->settings, user_fullname);
1319 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1320 modest_account_settings_set_email_address (priv->settings, emailaddress);
1323 if (priv->signature_dialog) {
1324 gboolean use_signature = FALSE;
1326 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1329 modest_account_settings_set_use_signature (priv->settings, use_signature);
1330 modest_account_settings_set_signature (priv->settings, signature);
1333 leave_on_server = modest_togglable_get_active (priv->checkbox_leave_messages);
1334 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1336 store_settings = modest_account_settings_get_store_settings (priv->settings);
1338 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1339 modest_server_account_settings_set_hostname (store_settings, hostname);
1341 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1342 modest_server_account_settings_set_username (store_settings, username);
1344 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1345 modest_server_account_settings_set_password (store_settings, password);
1347 /* Save security settings */
1348 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1351 g_object_unref (store_settings);
1354 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1356 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1357 modest_server_account_settings_set_hostname (transport_settings, hostname);
1359 /* Save security settings */
1360 modest_security_options_view_save_settings (
1361 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1364 /* Set the changed account title last, to simplify the previous code: */
1365 account_title = get_entered_account_title (dialog);
1367 return FALSE; /* Should be prevented already anyway. */
1369 /* if (strcmp (account_title, account_name) != 0) { */
1370 modest_account_settings_set_display_name (priv->settings, account_title);
1372 g_free (account_title);
1373 account_title = NULL;
1375 /* Save connection-specific SMTP server accounts: */
1376 modest_account_settings_set_use_connection_specific_smtp
1378 modest_togglable_get_active(priv->checkbox_outgoing_smtp_specific));
1380 /* this configuration is not persistent, we should not save */
1381 if (account_name != NULL)
1382 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1387 static gboolean entry_is_empty (GtkWidget *entry)
1392 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1393 if ((!text) || (strlen(text) == 0))
1396 /* Strip it of whitespace at the start and end: */
1397 gchar *stripped = g_strdup (text);
1398 stripped = g_strstrip (stripped);
1403 const gboolean result = (strlen (stripped) == 0);
1411 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1413 gboolean enable_ok = TRUE;
1414 ModestProtocolRegistry *protocol_registry;
1415 ModestSecurityOptionsView *sec_view;
1416 ModestDefaultAccountSettingsDialogPrivate *priv;
1418 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1420 /* The account details title is mandatory: */
1421 if (entry_is_empty(priv->entry_account_title))
1424 /* The user details username is mandatory: */
1425 if (enable_ok && entry_is_empty(priv->entry_user_username))
1428 /* The user details email address is mandatory: */
1429 if (enable_ok && entry_is_empty (priv->entry_user_email))
1432 /* The custom incoming server is mandatory: */
1433 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1436 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1438 modest_security_options_view_has_missing_mandatory_data (sec_view))
1441 /* The custom outgoing server is mandatory: */
1442 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1445 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1447 modest_security_options_view_has_missing_mandatory_data (sec_view))
1450 protocol_registry = modest_runtime_get_protocol_registry ();
1452 /* Enable the buttons,
1453 * identifying them via their associated response codes:
1455 GtkDialog *dialog_base = GTK_DIALOG (self);
1456 gtk_dialog_set_response_sensitive (dialog_base,
1462 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1464 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1465 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1467 object_class->dispose = modest_default_account_settings_dialog_dispose;
1468 object_class->finalize = modest_default_account_settings_dialog_finalize;
1472 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1474 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1476 iface->load_settings = modest_default_account_settings_dialog_load_settings;