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-retrieve-picker.h"
45 #include "modest-limit-retrieve-picker.h"
46 #include "modest-text-utils.h"
47 #include "modest-account-mgr.h"
48 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
49 #include <modest-server-account-settings.h>
50 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
51 #include "modest-connection-specific-smtp-window.h"
52 #include "modest-signature-editor-dialog.h"
53 #include <modest-utils.h>
54 #include <modest-defs.h>
55 #include "modest-maemo-utils.h"
56 #include "modest-maemo-security-options-view.h"
57 #include "modest-ui-actions.h"
58 #include "widgets/modest-ui-constants.h"
59 #include <tny-account.h>
60 #include <tny-status.h>
62 #include <gconf/gconf-client.h>
63 #include <string.h> /* For strlen(). */
66 /* Include config.h so that _() works: */
72 #define PORT_MAX 65535
74 static void modest_account_settings_dialog_init (gpointer g, gpointer iface_data);
76 G_DEFINE_TYPE_EXTENDED (ModestDefaultAccountSettingsDialog,
77 modest_default_account_settings_dialog,
80 G_IMPLEMENT_INTERFACE (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG,
81 modest_account_settings_dialog_init));
83 #define MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
84 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, ModestDefaultAccountSettingsDialogPrivate))
86 typedef struct _ModestDefaultAccountSettingsDialogPrivate ModestDefaultAccountSettingsDialogPrivate;
88 struct _ModestDefaultAccountSettingsDialogPrivate
90 /* Used by derived widgets to query existing accounts,
91 * and to create new accounts: */
92 ModestAccountMgr *account_manager;
93 ModestAccountSettings *settings;
96 gchar * account_name; /* This may not change. It is not user visible. */
97 ModestProtocolType incoming_protocol; /* This may not change. */
98 ModestProtocolType outgoing_protocol; /* This may not change. */
99 gchar * original_account_title;
101 ModestProtocolType protocol_authentication_incoming;
103 GtkWidget *main_container;
105 GtkWidget *page_account_details;
106 GtkWidget *entry_account_title;
107 GtkWidget *retrieve_picker;
108 GtkWidget *limit_retrieve_picker;
109 GtkWidget *checkbox_leave_messages;
111 GtkWidget *page_user_details;
112 GtkWidget *entry_user_name;
113 GtkWidget *entry_user_username;
114 GtkWidget *entry_user_password;
115 GtkWidget *entry_user_email;
116 /* GtkWidget *entry_incoming_port; */
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 const gchar * null_means_empty (const gchar * str);
146 null_means_empty (const gchar * str)
148 return str ? str : "";
152 modest_default_account_settings_dialog_dispose (GObject *object)
154 if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
155 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
159 modest_default_account_settings_dialog_finalize (GObject *object)
161 ModestDefaultAccountSettingsDialog *self;
162 ModestDefaultAccountSettingsDialogPrivate *priv;
164 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
165 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
167 if (priv->account_name)
168 g_free (priv->account_name);
170 if (priv->original_account_title)
171 g_free (priv->original_account_title);
173 if (priv->account_manager)
174 g_object_unref (G_OBJECT (priv->account_manager));
176 if (priv->settings) {
177 g_object_unref (priv->settings);
178 priv->settings = NULL;
181 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
185 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
187 ModestDefaultAccountSettingsDialogPrivate *priv;
189 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
190 priv->modified = modified;
194 on_modified_picker_changed (HildonPickerButton *widget, gpointer user_data)
196 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
200 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
202 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
206 on_modified_checkbutton_toggled (GtkButton *button, gpointer user_data)
208 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
212 on_modified_number_editor_changed (ModestNumberEditor *number_editor, gint new_value, gpointer user_data)
214 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
218 on_number_editor_notify (ModestNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
220 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
221 gint value = modest_number_editor_get_value (editor);
223 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
226 /* Set a modified boolean whenever the widget is changed,
227 * so we can check for it later.
230 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
232 if (MODEST_IS_NUMBER_EDITOR (widget)) {
233 g_signal_connect (G_OBJECT (widget), "notify::value",
234 G_CALLBACK (on_modified_number_editor_changed), self);
235 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
237 else if (GTK_IS_ENTRY (widget)) {
238 g_signal_connect (G_OBJECT (widget), "changed",
239 G_CALLBACK (on_modified_entry_changed), self);
240 } else if (HILDON_IS_PICKER_BUTTON (widget)) {
241 g_signal_connect (G_OBJECT (widget), "value-changed",
242 G_CALLBACK (on_modified_picker_changed), self);
243 } else if (HILDON_IS_CHECK_BUTTON (widget)) {
244 g_signal_connect (G_OBJECT (widget), "toggled",
245 G_CALLBACK (on_modified_checkbutton_toggled), self);
250 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
252 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
254 enable_buttons(self);
258 create_captioned (ModestDefaultAccountSettingsDialog *self,
259 GtkSizeGroup *title_sizegroup,
260 GtkSizeGroup *value_sizegroup,
261 const gchar *label_text,
268 result = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
269 label_text, use_markup, control);
271 /* Connect to the appropriate changed signal for the widget,
272 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
274 if (GTK_IS_ENTRY (control)) {
275 g_signal_connect (G_OBJECT (control), "changed",
276 G_CALLBACK (on_caption_entry_changed), self);
284 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
288 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
289 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
291 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
298 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
302 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
303 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
305 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
313 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
315 modest_platform_information_banner (GTK_WIDGET (self), NULL,
316 _CS("ckdg_ib_maximum_characters_reached"));
320 create_page_account_details (ModestDefaultAccountSettingsDialog *self)
322 ModestDefaultAccountSettingsDialogPrivate *priv;
324 GtkSizeGroup* title_sizegroup;
325 GtkSizeGroup* value_sizegroup;
328 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
329 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
330 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
331 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
333 /* The description widgets: */
334 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
335 /* Do use auto-capitalization: */
336 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
337 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
338 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
339 _("mcen_fi_account_title"), FALSE,
340 priv->entry_account_title);
341 gtk_widget_show (priv->entry_account_title);
342 connect_for_modified (self, priv->entry_account_title);
343 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
344 gtk_widget_show (caption);
346 /* Prevent the use of some characters in the account title,
347 * as required by our UI specification: */
348 GList *list_prevent = NULL;
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 list_prevent = g_list_append (list_prevent, "|");
358 list_prevent = g_list_append (list_prevent, "^");
359 modest_validating_entry_set_unallowed_characters (
360 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
361 g_list_free (list_prevent);
362 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
363 on_entry_invalid_account_title_character, self);
365 /* Set max length as in the UI spec:
366 * The UI spec seems to want us to show a dialog if we hit the maximum. */
367 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
368 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
371 hbox = gtk_hbox_new (TRUE, 0);
372 /* The retrieve picker: */
373 priv->retrieve_picker = GTK_WIDGET (modest_retrieve_picker_new (MODEST_EDITABLE_SIZE,
374 HILDON_BUTTON_ARRANGEMENT_VERTICAL));
375 modest_maemo_utils_set_vbutton_layout (title_sizegroup,
376 _("mcen_fi_advsetup_retrievetype"), priv->retrieve_picker);
378 gtk_widget_show (priv->retrieve_picker);
379 connect_for_modified (self, priv->retrieve_picker);
380 gtk_box_pack_start (GTK_BOX (hbox), priv->retrieve_picker, TRUE, TRUE, 0);
382 /* The limit-retrieve picker: */
383 priv->limit_retrieve_picker = GTK_WIDGET (modest_limit_retrieve_picker_new (MODEST_EDITABLE_SIZE,
384 HILDON_BUTTON_ARRANGEMENT_VERTICAL));
385 modest_maemo_utils_set_vbutton_layout (value_sizegroup,
386 _("mcen_fi_advsetup_limit_retrieve"),
387 priv->limit_retrieve_picker);
388 gtk_widget_show (priv->limit_retrieve_picker);
389 connect_for_modified (self, priv->limit_retrieve_picker);
390 gtk_box_pack_start (GTK_BOX (hbox), priv->limit_retrieve_picker, TRUE, TRUE, 0);
391 gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0);
392 gtk_widget_show (hbox);
394 /* The leave-messages widgets: */
395 if(!priv->checkbox_leave_messages) {
396 priv->checkbox_leave_messages =
397 hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
398 gtk_button_set_label (GTK_BUTTON (priv->checkbox_leave_messages),
399 _("mcen_fi_advsetup_leave_on_server"));
400 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_leave_messages), 0.0, 0.5);
402 connect_for_modified (self, priv->checkbox_leave_messages);
403 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_leave_messages, FALSE, FALSE, 0);
404 gtk_widget_show (priv->checkbox_leave_messages);
406 g_object_unref (title_sizegroup);
407 g_object_unref (value_sizegroup);
409 gtk_widget_show (GTK_WIDGET (box));
411 return GTK_WIDGET (box);
415 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
417 ModestDefaultAccountSettingsDialogPrivate *priv;
418 const gchar* account_title;
420 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
421 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
423 if (!account_title || (strlen (account_title) == 0))
426 /* Strip it of whitespace at the start and end: */
427 gchar *result = g_strdup (account_title);
428 result = g_strstrip (result);
433 if (strlen (result) == 0) {
444 on_button_signature (GtkButton *button, gpointer user_data)
446 ModestDefaultAccountSettingsDialog *self;
448 ModestDefaultAccountSettingsDialogPrivate *priv;
450 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
451 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
453 /* Create the window, if necessary: */
454 if (!(priv->signature_dialog)) {
455 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
457 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
458 const gchar *signature = modest_account_settings_get_signature(priv->settings);
459 gchar* account_title = get_entered_account_title (self);
460 modest_signature_editor_dialog_set_settings (
461 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
462 use_signature, signature, account_title);
464 g_free (account_title);
465 account_title = NULL;
469 /* Show the window: */
470 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
471 GTK_WINDOW (priv->signature_dialog), GTK_WINDOW (self));
473 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
474 gtk_widget_hide (priv->signature_dialog);
475 if (response != GTK_RESPONSE_OK) {
476 /* Destroy the widget now, and its data: */
477 gtk_widget_destroy (priv->signature_dialog);
478 priv->signature_dialog = NULL;
480 /* Mark modified, so we use the dialog's data later: */
481 priv->modified = TRUE;
486 on_button_delete (GtkButton *button, gpointer user_data)
488 ModestDefaultAccountSettingsDialog *self;
489 ModestDefaultAccountSettingsDialogPrivate *priv;
490 gchar *account_title;
493 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
494 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
497 account_title = g_strdup (priv->original_account_title);
499 account_title = get_entered_account_title (self);
501 removed = modest_ui_actions_on_delete_account (GTK_WINDOW (self),
503 (const gchar *) account_title);
504 g_free (account_title);
508 gtk_widget_destroy (GTK_WIDGET (self));
512 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
514 ModestDefaultAccountSettingsDialogPrivate *priv;
516 GtkSizeGroup* title_sizegroup;
517 GtkSizeGroup* value_sizegroup;
519 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
521 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
522 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
523 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
525 /* The name widgets: */
526 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
528 /* Auto-capitalization is the default, so let's turn it off: */
529 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
530 HILDON_GTK_INPUT_MODE_FULL |
531 HILDON_GTK_INPUT_MODE_AUTOCAP);
532 /* Set max length as in the UI spec:
533 * The UI spec seems to want us to show a dialog if we hit the maximum. */
534 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
535 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
538 create_captioned (self, title_sizegroup, value_sizegroup,
539 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
540 gtk_widget_show (priv->entry_user_name);
541 connect_for_modified (self, priv->entry_user_name);
542 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
543 gtk_widget_show (caption);
546 /* Prevent the use of some characters in the name,
547 * as required by our UI specification: */
548 GList *list_prevent = NULL;
549 list_prevent = g_list_append (list_prevent, "<");
550 list_prevent = g_list_append (list_prevent, ">");
551 modest_validating_entry_set_unallowed_characters (
552 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
553 g_list_free (list_prevent);
554 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
555 on_entry_invalid_fullname_character, self);
557 /* The username widgets: */
558 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
559 /* Auto-capitalization is the default, so let's turn it off: */
560 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
561 caption = create_captioned (self, title_sizegroup, value_sizegroup,
562 _("mail_fi_username"), FALSE,
563 priv->entry_user_username);
564 gtk_widget_show (priv->entry_user_username);
565 connect_for_modified (self, priv->entry_user_username);
566 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
567 gtk_widget_show (caption);
569 /* Prevent the use of some characters in the username,
570 * as required by our UI specification: */
571 modest_validating_entry_set_unallowed_characters_whitespace (
572 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
573 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
574 modest_utils_on_entry_invalid_character,
577 /* Set max length as in the UI spec:
578 * The UI spec seems to want us to show a dialog if we hit the maximum. */
579 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
580 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
583 /* The password widgets: */
584 priv->entry_user_password = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
585 /* Auto-capitalization is the default, so let's turn it off: */
586 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
587 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
588 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
589 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
590 caption = create_captioned (self, title_sizegroup, value_sizegroup,
591 _("mail_fi_password"), FALSE, priv->entry_user_password);
592 gtk_widget_show (priv->entry_user_password);
593 connect_for_modified (self, priv->entry_user_password);
594 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
595 gtk_widget_show (caption);
597 /* The email address widgets: */
598 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
599 /* Auto-capitalization is the default, so let's turn it off: */
600 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
601 caption = create_captioned (self, title_sizegroup, value_sizegroup,
602 _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
603 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
604 gtk_widget_show (priv->entry_user_email);
605 connect_for_modified (self, priv->entry_user_email);
606 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
607 gtk_widget_show (caption);
609 /* Set max length as in the UI spec:
610 * The UI spec seems to want us to show a dialog if we hit the maximum. */
611 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
612 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
616 if (!priv->button_delete)
617 priv->button_delete = gtk_button_new_with_label (_HL("wdgt_bd_delete"));
618 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (self)->action_area), priv->button_delete,
621 /* Signature button: */
622 if (!priv->button_signature)
623 priv->button_signature = gtk_button_new_with_label (_("mcen_bd_email_signature"));
624 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (self)->action_area), priv->button_signature,
626 gtk_widget_show (priv->button_signature);
628 g_object_unref (title_sizegroup);
629 g_object_unref (value_sizegroup);
631 g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
632 G_CALLBACK (on_button_signature), self);
634 g_signal_connect (G_OBJECT (priv->button_delete), "clicked",
635 G_CALLBACK (on_button_delete), self);
637 gtk_widget_show (GTK_WIDGET (box));
639 return GTK_WIDGET (box);
642 /* Change the caption title for the incoming server */
644 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
645 ModestProtocolType protocol_type)
647 ModestProtocolRegistry *protocol_registry;
648 ModestProtocol *protocol;
649 const gchar *protocol_display_name;
650 gchar* incomingserver_title;
651 ModestDefaultAccountSettingsDialogPrivate *priv;
653 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
655 protocol_registry = modest_runtime_get_protocol_registry ();
656 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
657 protocol_display_name = modest_protocol_get_display_name (protocol);
658 incomingserver_title = g_strconcat(_("mcen_li_emailsetup_servertype"), "*",
659 "\n<small>(", protocol_display_name, ")</small>", NULL);
661 modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
662 g_free (incomingserver_title);
666 create_page_incoming (ModestDefaultAccountSettingsDialog *self)
668 ModestDefaultAccountSettingsDialogPrivate *priv;
670 GtkSizeGroup *title_sizegroup;
671 GtkSizeGroup *value_sizegroup;
673 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
675 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
676 /* Create a size group to be used by all captions.
677 * Note that HildonCaption does not create a default size group if we do not specify one.
678 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
679 title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
680 value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
682 /* The incoming server widgets: */
683 if(!priv->entry_incomingserver)
684 priv->entry_incomingserver = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
685 /* Auto-capitalization is the default, so let's turn it off: */
686 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
688 if (priv->caption_incoming)
689 gtk_widget_destroy (priv->caption_incoming);
691 /* The caption title will be updated in update_incoming_server_title().
692 * so this default text will never be seen: */
693 /* (Note: Changing the title seems pointless. murrayc) */
694 priv->caption_incoming = create_captioned (self, title_sizegroup, value_sizegroup,
695 "Incoming Server", FALSE, priv->entry_incomingserver);
696 gtk_widget_show (priv->entry_incomingserver);
697 connect_for_modified (self, priv->entry_incomingserver);
698 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
699 gtk_widget_show (priv->caption_incoming);
701 /* Incoming security widgets */
702 priv->incoming_security =
703 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
704 TRUE, title_sizegroup, value_sizegroup);
705 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
708 gtk_widget_show (priv->incoming_security);
710 g_object_unref (title_sizegroup);
711 g_object_unref (value_sizegroup);
712 gtk_widget_show (GTK_WIDGET (box));
714 return GTK_WIDGET (box);
718 on_check_button_clicked (GtkButton *button, gpointer user_data)
720 GtkWidget *widget = GTK_WIDGET (user_data);
722 /* Enable the widget only if the check button is active: */
723 const gboolean enable = hildon_check_button_get_active (HILDON_CHECK_BUTTON (button));
724 gtk_widget_set_sensitive (widget, enable);
727 /* Make the sensitivity of a widget depend on a check button.
730 enable_widget_for_checkbutton (GtkWidget *widget, GtkButton* button)
732 g_signal_connect (G_OBJECT (button), "clicked",
733 G_CALLBACK (on_check_button_clicked), widget);
735 /* Set the starting sensitivity: */
736 on_check_button_clicked (button, widget);
740 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
742 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
743 ModestConnectionSpecificSmtpWindow *smtp_win;
744 ModestDefaultAccountSettingsDialogPrivate *priv;
746 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
748 /* Create the window if necessary: */
749 smtp_win = modest_connection_specific_smtp_window_new ();
750 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
752 /* Show the window: */
753 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win), GTK_WINDOW (self));
754 gtk_widget_show (GTK_WIDGET (smtp_win));
758 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
762 /* Disable the OK button */
763 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
769 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
771 ModestDefaultAccountSettingsDialogPrivate *priv;
772 gchar *smtp_caption_label;
773 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
775 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
777 /* Create a size group to be used by all captions.
778 * Note that HildonCaption does not create a default size group if we do not specify one.
779 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
780 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
781 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
783 /* The outgoing server widgets: */
784 if (!priv->entry_outgoingserver)
785 priv->entry_outgoingserver =
786 hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
787 /* Auto-capitalization is the default, so let's turn it off: */
788 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
789 smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
790 GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
791 smtp_caption_label, TRUE, priv->entry_outgoingserver);
792 g_free (smtp_caption_label);
793 gtk_widget_show (priv->entry_outgoingserver);
794 connect_for_modified (self, priv->entry_outgoingserver);
795 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
796 gtk_widget_show (caption);
798 /* Outgoing security widgets */
799 priv->outgoing_security =
800 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
801 TRUE, title_sizegroup, value_sizegroup);
802 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
804 gtk_widget_show (priv->outgoing_security);
805 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
806 G_CALLBACK (on_missing_mandatory_data), self);
808 GtkWidget *separator = gtk_hseparator_new ();
809 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_DEFAULT);
810 gtk_widget_show (separator);
812 /* connection-specific checkbox: */
813 if (!priv->checkbox_outgoing_smtp_specific) {
814 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (MODEST_EDITABLE_SIZE);
815 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
817 gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
818 _("mcen_fi_advsetup_connection_smtp"));
819 gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific), 0.0, 0.5);
821 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
822 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific,
824 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
826 /* Connection-specific SMTP-Severs Edit button: */
827 if (!priv->button_outgoing_smtp_servers)
828 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
829 hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers,
830 HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
831 gtk_widget_show (priv->button_outgoing_smtp_servers);
832 gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers, FALSE, FALSE, 0);
834 /* Only enable the button when the checkbox is checked: */
835 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
836 GTK_BUTTON (priv->checkbox_outgoing_smtp_specific));
838 g_object_unref (title_sizegroup);
839 g_object_unref (value_sizegroup);
841 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
842 G_CALLBACK (on_button_outgoing_smtp_servers), self);
844 gtk_widget_show (GTK_WIDGET (box));
846 return GTK_WIDGET (box);
850 check_data (ModestDefaultAccountSettingsDialog *self)
852 gchar* account_title;
853 const gchar* email_address;
854 const gchar* hostname;
855 const gchar* hostname2;
856 ModestDefaultAccountSettingsDialogPrivate *priv;
858 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
860 /* Check that the title is not already in use: */
861 account_title = get_entered_account_title (self);
863 return FALSE; /* Should be prevented already anyway. */
865 if (strcmp(account_title, priv->original_account_title) != 0) {
866 gboolean name_in_use;
868 /* Check the changed title: */
869 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
873 /* Warn the user via a dialog: */
874 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
876 g_free (account_title);
881 g_free (account_title);
882 account_title = NULL;
884 /* Check that the email address is valid: */
885 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
886 if ((!email_address) || (strlen(email_address) == 0)) {
890 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
891 /* Warn the user via a dialog: */
892 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
894 /* Return focus to the email address entry: */
895 gtk_widget_grab_focus (priv->entry_user_email);
896 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
900 /* make sure the domain name for the incoming server is valid */
901 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
902 if ((!hostname) || (strlen(hostname) == 0)) {
906 if (!modest_text_utils_validate_domain_name (hostname)) {
907 /* Warn the user via a dialog: */
908 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
910 /* Return focus to the email address entry: */
911 gtk_widget_grab_focus (priv->entry_incomingserver);
912 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
916 /* make sure the domain name for the outgoing server is valid */
917 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
918 if ((!hostname2) || (strlen(hostname2) == 0)) {
922 if (!modest_text_utils_validate_domain_name (hostname2)) {
923 /* Warn the user via a dialog: */
924 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
926 /* Return focus to the email address entry: */
927 gtk_widget_grab_focus (priv->entry_outgoingserver);
928 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
936 on_delete_event (GtkWidget *widget,
940 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
941 ModestDefaultAccountSettingsDialogPrivate *priv;
942 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
944 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
946 /* Check if security widgets changed */
947 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
948 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
950 return modest_security_options_view_changed (incoming_sec, priv->settings) ||
951 modest_security_options_view_changed (outgoing_sec, priv->settings) ||
956 on_response (GtkDialog *wizard_dialog,
960 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
961 ModestDefaultAccountSettingsDialogPrivate *priv;
962 gboolean prevent_response = FALSE, sec_changed;
963 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
965 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
966 enable_buttons (self);
968 /* Check if security widgets changed */
969 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
970 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
972 modest_security_options_view_changed (incoming_sec, priv->settings) ||
973 modest_security_options_view_changed (outgoing_sec, priv->settings);
975 /* Warn about unsaved changes: */
976 if ((response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) &&
977 (priv->modified || sec_changed)) {
978 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
979 _("imum_nc_wizard_confirm_lose_changes")));
980 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
982 const gint dialog_response = gtk_dialog_run (dialog);
983 gtk_widget_destroy (GTK_WIDGET (dialog));
985 if (dialog_response != GTK_RESPONSE_OK)
986 prevent_response = TRUE;
988 /* Check for invalid input: */
989 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
990 prevent_response = TRUE;
993 if (prevent_response) {
994 /* This is a nasty hack. murrayc. */
995 /* Don't let the dialog close */
996 g_signal_stop_emission_by_name (wizard_dialog, "response");
999 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
1002 if (response_id == GTK_RESPONSE_OK) {
1003 /* Try to save the changes if modified (NB #59251): */
1004 if (priv->modified || sec_changed) {
1005 if (save_configuration (self)) {
1006 /* Do not show the account-saved dialog if we are just saving this
1007 * temporarily, because from the user's point of view it will not
1008 * really be saved (saved + enabled) until later
1010 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
1011 ModestServerAccountSettings *store_settings;
1012 ModestServerAccountSettings *transport_settings;
1013 const gchar *store_account_name;
1014 const gchar *transport_account_name;
1017 store_settings = modest_account_settings_get_store_settings (priv->settings);
1018 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1019 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1020 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1022 if (store_account_name) {
1023 modest_account_mgr_notify_account_update (priv->account_manager,
1024 store_account_name);
1026 if (transport_account_name) {
1027 modest_account_mgr_notify_account_update (priv->account_manager,
1028 transport_account_name);
1030 g_object_unref (store_settings);
1031 g_object_unref (transport_settings);
1033 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1036 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1043 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1045 ModestDefaultAccountSettingsDialogPrivate *priv;
1046 GtkWidget *pannable;
1047 GtkWidget *separator;
1050 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1052 priv->incoming_security = NULL;
1053 priv->outgoing_security = NULL;
1055 priv->main_container = gtk_vbox_new (FALSE, 0);
1056 priv->settings = modest_account_settings_new ();
1058 /* Get the account manager object,
1059 * so we can check for existing accounts,
1060 * and create new accounts: */
1061 priv->account_manager = modest_runtime_get_account_mgr ();
1062 g_assert (priv->account_manager);
1063 g_object_ref (priv->account_manager);
1065 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1067 /* Create the common pages,
1069 priv->page_account_details = create_page_account_details (self);
1070 priv->page_user_details = create_page_user_details (self);
1071 priv->page_incoming = create_page_incoming (self);
1072 priv->page_outgoing = create_page_outgoing (self);
1074 /* Add the notebook pages: */
1075 gtk_box_pack_start (GTK_BOX (priv->main_container),
1076 priv->page_account_details,
1078 gtk_box_pack_start (GTK_BOX (priv->main_container),
1079 priv->page_user_details,
1082 separator = gtk_hseparator_new ();
1083 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1084 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1085 gtk_widget_show (separator);
1086 gtk_box_pack_start (GTK_BOX (priv->main_container),
1087 priv->page_incoming,
1089 separator = gtk_hseparator_new ();
1090 gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
1091 FALSE, FALSE, MODEST_MARGIN_DEFAULT);
1092 gtk_widget_show (separator);
1093 gtk_box_pack_start (GTK_BOX (priv->main_container),
1094 priv->page_outgoing,
1097 GtkDialog *dialog = GTK_DIALOG (self);
1098 pannable = hildon_pannable_area_new ();
1099 g_object_set (G_OBJECT (pannable), "initial-hint", TRUE, NULL);
1101 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
1102 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
1103 gtk_widget_show (align);
1104 gtk_container_add (GTK_CONTAINER (align), priv->main_container);
1106 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
1107 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (pannable));
1108 gtk_widget_show (GTK_WIDGET (priv->main_container));
1109 gtk_widget_show (GTK_WIDGET (pannable));
1111 /* Add the buttons: */
1112 gtk_dialog_add_button (GTK_DIALOG(self), _HL("wdgt_bd_save"), GTK_RESPONSE_OK);
1114 gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
1116 /* Connect to the dialog's "response" and "delete-event" signals */
1117 g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self);
1118 g_signal_connect (G_OBJECT (self), "delete-event", G_CALLBACK (on_delete_event), self);
1120 priv->modified = FALSE;
1122 /* When this window is shown, hibernation should not be possible,
1123 * because there is no sensible way to save the state: */
1124 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1125 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1127 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1128 * while sending messages causes an error dialog and we have a lock */
1129 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1133 ModestAccountSettingsDialog*
1134 modest_default_account_settings_dialog_new (void)
1136 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1139 /** Update the UI with the stored account details, so they can be edited.
1140 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1143 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1144 ModestAccountSettings *settings)
1146 ModestServerAccountSettings *incoming_account;
1147 ModestServerAccountSettings *outgoing_account;
1148 ModestProtocolRegistry *protocol_registry;
1149 const gchar *account_name, *server_account_name;
1150 ModestDefaultAccountSettingsDialogPrivate *priv;
1152 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1153 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1155 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1156 protocol_registry = modest_runtime_get_protocol_registry ();
1158 account_name = modest_account_settings_get_account_name (settings);
1160 /* Save the account name so we can refer to it later: */
1161 if (priv->account_name)
1162 g_free (priv->account_name);
1163 priv->account_name = g_strdup (account_name);
1165 if (priv->account_name)
1166 gtk_widget_show (priv->button_delete);
1168 gtk_widget_hide (priv->button_delete);
1171 g_object_unref (priv->settings);
1172 priv->settings = g_object_ref (settings);
1174 /* Save the account title so we can refer to it if the user changes it: */
1175 if (priv->original_account_title)
1176 g_free (priv->original_account_title);
1177 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1179 /* Show the account data in the widgets: */
1181 /* Note that we never show the non-display name in the UI.
1182 * (Though the display name defaults to the non-display name at the start.) */
1183 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1184 null_means_empty (modest_account_settings_get_display_name (settings)));
1185 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1186 null_means_empty (modest_account_settings_get_fullname (settings)));
1187 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1188 null_means_empty (modest_account_settings_get_email_address (settings)));
1189 modest_limit_retrieve_picker_set_active_limit_retrieve (
1190 MODEST_LIMIT_RETRIEVE_PICKER (priv->limit_retrieve_picker),
1191 modest_account_settings_get_retrieve_limit (settings));
1193 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_leave_messages),
1194 modest_account_settings_get_leave_messages_on_server (settings));
1196 incoming_account = modest_account_settings_get_store_settings (settings);
1197 if (incoming_account) {
1198 const gchar *username, *password, *hostname, *proto_str, *account_title;
1199 gchar *proto_name, *title;
1200 ModestProtocolType incoming_protocol;
1202 modest_retrieve_picker_fill (MODEST_RETRIEVE_PICKER (priv->retrieve_picker), modest_server_account_settings_get_protocol (incoming_account));
1203 modest_retrieve_picker_set_active_retrieve_conf (MODEST_RETRIEVE_PICKER (priv->retrieve_picker),
1204 modest_account_settings_get_retrieve_type (settings));
1206 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1207 modest_server_account_settings_get_protocol (incoming_account))) {
1208 gtk_widget_hide (priv->checkbox_leave_messages);
1210 gtk_widget_show (priv->checkbox_leave_messages);
1213 /* Remember this for later: */
1214 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1216 hostname = modest_server_account_settings_get_hostname (incoming_account);
1217 username = modest_server_account_settings_get_username (incoming_account);
1218 password = modest_server_account_settings_get_password (incoming_account);
1219 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1220 null_means_empty (username));
1221 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1222 null_means_empty (password));
1224 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1225 null_means_empty (hostname));
1227 /* Load security settings */
1228 modest_security_options_view_load_settings (
1229 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1231 gtk_widget_show (priv->incoming_security);
1233 /* Update the incoming label */
1234 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1237 /* Set window title according to account */
1238 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1239 proto_name = g_utf8_strup (proto_str, -1);
1240 account_title = modest_account_settings_get_display_name(settings);
1241 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1243 gtk_window_set_title (GTK_WINDOW (dialog), title);
1245 g_free (proto_name);
1247 g_object_unref (incoming_account);
1250 outgoing_account = modest_account_settings_get_transport_settings (settings);
1251 if (outgoing_account) {
1252 const gchar *hostname;
1253 const gchar *username;
1254 const gchar *password;
1255 ModestProtocolType outgoing_protocol;
1257 /* Remember this for later: */
1259 modest_server_account_settings_get_protocol (outgoing_account);
1261 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1262 username = modest_server_account_settings_get_username (outgoing_account);
1263 password = modest_server_account_settings_get_password (outgoing_account);
1264 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1265 null_means_empty (hostname));
1267 /* Load security settings */
1268 modest_security_options_view_load_settings (
1269 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1271 gtk_widget_show (priv->outgoing_security);
1273 const gboolean has_specific =
1274 modest_account_settings_get_use_connection_specific_smtp (settings);
1275 hildon_check_button_set_active (
1276 HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1278 g_object_unref (outgoing_account);
1281 /* Switch to user page */
1282 /* Check if we allow changes or not */
1283 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1284 if (server_account_name) {
1285 gboolean username_known;
1288 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1289 server_account_name);
1290 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1291 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1292 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1296 /* Unset the modified flag so we can detect changes later: */
1297 priv->modified = FALSE;
1301 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1303 const gchar* user_fullname;
1304 const gchar* emailaddress;
1305 ModestServerAccountSettings *store_settings;
1306 ModestServerAccountSettings *transport_settings;
1307 ModestAccountRetrieveType retrieve_type;
1308 gint retrieve_limit;
1309 gboolean leave_on_server;
1310 const gchar* hostname;
1311 const gchar* username;
1312 const gchar* password;
1313 gchar* account_title;
1314 ModestDefaultAccountSettingsDialogPrivate *priv;
1315 const gchar* account_name;
1317 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1318 account_name = priv->account_name;
1320 /* Set the account data from the widgets: */
1321 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1322 modest_account_settings_set_fullname (priv->settings, user_fullname);
1324 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1325 modest_account_settings_set_email_address (priv->settings, emailaddress);
1328 if (priv->signature_dialog) {
1329 gboolean use_signature = FALSE;
1331 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1334 modest_account_settings_set_use_signature (priv->settings, use_signature);
1335 modest_account_settings_set_signature (priv->settings, signature);
1338 retrieve_type = modest_retrieve_picker_get_active_retrieve_conf (
1339 MODEST_RETRIEVE_PICKER (priv->retrieve_picker));
1340 modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
1342 retrieve_limit = modest_limit_retrieve_picker_get_active_limit_retrieve (
1343 MODEST_LIMIT_RETRIEVE_PICKER (priv->limit_retrieve_picker));
1344 modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
1346 leave_on_server = hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox_leave_messages));
1347 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1349 store_settings = modest_account_settings_get_store_settings (priv->settings);
1351 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1352 modest_server_account_settings_set_hostname (store_settings, hostname);
1354 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1355 modest_server_account_settings_set_username (store_settings, username);
1357 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1358 modest_server_account_settings_set_password (store_settings, password);
1360 /* Save security settings */
1361 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1364 g_object_unref (store_settings);
1367 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1369 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1370 modest_server_account_settings_set_hostname (transport_settings, hostname);
1372 /* Save security settings */
1373 modest_security_options_view_save_settings (
1374 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1377 /* Set the changed account title last, to simplify the previous code: */
1378 account_title = get_entered_account_title (dialog);
1380 return FALSE; /* Should be prevented already anyway. */
1382 /* if (strcmp (account_title, account_name) != 0) { */
1383 modest_account_settings_set_display_name (priv->settings, account_title);
1385 g_free (account_title);
1386 account_title = NULL;
1388 /* Save connection-specific SMTP server accounts: */
1389 modest_account_settings_set_use_connection_specific_smtp
1391 hildon_check_button_get_active(HILDON_CHECK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1393 /* this configuration is not persistent, we should not save */
1394 if (account_name != NULL)
1395 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1400 static gboolean entry_is_empty (GtkWidget *entry)
1405 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1406 if ((!text) || (strlen(text) == 0))
1409 /* Strip it of whitespace at the start and end: */
1410 gchar *stripped = g_strdup (text);
1411 stripped = g_strstrip (stripped);
1416 const gboolean result = (strlen (stripped) == 0);
1424 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1426 gboolean enable_ok = TRUE;
1427 ModestProtocolRegistry *protocol_registry;
1428 ModestSecurityOptionsView *sec_view;
1429 ModestDefaultAccountSettingsDialogPrivate *priv;
1431 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1433 /* The account details title is mandatory: */
1434 if (entry_is_empty(priv->entry_account_title))
1437 /* The user details username is mandatory: */
1438 if (enable_ok && entry_is_empty(priv->entry_user_username))
1441 /* The user details email address is mandatory: */
1442 if (enable_ok && entry_is_empty (priv->entry_user_email))
1445 /* The custom incoming server is mandatory: */
1446 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1449 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1451 modest_security_options_view_has_missing_mandatory_data (sec_view))
1454 /* The custom outgoing server is mandatory: */
1455 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1458 sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1460 modest_security_options_view_has_missing_mandatory_data (sec_view))
1463 protocol_registry = modest_runtime_get_protocol_registry ();
1465 /* Enable the buttons,
1466 * identifying them via their associated response codes:
1468 GtkDialog *dialog_base = GTK_DIALOG (self);
1469 gtk_dialog_set_response_sensitive (dialog_base,
1475 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1477 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1478 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1480 object_class->dispose = modest_default_account_settings_dialog_dispose;
1481 object_class->finalize = modest_default_account_settings_dialog_finalize;
1485 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1487 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1489 iface->load_settings = modest_default_account_settings_dialog_load_settings;