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"
58 #include <tny-account.h>
59 #include <tny-status.h>
61 #include <gconf/gconf-client.h>
62 #include <string.h> /* For strlen(). */
64 /* Include config.h so that _() works: */
69 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
72 #define PORT_MAX 65535
74 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
76 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
77 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
79 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
81 struct _ModestAccountSettingsDialogPrivate
86 enable_buttons (ModestAccountSettingsDialog *self);
89 save_configuration (ModestAccountSettingsDialog *dialog);
92 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
93 GValue *value, GParamSpec *pspec)
95 switch (property_id) {
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
102 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
103 const GValue *value, GParamSpec *pspec)
105 switch (property_id) {
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
112 modest_account_settings_dialog_dispose (GObject *object)
114 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
115 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
119 modest_account_settings_dialog_finalize (GObject *object)
121 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
123 if (self->account_name)
124 g_free (self->account_name);
126 if (self->original_account_title)
127 g_free (self->original_account_title);
129 if (self->account_manager)
130 g_object_unref (G_OBJECT (self->account_manager));
132 if (self->specific_window)
133 gtk_widget_destroy (self->specific_window);
135 if (self->signature_dialog)
136 gtk_widget_destroy (self->signature_dialog);
138 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
142 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
145 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
148 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
150 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
151 self->modified = TRUE;
155 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
157 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
158 self->modified = TRUE;
162 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
164 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
165 self->modified = TRUE;
169 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
171 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
172 self->modified = TRUE;
175 /* Set a modified boolean whenever the widget is changed,
176 * so we can check for it later.
179 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
181 if (HILDON_IS_NUMBER_EDITOR (widget)) {
182 g_signal_connect (G_OBJECT (widget), "notify::value",
183 G_CALLBACK (on_modified_number_editor_changed), self);
185 else if (GTK_IS_ENTRY (widget)) {
186 g_signal_connect (G_OBJECT (widget), "changed",
187 G_CALLBACK (on_modified_entry_changed), self);
188 } else if (GTK_IS_COMBO_BOX (widget)) {
189 g_signal_connect (G_OBJECT (widget), "changed",
190 G_CALLBACK (on_modified_combobox_changed), self);
191 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
192 g_signal_connect (G_OBJECT (widget), "toggled",
193 G_CALLBACK (on_modified_checkbox_toggled), self);
198 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
200 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
202 enable_buttons(self);
206 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
208 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
210 enable_buttons(self);
213 /** This is a convenience function to create a caption containing a mandatory widget.
214 * When the widget is edited, the enable_buttons() vfunc will be called.
216 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
221 HildonCaptionStatus flag)
223 GtkWidget *caption = NULL;
225 /* Note: Previously, the translated strings already contained the "*",
226 * Comment out this code if they do again.
228 /* Add a * character to indicate mandatory fields,
229 * as specified in our "Email UI Specification": */
230 if (flag == HILDON_CAPTION_MANDATORY) {
231 gchar* title = g_strdup_printf("%s*", value);
232 caption = hildon_caption_new (group, title, control, icon, flag);
236 caption = hildon_caption_new (group, value, control, icon, flag);
238 /* Connect to the appropriate changed signal for the widget,
239 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
241 if (GTK_IS_ENTRY (control)) {
242 g_signal_connect (G_OBJECT (control), "changed",
243 G_CALLBACK (on_caption_entry_changed), self);
246 else if (GTK_IS_COMBO_BOX (control)) {
247 g_signal_connect (G_OBJECT (control), "changed",
248 G_CALLBACK (on_caption_combobox_changed), self);
255 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
259 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
260 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
262 hildon_banner_show_information(GTK_WIDGET (self), NULL, msg);
269 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
273 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
274 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
276 hildon_banner_show_information(GTK_WIDGET (self), NULL, msg);
284 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
286 hildon_banner_show_information(GTK_WIDGET (self), NULL,
287 _CS("ckdg_ib_maximum_characters_reached"));
291 create_page_account_details (ModestAccountSettingsDialog *self)
293 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
294 GtkAdjustment *focus_adjustment = NULL;
296 /* Create a size group to be used by all captions.
297 * Note that HildonCaption does not create a default size group if we do not specify one.
298 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
299 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
300 GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
301 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
302 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
304 /* The description widgets: */
305 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
306 /* Do use auto-capitalization: */
307 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
308 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
309 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
310 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
311 gtk_widget_show (self->entry_account_title);
312 connect_for_modified (self, self->entry_account_title);
313 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
314 gtk_widget_show (caption);
316 /* Prevent the use of some characters in the account title,
317 * as required by our UI specification: */
318 GList *list_prevent = NULL;
319 list_prevent = g_list_append (list_prevent, "\\");
320 list_prevent = g_list_append (list_prevent, "/");
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 modest_validating_entry_set_unallowed_characters (
330 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
331 g_list_free (list_prevent);
332 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
333 on_entry_invalid_account_title_character, self);
335 /* Set max length as in the UI spec:
336 * The UI spec seems to want us to show a dialog if we hit the maximum. */
337 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
338 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
341 /* The retrieve combobox: */
342 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
343 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
344 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
345 gtk_widget_show (self->combo_retrieve);
346 connect_for_modified (self, self->combo_retrieve);
347 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
348 gtk_widget_show (caption);
350 /* The limit-retrieve combobox: */
351 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
352 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
353 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
354 gtk_widget_show (self->combo_limit_retrieve);
355 connect_for_modified (self, self->combo_limit_retrieve);
356 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
357 gtk_widget_show (caption);
359 /* The leave-messages widgets: */
360 if(!self->checkbox_leave_messages)
361 self->checkbox_leave_messages = gtk_check_button_new ();
362 if (!self->caption_leave_messages) {
363 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
364 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
367 gtk_widget_show (self->checkbox_leave_messages);
368 connect_for_modified (self, self->checkbox_leave_messages);
369 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
370 gtk_widget_show (self->caption_leave_messages);
372 gtk_widget_show (GTK_WIDGET (box));
374 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
375 gtk_widget_show (scrollwin);
377 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
378 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
380 return GTK_WIDGET (scrollwin);
384 get_entered_account_title (ModestAccountSettingsDialog *dialog)
386 const gchar* account_title =
387 gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
388 if (!account_title || (strlen (account_title) == 0))
391 /* Strip it of whitespace at the start and end: */
392 gchar *result = g_strdup (account_title);
393 result = g_strstrip (result);
398 if (strlen (result) == 0) {
409 on_button_signature (GtkButton *button, gpointer user_data)
411 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
413 /* Create the window, if necessary: */
414 if (!(self->signature_dialog)) {
415 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
417 gboolean use_signature = FALSE;
418 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
420 gchar* account_title = get_entered_account_title (self);
421 modest_signature_editor_dialog_set_settings (
422 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
423 use_signature, signature, account_title);
425 g_free (account_title);
426 account_title = NULL;
431 /* Show the window: */
432 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
433 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
434 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
435 gtk_widget_hide (self->signature_dialog);
436 if (response != GTK_RESPONSE_OK) {
437 /* Destroy the widget now, and its data: */
438 gtk_widget_destroy (self->signature_dialog);
439 self->signature_dialog = NULL;
442 /* Mark modified, so we use the dialog's data later: */
443 self->modified = TRUE;
448 create_page_user_details (ModestAccountSettingsDialog *self)
450 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
451 GtkAdjustment *focus_adjustment = NULL;
453 /* Create a size group to be used by all captions.
454 * Note that HildonCaption does not create a default size group if we do not specify one.
455 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
456 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
457 GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
458 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
459 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
461 /* The name widgets: */
462 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
464 /* Auto-capitalization is the default, so let's turn it off: */
465 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
466 /* Set max length as in the UI spec:
467 * The UI spec seems to want us to show a dialog if we hit the maximum. */
468 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
469 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
471 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
472 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
473 gtk_widget_show (self->entry_user_name);
474 connect_for_modified (self, self->entry_user_name);
475 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
476 gtk_widget_show (caption);
479 /* Prevent the use of some characters in the name,
480 * as required by our UI specification: */
481 GList *list_prevent = NULL;
482 list_prevent = g_list_append (list_prevent, "<");
483 list_prevent = g_list_append (list_prevent, ">");
484 modest_validating_entry_set_unallowed_characters (
485 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
486 g_list_free (list_prevent);
487 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
488 on_entry_invalid_fullname_character, self);
490 /* The username widgets: */
491 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
492 /* Auto-capitalization is the default, so let's turn it off: */
493 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
494 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
495 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
496 gtk_widget_show (self->entry_user_username);
497 connect_for_modified (self, self->entry_user_username);
498 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
499 gtk_widget_show (caption);
501 /* Prevent the use of some characters in the username,
502 * as required by our UI specification: */
503 modest_validating_entry_set_unallowed_characters_whitespace (
504 MODEST_VALIDATING_ENTRY (self->entry_user_username));
506 /* Set max length as in the UI spec:
507 * The UI spec seems to want us to show a dialog if we hit the maximum. */
508 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
509 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
512 /* The password widgets: */
513 self->entry_user_password = gtk_entry_new ();
514 /* Auto-capitalization is the default, so let's turn it off: */
515 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
516 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
517 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
518 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
519 caption = create_caption_new_with_asterisk (self, sizegroup,
520 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
521 gtk_widget_show (self->entry_user_password);
522 connect_for_modified (self, self->entry_user_password);
523 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
524 gtk_widget_show (caption);
526 /* The email address widgets: */
527 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
528 /* Auto-capitalization is the default, so let's turn it off: */
529 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
530 caption = create_caption_new_with_asterisk (self, sizegroup,
531 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
532 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
533 gtk_widget_show (self->entry_user_email);
534 connect_for_modified (self, self->entry_user_email);
535 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
536 gtk_widget_show (caption);
538 /* Set max length as in the UI spec:
539 * The UI spec seems to want us to show a dialog if we hit the maximum. */
540 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
541 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
544 /* Signature button: */
545 if (!self->button_signature)
546 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
547 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
548 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
549 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
550 gtk_widget_show (self->button_signature);
551 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
552 gtk_widget_show (caption);
554 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
555 G_CALLBACK (on_button_signature), self);
557 gtk_widget_show (GTK_WIDGET (box));
558 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
559 gtk_widget_show (scrollwin);
561 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
562 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
564 return GTK_WIDGET (scrollwin);
567 /** Change the caption title for the incoming server,
568 * as specified in the UI spec:
570 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
573 (protocol == MODEST_PROTOCOL_STORE_POP ?
574 _("mail_fi_emailtype_pop3") :
575 _("mail_fi_emailtype_imap") );
578 /* Note that this produces a compiler warning,
579 * because the compiler does not know that the translated string will have a %s in it.
580 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
581 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
583 /* This is a mandatory field, so add a *. This is usually done by
584 * create_caption_new_with_asterisk() but we can't use that here. */
585 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
586 g_free (incomingserver_title);
588 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
589 g_free(with_asterisk);
592 /** Change the caption title for the incoming server,
593 * as specified in the UI spec:
595 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
597 /* Fill the combo with appropriately titled choices for POP or IMAP. */
598 /* The choices are the same, but the titles are different, as in the UI spec. */
599 modest_serversecurity_combo_box_fill (
600 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
603 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
605 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
607 /* Create a size group to be used by all captions.
608 * Note that HildonCaption does not create a default size group if we do not specify one.
609 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
610 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
612 /* The incoming server widgets: */
613 if(!self->entry_incomingserver)
614 self->entry_incomingserver = gtk_entry_new ();
615 /* Auto-capitalization is the default, so let's turn it off: */
616 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
618 if (self->caption_incoming)
619 gtk_widget_destroy (self->caption_incoming);
621 /* The caption title will be updated in update_incoming_server_title().
622 * so this default text will never be seen: */
623 /* (Note: Changing the title seems pointless. murrayc) */
624 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
625 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
626 gtk_widget_show (self->entry_incomingserver);
627 connect_for_modified (self, self->entry_incomingserver);
628 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
629 gtk_widget_show (self->caption_incoming);
631 /* The secure connection widgets: */
632 /* This will be filled by update_incoming_server_security_choices(). */
633 if (!self->combo_incoming_security)
634 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
635 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
636 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
637 gtk_widget_show (self->combo_incoming_security);
638 connect_for_modified (self, self->combo_incoming_security);
639 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
640 gtk_widget_show (caption);
642 /* Show a default port number when the security method changes, as per the UI spec: */
643 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
646 /* The port widgets: */
647 if (!self->entry_incoming_port)
648 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
649 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
650 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
651 gtk_widget_show (self->entry_incoming_port);
652 connect_for_modified (self, self->entry_incoming_port);
653 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
654 gtk_widget_show (caption);
656 /* The secure authentication widgets: */
657 if(!self->checkbox_incoming_auth)
658 self->checkbox_incoming_auth = gtk_check_button_new ();
659 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
660 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
661 gtk_widget_show (self->checkbox_incoming_auth);
662 connect_for_modified (self, self->checkbox_incoming_auth);
663 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
664 gtk_widget_show (caption);
666 gtk_widget_show (GTK_WIDGET (box));
668 return GTK_WIDGET (box);
672 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
674 GtkWidget *widget = GTK_WIDGET (user_data);
676 /* Enable the widget only if the toggle button is active: */
677 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
678 gtk_widget_set_sensitive (widget, enable);
681 /* Make the sensitivity of a widget depend on a toggle button.
684 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
686 g_signal_connect (G_OBJECT (button), "toggled",
687 G_CALLBACK (on_toggle_button_changed), widget);
689 /* Set the starting sensitivity: */
690 on_toggle_button_changed (button, widget);
694 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
696 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
698 /* Create the window if necessary: */
699 if (!(self->specific_window)) {
700 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
701 modest_connection_specific_smtp_window_fill_with_connections (
702 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager);
705 /* Show the window: */
706 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
707 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
708 gtk_widget_show (self->specific_window);
712 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
714 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
716 ModestAuthProtocol protocol_security =
717 modest_secureauth_combo_box_get_active_secureauth (
718 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
719 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
721 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
722 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
726 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
728 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
730 const gint port_number =
731 modest_serversecurity_combo_box_get_active_serversecurity_port (
732 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
734 if(port_number != 0) {
735 hildon_number_editor_set_value (
736 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
741 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
743 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
745 const gint port_number =
746 modest_serversecurity_combo_box_get_active_serversecurity_port (
747 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
749 if(port_number != 0) {
750 hildon_number_editor_set_value (
751 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
756 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
758 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
759 GtkAdjustment *focus_adjustment = NULL;
761 /* Put it all in a scrolled window, so that all widgets can be
762 * accessed even when the on-screen keyboard is visible: */
763 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
764 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
765 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
767 /* Create a size group to be used by all captions.
768 * Note that HildonCaption does not create a default size group if we do not specify one.
769 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
770 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
772 /* The outgoing server widgets: */
773 if (!self->entry_outgoingserver)
774 self->entry_outgoingserver = gtk_entry_new ();
775 /* Auto-capitalization is the default, so let's turn it off: */
776 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
777 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
778 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
779 gtk_widget_show (self->entry_outgoingserver);
780 connect_for_modified (self, self->entry_outgoingserver);
781 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
782 gtk_widget_show (caption);
784 /* The secure authentication widgets: */
785 if (!self->combo_outgoing_auth)
786 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
787 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
788 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
789 gtk_widget_show (self->combo_outgoing_auth);
790 connect_for_modified (self, self->combo_outgoing_auth);
791 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
792 gtk_widget_show (caption);
794 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
795 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
797 /* The username widgets: */
798 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
799 /* Auto-capitalization is the default, so let's turn it off: */
800 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
801 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
802 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
803 gtk_widget_show (self->entry_outgoing_username);
804 connect_for_modified (self, self->entry_outgoing_username);
805 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
806 gtk_widget_show (self->caption_outgoing_username);
808 /* Prevent the use of some characters in the username,
809 * as required by our UI specification: */
810 modest_validating_entry_set_unallowed_characters_whitespace (
811 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
813 /* Set max length as in the UI spec:
814 * The UI spec seems to want us to show a dialog if we hit the maximum. */
815 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
816 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
819 /* The password widgets: */
820 self->entry_outgoing_password = gtk_entry_new ();
821 /* Auto-capitalization is the default, so let's turn it off: */
822 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
823 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
824 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
825 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
826 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
827 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
828 gtk_widget_show (self->entry_outgoing_password);
829 connect_for_modified (self, self->entry_outgoing_password);
830 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
831 gtk_widget_show (self->caption_outgoing_password);
833 /* The secure connection widgets: */
834 /* This will be filled and set with modest_serversecurity_combo_box_fill()
835 * and modest_serversecurity_combo_box_set_active_serversecurity().
837 if (!self->combo_outgoing_security)
839 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
840 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
841 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
842 gtk_widget_show (self->combo_outgoing_security);
843 connect_for_modified (self, self->combo_outgoing_security);
844 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
845 gtk_widget_show (caption);
847 /* Show a default port number when the security method changes, as per the UI spec: */
848 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
850 /* The port widgets: */
851 if (!self->entry_outgoing_port)
852 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
853 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
854 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
855 gtk_widget_show (self->entry_outgoing_port);
856 connect_for_modified (self, self->entry_outgoing_port);
857 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
858 gtk_widget_show (caption);
860 GtkWidget *separator = gtk_hseparator_new ();
861 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
862 gtk_widget_show (separator);
864 /* connection-specific checkbox: */
865 if (!self->checkbox_outgoing_smtp_specific) {
866 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
867 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
870 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
871 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
872 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
873 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
874 gtk_widget_show (caption);
875 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
877 /* Connection-specific SMTP-Severs Edit button: */
878 if (!self->button_outgoing_smtp_servers)
879 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
880 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
881 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
882 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
883 gtk_widget_show (self->button_outgoing_smtp_servers);
884 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
885 gtk_widget_show (caption);
887 /* Only enable the button when the checkbox is checked: */
888 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
889 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
891 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
892 G_CALLBACK (on_button_outgoing_smtp_servers), self);
894 gtk_widget_show (GTK_WIDGET (box));
895 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
896 gtk_widget_show(scrollwin);
898 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
899 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
901 return GTK_WIDGET (scrollwin);
905 /** TODO: This doesn't work because hildon_number_editor_get_value() does not work until
906 * focus has been lost:
907 * See https://bugs.maemo.org/show_bug.cgi?id=1806.
910 check_hildon_number_editor_and_warn_value_not_in_range (HildonNumberEditor *widget, gint min, gint max)
912 g_return_val_if_fail (widget, FALSE);
914 const gint port = hildon_number_editor_get_value (widget);
915 /* printf ("DEBUG: %s, port=%d\n", __FUNCTION__, port); */
916 if (port < PORT_MIN ||
919 /* Warn the user via a dialog: */
920 gchar *message = g_strdup_printf (_CS("ckct_ib_set_a_value_within_range"),
923 hildon_banner_show_information (GTK_WIDGET (widget), NULL, message);
927 /* Return focus to the email address entry: */
928 gtk_widget_grab_focus (GTK_WIDGET (widget));
938 check_data (ModestAccountSettingsDialog *self)
940 /* Check that the title is not already in use: */
941 gchar* account_title = get_entered_account_title (self);
943 return FALSE; /* Should be prevented already anyway. */
945 if (strcmp(account_title, self->original_account_title) != 0) {
946 /* Check the changed title: */
947 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
951 /* Warn the user via a dialog: */
952 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
954 g_free (account_title);
959 g_free (account_title);
960 account_title = NULL;
962 /* Check that the email address is valid: */
963 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
964 if ((!email_address) || (strlen(email_address) == 0)) {
968 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
969 /* Warn the user via a dialog: */
970 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
972 /* Return focus to the email address entry: */
973 gtk_widget_grab_focus (self->entry_user_email);
974 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
978 /* make sure the domain name for the incoming server is valid */
979 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
980 if ((!hostname) || (strlen(hostname) == 0)) {
984 if (!modest_text_utils_validate_domain_name (hostname)) {
985 /* Warn the user via a dialog: */
986 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
988 /* Return focus to the email address entry: */
989 gtk_widget_grab_focus (self->entry_incomingserver);
990 gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
994 /* make sure the domain name for the outgoing server is valid */
995 const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
996 if ((!hostname2) || (strlen(hostname2) == 0)) {
1000 if (!modest_text_utils_validate_domain_name (hostname2)) {
1001 /* Warn the user via a dialog: */
1002 hildon_banner_show_information (self->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
1004 /* Return focus to the email address entry: */
1005 gtk_widget_grab_focus (self->entry_outgoingserver);
1006 gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
1010 /* Check that the port numbers are acceptable: */
1011 if (!check_hildon_number_editor_and_warn_value_not_in_range (
1012 HILDON_NUMBER_EDITOR (self->entry_incoming_port), PORT_MIN, PORT_MAX)) {
1016 if (!check_hildon_number_editor_and_warn_value_not_in_range (
1017 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), PORT_MIN, PORT_MAX)) {
1022 /* Find a suitable authentication method when secure authentication is desired */
1024 const gint port_num = hildon_number_editor_get_value (
1025 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
1026 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1029 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1030 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1032 /* If we use an encrypted protocol then there is no need to encrypt the password */
1033 /* I don't think this is a good assumption. It overrides the user's request. murrayc:
1034 * if (!modest_protocol_info_is_secure(protocol_security_incoming)) */
1037 if (gtk_toggle_button_get_active (
1038 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
1039 GError *error = NULL;
1041 GList *list_auth_methods =
1042 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
1043 hostname, port_num, username, GTK_WINDOW (self), &error);
1044 if (list_auth_methods) {
1045 /* Use the first supported method.
1046 * TODO: Should we prioritize them, to prefer a particular one? */
1048 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
1050 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(method->data));
1051 // Allow secure methods, e.g MD5 only
1052 if (modest_protocol_info_auth_is_secure(proto))
1054 self->protocol_authentication_incoming = proto;
1058 g_list_free (list_auth_methods);
1061 if (list_auth_methods == NULL ||
1062 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
1064 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
1065 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
1066 hildon_banner_show_information(GTK_WIDGET (self), NULL,
1067 _("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 if (modest_account_mgr_get_enabled (self->account_manager,
1129 self->account_name)) {
1130 gchar *incoming_account_name = NULL, *outgoing_account_name = NULL;
1132 incoming_account_name =
1133 modest_account_mgr_get_server_account_name (self->account_manager,
1135 TNY_ACCOUNT_TYPE_STORE);
1136 outgoing_account_name =
1137 modest_account_mgr_get_server_account_name (self->account_manager,
1139 TNY_ACCOUNT_TYPE_TRANSPORT);
1141 if (incoming_account_name) {
1142 modest_account_mgr_notify_account_update (self->account_manager,
1143 incoming_account_name);
1144 g_free (incoming_account_name);
1146 if (outgoing_account_name) {
1147 modest_account_mgr_notify_account_update (self->account_manager,
1148 outgoing_account_name);
1149 g_free (outgoing_account_name);
1152 hildon_banner_show_information(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1156 hildon_banner_show_information (NULL, NULL, _("mail_ib_setting_failed"));
1163 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
1165 /* Create the notebook to be used by the GtkDialog base class:
1166 * Each page of the notebook will be a page of the wizard: */
1167 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1169 /* Get the account manager object,
1170 * so we can check for existing accounts,
1171 * and create new accounts: */
1172 self->account_manager = modest_runtime_get_account_mgr ();
1173 g_assert (self->account_manager);
1174 g_object_ref (self->account_manager);
1176 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1178 /* Create the common pages,
1180 self->page_account_details = create_page_account_details (self);
1181 self->page_user_details = create_page_user_details (self);
1182 self->page_incoming = create_page_incoming (self);
1183 self->page_outgoing = create_page_outgoing (self);
1185 /* Add the notebook pages: */
1186 gtk_notebook_append_page (self->notebook, self->page_account_details,
1187 gtk_label_new (_("mcen_ti_account_settings_account")));
1188 gtk_notebook_append_page (self->notebook, self->page_user_details,
1189 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1190 gtk_notebook_append_page (self->notebook, self->page_incoming,
1191 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1192 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1193 gtk_label_new (_("mcen_ti_advsetup_sending")));
1195 GtkDialog *dialog = GTK_DIALOG (self);
1196 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1197 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1198 gtk_widget_show (GTK_WIDGET (self->notebook));
1200 /* Add the buttons: */
1201 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1202 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1204 /* Connect to the dialog's response signal: */
1205 /* We use connect-before
1206 * so we can stop the signal emission,
1207 * to stop the default signal handler from closing the dialog.
1209 g_signal_connect (G_OBJECT (self), "response",
1210 G_CALLBACK (on_response), self);
1212 self->modified = FALSE;
1214 /* When this window is shown, hibernation should not be possible,
1215 * because there is no sensible way to save the state: */
1216 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1217 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1220 ModestAccountSettingsDialog*
1221 modest_account_settings_dialog_new (void)
1223 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1226 /** Update the UI with the stored account details, so they can be edited.
1227 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1229 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1234 /* Save the account name so we can refer to it later: */
1235 if (dialog->account_name)
1236 g_free (dialog->account_name);
1237 dialog->account_name = g_strdup (account_name);
1240 /* Get the account data for this account name: */
1241 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1243 if (!account_data) {
1244 g_printerr ("modest: failed to get account data for %s\n", account_name);
1248 /* Save the account title so we can refer to it if the user changes it: */
1249 if (dialog->original_account_title)
1250 g_free (dialog->original_account_title);
1251 dialog->original_account_title = g_strdup (account_data->display_name);
1254 if (!(account_data->store_account)) {
1255 g_printerr ("modest: account has no stores: %s\n", account_name);
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 (dialog->entry_account_title),
1264 account_data->display_name ? account_data->display_name : "");
1266 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1267 account_data->fullname ? account_data->fullname : "");
1268 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1269 account_data->email ? account_data->email : "");
1271 ModestServerAccountData *incoming_account = account_data->store_account;
1273 if (incoming_account)
1274 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1277 gchar *retrieve = modest_account_mgr_get_retrieve_type (dialog->account_manager, account_name);
1279 /* Default to something, though no default is specified in the UI spec: */
1280 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1282 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1285 const gint limit_retrieve = modest_account_mgr_get_retrieve_limit (dialog->account_manager, account_name);
1286 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1289 const gboolean leave_on_server = modest_account_mgr_get_leave_on_server (dialog->account_manager, account_name);
1290 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1292 /* Only show the leave-on-server checkbox for POP,
1293 * as per the UI spec: */
1294 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1295 gtk_widget_hide (dialog->caption_leave_messages);
1297 gtk_widget_show (dialog->caption_leave_messages);
1300 update_incoming_server_security_choices (dialog, incoming_account->proto);
1301 if (incoming_account) {
1302 /* Remember this for later: */
1303 dialog->incoming_protocol = incoming_account->proto;
1305 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1306 incoming_account->username ? incoming_account->username : "");
1307 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1308 incoming_account->password ? incoming_account->password : "");
1310 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1311 incoming_account->hostname ? incoming_account->hostname : "");
1313 /* The UI spec says:
1314 * If secure authentication is unchecked, allow sending username and password also as plain text.
1315 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1316 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1318 const ModestConnectionProtocol security = modest_account_mgr_get_server_account_security (
1319 dialog->account_manager, incoming_account->account_name);
1320 modest_serversecurity_combo_box_set_active_serversecurity (
1321 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1326 - use encrypted passwords
1328 const ModestAuthProtocol secure_auth = modest_account_mgr_get_server_account_secure_auth(
1329 dialog->account_manager, incoming_account->account_name);
1330 dialog->protocol_authentication_incoming = secure_auth;
1331 if (modest_protocol_info_auth_is_secure(secure_auth))
1333 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1338 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1342 update_incoming_server_title (dialog, incoming_account->proto);
1344 const gint port_num = modest_account_mgr_get_server_account_port (dialog->account_manager,
1345 incoming_account->account_name);
1346 if (port_num == 0) {
1347 /* Show the appropriate port number: */
1348 on_combo_incoming_security_changed (
1349 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1351 /* Keep the user-entered port-number,
1352 * or the already-appropriate automatic port number: */
1353 hildon_number_editor_set_value (
1354 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1358 ModestServerAccountData *outgoing_account = account_data->transport_account;
1359 if (outgoing_account) {
1360 /* Remember this for later: */
1361 dialog->outgoing_protocol = outgoing_account->proto;
1363 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1364 outgoing_account->hostname ? outgoing_account->hostname : "");
1366 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1367 outgoing_account->username ? outgoing_account->username : "");
1368 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1369 outgoing_account->password ? outgoing_account->password : "");
1371 /* Get the secure-auth setting: */
1372 const ModestAuthProtocol secure_auth = modest_account_mgr_get_server_account_secure_auth(
1373 dialog->account_manager, outgoing_account->account_name);
1374 modest_secureauth_combo_box_set_active_secureauth (
1375 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1376 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1378 modest_serversecurity_combo_box_fill (
1379 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1381 /* Get the security setting: */
1382 const ModestConnectionProtocol security = modest_account_mgr_get_server_account_security (
1383 dialog->account_manager, outgoing_account->account_name);
1384 modest_serversecurity_combo_box_set_active_serversecurity (
1385 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1387 const gint port_num = modest_account_mgr_get_server_account_port (dialog->account_manager,
1388 outgoing_account->account_name);
1389 if (port_num == 0) {
1390 /* Show the appropriate port number: */
1391 on_combo_outgoing_security_changed (
1392 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1395 /* Keep the user-entered port-number,
1396 * or the already-appropriate automatic port number: */
1397 hildon_number_editor_set_value (
1398 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1401 const gboolean has_specific =
1402 modest_account_mgr_get_use_connection_specific_smtp (
1403 dialog->account_manager, account_name);
1404 gtk_toggle_button_set_active (
1405 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1409 /* Set window title according to account: */
1410 /* TODO: Is this the correct way to find a human-readable name for
1411 * the protocol used? */
1412 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1413 gchar *proto_name = g_utf8_strup(proto_str, -1);
1414 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1416 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1417 g_free (proto_name);
1418 g_free (account_title);
1420 gtk_window_set_title (GTK_WINDOW (dialog), title);
1423 /* account_data->is_enabled, */
1424 /*account_data->is_default, */
1426 /* account_data->store_account->proto */
1428 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1430 /* Unset the modified flag so we can detect changes later: */
1431 dialog->modified = FALSE;
1434 /** Show the User Info tab.
1436 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1438 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1439 if (page_num == -1) {
1440 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1443 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1444 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1446 gtk_widget_show (dialog->page_user_details);
1447 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1448 gtk_widget_show (GTK_WIDGET (dialog));
1449 gtk_notebook_set_current_page (dialog->notebook, page_num);
1453 save_configuration (ModestAccountSettingsDialog *dialog)
1455 g_assert (dialog->account_name);
1457 const gchar* account_name = dialog->account_name;
1459 /* Set the account data from the widgets: */
1460 const gchar* user_fullname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1461 modest_account_mgr_set_user_fullname (dialog->account_manager,
1465 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1466 modest_account_mgr_set_user_email (dialog->account_manager, account_name,
1470 if (dialog->signature_dialog) {
1471 gboolean use_signature = FALSE;
1473 modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1476 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1477 signature, use_signature);
1481 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1482 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1483 modest_account_mgr_set_retrieve_type (dialog->account_manager, account_name, (const gchar*) retrieve);
1486 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1487 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1488 modest_account_mgr_set_retrieve_limit (dialog->account_manager, account_name, limit_retrieve);
1490 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1491 modest_account_mgr_set_leave_on_server (dialog->account_manager, account_name, leave_on_server);
1494 gchar* incoming_account_name =
1495 modest_account_mgr_get_server_account_name (dialog->account_manager,
1497 TNY_ACCOUNT_TYPE_STORE);
1498 g_assert (incoming_account_name);
1500 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1501 modest_account_mgr_set_server_account_hostname (dialog->account_manager, incoming_account_name, hostname);
1503 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1504 modest_account_mgr_set_server_account_username (dialog->account_manager, incoming_account_name, username);
1506 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1507 modest_account_mgr_set_server_account_password (dialog->account_manager, incoming_account_name,
1511 gint port_num = hildon_number_editor_get_value (
1512 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1513 modest_account_mgr_set_server_account_port (dialog->account_manager, incoming_account_name, port_num);
1515 /* The UI spec says:
1516 * If secure authentication is unchecked, allow sending username and password also as plain text.
1517 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1520 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1521 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1522 modest_account_mgr_set_server_account_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1524 modest_account_mgr_set_server_account_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1527 g_free (incoming_account_name);
1530 gchar* outgoing_account_name =
1531 modest_account_mgr_get_server_account_name (dialog->account_manager,
1533 TNY_ACCOUNT_TYPE_TRANSPORT);
1534 g_assert (outgoing_account_name);
1536 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1537 modest_account_mgr_set_server_account_hostname (dialog->account_manager, outgoing_account_name, hostname);
1539 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1540 modest_account_mgr_set_server_account_username (dialog->account_manager, outgoing_account_name,
1543 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1544 modest_account_mgr_set_server_account_password (dialog->account_manager, outgoing_account_name,
1547 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1548 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1549 modest_account_mgr_set_server_account_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1551 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1552 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1553 modest_account_mgr_set_server_account_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1556 port_num = hildon_number_editor_get_value (
1557 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1558 modest_account_mgr_set_server_account_port (dialog->account_manager,
1559 outgoing_account_name,
1561 g_free (outgoing_account_name);
1564 /* Set the changed account title last, to simplify the previous code: */
1565 gchar* account_title = get_entered_account_title (dialog);
1567 return FALSE; /* Should be prevented already anyway. */
1569 /* if (strcmp (account_title, account_name) != 0) { */
1570 modest_account_mgr_set_display_name (dialog->account_manager, account_name, account_title);
1572 g_free (account_title);
1573 account_title = NULL;
1575 /* Save connection-specific SMTP server accounts: */
1576 modest_account_mgr_set_use_connection_specific_smtp(dialog->account_manager, account_name,
1577 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbox_outgoing_smtp_specific)));
1578 if (dialog->specific_window) {
1579 return modest_connection_specific_smtp_window_save_server_accounts (
1580 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window));
1586 static gboolean entry_is_empty (GtkWidget *entry)
1591 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1592 if ((!text) || (strlen(text) == 0))
1595 /* Strip it of whitespace at the start and end: */
1596 gchar *stripped = g_strdup (text);
1597 stripped = g_strstrip (stripped);
1602 const gboolean result = (strlen (stripped) == 0);
1610 enable_buttons (ModestAccountSettingsDialog *self)
1612 gboolean enable_ok = TRUE;
1614 /* The account details title is mandatory: */
1615 if (entry_is_empty(self->entry_account_title))
1618 /* The user details username is mandatory: */
1619 if (entry_is_empty(self->entry_user_username))
1622 /* The user details email address is mandatory: */
1623 if (enable_ok && entry_is_empty (self->entry_user_email))
1626 /* The custom incoming server is mandatory: */
1627 if (entry_is_empty(self->entry_incomingserver))
1630 /* Enable the buttons,
1631 * identifying them via their associated response codes:
1633 GtkDialog *dialog_base = GTK_DIALOG (self);
1634 gtk_dialog_set_response_sensitive (dialog_base,
1640 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1642 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1643 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1646 object_class->get_property = modest_account_settings_dialog_get_property;
1647 object_class->set_property = modest_account_settings_dialog_set_property;
1648 object_class->dispose = modest_account_settings_dialog_dispose;
1649 object_class->finalize = modest_account_settings_dialog_finalize;