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);
709 self->modified = TRUE;
713 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
715 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
717 ModestAuthProtocol protocol_security =
718 modest_secureauth_combo_box_get_active_secureauth (
719 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
720 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
722 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
723 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
727 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
729 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
731 const gint port_number =
732 modest_serversecurity_combo_box_get_active_serversecurity_port (
733 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
735 if(port_number != 0) {
736 hildon_number_editor_set_value (
737 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
742 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
744 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
746 const gint port_number =
747 modest_serversecurity_combo_box_get_active_serversecurity_port (
748 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
750 if(port_number != 0) {
751 hildon_number_editor_set_value (
752 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
757 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
759 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
760 GtkAdjustment *focus_adjustment = NULL;
762 /* Put it all in a scrolled window, so that all widgets can be
763 * accessed even when the on-screen keyboard is visible: */
764 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
765 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
766 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
768 /* Create a size group to be used by all captions.
769 * Note that HildonCaption does not create a default size group if we do not specify one.
770 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
771 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
773 /* The outgoing server widgets: */
774 if (!self->entry_outgoingserver)
775 self->entry_outgoingserver = gtk_entry_new ();
776 /* Auto-capitalization is the default, so let's turn it off: */
777 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
778 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
779 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
780 gtk_widget_show (self->entry_outgoingserver);
781 connect_for_modified (self, self->entry_outgoingserver);
782 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
783 gtk_widget_show (caption);
785 /* The secure authentication widgets: */
786 if (!self->combo_outgoing_auth)
787 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
788 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
789 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
790 gtk_widget_show (self->combo_outgoing_auth);
791 connect_for_modified (self, self->combo_outgoing_auth);
792 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
793 gtk_widget_show (caption);
795 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
796 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
798 /* The username widgets: */
799 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
800 /* Auto-capitalization is the default, so let's turn it off: */
801 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
802 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
803 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
804 gtk_widget_show (self->entry_outgoing_username);
805 connect_for_modified (self, self->entry_outgoing_username);
806 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
807 gtk_widget_show (self->caption_outgoing_username);
809 /* Prevent the use of some characters in the username,
810 * as required by our UI specification: */
811 modest_validating_entry_set_unallowed_characters_whitespace (
812 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
814 /* Set max length as in the UI spec:
815 * The UI spec seems to want us to show a dialog if we hit the maximum. */
816 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
817 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
820 /* The password widgets: */
821 self->entry_outgoing_password = gtk_entry_new ();
822 /* Auto-capitalization is the default, so let's turn it off: */
823 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
824 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
825 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
826 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
827 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
828 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
829 gtk_widget_show (self->entry_outgoing_password);
830 connect_for_modified (self, self->entry_outgoing_password);
831 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
832 gtk_widget_show (self->caption_outgoing_password);
834 /* The secure connection widgets: */
835 /* This will be filled and set with modest_serversecurity_combo_box_fill()
836 * and modest_serversecurity_combo_box_set_active_serversecurity().
838 if (!self->combo_outgoing_security)
840 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
841 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
842 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
843 gtk_widget_show (self->combo_outgoing_security);
844 connect_for_modified (self, self->combo_outgoing_security);
845 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
846 gtk_widget_show (caption);
848 /* Show a default port number when the security method changes, as per the UI spec: */
849 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
851 /* The port widgets: */
852 if (!self->entry_outgoing_port)
853 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
854 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
855 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
856 gtk_widget_show (self->entry_outgoing_port);
857 connect_for_modified (self, self->entry_outgoing_port);
858 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
859 gtk_widget_show (caption);
861 GtkWidget *separator = gtk_hseparator_new ();
862 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
863 gtk_widget_show (separator);
865 /* connection-specific checkbox: */
866 if (!self->checkbox_outgoing_smtp_specific) {
867 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
868 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
871 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
872 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
873 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
874 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
875 gtk_widget_show (caption);
876 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
878 /* Connection-specific SMTP-Severs Edit button: */
879 if (!self->button_outgoing_smtp_servers)
880 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
881 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
882 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
883 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
884 gtk_widget_show (self->button_outgoing_smtp_servers);
885 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
886 gtk_widget_show (caption);
888 /* Only enable the button when the checkbox is checked: */
889 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
890 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
892 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
893 G_CALLBACK (on_button_outgoing_smtp_servers), self);
895 gtk_widget_show (GTK_WIDGET (box));
896 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
897 gtk_widget_show(scrollwin);
899 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
900 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
902 return GTK_WIDGET (scrollwin);
906 /** TODO: This doesn't work because hildon_number_editor_get_value() does not work until
907 * focus has been lost:
908 * See https://bugs.maemo.org/show_bug.cgi?id=1806.
911 check_hildon_number_editor_and_warn_value_not_in_range (HildonNumberEditor *widget, gint min, gint max)
913 g_return_val_if_fail (widget, FALSE);
915 const gint port = hildon_number_editor_get_value (widget);
916 /* printf ("DEBUG: %s, port=%d\n", __FUNCTION__, port); */
917 if (port < PORT_MIN ||
920 /* Warn the user via a dialog: */
921 gchar *message = g_strdup_printf (_CS("ckct_ib_set_a_value_within_range"),
924 hildon_banner_show_information (GTK_WIDGET (widget), NULL, message);
928 /* Return focus to the email address entry: */
929 gtk_widget_grab_focus (GTK_WIDGET (widget));
939 check_data (ModestAccountSettingsDialog *self)
941 /* Check that the title is not already in use: */
942 gchar* account_title = get_entered_account_title (self);
944 return FALSE; /* Should be prevented already anyway. */
946 if (strcmp(account_title, self->original_account_title) != 0) {
947 /* Check the changed title: */
948 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
952 /* Warn the user via a dialog: */
953 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
955 g_free (account_title);
960 g_free (account_title);
961 account_title = NULL;
963 /* Check that the email address is valid: */
964 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
965 if ((!email_address) || (strlen(email_address) == 0)) {
969 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
970 /* Warn the user via a dialog: */
971 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
973 /* Return focus to the email address entry: */
974 gtk_widget_grab_focus (self->entry_user_email);
975 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
979 /* make sure the domain name for the incoming server is valid */
980 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
981 if ((!hostname) || (strlen(hostname) == 0)) {
985 if (!modest_text_utils_validate_domain_name (hostname)) {
986 /* Warn the user via a dialog: */
987 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
989 /* Return focus to the email address entry: */
990 gtk_widget_grab_focus (self->entry_incomingserver);
991 gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
995 /* make sure the domain name for the outgoing server is valid */
996 const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
997 if ((!hostname2) || (strlen(hostname2) == 0)) {
1001 if (!modest_text_utils_validate_domain_name (hostname2)) {
1002 /* Warn the user via a dialog: */
1003 hildon_banner_show_information (self->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
1005 /* Return focus to the email address entry: */
1006 gtk_widget_grab_focus (self->entry_outgoingserver);
1007 gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
1011 /* Check that the port numbers are acceptable: */
1012 if (!check_hildon_number_editor_and_warn_value_not_in_range (
1013 HILDON_NUMBER_EDITOR (self->entry_incoming_port), PORT_MIN, PORT_MAX)) {
1017 if (!check_hildon_number_editor_and_warn_value_not_in_range (
1018 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), PORT_MIN, PORT_MAX)) {
1023 /* Find a suitable authentication method when secure authentication is desired */
1025 const gint port_num = hildon_number_editor_get_value (
1026 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
1027 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1030 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1031 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1033 /* If we use an encrypted protocol then there is no need to encrypt the password */
1034 /* I don't think this is a good assumption. It overrides the user's request. murrayc:
1035 * if (!modest_protocol_info_is_secure(protocol_security_incoming)) */
1038 if (gtk_toggle_button_get_active (
1039 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
1040 GError *error = NULL;
1042 GList *list_auth_methods =
1043 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
1044 hostname, port_num, username, GTK_WINDOW (self), &error);
1045 if (list_auth_methods) {
1046 /* Use the first supported method.
1047 * TODO: Should we prioritize them, to prefer a particular one? */
1049 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
1051 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(method->data));
1052 // Allow secure methods, e.g MD5 only
1053 if (modest_protocol_info_auth_is_secure(proto))
1055 self->protocol_authentication_incoming = proto;
1059 g_list_free (list_auth_methods);
1062 if (list_auth_methods == NULL ||
1063 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
1065 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
1066 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
1067 hildon_banner_show_information(GTK_WIDGET (self), NULL,
1068 _("Could not discover supported secure authentication methods."));
1071 g_error_free(error);
1073 /* This is a nasty hack. jschmid. */
1074 /* Don't let the dialog close */
1075 /*g_signal_stop_emission_by_name (dialog, "response");*/
1086 on_response (GtkDialog *wizard_dialog,
1090 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
1091 enable_buttons (self);
1093 gboolean prevent_response = FALSE;
1095 /* Warn about unsaved changes: */
1096 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
1097 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1098 _("imum_nc_wizard_confirm_lose_changes")));
1099 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1101 const gint dialog_response = gtk_dialog_run (dialog);
1102 gtk_widget_destroy (GTK_WIDGET (dialog));
1104 if (dialog_response != GTK_RESPONSE_OK)
1105 prevent_response = TRUE;
1107 /* Check for invalid input: */
1108 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1109 prevent_response = TRUE;
1112 if (prevent_response) {
1113 /* This is a nasty hack. murrayc. */
1114 /* Don't let the dialog close */
1115 g_signal_stop_emission_by_name (wizard_dialog, "response");
1119 if (response_id == GTK_RESPONSE_OK) {
1120 /* Try to save the changes if modified (NB #59251): */
1123 const gboolean saved = save_configuration (self);
1125 /* Do not show the account-saved dialog if we are just saving this
1126 * temporarily, because from the user's point of view it will not
1127 * really be saved (saved + enabled) until later
1129 if (modest_account_mgr_get_enabled (self->account_manager,
1130 self->account_name)) {
1131 gchar *incoming_account_name = NULL, *outgoing_account_name = NULL;
1133 incoming_account_name =
1134 modest_account_mgr_get_server_account_name (self->account_manager,
1136 TNY_ACCOUNT_TYPE_STORE);
1137 outgoing_account_name =
1138 modest_account_mgr_get_server_account_name (self->account_manager,
1140 TNY_ACCOUNT_TYPE_TRANSPORT);
1142 if (incoming_account_name) {
1143 modest_account_mgr_notify_account_update (self->account_manager,
1144 incoming_account_name);
1145 g_free (incoming_account_name);
1147 if (outgoing_account_name) {
1148 modest_account_mgr_notify_account_update (self->account_manager,
1149 outgoing_account_name);
1150 g_free (outgoing_account_name);
1153 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));
1219 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1220 modest_maemo_utils_get_osso_context());
1223 ModestAccountSettingsDialog*
1224 modest_account_settings_dialog_new (void)
1226 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1229 /** Update the UI with the stored account details, so they can be edited.
1230 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1232 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1237 /* Save the account name so we can refer to it later: */
1238 if (dialog->account_name)
1239 g_free (dialog->account_name);
1240 dialog->account_name = g_strdup (account_name);
1243 /* Get the account data for this account name: */
1244 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1246 if (!account_data) {
1247 g_printerr ("modest: failed to get account data for %s\n", account_name);
1251 /* Save the account title so we can refer to it if the user changes it: */
1252 if (dialog->original_account_title)
1253 g_free (dialog->original_account_title);
1254 dialog->original_account_title = g_strdup (account_data->display_name);
1257 if (!(account_data->store_account)) {
1258 g_printerr ("modest: account has no stores: %s\n", account_name);
1262 /* Show the account data in the widgets: */
1264 /* Note that we never show the non-display name in the UI.
1265 * (Though the display name defaults to the non-display name at the start.) */
1266 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1267 account_data->display_name ? account_data->display_name : "");
1269 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1270 account_data->fullname ? account_data->fullname : "");
1271 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1272 account_data->email ? account_data->email : "");
1274 ModestServerAccountData *incoming_account = account_data->store_account;
1276 if (incoming_account)
1277 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1280 gchar *retrieve = modest_account_mgr_get_retrieve_type (dialog->account_manager, account_name);
1282 /* Default to something, though no default is specified in the UI spec: */
1283 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1285 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1288 const gint limit_retrieve = modest_account_mgr_get_retrieve_limit (dialog->account_manager, account_name);
1289 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1292 const gboolean leave_on_server = modest_account_mgr_get_leave_on_server (dialog->account_manager, account_name);
1293 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1295 /* Only show the leave-on-server checkbox for POP,
1296 * as per the UI spec: */
1297 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1298 gtk_widget_hide (dialog->caption_leave_messages);
1300 gtk_widget_show (dialog->caption_leave_messages);
1303 update_incoming_server_security_choices (dialog, incoming_account->proto);
1304 if (incoming_account) {
1305 /* Remember this for later: */
1306 dialog->incoming_protocol = incoming_account->proto;
1308 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1309 incoming_account->username ? incoming_account->username : "");
1310 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1311 incoming_account->password ? incoming_account->password : "");
1313 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1314 incoming_account->hostname ? incoming_account->hostname : "");
1316 /* The UI spec says:
1317 * If secure authentication is unchecked, allow sending username and password also as plain text.
1318 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1319 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1321 const ModestConnectionProtocol security = modest_account_mgr_get_server_account_security (
1322 dialog->account_manager, incoming_account->account_name);
1323 modest_serversecurity_combo_box_set_active_serversecurity (
1324 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1329 - use encrypted passwords
1331 const ModestAuthProtocol secure_auth = modest_account_mgr_get_server_account_secure_auth(
1332 dialog->account_manager, incoming_account->account_name);
1333 dialog->protocol_authentication_incoming = secure_auth;
1334 if (modest_protocol_info_auth_is_secure(secure_auth))
1336 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1341 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1345 update_incoming_server_title (dialog, incoming_account->proto);
1347 const gint port_num = modest_account_mgr_get_server_account_port (dialog->account_manager,
1348 incoming_account->account_name);
1349 if (port_num == 0) {
1350 /* Show the appropriate port number: */
1351 on_combo_incoming_security_changed (
1352 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1354 /* Keep the user-entered port-number,
1355 * or the already-appropriate automatic port number: */
1356 hildon_number_editor_set_value (
1357 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1361 ModestServerAccountData *outgoing_account = account_data->transport_account;
1362 if (outgoing_account) {
1363 /* Remember this for later: */
1364 dialog->outgoing_protocol = outgoing_account->proto;
1366 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1367 outgoing_account->hostname ? outgoing_account->hostname : "");
1369 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1370 outgoing_account->username ? outgoing_account->username : "");
1371 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1372 outgoing_account->password ? outgoing_account->password : "");
1374 /* Get the secure-auth setting: */
1375 const ModestAuthProtocol secure_auth = modest_account_mgr_get_server_account_secure_auth(
1376 dialog->account_manager, outgoing_account->account_name);
1377 modest_secureauth_combo_box_set_active_secureauth (
1378 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1379 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1381 modest_serversecurity_combo_box_fill (
1382 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1384 /* Get the security setting: */
1385 const ModestConnectionProtocol security = modest_account_mgr_get_server_account_security (
1386 dialog->account_manager, outgoing_account->account_name);
1387 modest_serversecurity_combo_box_set_active_serversecurity (
1388 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1390 const gint port_num = modest_account_mgr_get_server_account_port (dialog->account_manager,
1391 outgoing_account->account_name);
1392 if (port_num == 0) {
1393 /* Show the appropriate port number: */
1394 on_combo_outgoing_security_changed (
1395 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1398 /* Keep the user-entered port-number,
1399 * or the already-appropriate automatic port number: */
1400 hildon_number_editor_set_value (
1401 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1404 const gboolean has_specific =
1405 modest_account_mgr_get_use_connection_specific_smtp (
1406 dialog->account_manager, account_name);
1407 gtk_toggle_button_set_active (
1408 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1412 /* Set window title according to account: */
1413 /* TODO: Is this the correct way to find a human-readable name for
1414 * the protocol used? */
1415 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1416 gchar *proto_name = g_utf8_strup(proto_str, -1);
1417 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1419 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1420 g_free (proto_name);
1421 g_free (account_title);
1423 gtk_window_set_title (GTK_WINDOW (dialog), title);
1426 /* account_data->is_enabled, */
1427 /*account_data->is_default, */
1429 /* account_data->store_account->proto */
1431 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1433 /* Unset the modified flag so we can detect changes later: */
1434 dialog->modified = FALSE;
1437 /** Show the User Info tab.
1439 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1441 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1442 if (page_num == -1) {
1443 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1446 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1447 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1449 gtk_widget_show (dialog->page_user_details);
1450 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1451 gtk_widget_show (GTK_WIDGET (dialog));
1452 gtk_notebook_set_current_page (dialog->notebook, page_num);
1456 save_configuration (ModestAccountSettingsDialog *dialog)
1458 g_assert (dialog->account_name);
1460 const gchar* account_name = dialog->account_name;
1462 /* Set the account data from the widgets: */
1463 const gchar* user_fullname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1464 modest_account_mgr_set_user_fullname (dialog->account_manager,
1468 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1469 modest_account_mgr_set_user_email (dialog->account_manager, account_name,
1473 if (dialog->signature_dialog) {
1474 gboolean use_signature = FALSE;
1476 modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1479 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1480 signature, use_signature);
1484 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1485 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1486 modest_account_mgr_set_retrieve_type (dialog->account_manager, account_name, (const gchar*) retrieve);
1489 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1490 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1491 modest_account_mgr_set_retrieve_limit (dialog->account_manager, account_name, limit_retrieve);
1493 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1494 modest_account_mgr_set_leave_on_server (dialog->account_manager, account_name, leave_on_server);
1497 gchar* incoming_account_name =
1498 modest_account_mgr_get_server_account_name (dialog->account_manager,
1500 TNY_ACCOUNT_TYPE_STORE);
1501 g_assert (incoming_account_name);
1503 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1504 modest_account_mgr_set_server_account_hostname (dialog->account_manager, incoming_account_name, hostname);
1506 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1507 modest_account_mgr_set_server_account_username (dialog->account_manager, incoming_account_name, username);
1509 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1510 modest_account_mgr_set_server_account_password (dialog->account_manager, incoming_account_name,
1514 gint port_num = hildon_number_editor_get_value (
1515 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1516 modest_account_mgr_set_server_account_port (dialog->account_manager, incoming_account_name, port_num);
1518 /* The UI spec says:
1519 * If secure authentication is unchecked, allow sending username and password also as plain text.
1520 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1523 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1524 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1525 modest_account_mgr_set_server_account_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1527 modest_account_mgr_set_server_account_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1530 g_free (incoming_account_name);
1533 gchar* outgoing_account_name =
1534 modest_account_mgr_get_server_account_name (dialog->account_manager,
1536 TNY_ACCOUNT_TYPE_TRANSPORT);
1537 g_assert (outgoing_account_name);
1539 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1540 modest_account_mgr_set_server_account_hostname (dialog->account_manager, outgoing_account_name, hostname);
1542 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1543 modest_account_mgr_set_server_account_username (dialog->account_manager, outgoing_account_name,
1546 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1547 modest_account_mgr_set_server_account_password (dialog->account_manager, outgoing_account_name,
1550 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1551 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1552 modest_account_mgr_set_server_account_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1554 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1555 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1556 modest_account_mgr_set_server_account_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1559 port_num = hildon_number_editor_get_value (
1560 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1561 modest_account_mgr_set_server_account_port (dialog->account_manager,
1562 outgoing_account_name,
1564 g_free (outgoing_account_name);
1567 /* Set the changed account title last, to simplify the previous code: */
1568 gchar* account_title = get_entered_account_title (dialog);
1570 return FALSE; /* Should be prevented already anyway. */
1572 /* if (strcmp (account_title, account_name) != 0) { */
1573 modest_account_mgr_set_display_name (dialog->account_manager, account_name, account_title);
1575 g_free (account_title);
1576 account_title = NULL;
1578 /* Save connection-specific SMTP server accounts: */
1579 modest_account_mgr_set_use_connection_specific_smtp(dialog->account_manager, account_name,
1580 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbox_outgoing_smtp_specific)));
1581 if (dialog->specific_window) {
1582 return modest_connection_specific_smtp_window_save_server_accounts (
1583 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window));
1589 static gboolean entry_is_empty (GtkWidget *entry)
1594 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1595 if ((!text) || (strlen(text) == 0))
1598 /* Strip it of whitespace at the start and end: */
1599 gchar *stripped = g_strdup (text);
1600 stripped = g_strstrip (stripped);
1605 const gboolean result = (strlen (stripped) == 0);
1613 enable_buttons (ModestAccountSettingsDialog *self)
1615 gboolean enable_ok = TRUE;
1617 /* The account details title is mandatory: */
1618 if (entry_is_empty(self->entry_account_title))
1621 /* The user details username is mandatory: */
1622 if (entry_is_empty(self->entry_user_username))
1625 /* The user details email address is mandatory: */
1626 if (enable_ok && entry_is_empty (self->entry_user_email))
1629 /* The custom incoming server is mandatory: */
1630 if (entry_is_empty(self->entry_incomingserver))
1633 /* Enable the buttons,
1634 * identifying them via their associated response codes:
1636 GtkDialog *dialog_base = GTK_DIALOG (self);
1637 gtk_dialog_set_response_sensitive (dialog_base,
1643 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1645 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1646 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1649 object_class->get_property = modest_account_settings_dialog_get_property;
1650 object_class->set_property = modest_account_settings_dialog_set_property;
1651 object_class->dispose = modest_account_settings_dialog_dispose;
1652 object_class->finalize = modest_account_settings_dialog_finalize;