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/gtkcheckbutton.h>
37 #include <gtk/gtkmessagedialog.h>
38 #include <gtk/gtkstock.h>
39 #include "modest-hildon-includes.h"
40 #include "modest-default-account-settings-dialog.h"
41 #include "modest-account-mgr.h"
42 #include "modest-secureauth-picker.h"
43 #include "widgets/modest-validating-entry.h"
44 #include "modest-text-utils.h"
45 #include "modest-account-mgr.h"
46 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
47 #include <modest-server-account-settings.h>
48 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
49 #include "modest-connection-specific-smtp-window.h"
50 #include "modest-signature-editor-dialog.h"
51 #include <modest-utils.h>
52 #include <modest-defs.h>
53 #include "modest-maemo-utils.h"
54 #include "modest-maemo-security-options-view.h"
55 #include "modest-ui-actions.h"
56 #include "widgets/modest-ui-constants.h"
57 #include <tny-account.h>
58 #include <tny-status.h>
60 #include <gconf/gconf-client.h>
61 #include <string.h> /* For strlen(). */
64 /* Include config.h so that _() works: */
70 #define PORT_MAX 65535
72 #define RESPONSE_DELETE_DUMMY 1
73 #define RESPONSE_SIGNATURE_DUMMY 2
75 static void modest_account_settings_dialog_init (gpointer g, gpointer iface_data);
77 G_DEFINE_TYPE_EXTENDED (ModestDefaultAccountSettingsDialog,
78 modest_default_account_settings_dialog,
81 G_IMPLEMENT_INTERFACE (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG,
82 modest_account_settings_dialog_init));
84 #define MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
85 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, ModestDefaultAccountSettingsDialogPrivate))
87 typedef struct _ModestDefaultAccountSettingsDialogPrivate ModestDefaultAccountSettingsDialogPrivate;
89 struct _ModestDefaultAccountSettingsDialogPrivate
91 /* Used by derived widgets to query existing accounts,
92 * and to create new accounts: */
93 ModestAccountMgr *account_manager;
94 ModestAccountSettings *settings;
97 gchar * account_name; /* This may not change. It is not user visible. */
98 ModestProtocolType incoming_protocol; /* This may not change. */
99 ModestProtocolType outgoing_protocol; /* This may not change. */
100 gchar * original_account_title;
102 ModestProtocolType protocol_authentication_incoming;
104 GtkWidget *main_container;
106 GtkWidget *page_account_details;
107 GtkWidget *entry_account_title;
108 GtkWidget *checkbox_leave_messages;
110 GtkWidget *page_user_details;
111 GtkWidget *entry_user_name;
112 GtkWidget *entry_user_username;
113 GtkWidget *entry_user_password;
114 GtkWidget *entry_user_email;
115 GtkWidget *button_signature;
116 GtkWidget *button_delete;
118 GtkWidget *page_complete_easysetup;
120 GtkWidget *page_incoming;
121 GtkWidget *caption_incoming;
122 GtkWidget *entry_incomingserver;
124 GtkWidget *page_outgoing;
125 GtkWidget *entry_outgoingserver;
126 GtkWidget *checkbox_outgoing_smtp_specific;
127 GtkWidget *button_outgoing_smtp_servers;
129 GtkWidget *signature_dialog;
131 GtkWidget *incoming_security;
132 GtkWidget *outgoing_security;
136 enable_buttons (ModestDefaultAccountSettingsDialog *self);
139 save_configuration (ModestDefaultAccountSettingsDialog *dialog);
141 static const gchar * null_means_empty (const gchar * str);
144 null_means_empty (const gchar * str)
146 return str ? str : "";
150 modest_default_account_settings_dialog_dispose (GObject *object)
152 if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
153 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
157 modest_default_account_settings_dialog_finalize (GObject *object)
159 ModestDefaultAccountSettingsDialog *self;
160 ModestDefaultAccountSettingsDialogPrivate *priv;
162 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
163 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
165 if (priv->account_name)
166 g_free (priv->account_name);
168 if (priv->original_account_title)
169 g_free (priv->original_account_title);
171 if (priv->account_manager)
172 g_object_unref (G_OBJECT (priv->account_manager));
174 if (priv->settings) {
175 g_object_unref (priv->settings);
176 priv->settings = NULL;
179 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
183 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
185 ModestDefaultAccountSettingsDialogPrivate *priv;
187 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
188 priv->modified = modified;
192 on_modified_picker_changed (HildonPickerButton *widget, gpointer user_data)
194 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
198 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
200 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
204 on_modified_checkbutton_toggled (GtkButton *button, gpointer user_data)
206 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
210 on_modified_number_editor_changed (ModestNumberEditor *number_editor, gint new_value, gpointer user_data)
212 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
216 on_number_editor_notify (ModestNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
218 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
219 gint value = modest_number_editor_get_value (editor);
221 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
224 /* Set a modified boolean whenever the widget is changed,
225 * so we can check for it later.
228 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
230 if (MODEST_IS_NUMBER_EDITOR (widget)) {
231 g_signal_connect (G_OBJECT (widget), "notify::value",
232 G_CALLBACK (on_modified_number_editor_changed), self);
233 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
235 else if (GTK_IS_ENTRY (widget)) {
236 g_signal_connect (G_OBJECT (widget), "changed",
237 G_CALLBACK (on_modified_entry_changed), self);
238 } else if (HILDON_IS_PICKER_BUTTON (widget)) {
239 g_signal_connect (G_OBJECT (widget), "value-changed",
240 G_CALLBACK (on_modified_picker_changed), self);
241 } else if (HILDON_IS_CHECK_BUTTON (widget)) {
242 g_signal_connect (G_OBJECT (widget), "toggled",
243 G_CALLBACK (on_modified_checkbutton_toggled), self);
248 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
250 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
252 enable_buttons(self);
256 create_captioned (ModestDefaultAccountSettingsDialog *self,
257 GtkSizeGroup *title_sizegroup,
258 GtkSizeGroup *value_sizegroup,
259 const gchar *label_text,
266 result = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
267 label_text, use_markup, control);
269 /* Connect to the appropriate changed signal for the widget,
270 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
272 if (GTK_IS_ENTRY (control)) {
273 g_signal_connect (G_OBJECT (control), "changed",
274 G_CALLBACK (on_caption_entry_changed), self);
282 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
286 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
287 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
289 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
296 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
300 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
301 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
303 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
311 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
313 modest_platform_information_banner (GTK_WIDGET (self), NULL,
314 _CS("ckdg_ib_maximum_characters_reached"));
318 create_page_account_details (ModestDefaultAccountSettingsDialog *self)
320 ModestDefaultAccountSettingsDialogPrivate *priv;
322 GtkSizeGroup* title_sizegroup;
323 GtkSizeGroup* value_sizegroup;
326 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
327 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
328 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
329 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
331 /* The description widgets: */
332 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
333 /* Do use auto-capitalization: */
334 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
335 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
336 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
337 _("mcen_fi_account_title"), FALSE,
338 priv->entry_account_title);
339 gtk_widget_show (priv->entry_account_title);
340 connect_for_modified (self, priv->entry_account_title);
341 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
342 gtk_widget_show (caption);
344 /* Prevent the use of some characters in the account title,
345 * as required by our UI specification: */
346 GList *list_prevent = NULL;
347 list_prevent = g_list_append (list_prevent, "\\");
348 list_prevent = g_list_append (list_prevent, "/");
349 list_prevent = g_list_append (list_prevent, ":");
350 list_prevent = g_list_append (list_prevent, "*");
351 list_prevent = g_list_append (list_prevent, "?");
352 list_prevent = g_list_append (list_prevent, "\"");
353 list_prevent = g_list_append (list_prevent, "<");
354 list_prevent = g_list_append (list_prevent, ">");
355 list_prevent = g_list_append (list_prevent, "|");
356 list_prevent = g_list_append (list_prevent, "^");
357 modest_validating_entry_set_unallowed_characters (
358 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
359 g_list_free (list_prevent);
360 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
361 on_entry_invalid_account_title_character, self);
363 /* Set max length as in the UI spec:
364 * The UI spec seems to want us to show a dialog if we hit the maximum. */
365 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
366 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
369 hbox = gtk_hbox_new (TRUE, 0);
371 /* The leave-messages widgets: */
372 if(!priv->checkbox_leave_messages) {
373 priv->checkbox_leave_messages =
374 hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
375 gtk_button_set_label (GTK_BUTTON (priv->checkbox_leave_messages),
376 _("mcen_fi_advsetup_leave_on_server"));
377 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_leave_messages), 0.0, 0.5);
379 connect_for_modified (self, priv->checkbox_leave_messages);
380 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_leave_messages, FALSE, FALSE, 0);
381 gtk_widget_show (priv->checkbox_leave_messages);
383 g_object_unref (title_sizegroup);
384 g_object_unref (value_sizegroup);
386 gtk_widget_show (GTK_WIDGET (box));
388 return GTK_WIDGET (box);
392 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
394 ModestDefaultAccountSettingsDialogPrivate *priv;
395 const gchar* account_title;
397 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
398 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
400 if (!account_title || (strlen (account_title) == 0))
403 /* Strip it of whitespace at the start and end: */
404 gchar *result = g_strdup (account_title);
405 result = g_strstrip (result);
410 if (strlen (result) == 0) {
421 signature_button_clicked (ModestDefaultAccountSettingsDialog *self)
424 ModestDefaultAccountSettingsDialogPrivate *priv;
426 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
428 /* Create the window, if necessary: */
429 if (!(priv->signature_dialog)) {
430 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
432 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
433 const gchar *signature = modest_account_settings_get_signature(priv->settings);
434 gchar* account_title = get_entered_account_title (self);
435 modest_signature_editor_dialog_set_settings (
436 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
437 use_signature, signature, account_title);
439 g_free (account_title);
440 account_title = NULL;
444 /* Show the window: */
445 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
446 GTK_WINDOW (priv->signature_dialog), GTK_WINDOW (self));
448 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
449 gtk_widget_hide (priv->signature_dialog);
450 if (response != GTK_RESPONSE_OK) {
451 /* Destroy the widget now, and its data: */
452 gtk_widget_destroy (priv->signature_dialog);
453 priv->signature_dialog = NULL;
455 /* Mark modified, so we use the dialog's data later: */
456 priv->modified = TRUE;
461 delete_button_clicked (ModestDefaultAccountSettingsDialog *self)
463 ModestDefaultAccountSettingsDialogPrivate *priv;
464 gchar *account_title;
467 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
470 account_title = g_strdup (priv->original_account_title);
472 account_title = get_entered_account_title (self);
474 removed = modest_ui_actions_on_delete_account (GTK_WINDOW (self),
476 (const gchar *) account_title);
477 g_free (account_title);
483 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
485 ModestDefaultAccountSettingsDialogPrivate *priv;
487 GtkSizeGroup* title_sizegroup;
488 GtkSizeGroup* value_sizegroup;
490 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
492 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
493 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
494 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
496 /* The name widgets: */
497 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
499 /* Auto-capitalization is the default, so let's turn it off: */
500 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
501 HILDON_GTK_INPUT_MODE_FULL |
502 HILDON_GTK_INPUT_MODE_AUTOCAP);
503 /* Set max length as in the UI spec:
504 * The UI spec seems to want us to show a dialog if we hit the maximum. */
505 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
506 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
509 create_captioned (self, title_sizegroup, value_sizegroup,
510 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
511 gtk_widget_show (priv->entry_user_name);
512 connect_for_modified (self, priv->entry_user_name);
513 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
514 gtk_widget_show (caption);
517 /* Prevent the use of some characters in the name,
518 * as required by our UI specification: */
519 GList *list_prevent = NULL;
520 list_prevent = g_list_append (list_prevent, "<");
521 list_prevent = g_list_append (list_prevent, ">");
522 modest_validating_entry_set_unallowed_characters (
523 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
524 g_list_free (list_prevent);
525 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
526 on_entry_invalid_fullname_character, self);
528 /* The username widgets: */
529 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
530 /* Auto-capitalization is the default, so let's turn it off: */
531 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
532 caption = create_captioned (self, title_sizegroup, value_sizegroup,
533 _("mail_fi_username"), FALSE,
534 priv->entry_user_username);
535 gtk_widget_show (priv->entry_user_username);
536 connect_for_modified (self, priv->entry_user_username);
537 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
538 gtk_widget_show (caption);
540 /* Prevent the use of some characters in the username,
541 * as required by our UI specification: */
542 modest_validating_entry_set_unallowed_characters_whitespace (
543 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
544 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
545 modest_utils_on_entry_invalid_character,
548 /* Set max length as in the UI spec:
549 * The UI spec seems to want us to show a dialog if we hit the maximum. */
550 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
551 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
554 /* The password widgets: */
555 priv->entry_user_password = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
556 /* Auto-capitalization is the default, so let's turn it off: */
557 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
558 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
559 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
560 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
561 caption = create_captioned (self, title_sizegroup, value_sizegroup,
562 _("mail_fi_password"), FALSE, priv->entry_user_password);
563 gtk_widget_show (priv->entry_user_password);
564 connect_for_modified (self, priv->entry_user_password);
565 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
566 gtk_widget_show (caption);
568 /* The email address widgets: */
569 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
570 /* Auto-capitalization is the default, so let's turn it off: */
571 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
572 caption = create_captioned (self, title_sizegroup, value_sizegroup,
573 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
574 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
575 gtk_widget_show (priv->entry_user_email);
576 connect_for_modified (self, priv->entry_user_email);
577 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
578 gtk_widget_show (caption);
580 /* Set max length as in the UI spec:
581 * The UI spec seems to want us to show a dialog if we hit the maximum. */
582 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
583 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
587 if (!priv->button_delete)
588 priv->button_delete = gtk_dialog_add_button (GTK_DIALOG (self),
589 _HL("wdgt_bd_delete"),
590 RESPONSE_DELETE_DUMMY);
592 /* Signature button: */
593 if (!priv->button_signature)
594 priv->button_signature = gtk_dialog_add_button (GTK_DIALOG (self),
595 _("mcen_bd_email_signature"),
596 RESPONSE_SIGNATURE_DUMMY);
597 gtk_widget_show (priv->button_signature);
599 g_object_unref (title_sizegroup);
600 g_object_unref (value_sizegroup);
602 gtk_widget_show (GTK_WIDGET (box));
604 return GTK_WIDGET (box);
607 /* Change the caption title for the incoming server */
609 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
610 ModestProtocolType protocol_type)
612 ModestProtocolRegistry *protocol_registry;
613 ModestProtocol *protocol;
614 const gchar *protocol_display_name;
615 gchar* incomingserver_title;
616 ModestDefaultAccountSettingsDialogPrivate *priv;
618 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
620 protocol_registry = modest_runtime_get_protocol_registry ();
621 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
622 protocol_display_name = modest_protocol_get_display_name (protocol);
623 incomingserver_title = g_strconcat(_("mcen_li_emailsetup_servertype"), "*",
624 "\n<small>(", protocol_display_name, ")</small>", NULL);
626 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
627 g_free (incomingserver_title);
630 /* The size groups passed as arguments are only used by the security settings */
632 create_page_incoming (ModestDefaultAccountSettingsDialog *self,
633 GtkSizeGroup *security_title_sizegroup,
634 GtkSizeGroup *security_value_sizegroup)
636 ModestDefaultAccountSettingsDialogPrivate *priv;
639 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
641 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
643 /* The incoming server widgets: */
644 if(!priv->entry_incomingserver)
645 priv->entry_incomingserver = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
646 /* Auto-capitalization is the default, so let's turn it off: */
647 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
649 if (priv->caption_incoming)
650 gtk_widget_destroy (priv->caption_incoming);
652 /* The caption title will be updated in update_incoming_server_title().
653 * so this default text will never be seen: */
654 /* (Note: Changing the title seems pointless. murrayc) */
655 priv->caption_incoming = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
656 "Incoming Server", FALSE, priv->entry_incomingserver);
657 gtk_widget_show (priv->entry_incomingserver);
658 connect_for_modified (self, priv->entry_incomingserver);
659 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
660 gtk_widget_show (priv->caption_incoming);
662 /* Incoming security widgets */
663 priv->incoming_security =
664 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
665 TRUE, security_title_sizegroup,
666 security_value_sizegroup);
667 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
670 gtk_widget_show (priv->incoming_security);
671 gtk_widget_show (GTK_WIDGET (box));
673 return GTK_WIDGET (box);
677 on_check_button_clicked (GtkButton *button, gpointer user_data)
679 GtkWidget *widget = GTK_WIDGET (user_data);
681 /* Enable the widget only if the check button is active: */
682 const gboolean enable = hildon_check_button_get_active (HILDON_CHECK_BUTTON (button));
683 gtk_widget_set_sensitive (widget, enable);
686 /* Make the sensitivity of a widget depend on a check button.
689 enable_widget_for_checkbutton (GtkWidget *widget, GtkButton* button)
691 g_signal_connect (G_OBJECT (button), "clicked",
692 G_CALLBACK (on_check_button_clicked), widget);
694 /* Set the starting sensitivity: */
695 on_check_button_clicked (button, widget);
699 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
701 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
702 ModestConnectionSpecificSmtpWindow *smtp_win;
703 ModestDefaultAccountSettingsDialogPrivate *priv;
705 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
707 /* Create the window if necessary: */
708 smtp_win = modest_connection_specific_smtp_window_new ();
709 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
711 /* Show the window: */
712 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win), GTK_WINDOW (self));
713 gtk_widget_show (GTK_WIDGET (smtp_win));
717 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
721 /* Disable the OK button */
722 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
728 create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
729 GtkSizeGroup *security_title_sizegroup,
730 GtkSizeGroup *security_value_sizegroup)
732 ModestDefaultAccountSettingsDialogPrivate *priv;
733 gchar *smtp_caption_label;
734 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
736 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
738 /* The outgoing server widgets: */
739 if (!priv->entry_outgoingserver)
740 priv->entry_outgoingserver =
741 hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
742 /* Auto-capitalization is the default, so let's turn it off: */
743 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
744 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
745 GtkWidget *caption = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
746 smtp_caption_label, TRUE, priv->entry_outgoingserver);
747 g_free (smtp_caption_label);
748 gtk_widget_show (priv->entry_outgoingserver);
749 connect_for_modified (self, priv->entry_outgoingserver);
750 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
751 gtk_widget_show (caption);
753 /* Outgoing security widgets */
754 priv->outgoing_security =
755 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
756 TRUE, security_title_sizegroup,
757 security_value_sizegroup);
758 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
760 gtk_widget_show (priv->outgoing_security);
761 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
762 G_CALLBACK (on_missing_mandatory_data), self);
764 GtkWidget *separator = gtk_hseparator_new ();
765 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_DEFAULT);
766 gtk_widget_show (separator);
768 /* connection-specific checkbox: */
769 if (!priv->checkbox_outgoing_smtp_specific) {
770 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (MODEST_EDITABLE_SIZE);
771 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
773 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
774 _("mcen_fi_advsetup_connection_smtp"));
775 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific), 0.0, 0.5);
777 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
778 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
780 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
782 /* Connection-specific SMTP-Severs Edit button: */
783 if (!priv->button_outgoing_smtp_servers)
784 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
785 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
786 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
787 gtk_widget_show (priv->button_outgoing_smtp_servers);
788 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers, FALSE, FALSE, 0);
790 /* Only enable the button when the checkbox is checked: */
791 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
792 GTK_BUTTON (priv->checkbox_outgoing_smtp_specific));
794 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
795 G_CALLBACK (on_button_outgoing_smtp_servers), self);
797 gtk_widget_show (GTK_WIDGET (box));
799 return GTK_WIDGET (box);
803 check_data (ModestDefaultAccountSettingsDialog *self)
805 gchar* account_title;
806 const gchar* email_address;
807 const gchar* hostname;
808 const gchar* hostname2;
809 ModestDefaultAccountSettingsDialogPrivate *priv;
811 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
813 /* Check that the title is not already in use: */
814 account_title = get_entered_account_title (self);
816 return FALSE; /* Should be prevented already anyway. */
818 if (strcmp(account_title, priv->original_account_title) != 0) {
819 gboolean name_in_use;
821 /* Check the changed title: */
822 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
826 /* Warn the user via a dialog: */
827 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
829 g_free (account_title);
834 g_free (account_title);
835 account_title = NULL;
837 /* Check that the email address is valid: */
838 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
839 if ((!email_address) || (strlen(email_address) == 0)) {
843 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
844 /* Warn the user via a dialog: */
845 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
847 /* Return focus to the email address entry: */
848 gtk_widget_grab_focus (priv->entry_user_email);
849 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
853 /* make sure the domain name for the incoming server is valid */
854 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
855 if ((!hostname) || (strlen(hostname) == 0)) {
859 if (!modest_text_utils_validate_domain_name (hostname)) {
860 /* Warn the user via a dialog: */
861 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
863 /* Return focus to the email address entry: */
864 gtk_widget_grab_focus (priv->entry_incomingserver);
865 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
869 /* make sure the domain name for the outgoing server is valid */
870 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
871 if ((!hostname2) || (strlen(hostname2) == 0)) {
875 if (!modest_text_utils_validate_domain_name (hostname2)) {
876 /* Warn the user via a dialog: */
877 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
879 /* Return focus to the email address entry: */
880 gtk_widget_grab_focus (priv->entry_outgoingserver);
881 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
889 on_delete_event (GtkWidget *widget,
893 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
894 ModestDefaultAccountSettingsDialogPrivate *priv;
895 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
897 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
899 /* Check if security widgets changed */
900 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
901 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
903 return modest_security_options_view_changed (incoming_sec, priv->settings) ||
904 modest_security_options_view_changed (outgoing_sec, priv->settings) ||
909 on_response (GtkDialog *wizard_dialog,
913 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
914 ModestDefaultAccountSettingsDialogPrivate *priv;
915 gboolean prevent_response = FALSE, sec_changed;
916 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
918 /* Dummy and delete buttons have a response id because they're
919 added with gtk_dialog_add_button in order to get the proper
921 if (response_id == RESPONSE_SIGNATURE_DUMMY) {
922 signature_button_clicked (self);
923 g_signal_stop_emission_by_name (wizard_dialog, "response");
927 if (response_id == RESPONSE_DELETE_DUMMY) {
928 if (!delete_button_clicked (self))
929 g_signal_stop_emission_by_name (wizard_dialog, "response");
933 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
934 enable_buttons (self);
936 /* Check if security widgets changed */
937 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
938 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
940 modest_security_options_view_changed (incoming_sec, priv->settings) ||
941 modest_security_options_view_changed (outgoing_sec, priv->settings);
943 /* Warn about unsaved changes: */
944 if ((response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) &&
945 (priv->modified || sec_changed)) {
946 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
947 _("imum_nc_wizard_confirm_lose_changes")));
948 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
950 const gint dialog_response = gtk_dialog_run (dialog);
951 gtk_widget_destroy (GTK_WIDGET (dialog));
953 if (dialog_response != GTK_RESPONSE_OK)
954 prevent_response = TRUE;
956 /* Check for invalid input: */
957 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
958 prevent_response = TRUE;
961 if (prevent_response) {
962 /* Don't let the dialog close */
963 g_signal_stop_emission_by_name (wizard_dialog, "response");
966 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
969 if (response_id == GTK_RESPONSE_OK) {
970 /* Try to save the changes if modified (NB #59251): */
971 if (priv->modified || sec_changed) {
972 if (save_configuration (self)) {
973 /* Do not show the account-saved dialog if we are just saving this
974 * temporarily, because from the user's point of view it will not
975 * really be saved (saved + enabled) until later
977 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
978 ModestServerAccountSettings *store_settings;
979 ModestServerAccountSettings *transport_settings;
980 const gchar *store_account_name;
981 const gchar *transport_account_name;
984 store_settings = modest_account_settings_get_store_settings (priv->settings);
985 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
986 store_account_name = modest_server_account_settings_get_account_name (store_settings);
987 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
989 if (store_account_name) {
990 modest_account_mgr_notify_account_update (priv->account_manager,
993 if (transport_account_name) {
994 modest_account_mgr_notify_account_update (priv->account_manager,
995 transport_account_name);
997 g_object_unref (store_settings);
998 g_object_unref (transport_settings);
1000 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1003 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1010 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1012 ModestDefaultAccountSettingsDialogPrivate *priv;
1013 GtkWidget *pannable;
1014 GtkWidget *separator;
1016 GtkSizeGroup *sec_title_sizegroup, *sec_value_sizegroup;
1018 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1020 priv->incoming_security = NULL;
1021 priv->outgoing_security = NULL;
1023 priv->main_container = gtk_vbox_new (FALSE, 0);
1024 priv->settings = modest_account_settings_new ();
1026 /* Get the account manager object,
1027 * so we can check for existing accounts,
1028 * and create new accounts: */
1029 priv->account_manager = modest_runtime_get_account_mgr ();
1030 g_assert (priv->account_manager);
1031 g_object_ref (priv->account_manager);
1033 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1035 /* Create the common pages */
1036 priv->page_account_details = create_page_account_details (self);
1037 priv->page_user_details = create_page_user_details (self);
1039 /* Create size groups for security settings */
1040 sec_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1041 sec_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1043 /* Create incoming and outgoing "pages" */
1044 priv->page_incoming = create_page_incoming (self, sec_title_sizegroup, sec_value_sizegroup);
1045 priv->page_outgoing = create_page_outgoing (self, sec_title_sizegroup, sec_value_sizegroup);
1046 g_object_unref (sec_title_sizegroup);
1047 g_object_unref (sec_value_sizegroup);
1049 /* Add the notebook pages: */
1050 gtk_box_pack_start (GTK_BOX (priv->main_container),
1051 priv->page_account_details,
1053 gtk_box_pack_start (GTK_BOX (priv->main_container),
1054 priv->page_user_details,
1057 separator = gtk_hseparator_new ();
1058 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1059 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1060 gtk_widget_show (separator);
1061 gtk_box_pack_start (GTK_BOX (priv->main_container),
1062 priv->page_incoming,
1064 separator = gtk_hseparator_new ();
1065 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1066 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1067 gtk_widget_show (separator);
1068 gtk_box_pack_start (GTK_BOX (priv->main_container),
1069 priv->page_outgoing,
1072 GtkDialog *dialog = GTK_DIALOG (self);
1073 pannable = hildon_pannable_area_new ();
1074 g_object_set (G_OBJECT (pannable), "initial-hint", TRUE, NULL);
1076 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1077 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1078 gtk_widget_show (align);
1079 gtk_container_add (GTK_CONTAINER (align), priv->main_container);
1081 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
1082 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (pannable));
1083 gtk_widget_show (GTK_WIDGET (priv->main_container));
1084 gtk_widget_show (GTK_WIDGET (pannable));
1086 /* Add the buttons: */
1087 gtk_dialog_add_button (GTK_DIALOG(self), _HL("wdgt_bd_save"), GTK_RESPONSE_OK);
1089 gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1091 /* Connect to the dialog's "response" and "delete-event" signals */
1092 g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self);
1093 g_signal_connect (G_OBJECT (self), "delete-event", G_CALLBACK (on_delete_event), self);
1095 priv->modified = FALSE;
1097 /* When this window is shown, hibernation should not be possible,
1098 * because there is no sensible way to save the state: */
1099 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1100 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1102 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1103 * while sending messages causes an error dialog and we have a lock */
1104 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1108 ModestAccountSettingsDialog*
1109 modest_default_account_settings_dialog_new (void)
1111 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1114 /** Update the UI with the stored account details, so they can be edited.
1115 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1118 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1119 ModestAccountSettings *settings)
1121 ModestServerAccountSettings *incoming_account;
1122 ModestServerAccountSettings *outgoing_account;
1123 ModestProtocolRegistry *protocol_registry;
1124 const gchar *account_name, *server_account_name;
1125 ModestDefaultAccountSettingsDialogPrivate *priv;
1127 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1128 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1130 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1131 protocol_registry = modest_runtime_get_protocol_registry ();
1133 account_name = modest_account_settings_get_account_name (settings);
1135 /* Save the account name so we can refer to it later: */
1136 if (priv->account_name)
1137 g_free (priv->account_name);
1138 priv->account_name = g_strdup (account_name);
1140 if (priv->account_name)
1141 gtk_widget_show (priv->button_delete);
1143 gtk_widget_hide (priv->button_delete);
1146 g_object_unref (priv->settings);
1147 priv->settings = g_object_ref (settings);
1149 /* Save the account title so we can refer to it if the user changes it: */
1150 if (priv->original_account_title)
1151 g_free (priv->original_account_title);
1152 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1154 /* Show the account data in the widgets: */
1156 /* Note that we never show the non-display name in the UI.
1157 * (Though the display name defaults to the non-display name at the start.) */
1158 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1159 null_means_empty (modest_account_settings_get_display_name (settings)));
1160 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1161 null_means_empty (modest_account_settings_get_fullname (settings)));
1162 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1163 null_means_empty (modest_account_settings_get_email_address (settings)));
1165 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_leave_messages),
1166 modest_account_settings_get_leave_messages_on_server (settings));
1168 incoming_account = modest_account_settings_get_store_settings (settings);
1169 if (incoming_account) {
1170 const gchar *username, *password, *hostname, *proto_str, *account_title;
1171 gchar *proto_name, *title;
1172 ModestProtocolType incoming_protocol;
1174 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1175 modest_server_account_settings_get_protocol (incoming_account))) {
1176 gtk_widget_hide (priv->checkbox_leave_messages);
1178 gtk_widget_show (priv->checkbox_leave_messages);
1181 /* Remember this for later: */
1182 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1184 hostname = modest_server_account_settings_get_hostname (incoming_account);
1185 username = modest_server_account_settings_get_username (incoming_account);
1186 password = modest_server_account_settings_get_password (incoming_account);
1187 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1188 null_means_empty (username));
1189 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1190 null_means_empty (password));
1192 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1193 null_means_empty (hostname));
1195 /* Load security settings */
1196 modest_security_options_view_load_settings (
1197 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1199 gtk_widget_show (priv->incoming_security);
1201 /* Update the incoming label */
1202 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1205 /* Set window title according to account */
1206 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1207 proto_name = g_utf8_strup (proto_str, -1);
1208 account_title = modest_account_settings_get_display_name(settings);
1209 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1211 gtk_window_set_title (GTK_WINDOW (dialog), title);
1213 g_free (proto_name);
1215 g_object_unref (incoming_account);
1218 outgoing_account = modest_account_settings_get_transport_settings (settings);
1219 if (outgoing_account) {
1220 const gchar *hostname;
1221 const gchar *username;
1222 const gchar *password;
1223 ModestProtocolType outgoing_protocol;
1225 /* Remember this for later: */
1227 modest_server_account_settings_get_protocol (outgoing_account);
1229 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1230 username = modest_server_account_settings_get_username (outgoing_account);
1231 password = modest_server_account_settings_get_password (outgoing_account);
1232 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1233 null_means_empty (hostname));
1235 /* Load security settings */
1236 modest_security_options_view_load_settings (
1237 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1239 gtk_widget_show (priv->outgoing_security);
1241 const gboolean has_specific =
1242 modest_account_settings_get_use_connection_specific_smtp (settings);
1243 hildon_check_button_set_active (
1244 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1246 g_object_unref (outgoing_account);
1249 /* Switch to user page */
1250 /* Check if we allow changes or not */
1251 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1252 if (server_account_name) {
1253 gboolean username_known;
1256 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1257 server_account_name);
1258 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1259 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1260 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1264 /* Unset the modified flag so we can detect changes later: */
1265 priv->modified = FALSE;
1269 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1271 const gchar* user_fullname;
1272 const gchar* emailaddress;
1273 ModestServerAccountSettings *store_settings;
1274 ModestServerAccountSettings *transport_settings;
1275 gboolean leave_on_server;
1276 const gchar* hostname;
1277 const gchar* username;
1278 const gchar* password;
1279 gchar* account_title;
1280 ModestDefaultAccountSettingsDialogPrivate *priv;
1281 const gchar* account_name;
1283 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1284 account_name = priv->account_name;
1286 /* Set the account data from the widgets: */
1287 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1288 modest_account_settings_set_fullname (priv->settings, user_fullname);
1290 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1291 modest_account_settings_set_email_address (priv->settings, emailaddress);
1294 if (priv->signature_dialog) {
1295 gboolean use_signature = FALSE;
1297 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1300 modest_account_settings_set_use_signature (priv->settings, use_signature);
1301 modest_account_settings_set_signature (priv->settings, signature);
1304 leave_on_server = hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox_leave_messages));
1305 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1307 store_settings = modest_account_settings_get_store_settings (priv->settings);
1309 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1310 modest_server_account_settings_set_hostname (store_settings, hostname);
1312 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1313 modest_server_account_settings_set_username (store_settings, username);
1315 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1316 modest_server_account_settings_set_password (store_settings, password);
1318 /* Save security settings */
1319 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1322 g_object_unref (store_settings);
1325 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1327 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1328 modest_server_account_settings_set_hostname (transport_settings, hostname);
1330 /* Save security settings */
1331 modest_security_options_view_save_settings (
1332 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1335 /* Set the changed account title last, to simplify the previous code: */
1336 account_title = get_entered_account_title (dialog);
1338 return FALSE; /* Should be prevented already anyway. */
1340 /* if (strcmp (account_title, account_name) != 0) { */
1341 modest_account_settings_set_display_name (priv->settings, account_title);
1343 g_free (account_title);
1344 account_title = NULL;
1346 /* Save connection-specific SMTP server accounts: */
1347 modest_account_settings_set_use_connection_specific_smtp
1349 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1351 /* this configuration is not persistent, we should not save */
1352 if (account_name != NULL)
1353 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1358 static gboolean entry_is_empty (GtkWidget *entry)
1363 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1364 if ((!text) || (strlen(text) == 0))
1367 /* Strip it of whitespace at the start and end: */
1368 gchar *stripped = g_strdup (text);
1369 stripped = g_strstrip (stripped);
1374 const gboolean result = (strlen (stripped) == 0);
1382 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1384 gboolean enable_ok = TRUE;
1385 ModestProtocolRegistry *protocol_registry;
1386 ModestSecurityOptionsView *sec_view;
1387 ModestDefaultAccountSettingsDialogPrivate *priv;
1389 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1391 /* The account details title is mandatory: */
1392 if (entry_is_empty(priv->entry_account_title))
1395 /* The user details username is mandatory: */
1396 if (enable_ok && entry_is_empty(priv->entry_user_username))
1399 /* The user details email address is mandatory: */
1400 if (enable_ok && entry_is_empty (priv->entry_user_email))
1403 /* The custom incoming server is mandatory: */
1404 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1407 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1409 modest_security_options_view_has_missing_mandatory_data (sec_view))
1412 /* The custom outgoing server is mandatory: */
1413 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1416 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1418 modest_security_options_view_has_missing_mandatory_data (sec_view))
1421 protocol_registry = modest_runtime_get_protocol_registry ();
1423 /* Enable the buttons,
1424 * identifying them via their associated response codes:
1426 GtkDialog *dialog_base = GTK_DIALOG (self);
1427 gtk_dialog_set_response_sensitive (dialog_base,
1433 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1435 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1436 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1438 object_class->dispose = modest_default_account_settings_dialog_dispose;
1439 object_class->finalize = modest_default_account_settings_dialog_finalize;
1443 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1445 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1447 iface->load_settings = modest_default_account_settings_dialog_load_settings;