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 *button_signature;
120 GtkWidget *page_complete_easysetup;
122 GtkWidget *page_incoming;
123 GtkWidget *caption_incoming;
124 GtkWidget *entry_incomingserver;
126 GtkWidget *page_outgoing;
127 GtkWidget *entry_outgoingserver;
128 GtkWidget *checkbox_outgoing_smtp_specific;
129 GtkWidget *button_outgoing_smtp_servers;
131 GtkWidget *signature_dialog;
133 GtkWidget *incoming_security;
134 GtkWidget *outgoing_security;
138 enable_buttons (ModestDefaultAccountSettingsDialog *self);
141 save_configuration (ModestDefaultAccountSettingsDialog *dialog);
143 static const gchar * null_means_empty (const gchar * str);
146 null_means_empty (const gchar * str)
148 return str ? str : "";
152 modest_default_account_settings_dialog_dispose (GObject *object)
154 if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
155 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
159 modest_default_account_settings_dialog_finalize (GObject *object)
161 ModestDefaultAccountSettingsDialog *self;
162 ModestDefaultAccountSettingsDialogPrivate *priv;
164 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
165 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
167 if (priv->account_name)
168 g_free (priv->account_name);
170 if (priv->original_account_title)
171 g_free (priv->original_account_title);
173 if (priv->account_manager)
174 g_object_unref (G_OBJECT (priv->account_manager));
176 if (priv->signature_dialog)
177 gtk_widget_destroy (priv->signature_dialog);
179 if (priv->settings) {
180 g_object_unref (priv->settings);
181 priv->settings = NULL;
184 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
188 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
190 ModestDefaultAccountSettingsDialogPrivate *priv;
192 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
193 priv->modified = modified;
197 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
199 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
203 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
205 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
209 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
211 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
215 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
217 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
221 on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
223 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
224 gint value = hildon_number_editor_get_value (editor);
226 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
229 /* Set a modified boolean whenever the widget is changed,
230 * so we can check for it later.
233 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
235 if (HILDON_IS_NUMBER_EDITOR (widget)) {
236 g_signal_connect (G_OBJECT (widget), "notify::value",
237 G_CALLBACK (on_modified_number_editor_changed), self);
238 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
240 else if (GTK_IS_ENTRY (widget)) {
241 g_signal_connect (G_OBJECT (widget), "changed",
242 G_CALLBACK (on_modified_entry_changed), self);
243 } else if (GTK_IS_COMBO_BOX (widget)) {
244 g_signal_connect (G_OBJECT (widget), "changed",
245 G_CALLBACK (on_modified_combobox_changed), self);
246 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
247 g_signal_connect (G_OBJECT (widget), "toggled",
248 G_CALLBACK (on_modified_checkbox_toggled), self);
253 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
255 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
257 enable_buttons(self);
261 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
263 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
265 enable_buttons(self);
268 /** This is a convenience function to create a caption containing a mandatory widget.
269 * When the widget is edited, the enable_buttons() vfunc will be called.
272 create_caption_new_with_asterisk(ModestDefaultAccountSettingsDialog *self,
277 HildonCaptionStatus flag)
279 GtkWidget *caption = NULL;
281 /* Note: Previously, the translated strings already contained the "*",
282 * Comment out this code if they do again.
284 /* Add a * character to indicate mandatory fields,
285 * as specified in our "Email UI Specification": */
286 if (flag == HILDON_CAPTION_MANDATORY) {
287 gchar* title = g_strdup_printf("%s*", value);
288 caption = hildon_caption_new (group, title, control, icon, flag);
292 caption = hildon_caption_new (group, value, control, icon, flag);
294 /* Connect to the appropriate changed signal for the widget,
295 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
297 if (GTK_IS_ENTRY (control)) {
298 g_signal_connect (G_OBJECT (control), "changed",
299 G_CALLBACK (on_caption_entry_changed), self);
302 else if (GTK_IS_COMBO_BOX (control)) {
303 g_signal_connect (G_OBJECT (control), "changed",
304 G_CALLBACK (on_caption_combobox_changed), self);
311 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
315 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
316 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
318 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
325 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
329 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
330 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
332 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
340 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
342 modest_platform_information_banner (GTK_WIDGET (self), NULL,
343 _CS("ckdg_ib_maximum_characters_reached"));
347 create_page_account_details (ModestDefaultAccountSettingsDialog *self)
349 ModestDefaultAccountSettingsDialogPrivate *priv;
351 GtkAdjustment *focus_adjustment = NULL;
352 GtkSizeGroup* sizegroup;
353 GtkWidget *scrollwin;
355 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
356 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
357 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
358 scrollwin = gtk_scrolled_window_new (NULL, NULL);
359 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
360 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
362 /* The description widgets: */
363 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
364 /* Do use auto-capitalization: */
365 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
366 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
367 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
368 priv->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
369 gtk_widget_show (priv->entry_account_title);
370 connect_for_modified (self, priv->entry_account_title);
371 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
372 gtk_widget_show (caption);
374 /* Prevent the use of some characters in the account title,
375 * as required by our UI specification: */
376 GList *list_prevent = NULL;
377 list_prevent = g_list_append (list_prevent, "\\");
378 list_prevent = g_list_append (list_prevent, "/");
379 list_prevent = g_list_append (list_prevent, ":");
380 list_prevent = g_list_append (list_prevent, "*");
381 list_prevent = g_list_append (list_prevent, "?");
382 list_prevent = g_list_append (list_prevent, "\"");
383 list_prevent = g_list_append (list_prevent, "<");
384 list_prevent = g_list_append (list_prevent, ">");
385 list_prevent = g_list_append (list_prevent, "|");
386 list_prevent = g_list_append (list_prevent, "^");
387 modest_validating_entry_set_unallowed_characters (
388 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
389 g_list_free (list_prevent);
390 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
391 on_entry_invalid_account_title_character, self);
393 /* Set max length as in the UI spec:
394 * The UI spec seems to want us to show a dialog if we hit the maximum. */
395 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
396 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
399 /* The retrieve combobox: */
400 priv->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
401 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
402 priv->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
403 gtk_widget_show (priv->combo_retrieve);
404 connect_for_modified (self, priv->combo_retrieve);
405 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
406 gtk_widget_show (caption);
408 /* The limit-retrieve combobox: */
409 priv->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
410 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
411 priv->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
412 gtk_widget_show (priv->combo_limit_retrieve);
413 connect_for_modified (self, priv->combo_limit_retrieve);
414 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
415 gtk_widget_show (caption);
417 /* The leave-messages widgets: */
418 if(!priv->checkbox_leave_messages)
419 priv->checkbox_leave_messages = gtk_check_button_new ();
420 if (!priv->caption_leave_messages) {
421 priv->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
422 priv->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
425 gtk_widget_show (priv->checkbox_leave_messages);
426 connect_for_modified (self, priv->checkbox_leave_messages);
427 gtk_box_pack_start (GTK_BOX (box), priv->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
428 gtk_widget_show (priv->caption_leave_messages);
430 g_object_unref (sizegroup);
432 gtk_widget_show (GTK_WIDGET (box));
434 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
435 gtk_widget_show (scrollwin);
437 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
438 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
440 return GTK_WIDGET (scrollwin);
444 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
446 ModestDefaultAccountSettingsDialogPrivate *priv;
447 const gchar* account_title;
449 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
450 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
452 if (!account_title || (strlen (account_title) == 0))
455 /* Strip it of whitespace at the start and end: */
456 gchar *result = g_strdup (account_title);
457 result = g_strstrip (result);
462 if (strlen (result) == 0) {
473 on_button_signature (GtkButton *button, gpointer user_data)
475 ModestDefaultAccountSettingsDialog *self;
477 ModestDefaultAccountSettingsDialogPrivate *priv;
479 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
480 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
482 /* Create the window, if necessary: */
483 if (!(priv->signature_dialog)) {
484 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
486 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
487 const gchar *signature = modest_account_settings_get_signature(priv->settings);
488 gchar* account_title = get_entered_account_title (self);
489 modest_signature_editor_dialog_set_settings (
490 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
491 use_signature, signature, account_title);
493 g_free (account_title);
494 account_title = NULL;
498 /* Show the window: */
499 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
500 GTK_WINDOW (priv->signature_dialog),
503 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
504 gtk_widget_hide (priv->signature_dialog);
505 if (response != GTK_RESPONSE_OK) {
506 /* Destroy the widget now, and its data: */
507 gtk_widget_destroy (priv->signature_dialog);
508 priv->signature_dialog = NULL;
510 /* Mark modified, so we use the dialog's data later: */
511 priv->modified = TRUE;
516 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
518 ModestDefaultAccountSettingsDialogPrivate *priv;
520 GtkAdjustment *focus_adjustment = NULL;
521 GtkSizeGroup* sizegroup;
522 GtkWidget *scrollwin;
524 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
526 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
527 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
528 scrollwin = gtk_scrolled_window_new (NULL, NULL);
529 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
530 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
532 /* The name widgets: */
533 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
535 /* Auto-capitalization is the default, so let's turn it off: */
536 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
537 /* Set max length as in the UI spec:
538 * The UI spec seems to want us to show a dialog if we hit the maximum. */
539 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
540 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
542 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
543 _("mcen_li_emailsetup_name"), priv->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
544 gtk_widget_show (priv->entry_user_name);
545 connect_for_modified (self, priv->entry_user_name);
546 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
547 gtk_widget_show (caption);
550 /* Prevent the use of some characters in the name,
551 * as required by our UI specification: */
552 GList *list_prevent = NULL;
553 list_prevent = g_list_append (list_prevent, "<");
554 list_prevent = g_list_append (list_prevent, ">");
555 modest_validating_entry_set_unallowed_characters (
556 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
557 g_list_free (list_prevent);
558 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
559 on_entry_invalid_fullname_character, self);
561 /* The username widgets: */
562 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
563 /* Auto-capitalization is the default, so let's turn it off: */
564 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
565 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
566 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
567 gtk_widget_show (priv->entry_user_username);
568 connect_for_modified (self, priv->entry_user_username);
569 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
570 gtk_widget_show (caption);
572 /* Prevent the use of some characters in the username,
573 * as required by our UI specification: */
574 modest_validating_entry_set_unallowed_characters_whitespace (
575 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
576 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
577 modest_utils_on_entry_invalid_character,
580 /* Set max length as in the UI spec:
581 * The UI spec seems to want us to show a dialog if we hit the maximum. */
582 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
583 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
586 /* The password widgets: */
587 priv->entry_user_password = gtk_entry_new ();
588 /* Auto-capitalization is the default, so let's turn it off: */
589 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
590 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
591 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
592 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
593 caption = create_caption_new_with_asterisk (self, sizegroup,
594 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
595 gtk_widget_show (priv->entry_user_password);
596 connect_for_modified (self, priv->entry_user_password);
597 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
598 gtk_widget_show (caption);
600 /* The email address widgets: */
601 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
602 /* Auto-capitalization is the default, so let's turn it off: */
603 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
604 caption = create_caption_new_with_asterisk (self, sizegroup,
605 _("mcen_li_emailsetup_email_address"), priv->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
606 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
607 gtk_widget_show (priv->entry_user_email);
608 connect_for_modified (self, priv->entry_user_email);
609 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
610 gtk_widget_show (caption);
612 /* Set max length as in the UI spec:
613 * The UI spec seems to want us to show a dialog if we hit the maximum. */
614 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
615 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
618 /* Signature button: */
619 if (!priv->button_signature)
620 priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
621 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
622 priv->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
623 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
624 gtk_widget_show (priv->button_signature);
625 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
626 gtk_widget_show (caption);
628 g_object_unref (sizegroup);
630 g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
631 G_CALLBACK (on_button_signature), self);
633 gtk_widget_show (GTK_WIDGET (box));
634 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
635 gtk_widget_show (scrollwin);
637 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
638 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
640 return GTK_WIDGET (scrollwin);
643 /* Change the caption title for the incoming server */
645 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
646 ModestProtocolType protocol_type)
648 ModestProtocolRegistry *protocol_registry;
649 ModestProtocol *protocol;
650 const gchar *protocol_display_name;
651 gchar* incomingserver_title;
652 gchar *with_asterisk;
653 ModestDefaultAccountSettingsDialogPrivate *priv;
655 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
657 protocol_registry = modest_runtime_get_protocol_registry ();
658 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
659 protocol_display_name = modest_protocol_get_display_name (protocol);
660 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"),
661 protocol_display_name);
663 /* This is a mandatory field, so add a *. This is usually done by
664 * create_caption_new_with_asterisk() but we can't use that here. */
665 with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
666 g_free (incomingserver_title);
668 g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
669 g_free (with_asterisk);
672 /** Change the caption title for the incoming server,
673 * as specified in the UI spec:
676 /* update_incoming_server_security_choices (ModestDefaultAccountSettingsDialog *self, */
677 /* ModestProtocolType protocol) */
679 /* /\* Fill the combo with appropriately titled choices for POP or IMAP. *\/ */
680 /* /\* The choices are the same, but the titles are different, as in the UI spec. *\/ */
681 /* modest_serversecurity_combo_box_fill ( */
682 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security), protocol); */
686 create_page_incoming (ModestDefaultAccountSettingsDialog *self)
688 ModestDefaultAccountSettingsDialogPrivate *priv;
690 GtkSizeGroup *sizegroup;
692 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
694 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
695 /* Create a size group to be used by all captions.
696 * Note that HildonCaption does not create a default size group if we do not specify one.
697 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
698 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
700 /* The incoming server widgets: */
701 if(!priv->entry_incomingserver)
702 priv->entry_incomingserver = gtk_entry_new ();
703 /* Auto-capitalization is the default, so let's turn it off: */
704 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
706 if (priv->caption_incoming)
707 gtk_widget_destroy (priv->caption_incoming);
709 /* The caption title will be updated in update_incoming_server_title().
710 * so this default text will never be seen: */
711 /* (Note: Changing the title seems pointless. murrayc) */
712 priv->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
713 "Incoming Server", priv->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
714 gtk_widget_show (priv->entry_incomingserver);
715 connect_for_modified (self, priv->entry_incomingserver);
716 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
717 gtk_widget_show (priv->caption_incoming);
719 /* Incoming security widgets */
720 priv->incoming_security =
721 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
723 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
724 FALSE, FALSE, MODEST_MARGIN_HALF);
726 gtk_widget_show (priv->incoming_security);
728 g_object_unref (sizegroup);
729 gtk_widget_show (GTK_WIDGET (box));
731 return GTK_WIDGET (box);
735 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
737 GtkWidget *widget = GTK_WIDGET (user_data);
739 /* Enable the widget only if the toggle button is active: */
740 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
741 gtk_widget_set_sensitive (widget, enable);
744 /* Make the sensitivity of a widget depend on a toggle button.
747 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
749 g_signal_connect (G_OBJECT (button), "toggled",
750 G_CALLBACK (on_toggle_button_changed), widget);
752 /* Set the starting sensitivity: */
753 on_toggle_button_changed (button, widget);
757 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
759 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
760 ModestConnectionSpecificSmtpWindow *smtp_win;
761 ModestDefaultAccountSettingsDialogPrivate *priv;
763 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
765 /* Create the window if necessary: */
766 smtp_win = modest_connection_specific_smtp_window_new ();
767 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
769 /* Show the window: */
770 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
771 GTK_WINDOW (smtp_win), GTK_WINDOW (self));
772 gtk_widget_show (GTK_WIDGET (smtp_win));
773 priv->modified = TRUE;
777 /* on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data) */
779 /* ModestDefaultAccountSettingsDialog *self; */
780 /* ModestProtocolRegistry *protocol_registry; */
781 /* ModestProtocolType protocol_security; */
782 /* gboolean secureauth_used; */
784 /* self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data); */
785 /* protocol_registry = modest_runtime_get_protocol_registry (); */
787 /* protocol_security = */
788 /* modest_secureauth_combo_box_get_active_secureauth ( */
789 /* MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth)); */
790 /* secureauth_used = modest_protocol_registry_protocol_type_is_secure (protocol_registry, protocol_security); */
792 /* gtk_widget_set_sensitive (priv->caption_outgoing_username, secureauth_used); */
793 /* gtk_widget_set_sensitive (priv->caption_outgoing_password, secureauth_used); */
797 /* on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data) */
799 /* ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data); */
801 /* const gint port_number = */
802 /* modest_serversecurity_combo_box_get_active_serversecurity_port ( */
803 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security)); */
805 /* if(port_number != 0) { */
806 /* hildon_number_editor_set_value ( */
807 /* HILDON_NUMBER_EDITOR (priv->entry_outgoing_port), port_number); */
812 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
816 /* Disable the OK button */
817 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
823 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
825 ModestDefaultAccountSettingsDialogPrivate *priv;
826 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
827 GtkAdjustment *focus_adjustment = NULL;
829 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
831 /* Put it all in a scrolled window, so that all widgets can be
832 * accessed even when the on-screen keyboard is visible: */
833 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
834 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
835 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
837 /* Create a size group to be used by all captions.
838 * Note that HildonCaption does not create a default size group if we do not specify one.
839 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
840 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
842 /* The outgoing server widgets: */
843 if (!priv->entry_outgoingserver)
844 priv->entry_outgoingserver = gtk_entry_new ();
845 /* Auto-capitalization is the default, so let's turn it off: */
846 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
847 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
848 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
849 gtk_widget_show (priv->entry_outgoingserver);
850 connect_for_modified (self, priv->entry_outgoingserver);
851 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
852 gtk_widget_show (caption);
854 /* Outgoing security widgets */
855 priv->outgoing_security =
856 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
858 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
859 FALSE, FALSE, MODEST_MARGIN_HALF);
860 gtk_widget_show (priv->outgoing_security);
861 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
862 G_CALLBACK (on_missing_mandatory_data), self);
864 GtkWidget *separator = gtk_hseparator_new ();
865 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
866 gtk_widget_show (separator);
868 /* connection-specific checkbox: */
869 if (!priv->checkbox_outgoing_smtp_specific) {
870 priv->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
871 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
874 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
875 priv->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
876 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
877 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
878 gtk_widget_show (caption);
879 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
881 /* Connection-specific SMTP-Severs Edit button: */
882 if (!priv->button_outgoing_smtp_servers)
883 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
884 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
885 priv->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
886 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
887 gtk_widget_show (priv->button_outgoing_smtp_servers);
888 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
889 gtk_widget_show (caption);
891 /* Only enable the button when the checkbox is checked: */
892 enable_widget_for_togglebutton (priv->button_outgoing_smtp_servers,
893 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific));
895 g_object_unref (sizegroup);
897 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
898 G_CALLBACK (on_button_outgoing_smtp_servers), self);
900 gtk_widget_show (GTK_WIDGET (box));
901 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
902 gtk_widget_show(scrollwin);
904 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
905 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
907 return GTK_WIDGET (scrollwin);
911 check_data (ModestDefaultAccountSettingsDialog *self)
913 gchar* account_title;
914 const gchar* email_address;
915 const gchar* hostname;
916 const gchar* hostname2;
917 ModestDefaultAccountSettingsDialogPrivate *priv;
919 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
921 /* Check that the title is not already in use: */
922 account_title = get_entered_account_title (self);
924 return FALSE; /* Should be prevented already anyway. */
926 if (strcmp(account_title, priv->original_account_title) != 0) {
927 gboolean name_in_use;
929 /* Check the changed title: */
930 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
934 /* Warn the user via a dialog: */
935 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
937 g_free (account_title);
942 g_free (account_title);
943 account_title = NULL;
945 /* Check that the email address is valid: */
946 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
947 if ((!email_address) || (strlen(email_address) == 0)) {
951 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
952 /* Warn the user via a dialog: */
953 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
955 /* Return focus to the email address entry: */
956 gtk_widget_grab_focus (priv->entry_user_email);
957 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
961 /* make sure the domain name for the incoming server is valid */
962 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
963 if ((!hostname) || (strlen(hostname) == 0)) {
967 if (!modest_text_utils_validate_domain_name (hostname)) {
968 /* Warn the user via a dialog: */
969 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
971 /* Return focus to the email address entry: */
972 gtk_widget_grab_focus (priv->entry_incomingserver);
973 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
977 /* make sure the domain name for the outgoing server is valid */
978 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
979 if ((!hostname2) || (strlen(hostname2) == 0)) {
983 if (!modest_text_utils_validate_domain_name (hostname2)) {
984 /* Warn the user via a dialog: */
985 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
987 /* Return focus to the email address entry: */
988 gtk_widget_grab_focus (priv->entry_outgoingserver);
989 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
993 /* /\* Find a suitable authentication method when secure authentication is desired *\/ */
994 /* port_num = hildon_number_editor_get_value ( */
995 /* HILDON_NUMBER_EDITOR (priv->entry_incoming_port)); */
996 /* username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)); */
998 /* protocol_registry = modest_runtime_get_protocol_registry (); */
1000 /* protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity ( */
1001 /* MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_incoming_security)); */
1002 /* if (!modest_protocol_registry_protocol_type_is_secure(protocol_registry, protocol_security_incoming)) */
1004 /* if (gtk_toggle_button_get_active ( */
1005 /* GTK_TOGGLE_BUTTON (priv->checkbox_incoming_auth))) { */
1006 /* GError *error = NULL; */
1007 /* GList *list_auth_methods; */
1009 /* list_auth_methods = */
1010 /* modest_utils_get_supported_secure_authentication_methods (priv->incoming_protocol, */
1011 /* hostname, port_num, username, GTK_WINDOW (self), &error); */
1012 /* if (list_auth_methods) { */
1013 /* GList* method; */
1015 /* /\* Use the first supported method. */
1016 /* * TODO: Should we prioritize them, to prefer a particular one? *\/ */
1017 /* for (method = list_auth_methods; method != NULL; method = g_list_next(method)) */
1019 /* ModestProtocolType proto = (ModestProtocolType)(GPOINTER_TO_INT(method->data)); */
1020 /* // Allow secure methods, e.g MD5 only */
1021 /* if (modest_protocol_registry_protocol_type_is_secure(protocol_registry, proto)) */
1023 /* priv->protocol_authentication_incoming = proto; */
1027 /* g_list_free (list_auth_methods); */
1030 /* if (list_auth_methods == NULL || */
1031 /* !modest_protocol_registry_protocol_type_is_secure(protocol_registry, priv->protocol_authentication_incoming)) */
1033 /* if(error == NULL || error->domain != modest_utils_get_supported_secure_authentication_error_quark() || */
1034 /* error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED) */
1035 /* modest_platform_information_banner(GTK_WIDGET (self), NULL, */
1036 /* _("mcen_ib_unableto_discover_auth_methods")); */
1038 /* if(error != NULL) */
1039 /* g_error_free(error); */
1041 /* /\* This is a nasty hack. jschmid. *\/ */
1042 /* /\* Don't let the dialog close *\/ */
1043 /* /\*g_signal_stop_emission_by_name (dialog, "response");*\/ */
1053 on_delete_event (GtkWidget *widget,
1057 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
1058 ModestDefaultAccountSettingsDialogPrivate *priv;
1059 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
1061 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1063 /* Check if security widgets changed */
1064 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1065 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1067 return modest_security_options_view_changed (incoming_sec, priv->settings) ||
1068 modest_security_options_view_changed (outgoing_sec, priv->settings) ||
1073 on_response (GtkDialog *wizard_dialog,
1077 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
1078 ModestDefaultAccountSettingsDialogPrivate *priv;
1079 gboolean prevent_response = FALSE, sec_changed;
1080 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
1082 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1083 enable_buttons (self);
1085 /* Check if security widgets changed */
1086 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
1087 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
1089 modest_security_options_view_changed (incoming_sec, priv->settings) ||
1090 modest_security_options_view_changed (outgoing_sec, priv->settings);
1092 /* Warn about unsaved changes: */
1093 if ((response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) &&
1094 (priv->modified || sec_changed)) {
1095 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1096 _("imum_nc_wizard_confirm_lose_changes")));
1098 const gint dialog_response = gtk_dialog_run (dialog);
1099 gtk_widget_destroy (GTK_WIDGET (dialog));
1101 if (dialog_response != GTK_RESPONSE_OK)
1102 prevent_response = TRUE;
1104 /* Check for invalid input: */
1105 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1106 prevent_response = TRUE;
1109 if (prevent_response) {
1110 /* This is a nasty hack. murrayc. */
1111 /* Don't let the dialog close */
1112 g_signal_stop_emission_by_name (wizard_dialog, "response");
1115 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
1118 if (response_id == GTK_RESPONSE_OK) {
1119 /* Try to save the changes if modified (NB #59251): */
1120 if (priv->modified || sec_changed) {
1121 if (save_configuration (self)) {
1122 /* Do not show the account-saved dialog if we are just saving this
1123 * temporarily, because from the user's point of view it will not
1124 * really be saved (saved + enabled) until later
1126 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
1127 ModestServerAccountSettings *store_settings;
1128 ModestServerAccountSettings *transport_settings;
1129 const gchar *store_account_name;
1130 const gchar *transport_account_name;
1133 store_settings = modest_account_settings_get_store_settings (priv->settings);
1134 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1135 store_account_name = modest_server_account_settings_get_account_name (store_settings);
1136 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
1138 if (store_account_name) {
1139 modest_account_mgr_notify_account_update (priv->account_manager,
1140 store_account_name);
1142 if (transport_account_name) {
1143 modest_account_mgr_notify_account_update (priv->account_manager,
1144 transport_account_name);
1146 g_object_unref (store_settings);
1147 g_object_unref (transport_settings);
1149 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1152 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
1159 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
1161 ModestDefaultAccountSettingsDialogPrivate *priv;
1163 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
1165 priv->incoming_security = NULL;
1166 priv->outgoing_security = NULL;
1168 /* Create the notebook to be used by the GtkDialog base class:
1169 * Each page of the notebook will be a page of the wizard: */
1170 priv->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1171 priv->settings = modest_account_settings_new ();
1173 /* Get the account manager object,
1174 * so we can check for existing accounts,
1175 * and create new accounts: */
1176 priv->account_manager = modest_runtime_get_account_mgr ();
1177 g_assert (priv->account_manager);
1178 g_object_ref (priv->account_manager);
1180 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
1182 /* Create the common pages,
1184 priv->page_account_details = create_page_account_details (self);
1185 priv->page_user_details = create_page_user_details (self);
1186 priv->page_incoming = create_page_incoming (self);
1187 priv->page_outgoing = create_page_outgoing (self);
1189 /* Add the notebook pages: */
1190 gtk_notebook_append_page (priv->notebook, priv->page_account_details,
1191 gtk_label_new (_("mcen_ti_account_settings_account")));
1192 gtk_notebook_append_page (priv->notebook, priv->page_user_details,
1193 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1194 gtk_notebook_append_page (priv->notebook, priv->page_incoming,
1195 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1196 gtk_notebook_append_page (priv->notebook, priv->page_outgoing,
1197 gtk_label_new (_("mcen_ti_advsetup_sending")));
1199 GtkDialog *dialog = GTK_DIALOG (self);
1200 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (priv->notebook));
1201 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1202 gtk_widget_show (GTK_WIDGET (priv->notebook));
1204 /* Add the buttons: */
1205 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1206 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1208 /* Connect to the dialog's response signal: */
1209 /* We use connect-before
1210 * so we can stop the signal emission,
1211 * to stop the default signal handler from closing the dialog.
1213 g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self);
1214 g_signal_connect (G_OBJECT (self), "delete-event", G_CALLBACK (on_delete_event), self);
1216 priv->modified = FALSE;
1218 /* When this window is shown, hibernation should not be possible,
1219 * because there is no sensible way to save the state: */
1220 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1221 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1223 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1224 * while sending messages causes an error dialog and we have a lock */
1225 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1227 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1228 modest_maemo_utils_get_osso_context());
1231 ModestAccountSettingsDialog*
1232 modest_default_account_settings_dialog_new (void)
1234 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1237 /** Update the UI with the stored account details, so they can be edited.
1238 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1241 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1242 ModestAccountSettings *settings)
1244 ModestServerAccountSettings *incoming_account;
1245 ModestServerAccountSettings *outgoing_account;
1246 ModestProtocolRegistry *protocol_registry;
1247 const gchar *account_name, *server_account_name;
1248 ModestDefaultAccountSettingsDialogPrivate *priv;
1250 gboolean username_known;
1252 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1253 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1255 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1256 protocol_registry = modest_runtime_get_protocol_registry ();
1258 incoming_account = modest_account_settings_get_store_settings (settings);
1259 outgoing_account = modest_account_settings_get_transport_settings (settings);
1261 account_name = modest_account_settings_get_account_name (settings);
1263 /* Save the account name so we can refer to it later: */
1264 if (priv->account_name)
1265 g_free (priv->account_name);
1266 priv->account_name = g_strdup (account_name);
1269 g_object_unref (priv->settings);
1270 priv->settings = g_object_ref (settings);
1272 /* Save the account title so we can refer to it if the user changes it: */
1273 if (priv->original_account_title)
1274 g_free (priv->original_account_title);
1275 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1277 /* Show the account data in the widgets: */
1279 /* Note that we never show the non-display name in the UI.
1280 * (Though the display name defaults to the non-display name at the start.) */
1281 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1282 null_means_empty (modest_account_settings_get_display_name (settings)));
1283 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1284 null_means_empty (modest_account_settings_get_fullname (settings)));
1285 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1286 null_means_empty (modest_account_settings_get_email_address (settings)));
1287 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve),
1288 modest_account_settings_get_retrieve_type (settings));
1289 modest_limit_retrieve_combo_box_set_active_limit_retrieve (
1290 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve),
1291 modest_account_settings_get_retrieve_limit (settings));
1294 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages),
1295 modest_account_settings_get_leave_messages_on_server (settings));
1298 if (incoming_account) {
1299 const gchar *username, *password, *hostname, *proto_str, *account_title;
1300 gchar *proto_name, *title;
1301 ModestProtocolType incoming_protocol;
1303 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve), modest_server_account_settings_get_protocol (incoming_account));
1305 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1306 modest_server_account_settings_get_protocol (incoming_account))) {
1307 gtk_widget_hide (priv->caption_leave_messages);
1309 gtk_widget_show (priv->caption_leave_messages);
1312 /* Remember this for later: */
1313 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1315 hostname = modest_server_account_settings_get_hostname (incoming_account);
1316 username = modest_server_account_settings_get_username (incoming_account);
1317 password = modest_server_account_settings_get_password (incoming_account);
1318 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1319 null_means_empty (username));
1320 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1321 null_means_empty (password));
1323 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1324 null_means_empty (hostname));
1326 /* Load security settings */
1327 modest_security_options_view_load_settings (
1328 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1330 gtk_widget_show (priv->incoming_security);
1332 /* Update the incoming label */
1333 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1336 /* Set window title according to account */
1337 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1338 proto_name = g_utf8_strup (proto_str, -1);
1339 account_title = modest_account_settings_get_display_name(settings);
1340 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1342 gtk_window_set_title (GTK_WINDOW (dialog), title);
1344 g_free (proto_name);
1346 g_object_unref (incoming_account);
1349 outgoing_account = modest_account_settings_get_transport_settings (settings);
1350 if (outgoing_account) {
1351 const gchar *hostname;
1352 const gchar *username;
1353 const gchar *password;
1354 ModestProtocolType outgoing_protocol;
1356 /* Remember this for later: */
1358 modest_server_account_settings_get_protocol (outgoing_account);
1360 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1361 username = modest_server_account_settings_get_username (outgoing_account);
1362 password = modest_server_account_settings_get_password (outgoing_account);
1363 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1364 null_means_empty (hostname));
1366 /* Load security settings */
1367 modest_security_options_view_load_settings (
1368 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1370 gtk_widget_show (priv->outgoing_security);
1372 const gboolean has_specific =
1373 modest_account_settings_get_use_connection_specific_smtp (settings);
1374 gtk_toggle_button_set_active (
1375 GTK_TOGGLE_BUTTON (priv->checkbox_outgoing_smtp_specific),
1377 g_object_unref (outgoing_account);
1380 /* Switch to user page */
1381 page_num = gtk_notebook_page_num (priv->notebook,priv->page_user_details);
1382 gtk_notebook_set_current_page (priv->notebook, page_num);
1384 /* Check if we allow changes or not */
1385 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1387 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1388 server_account_name);
1389 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1390 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1391 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1395 /* Unset the modified flag so we can detect changes later: */
1396 priv->modified = FALSE;
1400 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1402 const gchar* user_fullname;
1403 const gchar* emailaddress;
1404 ModestServerAccountSettings *store_settings;
1405 ModestServerAccountSettings *transport_settings;
1406 ModestAccountRetrieveType retrieve_type;
1407 gint retrieve_limit;
1408 gboolean leave_on_server;
1409 const gchar* hostname;
1410 const gchar* username;
1411 const gchar* password;
1412 gchar* account_title;
1413 ModestDefaultAccountSettingsDialogPrivate *priv;
1414 const gchar* account_name;
1416 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1417 account_name = priv->account_name;
1419 /* Set the account data from the widgets: */
1420 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1421 modest_account_settings_set_fullname (priv->settings, user_fullname);
1423 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1424 modest_account_settings_set_email_address (priv->settings, emailaddress);
1427 if (priv->signature_dialog) {
1428 gboolean use_signature = FALSE;
1430 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1433 modest_account_settings_set_use_signature (priv->settings, use_signature);
1434 modest_account_settings_set_signature (priv->settings, signature);
1437 retrieve_type = modest_retrieve_combo_box_get_active_retrieve_conf (
1438 MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve));
1439 modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
1441 retrieve_limit = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1442 MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve));
1443 modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
1445 leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_leave_messages));
1446 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1448 store_settings = modest_account_settings_get_store_settings (priv->settings);
1450 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1451 modest_server_account_settings_set_hostname (store_settings, hostname);
1453 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1454 modest_server_account_settings_set_username (store_settings, username);
1456 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1457 modest_server_account_settings_set_password (store_settings, password);
1459 /* Save security settings */
1460 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1463 g_object_unref (store_settings);
1466 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1468 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1469 modest_server_account_settings_set_hostname (transport_settings, hostname);
1471 /* Save security settings */
1472 modest_security_options_view_save_settings (
1473 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1476 /* Set the changed account title last, to simplify the previous code: */
1477 account_title = get_entered_account_title (dialog);
1479 return FALSE; /* Should be prevented already anyway. */
1481 /* if (strcmp (account_title, account_name) != 0) { */
1482 modest_account_settings_set_display_name (priv->settings, account_title);
1484 g_free (account_title);
1485 account_title = NULL;
1487 /* Save connection-specific SMTP server accounts: */
1488 modest_account_settings_set_use_connection_specific_smtp
1490 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1492 /* this configuration is not persistent, we should not save */
1493 if (account_name != NULL)
1494 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1499 static gboolean entry_is_empty (GtkWidget *entry)
1504 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1505 if ((!text) || (strlen(text) == 0))
1508 /* Strip it of whitespace at the start and end: */
1509 gchar *stripped = g_strdup (text);
1510 stripped = g_strstrip (stripped);
1515 const gboolean result = (strlen (stripped) == 0);
1523 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1525 gboolean enable_ok = TRUE;
1526 ModestProtocolRegistry *protocol_registry;
1527 ModestDefaultAccountSettingsDialogPrivate *priv;
1529 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1531 /* The account details title is mandatory: */
1532 if (entry_is_empty(priv->entry_account_title))
1535 /* The user details username is mandatory: */
1536 if (enable_ok && entry_is_empty(priv->entry_user_username))
1539 /* The user details email address is mandatory: */
1540 if (enable_ok && entry_is_empty (priv->entry_user_email))
1543 /* The custom incoming server is mandatory: */
1544 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1547 /* The custom outgoing server is mandatory: */
1548 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1551 protocol_registry = modest_runtime_get_protocol_registry ();
1553 /* Enable the buttons,
1554 * identifying them via their associated response codes:
1556 GtkDialog *dialog_base = GTK_DIALOG (self);
1557 gtk_dialog_set_response_sensitive (dialog_base,
1563 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1565 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1566 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1568 object_class->dispose = modest_default_account_settings_dialog_dispose;
1569 object_class->finalize = modest_default_account_settings_dialog_finalize;
1573 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1575 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1577 iface->load_settings = modest_default_account_settings_dialog_load_settings;