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;
198 on_modified_picker_changed (GtkWidget *widget, gpointer user_data)
200 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
204 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
206 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
210 on_modified_checkbutton_toggled (GtkWidget *button, gpointer user_data)
212 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
216 on_modified_number_entry_changed (GtkWidget *number_entry, gint new_value, gpointer user_data)
218 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
222 on_number_entry_notify (GtkWidget *entry, GParamSpec *arg1, gpointer user_data)
224 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
225 gint value = modest_number_entry_get_value (entry);
227 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
230 /* Set a modified boolean whenever the widget is changed,
231 * so we can check for it later.
234 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
236 if (modest_is_number_entry (widget)) {
237 g_signal_connect (G_OBJECT (widget), "notify::value",
238 G_CALLBACK (on_modified_number_entry_changed), self);
239 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_entry_notify), self);
241 else if (GTK_IS_ENTRY (widget)) {
242 g_signal_connect (G_OBJECT (widget), "changed",
243 G_CALLBACK (on_modified_entry_changed), self);
244 #ifdef MODEST_TOOLKIT_HILDON2
245 } else if (HILDON_IS_PICKER_BUTTON (widget)) {
246 g_signal_connect (G_OBJECT (widget), "value-changed",
247 G_CALLBACK (on_modified_picker_changed), self);
249 } else if (modest_is_togglable (widget)) {
250 g_signal_connect (G_OBJECT (widget), "toggled",
251 G_CALLBACK (on_modified_checkbutton_toggled), self);
256 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
258 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
260 enable_buttons(self);
264 create_captioned (ModestDefaultAccountSettingsDialog *self,
265 GtkSizeGroup *title_sizegroup,
266 GtkSizeGroup *value_sizegroup,
267 const gchar *label_text,
274 result = modest_toolkit_utils_create_captioned_with_size_type (title_sizegroup, value_sizegroup,
275 label_text, use_markup, control,
276 MODEST_EDITABLE_SIZE);
278 /* Connect to the appropriate changed signal for the widget,
279 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
281 if (GTK_IS_ENTRY (control)) {
282 g_signal_connect (G_OBJECT (control), "changed",
283 G_CALLBACK (on_caption_entry_changed), self);
291 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
295 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
296 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
298 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
305 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
309 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
310 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
312 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
320 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
322 modest_platform_information_banner (GTK_WIDGET (self), NULL,
323 _CS("ckdg_ib_maximum_characters_reached"));
327 create_page_account_details (ModestDefaultAccountSettingsDialog *self,
328 GtkSizeGroup *title_sizegroup,
329 GtkSizeGroup *value_sizegroup)
331 ModestDefaultAccountSettingsDialogPrivate *priv;
335 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
336 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
338 /* The description widgets: */
339 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
340 /* Do use auto-capitalization: */
342 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
343 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
345 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
346 _("mcen_fi_account_title"), FALSE,
347 priv->entry_account_title);
348 gtk_widget_show (priv->entry_account_title);
349 connect_for_modified (self, priv->entry_account_title);
350 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
351 gtk_widget_show (caption);
353 /* Prevent the use of some characters in the account title,
354 * as required by our UI specification: */
355 GList *list_prevent = NULL;
356 list_prevent = g_list_append (list_prevent, "\\");
357 list_prevent = g_list_append (list_prevent, "/");
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 modest_validating_entry_set_unallowed_characters (
367 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
368 g_list_free (list_prevent);
369 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
370 on_entry_invalid_account_title_character, self);
372 /* Set max length as in the UI spec:
373 * The UI spec seems to want us to show a dialog if we hit the maximum. */
374 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
375 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
378 hbox = gtk_hbox_new (TRUE, 0);
380 /* The leave-messages widgets: */
381 if(!priv->checkbox_leave_messages) {
382 priv->checkbox_leave_messages =
383 modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
384 _("mcen_fi_advsetup_leave_on_server"));
386 connect_for_modified (self, priv->checkbox_leave_messages);
387 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_leave_messages, FALSE, FALSE, 0);
388 gtk_widget_show (priv->checkbox_leave_messages);
390 gtk_widget_show (GTK_WIDGET (box));
392 return GTK_WIDGET (box);
396 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
398 ModestDefaultAccountSettingsDialogPrivate *priv;
399 const gchar* account_title;
401 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
402 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
404 if (!account_title || (strlen (account_title) == 0))
407 /* Strip it of whitespace at the start and end: */
408 gchar *result = g_strdup (account_title);
409 result = g_strstrip (result);
414 if (strlen (result) == 0) {
425 signature_button_clicked (ModestDefaultAccountSettingsDialog *self)
428 ModestDefaultAccountSettingsDialogPrivate *priv;
430 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
432 /* Create the window, if necessary: */
433 if (!(priv->signature_dialog)) {
434 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
436 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
437 const gchar *signature = modest_account_settings_get_signature(priv->settings);
438 gchar* account_title = get_entered_account_title (self);
439 modest_signature_editor_dialog_set_settings (
440 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
441 use_signature, signature, account_title);
443 g_free (account_title);
444 account_title = NULL;
448 /* Show the window: */
449 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
450 GTK_WINDOW (priv->signature_dialog), GTK_WINDOW (self));
452 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
453 gtk_widget_hide (priv->signature_dialog);
454 if (response != GTK_RESPONSE_OK) {
455 /* Destroy the widget now, and its data: */
456 gtk_widget_destroy (priv->signature_dialog);
457 priv->signature_dialog = NULL;
459 /* Mark modified, so we use the dialog's data later: */
460 priv->modified = TRUE;
465 delete_button_clicked (ModestDefaultAccountSettingsDialog *self)
467 ModestDefaultAccountSettingsDialogPrivate *priv;
468 gchar *account_title;
471 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
474 account_title = g_strdup (priv->original_account_title);
476 account_title = get_entered_account_title (self);
478 removed = modest_ui_actions_on_delete_account (GTK_WINDOW (self),
480 (const gchar *) account_title);
481 g_free (account_title);
487 create_page_user_details (ModestDefaultAccountSettingsDialog *self,
488 GtkSizeGroup *title_sizegroup,
489 GtkSizeGroup *value_sizegroup)
491 ModestDefaultAccountSettingsDialogPrivate *priv;
494 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
496 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
498 /* The name widgets: */
499 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
501 /* Auto-capitalization is the default, so let's turn it off: */
503 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
504 HILDON_GTK_INPUT_MODE_FULL |
505 HILDON_GTK_INPUT_MODE_AUTOCAP);
507 /* Set max length as in the UI spec:
508 * The UI spec seems to want us to show a dialog if we hit the maximum. */
509 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
510 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
513 create_captioned (self, title_sizegroup, value_sizegroup,
514 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
515 gtk_widget_show (priv->entry_user_name);
516 connect_for_modified (self, priv->entry_user_name);
517 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
518 gtk_widget_show (caption);
521 /* Prevent the use of some characters in the name,
522 * as required by our UI specification: */
523 GList *list_prevent = NULL;
524 list_prevent = g_list_append (list_prevent, "<");
525 list_prevent = g_list_append (list_prevent, ">");
526 modest_validating_entry_set_unallowed_characters (
527 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
528 g_list_free (list_prevent);
529 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
530 on_entry_invalid_fullname_character, self);
532 /* The username widgets: */
533 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
534 /* Auto-capitalization is the default, so let's turn it off: */
536 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
538 caption = create_captioned (self, title_sizegroup, value_sizegroup,
539 _("mail_fi_username"), FALSE,
540 priv->entry_user_username);
541 gtk_widget_show (priv->entry_user_username);
542 connect_for_modified (self, priv->entry_user_username);
543 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
544 gtk_widget_show (caption);
546 /* Prevent the use of some characters in the username,
547 * as required by our UI specification: */
548 modest_validating_entry_set_unallowed_characters_whitespace (
549 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
550 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
551 modest_utils_on_entry_invalid_character,
554 /* Set max length as in the UI spec:
555 * The UI spec seems to want us to show a dialog if we hit the maximum. */
556 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
557 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
560 /* The password widgets: */
561 priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
562 /* Auto-capitalization is the default, so let's turn it off: */
564 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
565 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
567 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
568 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
569 caption = create_captioned (self, title_sizegroup, value_sizegroup,
570 _("mail_fi_password"), FALSE, priv->entry_user_password);
571 gtk_widget_show (priv->entry_user_password);
572 connect_for_modified (self, priv->entry_user_password);
573 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
574 gtk_widget_show (caption);
576 /* The email address widgets: */
577 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
578 /* Auto-capitalization is the default, so let's turn it off: */
580 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
582 caption = create_captioned (self, title_sizegroup, value_sizegroup,
583 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
584 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
585 gtk_widget_show (priv->entry_user_email);
586 connect_for_modified (self, priv->entry_user_email);
587 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
588 gtk_widget_show (caption);
590 /* Set max length as in the UI spec:
591 * The UI spec seems to want us to show a dialog if we hit the maximum. */
592 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
593 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
597 if (!priv->button_delete)
598 priv->button_delete = gtk_dialog_add_button (GTK_DIALOG (self),
599 _HL("wdgt_bd_delete"),
600 RESPONSE_DELETE_DUMMY);
602 /* Signature button: */
603 if (!priv->button_signature)
604 priv->button_signature = gtk_dialog_add_button (GTK_DIALOG (self),
605 _("mcen_bd_email_signature"),
606 RESPONSE_SIGNATURE_DUMMY);
607 gtk_widget_show (priv->button_signature);
609 gtk_widget_show (GTK_WIDGET (box));
611 return GTK_WIDGET (box);
614 /* Change the caption title for the incoming server */
616 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
617 ModestProtocolType protocol_type)
619 ModestProtocolRegistry *protocol_registry;
620 ModestProtocol *protocol;
621 const gchar *protocol_display_name;
622 gchar* incomingserver_title;
623 ModestDefaultAccountSettingsDialogPrivate *priv;
625 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
627 protocol_registry = modest_runtime_get_protocol_registry ();
628 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
629 protocol_display_name = modest_protocol_get_display_name (protocol);
630 incomingserver_title = g_strconcat(_("mcen_li_emailsetup_servertype"), "*",
631 "\n<small>(", protocol_display_name, ")</small>", NULL);
633 modest_toolkit_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
634 g_free (incomingserver_title);
637 /* The size groups passed as arguments are only used by the security settings */
639 create_page_incoming (ModestDefaultAccountSettingsDialog *self,
640 GtkSizeGroup *security_title_sizegroup,
641 GtkSizeGroup *security_value_sizegroup)
643 ModestDefaultAccountSettingsDialogPrivate *priv;
646 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
648 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
650 /* The incoming server widgets: */
651 if(!priv->entry_incomingserver)
652 priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
653 /* Auto-capitalization is the default, so let's turn it off: */
655 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
658 if (priv->caption_incoming)
659 gtk_widget_destroy (priv->caption_incoming);
661 /* The caption title will be updated in update_incoming_server_title().
662 * so this default text will never be seen: */
663 /* (Note: Changing the title seems pointless. murrayc) */
664 priv->caption_incoming = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
665 "Incoming Server", FALSE, priv->entry_incomingserver);
666 gtk_widget_show (priv->entry_incomingserver);
667 connect_for_modified (self, priv->entry_incomingserver);
668 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
669 gtk_widget_show (priv->caption_incoming);
671 /* Incoming security widgets */
672 priv->incoming_security =
673 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
674 MODEST_SECURITY_OPTIONS_INCOMING,
675 TRUE, security_title_sizegroup,
676 security_value_sizegroup);
677 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
680 gtk_widget_show (priv->incoming_security);
681 gtk_widget_show (GTK_WIDGET (box));
682 g_signal_connect (priv->incoming_security, "missing-mandatory-data",
683 G_CALLBACK (on_missing_mandatory_data), self);
685 return GTK_WIDGET (box);
689 on_check_button_clicked (GtkWidget *button, gpointer user_data)
691 GtkWidget *widget = GTK_WIDGET (user_data);
693 /* Enable the widget only if the check button is active: */
694 const gboolean enable = modest_togglable_get_active (button);
695 gtk_widget_set_sensitive (widget, enable);
698 /* Make the sensitivity of a widget depend on a check button.
701 enable_widget_for_checkbutton (GtkWidget *widget, GtkWidget* button)
703 g_signal_connect (G_OBJECT (button), "clicked",
704 G_CALLBACK (on_check_button_clicked), widget);
706 /* Set the starting sensitivity: */
707 on_check_button_clicked (button, widget);
711 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
713 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
714 ModestConnectionSpecificSmtpWindow *smtp_win;
715 ModestDefaultAccountSettingsDialogPrivate *priv;
717 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
719 /* Create the window if necessary: */
720 smtp_win = modest_connection_specific_smtp_window_new ();
721 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
723 /* Show the window: */
724 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win), GTK_WINDOW (self));
725 gtk_widget_show (GTK_WIDGET (smtp_win));
729 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
733 /* Disable the OK button */
734 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
740 create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
741 GtkSizeGroup *security_title_sizegroup,
742 GtkSizeGroup *security_value_sizegroup)
744 ModestDefaultAccountSettingsDialogPrivate *priv;
745 gchar *smtp_caption_label;
746 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
748 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
750 /* The outgoing server widgets: */
751 if (!priv->entry_outgoingserver)
752 priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
753 /* Auto-capitalization is the default, so let's turn it off: */
755 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
757 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
758 GtkWidget *caption = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
759 smtp_caption_label, TRUE, priv->entry_outgoingserver);
760 g_free (smtp_caption_label);
761 gtk_widget_show (priv->entry_outgoingserver);
762 connect_for_modified (self, priv->entry_outgoingserver);
763 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
764 gtk_widget_show (caption);
766 /* Outgoing security widgets */
767 priv->outgoing_security =
768 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
769 MODEST_SECURITY_OPTIONS_OUTGOING,
770 TRUE, security_title_sizegroup,
771 security_value_sizegroup);
772 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
774 gtk_widget_show (priv->outgoing_security);
775 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
776 G_CALLBACK (on_missing_mandatory_data), self);
778 GtkWidget *separator = gtk_hseparator_new ();
779 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_DEFAULT);
781 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
783 gtk_widget_show (separator);
785 /* connection-specific checkbox: */
786 if (!priv->checkbox_outgoing_smtp_specific) {
787 priv->checkbox_outgoing_smtp_specific =
788 modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
789 _("mcen_fi_advsetup_connection_smtp"));
790 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
793 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
794 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
796 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
798 /* Connection-specific SMTP-Severs Edit button: */
799 if (!priv->button_outgoing_smtp_servers)
800 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
802 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
803 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
805 gtk_widget_show (priv->button_outgoing_smtp_servers);
806 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers, FALSE, FALSE, 0);
808 /* Only enable the button when the checkbox is checked: */
809 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
810 priv->checkbox_outgoing_smtp_specific);
812 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
813 G_CALLBACK (on_button_outgoing_smtp_servers), self);
815 gtk_widget_show (GTK_WIDGET (box));
817 return GTK_WIDGET (box);
821 check_data (ModestDefaultAccountSettingsDialog *self)
823 gchar* account_title;
824 const gchar* email_address;
825 const gchar* hostname;
826 const gchar* hostname2;
827 ModestDefaultAccountSettingsDialogPrivate *priv;
829 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
831 /* Check that the title is not already in use: */
832 account_title = get_entered_account_title (self);
834 return FALSE; /* Should be prevented already anyway. */
836 if (g_strcmp0 (account_title, priv->original_account_title) != 0) {
837 gboolean name_in_use;
839 /* Check the changed title: */
840 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
844 /* Warn the user via a dialog: */
845 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
847 g_free (account_title);
852 g_free (account_title);
853 account_title = NULL;
855 /* Check that the email address is valid: */
856 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
857 if ((!email_address) || (strlen(email_address) == 0)) {
861 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
862 /* Warn the user via a dialog: */
863 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
865 /* Return focus to the email address entry: */
866 gtk_widget_grab_focus (priv->entry_user_email);
867 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
871 /* make sure the domain name for the incoming server is valid */
872 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
873 if ((!hostname) || (strlen(hostname) == 0)) {
877 if (!modest_text_utils_validate_domain_name (hostname)) {
878 /* Warn the user via a dialog: */
879 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
881 /* Return focus to the email address entry: */
882 gtk_widget_grab_focus (priv->entry_incomingserver);
883 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
887 /* make sure the domain name for the outgoing server is valid */
888 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
889 if ((!hostname2) || (strlen(hostname2) == 0)) {
893 if (!modest_text_utils_validate_domain_name (hostname2)) {
894 /* Warn the user via a dialog: */
895 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
897 /* Return focus to the email address entry: */
898 gtk_widget_grab_focus (priv->entry_outgoingserver);
899 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
907 on_delete_event (GtkWidget *widget,
911 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
912 ModestDefaultAccountSettingsDialogPrivate *priv;
913 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
915 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
917 /* Check if security widgets changed */
918 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
919 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
921 return modest_security_options_view_changed (incoming_sec, priv->settings) ||
922 modest_security_options_view_changed (outgoing_sec, priv->settings) ||
927 on_response (GtkDialog *wizard_dialog,
931 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
932 ModestDefaultAccountSettingsDialogPrivate *priv;
933 gboolean prevent_response = FALSE, sec_changed;
934 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
936 /* Dummy and delete buttons have a response id because they're
937 added with gtk_dialog_add_button in order to get the proper
939 if (response_id == RESPONSE_SIGNATURE_DUMMY) {
940 signature_button_clicked (self);
941 g_signal_stop_emission_by_name (wizard_dialog, "response");
945 if (response_id == RESPONSE_DELETE_DUMMY) {
946 if (!delete_button_clicked (self))
947 g_signal_stop_emission_by_name (wizard_dialog, "response");
951 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
952 enable_buttons (self);
954 /* Check if security widgets changed */
955 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
956 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
958 modest_security_options_view_changed (incoming_sec, priv->settings) ||
959 modest_security_options_view_changed (outgoing_sec, priv->settings);
961 /* Warn about unsaved changes: */
962 if ((response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) &&
963 (priv->modified || sec_changed)) {
964 gint response = modest_platform_run_confirmation_dialog (GTK_WINDOW (self),
965 _("imum_nc_wizard_confirm_lose_changes")));
966 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
969 if (dialog_response != GTK_RESPONSE_OK)
970 prevent_response = TRUE;
972 /* Check for invalid input: */
973 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
974 prevent_response = TRUE;
977 if (prevent_response) {
978 /* Don't let the dialog close */
979 g_signal_stop_emission_by_name (wizard_dialog, "response");
982 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
985 if (response_id == GTK_RESPONSE_OK) {
986 /* Try to save the changes if modified (NB #59251): */
987 if (priv->modified || sec_changed) {
988 if (save_configuration (self)) {
989 /* Do not show the account-saved dialog if we are just saving this
990 * temporarily, because from the user's point of view it will not
991 * really be saved (saved + enabled) until later
993 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
994 ModestServerAccountSettings *store_settings;
995 ModestServerAccountSettings *transport_settings;
996 const gchar *store_account_name;
997 const gchar *transport_account_name;
1000 store_settings = modest_account_settings_get_store_settings (priv->settings);
1001 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1002 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1003 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1005 if (store_account_name) {
1006 modest_account_mgr_notify_account_update (priv->account_manager,
1007 store_account_name);
1009 if (transport_account_name) {
1010 modest_account_mgr_notify_account_update (priv->account_manager,
1011 transport_account_name);
1013 g_object_unref (store_settings);
1014 g_object_unref (transport_settings);
1016 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1019 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1026 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1028 ModestDefaultAccountSettingsDialogPrivate *priv;
1029 GtkWidget *scrollable;
1030 GtkWidget *separator;
1032 GtkSizeGroup* account_title_sizegroup;
1033 GtkSizeGroup* account_value_sizegroup;
1034 GtkSizeGroup *sec_title_sizegroup, *sec_value_sizegroup;
1036 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1038 priv->incoming_security = NULL;
1039 priv->outgoing_security = NULL;
1041 priv->main_container = gtk_vbox_new (FALSE, 0);
1042 priv->settings = modest_account_settings_new ();
1044 /* Get the account manager object,
1045 * so we can check for existing accounts,
1046 * and create new accounts: */
1047 priv->account_manager = modest_runtime_get_account_mgr ();
1048 g_assert (priv->account_manager);
1049 g_object_ref (priv->account_manager);
1051 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1053 /* Create the common pages */
1054 account_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1055 account_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1056 priv->page_account_details = create_page_account_details (self, account_title_sizegroup, account_value_sizegroup);
1057 priv->page_user_details = create_page_user_details (self, account_title_sizegroup, account_value_sizegroup);
1058 g_object_unref (account_title_sizegroup);
1059 g_object_unref (account_value_sizegroup);
1062 /* Create size groups for security settings */
1063 sec_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1064 sec_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1066 /* Create incoming and outgoing "pages" */
1067 priv->page_incoming = create_page_incoming (self, sec_title_sizegroup, sec_value_sizegroup);
1068 priv->page_outgoing = create_page_outgoing (self, sec_title_sizegroup, sec_value_sizegroup);
1069 g_object_unref (sec_title_sizegroup);
1070 g_object_unref (sec_value_sizegroup);
1072 /* Add the notebook pages: */
1073 gtk_box_pack_start (GTK_BOX (priv->main_container),
1074 priv->page_account_details,
1076 gtk_box_pack_start (GTK_BOX (priv->main_container),
1077 priv->page_user_details,
1080 separator = gtk_hseparator_new ();
1081 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
1082 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1083 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1084 gtk_widget_show (separator);
1085 gtk_box_pack_start (GTK_BOX (priv->main_container),
1086 priv->page_incoming,
1088 separator = gtk_hseparator_new ();
1089 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
1090 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1091 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1092 gtk_widget_show (separator);
1093 gtk_box_pack_start (GTK_BOX (priv->main_container),
1094 priv->page_outgoing,
1097 GtkDialog *dialog = GTK_DIALOG (self);
1098 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1100 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1101 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1102 gtk_widget_show (align);
1103 gtk_container_add (GTK_CONTAINER (align), priv->main_container);
1105 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1106 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (scrollable));
1107 gtk_widget_show (GTK_WIDGET (priv->main_container));
1108 gtk_widget_show (GTK_WIDGET (scrollable));
1110 /* Add the buttons: */
1111 gtk_dialog_add_button (GTK_DIALOG(self), _HL("wdgt_bd_save"), GTK_RESPONSE_OK);
1113 gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1115 /* Connect to the dialog's "response" and "delete-event" signals */
1116 g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self);
1117 g_signal_connect (G_OBJECT (self), "delete-event", G_CALLBACK (on_delete_event), self);
1119 priv->modified = FALSE;
1121 /* When this window is shown, hibernation should not be possible,
1122 * because there is no sensible way to save the state: */
1123 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1124 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1126 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1127 * while sending messages causes an error dialog and we have a lock */
1128 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1132 ModestAccountSettingsDialog*
1133 modest_default_account_settings_dialog_new (void)
1135 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1138 /** Update the UI with the stored account details, so they can be edited.
1139 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1142 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1143 ModestAccountSettings *settings)
1145 ModestServerAccountSettings *incoming_account;
1146 ModestServerAccountSettings *outgoing_account;
1147 ModestProtocolRegistry *protocol_registry;
1148 const gchar *account_name, *server_account_name;
1149 ModestDefaultAccountSettingsDialogPrivate *priv;
1151 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1152 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1154 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1155 protocol_registry = modest_runtime_get_protocol_registry ();
1157 account_name = modest_account_settings_get_account_name (settings);
1159 /* Save the account name so we can refer to it later: */
1160 if (priv->account_name)
1161 g_free (priv->account_name);
1162 priv->account_name = g_strdup (account_name);
1164 if (priv->account_name)
1165 gtk_widget_show (priv->button_delete);
1167 gtk_widget_hide (priv->button_delete);
1170 g_object_unref (priv->settings);
1171 priv->settings = g_object_ref (settings);
1173 /* Save the account title so we can refer to it if the user changes it: */
1174 if (priv->original_account_title)
1175 g_free (priv->original_account_title);
1176 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1178 /* Show the account data in the widgets: */
1180 /* Note that we never show the non-display name in the UI.
1181 * (Though the display name defaults to the non-display name at the start.) */
1182 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1183 null_means_empty (modest_account_settings_get_display_name (settings)));
1184 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1185 null_means_empty (modest_account_settings_get_fullname (settings)));
1186 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1187 null_means_empty (modest_account_settings_get_email_address (settings)));
1189 modest_togglable_set_active (priv->checkbox_leave_messages,
1190 modest_account_settings_get_leave_messages_on_server (settings));
1192 incoming_account = modest_account_settings_get_store_settings (settings);
1193 if (incoming_account) {
1194 const gchar *username, *password, *hostname, *proto_str, *account_title;
1195 gchar *proto_name, *title;
1196 ModestProtocolType incoming_protocol;
1198 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1199 modest_server_account_settings_get_protocol (incoming_account))) {
1200 gtk_widget_hide (priv->checkbox_leave_messages);
1202 gtk_widget_show (priv->checkbox_leave_messages);
1205 /* Remember this for later: */
1206 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1208 hostname = modest_server_account_settings_get_hostname (incoming_account);
1209 username = modest_server_account_settings_get_username (incoming_account);
1210 password = modest_server_account_settings_get_password (incoming_account);
1211 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1212 null_means_empty (username));
1213 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1214 null_means_empty (password));
1216 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1217 null_means_empty (hostname));
1219 /* Load security settings */
1220 modest_security_options_view_load_settings (
1221 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1223 gtk_widget_show (priv->incoming_security);
1225 /* Update the incoming label */
1226 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1229 /* Set window title according to account */
1230 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1231 proto_name = g_utf8_strup (proto_str, -1);
1232 account_title = modest_account_settings_get_display_name(settings);
1233 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1235 gtk_window_set_title (GTK_WINDOW (dialog), title);
1237 g_free (proto_name);
1239 g_object_unref (incoming_account);
1242 outgoing_account = modest_account_settings_get_transport_settings (settings);
1243 if (outgoing_account) {
1244 const gchar *hostname;
1245 const gchar *username;
1246 const gchar *password;
1247 ModestProtocolType outgoing_protocol;
1249 /* Remember this for later: */
1251 modest_server_account_settings_get_protocol (outgoing_account);
1253 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1254 username = modest_server_account_settings_get_username (outgoing_account);
1255 password = modest_server_account_settings_get_password (outgoing_account);
1256 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1257 null_means_empty (hostname));
1259 /* Load security settings */
1260 modest_security_options_view_load_settings (
1261 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1263 gtk_widget_show (priv->outgoing_security);
1265 const gboolean has_specific =
1266 modest_account_settings_get_use_connection_specific_smtp (settings);
1267 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
1269 g_object_unref (outgoing_account);
1272 /* Switch to user page */
1273 /* Check if we allow changes or not */
1274 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1275 if (server_account_name) {
1276 gboolean username_known;
1279 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1280 server_account_name);
1281 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1282 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1283 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1287 /* Unset the modified flag so we can detect changes later: */
1288 priv->modified = FALSE;
1292 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1294 const gchar* user_fullname;
1295 const gchar* emailaddress;
1296 ModestServerAccountSettings *store_settings;
1297 ModestServerAccountSettings *transport_settings;
1298 gboolean leave_on_server;
1299 const gchar* hostname;
1300 const gchar* username;
1301 const gchar* password;
1302 gchar* account_title;
1303 ModestDefaultAccountSettingsDialogPrivate *priv;
1304 const gchar* account_name;
1306 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1307 account_name = priv->account_name;
1309 /* Set the account data from the widgets: */
1310 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1311 modest_account_settings_set_fullname (priv->settings, user_fullname);
1313 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1314 modest_account_settings_set_email_address (priv->settings, emailaddress);
1317 if (priv->signature_dialog) {
1318 gboolean use_signature = FALSE;
1320 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1323 modest_account_settings_set_use_signature (priv->settings, use_signature);
1324 modest_account_settings_set_signature (priv->settings, signature);
1327 leave_on_server = modest_togglable_get_active (priv->checkbox_leave_messages);
1328 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1330 store_settings = modest_account_settings_get_store_settings (priv->settings);
1332 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1333 modest_server_account_settings_set_hostname (store_settings, hostname);
1335 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1336 modest_server_account_settings_set_username (store_settings, username);
1338 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1339 modest_server_account_settings_set_password (store_settings, password);
1341 /* Save security settings */
1342 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1345 g_object_unref (store_settings);
1348 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1350 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1351 modest_server_account_settings_set_hostname (transport_settings, hostname);
1353 /* Save security settings */
1354 modest_security_options_view_save_settings (
1355 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1358 /* Set the changed account title last, to simplify the previous code: */
1359 account_title = get_entered_account_title (dialog);
1361 return FALSE; /* Should be prevented already anyway. */
1363 /* if (strcmp (account_title, account_name) != 0) { */
1364 modest_account_settings_set_display_name (priv->settings, account_title);
1366 g_free (account_title);
1367 account_title = NULL;
1369 /* Save connection-specific SMTP server accounts: */
1370 modest_account_settings_set_use_connection_specific_smtp
1372 modest_togglable_get_active(priv->checkbox_outgoing_smtp_specific));
1374 /* this configuration is not persistent, we should not save */
1375 if (account_name != NULL)
1376 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1381 static gboolean entry_is_empty (GtkWidget *entry)
1386 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1387 if ((!text) || (strlen(text) == 0))
1390 /* Strip it of whitespace at the start and end: */
1391 gchar *stripped = g_strdup (text);
1392 stripped = g_strstrip (stripped);
1397 const gboolean result = (strlen (stripped) == 0);
1405 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1407 gboolean enable_ok = TRUE;
1408 ModestProtocolRegistry *protocol_registry;
1409 ModestSecurityOptionsView *sec_view;
1410 ModestDefaultAccountSettingsDialogPrivate *priv;
1412 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1414 /* The account details title is mandatory: */
1415 if (entry_is_empty(priv->entry_account_title))
1418 /* The user details username is mandatory: */
1419 if (enable_ok && entry_is_empty(priv->entry_user_username))
1422 /* The user details email address is mandatory: */
1423 if (enable_ok && entry_is_empty (priv->entry_user_email))
1426 /* The custom incoming server is mandatory: */
1427 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1430 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1432 modest_security_options_view_has_missing_mandatory_data (sec_view))
1435 /* The custom outgoing server is mandatory: */
1436 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1439 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1441 modest_security_options_view_has_missing_mandatory_data (sec_view))
1444 protocol_registry = modest_runtime_get_protocol_registry ();
1446 /* Enable the buttons,
1447 * identifying them via their associated response codes:
1449 GtkDialog *dialog_base = GTK_DIALOG (self);
1450 gtk_dialog_set_response_sensitive (dialog_base,
1456 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1458 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1459 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1461 object_class->dispose = modest_default_account_settings_dialog_dispose;
1462 object_class->finalize = modest_default_account_settings_dialog_finalize;
1466 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1468 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1470 iface->load_settings = modest_default_account_settings_dialog_load_settings;