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/gtkcombobox.h>
36 #include <gtk/gtkentry.h>
37 #include <gtk/gtkbutton.h>
38 #include <gtk/gtkcheckbutton.h>
39 #include <gtk/gtkmessagedialog.h>
40 #include <gtk/gtkstock.h>
41 #include "modest-hildon-includes.h"
42 #include "modest-default-account-settings-dialog.h"
43 #include "modest-account-mgr.h"
44 #include "modest-secureauth-picker.h"
45 #include "widgets/modest-validating-entry.h"
46 #include "modest-retrieve-picker.h"
47 #include "widgets/modest-limit-retrieve-combo-box.h"
48 #include "modest-text-utils.h"
49 #include "modest-account-mgr.h"
50 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
51 #include <modest-server-account-settings.h>
52 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "modest-connection-specific-smtp-window.h"
54 #include "modest-signature-editor-dialog.h"
55 #include <modest-utils.h>
56 #include <modest-defs.h>
57 #include "modest-maemo-utils.h"
58 #include "modest-maemo-security-options-view.h"
59 #include "widgets/modest-ui-constants.h"
60 #include <tny-account.h>
61 #include <tny-status.h>
63 #include <gconf/gconf-client.h>
64 #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 GtkNotebook *notebook;
105 GtkWidget *page_account_details;
106 GtkWidget *entry_account_title;
107 GtkWidget *retrieve_picker;
108 GtkWidget *combo_limit_retrieve;
109 GtkWidget *caption_leave_messages;
110 GtkWidget *checkbox_leave_messages;
112 GtkWidget *page_user_details;
113 GtkWidget *entry_user_name;
114 GtkWidget *entry_user_username;
115 GtkWidget *entry_user_password;
116 GtkWidget *entry_user_email;
117 /* GtkWidget *entry_incoming_port; */
118 GtkWidget *button_signature;
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->signature_dialog)
177 gtk_widget_destroy (priv->signature_dialog);
179 if (priv->settings) {
180 g_object_unref (priv->settings);
181 priv->settings = NULL;
184 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
188 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
190 ModestDefaultAccountSettingsDialogPrivate *priv;
192 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
193 priv->modified = modified;
197 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
199 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
203 on_modified_picker_changed (HildonPickerButton *widget, gpointer user_data)
205 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
209 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
211 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
215 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
217 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
221 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
223 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
227 on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
229 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
230 gint value = hildon_number_editor_get_value (editor);
232 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
235 /* Set a modified boolean whenever the widget is changed,
236 * so we can check for it later.
239 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
241 if (HILDON_IS_NUMBER_EDITOR (widget)) {
242 g_signal_connect (G_OBJECT (widget), "notify::value",
243 G_CALLBACK (on_modified_number_editor_changed), self);
244 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
246 else if (GTK_IS_ENTRY (widget)) {
247 g_signal_connect (G_OBJECT (widget), "changed",
248 G_CALLBACK (on_modified_entry_changed), self);
249 } else if (GTK_IS_COMBO_BOX (widget)) {
250 g_signal_connect (G_OBJECT (widget), "changed",
251 G_CALLBACK (on_modified_combobox_changed), self);
252 } else if (HILDON_IS_PICKER_BUTTON (widget)) {
253 g_signal_connect (G_OBJECT (widget), "value-changed",
254 G_CALLBACK (on_modified_picker_changed), self);
255 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
256 g_signal_connect (G_OBJECT (widget), "toggled",
257 G_CALLBACK (on_modified_checkbox_toggled), self);
262 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
264 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
266 enable_buttons(self);
270 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
272 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
274 enable_buttons(self);
277 /** This is a convenience function to create a caption containing a mandatory widget.
278 * When the widget is edited, the enable_buttons() vfunc will be called.
281 create_caption_new_with_asterisk(ModestDefaultAccountSettingsDialog *self,
286 HildonCaptionStatus flag)
288 GtkWidget *caption = NULL;
290 /* Note: Previously, the translated strings already contained the "*",
291 * Comment out this code if they do again.
293 /* Add a * character to indicate mandatory fields,
294 * as specified in our "Email UI Specification": */
295 if (flag == HILDON_CAPTION_MANDATORY) {
296 gchar* title = g_strdup_printf("%s*", value);
297 caption = hildon_caption_new (group, title, control, icon, flag);
301 caption = hildon_caption_new (group, value, control, icon, flag);
303 /* Connect to the appropriate changed signal for the widget,
304 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
306 if (GTK_IS_ENTRY (control)) {
307 g_signal_connect (G_OBJECT (control), "changed",
308 G_CALLBACK (on_caption_entry_changed), self);
311 else if (GTK_IS_COMBO_BOX (control)) {
312 g_signal_connect (G_OBJECT (control), "changed",
313 G_CALLBACK (on_caption_combobox_changed), self);
320 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
324 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
325 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
327 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
334 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
338 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
339 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
341 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
349 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
351 modest_platform_information_banner (GTK_WIDGET (self), NULL,
352 _CS("ckdg_ib_maximum_characters_reached"));
356 create_page_account_details (ModestDefaultAccountSettingsDialog *self)
358 ModestDefaultAccountSettingsDialogPrivate *priv;
360 GtkAdjustment *focus_adjustment = NULL;
361 GtkSizeGroup* sizegroup;
362 GtkWidget *scrollwin;
364 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
365 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
366 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
367 scrollwin = gtk_scrolled_window_new (NULL, NULL);
368 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
369 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
371 /* The description widgets: */
372 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
373 /* Do use auto-capitalization: */
374 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
375 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
376 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
377 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
378 gtk_widget_show (priv->entry_account_title);
379 connect_for_modified (self, priv->entry_account_title);
380 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
381 gtk_widget_show (caption);
383 /* Prevent the use of some characters in the account title,
384 * as required by our UI specification: */
385 GList *list_prevent = NULL;
386 list_prevent = g_list_append (list_prevent, "\\");
387 list_prevent = g_list_append (list_prevent, "/");
388 list_prevent = g_list_append (list_prevent, ":");
389 list_prevent = g_list_append (list_prevent, "*");
390 list_prevent = g_list_append (list_prevent, "?");
391 list_prevent = g_list_append (list_prevent, "\"");
392 list_prevent = g_list_append (list_prevent, "<");
393 list_prevent = g_list_append (list_prevent, ">");
394 list_prevent = g_list_append (list_prevent, "|");
395 list_prevent = g_list_append (list_prevent, "^");
396 modest_validating_entry_set_unallowed_characters (
397 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
398 g_list_free (list_prevent);
399 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
400 on_entry_invalid_account_title_character, self);
402 /* Set max length as in the UI spec:
403 * The UI spec seems to want us to show a dialog if we hit the maximum. */
404 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
405 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
408 /* The retrieve combobox: */
409 priv->retrieve_picker = GTK_WIDGET (modest_retrieve_picker_new ());
410 hildon_button_set_title (HILDON_BUTTON (priv->retrieve_picker), _("mcen_fi_advsetup_retrievetype"));
411 gtk_widget_show (priv->retrieve_picker);
412 connect_for_modified (self, priv->retrieve_picker);
413 gtk_box_pack_start (GTK_BOX (box), priv->retrieve_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
415 /* The limit-retrieve combobox: */
416 priv->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
417 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
418 priv->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
419 gtk_widget_show (priv->combo_limit_retrieve);
420 connect_for_modified (self, priv->combo_limit_retrieve);
421 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
422 gtk_widget_show (caption);
424 /* The leave-messages widgets: */
425 if(!priv->checkbox_leave_messages)
426 priv->checkbox_leave_messages = gtk_check_button_new ();
427 if (!priv->caption_leave_messages) {
428 priv->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
429 priv->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
432 gtk_widget_show (priv->checkbox_leave_messages);
433 connect_for_modified (self, priv->checkbox_leave_messages);
434 gtk_box_pack_start (GTK_BOX (box), priv->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
435 gtk_widget_show (priv->caption_leave_messages);
437 g_object_unref (sizegroup);
439 gtk_widget_show (GTK_WIDGET (box));
441 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
442 gtk_widget_show (scrollwin);
444 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
445 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
447 return GTK_WIDGET (scrollwin);
451 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
453 ModestDefaultAccountSettingsDialogPrivate *priv;
454 const gchar* account_title;
456 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
457 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
459 if (!account_title || (strlen (account_title) == 0))
462 /* Strip it of whitespace at the start and end: */
463 gchar *result = g_strdup (account_title);
464 result = g_strstrip (result);
469 if (strlen (result) == 0) {
480 on_button_signature (GtkButton *button, gpointer user_data)
482 ModestDefaultAccountSettingsDialog *self;
484 ModestDefaultAccountSettingsDialogPrivate *priv;
486 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
487 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
489 /* Create the window, if necessary: */
490 if (!(priv->signature_dialog)) {
491 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
493 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
494 const gchar *signature = modest_account_settings_get_signature(priv->settings);
495 gchar* account_title = get_entered_account_title (self);
496 modest_signature_editor_dialog_set_settings (
497 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
498 use_signature, signature, account_title);
500 g_free (account_title);
501 account_title = NULL;
505 /* Show the window: */
506 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
507 GTK_WINDOW (priv->signature_dialog));
509 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
510 gtk_widget_hide (priv->signature_dialog);
511 if (response != GTK_RESPONSE_OK) {
512 /* Destroy the widget now, and its data: */
513 gtk_widget_destroy (priv->signature_dialog);
514 priv->signature_dialog = NULL;
516 /* Mark modified, so we use the dialog's data later: */
517 priv->modified = TRUE;
522 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
524 ModestDefaultAccountSettingsDialogPrivate *priv;
526 GtkAdjustment *focus_adjustment = NULL;
527 GtkSizeGroup* sizegroup;
528 GtkWidget *scrollwin;
530 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
532 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
533 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
534 scrollwin = gtk_scrolled_window_new (NULL, NULL);
535 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
536 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
538 /* The name widgets: */
539 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
541 /* Auto-capitalization is the default, so let's turn it off: */
542 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
543 /* Set max length as in the UI spec:
544 * The UI spec seems to want us to show a dialog if we hit the maximum. */
545 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
546 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
548 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
549 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
550 gtk_widget_show (priv->entry_user_name);
551 connect_for_modified (self, priv->entry_user_name);
552 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
553 gtk_widget_show (caption);
556 /* Prevent the use of some characters in the name,
557 * as required by our UI specification: */
558 GList *list_prevent = NULL;
559 list_prevent = g_list_append (list_prevent, "<");
560 list_prevent = g_list_append (list_prevent, ">");
561 modest_validating_entry_set_unallowed_characters (
562 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
563 g_list_free (list_prevent);
564 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
565 on_entry_invalid_fullname_character, self);
567 /* The username widgets: */
568 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
569 /* Auto-capitalization is the default, so let's turn it off: */
570 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
571 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
572 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
573 gtk_widget_show (priv->entry_user_username);
574 connect_for_modified (self, priv->entry_user_username);
575 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
576 gtk_widget_show (caption);
578 /* Prevent the use of some characters in the username,
579 * as required by our UI specification: */
580 modest_validating_entry_set_unallowed_characters_whitespace (
581 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
582 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
583 modest_utils_on_entry_invalid_character,
586 /* Set max length as in the UI spec:
587 * The UI spec seems to want us to show a dialog if we hit the maximum. */
588 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
589 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
592 /* The password widgets: */
593 priv->entry_user_password = gtk_entry_new ();
594 /* Auto-capitalization is the default, so let's turn it off: */
595 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
596 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
597 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
598 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
599 caption = create_caption_new_with_asterisk (self, sizegroup,
600 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
601 gtk_widget_show (priv->entry_user_password);
602 connect_for_modified (self, priv->entry_user_password);
603 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
604 gtk_widget_show (caption);
606 /* The email address widgets: */
607 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
608 /* Auto-capitalization is the default, so let's turn it off: */
609 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
610 caption = create_caption_new_with_asterisk (self, sizegroup,
611 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
612 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
613 gtk_widget_show (priv->entry_user_email);
614 connect_for_modified (self, priv->entry_user_email);
615 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
616 gtk_widget_show (caption);
618 /* Set max length as in the UI spec:
619 * The UI spec seems to want us to show a dialog if we hit the maximum. */
620 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
621 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
624 /* Signature button: */
625 if (!priv->button_signature)
626 priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
627 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
628 priv->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
629 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
630 gtk_widget_show (priv->button_signature);
631 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
632 gtk_widget_show (caption);
634 g_object_unref (sizegroup);
636 g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
637 G_CALLBACK (on_button_signature), self);
639 gtk_widget_show (GTK_WIDGET (box));
640 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
641 gtk_widget_show (scrollwin);
643 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
644 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
646 return GTK_WIDGET (scrollwin);
649 /* Change the caption title for the incoming server */
651 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
652 ModestProtocolType protocol_type)
654 ModestProtocolRegistry *protocol_registry;
655 ModestProtocol *protocol;
656 const gchar *protocol_display_name;
657 gchar* incomingserver_title;
658 gchar *with_asterisk;
659 ModestDefaultAccountSettingsDialogPrivate *priv;
661 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
663 protocol_registry = modest_runtime_get_protocol_registry ();
664 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
665 protocol_display_name = modest_protocol_get_display_name (protocol);
666 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"),
667 protocol_display_name);
669 /* This is a mandatory field, so add a *. This is usually done by
670 * create_caption_new_with_asterisk() but we can't use that here. */
671 with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
672 g_free (incomingserver_title);
674 g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
675 g_free (with_asterisk);
679 create_page_incoming (ModestDefaultAccountSettingsDialog *self)
681 ModestDefaultAccountSettingsDialogPrivate *priv;
683 GtkSizeGroup *sizegroup;
685 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
687 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
688 /* Create a size group to be used by all captions.
689 * Note that HildonCaption does not create a default size group if we do not specify one.
690 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
691 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
693 /* The incoming server widgets: */
694 if(!priv->entry_incomingserver)
695 priv->entry_incomingserver = gtk_entry_new ();
696 /* Auto-capitalization is the default, so let's turn it off: */
697 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
699 if (priv->caption_incoming)
700 gtk_widget_destroy (priv->caption_incoming);
702 /* The caption title will be updated in update_incoming_server_title().
703 * so this default text will never be seen: */
704 /* (Note: Changing the title seems pointless. murrayc) */
705 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
706 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
707 gtk_widget_show (priv->entry_incomingserver);
708 connect_for_modified (self, priv->entry_incomingserver);
709 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
710 gtk_widget_show (priv->caption_incoming);
712 /* Incoming security widgets */
713 priv->incoming_security =
714 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
716 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
717 FALSE, FALSE, MODEST_MARGIN_HALF);
719 gtk_widget_show (priv->incoming_security);
721 g_object_unref (sizegroup);
722 gtk_widget_show (GTK_WIDGET (box));
724 return GTK_WIDGET (box);
728 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
730 GtkWidget *widget = GTK_WIDGET (user_data);
732 /* Enable the widget only if the toggle button is active: */
733 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
734 gtk_widget_set_sensitive (widget, enable);
737 /* Make the sensitivity of a widget depend on a toggle button.
740 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
742 g_signal_connect (G_OBJECT (button), "toggled",
743 G_CALLBACK (on_toggle_button_changed), widget);
745 /* Set the starting sensitivity: */
746 on_toggle_button_changed (button, widget);
750 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
752 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
753 ModestConnectionSpecificSmtpWindow *smtp_win;
754 ModestDefaultAccountSettingsDialogPrivate *priv;
756 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
758 /* Create the window if necessary: */
759 smtp_win = modest_connection_specific_smtp_window_new ();
760 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
762 /* Show the window: */
763 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win));
764 gtk_widget_show (GTK_WIDGET (smtp_win));
765 priv->modified = TRUE;
769 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
773 /* Disable the OK button */
774 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
780 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
782 ModestDefaultAccountSettingsDialogPrivate *priv;
783 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
784 GtkAdjustment *focus_adjustment = NULL;
786 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
788 /* Put it all in a scrolled window, so that all widgets can be
789 * accessed even when the on-screen keyboard is visible: */
790 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
791 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
792 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
794 /* Create a size group to be used by all captions.
795 * Note that HildonCaption does not create a default size group if we do not specify one.
796 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
797 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
799 /* The outgoing server widgets: */
800 if (!priv->entry_outgoingserver)
801 priv->entry_outgoingserver = gtk_entry_new ();
802 /* Auto-capitalization is the default, so let's turn it off: */
803 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
804 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
805 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
806 gtk_widget_show (priv->entry_outgoingserver);
807 connect_for_modified (self, priv->entry_outgoingserver);
808 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
809 gtk_widget_show (caption);
811 /* Outgoing security widgets */
812 priv->outgoing_security =
813 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
815 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
816 FALSE, FALSE, MODEST_MARGIN_HALF);
817 gtk_widget_show (priv->outgoing_security);
818 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
819 G_CALLBACK (on_missing_mandatory_data), self);
821 GtkWidget *separator = gtk_hseparator_new ();
822 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
823 gtk_widget_show (separator);
825 /* connection-specific checkbox: */
826 if (!priv->checkbox_outgoing_smtp_specific) {
827 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
828 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
831 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
832 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
833 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
834 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
835 gtk_widget_show (caption);
836 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
838 /* Connection-specific SMTP-Severs Edit button: */
839 if (!priv->button_outgoing_smtp_servers)
840 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
841 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
842 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
843 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
844 gtk_widget_show (priv->button_outgoing_smtp_servers);
845 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
846 gtk_widget_show (caption);
848 /* Only enable the button when the checkbox is checked: */
849 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
850 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
852 g_object_unref (sizegroup);
854 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
855 G_CALLBACK (on_button_outgoing_smtp_servers), self);
857 gtk_widget_show (GTK_WIDGET (box));
858 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
859 gtk_widget_show(scrollwin);
861 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
862 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
864 return GTK_WIDGET (scrollwin);
868 check_data (ModestDefaultAccountSettingsDialog *self)
870 gchar* account_title;
871 const gchar* email_address;
872 const gchar* hostname;
873 const gchar* hostname2;
874 ModestDefaultAccountSettingsDialogPrivate *priv;
876 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
878 /* Check that the title is not already in use: */
879 account_title = get_entered_account_title (self);
881 return FALSE; /* Should be prevented already anyway. */
883 if (strcmp(account_title, priv->original_account_title) != 0) {
884 gboolean name_in_use;
886 /* Check the changed title: */
887 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
891 /* Warn the user via a dialog: */
892 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
894 g_free (account_title);
899 g_free (account_title);
900 account_title = NULL;
902 /* Check that the email address is valid: */
903 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
904 if ((!email_address) || (strlen(email_address) == 0)) {
908 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
909 /* Warn the user via a dialog: */
910 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
912 /* Return focus to the email address entry: */
913 gtk_widget_grab_focus (priv->entry_user_email);
914 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
918 /* make sure the domain name for the incoming server is valid */
919 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
920 if ((!hostname) || (strlen(hostname) == 0)) {
924 if (!modest_text_utils_validate_domain_name (hostname)) {
925 /* Warn the user via a dialog: */
926 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
928 /* Return focus to the email address entry: */
929 gtk_widget_grab_focus (priv->entry_incomingserver);
930 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
934 /* make sure the domain name for the outgoing server is valid */
935 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
936 if ((!hostname2) || (strlen(hostname2) == 0)) {
940 if (!modest_text_utils_validate_domain_name (hostname2)) {
941 /* Warn the user via a dialog: */
942 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
944 /* Return focus to the email address entry: */
945 gtk_widget_grab_focus (priv->entry_outgoingserver);
946 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
954 on_response (GtkDialog *wizard_dialog,
958 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
959 ModestDefaultAccountSettingsDialogPrivate *priv;
960 gboolean prevent_response = FALSE, sec_changed;
961 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
963 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
964 enable_buttons (self);
966 /* Check if security widgets changed */
967 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
968 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
970 modest_security_options_view_changed (incoming_sec, priv->settings) ||
971 modest_security_options_view_changed (outgoing_sec, priv->settings);
973 /* Warn about unsaved changes: */
974 if (response_id == GTK_RESPONSE_CANCEL && (priv->modified || sec_changed)) {
975 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
976 _("imum_nc_wizard_confirm_lose_changes")));
977 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
979 const gint dialog_response = gtk_dialog_run (dialog);
980 gtk_widget_destroy (GTK_WIDGET (dialog));
982 if (dialog_response != GTK_RESPONSE_OK)
983 prevent_response = TRUE;
985 /* Check for invalid input: */
986 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
987 prevent_response = TRUE;
990 if (prevent_response) {
991 /* This is a nasty hack. murrayc. */
992 /* Don't let the dialog close */
993 g_signal_stop_emission_by_name (wizard_dialog, "response");
996 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
999 if (response_id == GTK_RESPONSE_OK) {
1000 /* Try to save the changes if modified (NB #59251): */
1001 if (priv->modified || sec_changed) {
1002 if (save_configuration (self)) {
1003 /* Do not show the account-saved dialog if we are just saving this
1004 * temporarily, because from the user's point of view it will not
1005 * really be saved (saved + enabled) until later
1007 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
1008 ModestServerAccountSettings *store_settings;
1009 ModestServerAccountSettings *transport_settings;
1010 const gchar *store_account_name;
1011 const gchar *transport_account_name;
1014 store_settings = modest_account_settings_get_store_settings (priv->settings);
1015 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1016 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1017 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1019 if (store_account_name) {
1020 modest_account_mgr_notify_account_update (priv->account_manager,
1021 store_account_name);
1023 if (transport_account_name) {
1024 modest_account_mgr_notify_account_update (priv->account_manager,
1025 transport_account_name);
1027 g_object_unref (store_settings);
1028 g_object_unref (transport_settings);
1030 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1033 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1040 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1042 ModestDefaultAccountSettingsDialogPrivate *priv;
1044 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1046 priv->incoming_security = NULL;
1047 priv->outgoing_security = NULL;
1049 /* Create the notebook to be used by the GtkDialog base class:
1050 * Each page of the notebook will be a page of the wizard: */
1051 priv->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1052 priv->settings = modest_account_settings_new ();
1054 /* Get the account manager object,
1055 * so we can check for existing accounts,
1056 * and create new accounts: */
1057 priv->account_manager = modest_runtime_get_account_mgr ();
1058 g_assert (priv->account_manager);
1059 g_object_ref (priv->account_manager);
1061 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1063 /* Create the common pages,
1065 priv->page_account_details = create_page_account_details (self);
1066 priv->page_user_details = create_page_user_details (self);
1067 priv->page_incoming = create_page_incoming (self);
1068 priv->page_outgoing = create_page_outgoing (self);
1070 /* Add the notebook pages: */
1071 gtk_notebook_append_page (priv->notebook, priv->page_account_details,
1072 gtk_label_new (_("mcen_ti_account_settings_account")));
1073 gtk_notebook_append_page (priv->notebook, priv->page_user_details,
1074 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1075 gtk_notebook_append_page (priv->notebook, priv->page_incoming,
1076 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1077 gtk_notebook_append_page (priv->notebook, priv->page_outgoing,
1078 gtk_label_new (_("mcen_ti_advsetup_sending")));
1080 GtkDialog *dialog = GTK_DIALOG (self);
1081 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (priv->notebook));
1082 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1083 gtk_widget_show (GTK_WIDGET (priv->notebook));
1085 /* Add the buttons: */
1086 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1087 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1089 /* Connect to the dialog's response signal: */
1090 /* We use connect-before
1091 * so we can stop the signal emission,
1092 * to stop the default signal handler from closing the dialog.
1094 g_signal_connect (G_OBJECT (self), "response",
1095 G_CALLBACK (on_response), self);
1097 priv->modified = FALSE;
1099 /* When this window is shown, hibernation should not be possible,
1100 * because there is no sensible way to save the state: */
1101 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1102 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1104 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1105 * while sending messages causes an error dialog and we have a lock */
1106 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1108 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1109 modest_maemo_utils_get_osso_context());
1112 ModestAccountSettingsDialog*
1113 modest_default_account_settings_dialog_new (void)
1115 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1118 /** Update the UI with the stored account details, so they can be edited.
1119 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1122 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1123 ModestAccountSettings *settings)
1125 ModestServerAccountSettings *incoming_account;
1126 ModestServerAccountSettings *outgoing_account;
1127 ModestProtocolRegistry *protocol_registry;
1128 const gchar *account_name, *server_account_name;
1129 ModestDefaultAccountSettingsDialogPrivate *priv;
1131 gboolean username_known;
1133 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1134 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1136 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1137 protocol_registry = modest_runtime_get_protocol_registry ();
1139 incoming_account = modest_account_settings_get_store_settings (settings);
1140 outgoing_account = modest_account_settings_get_transport_settings (settings);
1142 account_name = modest_account_settings_get_account_name (settings);
1144 /* Save the account name so we can refer to it later: */
1145 if (priv->account_name)
1146 g_free (priv->account_name);
1147 priv->account_name = g_strdup (account_name);
1150 g_object_unref (priv->settings);
1151 priv->settings = g_object_ref (settings);
1153 /* Save the account title so we can refer to it if the user changes it: */
1154 if (priv->original_account_title)
1155 g_free (priv->original_account_title);
1156 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1158 /* Show the account data in the widgets: */
1160 /* Note that we never show the non-display name in the UI.
1161 * (Though the display name defaults to the non-display name at the start.) */
1162 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1163 null_means_empty (modest_account_settings_get_display_name (settings)));
1164 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1165 null_means_empty (modest_account_settings_get_fullname (settings)));
1166 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1167 null_means_empty (modest_account_settings_get_email_address (settings)));
1168 modest_limit_retrieve_combo_box_set_active_limit_retrieve (
1169 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve),
1170 modest_account_settings_get_retrieve_limit (settings));
1173 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages),
1174 modest_account_settings_get_leave_messages_on_server (settings));
1177 if (incoming_account) {
1178 const gchar *username, *password, *hostname, *proto_str, *account_title;
1179 gchar *proto_name, *title;
1180 ModestProtocolType incoming_protocol;
1182 modest_retrieve_picker_fill (MODEST_RETRIEVE_PICKER (priv->retrieve_picker), modest_server_account_settings_get_protocol (incoming_account));
1183 modest_retrieve_picker_set_active_retrieve_conf (MODEST_RETRIEVE_PICKER (priv->retrieve_picker),
1184 modest_account_settings_get_retrieve_type (settings));
1186 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1187 modest_server_account_settings_get_protocol (incoming_account))) {
1188 gtk_widget_hide (priv->caption_leave_messages);
1190 gtk_widget_show (priv->caption_leave_messages);
1193 /* Remember this for later: */
1194 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1196 hostname = modest_server_account_settings_get_hostname (incoming_account);
1197 username = modest_server_account_settings_get_username (incoming_account);
1198 password = modest_server_account_settings_get_password (incoming_account);
1199 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1200 null_means_empty (username));
1201 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1202 null_means_empty (password));
1204 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1205 null_means_empty (hostname));
1207 /* Load security settings */
1208 modest_security_options_view_load_settings (
1209 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1211 gtk_widget_show (priv->incoming_security);
1213 /* Update the incoming label */
1214 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1217 /* Set window title according to account */
1218 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1219 proto_name = g_utf8_strup (proto_str, -1);
1220 account_title = modest_account_settings_get_display_name(settings);
1221 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1223 gtk_window_set_title (GTK_WINDOW (dialog), title);
1225 g_free (proto_name);
1227 g_object_unref (incoming_account);
1230 outgoing_account = modest_account_settings_get_transport_settings (settings);
1231 if (outgoing_account) {
1232 const gchar *hostname;
1233 const gchar *username;
1234 const gchar *password;
1235 ModestProtocolType outgoing_protocol;
1237 /* Remember this for later: */
1239 modest_server_account_settings_get_protocol (outgoing_account);
1241 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1242 username = modest_server_account_settings_get_username (outgoing_account);
1243 password = modest_server_account_settings_get_password (outgoing_account);
1244 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1245 null_means_empty (hostname));
1247 /* Load security settings */
1248 modest_security_options_view_load_settings (
1249 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1251 gtk_widget_show (priv->outgoing_security);
1253 const gboolean has_specific =
1254 modest_account_settings_get_use_connection_specific_smtp (settings);
1255 gtk_toggle_button_set_active (
1256 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1258 g_object_unref (outgoing_account);
1261 /* Switch to user page */
1262 page_num = gtk_notebook_page_num (priv->notebook,priv->page_user_details);
1263 gtk_notebook_set_current_page (priv->notebook, page_num);
1265 /* Check if we allow changes or not */
1266 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1268 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1269 server_account_name);
1270 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1271 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1272 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1276 /* Unset the modified flag so we can detect changes later: */
1277 priv->modified = FALSE;
1281 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1283 const gchar* user_fullname;
1284 const gchar* emailaddress;
1285 ModestServerAccountSettings *store_settings;
1286 ModestServerAccountSettings *transport_settings;
1287 ModestAccountRetrieveType retrieve_type;
1288 gint retrieve_limit;
1289 gboolean leave_on_server;
1290 const gchar* hostname;
1291 const gchar* username;
1292 const gchar* password;
1293 gchar* account_title;
1294 ModestDefaultAccountSettingsDialogPrivate *priv;
1295 const gchar* account_name;
1297 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1298 account_name = priv->account_name;
1300 /* Set the account data from the widgets: */
1301 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1302 modest_account_settings_set_fullname (priv->settings, user_fullname);
1304 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1305 modest_account_settings_set_email_address (priv->settings, emailaddress);
1308 if (priv->signature_dialog) {
1309 gboolean use_signature = FALSE;
1311 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1314 modest_account_settings_set_use_signature (priv->settings, use_signature);
1315 modest_account_settings_set_signature (priv->settings, signature);
1318 retrieve_type = modest_retrieve_picker_get_active_retrieve_conf (
1319 MODEST_RETRIEVE_PICKER (priv->retrieve_picker));
1320 modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
1322 retrieve_limit = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1323 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve));
1324 modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
1326 leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages));
1327 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1329 store_settings = modest_account_settings_get_store_settings (priv->settings);
1331 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1332 modest_server_account_settings_set_hostname (store_settings, hostname);
1334 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1335 modest_server_account_settings_set_username (store_settings, username);
1337 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1338 modest_server_account_settings_set_password (store_settings, password);
1340 /* Save security settings */
1341 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1344 g_object_unref (store_settings);
1347 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1349 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1350 modest_server_account_settings_set_hostname (transport_settings, hostname);
1352 /* Save security settings */
1353 modest_security_options_view_save_settings (
1354 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1357 /* Set the changed account title last, to simplify the previous code: */
1358 account_title = get_entered_account_title (dialog);
1360 return FALSE; /* Should be prevented already anyway. */
1362 /* if (strcmp (account_title, account_name) != 0) { */
1363 modest_account_settings_set_display_name (priv->settings, account_title);
1365 g_free (account_title);
1366 account_title = NULL;
1368 /* Save connection-specific SMTP server accounts: */
1369 modest_account_settings_set_use_connection_specific_smtp
1371 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1373 /* this configuration is not persistent, we should not save */
1374 if (account_name != NULL)
1375 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1380 static gboolean entry_is_empty (GtkWidget *entry)
1385 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1386 if ((!text) || (strlen(text) == 0))
1389 /* Strip it of whitespace at the start and end: */
1390 gchar *stripped = g_strdup (text);
1391 stripped = g_strstrip (stripped);
1396 const gboolean result = (strlen (stripped) == 0);
1404 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1406 gboolean enable_ok = TRUE;
1407 ModestProtocolRegistry *protocol_registry;
1408 ModestDefaultAccountSettingsDialogPrivate *priv;
1410 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1412 /* The account details title is mandatory: */
1413 if (entry_is_empty(priv->entry_account_title))
1416 /* The user details username is mandatory: */
1417 if (enable_ok && entry_is_empty(priv->entry_user_username))
1420 /* The user details email address is mandatory: */
1421 if (enable_ok && entry_is_empty (priv->entry_user_email))
1424 /* The custom incoming server is mandatory: */
1425 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1428 /* The custom outgoing server is mandatory: */
1429 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1432 protocol_registry = modest_runtime_get_protocol_registry ();
1434 /* Enable the buttons,
1435 * identifying them via their associated response codes:
1437 GtkDialog *dialog_base = GTK_DIALOG (self);
1438 gtk_dialog_set_response_sensitive (dialog_base,
1444 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1446 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1447 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1449 object_class->dispose = modest_default_account_settings_dialog_dispose;
1450 object_class->finalize = modest_default_account_settings_dialog_finalize;
1454 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1456 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1458 iface->load_settings = modest_default_account_settings_dialog_load_settings;