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-serversecurity-combo-box.h"
45 #include "widgets/modest-secureauth-combo-box.h"
46 #include "widgets/modest-validating-entry.h"
47 #include "widgets/modest-retrieve-combo-box.h"
48 #include "widgets/modest-limit-retrieve-combo-box.h"
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
52 #include <modest-server-account-settings.h>
53 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
54 #include "maemo/modest-connection-specific-smtp-window.h"
55 #include "maemo/modest-signature-editor-dialog.h"
56 #include <modest-utils.h>
57 #include <modest-defs.h>
58 #include "maemo/modest-maemo-utils.h"
59 #include "maemo/modest-maemo-security-options-view.h"
60 #include "widgets/modest-ui-constants.h"
61 #include <tny-account.h>
62 #include <tny-status.h>
64 #include <gconf/gconf-client.h>
65 #include <string.h> /* For strlen(). */
67 /* Include config.h so that _() works: */
73 #define PORT_MAX 65535
75 static void modest_account_settings_dialog_init (gpointer g, gpointer iface_data);
77 G_DEFINE_TYPE_EXTENDED (ModestDefaultAccountSettingsDialog,
78 modest_default_account_settings_dialog,
81 G_IMPLEMENT_INTERFACE (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG,
82 modest_account_settings_dialog_init));
84 #define MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
85 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, ModestDefaultAccountSettingsDialogPrivate))
87 typedef struct _ModestDefaultAccountSettingsDialogPrivate ModestDefaultAccountSettingsDialogPrivate;
89 struct _ModestDefaultAccountSettingsDialogPrivate
91 /* Used by derived widgets to query existing accounts,
92 * and to create new accounts: */
93 ModestAccountMgr *account_manager;
94 ModestAccountSettings *settings;
97 gchar * account_name; /* This may not change. It is not user visible. */
98 ModestProtocolType incoming_protocol; /* This may not change. */
99 ModestProtocolType outgoing_protocol; /* This may not change. */
100 gchar * original_account_title;
102 ModestProtocolType protocol_authentication_incoming;
104 GtkNotebook *notebook;
106 GtkWidget *page_account_details;
107 GtkWidget *entry_account_title;
108 GtkWidget *combo_retrieve;
109 GtkWidget *combo_limit_retrieve;
110 GtkWidget *caption_leave_messages;
111 GtkWidget *checkbox_leave_messages;
113 GtkWidget *page_user_details;
114 GtkWidget *entry_user_name;
115 GtkWidget *entry_user_username;
116 GtkWidget *entry_user_password;
117 GtkWidget *entry_user_email;
118 /* GtkWidget *entry_incoming_port; */
119 GtkWidget *button_signature;
121 GtkWidget *page_complete_easysetup;
123 GtkWidget *page_incoming;
124 GtkWidget *caption_incoming;
125 GtkWidget *entry_incomingserver;
126 /* GtkWidget *combo_incoming_security; */
127 /* GtkWidget *checkbox_incoming_auth; */
129 GtkWidget *page_outgoing;
130 GtkWidget *entry_outgoingserver;
131 /* GtkWidget *caption_outgoing_username; */
132 /* GtkWidget *entry_outgoing_username; */
133 /* GtkWidget *caption_outgoing_password; */
134 /* GtkWidget *entry_outgoing_password; */
135 /* GtkWidget *combo_outgoing_security; */
136 /* GtkWidget *combo_outgoing_auth; */
137 /* GtkWidget *entry_outgoing_port; */
138 GtkWidget *checkbox_outgoing_smtp_specific;
139 GtkWidget *button_outgoing_smtp_servers;
141 GtkWidget *signature_dialog;
143 GtkWidget *incoming_security;
144 GtkWidget *outgoing_security;
148 enable_buttons (ModestDefaultAccountSettingsDialog *self);
151 save_configuration (ModestDefaultAccountSettingsDialog *dialog);
153 static const gchar * null_means_empty (const gchar * str);
156 null_means_empty (const gchar * str)
158 return str ? str : "";
162 modest_default_account_settings_dialog_dispose (GObject *object)
164 if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
165 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
169 modest_default_account_settings_dialog_finalize (GObject *object)
171 ModestDefaultAccountSettingsDialog *self;
172 ModestDefaultAccountSettingsDialogPrivate *priv;
174 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
175 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
177 if (priv->account_name)
178 g_free (priv->account_name);
180 if (priv->original_account_title)
181 g_free (priv->original_account_title);
183 if (priv->account_manager)
184 g_object_unref (G_OBJECT (priv->account_manager));
186 if (priv->signature_dialog)
187 gtk_widget_destroy (priv->signature_dialog);
189 if (priv->settings) {
190 g_object_unref (priv->settings);
191 priv->settings = NULL;
194 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
198 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
200 ModestDefaultAccountSettingsDialogPrivate *priv;
202 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
203 priv->modified = modified;
207 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
209 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
213 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
215 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
219 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
221 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
225 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
227 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
231 on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
233 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
234 gint value = hildon_number_editor_get_value (editor);
236 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
239 /* Set a modified boolean whenever the widget is changed,
240 * so we can check for it later.
243 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
245 if (HILDON_IS_NUMBER_EDITOR (widget)) {
246 g_signal_connect (G_OBJECT (widget), "notify::value",
247 G_CALLBACK (on_modified_number_editor_changed), self);
248 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
250 else if (GTK_IS_ENTRY (widget)) {
251 g_signal_connect (G_OBJECT (widget), "changed",
252 G_CALLBACK (on_modified_entry_changed), self);
253 } else if (GTK_IS_COMBO_BOX (widget)) {
254 g_signal_connect (G_OBJECT (widget), "changed",
255 G_CALLBACK (on_modified_combobox_changed), self);
256 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
257 g_signal_connect (G_OBJECT (widget), "toggled",
258 G_CALLBACK (on_modified_checkbox_toggled), self);
263 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
265 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
267 enable_buttons(self);
271 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
273 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
275 enable_buttons(self);
278 /** This is a convenience function to create a caption containing a mandatory widget.
279 * When the widget is edited, the enable_buttons() vfunc will be called.
282 create_caption_new_with_asterisk(ModestDefaultAccountSettingsDialog *self,
287 HildonCaptionStatus flag)
289 GtkWidget *caption = NULL;
291 /* Note: Previously, the translated strings already contained the "*",
292 * Comment out this code if they do again.
294 /* Add a * character to indicate mandatory fields,
295 * as specified in our "Email UI Specification": */
296 if (flag == HILDON_CAPTION_MANDATORY) {
297 gchar* title = g_strdup_printf("%s*", value);
298 caption = hildon_caption_new (group, title, control, icon, flag);
302 caption = hildon_caption_new (group, value, control, icon, flag);
304 /* Connect to the appropriate changed signal for the widget,
305 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
307 if (GTK_IS_ENTRY (control)) {
308 g_signal_connect (G_OBJECT (control), "changed",
309 G_CALLBACK (on_caption_entry_changed), self);
312 else if (GTK_IS_COMBO_BOX (control)) {
313 g_signal_connect (G_OBJECT (control), "changed",
314 G_CALLBACK (on_caption_combobox_changed), self);
321 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
325 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
326 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
328 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
335 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
339 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
340 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
342 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
350 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
352 modest_platform_information_banner (GTK_WIDGET (self), NULL,
353 _CS("ckdg_ib_maximum_characters_reached"));
357 create_page_account_details (ModestDefaultAccountSettingsDialog *self)
359 ModestDefaultAccountSettingsDialogPrivate *priv;
361 GtkAdjustment *focus_adjustment = NULL;
362 GtkSizeGroup* sizegroup;
363 GtkWidget *scrollwin;
365 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
366 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
367 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
368 scrollwin = gtk_scrolled_window_new (NULL, NULL);
369 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
370 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
372 /* The description widgets: */
373 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
374 /* Do use auto-capitalization: */
375 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
376 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
377 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
378 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
379 gtk_widget_show (priv->entry_account_title);
380 connect_for_modified (self, priv->entry_account_title);
381 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
382 gtk_widget_show (caption);
384 /* Prevent the use of some characters in the account title,
385 * as required by our UI specification: */
386 GList *list_prevent = NULL;
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 list_prevent = g_list_append (list_prevent, "^");
397 modest_validating_entry_set_unallowed_characters (
398 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
399 g_list_free (list_prevent);
400 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
401 on_entry_invalid_account_title_character, self);
403 /* Set max length as in the UI spec:
404 * The UI spec seems to want us to show a dialog if we hit the maximum. */
405 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
406 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
409 /* The retrieve combobox: */
410 priv->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
411 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
412 priv->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
413 gtk_widget_show (priv->combo_retrieve);
414 connect_for_modified (self, priv->combo_retrieve);
415 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
416 gtk_widget_show (caption);
418 /* The limit-retrieve combobox: */
419 priv->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
420 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
421 priv->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
422 gtk_widget_show (priv->combo_limit_retrieve);
423 connect_for_modified (self, priv->combo_limit_retrieve);
424 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
425 gtk_widget_show (caption);
427 /* The leave-messages widgets: */
428 if(!priv->checkbox_leave_messages)
429 priv->checkbox_leave_messages = gtk_check_button_new ();
430 if (!priv->caption_leave_messages) {
431 priv->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
432 priv->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
435 gtk_widget_show (priv->checkbox_leave_messages);
436 connect_for_modified (self, priv->checkbox_leave_messages);
437 gtk_box_pack_start (GTK_BOX (box), priv->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
438 gtk_widget_show (priv->caption_leave_messages);
440 g_object_unref (sizegroup);
442 gtk_widget_show (GTK_WIDGET (box));
444 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
445 gtk_widget_show (scrollwin);
447 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
448 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
450 return GTK_WIDGET (scrollwin);
454 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
456 ModestDefaultAccountSettingsDialogPrivate *priv;
457 const gchar* account_title;
459 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
460 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
462 if (!account_title || (strlen (account_title) == 0))
465 /* Strip it of whitespace at the start and end: */
466 gchar *result = g_strdup (account_title);
467 result = g_strstrip (result);
472 if (strlen (result) == 0) {
483 on_button_signature (GtkButton *button, gpointer user_data)
485 ModestDefaultAccountSettingsDialog *self;
487 ModestDefaultAccountSettingsDialogPrivate *priv;
489 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
490 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
492 /* Create the window, if necessary: */
493 if (!(priv->signature_dialog)) {
494 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
496 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
497 const gchar *signature = modest_account_settings_get_signature(priv->settings);
498 gchar* account_title = get_entered_account_title (self);
499 modest_signature_editor_dialog_set_settings (
500 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
501 use_signature, signature, account_title);
503 g_free (account_title);
504 account_title = NULL;
508 /* Show the window: */
509 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
510 GTK_WINDOW (priv->signature_dialog));
512 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
513 gtk_widget_hide (priv->signature_dialog);
514 if (response != GTK_RESPONSE_OK) {
515 /* Destroy the widget now, and its data: */
516 gtk_widget_destroy (priv->signature_dialog);
517 priv->signature_dialog = NULL;
519 /* Mark modified, so we use the dialog's data later: */
520 priv->modified = TRUE;
525 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
527 ModestDefaultAccountSettingsDialogPrivate *priv;
529 GtkAdjustment *focus_adjustment = NULL;
530 GtkSizeGroup* sizegroup;
531 GtkWidget *scrollwin;
533 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
535 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
536 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
537 scrollwin = gtk_scrolled_window_new (NULL, NULL);
538 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
539 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
541 /* The name widgets: */
542 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
544 /* Auto-capitalization is the default, so let's turn it off: */
545 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
546 /* Set max length as in the UI spec:
547 * The UI spec seems to want us to show a dialog if we hit the maximum. */
548 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
549 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
551 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
552 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
553 gtk_widget_show (priv->entry_user_name);
554 connect_for_modified (self, priv->entry_user_name);
555 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
556 gtk_widget_show (caption);
559 /* Prevent the use of some characters in the name,
560 * as required by our UI specification: */
561 GList *list_prevent = NULL;
562 list_prevent = g_list_append (list_prevent, "<");
563 list_prevent = g_list_append (list_prevent, ">");
564 modest_validating_entry_set_unallowed_characters (
565 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
566 g_list_free (list_prevent);
567 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
568 on_entry_invalid_fullname_character, self);
570 /* The username widgets: */
571 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
572 /* Auto-capitalization is the default, so let's turn it off: */
573 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
574 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
575 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
576 gtk_widget_show (priv->entry_user_username);
577 connect_for_modified (self, priv->entry_user_username);
578 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
579 gtk_widget_show (caption);
581 /* Prevent the use of some characters in the username,
582 * as required by our UI specification: */
583 modest_validating_entry_set_unallowed_characters_whitespace (
584 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
585 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
586 modest_utils_on_entry_invalid_character,
589 /* Set max length as in the UI spec:
590 * The UI spec seems to want us to show a dialog if we hit the maximum. */
591 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
592 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
595 /* The password widgets: */
596 priv->entry_user_password = gtk_entry_new ();
597 /* Auto-capitalization is the default, so let's turn it off: */
598 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
599 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
600 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
601 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
602 caption = create_caption_new_with_asterisk (self, sizegroup,
603 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
604 gtk_widget_show (priv->entry_user_password);
605 connect_for_modified (self, priv->entry_user_password);
606 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
607 gtk_widget_show (caption);
609 /* The email address widgets: */
610 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
611 /* Auto-capitalization is the default, so let's turn it off: */
612 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
613 caption = create_caption_new_with_asterisk (self, sizegroup,
614 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
615 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
616 gtk_widget_show (priv->entry_user_email);
617 connect_for_modified (self, priv->entry_user_email);
618 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
619 gtk_widget_show (caption);
621 /* Set max length as in the UI spec:
622 * The UI spec seems to want us to show a dialog if we hit the maximum. */
623 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
624 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
627 /* Signature button: */
628 if (!priv->button_signature)
629 priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
630 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
631 priv->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
632 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
633 gtk_widget_show (priv->button_signature);
634 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
635 gtk_widget_show (caption);
637 g_object_unref (sizegroup);
639 g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
640 G_CALLBACK (on_button_signature), self);
642 gtk_widget_show (GTK_WIDGET (box));
643 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
644 gtk_widget_show (scrollwin);
646 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
647 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
649 return GTK_WIDGET (scrollwin);
652 /* Change the caption title for the incoming server */
654 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
655 ModestProtocolType protocol_type)
657 ModestProtocolRegistry *protocol_registry;
658 ModestProtocol *protocol;
659 const gchar *protocol_display_name;
660 gchar* incomingserver_title;
661 gchar *with_asterisk;
662 ModestDefaultAccountSettingsDialogPrivate *priv;
664 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
666 protocol_registry = modest_runtime_get_protocol_registry ();
667 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
668 protocol_display_name = modest_protocol_get_display_name (protocol);
669 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"),
670 protocol_display_name);
672 /* This is a mandatory field, so add a *. This is usually done by
673 * create_caption_new_with_asterisk() but we can't use that here. */
674 with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
675 g_free (incomingserver_title);
677 g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
678 g_free (with_asterisk);
681 /** Change the caption title for the incoming server,
682 * as specified in the UI spec:
685 /* update_incoming_server_security_choices (ModestDefaultAccountSettingsDialog *self, */
686 /* ModestProtocolType protocol) */
688 /* /\* Fill the combo with appropriately titled choices for POP or IMAP. *\/ */
689 /* /\* The choices are the same, but the titles are different, as in the UI spec. *\/ */
690 /* modest_serversecurity_combo_box_fill ( */
691 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol); */
695 create_page_incoming (ModestDefaultAccountSettingsDialog *self)
697 ModestDefaultAccountSettingsDialogPrivate *priv;
699 GtkSizeGroup *sizegroup;
701 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
703 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
704 /* Create a size group to be used by all captions.
705 * Note that HildonCaption does not create a default size group if we do not specify one.
706 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
707 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
709 /* The incoming server widgets: */
710 if(!priv->entry_incomingserver)
711 priv->entry_incomingserver = gtk_entry_new ();
712 /* Auto-capitalization is the default, so let's turn it off: */
713 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
715 if (priv->caption_incoming)
716 gtk_widget_destroy (priv->caption_incoming);
718 /* The caption title will be updated in update_incoming_server_title().
719 * so this default text will never be seen: */
720 /* (Note: Changing the title seems pointless. murrayc) */
721 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
722 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
723 gtk_widget_show (priv->entry_incomingserver);
724 connect_for_modified (self, priv->entry_incomingserver);
725 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
726 gtk_widget_show (priv->caption_incoming);
728 /* Incoming security widgets */
729 priv->incoming_security =
730 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
732 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
733 FALSE, FALSE, MODEST_MARGIN_HALF);
735 gtk_widget_show (priv->incoming_security);
737 g_object_unref (sizegroup);
738 gtk_widget_show (GTK_WIDGET (box));
740 return GTK_WIDGET (box);
744 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
746 GtkWidget *widget = GTK_WIDGET (user_data);
748 /* Enable the widget only if the toggle button is active: */
749 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
750 gtk_widget_set_sensitive (widget, enable);
753 /* Make the sensitivity of a widget depend on a toggle button.
756 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
758 g_signal_connect (G_OBJECT (button), "toggled",
759 G_CALLBACK (on_toggle_button_changed), widget);
761 /* Set the starting sensitivity: */
762 on_toggle_button_changed (button, widget);
766 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
768 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
769 ModestConnectionSpecificSmtpWindow *smtp_win;
770 ModestDefaultAccountSettingsDialogPrivate *priv;
772 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
774 /* Create the window if necessary: */
775 smtp_win = modest_connection_specific_smtp_window_new ();
776 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
778 /* Show the window: */
779 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win));
780 gtk_widget_show (GTK_WIDGET (smtp_win));
781 priv->modified = TRUE;
785 /* on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data) */
787 /* ModestDefaultAccountSettingsDialog *self; */
788 /* ModestProtocolRegistry *protocol_registry; */
789 /* ModestProtocolType protocol_security; */
790 /* gboolean secureauth_used; */
792 /* self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data); */
793 /* protocol_registry = modest_runtime_get_protocol_registry (); */
795 /* protocol_security = */
796 /* modest_secureauth_combo_box_get_active_secureauth ( */
797 /* MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth)); */
798 /* secureauth_used = modest_protocol_registry_protocol_type_is_secure (protocol_registry, protocol_security); */
800 /* gtk_widget_set_sensitive (priv->caption_outgoing_username, secureauth_used); */
801 /* gtk_widget_set_sensitive (priv->caption_outgoing_password, secureauth_used); */
805 /* on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data) */
807 /* ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data); */
809 /* const gint port_number = */
810 /* modest_serversecurity_combo_box_get_active_serversecurity_port ( */
811 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security)); */
813 /* if(port_number != 0) { */
814 /* hildon_number_editor_set_value ( */
815 /* HILDON_NUMBER_EDITOR (priv->entry_outgoing_port), port_number); */
820 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
824 /* Disable the OK button */
825 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
831 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
833 ModestDefaultAccountSettingsDialogPrivate *priv;
834 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
835 GtkAdjustment *focus_adjustment = NULL;
837 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
839 /* Put it all in a scrolled window, so that all widgets can be
840 * accessed even when the on-screen keyboard is visible: */
841 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
842 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
843 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
845 /* Create a size group to be used by all captions.
846 * Note that HildonCaption does not create a default size group if we do not specify one.
847 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
848 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
850 /* The outgoing server widgets: */
851 if (!priv->entry_outgoingserver)
852 priv->entry_outgoingserver = gtk_entry_new ();
853 /* Auto-capitalization is the default, so let's turn it off: */
854 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
855 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
856 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
857 gtk_widget_show (priv->entry_outgoingserver);
858 connect_for_modified (self, priv->entry_outgoingserver);
859 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
860 gtk_widget_show (caption);
862 /* Outgoing security widgets */
863 priv->outgoing_security =
864 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
866 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
867 FALSE, FALSE, MODEST_MARGIN_HALF);
868 gtk_widget_show (priv->outgoing_security);
869 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
870 G_CALLBACK (on_missing_mandatory_data), self);
872 GtkWidget *separator = gtk_hseparator_new ();
873 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
874 gtk_widget_show (separator);
876 /* connection-specific checkbox: */
877 if (!priv->checkbox_outgoing_smtp_specific) {
878 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
879 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
882 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
883 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
884 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
885 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
886 gtk_widget_show (caption);
887 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
889 /* Connection-specific SMTP-Severs Edit button: */
890 if (!priv->button_outgoing_smtp_servers)
891 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
892 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
893 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
894 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
895 gtk_widget_show (priv->button_outgoing_smtp_servers);
896 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
897 gtk_widget_show (caption);
899 /* Only enable the button when the checkbox is checked: */
900 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
901 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
903 g_object_unref (sizegroup);
905 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
906 G_CALLBACK (on_button_outgoing_smtp_servers), self);
908 gtk_widget_show (GTK_WIDGET (box));
909 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
910 gtk_widget_show(scrollwin);
912 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
913 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
915 return GTK_WIDGET (scrollwin);
919 check_data (ModestDefaultAccountSettingsDialog *self)
921 gchar* account_title;
922 const gchar* email_address;
923 const gchar* hostname;
924 const gchar* hostname2;
925 ModestDefaultAccountSettingsDialogPrivate *priv;
927 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
929 /* Check that the title is not already in use: */
930 account_title = get_entered_account_title (self);
932 return FALSE; /* Should be prevented already anyway. */
934 if (strcmp(account_title, priv->original_account_title) != 0) {
935 gboolean name_in_use;
937 /* Check the changed title: */
938 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
942 /* Warn the user via a dialog: */
943 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
945 g_free (account_title);
950 g_free (account_title);
951 account_title = NULL;
953 /* Check that the email address is valid: */
954 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
955 if ((!email_address) || (strlen(email_address) == 0)) {
959 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
960 /* Warn the user via a dialog: */
961 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
963 /* Return focus to the email address entry: */
964 gtk_widget_grab_focus (priv->entry_user_email);
965 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
969 /* make sure the domain name for the incoming server is valid */
970 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
971 if ((!hostname) || (strlen(hostname) == 0)) {
975 if (!modest_text_utils_validate_domain_name (hostname)) {
976 /* Warn the user via a dialog: */
977 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
979 /* Return focus to the email address entry: */
980 gtk_widget_grab_focus (priv->entry_incomingserver);
981 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
985 /* make sure the domain name for the outgoing server is valid */
986 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
987 if ((!hostname2) || (strlen(hostname2) == 0)) {
991 if (!modest_text_utils_validate_domain_name (hostname2)) {
992 /* Warn the user via a dialog: */
993 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
995 /* Return focus to the email address entry: */
996 gtk_widget_grab_focus (priv->entry_outgoingserver);
997 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
1001 /* /\* Find a suitable authentication method when secure authentication is desired *\/ */
1002 /* port_num = hildon_number_editor_get_value ( */
1003 /* HILDON_NUMBER_EDITOR (priv->entry_incoming_port)); */
1004 /* username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)); */
1006 /* protocol_registry = modest_runtime_get_protocol_registry (); */
1008 /* protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity ( */
1009 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security)); */
1010 /* if (!modest_protocol_registry_protocol_type_is_secure(protocol_registry, protocol_security_incoming)) */
1012 /* if (gtk_toggle_button_get_active ( */
1013 /* GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))) { */
1014 /* GError *error = NULL; */
1015 /* GList *list_auth_methods; */
1017 /* list_auth_methods = */
1018 /* modest_utils_get_supported_secure_authentication_methods (priv->incoming_protocol, */
1019 /* hostname, port_num, username, GTK_WINDOW (self), &error); */
1020 /* if (list_auth_methods) { */
1021 /* GList* method; */
1023 /* /\* Use the first supported method. */
1024 /* * TODO: Should we prioritize them, to prefer a particular one? *\/ */
1025 /* for (method = list_auth_methods; method != NULL; method = g_list_next(method)) */
1027 /* ModestProtocolType proto = (ModestProtocolType)(GPOINTER_TO_INT(method->data)); */
1028 /* // Allow secure methods, e.g MD5 only */
1029 /* if (modest_protocol_registry_protocol_type_is_secure(protocol_registry, proto)) */
1031 /* priv->protocol_authentication_incoming = proto; */
1035 /* g_list_free (list_auth_methods); */
1038 /* if (list_auth_methods == NULL || */
1039 /* !modest_protocol_registry_protocol_type_is_secure(protocol_registry, priv->protocol_authentication_incoming)) */
1041 /* if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() || */
1042 /* error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED) */
1043 /* modest_platform_information_banner(GTK_WIDGET (self), NULL, */
1044 /* _("mcen_ib_unableto_discover_auth_methods")); */
1046 /* if(error != NULL) */
1047 /* g_error_free(error); */
1049 /* /\* This is a nasty hack. jschmid. *\/ */
1050 /* /\* Don't let the dialog close *\/ */
1051 /* /\*g_signal_stop_emission_by_name (dialog, "response");*\/ */
1061 on_response (GtkDialog *wizard_dialog,
1065 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
1066 ModestDefaultAccountSettingsDialogPrivate *priv;
1067 gboolean prevent_response = FALSE, sec_changed;
1068 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
1070 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1071 enable_buttons (self);
1073 /* Check if security widgets changed */
1074 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1075 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1077 modest_security_options_view_changed (incoming_sec, priv->settings) ||
1078 modest_security_options_view_changed (outgoing_sec, priv->settings);
1080 /* Warn about unsaved changes: */
1081 if (response_id == GTK_RESPONSE_CANCEL && (priv->modified || sec_changed)) {
1082 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1083 _("imum_nc_wizard_confirm_lose_changes")));
1084 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1086 const gint dialog_response = gtk_dialog_run (dialog);
1087 gtk_widget_destroy (GTK_WIDGET (dialog));
1089 if (dialog_response != GTK_RESPONSE_OK)
1090 prevent_response = TRUE;
1092 /* Check for invalid input: */
1093 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1094 prevent_response = TRUE;
1097 if (prevent_response) {
1098 /* This is a nasty hack. murrayc. */
1099 /* Don't let the dialog close */
1100 g_signal_stop_emission_by_name (wizard_dialog, "response");
1103 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
1106 if (response_id == GTK_RESPONSE_OK) {
1107 /* Try to save the changes if modified (NB #59251): */
1108 if (priv->modified || sec_changed) {
1109 if (save_configuration (self)) {
1110 /* Do not show the account-saved dialog if we are just saving this
1111 * temporarily, because from the user's point of view it will not
1112 * really be saved (saved + enabled) until later
1114 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
1115 ModestServerAccountSettings *store_settings;
1116 ModestServerAccountSettings *transport_settings;
1117 const gchar *store_account_name;
1118 const gchar *transport_account_name;
1121 store_settings = modest_account_settings_get_store_settings (priv->settings);
1122 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1123 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1124 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1126 if (store_account_name) {
1127 modest_account_mgr_notify_account_update (priv->account_manager,
1128 store_account_name);
1130 if (transport_account_name) {
1131 modest_account_mgr_notify_account_update (priv->account_manager,
1132 transport_account_name);
1134 g_object_unref (store_settings);
1135 g_object_unref (transport_settings);
1137 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1140 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1147 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1149 ModestDefaultAccountSettingsDialogPrivate *priv;
1151 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1153 priv->incoming_security = NULL;
1154 priv->outgoing_security = NULL;
1156 /* Create the notebook to be used by the GtkDialog base class:
1157 * Each page of the notebook will be a page of the wizard: */
1158 priv->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1159 priv->settings = modest_account_settings_new ();
1161 /* Get the account manager object,
1162 * so we can check for existing accounts,
1163 * and create new accounts: */
1164 priv->account_manager = modest_runtime_get_account_mgr ();
1165 g_assert (priv->account_manager);
1166 g_object_ref (priv->account_manager);
1168 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1170 /* Create the common pages,
1172 priv->page_account_details = create_page_account_details (self);
1173 priv->page_user_details = create_page_user_details (self);
1174 priv->page_incoming = create_page_incoming (self);
1175 priv->page_outgoing = create_page_outgoing (self);
1177 /* Add the notebook pages: */
1178 gtk_notebook_append_page (priv->notebook, priv->page_account_details,
1179 gtk_label_new (_("mcen_ti_account_settings_account")));
1180 gtk_notebook_append_page (priv->notebook, priv->page_user_details,
1181 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1182 gtk_notebook_append_page (priv->notebook, priv->page_incoming,
1183 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1184 gtk_notebook_append_page (priv->notebook, priv->page_outgoing,
1185 gtk_label_new (_("mcen_ti_advsetup_sending")));
1187 GtkDialog *dialog = GTK_DIALOG (self);
1188 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (priv->notebook));
1189 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1190 gtk_widget_show (GTK_WIDGET (priv->notebook));
1192 /* Add the buttons: */
1193 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1194 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1196 /* Connect to the dialog's response signal: */
1197 /* We use connect-before
1198 * so we can stop the signal emission,
1199 * to stop the default signal handler from closing the dialog.
1201 g_signal_connect (G_OBJECT (self), "response",
1202 G_CALLBACK (on_response), self);
1204 priv->modified = FALSE;
1206 /* When this window is shown, hibernation should not be possible,
1207 * because there is no sensible way to save the state: */
1208 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1209 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1211 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1212 * while sending messages causes an error dialog and we have a lock */
1213 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1215 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1216 modest_maemo_utils_get_osso_context());
1219 ModestAccountSettingsDialog*
1220 modest_default_account_settings_dialog_new (void)
1222 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1225 /** Update the UI with the stored account details, so they can be edited.
1226 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1229 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1230 ModestAccountSettings *settings)
1232 ModestServerAccountSettings *incoming_account;
1233 ModestServerAccountSettings *outgoing_account;
1234 ModestProtocolRegistry *protocol_registry;
1235 const gchar *account_name, *server_account_name;
1236 ModestDefaultAccountSettingsDialogPrivate *priv;
1238 gboolean username_known;
1240 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1241 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1243 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1244 protocol_registry = modest_runtime_get_protocol_registry ();
1246 incoming_account = modest_account_settings_get_store_settings (settings);
1247 outgoing_account = modest_account_settings_get_transport_settings (settings);
1249 account_name = modest_account_settings_get_account_name (settings);
1251 /* Save the account name so we can refer to it later: */
1252 if (priv->account_name)
1253 g_free (priv->account_name);
1254 priv->account_name = g_strdup (account_name);
1257 g_object_unref (priv->settings);
1258 priv->settings = g_object_ref (settings);
1260 /* Save the account title so we can refer to it if the user changes it: */
1261 if (priv->original_account_title)
1262 g_free (priv->original_account_title);
1263 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1265 /* Show the account data in the widgets: */
1267 /* Note that we never show the non-display name in the UI.
1268 * (Though the display name defaults to the non-display name at the start.) */
1269 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1270 null_means_empty (modest_account_settings_get_display_name (settings)));
1271 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1272 null_means_empty (modest_account_settings_get_fullname (settings)));
1273 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1274 null_means_empty (modest_account_settings_get_email_address (settings)));
1275 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve),
1276 modest_account_settings_get_retrieve_type (settings));
1277 modest_limit_retrieve_combo_box_set_active_limit_retrieve (
1278 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve),
1279 modest_account_settings_get_retrieve_limit (settings));
1282 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages),
1283 modest_account_settings_get_leave_messages_on_server (settings));
1286 if (incoming_account) {
1287 const gchar *username, *password, *hostname, *proto_str, *account_title;
1288 gchar *proto_name, *title;
1289 ModestProtocolType incoming_protocol;
1291 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve), modest_server_account_settings_get_protocol (incoming_account));
1293 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1294 modest_server_account_settings_get_protocol (incoming_account))) {
1295 gtk_widget_hide (priv->caption_leave_messages);
1297 gtk_widget_show (priv->caption_leave_messages);
1300 /* Remember this for later: */
1301 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1303 hostname = modest_server_account_settings_get_hostname (incoming_account);
1304 username = modest_server_account_settings_get_username (incoming_account);
1305 password = modest_server_account_settings_get_password (incoming_account);
1306 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1307 null_means_empty (username));
1308 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1309 null_means_empty (password));
1311 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1312 null_means_empty (hostname));
1314 /* Load security settings */
1315 modest_security_options_view_load_settings (
1316 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1318 gtk_widget_show (priv->incoming_security);
1320 /* Update the incoming label */
1321 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1324 /* Set window title according to account */
1325 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1326 proto_name = g_utf8_strup (proto_str, -1);
1327 account_title = modest_account_settings_get_display_name(settings);
1328 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1330 gtk_window_set_title (GTK_WINDOW (dialog), title);
1332 g_free (proto_name);
1334 g_object_unref (incoming_account);
1337 outgoing_account = modest_account_settings_get_transport_settings (settings);
1338 if (outgoing_account) {
1339 const gchar *hostname;
1340 const gchar *username;
1341 const gchar *password;
1342 ModestProtocolType outgoing_protocol;
1344 /* Remember this for later: */
1346 modest_server_account_settings_get_protocol (outgoing_account);
1348 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1349 username = modest_server_account_settings_get_username (outgoing_account);
1350 password = modest_server_account_settings_get_password (outgoing_account);
1351 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1352 null_means_empty (hostname));
1354 /* Load security settings */
1355 modest_security_options_view_load_settings (
1356 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1358 gtk_widget_show (priv->outgoing_security);
1360 const gboolean has_specific =
1361 modest_account_settings_get_use_connection_specific_smtp (settings);
1362 gtk_toggle_button_set_active (
1363 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1365 g_object_unref (outgoing_account);
1368 /* Switch to user page */
1369 page_num = gtk_notebook_page_num (priv->notebook,priv->page_user_details);
1370 gtk_notebook_set_current_page (priv->notebook, page_num);
1372 /* Check if we allow changes or not */
1373 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1375 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1376 server_account_name);
1377 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1378 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1379 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1383 /* Unset the modified flag so we can detect changes later: */
1384 priv->modified = FALSE;
1388 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1390 const gchar* user_fullname;
1391 const gchar* emailaddress;
1392 ModestServerAccountSettings *store_settings;
1393 ModestServerAccountSettings *transport_settings;
1394 ModestAccountRetrieveType retrieve_type;
1395 gint retrieve_limit;
1396 gboolean leave_on_server;
1397 const gchar* hostname;
1398 const gchar* username;
1399 const gchar* password;
1400 gchar* account_title;
1401 ModestDefaultAccountSettingsDialogPrivate *priv;
1402 const gchar* account_name;
1404 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1405 account_name = priv->account_name;
1407 /* Set the account data from the widgets: */
1408 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1409 modest_account_settings_set_fullname (priv->settings, user_fullname);
1411 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1412 modest_account_settings_set_email_address (priv->settings, emailaddress);
1415 if (priv->signature_dialog) {
1416 gboolean use_signature = FALSE;
1418 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1421 modest_account_settings_set_use_signature (priv->settings, use_signature);
1422 modest_account_settings_set_signature (priv->settings, signature);
1425 retrieve_type = modest_retrieve_combo_box_get_active_retrieve_conf (
1426 MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve));
1427 modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
1429 retrieve_limit = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1430 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve));
1431 modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
1433 leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages));
1434 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1436 store_settings = modest_account_settings_get_store_settings (priv->settings);
1438 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1439 modest_server_account_settings_set_hostname (store_settings, hostname);
1441 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1442 modest_server_account_settings_set_username (store_settings, username);
1444 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1445 modest_server_account_settings_set_password (store_settings, password);
1447 /* Save security settings */
1448 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1451 g_object_unref (store_settings);
1454 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1456 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1457 modest_server_account_settings_set_hostname (transport_settings, hostname);
1459 /* Save security settings */
1460 modest_security_options_view_save_settings (
1461 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1464 /* Set the changed account title last, to simplify the previous code: */
1465 account_title = get_entered_account_title (dialog);
1467 return FALSE; /* Should be prevented already anyway. */
1469 /* if (strcmp (account_title, account_name) != 0) { */
1470 modest_account_settings_set_display_name (priv->settings, account_title);
1472 g_free (account_title);
1473 account_title = NULL;
1475 /* Save connection-specific SMTP server accounts: */
1476 modest_account_settings_set_use_connection_specific_smtp
1478 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1480 /* this configuration is not persistent, we should not save */
1481 if (account_name != NULL)
1482 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1487 static gboolean entry_is_empty (GtkWidget *entry)
1492 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1493 if ((!text) || (strlen(text) == 0))
1496 /* Strip it of whitespace at the start and end: */
1497 gchar *stripped = g_strdup (text);
1498 stripped = g_strstrip (stripped);
1503 const gboolean result = (strlen (stripped) == 0);
1511 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1513 gboolean enable_ok = TRUE;
1514 ModestProtocolRegistry *protocol_registry;
1515 ModestDefaultAccountSettingsDialogPrivate *priv;
1517 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1519 /* The account details title is mandatory: */
1520 if (entry_is_empty(priv->entry_account_title))
1523 /* The user details username is mandatory: */
1524 if (enable_ok && entry_is_empty(priv->entry_user_username))
1527 /* The user details email address is mandatory: */
1528 if (enable_ok && entry_is_empty (priv->entry_user_email))
1531 /* The custom incoming server is mandatory: */
1532 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1535 /* The custom outgoing server is mandatory: */
1536 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1539 protocol_registry = modest_runtime_get_protocol_registry ();
1541 /* Enable the buttons,
1542 * identifying them via their associated response codes:
1544 GtkDialog *dialog_base = GTK_DIALOG (self);
1545 gtk_dialog_set_response_sensitive (dialog_base,
1551 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1553 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1554 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1556 object_class->dispose = modest_default_account_settings_dialog_dispose;
1557 object_class->finalize = modest_default_account_settings_dialog_finalize;
1561 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1563 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1565 iface->load_settings = modest_default_account_settings_dialog_load_settings;