1 /* Copyright (c) 2006, 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 "modest-account-settings-dialog.h"
32 #include <glib/gi18n.h>
33 #include <gtk/gtknotebook.h>
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkcombobox.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkstock.h>
42 #include "modest-hildon-includes.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-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "modest-protocol-info.h"
54 #include "maemo/modest-connection-specific-smtp-window.h"
55 #include "maemo/modest-signature-editor-dialog.h"
56 #include "maemo/modest-maemo-utils.h"
57 #include "widgets/modest-ui-constants.h"
59 #include <tny-camel-transport-account.h>
60 #include <tny-camel-imap-store-account.h>
61 #include <tny-camel-pop-store-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: */
72 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
75 #define PORT_MAX 65535
77 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
79 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
80 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
82 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
84 struct _ModestAccountSettingsDialogPrivate
89 enable_buttons (ModestAccountSettingsDialog *self);
92 save_configuration (ModestAccountSettingsDialog *dialog);
95 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
96 GValue *value, GParamSpec *pspec)
98 switch (property_id) {
100 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
105 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
106 const GValue *value, GParamSpec *pspec)
108 switch (property_id) {
110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
115 modest_account_settings_dialog_dispose (GObject *object)
117 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
118 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
122 modest_account_settings_dialog_finalize (GObject *object)
124 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
126 if (self->account_name)
127 g_free (self->account_name);
129 if (self->original_account_title)
130 g_free (self->original_account_title);
132 if (self->account_manager)
133 g_object_unref (G_OBJECT (self->account_manager));
135 if (self->specific_window)
136 gtk_widget_destroy (self->specific_window);
138 if (self->signature_dialog)
139 gtk_widget_destroy (self->signature_dialog);
141 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
145 show_error (GtkWidget *parent_widget, const gchar* text);
148 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
151 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
154 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
156 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
157 self->modified = TRUE;
161 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
163 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
164 self->modified = TRUE;
168 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
170 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
171 self->modified = TRUE;
175 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
177 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
178 self->modified = TRUE;
181 /* Set a modified boolean whenever the widget is changed,
182 * so we can check for it later.
185 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
187 if (HILDON_IS_NUMBER_EDITOR (widget)) {
188 g_signal_connect (G_OBJECT (widget), "notify::value",
189 G_CALLBACK (on_modified_number_editor_changed), self);
191 else if (GTK_IS_ENTRY (widget)) {
192 g_signal_connect (G_OBJECT (widget), "changed",
193 G_CALLBACK (on_modified_entry_changed), self);
194 } else if (GTK_IS_COMBO_BOX (widget)) {
195 g_signal_connect (G_OBJECT (widget), "changed",
196 G_CALLBACK (on_modified_combobox_changed), self);
197 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
198 g_signal_connect (G_OBJECT (widget), "toggled",
199 G_CALLBACK (on_modified_checkbox_toggled), self);
204 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
206 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
208 enable_buttons(self);
212 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
214 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
216 enable_buttons(self);
219 /** This is a convenience function to create a caption containing a mandatory widget.
220 * When the widget is edited, the enable_buttons() vfunc will be called.
222 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
227 HildonCaptionStatus flag)
229 GtkWidget *caption = NULL;
231 /* Note: Previously, the translated strings already contained the "*",
232 * Comment out this code if they do again.
234 /* Add a * character to indicate mandatory fields,
235 * as specified in our "Email UI Specification": */
236 if (flag == HILDON_CAPTION_MANDATORY) {
237 gchar* title = g_strdup_printf("%s*", value);
238 caption = hildon_caption_new (group, title, control, icon, flag);
242 caption = hildon_caption_new (group, value, control, icon, flag);
244 /* Connect to the appropriate changed signal for the widget,
245 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
247 if (GTK_IS_ENTRY (control)) {
248 g_signal_connect (G_OBJECT (control), "changed",
249 G_CALLBACK (on_caption_entry_changed), self);
252 else if (GTK_IS_COMBO_BOX (control)) {
253 g_signal_connect (G_OBJECT (control), "changed",
254 G_CALLBACK (on_caption_combobox_changed), self);
261 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
265 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
266 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
268 show_error (GTK_WIDGET (self), msg);
275 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
279 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
280 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
282 show_error (GTK_WIDGET (self), msg);
290 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
292 /* ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data); */
293 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
297 create_page_account_details (ModestAccountSettingsDialog *self)
299 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
301 /* Create a size group to be used by all captions.
302 * Note that HildonCaption does not create a default size group if we do not specify one.
303 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
304 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
306 /* The description widgets: */
307 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
308 /* Do use auto-capitalization: */
309 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
310 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
311 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
312 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
313 gtk_widget_show (self->entry_account_title);
314 connect_for_modified (self, self->entry_account_title);
315 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
316 gtk_widget_show (caption);
318 /* Prevent the use of some characters in the account title,
319 * as required by our UI specification: */
320 GList *list_prevent = NULL;
321 list_prevent = g_list_append (list_prevent, "\\");
322 list_prevent = g_list_append (list_prevent, "/");
323 list_prevent = g_list_append (list_prevent, ":");
324 list_prevent = g_list_append (list_prevent, "*");
325 list_prevent = g_list_append (list_prevent, "?");
326 list_prevent = g_list_append (list_prevent, "\"");
327 list_prevent = g_list_append (list_prevent, "<");
328 list_prevent = g_list_append (list_prevent, ">");
329 list_prevent = g_list_append (list_prevent, "|");
330 list_prevent = g_list_append (list_prevent, "^");
331 modest_validating_entry_set_unallowed_characters (
332 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
333 g_list_free (list_prevent);
334 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
335 on_entry_invalid_account_title_character, self);
337 /* Set max length as in the UI spec:
338 * The UI spec seems to want us to show a dialog if we hit the maximum. */
339 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
340 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
343 /* The retrieve combobox: */
344 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
345 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
346 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
347 gtk_widget_show (self->combo_retrieve);
348 connect_for_modified (self, self->combo_retrieve);
349 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
350 gtk_widget_show (caption);
352 /* The limit-retrieve combobox: */
353 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
354 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
355 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
356 gtk_widget_show (self->combo_limit_retrieve);
357 connect_for_modified (self, self->combo_limit_retrieve);
358 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
359 gtk_widget_show (caption);
361 /* The leave-messages widgets: */
362 if(!self->checkbox_leave_messages)
363 self->checkbox_leave_messages = gtk_check_button_new ();
364 if (!self->caption_leave_messages) {
365 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
366 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
369 gtk_widget_show (self->checkbox_leave_messages);
370 connect_for_modified (self, self->checkbox_leave_messages);
371 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
372 gtk_widget_show (self->caption_leave_messages);
374 gtk_widget_show (GTK_WIDGET (box));
376 return GTK_WIDGET (box);
380 get_entered_account_title (ModestAccountSettingsDialog *dialog)
382 const gchar* account_title =
383 gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
384 if (!account_title || (strlen (account_title) == 0))
387 /* Strip it of whitespace at the start and end: */
388 gchar *result = g_strdup (account_title);
389 result = g_strstrip (result);
394 if (strlen (result) == 0) {
405 on_button_signature (GtkButton *button, gpointer user_data)
407 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
409 /* Create the window, if necessary: */
410 if (!(self->signature_dialog)) {
411 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
413 gboolean use_signature = FALSE;
414 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
416 gchar* account_title = get_entered_account_title (self);
417 modest_signature_editor_dialog_set_settings (
418 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
419 use_signature, signature, account_title);
420 g_free (account_title);
421 account_title = NULL;
426 /* Show the window: */
427 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
428 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
429 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
430 gtk_widget_hide (self->signature_dialog);
431 if (response != GTK_RESPONSE_OK) {
432 /* Destroy the widget now, and its data: */
433 gtk_widget_destroy (self->signature_dialog);
434 self->signature_dialog = NULL;
437 /* Mark modified, so we use the dialog's data later: */
438 self->modified = TRUE;
443 create_page_user_details (ModestAccountSettingsDialog *self)
445 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
446 GtkAdjustment *focus_adjustment = NULL;
448 /* Create a size group to be used by all captions.
449 * Note that HildonCaption does not create a default size group if we do not specify one.
450 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
451 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
452 GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
453 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
454 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
456 /* The name widgets: */
457 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
459 /* Auto-capitalization is the default, so let's turn it off: */
460 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
461 /* Set max length as in the UI spec:
462 * The UI spec seems to want us to show a dialog if we hit the maximum. */
463 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
464 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
466 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
467 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
468 gtk_widget_show (self->entry_user_name);
469 connect_for_modified (self, self->entry_user_name);
470 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
471 gtk_widget_show (caption);
474 /* Prevent the use of some characters in the name,
475 * as required by our UI specification: */
476 GList *list_prevent = NULL;
477 list_prevent = g_list_append (list_prevent, "<");
478 list_prevent = g_list_append (list_prevent, ">");
479 modest_validating_entry_set_unallowed_characters (
480 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
481 g_list_free (list_prevent);
482 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
483 on_entry_invalid_fullname_character, self);
485 /* The username widgets: */
486 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
487 /* Auto-capitalization is the default, so let's turn it off: */
488 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
489 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
490 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
491 gtk_widget_show (self->entry_user_username);
492 connect_for_modified (self, self->entry_user_username);
493 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
494 gtk_widget_show (caption);
496 /* Prevent the use of some characters in the username,
497 * as required by our UI specification: */
498 modest_validating_entry_set_unallowed_characters_whitespace (
499 MODEST_VALIDATING_ENTRY (self->entry_user_username));
501 /* Set max length as in the UI spec:
502 * The UI spec seems to want us to show a dialog if we hit the maximum. */
503 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
504 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
507 /* The password widgets: */
508 self->entry_user_password = gtk_entry_new ();
509 /* Auto-capitalization is the default, so let's turn it off: */
510 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
511 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
512 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
513 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
514 caption = create_caption_new_with_asterisk (self, sizegroup,
515 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
516 gtk_widget_show (self->entry_user_password);
517 connect_for_modified (self, self->entry_user_password);
518 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
519 gtk_widget_show (caption);
521 /* The email address widgets: */
522 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
523 /* Auto-capitalization is the default, so let's turn it off: */
524 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
525 caption = create_caption_new_with_asterisk (self, sizegroup,
526 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
527 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
528 gtk_widget_show (self->entry_user_email);
529 connect_for_modified (self, self->entry_user_email);
530 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
531 gtk_widget_show (caption);
533 /* Set max length as in the UI spec:
534 * The UI spec seems to want us to show a dialog if we hit the maximum. */
535 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
536 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
539 /* Signature button: */
540 if (!self->button_signature)
541 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
542 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
543 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
544 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
545 gtk_widget_show (self->button_signature);
546 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
547 gtk_widget_show (caption);
549 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
550 G_CALLBACK (on_button_signature), self);
552 gtk_widget_show (GTK_WIDGET (box));
553 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
554 gtk_widget_show (scrollwin);
556 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
557 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
559 return GTK_WIDGET (scrollwin);
562 /** Change the caption title for the incoming server,
563 * as specified in the UI spec:
565 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
568 (protocol == MODEST_PROTOCOL_STORE_POP ?
569 _("mail_fi_emailtype_pop3") :
570 _("mail_fi_emailtype_imap") );
573 /* Note that this produces a compiler warning,
574 * because the compiler does not know that the translated string will have a %s in it.
575 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
576 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
578 /* This is a mandatory field, so add a *. This is usually done by
579 * create_caption_new_with_asterisk() but we can't use that here. */
580 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
581 g_free (incomingserver_title);
583 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
584 g_free(with_asterisk);
587 /** Change the caption title for the incoming server,
588 * as specified in the UI spec:
590 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
592 /* Fill the combo with appropriately titled choices for POP or IMAP. */
593 /* The choices are the same, but the titles are different, as in the UI spec. */
594 modest_serversecurity_combo_box_fill (
595 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
598 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
600 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
602 /* Create a size group to be used by all captions.
603 * Note that HildonCaption does not create a default size group if we do not specify one.
604 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
605 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
607 /* The incoming server widgets: */
608 if(!self->entry_incomingserver)
609 self->entry_incomingserver = gtk_entry_new ();
610 /* Auto-capitalization is the default, so let's turn it off: */
611 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
613 if (self->caption_incoming)
614 gtk_widget_destroy (self->caption_incoming);
616 /* The caption title will be updated in update_incoming_server_title().
617 * so this default text will never be seen: */
618 /* (Note: Changing the title seems pointless. murrayc) */
619 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
620 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
621 gtk_widget_show (self->entry_incomingserver);
622 connect_for_modified (self, self->entry_incomingserver);
623 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
624 gtk_widget_show (self->caption_incoming);
626 /* The secure connection widgets: */
627 /* This will be filled by update_incoming_server_security_choices(). */
628 if (!self->combo_incoming_security)
629 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
630 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
631 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
632 gtk_widget_show (self->combo_incoming_security);
633 connect_for_modified (self, self->combo_incoming_security);
634 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
635 gtk_widget_show (caption);
637 /* Show a default port number when the security method changes, as per the UI spec: */
638 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
641 /* The port widgets: */
642 if (!self->entry_incoming_port)
643 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
644 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
645 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
646 gtk_widget_show (self->entry_incoming_port);
647 connect_for_modified (self, self->entry_incoming_port);
648 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
649 gtk_widget_show (caption);
651 /* The secure authentication widgets: */
652 if(!self->checkbox_incoming_auth)
653 self->checkbox_incoming_auth = gtk_check_button_new ();
654 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
655 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
656 gtk_widget_show (self->checkbox_incoming_auth);
657 connect_for_modified (self, self->checkbox_incoming_auth);
658 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
659 gtk_widget_show (caption);
661 gtk_widget_show (GTK_WIDGET (box));
663 return GTK_WIDGET (box);
667 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
669 GtkWidget *widget = GTK_WIDGET (user_data);
671 /* Enable the widget only if the toggle button is active: */
672 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
673 gtk_widget_set_sensitive (widget, enable);
676 /* Make the sensitivity of a widget depend on a toggle button.
679 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
681 g_signal_connect (G_OBJECT (button), "toggled",
682 G_CALLBACK (on_toggle_button_changed), widget);
684 /* Set the starting sensitivity: */
685 on_toggle_button_changed (button, widget);
689 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
691 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
693 /* Create the window if necessary: */
694 if (!(self->specific_window)) {
695 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
696 modest_connection_specific_smtp_window_fill_with_connections (
697 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager);
700 /* Show the window: */
701 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
702 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
703 gtk_widget_show (self->specific_window);
707 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
709 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
711 ModestAuthProtocol protocol_security =
712 modest_secureauth_combo_box_get_active_secureauth (
713 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
714 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
716 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
717 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
721 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
723 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
725 const gint port_number =
726 modest_serversecurity_combo_box_get_active_serversecurity_port (
727 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
729 if(port_number != 0) {
730 hildon_number_editor_set_value (
731 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
736 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
738 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
740 const gint port_number =
741 modest_serversecurity_combo_box_get_active_serversecurity_port (
742 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
744 if(port_number != 0) {
745 hildon_number_editor_set_value (
746 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
751 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
753 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
754 GtkAdjustment *focus_adjustment = NULL;
756 /* Put it all in a scrolled window, so that all widgets can be
757 * accessed even when the on-screen keyboard is visible: */
758 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
759 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
760 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
762 /* Create a size group to be used by all captions.
763 * Note that HildonCaption does not create a default size group if we do not specify one.
764 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
765 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
767 /* The outgoing server widgets: */
768 if (!self->entry_outgoingserver)
769 self->entry_outgoingserver = gtk_entry_new ();
770 /* Auto-capitalization is the default, so let's turn it off: */
771 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
772 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
773 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
774 gtk_widget_show (self->entry_outgoingserver);
775 connect_for_modified (self, self->entry_outgoingserver);
776 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
777 gtk_widget_show (caption);
779 /* The secure authentication widgets: */
780 if (!self->combo_outgoing_auth)
781 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
782 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
783 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
784 gtk_widget_show (self->combo_outgoing_auth);
785 connect_for_modified (self, self->combo_outgoing_auth);
786 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
787 gtk_widget_show (caption);
789 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
790 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
792 /* The username widgets: */
793 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
794 /* Auto-capitalization is the default, so let's turn it off: */
795 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
796 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
797 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
798 gtk_widget_show (self->entry_outgoing_username);
799 connect_for_modified (self, self->entry_outgoing_username);
800 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
801 gtk_widget_show (self->caption_outgoing_username);
803 /* Prevent the use of some characters in the username,
804 * as required by our UI specification: */
805 modest_validating_entry_set_unallowed_characters_whitespace (
806 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
808 /* Set max length as in the UI spec:
809 * The UI spec seems to want us to show a dialog if we hit the maximum. */
810 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
811 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
814 /* The password widgets: */
815 self->entry_outgoing_password = gtk_entry_new ();
816 /* Auto-capitalization is the default, so let's turn it off: */
817 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
818 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
819 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
820 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
821 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
822 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
823 gtk_widget_show (self->entry_outgoing_password);
824 connect_for_modified (self, self->entry_outgoing_password);
825 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
826 gtk_widget_show (self->caption_outgoing_password);
828 /* The secure connection widgets: */
829 /* This will be filled and set with modest_serversecurity_combo_box_fill()
830 * and modest_serversecurity_combo_box_set_active_serversecurity().
832 if (!self->combo_outgoing_security)
834 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
835 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
836 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
837 gtk_widget_show (self->combo_outgoing_security);
838 connect_for_modified (self, self->combo_outgoing_security);
839 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
840 gtk_widget_show (caption);
842 /* Show a default port number when the security method changes, as per the UI spec: */
843 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
845 /* The port widgets: */
846 if (!self->entry_outgoing_port)
847 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
848 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
849 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
850 gtk_widget_show (self->entry_outgoing_port);
851 connect_for_modified (self, self->entry_outgoing_port);
852 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
853 gtk_widget_show (caption);
855 GtkWidget *separator = gtk_hseparator_new ();
856 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
857 gtk_widget_show (separator);
859 /* connection-specific checkbox: */
860 if (!self->checkbox_outgoing_smtp_specific) {
861 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
862 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
865 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
866 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
867 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
868 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
869 gtk_widget_show (caption);
870 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
872 /* Connection-specific SMTP-Severs Edit button: */
873 if (!self->button_outgoing_smtp_servers)
874 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
875 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
876 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
877 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
878 gtk_widget_show (self->button_outgoing_smtp_servers);
879 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
880 gtk_widget_show (caption);
882 /* Only enable the button when the checkbox is checked: */
883 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
884 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
886 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
887 G_CALLBACK (on_button_outgoing_smtp_servers), self);
889 gtk_widget_show (GTK_WIDGET (box));
890 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
891 gtk_widget_show(scrollwin);
893 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
894 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
896 return GTK_WIDGET (scrollwin);
900 /** TODO: This doesn't work because hildon_number_editor_get_value() does not work until
901 * focus has been lost:
902 * See https://bugs.maemo.org/show_bug.cgi?id=1806.
905 check_hildon_number_editor_and_warn_value_not_in_range (HildonNumberEditor *widget, gint min, gint max)
907 g_return_val_if_fail (widget, FALSE);
909 const gint port = hildon_number_editor_get_value (widget);
910 /* printf ("DEBUG: %s, port=%d\n", __FUNCTION__, port); */
911 if (port < PORT_MIN ||
914 /* Warn the user via a dialog: */
915 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
916 gchar *message = g_strdup_printf (_CS("ckct_ib_set_a_value_within_range"),
919 hildon_banner_show_information (GTK_WIDGET (widget), NULL, message);
923 /* Return focus to the email address entry: */
924 gtk_widget_grab_focus (GTK_WIDGET (widget));
934 check_data (ModestAccountSettingsDialog *self)
936 /* Check that the title is not already in use: */
937 gchar* account_title = get_entered_account_title (self);
939 return FALSE; /* Should be prevented already anyway. */
941 if (strcmp(account_title, self->original_account_title) != 0) {
942 /* Check the changed title: */
943 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
947 /* Warn the user via a dialog: */
948 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
950 g_free (account_title);
955 g_free (account_title);
956 account_title = NULL;
958 /* Check that the email address is valid: */
959 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
960 if ((!email_address) || (strlen(email_address) == 0)) {
964 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
965 /* Warn the user via a dialog: */
966 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
967 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
969 /* Return focus to the email address entry: */
970 gtk_widget_grab_focus (self->entry_user_email);
971 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
975 /* make sure the domain name for the incoming server is valid */
976 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
977 if ((!hostname) || (strlen(hostname) == 0)) {
981 if (!modest_text_utils_validate_domain_name (hostname)) {
982 /* Warn the user via a dialog: */
983 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
984 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
986 /* Return focus to the email address entry: */
987 gtk_widget_grab_focus (self->entry_incomingserver);
988 gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
992 /* make sure the domain name for the outgoing server is valid */
993 const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
994 if ((!hostname2) || (strlen(hostname2) == 0)) {
998 if (!modest_text_utils_validate_domain_name (hostname2)) {
999 /* Warn the user via a dialog: */
1000 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
1001 hildon_banner_show_information (self->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
1003 /* Return focus to the email address entry: */
1004 gtk_widget_grab_focus (self->entry_outgoingserver);
1005 gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
1009 /* Check that the port numbers are acceptable: */
1010 if (!check_hildon_number_editor_and_warn_value_not_in_range (
1011 HILDON_NUMBER_EDITOR (self->entry_incoming_port), PORT_MIN, PORT_MAX)) {
1015 if (!check_hildon_number_editor_and_warn_value_not_in_range (
1016 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), PORT_MIN, PORT_MAX)) {
1021 /* Find a suitable authentication method when secure authentication is desired */
1023 const gint port_num = hildon_number_editor_get_value (
1024 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
1025 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1028 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1029 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1031 /* If we use an encrypted protocol then there is no need to encrypt the password */
1032 /* I don't think this is a good assumption. It overrides the user's request. murrayc:
1033 * if (!modest_protocol_info_is_secure(protocol_security_incoming)) */
1036 if (gtk_toggle_button_get_active (
1037 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
1038 GError *error = NULL;
1040 GList *list_auth_methods =
1041 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
1042 hostname, port_num, username, GTK_WINDOW (self), &error);
1043 if (list_auth_methods) {
1044 /* Use the first supported method.
1045 * TODO: Should we prioritize them, to prefer a particular one? */
1047 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
1049 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(method->data));
1050 // Allow secure methods, e.g MD5 only
1051 if (modest_protocol_info_auth_is_secure(proto))
1053 self->protocol_authentication_incoming = proto;
1057 g_list_free (list_auth_methods);
1060 if (list_auth_methods == NULL ||
1061 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
1063 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
1064 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
1066 show_error (GTK_WIDGET (self), _("Could not discover supported secure authentication methods."));
1070 g_error_free(error);
1072 /* This is a nasty hack. jschmid. */
1073 /* Don't let the dialog close */
1074 /*g_signal_stop_emission_by_name (dialog, "response");*/
1085 on_response (GtkDialog *wizard_dialog,
1089 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
1090 enable_buttons (self);
1092 gboolean prevent_response = FALSE;
1094 /* Warn about unsaved changes: */
1095 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
1096 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1097 _("imum_nc_wizard_confirm_lose_changes")));
1098 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1100 const gint dialog_response = gtk_dialog_run (dialog);
1101 gtk_widget_destroy (GTK_WIDGET (dialog));
1103 if (dialog_response != GTK_RESPONSE_OK)
1104 prevent_response = TRUE;
1106 /* Check for invalid input: */
1107 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1108 prevent_response = TRUE;
1111 if (prevent_response) {
1112 /* This is a nasty hack. murrayc. */
1113 /* Don't let the dialog close */
1114 g_signal_stop_emission_by_name (wizard_dialog, "response");
1118 if (response_id == GTK_RESPONSE_OK) {
1119 /* Try to save the changes if modified (NB #59251): */
1122 const gboolean saved = save_configuration (self);
1124 /* Do not show the account-saved dialog if we are just saving this
1125 * temporarily, because from the user's point of view it will not
1126 * really be saved (saved + enabled) until later.
1128 const gboolean enabled =
1129 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
1131 show_error (NULL, _("mcen_ib_advsetup_settings_saved"));
1134 show_error (NULL, _("mail_ib_setting_failed"));
1140 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
1142 /* Create the notebook to be used by the GtkDialog base class:
1143 * Each page of the notebook will be a page of the wizard: */
1144 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1146 /* Get the account manager object,
1147 * so we can check for existing accounts,
1148 * and create new accounts: */
1149 self->account_manager = modest_runtime_get_account_mgr ();
1150 g_assert (self->account_manager);
1151 g_object_ref (self->account_manager);
1153 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1155 /* Create the common pages,
1157 self->page_account_details = create_page_account_details (self);
1158 self->page_user_details = create_page_user_details (self);
1159 self->page_incoming = create_page_incoming (self);
1160 self->page_outgoing = create_page_outgoing (self);
1162 /* Add the notebook pages: */
1163 gtk_notebook_append_page (self->notebook, self->page_account_details,
1164 gtk_label_new (_("mcen_ti_account_settings_account")));
1165 gtk_notebook_append_page (self->notebook, self->page_user_details,
1166 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1167 gtk_notebook_append_page (self->notebook, self->page_incoming,
1168 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1169 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1170 gtk_label_new (_("mcen_ti_advsetup_sending")));
1172 GtkDialog *dialog = GTK_DIALOG (self);
1173 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1174 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1175 gtk_widget_show (GTK_WIDGET (self->notebook));
1177 /* Add the buttons: */
1178 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1179 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1181 /* Connect to the dialog's response signal: */
1182 /* We use connect-before
1183 * so we can stop the signal emission,
1184 * to stop the default signal handler from closing the dialog.
1186 g_signal_connect (G_OBJECT (self), "response",
1187 G_CALLBACK (on_response), self);
1189 self->modified = FALSE;
1191 /* When this window is shown, hibernation should not be possible,
1192 * because there is no sensible way to save the state: */
1193 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1194 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1197 ModestAccountSettingsDialog*
1198 modest_account_settings_dialog_new (void)
1200 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1203 /** Update the UI with the stored account details, so they can be edited.
1204 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1206 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1211 /* Save the account name so we can refer to it later: */
1212 if (dialog->account_name)
1213 g_free (dialog->account_name);
1214 dialog->account_name = g_strdup (account_name);
1217 /* Get the account data for this account name: */
1218 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1220 if (!account_data) {
1221 g_printerr ("modest: failed to get account data for %s\n", account_name);
1225 /* Save the account title so we can refer to it if the user changes it: */
1226 if (dialog->original_account_title)
1227 g_free (dialog->original_account_title);
1228 dialog->original_account_title = g_strdup (account_data->display_name);
1231 if (!(account_data->store_account)) {
1232 g_printerr ("modest: account has no stores: %s\n", account_name);
1236 /* Show the account data in the widgets: */
1238 /* Note that we never show the non-display name in the UI.
1239 * (Though the display name defaults to the non-display name at the start.) */
1240 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1241 account_data->display_name ? account_data->display_name : "");
1243 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1244 account_data->fullname ? account_data->fullname : "");
1245 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1246 account_data->email ? account_data->email : "");
1248 ModestServerAccountData *incoming_account = account_data->store_account;
1250 if (incoming_account)
1251 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1252 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1253 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1255 /* Default to something, though no default is specified in the UI spec: */
1256 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1258 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1261 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1262 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1263 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1266 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1267 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1268 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1270 /* Only show the leave-on-server checkbox for POP,
1271 * as per the UI spec: */
1272 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1273 gtk_widget_hide (dialog->caption_leave_messages);
1275 gtk_widget_show (dialog->caption_leave_messages);
1278 update_incoming_server_security_choices (dialog, incoming_account->proto);
1279 if (incoming_account) {
1280 /* Remember this for later: */
1281 dialog->incoming_protocol = incoming_account->proto;
1283 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1284 incoming_account->username ? incoming_account->username : "");
1285 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1286 incoming_account->password ? incoming_account->password : "");
1288 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1289 incoming_account->hostname ? incoming_account->hostname : "");
1291 /* The UI spec says:
1292 * If secure authentication is unchecked, allow sending username and password also as plain text.
1293 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1294 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1296 const ModestConnectionProtocol security = modest_server_account_get_security (
1297 dialog->account_manager, incoming_account->account_name);
1298 modest_serversecurity_combo_box_set_active_serversecurity (
1299 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1304 - use encrypted passwords
1306 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1307 dialog->account_manager, incoming_account->account_name);
1308 dialog->protocol_authentication_incoming = secure_auth;
1309 if (modest_protocol_info_is_secure(security) ||
1310 modest_protocol_info_auth_is_secure(secure_auth))
1312 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1317 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1321 update_incoming_server_title (dialog, incoming_account->proto);
1323 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1324 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1326 if (port_num == 0) {
1327 /* Show the appropriate port number: */
1328 on_combo_incoming_security_changed (
1329 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1331 /* Keep the user-entered port-number,
1332 * or the already-appropriate automatic port number: */
1333 hildon_number_editor_set_value (
1334 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1338 ModestServerAccountData *outgoing_account = account_data->transport_account;
1339 if (outgoing_account) {
1340 /* Remember this for later: */
1341 dialog->outgoing_protocol = outgoing_account->proto;
1343 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1344 outgoing_account->hostname ? outgoing_account->hostname : "");
1346 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1347 outgoing_account->username ? outgoing_account->username : "");
1348 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1349 outgoing_account->password ? outgoing_account->password : "");
1351 /* Get the secure-auth setting: */
1352 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1353 dialog->account_manager, outgoing_account->account_name);
1354 modest_secureauth_combo_box_set_active_secureauth (
1355 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1356 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1358 modest_serversecurity_combo_box_fill (
1359 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1361 /* Get the security setting: */
1362 const ModestConnectionProtocol security = modest_server_account_get_security (
1363 dialog->account_manager, outgoing_account->account_name);
1364 modest_serversecurity_combo_box_set_active_serversecurity (
1365 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1367 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1368 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1369 if (port_num == 0) {
1370 /* Show the appropriate port number: */
1371 on_combo_outgoing_security_changed (
1372 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1375 /* Keep the user-entered port-number,
1376 * or the already-appropriate automatic port number: */
1377 hildon_number_editor_set_value (
1378 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1381 const gboolean has_specific =
1382 modest_account_mgr_get_use_connection_specific_smtp (
1383 dialog->account_manager, account_name);
1384 gtk_toggle_button_set_active (
1385 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1389 /* Set window title according to account: */
1390 /* TODO: Is this the correct way to find a human-readable name for
1391 * the protocol used? */
1392 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1393 gchar *proto_name = g_utf8_strup(proto_str, -1);
1394 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1396 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1397 g_free (proto_name);
1398 g_free (account_title);
1400 gtk_window_set_title (GTK_WINDOW (dialog), title);
1403 /* account_data->is_enabled, */
1404 /*account_data->is_default, */
1406 /* account_data->store_account->proto */
1408 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1410 /* Unset the modified flag so we can detect changes later: */
1411 dialog->modified = FALSE;
1414 /** Show the User Info tab.
1416 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1418 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1419 if (page_num == -1) {
1420 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1423 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1424 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1426 gtk_widget_show (dialog->page_user_details);
1427 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1428 gtk_widget_show (GTK_WIDGET (dialog));
1429 gtk_notebook_set_current_page (dialog->notebook, page_num);
1433 save_configuration (ModestAccountSettingsDialog *dialog)
1435 g_assert (dialog->account_name);
1437 const gchar* account_name = dialog->account_name;
1439 /* Set the account data from the widgets: */
1440 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1441 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1442 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1446 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1447 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1448 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1453 if (dialog->signature_dialog) {
1454 gboolean use_signature = FALSE;
1455 gchar *signature = modest_signature_editor_dialog_get_settings (
1456 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1459 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1460 signature, use_signature);
1464 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1465 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1466 modest_account_mgr_set_string (dialog->account_manager, account_name,
1467 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1470 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1471 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1472 modest_account_mgr_set_int (dialog->account_manager, account_name,
1473 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1475 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1476 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1477 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1482 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1483 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1484 g_assert (incoming_account_name);
1486 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1487 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1488 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1492 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1493 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1495 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1496 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1499 gint port_num = hildon_number_editor_get_value (
1500 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1501 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1502 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1504 /* The UI spec says:
1505 * If secure authentication is unchecked, allow sending username and password also as plain text.
1506 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1509 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1510 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1511 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1513 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1516 g_free (incoming_account_name);
1519 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1520 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1521 g_assert (outgoing_account_name);
1523 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1524 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1525 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1529 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1530 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1533 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1534 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1537 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1538 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1539 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1541 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1542 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1543 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1546 port_num = hildon_number_editor_get_value (
1547 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1548 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1549 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1551 g_free (outgoing_account_name);
1554 /* Set the changed account title last, to simplify the previous code: */
1555 gchar* account_title = get_entered_account_title (dialog);
1557 return FALSE; /* Should be prevented already anyway. */
1559 if (strcmp(account_title, account_name) != 0) {
1560 /* Change the title: */
1561 const gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1562 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1564 g_free (account_title);
1569 g_free (account_title);
1570 account_title = NULL;
1572 /* Save connection-specific SMTP server accounts: */
1573 modest_account_mgr_set_use_connection_specific_smtp(dialog->account_manager, account_name,
1574 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbox_outgoing_smtp_specific)));
1575 if (dialog->specific_window) {
1576 return modest_connection_specific_smtp_window_save_server_accounts (
1577 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window));
1583 static gboolean entry_is_empty (GtkWidget *entry)
1588 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1589 if ((!text) || (strlen(text) == 0))
1592 /* Strip it of whitespace at the start and end: */
1593 gchar *stripped = g_strdup (text);
1594 stripped = g_strstrip (stripped);
1599 const gboolean result = (strlen (stripped) == 0);
1607 enable_buttons (ModestAccountSettingsDialog *self)
1609 gboolean enable_ok = TRUE;
1611 /* The account details title is mandatory: */
1612 if (entry_is_empty(self->entry_account_title))
1615 /* The user details username is mandatory: */
1616 if (entry_is_empty(self->entry_user_username))
1619 /* The user details email address is mandatory: */
1620 if (enable_ok && entry_is_empty (self->entry_user_email))
1623 /* The custom incoming server is mandatory: */
1624 if (entry_is_empty(self->entry_incomingserver))
1627 /* Enable the buttons,
1628 * identifying them via their associated response codes:
1630 GtkDialog *dialog_base = GTK_DIALOG (self);
1631 gtk_dialog_set_response_sensitive (dialog_base,
1637 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1639 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1640 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1643 object_class->get_property = modest_account_settings_dialog_get_property;
1644 object_class->set_property = modest_account_settings_dialog_set_property;
1645 object_class->dispose = modest_account_settings_dialog_dispose;
1646 object_class->finalize = modest_account_settings_dialog_finalize;
1650 show_error (GtkWidget *parent_widget, const gchar* text)
1652 hildon_banner_show_information(parent_widget, NULL, text);
1655 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_widget, text);
1657 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1664 gtk_dialog_run (dialog);
1665 gtk_widget_destroy (GTK_WIDGET (dialog));