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),
513 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
514 gtk_widget_hide (priv->signature_dialog);
515 if (response != GTK_RESPONSE_OK) {
516 /* Destroy the widget now, and its data: */
517 gtk_widget_destroy (priv->signature_dialog);
518 priv->signature_dialog = NULL;
520 /* Mark modified, so we use the dialog's data later: */
521 priv->modified = TRUE;
526 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
528 ModestDefaultAccountSettingsDialogPrivate *priv;
530 GtkAdjustment *focus_adjustment = NULL;
531 GtkSizeGroup* sizegroup;
532 GtkWidget *scrollwin;
534 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
536 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
537 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
538 scrollwin = gtk_scrolled_window_new (NULL, NULL);
539 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
540 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
542 /* The name widgets: */
543 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
545 /* Auto-capitalization is the default, so let's turn it off: */
546 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
547 /* Set max length as in the UI spec:
548 * The UI spec seems to want us to show a dialog if we hit the maximum. */
549 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
550 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
552 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
553 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
554 gtk_widget_show (priv->entry_user_name);
555 connect_for_modified (self, priv->entry_user_name);
556 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
557 gtk_widget_show (caption);
560 /* Prevent the use of some characters in the name,
561 * as required by our UI specification: */
562 GList *list_prevent = NULL;
563 list_prevent = g_list_append (list_prevent, "<");
564 list_prevent = g_list_append (list_prevent, ">");
565 modest_validating_entry_set_unallowed_characters (
566 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
567 g_list_free (list_prevent);
568 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
569 on_entry_invalid_fullname_character, self);
571 /* The username widgets: */
572 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
573 /* Auto-capitalization is the default, so let's turn it off: */
574 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
575 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
576 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
577 gtk_widget_show (priv->entry_user_username);
578 connect_for_modified (self, priv->entry_user_username);
579 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
580 gtk_widget_show (caption);
582 /* Prevent the use of some characters in the username,
583 * as required by our UI specification: */
584 modest_validating_entry_set_unallowed_characters_whitespace (
585 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
586 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
587 modest_utils_on_entry_invalid_character,
590 /* Set max length as in the UI spec:
591 * The UI spec seems to want us to show a dialog if we hit the maximum. */
592 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
593 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
596 /* The password widgets: */
597 priv->entry_user_password = gtk_entry_new ();
598 /* Auto-capitalization is the default, so let's turn it off: */
599 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
600 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
601 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
602 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
603 caption = create_caption_new_with_asterisk (self, sizegroup,
604 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
605 gtk_widget_show (priv->entry_user_password);
606 connect_for_modified (self, priv->entry_user_password);
607 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
608 gtk_widget_show (caption);
610 /* The email address widgets: */
611 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
612 /* Auto-capitalization is the default, so let's turn it off: */
613 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
614 caption = create_caption_new_with_asterisk (self, sizegroup,
615 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
616 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
617 gtk_widget_show (priv->entry_user_email);
618 connect_for_modified (self, priv->entry_user_email);
619 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
620 gtk_widget_show (caption);
622 /* Set max length as in the UI spec:
623 * The UI spec seems to want us to show a dialog if we hit the maximum. */
624 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
625 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
628 /* Signature button: */
629 if (!priv->button_signature)
630 priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
631 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
632 priv->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
633 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
634 gtk_widget_show (priv->button_signature);
635 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
636 gtk_widget_show (caption);
638 g_object_unref (sizegroup);
640 g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
641 G_CALLBACK (on_button_signature), self);
643 gtk_widget_show (GTK_WIDGET (box));
644 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
645 gtk_widget_show (scrollwin);
647 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
648 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
650 return GTK_WIDGET (scrollwin);
653 /* Change the caption title for the incoming server */
655 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
656 ModestProtocolType protocol_type)
658 ModestProtocolRegistry *protocol_registry;
659 ModestProtocol *protocol;
660 const gchar *protocol_display_name;
661 gchar* incomingserver_title;
662 gchar *with_asterisk;
663 ModestDefaultAccountSettingsDialogPrivate *priv;
665 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
667 protocol_registry = modest_runtime_get_protocol_registry ();
668 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
669 protocol_display_name = modest_protocol_get_display_name (protocol);
670 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"),
671 protocol_display_name);
673 /* This is a mandatory field, so add a *. This is usually done by
674 * create_caption_new_with_asterisk() but we can't use that here. */
675 with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
676 g_free (incomingserver_title);
678 g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
679 g_free (with_asterisk);
682 /** Change the caption title for the incoming server,
683 * as specified in the UI spec:
686 /* update_incoming_server_security_choices (ModestDefaultAccountSettingsDialog *self, */
687 /* ModestProtocolType protocol) */
689 /* /\* Fill the combo with appropriately titled choices for POP or IMAP. *\/ */
690 /* /\* The choices are the same, but the titles are different, as in the UI spec. *\/ */
691 /* modest_serversecurity_combo_box_fill ( */
692 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol); */
696 create_page_incoming (ModestDefaultAccountSettingsDialog *self)
698 ModestDefaultAccountSettingsDialogPrivate *priv;
700 GtkSizeGroup *sizegroup;
702 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
704 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
705 /* Create a size group to be used by all captions.
706 * Note that HildonCaption does not create a default size group if we do not specify one.
707 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
708 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
710 /* The incoming server widgets: */
711 if(!priv->entry_incomingserver)
712 priv->entry_incomingserver = gtk_entry_new ();
713 /* Auto-capitalization is the default, so let's turn it off: */
714 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
716 if (priv->caption_incoming)
717 gtk_widget_destroy (priv->caption_incoming);
719 /* The caption title will be updated in update_incoming_server_title().
720 * so this default text will never be seen: */
721 /* (Note: Changing the title seems pointless. murrayc) */
722 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
723 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
724 gtk_widget_show (priv->entry_incomingserver);
725 connect_for_modified (self, priv->entry_incomingserver);
726 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
727 gtk_widget_show (priv->caption_incoming);
729 /* Incoming security widgets */
730 priv->incoming_security =
731 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
733 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
734 FALSE, FALSE, MODEST_MARGIN_HALF);
736 gtk_widget_show (priv->incoming_security);
738 g_object_unref (sizegroup);
739 gtk_widget_show (GTK_WIDGET (box));
741 return GTK_WIDGET (box);
745 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
747 GtkWidget *widget = GTK_WIDGET (user_data);
749 /* Enable the widget only if the toggle button is active: */
750 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
751 gtk_widget_set_sensitive (widget, enable);
754 /* Make the sensitivity of a widget depend on a toggle button.
757 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
759 g_signal_connect (G_OBJECT (button), "toggled",
760 G_CALLBACK (on_toggle_button_changed), widget);
762 /* Set the starting sensitivity: */
763 on_toggle_button_changed (button, widget);
767 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
769 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
770 ModestConnectionSpecificSmtpWindow *smtp_win;
771 ModestDefaultAccountSettingsDialogPrivate *priv;
773 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
775 /* Create the window if necessary: */
776 smtp_win = modest_connection_specific_smtp_window_new ();
777 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
779 /* Show the window: */
780 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
781 GTK_WINDOW (smtp_win), GTK_WINDOW (self));
782 gtk_widget_show (GTK_WIDGET (smtp_win));
783 priv->modified = TRUE;
787 /* on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data) */
789 /* ModestDefaultAccountSettingsDialog *self; */
790 /* ModestProtocolRegistry *protocol_registry; */
791 /* ModestProtocolType protocol_security; */
792 /* gboolean secureauth_used; */
794 /* self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data); */
795 /* protocol_registry = modest_runtime_get_protocol_registry (); */
797 /* protocol_security = */
798 /* modest_secureauth_combo_box_get_active_secureauth ( */
799 /* MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth)); */
800 /* secureauth_used = modest_protocol_registry_protocol_type_is_secure (protocol_registry, protocol_security); */
802 /* gtk_widget_set_sensitive (priv->caption_outgoing_username, secureauth_used); */
803 /* gtk_widget_set_sensitive (priv->caption_outgoing_password, secureauth_used); */
807 /* on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data) */
809 /* ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data); */
811 /* const gint port_number = */
812 /* modest_serversecurity_combo_box_get_active_serversecurity_port ( */
813 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security)); */
815 /* if(port_number != 0) { */
816 /* hildon_number_editor_set_value ( */
817 /* HILDON_NUMBER_EDITOR (priv->entry_outgoing_port), port_number); */
822 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
826 /* Disable the OK button */
827 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
833 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
835 ModestDefaultAccountSettingsDialogPrivate *priv;
836 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
837 GtkAdjustment *focus_adjustment = NULL;
839 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
841 /* Put it all in a scrolled window, so that all widgets can be
842 * accessed even when the on-screen keyboard is visible: */
843 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
844 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
845 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
847 /* Create a size group to be used by all captions.
848 * Note that HildonCaption does not create a default size group if we do not specify one.
849 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
850 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
852 /* The outgoing server widgets: */
853 if (!priv->entry_outgoingserver)
854 priv->entry_outgoingserver = gtk_entry_new ();
855 /* Auto-capitalization is the default, so let's turn it off: */
856 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
857 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
858 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
859 gtk_widget_show (priv->entry_outgoingserver);
860 connect_for_modified (self, priv->entry_outgoingserver);
861 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
862 gtk_widget_show (caption);
864 /* Outgoing security widgets */
865 priv->outgoing_security =
866 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
868 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
869 FALSE, FALSE, MODEST_MARGIN_HALF);
870 gtk_widget_show (priv->outgoing_security);
871 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
872 G_CALLBACK (on_missing_mandatory_data), self);
874 GtkWidget *separator = gtk_hseparator_new ();
875 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
876 gtk_widget_show (separator);
878 /* connection-specific checkbox: */
879 if (!priv->checkbox_outgoing_smtp_specific) {
880 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
881 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
884 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
885 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
886 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
887 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
888 gtk_widget_show (caption);
889 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
891 /* Connection-specific SMTP-Severs Edit button: */
892 if (!priv->button_outgoing_smtp_servers)
893 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
894 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
895 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
896 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
897 gtk_widget_show (priv->button_outgoing_smtp_servers);
898 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
899 gtk_widget_show (caption);
901 /* Only enable the button when the checkbox is checked: */
902 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
903 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
905 g_object_unref (sizegroup);
907 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
908 G_CALLBACK (on_button_outgoing_smtp_servers), self);
910 gtk_widget_show (GTK_WIDGET (box));
911 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
912 gtk_widget_show(scrollwin);
914 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
915 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
917 return GTK_WIDGET (scrollwin);
921 check_data (ModestDefaultAccountSettingsDialog *self)
923 gchar* account_title;
924 const gchar* email_address;
925 const gchar* hostname;
926 const gchar* hostname2;
927 ModestDefaultAccountSettingsDialogPrivate *priv;
929 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
931 /* Check that the title is not already in use: */
932 account_title = get_entered_account_title (self);
934 return FALSE; /* Should be prevented already anyway. */
936 if (strcmp(account_title, priv->original_account_title) != 0) {
937 gboolean name_in_use;
939 /* Check the changed title: */
940 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
944 /* Warn the user via a dialog: */
945 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
947 g_free (account_title);
952 g_free (account_title);
953 account_title = NULL;
955 /* Check that the email address is valid: */
956 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
957 if ((!email_address) || (strlen(email_address) == 0)) {
961 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
962 /* Warn the user via a dialog: */
963 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
965 /* Return focus to the email address entry: */
966 gtk_widget_grab_focus (priv->entry_user_email);
967 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
971 /* make sure the domain name for the incoming server is valid */
972 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
973 if ((!hostname) || (strlen(hostname) == 0)) {
977 if (!modest_text_utils_validate_domain_name (hostname)) {
978 /* Warn the user via a dialog: */
979 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
981 /* Return focus to the email address entry: */
982 gtk_widget_grab_focus (priv->entry_incomingserver);
983 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
987 /* make sure the domain name for the outgoing server is valid */
988 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
989 if ((!hostname2) || (strlen(hostname2) == 0)) {
993 if (!modest_text_utils_validate_domain_name (hostname2)) {
994 /* Warn the user via a dialog: */
995 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
997 /* Return focus to the email address entry: */
998 gtk_widget_grab_focus (priv->entry_outgoingserver);
999 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
1003 /* /\* Find a suitable authentication method when secure authentication is desired *\/ */
1004 /* port_num = hildon_number_editor_get_value ( */
1005 /* HILDON_NUMBER_EDITOR (priv->entry_incoming_port)); */
1006 /* username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)); */
1008 /* protocol_registry = modest_runtime_get_protocol_registry (); */
1010 /* protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity ( */
1011 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security)); */
1012 /* if (!modest_protocol_registry_protocol_type_is_secure(protocol_registry, protocol_security_incoming)) */
1014 /* if (gtk_toggle_button_get_active ( */
1015 /* GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))) { */
1016 /* GError *error = NULL; */
1017 /* GList *list_auth_methods; */
1019 /* list_auth_methods = */
1020 /* modest_utils_get_supported_secure_authentication_methods (priv->incoming_protocol, */
1021 /* hostname, port_num, username, GTK_WINDOW (self), &error); */
1022 /* if (list_auth_methods) { */
1023 /* GList* method; */
1025 /* /\* Use the first supported method. */
1026 /* * TODO: Should we prioritize them, to prefer a particular one? *\/ */
1027 /* for (method = list_auth_methods; method != NULL; method = g_list_next(method)) */
1029 /* ModestProtocolType proto = (ModestProtocolType)(GPOINTER_TO_INT(method->data)); */
1030 /* // Allow secure methods, e.g MD5 only */
1031 /* if (modest_protocol_registry_protocol_type_is_secure(protocol_registry, proto)) */
1033 /* priv->protocol_authentication_incoming = proto; */
1037 /* g_list_free (list_auth_methods); */
1040 /* if (list_auth_methods == NULL || */
1041 /* !modest_protocol_registry_protocol_type_is_secure(protocol_registry, priv->protocol_authentication_incoming)) */
1043 /* if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() || */
1044 /* error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED) */
1045 /* modest_platform_information_banner(GTK_WIDGET (self), NULL, */
1046 /* _("mcen_ib_unableto_discover_auth_methods")); */
1048 /* if(error != NULL) */
1049 /* g_error_free(error); */
1051 /* /\* This is a nasty hack. jschmid. *\/ */
1052 /* /\* Don't let the dialog close *\/ */
1053 /* /\*g_signal_stop_emission_by_name (dialog, "response");*\/ */
1063 on_response (GtkDialog *wizard_dialog,
1067 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
1068 ModestDefaultAccountSettingsDialogPrivate *priv;
1069 gboolean prevent_response = FALSE, sec_changed;
1070 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
1072 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1073 enable_buttons (self);
1075 /* Check if security widgets changed */
1076 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1077 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1079 modest_security_options_view_changed (incoming_sec, priv->settings) ||
1080 modest_security_options_view_changed (outgoing_sec, priv->settings);
1082 /* Warn about unsaved changes: */
1083 if (response_id == GTK_RESPONSE_CANCEL && (priv->modified || sec_changed)) {
1084 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1085 _("imum_nc_wizard_confirm_lose_changes")));
1086 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1088 const gint dialog_response = gtk_dialog_run (dialog);
1089 gtk_widget_destroy (GTK_WIDGET (dialog));
1091 if (dialog_response != GTK_RESPONSE_OK)
1092 prevent_response = TRUE;
1094 /* Check for invalid input: */
1095 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1096 prevent_response = TRUE;
1099 if (prevent_response) {
1100 /* This is a nasty hack. murrayc. */
1101 /* Don't let the dialog close */
1102 g_signal_stop_emission_by_name (wizard_dialog, "response");
1105 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
1108 if (response_id == GTK_RESPONSE_OK) {
1109 /* Try to save the changes if modified (NB #59251): */
1110 if (priv->modified || sec_changed) {
1111 if (save_configuration (self)) {
1112 /* Do not show the account-saved dialog if we are just saving this
1113 * temporarily, because from the user's point of view it will not
1114 * really be saved (saved + enabled) until later
1116 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
1117 ModestServerAccountSettings *store_settings;
1118 ModestServerAccountSettings *transport_settings;
1119 const gchar *store_account_name;
1120 const gchar *transport_account_name;
1123 store_settings = modest_account_settings_get_store_settings (priv->settings);
1124 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1125 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1126 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1128 if (store_account_name) {
1129 modest_account_mgr_notify_account_update (priv->account_manager,
1130 store_account_name);
1132 if (transport_account_name) {
1133 modest_account_mgr_notify_account_update (priv->account_manager,
1134 transport_account_name);
1136 g_object_unref (store_settings);
1137 g_object_unref (transport_settings);
1139 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1142 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1149 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1151 ModestDefaultAccountSettingsDialogPrivate *priv;
1153 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1155 priv->incoming_security = NULL;
1156 priv->outgoing_security = NULL;
1158 /* Create the notebook to be used by the GtkDialog base class:
1159 * Each page of the notebook will be a page of the wizard: */
1160 priv->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1161 priv->settings = modest_account_settings_new ();
1163 /* Get the account manager object,
1164 * so we can check for existing accounts,
1165 * and create new accounts: */
1166 priv->account_manager = modest_runtime_get_account_mgr ();
1167 g_assert (priv->account_manager);
1168 g_object_ref (priv->account_manager);
1170 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1172 /* Create the common pages,
1174 priv->page_account_details = create_page_account_details (self);
1175 priv->page_user_details = create_page_user_details (self);
1176 priv->page_incoming = create_page_incoming (self);
1177 priv->page_outgoing = create_page_outgoing (self);
1179 /* Add the notebook pages: */
1180 gtk_notebook_append_page (priv->notebook, priv->page_account_details,
1181 gtk_label_new (_("mcen_ti_account_settings_account")));
1182 gtk_notebook_append_page (priv->notebook, priv->page_user_details,
1183 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1184 gtk_notebook_append_page (priv->notebook, priv->page_incoming,
1185 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1186 gtk_notebook_append_page (priv->notebook, priv->page_outgoing,
1187 gtk_label_new (_("mcen_ti_advsetup_sending")));
1189 GtkDialog *dialog = GTK_DIALOG (self);
1190 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (priv->notebook));
1191 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1192 gtk_widget_show (GTK_WIDGET (priv->notebook));
1194 /* Add the buttons: */
1195 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1196 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1198 /* Connect to the dialog's response signal: */
1199 /* We use connect-before
1200 * so we can stop the signal emission,
1201 * to stop the default signal handler from closing the dialog.
1203 g_signal_connect (G_OBJECT (self), "response",
1204 G_CALLBACK (on_response), self);
1206 priv->modified = FALSE;
1208 /* When this window is shown, hibernation should not be possible,
1209 * because there is no sensible way to save the state: */
1210 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1211 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1213 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1214 * while sending messages causes an error dialog and we have a lock */
1215 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1217 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1218 modest_maemo_utils_get_osso_context());
1221 ModestAccountSettingsDialog*
1222 modest_default_account_settings_dialog_new (void)
1224 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1227 /** Update the UI with the stored account details, so they can be edited.
1228 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1231 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1232 ModestAccountSettings *settings)
1234 ModestServerAccountSettings *incoming_account;
1235 ModestServerAccountSettings *outgoing_account;
1236 ModestProtocolRegistry *protocol_registry;
1237 const gchar *account_name, *server_account_name;
1238 ModestDefaultAccountSettingsDialogPrivate *priv;
1240 gboolean username_known;
1242 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1243 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1245 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1246 protocol_registry = modest_runtime_get_protocol_registry ();
1248 incoming_account = modest_account_settings_get_store_settings (settings);
1249 outgoing_account = modest_account_settings_get_transport_settings (settings);
1251 account_name = modest_account_settings_get_account_name (settings);
1253 /* Save the account name so we can refer to it later: */
1254 if (priv->account_name)
1255 g_free (priv->account_name);
1256 priv->account_name = g_strdup (account_name);
1259 g_object_unref (priv->settings);
1260 priv->settings = g_object_ref (settings);
1262 /* Save the account title so we can refer to it if the user changes it: */
1263 if (priv->original_account_title)
1264 g_free (priv->original_account_title);
1265 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1267 /* Show the account data in the widgets: */
1269 /* Note that we never show the non-display name in the UI.
1270 * (Though the display name defaults to the non-display name at the start.) */
1271 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1272 null_means_empty (modest_account_settings_get_display_name (settings)));
1273 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1274 null_means_empty (modest_account_settings_get_fullname (settings)));
1275 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1276 null_means_empty (modest_account_settings_get_email_address (settings)));
1277 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve),
1278 modest_account_settings_get_retrieve_type (settings));
1279 modest_limit_retrieve_combo_box_set_active_limit_retrieve (
1280 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve),
1281 modest_account_settings_get_retrieve_limit (settings));
1284 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages),
1285 modest_account_settings_get_leave_messages_on_server (settings));
1288 if (incoming_account) {
1289 const gchar *username, *password, *hostname, *proto_str, *account_title;
1290 gchar *proto_name, *title;
1291 ModestProtocolType incoming_protocol;
1293 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve), modest_server_account_settings_get_protocol (incoming_account));
1295 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1296 modest_server_account_settings_get_protocol (incoming_account))) {
1297 gtk_widget_hide (priv->caption_leave_messages);
1299 gtk_widget_show (priv->caption_leave_messages);
1302 /* Remember this for later: */
1303 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1305 hostname = modest_server_account_settings_get_hostname (incoming_account);
1306 username = modest_server_account_settings_get_username (incoming_account);
1307 password = modest_server_account_settings_get_password (incoming_account);
1308 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1309 null_means_empty (username));
1310 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1311 null_means_empty (password));
1313 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1314 null_means_empty (hostname));
1316 /* Load security settings */
1317 modest_security_options_view_load_settings (
1318 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1320 gtk_widget_show (priv->incoming_security);
1322 /* Update the incoming label */
1323 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1326 /* Set window title according to account */
1327 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1328 proto_name = g_utf8_strup (proto_str, -1);
1329 account_title = modest_account_settings_get_display_name(settings);
1330 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1332 gtk_window_set_title (GTK_WINDOW (dialog), title);
1334 g_free (proto_name);
1336 g_object_unref (incoming_account);
1339 outgoing_account = modest_account_settings_get_transport_settings (settings);
1340 if (outgoing_account) {
1341 const gchar *hostname;
1342 const gchar *username;
1343 const gchar *password;
1344 ModestProtocolType outgoing_protocol;
1346 /* Remember this for later: */
1348 modest_server_account_settings_get_protocol (outgoing_account);
1350 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1351 username = modest_server_account_settings_get_username (outgoing_account);
1352 password = modest_server_account_settings_get_password (outgoing_account);
1353 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1354 null_means_empty (hostname));
1356 /* Load security settings */
1357 modest_security_options_view_load_settings (
1358 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1360 gtk_widget_show (priv->outgoing_security);
1362 const gboolean has_specific =
1363 modest_account_settings_get_use_connection_specific_smtp (settings);
1364 gtk_toggle_button_set_active (
1365 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1367 g_object_unref (outgoing_account);
1370 /* Switch to user page */
1371 page_num = gtk_notebook_page_num (priv->notebook,priv->page_user_details);
1372 gtk_notebook_set_current_page (priv->notebook, page_num);
1374 /* Check if we allow changes or not */
1375 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1377 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1378 server_account_name);
1379 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1380 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1381 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1385 /* Unset the modified flag so we can detect changes later: */
1386 priv->modified = FALSE;
1390 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1392 const gchar* user_fullname;
1393 const gchar* emailaddress;
1394 ModestServerAccountSettings *store_settings;
1395 ModestServerAccountSettings *transport_settings;
1396 ModestAccountRetrieveType retrieve_type;
1397 gint retrieve_limit;
1398 gboolean leave_on_server;
1399 const gchar* hostname;
1400 const gchar* username;
1401 const gchar* password;
1402 gchar* account_title;
1403 ModestDefaultAccountSettingsDialogPrivate *priv;
1404 const gchar* account_name;
1406 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1407 account_name = priv->account_name;
1409 /* Set the account data from the widgets: */
1410 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1411 modest_account_settings_set_fullname (priv->settings, user_fullname);
1413 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1414 modest_account_settings_set_email_address (priv->settings, emailaddress);
1417 if (priv->signature_dialog) {
1418 gboolean use_signature = FALSE;
1420 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1423 modest_account_settings_set_use_signature (priv->settings, use_signature);
1424 modest_account_settings_set_signature (priv->settings, signature);
1427 retrieve_type = modest_retrieve_combo_box_get_active_retrieve_conf (
1428 MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve));
1429 modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
1431 retrieve_limit = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1432 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve));
1433 modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
1435 leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages));
1436 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1438 store_settings = modest_account_settings_get_store_settings (priv->settings);
1440 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1441 modest_server_account_settings_set_hostname (store_settings, hostname);
1443 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1444 modest_server_account_settings_set_username (store_settings, username);
1446 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1447 modest_server_account_settings_set_password (store_settings, password);
1449 /* Save security settings */
1450 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1453 g_object_unref (store_settings);
1456 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1458 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1459 modest_server_account_settings_set_hostname (transport_settings, hostname);
1461 /* Save security settings */
1462 modest_security_options_view_save_settings (
1463 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1466 /* Set the changed account title last, to simplify the previous code: */
1467 account_title = get_entered_account_title (dialog);
1469 return FALSE; /* Should be prevented already anyway. */
1471 /* if (strcmp (account_title, account_name) != 0) { */
1472 modest_account_settings_set_display_name (priv->settings, account_title);
1474 g_free (account_title);
1475 account_title = NULL;
1477 /* Save connection-specific SMTP server accounts: */
1478 modest_account_settings_set_use_connection_specific_smtp
1480 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1482 /* this configuration is not persistent, we should not save */
1483 if (account_name != NULL)
1484 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1489 static gboolean entry_is_empty (GtkWidget *entry)
1494 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1495 if ((!text) || (strlen(text) == 0))
1498 /* Strip it of whitespace at the start and end: */
1499 gchar *stripped = g_strdup (text);
1500 stripped = g_strstrip (stripped);
1505 const gboolean result = (strlen (stripped) == 0);
1513 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1515 gboolean enable_ok = TRUE;
1516 ModestProtocolRegistry *protocol_registry;
1517 ModestDefaultAccountSettingsDialogPrivate *priv;
1519 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1521 /* The account details title is mandatory: */
1522 if (entry_is_empty(priv->entry_account_title))
1525 /* The user details username is mandatory: */
1526 if (enable_ok && entry_is_empty(priv->entry_user_username))
1529 /* The user details email address is mandatory: */
1530 if (enable_ok && entry_is_empty (priv->entry_user_email))
1533 /* The custom incoming server is mandatory: */
1534 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1537 /* The custom outgoing server is mandatory: */
1538 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1541 protocol_registry = modest_runtime_get_protocol_registry ();
1543 /* Enable the buttons,
1544 * identifying them via their associated response codes:
1546 GtkDialog *dialog_base = GTK_DIALOG (self);
1547 gtk_dialog_set_response_sensitive (dialog_base,
1553 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1555 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1556 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1558 object_class->dispose = modest_default_account_settings_dialog_dispose;
1559 object_class->finalize = modest_default_account_settings_dialog_finalize;
1563 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1565 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1567 iface->load_settings = modest_default_account_settings_dialog_load_settings;