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/gtknotebook.h>
33 #include <gtk/gtkvbox.h>
34 #include <gtk/gtklabel.h>
35 #include <gtk/gtkentry.h>
36 #include <gtk/gtkbutton.h>
37 #include <gtk/gtkcheckbutton.h>
38 #include <gtk/gtkmessagedialog.h>
39 #include <gtk/gtkstock.h>
40 #include "modest-hildon-includes.h"
41 #include "modest-default-account-settings-dialog.h"
42 #include "modest-account-mgr.h"
43 #include "modest-secureauth-picker.h"
44 #include "widgets/modest-validating-entry.h"
45 #include "modest-retrieve-picker.h"
46 #include "modest-limit-retrieve-picker.h"
47 #include "modest-text-utils.h"
48 #include "modest-account-mgr.h"
49 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
50 #include <modest-server-account-settings.h>
51 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
52 #include "modest-connection-specific-smtp-window.h"
53 #include "modest-signature-editor-dialog.h"
54 #include <modest-utils.h>
55 #include <modest-defs.h>
56 #include "modest-maemo-utils.h"
57 #include "modest-maemo-security-options-view.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(). */
65 /* Include config.h so that _() works: */
71 #define PORT_MAX 65535
73 static void modest_account_settings_dialog_init (gpointer g, gpointer iface_data);
75 G_DEFINE_TYPE_EXTENDED (ModestDefaultAccountSettingsDialog,
76 modest_default_account_settings_dialog,
79 G_IMPLEMENT_INTERFACE (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG,
80 modest_account_settings_dialog_init));
82 #define MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
83 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, ModestDefaultAccountSettingsDialogPrivate))
85 typedef struct _ModestDefaultAccountSettingsDialogPrivate ModestDefaultAccountSettingsDialogPrivate;
87 struct _ModestDefaultAccountSettingsDialogPrivate
89 /* Used by derived widgets to query existing accounts,
90 * and to create new accounts: */
91 ModestAccountMgr *account_manager;
92 ModestAccountSettings *settings;
95 gchar * account_name; /* This may not change. It is not user visible. */
96 ModestProtocolType incoming_protocol; /* This may not change. */
97 ModestProtocolType outgoing_protocol; /* This may not change. */
98 gchar * original_account_title;
100 ModestProtocolType protocol_authentication_incoming;
102 GtkNotebook *notebook;
104 GtkWidget *page_account_details;
105 GtkWidget *entry_account_title;
106 GtkWidget *retrieve_picker;
107 GtkWidget *limit_retrieve_picker;
108 GtkWidget *caption_leave_messages;
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;
119 GtkWidget *page_complete_easysetup;
121 GtkWidget *page_incoming;
122 GtkWidget *caption_incoming;
123 GtkWidget *entry_incomingserver;
125 GtkWidget *page_outgoing;
126 GtkWidget *entry_outgoingserver;
127 GtkWidget *checkbox_outgoing_smtp_specific;
128 GtkWidget *button_outgoing_smtp_servers;
130 GtkWidget *signature_dialog;
132 GtkWidget *incoming_security;
133 GtkWidget *outgoing_security;
137 enable_buttons (ModestDefaultAccountSettingsDialog *self);
140 save_configuration (ModestDefaultAccountSettingsDialog *dialog);
142 static const gchar * null_means_empty (const gchar * str);
145 null_means_empty (const gchar * str)
147 return str ? str : "";
151 modest_default_account_settings_dialog_dispose (GObject *object)
153 if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
154 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
158 modest_default_account_settings_dialog_finalize (GObject *object)
160 ModestDefaultAccountSettingsDialog *self;
161 ModestDefaultAccountSettingsDialogPrivate *priv;
163 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
164 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
166 if (priv->account_name)
167 g_free (priv->account_name);
169 if (priv->original_account_title)
170 g_free (priv->original_account_title);
172 if (priv->account_manager)
173 g_object_unref (G_OBJECT (priv->account_manager));
175 if (priv->signature_dialog)
176 gtk_widget_destroy (priv->signature_dialog);
178 if (priv->settings) {
179 g_object_unref (priv->settings);
180 priv->settings = NULL;
183 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
187 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
189 ModestDefaultAccountSettingsDialogPrivate *priv;
191 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
192 priv->modified = modified;
196 on_modified_picker_changed (HildonPickerButton *widget, gpointer user_data)
198 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
202 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
204 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
208 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
210 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
214 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
216 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
220 on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
222 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
223 gint value = hildon_number_editor_get_value (editor);
225 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
228 /* Set a modified boolean whenever the widget is changed,
229 * so we can check for it later.
232 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
234 if (HILDON_IS_NUMBER_EDITOR (widget)) {
235 g_signal_connect (G_OBJECT (widget), "notify::value",
236 G_CALLBACK (on_modified_number_editor_changed), self);
237 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
239 else if (GTK_IS_ENTRY (widget)) {
240 g_signal_connect (G_OBJECT (widget), "changed",
241 G_CALLBACK (on_modified_entry_changed), self);
242 } else if (HILDON_IS_PICKER_BUTTON (widget)) {
243 g_signal_connect (G_OBJECT (widget), "value-changed",
244 G_CALLBACK (on_modified_picker_changed), self);
245 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
246 g_signal_connect (G_OBJECT (widget), "toggled",
247 G_CALLBACK (on_modified_checkbox_toggled), self);
252 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
254 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
256 enable_buttons(self);
259 /** This is a convenience function to create a caption containing a mandatory widget.
260 * When the widget is edited, the enable_buttons() vfunc will be called.
263 create_caption_new_with_asterisk(ModestDefaultAccountSettingsDialog *self,
268 HildonCaptionStatus flag)
270 GtkWidget *caption = NULL;
272 /* Note: Previously, the translated strings already contained the "*",
273 * Comment out this code if they do again.
275 /* Add a * character to indicate mandatory fields,
276 * as specified in our "Email UI Specification": */
277 if (flag == HILDON_CAPTION_MANDATORY) {
278 gchar* title = g_strdup_printf("%s*", value);
279 caption = hildon_caption_new (group, title, control, icon, flag);
283 caption = hildon_caption_new (group, value, control, icon, flag);
285 /* Connect to the appropriate changed signal for the widget,
286 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
288 if (GTK_IS_ENTRY (control)) {
289 g_signal_connect (G_OBJECT (control), "changed",
290 G_CALLBACK (on_caption_entry_changed), self);
298 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
302 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_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);
312 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
316 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
317 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
319 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
327 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
329 modest_platform_information_banner (GTK_WIDGET (self), NULL,
330 _CS("ckdg_ib_maximum_characters_reached"));
334 create_page_account_details (ModestDefaultAccountSettingsDialog *self)
336 ModestDefaultAccountSettingsDialogPrivate *priv;
338 GtkAdjustment *focus_adjustment = NULL;
339 GtkSizeGroup* sizegroup;
340 GtkWidget *scrollwin;
342 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
343 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
344 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
345 scrollwin = gtk_scrolled_window_new (NULL, NULL);
346 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
347 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
349 /* The description widgets: */
350 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
351 /* Do use auto-capitalization: */
352 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
353 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
354 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
355 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
356 gtk_widget_show (priv->entry_account_title);
357 connect_for_modified (self, priv->entry_account_title);
358 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
359 gtk_widget_show (caption);
361 /* Prevent the use of some characters in the account title,
362 * as required by our UI specification: */
363 GList *list_prevent = NULL;
364 list_prevent = g_list_append (list_prevent, "\\");
365 list_prevent = g_list_append (list_prevent, "/");
366 list_prevent = g_list_append (list_prevent, ":");
367 list_prevent = g_list_append (list_prevent, "*");
368 list_prevent = g_list_append (list_prevent, "?");
369 list_prevent = g_list_append (list_prevent, "\"");
370 list_prevent = g_list_append (list_prevent, "<");
371 list_prevent = g_list_append (list_prevent, ">");
372 list_prevent = g_list_append (list_prevent, "|");
373 list_prevent = g_list_append (list_prevent, "^");
374 modest_validating_entry_set_unallowed_characters (
375 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
376 g_list_free (list_prevent);
377 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
378 on_entry_invalid_account_title_character, self);
380 /* Set max length as in the UI spec:
381 * The UI spec seems to want us to show a dialog if we hit the maximum. */
382 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
383 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
386 /* The retrieve picker: */
387 priv->retrieve_picker = GTK_WIDGET (modest_retrieve_picker_new ());
388 hildon_button_set_title (HILDON_BUTTON (priv->retrieve_picker), _("mcen_fi_advsetup_retrievetype"));
389 gtk_widget_show (priv->retrieve_picker);
390 connect_for_modified (self, priv->retrieve_picker);
391 gtk_box_pack_start (GTK_BOX (box), priv->retrieve_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
393 /* The limit-retrieve picker: */
394 priv->limit_retrieve_picker = GTK_WIDGET (modest_limit_retrieve_picker_new ());
395 hildon_button_set_title (HILDON_BUTTON (priv->limit_retrieve_picker), _("mcen_fi_advsetup_limit_retrieve"));
396 gtk_widget_show (priv->limit_retrieve_picker);
397 connect_for_modified (self, priv->limit_retrieve_picker);
398 gtk_box_pack_start (GTK_BOX (box), priv->limit_retrieve_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
400 /* The leave-messages widgets: */
401 if(!priv->checkbox_leave_messages)
402 priv->checkbox_leave_messages = gtk_check_button_new ();
403 if (!priv->caption_leave_messages) {
404 priv->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
405 priv->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
408 gtk_widget_show (priv->checkbox_leave_messages);
409 connect_for_modified (self, priv->checkbox_leave_messages);
410 gtk_box_pack_start (GTK_BOX (box), priv->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
411 gtk_widget_show (priv->caption_leave_messages);
413 g_object_unref (sizegroup);
415 gtk_widget_show (GTK_WIDGET (box));
417 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
418 gtk_widget_show (scrollwin);
420 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
421 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
423 return GTK_WIDGET (scrollwin);
427 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
429 ModestDefaultAccountSettingsDialogPrivate *priv;
430 const gchar* account_title;
432 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
433 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
435 if (!account_title || (strlen (account_title) == 0))
438 /* Strip it of whitespace at the start and end: */
439 gchar *result = g_strdup (account_title);
440 result = g_strstrip (result);
445 if (strlen (result) == 0) {
456 on_button_signature (GtkButton *button, gpointer user_data)
458 ModestDefaultAccountSettingsDialog *self;
460 ModestDefaultAccountSettingsDialogPrivate *priv;
462 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
463 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
465 /* Create the window, if necessary: */
466 if (!(priv->signature_dialog)) {
467 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
469 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
470 const gchar *signature = modest_account_settings_get_signature(priv->settings);
471 gchar* account_title = get_entered_account_title (self);
472 modest_signature_editor_dialog_set_settings (
473 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
474 use_signature, signature, account_title);
476 g_free (account_title);
477 account_title = NULL;
481 /* Show the window: */
482 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
483 GTK_WINDOW (priv->signature_dialog));
485 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
486 gtk_widget_hide (priv->signature_dialog);
487 if (response != GTK_RESPONSE_OK) {
488 /* Destroy the widget now, and its data: */
489 gtk_widget_destroy (priv->signature_dialog);
490 priv->signature_dialog = NULL;
492 /* Mark modified, so we use the dialog's data later: */
493 priv->modified = TRUE;
498 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
500 ModestDefaultAccountSettingsDialogPrivate *priv;
502 GtkAdjustment *focus_adjustment = NULL;
503 GtkSizeGroup* sizegroup;
504 GtkWidget *scrollwin;
506 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
508 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
509 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
510 scrollwin = gtk_scrolled_window_new (NULL, NULL);
511 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
512 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
514 /* The name widgets: */
515 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
517 /* Auto-capitalization is the default, so let's turn it off: */
518 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
519 /* Set max length as in the UI spec:
520 * The UI spec seems to want us to show a dialog if we hit the maximum. */
521 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
522 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
524 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
525 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
526 gtk_widget_show (priv->entry_user_name);
527 connect_for_modified (self, priv->entry_user_name);
528 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
529 gtk_widget_show (caption);
532 /* Prevent the use of some characters in the name,
533 * as required by our UI specification: */
534 GList *list_prevent = NULL;
535 list_prevent = g_list_append (list_prevent, "<");
536 list_prevent = g_list_append (list_prevent, ">");
537 modest_validating_entry_set_unallowed_characters (
538 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
539 g_list_free (list_prevent);
540 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
541 on_entry_invalid_fullname_character, self);
543 /* The username widgets: */
544 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
545 /* Auto-capitalization is the default, so let's turn it off: */
546 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
547 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
548 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
549 gtk_widget_show (priv->entry_user_username);
550 connect_for_modified (self, priv->entry_user_username);
551 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
552 gtk_widget_show (caption);
554 /* Prevent the use of some characters in the username,
555 * as required by our UI specification: */
556 modest_validating_entry_set_unallowed_characters_whitespace (
557 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
558 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
559 modest_utils_on_entry_invalid_character,
562 /* Set max length as in the UI spec:
563 * The UI spec seems to want us to show a dialog if we hit the maximum. */
564 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
565 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
568 /* The password widgets: */
569 priv->entry_user_password = gtk_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_password),
572 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
573 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
574 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
575 caption = create_caption_new_with_asterisk (self, sizegroup,
576 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
577 gtk_widget_show (priv->entry_user_password);
578 connect_for_modified (self, priv->entry_user_password);
579 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
580 gtk_widget_show (caption);
582 /* The email address widgets: */
583 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
584 /* Auto-capitalization is the default, so let's turn it off: */
585 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
586 caption = create_caption_new_with_asterisk (self, sizegroup,
587 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
588 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
589 gtk_widget_show (priv->entry_user_email);
590 connect_for_modified (self, priv->entry_user_email);
591 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
592 gtk_widget_show (caption);
594 /* Set max length as in the UI spec:
595 * The UI spec seems to want us to show a dialog if we hit the maximum. */
596 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
597 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
600 /* Signature button: */
601 if (!priv->button_signature)
602 priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
603 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
604 priv->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
605 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
606 gtk_widget_show (priv->button_signature);
607 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
608 gtk_widget_show (caption);
610 g_object_unref (sizegroup);
612 g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
613 G_CALLBACK (on_button_signature), self);
615 gtk_widget_show (GTK_WIDGET (box));
616 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
617 gtk_widget_show (scrollwin);
619 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
620 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
622 return GTK_WIDGET (scrollwin);
625 /* Change the caption title for the incoming server */
627 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
628 ModestProtocolType protocol_type)
630 ModestProtocolRegistry *protocol_registry;
631 ModestProtocol *protocol;
632 const gchar *protocol_display_name;
633 gchar* incomingserver_title;
634 gchar *with_asterisk;
635 ModestDefaultAccountSettingsDialogPrivate *priv;
637 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
639 protocol_registry = modest_runtime_get_protocol_registry ();
640 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
641 protocol_display_name = modest_protocol_get_display_name (protocol);
642 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"),
643 protocol_display_name);
645 /* This is a mandatory field, so add a *. This is usually done by
646 * create_caption_new_with_asterisk() but we can't use that here. */
647 with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
648 g_free (incomingserver_title);
650 g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
651 g_free (with_asterisk);
655 create_page_incoming (ModestDefaultAccountSettingsDialog *self)
657 ModestDefaultAccountSettingsDialogPrivate *priv;
659 GtkSizeGroup *sizegroup;
661 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
663 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
664 /* Create a size group to be used by all captions.
665 * Note that HildonCaption does not create a default size group if we do not specify one.
666 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
667 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
669 /* The incoming server widgets: */
670 if(!priv->entry_incomingserver)
671 priv->entry_incomingserver = gtk_entry_new ();
672 /* Auto-capitalization is the default, so let's turn it off: */
673 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
675 if (priv->caption_incoming)
676 gtk_widget_destroy (priv->caption_incoming);
678 /* The caption title will be updated in update_incoming_server_title().
679 * so this default text will never be seen: */
680 /* (Note: Changing the title seems pointless. murrayc) */
681 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
682 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
683 gtk_widget_show (priv->entry_incomingserver);
684 connect_for_modified (self, priv->entry_incomingserver);
685 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
686 gtk_widget_show (priv->caption_incoming);
688 /* Incoming security widgets */
689 priv->incoming_security =
690 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
692 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
693 FALSE, FALSE, MODEST_MARGIN_HALF);
695 gtk_widget_show (priv->incoming_security);
697 g_object_unref (sizegroup);
698 gtk_widget_show (GTK_WIDGET (box));
700 return GTK_WIDGET (box);
704 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
706 GtkWidget *widget = GTK_WIDGET (user_data);
708 /* Enable the widget only if the toggle button is active: */
709 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
710 gtk_widget_set_sensitive (widget, enable);
713 /* Make the sensitivity of a widget depend on a toggle button.
716 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
718 g_signal_connect (G_OBJECT (button), "toggled",
719 G_CALLBACK (on_toggle_button_changed), widget);
721 /* Set the starting sensitivity: */
722 on_toggle_button_changed (button, widget);
726 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
728 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
729 ModestConnectionSpecificSmtpWindow *smtp_win;
730 ModestDefaultAccountSettingsDialogPrivate *priv;
732 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
734 /* Create the window if necessary: */
735 smtp_win = modest_connection_specific_smtp_window_new ();
736 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
738 /* Show the window: */
739 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win));
740 gtk_widget_show (GTK_WIDGET (smtp_win));
741 priv->modified = TRUE;
745 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
749 /* Disable the OK button */
750 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
756 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
758 ModestDefaultAccountSettingsDialogPrivate *priv;
759 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
760 GtkAdjustment *focus_adjustment = NULL;
762 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
764 /* Put it all in a scrolled window, so that all widgets can be
765 * accessed even when the on-screen keyboard is visible: */
766 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
767 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
768 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
770 /* Create a size group to be used by all captions.
771 * Note that HildonCaption does not create a default size group if we do not specify one.
772 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
773 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
775 /* The outgoing server widgets: */
776 if (!priv->entry_outgoingserver)
777 priv->entry_outgoingserver = gtk_entry_new ();
778 /* Auto-capitalization is the default, so let's turn it off: */
779 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
780 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
781 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
782 gtk_widget_show (priv->entry_outgoingserver);
783 connect_for_modified (self, priv->entry_outgoingserver);
784 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
785 gtk_widget_show (caption);
787 /* Outgoing security widgets */
788 priv->outgoing_security =
789 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
791 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
792 FALSE, FALSE, MODEST_MARGIN_HALF);
793 gtk_widget_show (priv->outgoing_security);
794 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
795 G_CALLBACK (on_missing_mandatory_data), self);
797 GtkWidget *separator = gtk_hseparator_new ();
798 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
799 gtk_widget_show (separator);
801 /* connection-specific checkbox: */
802 if (!priv->checkbox_outgoing_smtp_specific) {
803 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
804 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
807 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
808 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
809 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
810 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
811 gtk_widget_show (caption);
812 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
814 /* Connection-specific SMTP-Severs Edit button: */
815 if (!priv->button_outgoing_smtp_servers)
816 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
817 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
818 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
819 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
820 gtk_widget_show (priv->button_outgoing_smtp_servers);
821 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
822 gtk_widget_show (caption);
824 /* Only enable the button when the checkbox is checked: */
825 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
826 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
828 g_object_unref (sizegroup);
830 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
831 G_CALLBACK (on_button_outgoing_smtp_servers), self);
833 gtk_widget_show (GTK_WIDGET (box));
834 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
835 gtk_widget_show(scrollwin);
837 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
838 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
840 return GTK_WIDGET (scrollwin);
844 check_data (ModestDefaultAccountSettingsDialog *self)
846 gchar* account_title;
847 const gchar* email_address;
848 const gchar* hostname;
849 const gchar* hostname2;
850 ModestDefaultAccountSettingsDialogPrivate *priv;
852 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
854 /* Check that the title is not already in use: */
855 account_title = get_entered_account_title (self);
857 return FALSE; /* Should be prevented already anyway. */
859 if (strcmp(account_title, priv->original_account_title) != 0) {
860 gboolean name_in_use;
862 /* Check the changed title: */
863 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
867 /* Warn the user via a dialog: */
868 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
870 g_free (account_title);
875 g_free (account_title);
876 account_title = NULL;
878 /* Check that the email address is valid: */
879 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
880 if ((!email_address) || (strlen(email_address) == 0)) {
884 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
885 /* Warn the user via a dialog: */
886 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
888 /* Return focus to the email address entry: */
889 gtk_widget_grab_focus (priv->entry_user_email);
890 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
894 /* make sure the domain name for the incoming server is valid */
895 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
896 if ((!hostname) || (strlen(hostname) == 0)) {
900 if (!modest_text_utils_validate_domain_name (hostname)) {
901 /* Warn the user via a dialog: */
902 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
904 /* Return focus to the email address entry: */
905 gtk_widget_grab_focus (priv->entry_incomingserver);
906 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
910 /* make sure the domain name for the outgoing server is valid */
911 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
912 if ((!hostname2) || (strlen(hostname2) == 0)) {
916 if (!modest_text_utils_validate_domain_name (hostname2)) {
917 /* Warn the user via a dialog: */
918 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
920 /* Return focus to the email address entry: */
921 gtk_widget_grab_focus (priv->entry_outgoingserver);
922 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
930 on_response (GtkDialog *wizard_dialog,
934 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
935 ModestDefaultAccountSettingsDialogPrivate *priv;
936 gboolean prevent_response = FALSE, sec_changed;
937 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
939 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
940 enable_buttons (self);
942 /* Check if security widgets changed */
943 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
944 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
946 modest_security_options_view_changed (incoming_sec, priv->settings) ||
947 modest_security_options_view_changed (outgoing_sec, priv->settings);
949 /* Warn about unsaved changes: */
950 if (response_id == GTK_RESPONSE_CANCEL && (priv->modified || sec_changed)) {
951 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
952 _("imum_nc_wizard_confirm_lose_changes")));
953 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
955 const gint dialog_response = gtk_dialog_run (dialog);
956 gtk_widget_destroy (GTK_WIDGET (dialog));
958 if (dialog_response != GTK_RESPONSE_OK)
959 prevent_response = TRUE;
961 /* Check for invalid input: */
962 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
963 prevent_response = TRUE;
966 if (prevent_response) {
967 /* This is a nasty hack. murrayc. */
968 /* Don't let the dialog close */
969 g_signal_stop_emission_by_name (wizard_dialog, "response");
972 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
975 if (response_id == GTK_RESPONSE_OK) {
976 /* Try to save the changes if modified (NB #59251): */
977 if (priv->modified || sec_changed) {
978 if (save_configuration (self)) {
979 /* Do not show the account-saved dialog if we are just saving this
980 * temporarily, because from the user's point of view it will not
981 * really be saved (saved + enabled) until later
983 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
984 ModestServerAccountSettings *store_settings;
985 ModestServerAccountSettings *transport_settings;
986 const gchar *store_account_name;
987 const gchar *transport_account_name;
990 store_settings = modest_account_settings_get_store_settings (priv->settings);
991 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
992 store_account_name = modest_server_account_settings_get_account_name (store_settings);
993 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
995 if (store_account_name) {
996 modest_account_mgr_notify_account_update (priv->account_manager,
999 if (transport_account_name) {
1000 modest_account_mgr_notify_account_update (priv->account_manager,
1001 transport_account_name);
1003 g_object_unref (store_settings);
1004 g_object_unref (transport_settings);
1006 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1009 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1016 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1018 ModestDefaultAccountSettingsDialogPrivate *priv;
1020 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1022 priv->incoming_security = NULL;
1023 priv->outgoing_security = NULL;
1025 /* Create the notebook to be used by the GtkDialog base class:
1026 * Each page of the notebook will be a page of the wizard: */
1027 priv->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1028 priv->settings = modest_account_settings_new ();
1030 /* Get the account manager object,
1031 * so we can check for existing accounts,
1032 * and create new accounts: */
1033 priv->account_manager = modest_runtime_get_account_mgr ();
1034 g_assert (priv->account_manager);
1035 g_object_ref (priv->account_manager);
1037 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1039 /* Create the common pages,
1041 priv->page_account_details = create_page_account_details (self);
1042 priv->page_user_details = create_page_user_details (self);
1043 priv->page_incoming = create_page_incoming (self);
1044 priv->page_outgoing = create_page_outgoing (self);
1046 /* Add the notebook pages: */
1047 gtk_notebook_append_page (priv->notebook, priv->page_account_details,
1048 gtk_label_new (_("mcen_ti_account_settings_account")));
1049 gtk_notebook_append_page (priv->notebook, priv->page_user_details,
1050 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1051 gtk_notebook_append_page (priv->notebook, priv->page_incoming,
1052 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1053 gtk_notebook_append_page (priv->notebook, priv->page_outgoing,
1054 gtk_label_new (_("mcen_ti_advsetup_sending")));
1056 GtkDialog *dialog = GTK_DIALOG (self);
1057 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (priv->notebook));
1058 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1059 gtk_widget_show (GTK_WIDGET (priv->notebook));
1061 /* Add the buttons: */
1062 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1063 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1065 /* Connect to the dialog's response signal: */
1066 /* We use connect-before
1067 * so we can stop the signal emission,
1068 * to stop the default signal handler from closing the dialog.
1070 g_signal_connect (G_OBJECT (self), "response",
1071 G_CALLBACK (on_response), self);
1073 priv->modified = FALSE;
1075 /* When this window is shown, hibernation should not be possible,
1076 * because there is no sensible way to save the state: */
1077 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1078 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1080 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1081 * while sending messages causes an error dialog and we have a lock */
1082 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1084 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1085 modest_maemo_utils_get_osso_context());
1088 ModestAccountSettingsDialog*
1089 modest_default_account_settings_dialog_new (void)
1091 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1094 /** Update the UI with the stored account details, so they can be edited.
1095 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1098 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1099 ModestAccountSettings *settings)
1101 ModestServerAccountSettings *incoming_account;
1102 ModestServerAccountSettings *outgoing_account;
1103 ModestProtocolRegistry *protocol_registry;
1104 const gchar *account_name, *server_account_name;
1105 ModestDefaultAccountSettingsDialogPrivate *priv;
1107 gboolean username_known;
1109 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1110 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1112 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1113 protocol_registry = modest_runtime_get_protocol_registry ();
1115 incoming_account = modest_account_settings_get_store_settings (settings);
1116 outgoing_account = modest_account_settings_get_transport_settings (settings);
1118 account_name = modest_account_settings_get_account_name (settings);
1120 /* Save the account name so we can refer to it later: */
1121 if (priv->account_name)
1122 g_free (priv->account_name);
1123 priv->account_name = g_strdup (account_name);
1126 g_object_unref (priv->settings);
1127 priv->settings = g_object_ref (settings);
1129 /* Save the account title so we can refer to it if the user changes it: */
1130 if (priv->original_account_title)
1131 g_free (priv->original_account_title);
1132 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1134 /* Show the account data in the widgets: */
1136 /* Note that we never show the non-display name in the UI.
1137 * (Though the display name defaults to the non-display name at the start.) */
1138 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1139 null_means_empty (modest_account_settings_get_display_name (settings)));
1140 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1141 null_means_empty (modest_account_settings_get_fullname (settings)));
1142 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1143 null_means_empty (modest_account_settings_get_email_address (settings)));
1144 modest_limit_retrieve_picker_set_active_limit_retrieve (
1145 MODEST_LIMIT_RETRIEVE_PICKER (priv->limit_retrieve_picker),
1146 modest_account_settings_get_retrieve_limit (settings));
1149 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages),
1150 modest_account_settings_get_leave_messages_on_server (settings));
1153 if (incoming_account) {
1154 const gchar *username, *password, *hostname, *proto_str, *account_title;
1155 gchar *proto_name, *title;
1156 ModestProtocolType incoming_protocol;
1158 modest_retrieve_picker_fill (MODEST_RETRIEVE_PICKER (priv->retrieve_picker), modest_server_account_settings_get_protocol (incoming_account));
1159 modest_retrieve_picker_set_active_retrieve_conf (MODEST_RETRIEVE_PICKER (priv->retrieve_picker),
1160 modest_account_settings_get_retrieve_type (settings));
1162 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1163 modest_server_account_settings_get_protocol (incoming_account))) {
1164 gtk_widget_hide (priv->caption_leave_messages);
1166 gtk_widget_show (priv->caption_leave_messages);
1169 /* Remember this for later: */
1170 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1172 hostname = modest_server_account_settings_get_hostname (incoming_account);
1173 username = modest_server_account_settings_get_username (incoming_account);
1174 password = modest_server_account_settings_get_password (incoming_account);
1175 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1176 null_means_empty (username));
1177 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1178 null_means_empty (password));
1180 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1181 null_means_empty (hostname));
1183 /* Load security settings */
1184 modest_security_options_view_load_settings (
1185 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1187 gtk_widget_show (priv->incoming_security);
1189 /* Update the incoming label */
1190 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1193 /* Set window title according to account */
1194 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1195 proto_name = g_utf8_strup (proto_str, -1);
1196 account_title = modest_account_settings_get_display_name(settings);
1197 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1199 gtk_window_set_title (GTK_WINDOW (dialog), title);
1201 g_free (proto_name);
1203 g_object_unref (incoming_account);
1206 outgoing_account = modest_account_settings_get_transport_settings (settings);
1207 if (outgoing_account) {
1208 const gchar *hostname;
1209 const gchar *username;
1210 const gchar *password;
1211 ModestProtocolType outgoing_protocol;
1213 /* Remember this for later: */
1215 modest_server_account_settings_get_protocol (outgoing_account);
1217 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1218 username = modest_server_account_settings_get_username (outgoing_account);
1219 password = modest_server_account_settings_get_password (outgoing_account);
1220 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1221 null_means_empty (hostname));
1223 /* Load security settings */
1224 modest_security_options_view_load_settings (
1225 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1227 gtk_widget_show (priv->outgoing_security);
1229 const gboolean has_specific =
1230 modest_account_settings_get_use_connection_specific_smtp (settings);
1231 gtk_toggle_button_set_active (
1232 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1234 g_object_unref (outgoing_account);
1237 /* Switch to user page */
1238 page_num = gtk_notebook_page_num (priv->notebook,priv->page_user_details);
1239 gtk_notebook_set_current_page (priv->notebook, page_num);
1241 /* Check if we allow changes or not */
1242 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1244 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1245 server_account_name);
1246 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1247 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1248 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1252 /* Unset the modified flag so we can detect changes later: */
1253 priv->modified = FALSE;
1257 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1259 const gchar* user_fullname;
1260 const gchar* emailaddress;
1261 ModestServerAccountSettings *store_settings;
1262 ModestServerAccountSettings *transport_settings;
1263 ModestAccountRetrieveType retrieve_type;
1264 gint retrieve_limit;
1265 gboolean leave_on_server;
1266 const gchar* hostname;
1267 const gchar* username;
1268 const gchar* password;
1269 gchar* account_title;
1270 ModestDefaultAccountSettingsDialogPrivate *priv;
1271 const gchar* account_name;
1273 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1274 account_name = priv->account_name;
1276 /* Set the account data from the widgets: */
1277 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1278 modest_account_settings_set_fullname (priv->settings, user_fullname);
1280 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1281 modest_account_settings_set_email_address (priv->settings, emailaddress);
1284 if (priv->signature_dialog) {
1285 gboolean use_signature = FALSE;
1287 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1290 modest_account_settings_set_use_signature (priv->settings, use_signature);
1291 modest_account_settings_set_signature (priv->settings, signature);
1294 retrieve_type = modest_retrieve_picker_get_active_retrieve_conf (
1295 MODEST_RETRIEVE_PICKER (priv->retrieve_picker));
1296 modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
1298 retrieve_limit = modest_limit_retrieve_picker_get_active_limit_retrieve (
1299 MODEST_LIMIT_RETRIEVE_PICKER (priv->limit_retrieve_picker));
1300 modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
1302 leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages));
1303 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1305 store_settings = modest_account_settings_get_store_settings (priv->settings);
1307 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1308 modest_server_account_settings_set_hostname (store_settings, hostname);
1310 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1311 modest_server_account_settings_set_username (store_settings, username);
1313 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1314 modest_server_account_settings_set_password (store_settings, password);
1316 /* Save security settings */
1317 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1320 g_object_unref (store_settings);
1323 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1325 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1326 modest_server_account_settings_set_hostname (transport_settings, hostname);
1328 /* Save security settings */
1329 modest_security_options_view_save_settings (
1330 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1333 /* Set the changed account title last, to simplify the previous code: */
1334 account_title = get_entered_account_title (dialog);
1336 return FALSE; /* Should be prevented already anyway. */
1338 /* if (strcmp (account_title, account_name) != 0) { */
1339 modest_account_settings_set_display_name (priv->settings, account_title);
1341 g_free (account_title);
1342 account_title = NULL;
1344 /* Save connection-specific SMTP server accounts: */
1345 modest_account_settings_set_use_connection_specific_smtp
1347 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1349 /* this configuration is not persistent, we should not save */
1350 if (account_name != NULL)
1351 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1356 static gboolean entry_is_empty (GtkWidget *entry)
1361 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1362 if ((!text) || (strlen(text) == 0))
1365 /* Strip it of whitespace at the start and end: */
1366 gchar *stripped = g_strdup (text);
1367 stripped = g_strstrip (stripped);
1372 const gboolean result = (strlen (stripped) == 0);
1380 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1382 gboolean enable_ok = TRUE;
1383 ModestProtocolRegistry *protocol_registry;
1384 ModestDefaultAccountSettingsDialogPrivate *priv;
1386 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1388 /* The account details title is mandatory: */
1389 if (entry_is_empty(priv->entry_account_title))
1392 /* The user details username is mandatory: */
1393 if (enable_ok && entry_is_empty(priv->entry_user_username))
1396 /* The user details email address is mandatory: */
1397 if (enable_ok && entry_is_empty (priv->entry_user_email))
1400 /* The custom incoming server is mandatory: */
1401 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1404 /* The custom outgoing server is mandatory: */
1405 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1408 protocol_registry = modest_runtime_get_protocol_registry ();
1410 /* Enable the buttons,
1411 * identifying them via their associated response codes:
1413 GtkDialog *dialog_base = GTK_DIALOG (self);
1414 gtk_dialog_set_response_sensitive (dialog_base,
1420 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1422 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1423 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1425 object_class->dispose = modest_default_account_settings_dialog_dispose;
1426 object_class->finalize = modest_default_account_settings_dialog_finalize;
1430 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1432 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1434 iface->load_settings = modest_default_account_settings_dialog_load_settings;