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 "widgets/modest-secureauth-combo-box.h"
45 #include "widgets/modest-validating-entry.h"
46 #include "widgets/modest-retrieve-combo-box.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 *combo_retrieve;
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;
125 /* GtkWidget *combo_incoming_security; */
126 /* GtkWidget *checkbox_incoming_auth; */
128 GtkWidget *page_outgoing;
129 GtkWidget *entry_outgoingserver;
130 /* GtkWidget *caption_outgoing_username; */
131 /* GtkWidget *entry_outgoing_username; */
132 /* GtkWidget *caption_outgoing_password; */
133 /* GtkWidget *entry_outgoing_password; */
134 /* GtkWidget *combo_outgoing_security; */
135 /* GtkWidget *combo_outgoing_auth; */
136 /* GtkWidget *entry_outgoing_port; */
137 GtkWidget *checkbox_outgoing_smtp_specific;
138 GtkWidget *button_outgoing_smtp_servers;
140 GtkWidget *signature_dialog;
142 GtkWidget *incoming_security;
143 GtkWidget *outgoing_security;
147 enable_buttons (ModestDefaultAccountSettingsDialog *self);
150 save_configuration (ModestDefaultAccountSettingsDialog *dialog);
152 static const gchar * null_means_empty (const gchar * str);
155 null_means_empty (const gchar * str)
157 return str ? str : "";
161 modest_default_account_settings_dialog_dispose (GObject *object)
163 if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
164 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
168 modest_default_account_settings_dialog_finalize (GObject *object)
170 ModestDefaultAccountSettingsDialog *self;
171 ModestDefaultAccountSettingsDialogPrivate *priv;
173 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
174 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
176 if (priv->account_name)
177 g_free (priv->account_name);
179 if (priv->original_account_title)
180 g_free (priv->original_account_title);
182 if (priv->account_manager)
183 g_object_unref (G_OBJECT (priv->account_manager));
185 if (priv->signature_dialog)
186 gtk_widget_destroy (priv->signature_dialog);
188 if (priv->settings) {
189 g_object_unref (priv->settings);
190 priv->settings = NULL;
193 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
197 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
199 ModestDefaultAccountSettingsDialogPrivate *priv;
201 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
202 priv->modified = modified;
206 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
208 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
212 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
214 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
218 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
220 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
224 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
226 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
230 on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
232 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
233 gint value = hildon_number_editor_get_value (editor);
235 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
238 /* Set a modified boolean whenever the widget is changed,
239 * so we can check for it later.
242 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
244 if (HILDON_IS_NUMBER_EDITOR (widget)) {
245 g_signal_connect (G_OBJECT (widget), "notify::value",
246 G_CALLBACK (on_modified_number_editor_changed), self);
247 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
249 else if (GTK_IS_ENTRY (widget)) {
250 g_signal_connect (G_OBJECT (widget), "changed",
251 G_CALLBACK (on_modified_entry_changed), self);
252 } else if (GTK_IS_COMBO_BOX (widget)) {
253 g_signal_connect (G_OBJECT (widget), "changed",
254 G_CALLBACK (on_modified_combobox_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->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
410 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
411 priv->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
412 gtk_widget_show (priv->combo_retrieve);
413 connect_for_modified (self, priv->combo_retrieve);
414 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
415 gtk_widget_show (caption);
417 /* The limit-retrieve combobox: */
418 priv->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
419 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
420 priv->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
421 gtk_widget_show (priv->combo_limit_retrieve);
422 connect_for_modified (self, priv->combo_limit_retrieve);
423 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
424 gtk_widget_show (caption);
426 /* The leave-messages widgets: */
427 if(!priv->checkbox_leave_messages)
428 priv->checkbox_leave_messages = gtk_check_button_new ();
429 if (!priv->caption_leave_messages) {
430 priv->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
431 priv->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
434 gtk_widget_show (priv->checkbox_leave_messages);
435 connect_for_modified (self, priv->checkbox_leave_messages);
436 gtk_box_pack_start (GTK_BOX (box), priv->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
437 gtk_widget_show (priv->caption_leave_messages);
439 g_object_unref (sizegroup);
441 gtk_widget_show (GTK_WIDGET (box));
443 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
444 gtk_widget_show (scrollwin);
446 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
447 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
449 return GTK_WIDGET (scrollwin);
453 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
455 ModestDefaultAccountSettingsDialogPrivate *priv;
456 const gchar* account_title;
458 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
459 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
461 if (!account_title || (strlen (account_title) == 0))
464 /* Strip it of whitespace at the start and end: */
465 gchar *result = g_strdup (account_title);
466 result = g_strstrip (result);
471 if (strlen (result) == 0) {
482 on_button_signature (GtkButton *button, gpointer user_data)
484 ModestDefaultAccountSettingsDialog *self;
486 ModestDefaultAccountSettingsDialogPrivate *priv;
488 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
489 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
491 /* Create the window, if necessary: */
492 if (!(priv->signature_dialog)) {
493 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
495 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
496 const gchar *signature = modest_account_settings_get_signature(priv->settings);
497 gchar* account_title = get_entered_account_title (self);
498 modest_signature_editor_dialog_set_settings (
499 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
500 use_signature, signature, account_title);
502 g_free (account_title);
503 account_title = NULL;
507 /* Show the window: */
508 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
509 GTK_WINDOW (priv->signature_dialog));
511 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
512 gtk_widget_hide (priv->signature_dialog);
513 if (response != GTK_RESPONSE_OK) {
514 /* Destroy the widget now, and its data: */
515 gtk_widget_destroy (priv->signature_dialog);
516 priv->signature_dialog = NULL;
518 /* Mark modified, so we use the dialog's data later: */
519 priv->modified = TRUE;
524 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
526 ModestDefaultAccountSettingsDialogPrivate *priv;
528 GtkAdjustment *focus_adjustment = NULL;
529 GtkSizeGroup* sizegroup;
530 GtkWidget *scrollwin;
532 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
534 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
535 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
536 scrollwin = gtk_scrolled_window_new (NULL, NULL);
537 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
538 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
540 /* The name widgets: */
541 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
543 /* Auto-capitalization is the default, so let's turn it off: */
544 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
545 /* Set max length as in the UI spec:
546 * The UI spec seems to want us to show a dialog if we hit the maximum. */
547 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
548 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
550 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
551 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
552 gtk_widget_show (priv->entry_user_name);
553 connect_for_modified (self, priv->entry_user_name);
554 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
555 gtk_widget_show (caption);
558 /* Prevent the use of some characters in the name,
559 * as required by our UI specification: */
560 GList *list_prevent = NULL;
561 list_prevent = g_list_append (list_prevent, "<");
562 list_prevent = g_list_append (list_prevent, ">");
563 modest_validating_entry_set_unallowed_characters (
564 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
565 g_list_free (list_prevent);
566 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
567 on_entry_invalid_fullname_character, self);
569 /* The username widgets: */
570 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
571 /* Auto-capitalization is the default, so let's turn it off: */
572 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
573 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
574 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
575 gtk_widget_show (priv->entry_user_username);
576 connect_for_modified (self, priv->entry_user_username);
577 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
578 gtk_widget_show (caption);
580 /* Prevent the use of some characters in the username,
581 * as required by our UI specification: */
582 modest_validating_entry_set_unallowed_characters_whitespace (
583 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
584 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
585 modest_utils_on_entry_invalid_character,
588 /* Set max length as in the UI spec:
589 * The UI spec seems to want us to show a dialog if we hit the maximum. */
590 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
591 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
594 /* The password widgets: */
595 priv->entry_user_password = gtk_entry_new ();
596 /* Auto-capitalization is the default, so let's turn it off: */
597 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
598 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
599 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
600 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
601 caption = create_caption_new_with_asterisk (self, sizegroup,
602 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
603 gtk_widget_show (priv->entry_user_password);
604 connect_for_modified (self, priv->entry_user_password);
605 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
606 gtk_widget_show (caption);
608 /* The email address widgets: */
609 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
610 /* Auto-capitalization is the default, so let's turn it off: */
611 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
612 caption = create_caption_new_with_asterisk (self, sizegroup,
613 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
614 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
615 gtk_widget_show (priv->entry_user_email);
616 connect_for_modified (self, priv->entry_user_email);
617 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
618 gtk_widget_show (caption);
620 /* Set max length as in the UI spec:
621 * The UI spec seems to want us to show a dialog if we hit the maximum. */
622 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
623 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
626 /* Signature button: */
627 if (!priv->button_signature)
628 priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
629 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
630 priv->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
631 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
632 gtk_widget_show (priv->button_signature);
633 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
634 gtk_widget_show (caption);
636 g_object_unref (sizegroup);
638 g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
639 G_CALLBACK (on_button_signature), self);
641 gtk_widget_show (GTK_WIDGET (box));
642 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
643 gtk_widget_show (scrollwin);
645 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
646 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
648 return GTK_WIDGET (scrollwin);
651 /* Change the caption title for the incoming server */
653 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
654 ModestProtocolType protocol_type)
656 ModestProtocolRegistry *protocol_registry;
657 ModestProtocol *protocol;
658 const gchar *protocol_display_name;
659 gchar* incomingserver_title;
660 gchar *with_asterisk;
661 ModestDefaultAccountSettingsDialogPrivate *priv;
663 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
665 protocol_registry = modest_runtime_get_protocol_registry ();
666 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
667 protocol_display_name = modest_protocol_get_display_name (protocol);
668 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"),
669 protocol_display_name);
671 /* This is a mandatory field, so add a *. This is usually done by
672 * create_caption_new_with_asterisk() but we can't use that here. */
673 with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
674 g_free (incomingserver_title);
676 g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
677 g_free (with_asterisk);
681 create_page_incoming (ModestDefaultAccountSettingsDialog *self)
683 ModestDefaultAccountSettingsDialogPrivate *priv;
685 GtkSizeGroup *sizegroup;
687 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
689 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
690 /* Create a size group to be used by all captions.
691 * Note that HildonCaption does not create a default size group if we do not specify one.
692 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
693 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
695 /* The incoming server widgets: */
696 if(!priv->entry_incomingserver)
697 priv->entry_incomingserver = gtk_entry_new ();
698 /* Auto-capitalization is the default, so let's turn it off: */
699 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
701 if (priv->caption_incoming)
702 gtk_widget_destroy (priv->caption_incoming);
704 /* The caption title will be updated in update_incoming_server_title().
705 * so this default text will never be seen: */
706 /* (Note: Changing the title seems pointless. murrayc) */
707 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
708 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
709 gtk_widget_show (priv->entry_incomingserver);
710 connect_for_modified (self, priv->entry_incomingserver);
711 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
712 gtk_widget_show (priv->caption_incoming);
714 /* Incoming security widgets */
715 priv->incoming_security =
716 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
718 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
719 FALSE, FALSE, MODEST_MARGIN_HALF);
721 gtk_widget_show (priv->incoming_security);
723 g_object_unref (sizegroup);
724 gtk_widget_show (GTK_WIDGET (box));
726 return GTK_WIDGET (box);
730 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
732 GtkWidget *widget = GTK_WIDGET (user_data);
734 /* Enable the widget only if the toggle button is active: */
735 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
736 gtk_widget_set_sensitive (widget, enable);
739 /* Make the sensitivity of a widget depend on a toggle button.
742 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
744 g_signal_connect (G_OBJECT (button), "toggled",
745 G_CALLBACK (on_toggle_button_changed), widget);
747 /* Set the starting sensitivity: */
748 on_toggle_button_changed (button, widget);
752 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
754 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
755 ModestConnectionSpecificSmtpWindow *smtp_win;
756 ModestDefaultAccountSettingsDialogPrivate *priv;
758 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
760 /* Create the window if necessary: */
761 smtp_win = modest_connection_specific_smtp_window_new ();
762 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
764 /* Show the window: */
765 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win));
766 gtk_widget_show (GTK_WIDGET (smtp_win));
767 priv->modified = TRUE;
771 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
775 /* Disable the OK button */
776 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
782 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
784 ModestDefaultAccountSettingsDialogPrivate *priv;
785 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
786 GtkAdjustment *focus_adjustment = NULL;
788 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
790 /* Put it all in a scrolled window, so that all widgets can be
791 * accessed even when the on-screen keyboard is visible: */
792 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
793 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
794 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
796 /* Create a size group to be used by all captions.
797 * Note that HildonCaption does not create a default size group if we do not specify one.
798 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
799 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
801 /* The outgoing server widgets: */
802 if (!priv->entry_outgoingserver)
803 priv->entry_outgoingserver = gtk_entry_new ();
804 /* Auto-capitalization is the default, so let's turn it off: */
805 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
806 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
807 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
808 gtk_widget_show (priv->entry_outgoingserver);
809 connect_for_modified (self, priv->entry_outgoingserver);
810 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
811 gtk_widget_show (caption);
813 /* Outgoing security widgets */
814 priv->outgoing_security =
815 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
817 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
818 FALSE, FALSE, MODEST_MARGIN_HALF);
819 gtk_widget_show (priv->outgoing_security);
820 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
821 G_CALLBACK (on_missing_mandatory_data), self);
823 GtkWidget *separator = gtk_hseparator_new ();
824 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
825 gtk_widget_show (separator);
827 /* connection-specific checkbox: */
828 if (!priv->checkbox_outgoing_smtp_specific) {
829 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
830 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
833 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
834 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
835 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
836 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
837 gtk_widget_show (caption);
838 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
840 /* Connection-specific SMTP-Severs Edit button: */
841 if (!priv->button_outgoing_smtp_servers)
842 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
843 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
844 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
845 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
846 gtk_widget_show (priv->button_outgoing_smtp_servers);
847 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
848 gtk_widget_show (caption);
850 /* Only enable the button when the checkbox is checked: */
851 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
852 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
854 g_object_unref (sizegroup);
856 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
857 G_CALLBACK (on_button_outgoing_smtp_servers), self);
859 gtk_widget_show (GTK_WIDGET (box));
860 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
861 gtk_widget_show(scrollwin);
863 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
864 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
866 return GTK_WIDGET (scrollwin);
870 check_data (ModestDefaultAccountSettingsDialog *self)
872 gchar* account_title;
873 const gchar* email_address;
874 const gchar* hostname;
875 const gchar* hostname2;
876 ModestDefaultAccountSettingsDialogPrivate *priv;
878 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
880 /* Check that the title is not already in use: */
881 account_title = get_entered_account_title (self);
883 return FALSE; /* Should be prevented already anyway. */
885 if (strcmp(account_title, priv->original_account_title) != 0) {
886 gboolean name_in_use;
888 /* Check the changed title: */
889 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
893 /* Warn the user via a dialog: */
894 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
896 g_free (account_title);
901 g_free (account_title);
902 account_title = NULL;
904 /* Check that the email address is valid: */
905 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
906 if ((!email_address) || (strlen(email_address) == 0)) {
910 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
911 /* Warn the user via a dialog: */
912 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
914 /* Return focus to the email address entry: */
915 gtk_widget_grab_focus (priv->entry_user_email);
916 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
920 /* make sure the domain name for the incoming server is valid */
921 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
922 if ((!hostname) || (strlen(hostname) == 0)) {
926 if (!modest_text_utils_validate_domain_name (hostname)) {
927 /* Warn the user via a dialog: */
928 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
930 /* Return focus to the email address entry: */
931 gtk_widget_grab_focus (priv->entry_incomingserver);
932 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
936 /* make sure the domain name for the outgoing server is valid */
937 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
938 if ((!hostname2) || (strlen(hostname2) == 0)) {
942 if (!modest_text_utils_validate_domain_name (hostname2)) {
943 /* Warn the user via a dialog: */
944 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
946 /* Return focus to the email address entry: */
947 gtk_widget_grab_focus (priv->entry_outgoingserver);
948 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
956 on_response (GtkDialog *wizard_dialog,
960 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
961 ModestDefaultAccountSettingsDialogPrivate *priv;
962 gboolean prevent_response = FALSE, sec_changed;
963 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
965 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
966 enable_buttons (self);
968 /* Check if security widgets changed */
969 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
970 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
972 modest_security_options_view_changed (incoming_sec, priv->settings) ||
973 modest_security_options_view_changed (outgoing_sec, priv->settings);
975 /* Warn about unsaved changes: */
976 if (response_id == GTK_RESPONSE_CANCEL && (priv->modified || sec_changed)) {
977 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
978 _("imum_nc_wizard_confirm_lose_changes")));
979 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
981 const gint dialog_response = gtk_dialog_run (dialog);
982 gtk_widget_destroy (GTK_WIDGET (dialog));
984 if (dialog_response != GTK_RESPONSE_OK)
985 prevent_response = TRUE;
987 /* Check for invalid input: */
988 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
989 prevent_response = TRUE;
992 if (prevent_response) {
993 /* This is a nasty hack. murrayc. */
994 /* Don't let the dialog close */
995 g_signal_stop_emission_by_name (wizard_dialog, "response");
998 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
1001 if (response_id == GTK_RESPONSE_OK) {
1002 /* Try to save the changes if modified (NB #59251): */
1003 if (priv->modified || sec_changed) {
1004 if (save_configuration (self)) {
1005 /* Do not show the account-saved dialog if we are just saving this
1006 * temporarily, because from the user's point of view it will not
1007 * really be saved (saved + enabled) until later
1009 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
1010 ModestServerAccountSettings *store_settings;
1011 ModestServerAccountSettings *transport_settings;
1012 const gchar *store_account_name;
1013 const gchar *transport_account_name;
1016 store_settings = modest_account_settings_get_store_settings (priv->settings);
1017 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1018 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1019 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1021 if (store_account_name) {
1022 modest_account_mgr_notify_account_update (priv->account_manager,
1023 store_account_name);
1025 if (transport_account_name) {
1026 modest_account_mgr_notify_account_update (priv->account_manager,
1027 transport_account_name);
1029 g_object_unref (store_settings);
1030 g_object_unref (transport_settings);
1032 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1035 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1042 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1044 ModestDefaultAccountSettingsDialogPrivate *priv;
1046 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1048 priv->incoming_security = NULL;
1049 priv->outgoing_security = NULL;
1051 /* Create the notebook to be used by the GtkDialog base class:
1052 * Each page of the notebook will be a page of the wizard: */
1053 priv->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1054 priv->settings = modest_account_settings_new ();
1056 /* Get the account manager object,
1057 * so we can check for existing accounts,
1058 * and create new accounts: */
1059 priv->account_manager = modest_runtime_get_account_mgr ();
1060 g_assert (priv->account_manager);
1061 g_object_ref (priv->account_manager);
1063 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1065 /* Create the common pages,
1067 priv->page_account_details = create_page_account_details (self);
1068 priv->page_user_details = create_page_user_details (self);
1069 priv->page_incoming = create_page_incoming (self);
1070 priv->page_outgoing = create_page_outgoing (self);
1072 /* Add the notebook pages: */
1073 gtk_notebook_append_page (priv->notebook, priv->page_account_details,
1074 gtk_label_new (_("mcen_ti_account_settings_account")));
1075 gtk_notebook_append_page (priv->notebook, priv->page_user_details,
1076 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1077 gtk_notebook_append_page (priv->notebook, priv->page_incoming,
1078 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1079 gtk_notebook_append_page (priv->notebook, priv->page_outgoing,
1080 gtk_label_new (_("mcen_ti_advsetup_sending")));
1082 GtkDialog *dialog = GTK_DIALOG (self);
1083 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (priv->notebook));
1084 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1085 gtk_widget_show (GTK_WIDGET (priv->notebook));
1087 /* Add the buttons: */
1088 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1089 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1091 /* Connect to the dialog's response signal: */
1092 /* We use connect-before
1093 * so we can stop the signal emission,
1094 * to stop the default signal handler from closing the dialog.
1096 g_signal_connect (G_OBJECT (self), "response",
1097 G_CALLBACK (on_response), self);
1099 priv->modified = FALSE;
1101 /* When this window is shown, hibernation should not be possible,
1102 * because there is no sensible way to save the state: */
1103 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1104 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1106 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1107 * while sending messages causes an error dialog and we have a lock */
1108 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1110 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1111 modest_maemo_utils_get_osso_context());
1114 ModestAccountSettingsDialog*
1115 modest_default_account_settings_dialog_new (void)
1117 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1120 /** Update the UI with the stored account details, so they can be edited.
1121 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1124 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1125 ModestAccountSettings *settings)
1127 ModestServerAccountSettings *incoming_account;
1128 ModestServerAccountSettings *outgoing_account;
1129 ModestProtocolRegistry *protocol_registry;
1130 const gchar *account_name, *server_account_name;
1131 ModestDefaultAccountSettingsDialogPrivate *priv;
1133 gboolean username_known;
1135 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1136 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1138 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1139 protocol_registry = modest_runtime_get_protocol_registry ();
1141 incoming_account = modest_account_settings_get_store_settings (settings);
1142 outgoing_account = modest_account_settings_get_transport_settings (settings);
1144 account_name = modest_account_settings_get_account_name (settings);
1146 /* Save the account name so we can refer to it later: */
1147 if (priv->account_name)
1148 g_free (priv->account_name);
1149 priv->account_name = g_strdup (account_name);
1152 g_object_unref (priv->settings);
1153 priv->settings = g_object_ref (settings);
1155 /* Save the account title so we can refer to it if the user changes it: */
1156 if (priv->original_account_title)
1157 g_free (priv->original_account_title);
1158 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1160 /* Show the account data in the widgets: */
1162 /* Note that we never show the non-display name in the UI.
1163 * (Though the display name defaults to the non-display name at the start.) */
1164 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1165 null_means_empty (modest_account_settings_get_display_name (settings)));
1166 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1167 null_means_empty (modest_account_settings_get_fullname (settings)));
1168 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1169 null_means_empty (modest_account_settings_get_email_address (settings)));
1170 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve),
1171 modest_account_settings_get_retrieve_type (settings));
1172 modest_limit_retrieve_combo_box_set_active_limit_retrieve (
1173 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve),
1174 modest_account_settings_get_retrieve_limit (settings));
1177 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages),
1178 modest_account_settings_get_leave_messages_on_server (settings));
1181 if (incoming_account) {
1182 const gchar *username, *password, *hostname, *proto_str, *account_title;
1183 gchar *proto_name, *title;
1184 ModestProtocolType incoming_protocol;
1186 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve), modest_server_account_settings_get_protocol (incoming_account));
1188 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1189 modest_server_account_settings_get_protocol (incoming_account))) {
1190 gtk_widget_hide (priv->caption_leave_messages);
1192 gtk_widget_show (priv->caption_leave_messages);
1195 /* Remember this for later: */
1196 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1198 hostname = modest_server_account_settings_get_hostname (incoming_account);
1199 username = modest_server_account_settings_get_username (incoming_account);
1200 password = modest_server_account_settings_get_password (incoming_account);
1201 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1202 null_means_empty (username));
1203 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1204 null_means_empty (password));
1206 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1207 null_means_empty (hostname));
1209 /* Load security settings */
1210 modest_security_options_view_load_settings (
1211 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1213 gtk_widget_show (priv->incoming_security);
1215 /* Update the incoming label */
1216 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1219 /* Set window title according to account */
1220 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1221 proto_name = g_utf8_strup (proto_str, -1);
1222 account_title = modest_account_settings_get_display_name(settings);
1223 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1225 gtk_window_set_title (GTK_WINDOW (dialog), title);
1227 g_free (proto_name);
1229 g_object_unref (incoming_account);
1232 outgoing_account = modest_account_settings_get_transport_settings (settings);
1233 if (outgoing_account) {
1234 const gchar *hostname;
1235 const gchar *username;
1236 const gchar *password;
1237 ModestProtocolType outgoing_protocol;
1239 /* Remember this for later: */
1241 modest_server_account_settings_get_protocol (outgoing_account);
1243 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1244 username = modest_server_account_settings_get_username (outgoing_account);
1245 password = modest_server_account_settings_get_password (outgoing_account);
1246 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1247 null_means_empty (hostname));
1249 /* Load security settings */
1250 modest_security_options_view_load_settings (
1251 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1253 gtk_widget_show (priv->outgoing_security);
1255 const gboolean has_specific =
1256 modest_account_settings_get_use_connection_specific_smtp (settings);
1257 gtk_toggle_button_set_active (
1258 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1260 g_object_unref (outgoing_account);
1263 /* Switch to user page */
1264 page_num = gtk_notebook_page_num (priv->notebook,priv->page_user_details);
1265 gtk_notebook_set_current_page (priv->notebook, page_num);
1267 /* Check if we allow changes or not */
1268 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1270 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1271 server_account_name);
1272 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1273 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1274 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1278 /* Unset the modified flag so we can detect changes later: */
1279 priv->modified = FALSE;
1283 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1285 const gchar* user_fullname;
1286 const gchar* emailaddress;
1287 ModestServerAccountSettings *store_settings;
1288 ModestServerAccountSettings *transport_settings;
1289 ModestAccountRetrieveType retrieve_type;
1290 gint retrieve_limit;
1291 gboolean leave_on_server;
1292 const gchar* hostname;
1293 const gchar* username;
1294 const gchar* password;
1295 gchar* account_title;
1296 ModestDefaultAccountSettingsDialogPrivate *priv;
1297 const gchar* account_name;
1299 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1300 account_name = priv->account_name;
1302 /* Set the account data from the widgets: */
1303 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1304 modest_account_settings_set_fullname (priv->settings, user_fullname);
1306 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1307 modest_account_settings_set_email_address (priv->settings, emailaddress);
1310 if (priv->signature_dialog) {
1311 gboolean use_signature = FALSE;
1313 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1316 modest_account_settings_set_use_signature (priv->settings, use_signature);
1317 modest_account_settings_set_signature (priv->settings, signature);
1320 retrieve_type = modest_retrieve_combo_box_get_active_retrieve_conf (
1321 MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve));
1322 modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
1324 retrieve_limit = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1325 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve));
1326 modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
1328 leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages));
1329 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1331 store_settings = modest_account_settings_get_store_settings (priv->settings);
1333 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1334 modest_server_account_settings_set_hostname (store_settings, hostname);
1336 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1337 modest_server_account_settings_set_username (store_settings, username);
1339 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1340 modest_server_account_settings_set_password (store_settings, password);
1342 /* Save security settings */
1343 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1346 g_object_unref (store_settings);
1349 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1351 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1352 modest_server_account_settings_set_hostname (transport_settings, hostname);
1354 /* Save security settings */
1355 modest_security_options_view_save_settings (
1356 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1359 /* Set the changed account title last, to simplify the previous code: */
1360 account_title = get_entered_account_title (dialog);
1362 return FALSE; /* Should be prevented already anyway. */
1364 /* if (strcmp (account_title, account_name) != 0) { */
1365 modest_account_settings_set_display_name (priv->settings, account_title);
1367 g_free (account_title);
1368 account_title = NULL;
1370 /* Save connection-specific SMTP server accounts: */
1371 modest_account_settings_set_use_connection_specific_smtp
1373 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1375 /* this configuration is not persistent, we should not save */
1376 if (account_name != NULL)
1377 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1382 static gboolean entry_is_empty (GtkWidget *entry)
1387 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1388 if ((!text) || (strlen(text) == 0))
1391 /* Strip it of whitespace at the start and end: */
1392 gchar *stripped = g_strdup (text);
1393 stripped = g_strstrip (stripped);
1398 const gboolean result = (strlen (stripped) == 0);
1406 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1408 gboolean enable_ok = TRUE;
1409 ModestProtocolRegistry *protocol_registry;
1410 ModestDefaultAccountSettingsDialogPrivate *priv;
1412 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1414 /* The account details title is mandatory: */
1415 if (entry_is_empty(priv->entry_account_title))
1418 /* The user details username is mandatory: */
1419 if (enable_ok && entry_is_empty(priv->entry_user_username))
1422 /* The user details email address is mandatory: */
1423 if (enable_ok && entry_is_empty (priv->entry_user_email))
1426 /* The custom incoming server is mandatory: */
1427 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1430 /* The custom outgoing server is mandatory: */
1431 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1434 protocol_registry = modest_runtime_get_protocol_registry ();
1436 /* Enable the buttons,
1437 * identifying them via their associated response codes:
1439 GtkDialog *dialog_base = GTK_DIALOG (self);
1440 gtk_dialog_set_response_sensitive (dialog_base,
1446 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1448 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1449 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1451 object_class->dispose = modest_default_account_settings_dialog_dispose;
1452 object_class->finalize = modest_default_account_settings_dialog_finalize;
1456 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1458 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1460 iface->load_settings = modest_default_account_settings_dialog_load_settings;