1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "modest-account-settings-dialog.h"
32 #include <glib/gi18n.h>
33 #include <gtk/gtknotebook.h>
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkcombobox.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkstock.h>
42 #include "modest-hildon-includes.h"
44 #include "widgets/modest-serversecurity-combo-box.h"
45 #include "widgets/modest-secureauth-combo-box.h"
46 #include "widgets/modest-validating-entry.h"
47 #include "widgets/modest-retrieve-combo-box.h"
48 #include "widgets/modest-limit-retrieve-combo-box.h"
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
52 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "modest-protocol-info.h"
54 #include "maemo/modest-connection-specific-smtp-window.h"
55 #include "maemo/modest-signature-editor-dialog.h"
56 #include "maemo/modest-maemo-utils.h"
57 #include "widgets/modest-ui-constants.h"
59 #include <tny-camel-transport-account.h>
60 #include <tny-camel-imap-store-account.h>
61 #include <tny-camel-pop-store-account.h>
62 #include <tny-status.h>
64 #include <gconf/gconf-client.h>
65 #include <string.h> /* For strlen(). */
67 /* Include config.h so that _() works: */
72 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
75 #define PORT_MAX 65535
77 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
79 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
80 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
82 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
84 struct _ModestAccountSettingsDialogPrivate
89 enable_buttons (ModestAccountSettingsDialog *self);
92 save_configuration (ModestAccountSettingsDialog *dialog);
95 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
96 GValue *value, GParamSpec *pspec)
98 switch (property_id) {
100 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
105 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
106 const GValue *value, GParamSpec *pspec)
108 switch (property_id) {
110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
115 modest_account_settings_dialog_dispose (GObject *object)
117 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
118 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
122 modest_account_settings_dialog_finalize (GObject *object)
124 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
126 if (self->account_name)
127 g_free (self->account_name);
129 if (self->original_account_title)
130 g_free (self->original_account_title);
132 if (self->account_manager)
133 g_object_unref (G_OBJECT (self->account_manager));
135 if (self->specific_window)
136 gtk_widget_destroy (self->specific_window);
138 if (self->signature_dialog)
139 gtk_widget_destroy (self->signature_dialog);
141 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
145 show_error (GtkWidget *parent_widget, const gchar* text);
148 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
151 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
154 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
156 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
157 self->modified = TRUE;
161 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
163 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
164 self->modified = TRUE;
168 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
170 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
171 self->modified = TRUE;
175 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
177 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
178 self->modified = TRUE;
181 /* Set a modified boolean whenever the widget is changed,
182 * so we can check for it later.
185 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
187 if (HILDON_IS_NUMBER_EDITOR (widget)) {
188 g_signal_connect (G_OBJECT (widget), "notify::value",
189 G_CALLBACK (on_modified_number_editor_changed), self);
191 else if (GTK_IS_ENTRY (widget)) {
192 g_signal_connect (G_OBJECT (widget), "changed",
193 G_CALLBACK (on_modified_entry_changed), self);
194 } else if (GTK_IS_COMBO_BOX (widget)) {
195 g_signal_connect (G_OBJECT (widget), "changed",
196 G_CALLBACK (on_modified_combobox_changed), self);
197 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
198 g_signal_connect (G_OBJECT (widget), "toggled",
199 G_CALLBACK (on_modified_checkbox_toggled), self);
204 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
206 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
208 enable_buttons(self);
212 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
214 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
216 enable_buttons(self);
219 /** This is a convenience function to create a caption containing a mandatory widget.
220 * When the widget is edited, the enable_buttons() vfunc will be called.
222 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
227 HildonCaptionStatus flag)
229 GtkWidget *caption = NULL;
231 /* Note: Previously, the translated strings already contained the "*",
232 * Comment out this code if they do again.
234 /* Add a * character to indicate mandatory fields,
235 * as specified in our "Email UI Specification": */
236 if (flag == HILDON_CAPTION_MANDATORY) {
237 gchar* title = g_strdup_printf("%s*", value);
238 caption = hildon_caption_new (group, title, control, icon, flag);
242 caption = hildon_caption_new (group, value, control, icon, flag);
244 /* Connect to the appropriate changed signal for the widget,
245 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
247 if (GTK_IS_ENTRY (control)) {
248 g_signal_connect (G_OBJECT (control), "changed",
249 G_CALLBACK (on_caption_entry_changed), self);
252 else if (GTK_IS_COMBO_BOX (control)) {
253 g_signal_connect (G_OBJECT (control), "changed",
254 G_CALLBACK (on_caption_combobox_changed), self);
261 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
265 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
266 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
268 show_error (GTK_WIDGET (self), msg);
275 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
279 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
280 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
282 show_error (GTK_WIDGET (self), msg);
290 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
292 /* ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data); */
293 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
297 create_page_account_details (ModestAccountSettingsDialog *self)
299 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
300 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
301 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
302 gtk_widget_show (label);
304 /* Create a size group to be used by all captions.
305 * Note that HildonCaption does not create a default size group if we do not specify one.
306 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
307 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
309 /* The description widgets: */
310 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
311 /* Do use auto-capitalization: */
312 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
313 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
314 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
315 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
316 gtk_widget_show (self->entry_account_title);
317 connect_for_modified (self, self->entry_account_title);
318 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
319 gtk_widget_show (caption);
321 /* Prevent the use of some characters in the account title,
322 * as required by our UI specification: */
323 GList *list_prevent = NULL;
324 list_prevent = g_list_append (list_prevent, "\\");
325 list_prevent = g_list_append (list_prevent, "/");
326 list_prevent = g_list_append (list_prevent, ":");
327 list_prevent = g_list_append (list_prevent, "*");
328 list_prevent = g_list_append (list_prevent, "?");
329 list_prevent = g_list_append (list_prevent, "\"");
330 list_prevent = g_list_append (list_prevent, "<");
331 list_prevent = g_list_append (list_prevent, ">");
332 list_prevent = g_list_append (list_prevent, "|");
333 list_prevent = g_list_append (list_prevent, "^");
334 modest_validating_entry_set_unallowed_characters (
335 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
336 g_list_free (list_prevent);
337 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
338 on_entry_invalid_account_title_character, self);
340 /* Set max length as in the UI spec:
341 * The UI spec seems to want us to show a dialog if we hit the maximum. */
342 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
343 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
346 /* The retrieve combobox: */
347 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
348 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
349 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
350 gtk_widget_show (self->combo_retrieve);
351 connect_for_modified (self, self->combo_retrieve);
352 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
353 gtk_widget_show (caption);
355 /* The limit-retrieve combobox: */
356 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
357 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
358 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
359 gtk_widget_show (self->combo_limit_retrieve);
360 connect_for_modified (self, self->combo_limit_retrieve);
361 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
362 gtk_widget_show (caption);
364 /* The leave-messages widgets: */
365 if(!self->checkbox_leave_messages)
366 self->checkbox_leave_messages = gtk_check_button_new ();
367 if (!self->caption_leave_messages) {
368 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
369 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
372 gtk_widget_show (self->checkbox_leave_messages);
373 connect_for_modified (self, self->checkbox_leave_messages);
374 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
375 gtk_widget_show (self->caption_leave_messages);
377 gtk_widget_show (GTK_WIDGET (box));
379 return GTK_WIDGET (box);
383 get_entered_account_title (ModestAccountSettingsDialog *dialog)
385 const gchar* account_title =
386 gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
387 if (!account_title || (strlen (account_title) == 0))
390 /* Strip it of whitespace at the start and end: */
391 gchar *result = g_strdup (account_title);
392 result = g_strstrip (result);
397 if (strlen (result) == 0) {
408 on_button_signature (GtkButton *button, gpointer user_data)
410 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
412 /* Create the window, if necessary: */
413 if (!(self->signature_dialog)) {
414 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
416 gboolean use_signature = FALSE;
417 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
419 gchar* account_title = get_entered_account_title (self);
420 modest_signature_editor_dialog_set_settings (
421 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
422 use_signature, signature, account_title);
423 g_free (account_title);
424 account_title = NULL;
429 /* Show the window: */
430 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
431 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
432 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
433 gtk_widget_hide (self->signature_dialog);
434 if (response != GTK_RESPONSE_OK) {
435 /* Destroy the widget now, and its data: */
436 gtk_widget_destroy (self->signature_dialog);
437 self->signature_dialog = NULL;
440 /* Mark modified, so we use the dialog's data later: */
441 self->modified = TRUE;
446 create_page_user_details (ModestAccountSettingsDialog *self)
448 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
449 GtkAdjustment *focus_adjustment = NULL;
451 /* Create a size group to be used by all captions.
452 * Note that HildonCaption does not create a default size group if we do not specify one.
453 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
454 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
455 GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
456 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
457 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
459 /* The name widgets: */
460 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
462 /* Auto-capitalization is the default, so let's turn it off: */
463 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
464 /* Set max length as in the UI spec:
465 * The UI spec seems to want us to show a dialog if we hit the maximum. */
466 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
467 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
469 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
470 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
471 gtk_widget_show (self->entry_user_name);
472 connect_for_modified (self, self->entry_user_name);
473 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
474 gtk_widget_show (caption);
477 /* Prevent the use of some characters in the name,
478 * as required by our UI specification: */
479 GList *list_prevent = NULL;
480 list_prevent = g_list_append (list_prevent, "<");
481 list_prevent = g_list_append (list_prevent, ">");
482 modest_validating_entry_set_unallowed_characters (
483 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
484 g_list_free (list_prevent);
485 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
486 on_entry_invalid_fullname_character, self);
488 /* The username widgets: */
489 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
490 /* Auto-capitalization is the default, so let's turn it off: */
491 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
492 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
493 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
494 gtk_widget_show (self->entry_user_username);
495 connect_for_modified (self, self->entry_user_username);
496 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
497 gtk_widget_show (caption);
499 /* Prevent the use of some characters in the username,
500 * as required by our UI specification: */
501 modest_validating_entry_set_unallowed_characters_whitespace (
502 MODEST_VALIDATING_ENTRY (self->entry_user_username));
504 /* Set max length as in the UI spec:
505 * The UI spec seems to want us to show a dialog if we hit the maximum. */
506 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
507 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
510 /* The password widgets: */
511 self->entry_user_password = gtk_entry_new ();
512 /* Auto-capitalization is the default, so let's turn it off: */
513 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
514 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
515 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
516 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
517 caption = create_caption_new_with_asterisk (self, sizegroup,
518 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
519 gtk_widget_show (self->entry_user_password);
520 connect_for_modified (self, self->entry_user_password);
521 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
522 gtk_widget_show (caption);
524 /* The email address widgets: */
525 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
526 /* Auto-capitalization is the default, so let's turn it off: */
527 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
528 caption = create_caption_new_with_asterisk (self, sizegroup,
529 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
530 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
531 gtk_widget_show (self->entry_user_email);
532 connect_for_modified (self, self->entry_user_email);
533 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
534 gtk_widget_show (caption);
536 /* Set max length as in the UI spec:
537 * The UI spec seems to want us to show a dialog if we hit the maximum. */
538 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
539 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
542 /* Signature button: */
543 if (!self->button_signature)
544 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
545 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
546 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
547 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
548 gtk_widget_show (self->button_signature);
549 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
550 gtk_widget_show (caption);
552 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
553 G_CALLBACK (on_button_signature), self);
555 gtk_widget_show (GTK_WIDGET (box));
556 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
557 gtk_widget_show (scrollwin);
559 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
560 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
562 return GTK_WIDGET (scrollwin);
565 /** Change the caption title for the incoming server,
566 * as specified in the UI spec:
568 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
571 (protocol == MODEST_PROTOCOL_STORE_POP ?
572 _("mail_fi_emailtype_pop3") :
573 _("mail_fi_emailtype_imap") );
576 /* Note that this produces a compiler warning,
577 * because the compiler does not know that the translated string will have a %s in it.
578 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
579 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
581 /* This is a mandatory field, so add a *. This is usually done by
582 * create_caption_new_with_asterisk() but we can't use that here. */
583 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
584 g_free (incomingserver_title);
586 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
587 g_free(with_asterisk);
590 /** Change the caption title for the incoming server,
591 * as specified in the UI spec:
593 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
595 /* Fill the combo with appropriately titled choices for POP or IMAP. */
596 /* The choices are the same, but the titles are different, as in the UI spec. */
597 modest_serversecurity_combo_box_fill (
598 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
601 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
603 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
605 /* Create a size group to be used by all captions.
606 * Note that HildonCaption does not create a default size group if we do not specify one.
607 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
608 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
610 /* The incoming server widgets: */
611 if(!self->entry_incomingserver)
612 self->entry_incomingserver = gtk_entry_new ();
613 /* Auto-capitalization is the default, so let's turn it off: */
614 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
616 if (self->caption_incoming)
617 gtk_widget_destroy (self->caption_incoming);
619 /* The caption title will be updated in update_incoming_server_title().
620 * so this default text will never be seen: */
621 /* (Note: Changing the title seems pointless. murrayc) */
622 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
623 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
624 gtk_widget_show (self->entry_incomingserver);
625 connect_for_modified (self, self->entry_incomingserver);
626 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
627 gtk_widget_show (self->caption_incoming);
629 /* The secure connection widgets: */
630 /* This will be filled by update_incoming_server_security_choices(). */
631 if (!self->combo_incoming_security)
632 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
633 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
634 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
635 gtk_widget_show (self->combo_incoming_security);
636 connect_for_modified (self, self->combo_incoming_security);
637 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
638 gtk_widget_show (caption);
640 /* Show a default port number when the security method changes, as per the UI spec: */
641 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
644 /* The port widgets: */
645 if (!self->entry_incoming_port)
646 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
647 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
648 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
649 gtk_widget_show (self->entry_incoming_port);
650 connect_for_modified (self, self->entry_incoming_port);
651 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
652 gtk_widget_show (caption);
654 /* The secure authentication widgets: */
655 if(!self->checkbox_incoming_auth)
656 self->checkbox_incoming_auth = gtk_check_button_new ();
657 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
658 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
659 gtk_widget_show (self->checkbox_incoming_auth);
660 connect_for_modified (self, self->checkbox_incoming_auth);
661 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
662 gtk_widget_show (caption);
664 gtk_widget_show (GTK_WIDGET (box));
666 return GTK_WIDGET (box);
670 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
672 GtkWidget *widget = GTK_WIDGET (user_data);
674 /* Enable the widget only if the toggle button is active: */
675 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
676 gtk_widget_set_sensitive (widget, enable);
679 /* Make the sensitivity of a widget depend on a toggle button.
682 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
684 g_signal_connect (G_OBJECT (button), "toggled",
685 G_CALLBACK (on_toggle_button_changed), widget);
687 /* Set the starting sensitivity: */
688 on_toggle_button_changed (button, widget);
692 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
694 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
696 /* Create the window if necessary: */
697 if (!(self->specific_window)) {
698 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
699 modest_connection_specific_smtp_window_fill_with_connections (
700 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
704 /* Show the window: */
705 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
706 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
707 gtk_widget_show (self->specific_window);
711 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
713 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
715 ModestAuthProtocol protocol_security =
716 modest_secureauth_combo_box_get_active_secureauth (
717 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
718 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
720 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
721 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
725 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
727 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
729 const gint port_number =
730 modest_serversecurity_combo_box_get_active_serversecurity_port (
731 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
733 if(port_number != 0) {
734 hildon_number_editor_set_value (
735 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
740 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
742 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
744 const gint port_number =
745 modest_serversecurity_combo_box_get_active_serversecurity_port (
746 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
748 if(port_number != 0) {
749 hildon_number_editor_set_value (
750 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
755 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
757 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
758 GtkAdjustment *focus_adjustment = NULL;
760 /* Put it all in a scrolled window, so that all widgets can be
761 * accessed even when the on-screen keyboard is visible: */
762 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
763 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
764 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
766 /* Create a size group to be used by all captions.
767 * Note that HildonCaption does not create a default size group if we do not specify one.
768 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
769 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
771 /* The outgoing server widgets: */
772 if (!self->entry_outgoingserver)
773 self->entry_outgoingserver = gtk_entry_new ();
774 /* Auto-capitalization is the default, so let's turn it off: */
775 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
776 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
777 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
778 gtk_widget_show (self->entry_outgoingserver);
779 connect_for_modified (self, self->entry_outgoingserver);
780 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
781 gtk_widget_show (caption);
783 /* The secure authentication widgets: */
784 if (!self->combo_outgoing_auth)
785 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
786 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
787 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
788 gtk_widget_show (self->combo_outgoing_auth);
789 connect_for_modified (self, self->combo_outgoing_auth);
790 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
791 gtk_widget_show (caption);
793 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
794 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
796 /* The username widgets: */
797 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
798 /* Auto-capitalization is the default, so let's turn it off: */
799 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
800 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
801 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
802 gtk_widget_show (self->entry_outgoing_username);
803 connect_for_modified (self, self->entry_outgoing_username);
804 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
805 gtk_widget_show (self->caption_outgoing_username);
807 /* Prevent the use of some characters in the username,
808 * as required by our UI specification: */
809 modest_validating_entry_set_unallowed_characters_whitespace (
810 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
812 /* Set max length as in the UI spec:
813 * The UI spec seems to want us to show a dialog if we hit the maximum. */
814 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
815 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
818 /* The password widgets: */
819 self->entry_outgoing_password = gtk_entry_new ();
820 /* Auto-capitalization is the default, so let's turn it off: */
821 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
822 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
823 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
824 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
825 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
826 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
827 gtk_widget_show (self->entry_outgoing_password);
828 connect_for_modified (self, self->entry_outgoing_password);
829 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
830 gtk_widget_show (self->caption_outgoing_password);
832 /* The secure connection widgets: */
833 /* This will be filled and set with modest_serversecurity_combo_box_fill()
834 * and modest_serversecurity_combo_box_set_active_serversecurity().
836 if (!self->combo_outgoing_security)
838 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
839 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
840 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
841 gtk_widget_show (self->combo_outgoing_security);
842 connect_for_modified (self, self->combo_outgoing_security);
843 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
844 gtk_widget_show (caption);
846 /* Show a default port number when the security method changes, as per the UI spec: */
847 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
849 /* The port widgets: */
850 if (!self->entry_outgoing_port)
851 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
852 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
853 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
854 gtk_widget_show (self->entry_outgoing_port);
855 connect_for_modified (self, self->entry_outgoing_port);
856 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
857 gtk_widget_show (caption);
859 GtkWidget *separator = gtk_hseparator_new ();
860 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
861 gtk_widget_show (separator);
863 /* connection-specific checkbox: */
864 if (!self->checkbox_outgoing_smtp_specific) {
865 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
866 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
869 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
870 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
871 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
872 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
873 gtk_widget_show (caption);
874 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
876 /* Connection-specific SMTP-Severs Edit button: */
877 if (!self->button_outgoing_smtp_servers)
878 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
879 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
880 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
881 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
882 gtk_widget_show (self->button_outgoing_smtp_servers);
883 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
884 gtk_widget_show (caption);
886 /* Only enable the button when the checkbox is checked: */
887 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
888 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
890 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
891 G_CALLBACK (on_button_outgoing_smtp_servers), self);
893 gtk_widget_show (GTK_WIDGET (box));
894 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
895 gtk_widget_show(scrollwin);
897 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
898 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
900 return GTK_WIDGET (scrollwin);
904 /** TODO: This doesn't work because hildon_number_editor_get_value() does not work until
905 * focus has been lost:
906 * See https://bugs.maemo.org/show_bug.cgi?id=1806.
909 check_hildon_number_editor_and_warn_value_not_in_range (HildonNumberEditor *widget, gint min, gint max)
911 g_return_val_if_fail (widget, FALSE);
913 const gint port = hildon_number_editor_get_value (widget);
914 /* printf ("DEBUG: %s, port=%d\n", __FUNCTION__, port); */
915 if (port < PORT_MIN ||
918 /* Warn the user via a dialog: */
919 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
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 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
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 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
988 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
990 /* Return focus to the email address entry: */
991 gtk_widget_grab_focus (self->entry_incomingserver);
992 gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
996 /* make sure the domain name for the outgoing server is valid */
997 const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
998 if ((!hostname2) || (strlen(hostname2) == 0)) {
1002 if (!modest_text_utils_validate_domain_name (hostname2)) {
1003 /* Warn the user via a dialog: */
1004 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
1005 hildon_banner_show_information (self->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
1007 /* Return focus to the email address entry: */
1008 gtk_widget_grab_focus (self->entry_outgoingserver);
1009 gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
1013 /* Check that the port numbers are acceptable: */
1014 if (!check_hildon_number_editor_and_warn_value_not_in_range (
1015 HILDON_NUMBER_EDITOR (self->entry_incoming_port), PORT_MIN, PORT_MAX)) {
1019 if (!check_hildon_number_editor_and_warn_value_not_in_range (
1020 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), PORT_MIN, PORT_MAX)) {
1025 /* Find a suitable authentication method when secure authentication is desired */
1027 const gint port_num = hildon_number_editor_get_value (
1028 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
1029 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
1031 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1032 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
1034 /* If we use an encrypted protocol then there is no need to encrypt the password */
1035 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;
1040 GList *list_auth_methods =
1041 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
1042 hostname, port_num, username, GTK_WINDOW (self), &error);
1043 if (list_auth_methods) {
1044 /* Use the first supported method.
1045 * TODO: Should we prioritize them, to prefer a particular one? */
1047 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
1049 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
1050 // Allow secure methods, e.g MD5 only
1051 if (modest_protocol_info_auth_is_secure(proto))
1053 self->protocol_authentication_incoming = proto;
1057 g_list_free (list_auth_methods);
1060 if (list_auth_methods == NULL ||
1061 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
1063 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
1064 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
1066 show_error (GTK_WIDGET (self), _("Could not discover supported secure authentication methods."));
1070 g_error_free(error);
1072 /* This is a nasty hack. jschmid. */
1073 /* Don't let the dialog close */
1074 /*g_signal_stop_emission_by_name (dialog, "response");*/
1085 on_response (GtkDialog *wizard_dialog,
1089 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
1090 enable_buttons (self);
1092 gboolean prevent_response = FALSE;
1094 /* Warn about unsaved changes: */
1095 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
1096 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1097 _("imum_nc_wizard_confirm_lose_changes")));
1098 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1100 const gint dialog_response = gtk_dialog_run (dialog);
1101 gtk_widget_destroy (GTK_WIDGET (dialog));
1103 if (dialog_response != GTK_RESPONSE_OK)
1104 prevent_response = TRUE;
1106 /* Check for invalid input: */
1107 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1108 prevent_response = TRUE;
1111 if (prevent_response) {
1112 /* This is a nasty hack. murrayc. */
1113 /* Don't let the dialog close */
1114 g_signal_stop_emission_by_name (wizard_dialog, "response");
1118 if (response_id == GTK_RESPONSE_OK) {
1119 /* Try to save the changes if modified (NB #59251): */
1122 const gboolean saved = save_configuration (self);
1124 /* Do not show the account-saved dialog if we are just saving this
1125 * temporarily, because from the user's point of view it will not
1126 * really be saved (saved + enabled) until later.
1128 const gboolean enabled =
1129 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
1131 show_error (NULL, _("mcen_ib_advsetup_settings_saved"));
1134 show_error (NULL, _("mail_ib_setting_failed"));
1140 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
1142 /* Create the notebook to be used by the GtkDialog base class:
1143 * Each page of the notebook will be a page of the wizard: */
1144 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1146 /* Get the account manager object,
1147 * so we can check for existing accounts,
1148 * and create new accounts: */
1149 self->account_manager = modest_runtime_get_account_mgr ();
1150 g_assert (self->account_manager);
1151 g_object_ref (self->account_manager);
1153 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1155 /* Create the common pages,
1157 self->page_account_details = create_page_account_details (self);
1158 self->page_user_details = create_page_user_details (self);
1159 self->page_incoming = create_page_incoming (self);
1160 self->page_outgoing = create_page_outgoing (self);
1162 /* Add the notebook pages: */
1163 gtk_notebook_append_page (self->notebook, self->page_account_details,
1164 gtk_label_new (_("mcen_ti_account_settings_account")));
1165 gtk_notebook_append_page (self->notebook, self->page_user_details,
1166 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1167 gtk_notebook_append_page (self->notebook, self->page_incoming,
1168 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1169 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1170 gtk_label_new (_("mcen_ti_advsetup_sending")));
1172 GtkDialog *dialog = GTK_DIALOG (self);
1173 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1174 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1175 gtk_widget_show (GTK_WIDGET (self->notebook));
1177 /* Add the buttons: */
1178 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1179 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1181 /* Connect to the dialog's response signal: */
1182 /* We use connect-before
1183 * so we can stop the signal emission,
1184 * to stop the default signal handler from closing the dialog.
1186 g_signal_connect (G_OBJECT (self), "response",
1187 G_CALLBACK (on_response), self);
1189 self->modified = FALSE;
1191 /* When this window is shown, hibernation should not be possible,
1192 * because there is no sensible way to save the state: */
1193 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1194 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1197 ModestAccountSettingsDialog*
1198 modest_account_settings_dialog_new (void)
1200 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1203 /** Update the UI with the stored account details, so they can be edited.
1204 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1206 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1211 /* Save the account name so we can refer to it later: */
1212 if (dialog->account_name)
1213 g_free (dialog->account_name);
1214 dialog->account_name = g_strdup (account_name);
1217 /* Get the account data for this account name: */
1218 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1220 if (!account_data) {
1221 g_printerr ("modest: failed to get account data for %s\n", account_name);
1225 /* Save the account title so we can refer to it if the user changes it: */
1226 if (dialog->original_account_title)
1227 g_free (dialog->original_account_title);
1228 dialog->original_account_title = g_strdup (account_data->display_name);
1231 if (!(account_data->store_account)) {
1232 g_printerr ("modest: account has no stores: %s\n", account_name);
1236 /* Show the account data in the widgets: */
1238 /* Note that we never show the non-display name in the UI.
1239 * (Though the display name defaults to the non-display name at the start.) */
1240 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1241 account_data->display_name ? account_data->display_name : "");
1243 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1244 account_data->fullname ? account_data->fullname : "");
1245 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1246 account_data->email ? account_data->email : "");
1248 ModestServerAccountData *incoming_account = account_data->store_account;
1250 if (incoming_account)
1251 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1252 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1253 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1255 /* Default to something, though no default is specified in the UI spec: */
1256 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1258 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1261 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1262 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1263 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1266 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1267 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1268 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1270 /* Only show the leave-on-server checkbox for POP,
1271 * as per the UI spec: */
1272 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1273 gtk_widget_hide (dialog->caption_leave_messages);
1275 gtk_widget_show (dialog->caption_leave_messages);
1278 update_incoming_server_security_choices (dialog, incoming_account->proto);
1279 if (incoming_account) {
1280 /* Remember this for later: */
1281 dialog->incoming_protocol = incoming_account->proto;
1283 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1284 incoming_account->username ? incoming_account->username : "");
1285 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1286 incoming_account->password ? incoming_account->password : "");
1288 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1289 incoming_account->hostname ? incoming_account->hostname : "");
1291 /* The UI spec says:
1292 * If secure authentication is unchecked, allow sending username and password also as plain text.
1293 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1294 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1296 const ModestConnectionProtocol security = modest_server_account_get_security (
1297 dialog->account_manager, incoming_account->account_name);
1298 modest_serversecurity_combo_box_set_active_serversecurity (
1299 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1304 - use encrypted passwords
1306 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1307 dialog->account_manager, incoming_account->account_name);
1308 dialog->protocol_authentication_incoming = secure_auth;
1309 if (modest_protocol_info_is_secure(security) ||
1310 modest_protocol_info_auth_is_secure(secure_auth))
1312 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1317 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1321 update_incoming_server_title (dialog, incoming_account->proto);
1323 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1324 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1326 if (port_num == 0) {
1327 /* Show the appropriate port number: */
1328 on_combo_incoming_security_changed (
1329 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1331 /* Keep the user-entered port-number,
1332 * or the already-appropriate automatic port number: */
1333 hildon_number_editor_set_value (
1334 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1338 ModestServerAccountData *outgoing_account = account_data->transport_account;
1339 if (outgoing_account) {
1340 /* Remember this for later: */
1341 dialog->outgoing_protocol = outgoing_account->proto;
1343 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1344 outgoing_account->hostname ? outgoing_account->hostname : "");
1346 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1347 outgoing_account->username ? outgoing_account->username : "");
1348 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1349 outgoing_account->password ? outgoing_account->password : "");
1351 /* Get the secure-auth setting: */
1352 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1353 dialog->account_manager, outgoing_account->account_name);
1354 modest_secureauth_combo_box_set_active_secureauth (
1355 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1356 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1358 modest_serversecurity_combo_box_fill (
1359 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1361 /* Get the security setting: */
1362 const ModestConnectionProtocol security = modest_server_account_get_security (
1363 dialog->account_manager, outgoing_account->account_name);
1364 modest_serversecurity_combo_box_set_active_serversecurity (
1365 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1367 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1368 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1369 if (port_num == 0) {
1370 /* Show the appropriate port number: */
1371 on_combo_outgoing_security_changed (
1372 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1375 /* Keep the user-entered port-number,
1376 * or the already-appropriate automatic port number: */
1377 hildon_number_editor_set_value (
1378 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1381 const gboolean has_specific =
1382 modest_account_mgr_get_use_connection_specific_smtp (
1383 dialog->account_manager,
1385 gtk_toggle_button_set_active (
1386 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1390 /* Set window title according to account: */
1391 /* TODO: Is this the correct way to find a human-readable name for
1392 * the protocol used? */
1393 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1394 gchar *proto_name = g_utf8_strup(proto_str, -1);
1395 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1397 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1398 g_free (proto_name);
1399 g_free (account_title);
1401 gtk_window_set_title (GTK_WINDOW (dialog), title);
1404 /* account_data->is_enabled, */
1405 /*account_data->is_default, */
1407 /* account_data->store_account->proto */
1409 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1411 /* Unset the modified flag so we can detect changes later: */
1412 dialog->modified = FALSE;
1415 /** Show the User Info tab.
1417 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1419 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1420 if (page_num == -1) {
1421 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1424 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1425 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1427 gtk_widget_show (dialog->page_user_details);
1428 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1429 gtk_widget_show (GTK_WIDGET (dialog));
1430 gtk_notebook_set_current_page (dialog->notebook, page_num);
1434 save_configuration (ModestAccountSettingsDialog *dialog)
1436 g_assert (dialog->account_name);
1438 const gchar* account_name = dialog->account_name;
1440 /* Set the account data from the widgets: */
1441 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1442 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1443 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1447 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1448 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1449 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1454 if (dialog->signature_dialog) {
1455 gboolean use_signature = FALSE;
1456 gchar *signature = modest_signature_editor_dialog_get_settings (
1457 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1460 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1461 signature, use_signature);
1465 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1466 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1467 modest_account_mgr_set_string (dialog->account_manager, account_name,
1468 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1471 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1472 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1473 modest_account_mgr_set_int (dialog->account_manager, account_name,
1474 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1476 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1477 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1478 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1483 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1484 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1485 g_assert (incoming_account_name);
1487 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1488 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1489 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1493 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1494 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1496 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1497 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1500 gint port_num = hildon_number_editor_get_value (
1501 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1502 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1503 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1505 /* The UI spec says:
1506 * If secure authentication is unchecked, allow sending username and password also as plain text.
1507 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1510 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1511 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1512 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1514 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1517 g_free (incoming_account_name);
1520 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1521 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1522 g_assert (outgoing_account_name);
1524 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1525 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1526 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1530 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1531 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1534 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1535 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1538 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1539 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1540 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1542 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1543 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1544 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1547 port_num = hildon_number_editor_get_value (
1548 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1549 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1550 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1552 g_free (outgoing_account_name);
1555 /* Set the changed account title last, to simplify the previous code: */
1556 gchar* account_title = get_entered_account_title (dialog);
1558 return FALSE; /* Should be prevented already anyway. */
1560 if (strcmp(account_title, account_name) != 0) {
1561 /* Change the title: */
1562 const gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1563 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1565 g_free (account_title);
1570 g_free (account_title);
1571 account_title = NULL;
1573 /* Save connection-specific SMTP server accounts: */
1574 modest_account_mgr_set_use_connection_specific_smtp(dialog->account_manager, account_name,
1575 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbox_outgoing_smtp_specific)));
1576 if (dialog->specific_window) {
1577 return modest_connection_specific_smtp_window_save_server_accounts (
1578 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1584 static gboolean entry_is_empty (GtkWidget *entry)
1589 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1590 if ((!text) || (strlen(text) == 0))
1593 /* Strip it of whitespace at the start and end: */
1594 gchar *stripped = g_strdup (text);
1595 stripped = g_strstrip (stripped);
1600 const gboolean result = (strlen (stripped) == 0);
1608 enable_buttons (ModestAccountSettingsDialog *self)
1610 gboolean enable_ok = TRUE;
1612 /* The account details title is mandatory: */
1613 if (entry_is_empty(self->entry_account_title))
1616 /* The user details username is mandatory: */
1617 if (entry_is_empty(self->entry_user_username))
1620 /* The user details email address is mandatory: */
1621 if (enable_ok && entry_is_empty (self->entry_user_email))
1624 /* The custom incoming server is mandatory: */
1625 if (entry_is_empty(self->entry_incomingserver))
1628 /* Enable the buttons,
1629 * identifying them via their associated response codes:
1631 GtkDialog *dialog_base = GTK_DIALOG (self);
1632 gtk_dialog_set_response_sensitive (dialog_base,
1638 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1640 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1641 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1644 object_class->get_property = modest_account_settings_dialog_get_property;
1645 object_class->set_property = modest_account_settings_dialog_set_property;
1646 object_class->dispose = modest_account_settings_dialog_dispose;
1647 object_class->finalize = modest_account_settings_dialog_finalize;
1651 show_error (GtkWidget *parent_widget, const gchar* text)
1653 hildon_banner_show_information(parent_widget, NULL, text);
1656 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_widget, text);
1658 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1665 gtk_dialog_run (dialog);
1666 gtk_widget_destroy (GTK_WIDGET (dialog));