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_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_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_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;
497 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
499 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
501 /* The name widgets: */
502 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
504 /* Auto-capitalization is the default, so let's turn it off: */
506 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
507 HILDON_GTK_INPUT_MODE_FULL |
508 HILDON_GTK_INPUT_MODE_AUTOCAP);
510 /* Set max length as in the UI spec:
511 * The UI spec seems to want us to show a dialog if we hit the maximum. */
512 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
513 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
516 create_captioned (self, title_sizegroup, value_sizegroup,
517 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
518 gtk_widget_show (priv->entry_user_name);
519 connect_for_modified (self, priv->entry_user_name);
520 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
521 gtk_widget_show (caption);
524 /* Prevent the use of some characters in the name,
525 * as required by our UI specification: */
526 GList *list_prevent = NULL;
527 list_prevent = g_list_append (list_prevent, "<");
528 list_prevent = g_list_append (list_prevent, ">");
529 modest_validating_entry_set_unallowed_characters (
530 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
531 g_list_free (list_prevent);
532 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
533 on_entry_invalid_fullname_character, self);
535 /* The username widgets: */
536 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
537 /* Auto-capitalization is the default, so let's turn it off: */
539 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
541 tmp = g_strconcat (_("mail_fi_username"), "*", NULL);
542 caption = create_captioned (self, title_sizegroup, value_sizegroup,
544 priv->entry_user_username);
546 gtk_widget_show (priv->entry_user_username);
547 connect_for_modified (self, priv->entry_user_username);
548 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
549 gtk_widget_show (caption);
551 /* Prevent the use of some characters in the username,
552 * as required by our UI specification: */
553 modest_validating_entry_set_unallowed_characters_whitespace (
554 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
555 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
556 modest_utils_on_entry_invalid_character,
559 /* Set max length as in the UI spec:
560 * The UI spec seems to want us to show a dialog if we hit the maximum. */
561 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
562 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
565 /* The password widgets: */
566 priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
567 /* Auto-capitalization is the default, so let's turn it off: */
569 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
570 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
572 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
573 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
574 caption = create_captioned (self, title_sizegroup, value_sizegroup,
575 _("mail_fi_password"), FALSE, priv->entry_user_password);
576 gtk_widget_show (priv->entry_user_password);
577 connect_for_modified (self, priv->entry_user_password);
578 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
579 gtk_widget_show (caption);
581 /* The email address widgets: */
582 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
583 /* Auto-capitalization is the default, so let's turn it off: */
585 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
587 tmp = g_strconcat (_("mcen_li_emailsetup_email_address"), "*", NULL);
588 caption = create_captioned (self, title_sizegroup, value_sizegroup,
589 tmp, FALSE, priv->entry_user_email);
591 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
592 gtk_widget_show (priv->entry_user_email);
593 connect_for_modified (self, priv->entry_user_email);
594 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
595 gtk_widget_show (caption);
597 /* Set max length as in the UI spec:
598 * The UI spec seems to want us to show a dialog if we hit the maximum. */
599 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
600 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
604 if (!priv->button_delete)
605 priv->button_delete = gtk_dialog_add_button (GTK_DIALOG (self),
607 RESPONSE_DELETE_DUMMY);
609 /* Signature button: */
610 if (!priv->button_signature)
611 priv->button_signature = gtk_dialog_add_button (GTK_DIALOG (self),
612 _("mcen_bd_email_signature"),
613 RESPONSE_SIGNATURE_DUMMY);
614 gtk_widget_show (priv->button_signature);
616 gtk_widget_show (GTK_WIDGET (box));
618 return GTK_WIDGET (box);
621 /* Change the caption title for the incoming server */
623 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
624 ModestProtocolType protocol_type)
626 ModestProtocolRegistry *protocol_registry;
627 ModestProtocol *protocol;
628 const gchar *protocol_display_name;
629 gchar* incomingserver_title;
630 ModestDefaultAccountSettingsDialogPrivate *priv;
632 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
634 protocol_registry = modest_runtime_get_protocol_registry ();
635 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
636 protocol_display_name = modest_protocol_get_display_name (protocol);
637 incomingserver_title = g_strconcat(_("mcen_li_emailsetup_servertype"), "*",
638 "\n<small>(", protocol_display_name, ")</small>", NULL);
640 modest_toolkit_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
641 g_free (incomingserver_title);
644 /* The size groups passed as arguments are only used by the security settings */
646 create_page_incoming (ModestDefaultAccountSettingsDialog *self,
647 GtkSizeGroup *security_title_sizegroup,
648 GtkSizeGroup *security_value_sizegroup)
650 ModestDefaultAccountSettingsDialogPrivate *priv;
653 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
655 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
657 /* The incoming server widgets: */
658 if(!priv->entry_incomingserver)
659 priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
660 /* Auto-capitalization is the default, so let's turn it off: */
662 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
665 if (priv->caption_incoming)
666 gtk_widget_destroy (priv->caption_incoming);
668 /* The caption title will be updated in update_incoming_server_title().
669 * so this default text will never be seen: */
670 /* (Note: Changing the title seems pointless. murrayc) */
671 priv->caption_incoming = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
672 "Incoming Server", FALSE, priv->entry_incomingserver);
673 gtk_widget_show (priv->entry_incomingserver);
674 connect_for_modified (self, priv->entry_incomingserver);
675 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
676 gtk_widget_show (priv->caption_incoming);
678 /* Incoming security widgets */
679 priv->incoming_security =
680 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
681 MODEST_SECURITY_OPTIONS_INCOMING,
682 TRUE, security_title_sizegroup,
683 security_value_sizegroup);
684 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
687 gtk_widget_show (priv->incoming_security);
688 gtk_widget_show (GTK_WIDGET (box));
689 g_signal_connect (priv->incoming_security, "missing-mandatory-data",
690 G_CALLBACK (on_missing_mandatory_data), self);
692 return GTK_WIDGET (box);
696 on_check_button_clicked (GtkWidget *button, gpointer user_data)
698 GtkWidget *widget = GTK_WIDGET (user_data);
700 /* Enable the widget only if the check button is active: */
701 const gboolean enable = modest_togglable_get_active (button);
702 gtk_widget_set_sensitive (widget, enable);
705 /* Make the sensitivity of a widget depend on a check button.
708 enable_widget_for_checkbutton (GtkWidget *widget, GtkWidget* button)
710 g_signal_connect (G_OBJECT (button), "clicked",
711 G_CALLBACK (on_check_button_clicked), widget);
713 /* Set the starting sensitivity: */
714 on_check_button_clicked (button, widget);
718 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
720 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
721 ModestConnectionSpecificSmtpWindow *smtp_win;
722 ModestDefaultAccountSettingsDialogPrivate *priv;
724 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
726 /* Create the window if necessary: */
727 smtp_win = modest_connection_specific_smtp_window_new ();
728 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
730 /* Show the window: */
731 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win), GTK_WINDOW (self));
732 gtk_widget_show (GTK_WIDGET (smtp_win));
736 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
740 /* Disable the OK button */
741 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
747 create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
748 GtkSizeGroup *security_title_sizegroup,
749 GtkSizeGroup *security_value_sizegroup)
751 ModestDefaultAccountSettingsDialogPrivate *priv;
752 gchar *smtp_caption_label;
753 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
755 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
757 /* The outgoing server widgets: */
758 if (!priv->entry_outgoingserver)
759 priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
760 /* Auto-capitalization is the default, so let's turn it off: */
762 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
764 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "*\n<small>(SMTP)</small>", NULL);
765 GtkWidget *caption = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
766 smtp_caption_label, TRUE, priv->entry_outgoingserver);
767 g_free (smtp_caption_label);
768 gtk_widget_show (priv->entry_outgoingserver);
769 connect_for_modified (self, priv->entry_outgoingserver);
770 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
771 gtk_widget_show (caption);
773 /* Outgoing security widgets */
774 priv->outgoing_security =
775 modest_toolkit_factory_create_security_options_view (modest_runtime_get_toolkit_factory (),
776 MODEST_SECURITY_OPTIONS_OUTGOING,
777 TRUE, security_title_sizegroup,
778 security_value_sizegroup);
779 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
781 gtk_widget_show (priv->outgoing_security);
782 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
783 G_CALLBACK (on_missing_mandatory_data), self);
785 GtkWidget *separator = gtk_hseparator_new ();
786 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_DEFAULT);
788 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
790 gtk_widget_show (separator);
792 /* connection-specific checkbox: */
793 if (!priv->checkbox_outgoing_smtp_specific) {
794 priv->checkbox_outgoing_smtp_specific =
795 modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
796 _("mcen_fi_advsetup_connection_smtp"));
797 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
800 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
801 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
803 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
805 /* Connection-specific SMTP-Severs Edit button: */
806 if (!priv->button_outgoing_smtp_servers)
807 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
809 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
810 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
812 gtk_widget_show (priv->button_outgoing_smtp_servers);
813 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers, FALSE, FALSE, 0);
815 /* Only enable the button when the checkbox is checked: */
816 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
817 priv->checkbox_outgoing_smtp_specific);
819 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
820 G_CALLBACK (on_button_outgoing_smtp_servers), self);
822 gtk_widget_show (GTK_WIDGET (box));
824 return GTK_WIDGET (box);
828 check_data (ModestDefaultAccountSettingsDialog *self)
830 gchar* account_title;
831 const gchar* email_address;
832 const gchar* hostname;
833 const gchar* hostname2;
834 ModestDefaultAccountSettingsDialogPrivate *priv;
836 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
838 /* Check that the title is not already in use: */
839 account_title = get_entered_account_title (self);
841 return FALSE; /* Should be prevented already anyway. */
843 if (g_strcmp0 (account_title, priv->original_account_title) != 0) {
844 gboolean name_in_use;
846 /* Check the changed title: */
847 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
851 /* Warn the user via a dialog: */
852 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
854 g_free (account_title);
859 g_free (account_title);
860 account_title = NULL;
862 /* Check that the email address is valid: */
863 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
864 if ((!email_address) || (strlen(email_address) == 0)) {
868 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
869 /* Warn the user via a dialog: */
870 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
872 /* Return focus to the email address entry: */
873 gtk_widget_grab_focus (priv->entry_user_email);
874 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
878 /* make sure the domain name for the incoming server is valid */
879 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
880 if ((!hostname) || (strlen(hostname) == 0)) {
884 if (!modest_text_utils_validate_domain_name (hostname)) {
885 /* Warn the user via a dialog: */
886 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
888 /* Return focus to the email address entry: */
889 gtk_widget_grab_focus (priv->entry_incomingserver);
890 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
894 /* make sure the domain name for the outgoing server is valid */
895 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
896 if ((!hostname2) || (strlen(hostname2) == 0)) {
900 if (!modest_text_utils_validate_domain_name (hostname2)) {
901 /* Warn the user via a dialog: */
902 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
904 /* Return focus to the email address entry: */
905 gtk_widget_grab_focus (priv->entry_outgoingserver);
906 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
914 on_delete_event (GtkWidget *widget,
918 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
919 ModestDefaultAccountSettingsDialogPrivate *priv;
920 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
922 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
924 /* Check if security widgets changed */
925 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
926 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
928 return modest_security_options_view_changed (incoming_sec, priv->settings) ||
929 modest_security_options_view_changed (outgoing_sec, priv->settings) ||
934 on_response (GtkDialog *wizard_dialog,
938 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
939 ModestDefaultAccountSettingsDialogPrivate *priv;
940 gboolean prevent_response = FALSE, sec_changed;
941 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
943 /* Dummy and delete buttons have a response id because they're
944 added with gtk_dialog_add_button in order to get the proper
946 if (response_id == RESPONSE_SIGNATURE_DUMMY) {
947 signature_button_clicked (self);
948 g_signal_stop_emission_by_name (wizard_dialog, "response");
952 if (response_id == RESPONSE_DELETE_DUMMY) {
953 if (!delete_button_clicked (self))
954 g_signal_stop_emission_by_name (wizard_dialog, "response");
958 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
959 enable_buttons (self);
961 /* Check if security widgets changed */
962 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
963 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
965 modest_security_options_view_changed (incoming_sec, priv->settings) ||
966 modest_security_options_view_changed (outgoing_sec, priv->settings);
968 /* Warn about unsaved changes: */
969 if ((response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) &&
970 (priv->modified || sec_changed)) {
971 gint dialog_response = modest_platform_run_confirmation_dialog (GTK_WINDOW (self),
972 _("imum_nc_wizard_confirm_lose_changes"));
973 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
976 if (dialog_response != GTK_RESPONSE_OK)
977 prevent_response = TRUE;
979 /* Check for invalid input: */
980 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
981 prevent_response = TRUE;
984 if (prevent_response) {
985 /* Don't let the dialog close */
986 g_signal_stop_emission_by_name (wizard_dialog, "response");
989 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
992 if (response_id == GTK_RESPONSE_OK) {
993 /* Try to save the changes if modified (NB #59251): */
994 if (priv->modified || sec_changed) {
995 if (save_configuration (self)) {
996 /* Do not show the account-saved dialog if we are just saving this
997 * temporarily, because from the user's point of view it will not
998 * really be saved (saved + enabled) until later
1000 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
1001 ModestServerAccountSettings *store_settings;
1002 ModestServerAccountSettings *transport_settings;
1003 const gchar *store_account_name;
1004 const gchar *transport_account_name;
1007 store_settings = modest_account_settings_get_store_settings (priv->settings);
1008 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1009 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1010 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1012 if (store_account_name) {
1013 modest_account_mgr_notify_account_update (priv->account_manager,
1014 store_account_name);
1016 if (transport_account_name) {
1017 modest_account_mgr_notify_account_update (priv->account_manager,
1018 transport_account_name);
1020 g_object_unref (store_settings);
1021 g_object_unref (transport_settings);
1023 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1026 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1033 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1035 ModestDefaultAccountSettingsDialogPrivate *priv;
1036 GtkWidget *scrollable;
1037 GtkWidget *separator;
1039 GtkSizeGroup* account_title_sizegroup;
1040 GtkSizeGroup* account_value_sizegroup;
1041 GtkSizeGroup *sec_title_sizegroup, *sec_value_sizegroup;
1043 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1045 #ifndef MODEST_TOOLKIT_HILDON2
1046 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1049 priv->incoming_security = NULL;
1050 priv->outgoing_security = NULL;
1052 priv->main_container = gtk_vbox_new (FALSE, 0);
1053 priv->settings = modest_account_settings_new ();
1055 /* Get the account manager object,
1056 * so we can check for existing accounts,
1057 * and create new accounts: */
1058 priv->account_manager = modest_runtime_get_account_mgr ();
1059 g_assert (priv->account_manager);
1060 g_object_ref (priv->account_manager);
1062 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1064 /* Create the common pages */
1065 account_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1066 account_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1067 priv->page_account_details = create_page_account_details (self, account_title_sizegroup, account_value_sizegroup);
1068 priv->page_user_details = create_page_user_details (self, account_title_sizegroup, account_value_sizegroup);
1069 g_object_unref (account_title_sizegroup);
1070 g_object_unref (account_value_sizegroup);
1073 /* Create size groups for security settings */
1074 sec_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1075 sec_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1077 /* Create incoming and outgoing "pages" */
1078 priv->page_incoming = create_page_incoming (self, sec_title_sizegroup, sec_value_sizegroup);
1079 priv->page_outgoing = create_page_outgoing (self, sec_title_sizegroup, sec_value_sizegroup);
1080 g_object_unref (sec_title_sizegroup);
1081 g_object_unref (sec_value_sizegroup);
1083 /* Add the notebook pages: */
1084 gtk_box_pack_start (GTK_BOX (priv->main_container),
1085 priv->page_account_details,
1087 gtk_box_pack_start (GTK_BOX (priv->main_container),
1088 priv->page_user_details,
1091 separator = gtk_hseparator_new ();
1092 #ifdef MAEMO_CHANGES
1093 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
1095 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1096 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1097 gtk_widget_show (separator);
1098 gtk_box_pack_start (GTK_BOX (priv->main_container),
1099 priv->page_incoming,
1101 separator = gtk_hseparator_new ();
1102 #ifdef MAEMO_CHANGES
1103 hildon_gtk_widget_set_theme_size (separator, HILDON_SIZE_AUTO);
1105 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1106 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1107 gtk_widget_show (separator);
1108 gtk_box_pack_start (GTK_BOX (priv->main_container),
1109 priv->page_outgoing,
1112 GtkDialog *dialog = GTK_DIALOG (self);
1113 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
1115 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1116 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1117 gtk_widget_show (align);
1118 gtk_container_add (GTK_CONTAINER (align), priv->main_container);
1120 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
1121 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (scrollable));
1122 gtk_widget_show (GTK_WIDGET (priv->main_container));
1123 gtk_widget_show (GTK_WIDGET (scrollable));
1125 /* Add the buttons: */
1126 gtk_dialog_add_button (GTK_DIALOG(self), _HL_SAVE, GTK_RESPONSE_OK);
1128 gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1130 /* Connect to the dialog's "response" and "delete-event" signals */
1131 g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self);
1132 g_signal_connect (G_OBJECT (self), "delete-event", G_CALLBACK (on_delete_event), self);
1134 priv->modified = FALSE;
1136 /* When this window is shown, hibernation should not be possible,
1137 * because there is no sensible way to save the state: */
1138 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1139 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1141 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1142 * while sending messages causes an error dialog and we have a lock */
1143 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1147 ModestAccountSettingsDialog*
1148 modest_default_account_settings_dialog_new (void)
1150 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1153 /** Update the UI with the stored account details, so they can be edited.
1154 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1157 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1158 ModestAccountSettings *settings)
1160 ModestServerAccountSettings *incoming_account;
1161 ModestServerAccountSettings *outgoing_account;
1162 ModestProtocolRegistry *protocol_registry;
1163 const gchar *account_name, *server_account_name;
1164 ModestDefaultAccountSettingsDialogPrivate *priv;
1166 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1167 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1169 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1170 protocol_registry = modest_runtime_get_protocol_registry ();
1172 account_name = modest_account_settings_get_account_name (settings);
1174 /* Save the account name so we can refer to it later: */
1175 if (priv->account_name)
1176 g_free (priv->account_name);
1177 priv->account_name = g_strdup (account_name);
1179 if (priv->account_name)
1180 gtk_widget_show (priv->button_delete);
1182 gtk_widget_hide (priv->button_delete);
1185 g_object_unref (priv->settings);
1186 priv->settings = g_object_ref (settings);
1188 /* Save the account title so we can refer to it if the user changes it: */
1189 if (priv->original_account_title)
1190 g_free (priv->original_account_title);
1191 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1193 /* Show the account data in the widgets: */
1195 /* Note that we never show the non-display name in the UI.
1196 * (Though the display name defaults to the non-display name at the start.) */
1197 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1198 null_means_empty (modest_account_settings_get_display_name (settings)));
1199 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1200 null_means_empty (modest_account_settings_get_fullname (settings)));
1201 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1202 null_means_empty (modest_account_settings_get_email_address (settings)));
1204 modest_togglable_set_active (priv->checkbox_leave_messages,
1205 modest_account_settings_get_leave_messages_on_server (settings));
1207 incoming_account = modest_account_settings_get_store_settings (settings);
1208 if (incoming_account) {
1209 const gchar *username, *password, *hostname, *proto_str, *account_title;
1210 gchar *proto_name, *title;
1211 ModestProtocolType incoming_protocol;
1213 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1214 modest_server_account_settings_get_protocol (incoming_account))) {
1215 gtk_widget_hide (priv->checkbox_leave_messages);
1217 gtk_widget_show (priv->checkbox_leave_messages);
1220 /* Remember this for later: */
1221 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1223 hostname = modest_server_account_settings_get_hostname (incoming_account);
1224 username = modest_server_account_settings_get_username (incoming_account);
1225 password = modest_server_account_settings_get_password (incoming_account);
1226 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1227 null_means_empty (username));
1228 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1229 null_means_empty (password));
1231 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1232 null_means_empty (hostname));
1234 /* Load security settings */
1235 modest_security_options_view_load_settings (
1236 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1238 gtk_widget_show (priv->incoming_security);
1240 /* Update the incoming label */
1241 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1244 /* Set window title according to account */
1245 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1246 proto_name = g_utf8_strup (proto_str, -1);
1247 account_title = modest_account_settings_get_display_name(settings);
1248 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1250 gtk_window_set_title (GTK_WINDOW (dialog), title);
1252 g_free (proto_name);
1254 g_object_unref (incoming_account);
1257 outgoing_account = modest_account_settings_get_transport_settings (settings);
1258 if (outgoing_account) {
1259 const gchar *hostname;
1260 const gchar *username;
1261 const gchar *password;
1262 ModestProtocolType outgoing_protocol;
1264 /* Remember this for later: */
1266 modest_server_account_settings_get_protocol (outgoing_account);
1268 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1269 username = modest_server_account_settings_get_username (outgoing_account);
1270 password = modest_server_account_settings_get_password (outgoing_account);
1271 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1272 null_means_empty (hostname));
1274 /* Load security settings */
1275 modest_security_options_view_load_settings (
1276 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1278 gtk_widget_show (priv->outgoing_security);
1280 const gboolean has_specific =
1281 modest_account_settings_get_use_connection_specific_smtp (settings);
1282 modest_togglable_set_active (priv->checkbox_outgoing_smtp_specific,
1284 g_object_unref (outgoing_account);
1287 /* Switch to user page */
1288 /* Check if we allow changes or not */
1289 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1290 if (server_account_name) {
1291 gboolean username_known;
1294 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1295 server_account_name);
1296 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1297 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1298 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1302 /* Unset the modified flag so we can detect changes later: */
1303 priv->modified = FALSE;
1307 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1309 const gchar* user_fullname;
1310 const gchar* emailaddress;
1311 ModestServerAccountSettings *store_settings;
1312 ModestServerAccountSettings *transport_settings;
1313 gboolean leave_on_server;
1314 const gchar* hostname;
1315 const gchar* username;
1316 const gchar* password;
1317 gchar* account_title;
1318 ModestDefaultAccountSettingsDialogPrivate *priv;
1319 const gchar* account_name;
1321 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1322 account_name = priv->account_name;
1324 /* Set the account data from the widgets: */
1325 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1326 modest_account_settings_set_fullname (priv->settings, user_fullname);
1328 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1329 modest_account_settings_set_email_address (priv->settings, emailaddress);
1332 if (priv->signature_dialog) {
1333 gboolean use_signature = FALSE;
1335 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1338 modest_account_settings_set_use_signature (priv->settings, use_signature);
1339 modest_account_settings_set_signature (priv->settings, signature);
1342 leave_on_server = modest_togglable_get_active (priv->checkbox_leave_messages);
1343 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1345 store_settings = modest_account_settings_get_store_settings (priv->settings);
1347 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1348 modest_server_account_settings_set_hostname (store_settings, hostname);
1350 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1351 modest_server_account_settings_set_username (store_settings, username);
1353 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1354 modest_server_account_settings_set_password (store_settings, password);
1356 /* Save security settings */
1357 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1360 g_object_unref (store_settings);
1363 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1365 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1366 modest_server_account_settings_set_hostname (transport_settings, hostname);
1368 /* Save security settings */
1369 modest_security_options_view_save_settings (
1370 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1373 /* Set the changed account title last, to simplify the previous code: */
1374 account_title = get_entered_account_title (dialog);
1376 return FALSE; /* Should be prevented already anyway. */
1378 /* if (strcmp (account_title, account_name) != 0) { */
1379 modest_account_settings_set_display_name (priv->settings, account_title);
1381 g_free (account_title);
1382 account_title = NULL;
1384 /* Save connection-specific SMTP server accounts: */
1385 modest_account_settings_set_use_connection_specific_smtp
1387 modest_togglable_get_active(priv->checkbox_outgoing_smtp_specific));
1389 /* this configuration is not persistent, we should not save */
1390 if (account_name != NULL)
1391 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1396 static gboolean entry_is_empty (GtkWidget *entry)
1401 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1402 if ((!text) || (strlen(text) == 0))
1405 /* Strip it of whitespace at the start and end: */
1406 gchar *stripped = g_strdup (text);
1407 stripped = g_strstrip (stripped);
1412 const gboolean result = (strlen (stripped) == 0);
1420 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1422 gboolean enable_ok = TRUE;
1423 ModestProtocolRegistry *protocol_registry;
1424 ModestSecurityOptionsView *sec_view;
1425 ModestDefaultAccountSettingsDialogPrivate *priv;
1427 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1429 /* The account details title is mandatory: */
1430 if (entry_is_empty(priv->entry_account_title))
1433 /* The user details username is mandatory: */
1434 if (enable_ok && entry_is_empty(priv->entry_user_username))
1437 /* The user details email address is mandatory: */
1438 if (enable_ok && entry_is_empty (priv->entry_user_email))
1441 /* The custom incoming server is mandatory: */
1442 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1445 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1447 modest_security_options_view_has_missing_mandatory_data (sec_view))
1450 /* The custom outgoing server is mandatory: */
1451 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1454 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1456 modest_security_options_view_has_missing_mandatory_data (sec_view))
1459 protocol_registry = modest_runtime_get_protocol_registry ();
1461 /* Enable the buttons,
1462 * identifying them via their associated response codes:
1464 GtkDialog *dialog_base = GTK_DIALOG (self);
1465 gtk_dialog_set_response_sensitive (dialog_base,
1471 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1473 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1474 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1476 object_class->dispose = modest_default_account_settings_dialog_dispose;
1477 object_class->finalize = modest_default_account_settings_dialog_finalize;
1481 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1483 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1485 iface->load_settings = modest_default_account_settings_dialog_load_settings;