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