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: */
70 #define PORT_MAX 65535
72 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
74 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
75 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
77 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
79 struct _ModestAccountSettingsDialogPrivate
84 enable_buttons (ModestAccountSettingsDialog *self);
87 save_configuration (ModestAccountSettingsDialog *dialog);
90 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
91 GValue *value, GParamSpec *pspec)
93 switch (property_id) {
95 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
100 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
101 const GValue *value, GParamSpec *pspec)
103 switch (property_id) {
105 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
110 modest_account_settings_dialog_dispose (GObject *object)
112 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
113 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
117 modest_account_settings_dialog_finalize (GObject *object)
119 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
121 if (self->account_name)
122 g_free (self->account_name);
124 if (self->original_account_title)
125 g_free (self->original_account_title);
127 if (self->account_manager)
128 g_object_unref (G_OBJECT (self->account_manager));
130 if (self->specific_window)
131 gtk_widget_destroy (self->specific_window);
133 if (self->signature_dialog)
134 gtk_widget_destroy (self->signature_dialog);
136 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
140 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
143 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
146 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
148 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
149 self->modified = TRUE;
153 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
155 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
156 self->modified = TRUE;
160 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
162 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
163 self->modified = TRUE;
167 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
169 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
170 self->modified = TRUE;
174 on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
176 ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
177 gint value = hildon_number_editor_get_value (editor);
179 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
182 /* Set a modified boolean whenever the widget is changed,
183 * so we can check for it later.
186 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
188 if (HILDON_IS_NUMBER_EDITOR (widget)) {
189 g_signal_connect (G_OBJECT (widget), "notify::value",
190 G_CALLBACK (on_modified_number_editor_changed), self);
191 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
193 else if (GTK_IS_ENTRY (widget)) {
194 g_signal_connect (G_OBJECT (widget), "changed",
195 G_CALLBACK (on_modified_entry_changed), self);
196 } else if (GTK_IS_COMBO_BOX (widget)) {
197 g_signal_connect (G_OBJECT (widget), "changed",
198 G_CALLBACK (on_modified_combobox_changed), self);
199 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
200 g_signal_connect (G_OBJECT (widget), "toggled",
201 G_CALLBACK (on_modified_checkbox_toggled), self);
206 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
208 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
210 enable_buttons(self);
214 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
216 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
218 enable_buttons(self);
221 /** This is a convenience function to create a caption containing a mandatory widget.
222 * When the widget is edited, the enable_buttons() vfunc will be called.
224 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
229 HildonCaptionStatus flag)
231 GtkWidget *caption = NULL;
233 /* Note: Previously, the translated strings already contained the "*",
234 * Comment out this code if they do again.
236 /* Add a * character to indicate mandatory fields,
237 * as specified in our "Email UI Specification": */
238 if (flag == HILDON_CAPTION_MANDATORY) {
239 gchar* title = g_strdup_printf("%s*", value);
240 caption = hildon_caption_new (group, title, control, icon, flag);
244 caption = hildon_caption_new (group, value, control, icon, flag);
246 /* Connect to the appropriate changed signal for the widget,
247 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
249 if (GTK_IS_ENTRY (control)) {
250 g_signal_connect (G_OBJECT (control), "changed",
251 G_CALLBACK (on_caption_entry_changed), self);
254 else if (GTK_IS_COMBO_BOX (control)) {
255 g_signal_connect (G_OBJECT (control), "changed",
256 G_CALLBACK (on_caption_combobox_changed), self);
263 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
267 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
268 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
270 hildon_banner_show_information(GTK_WIDGET (self), NULL, msg);
277 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
281 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
282 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
284 hildon_banner_show_information(GTK_WIDGET (self), NULL, msg);
292 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
294 hildon_banner_show_information(GTK_WIDGET (self), NULL,
295 _CS("ckdg_ib_maximum_characters_reached"));
299 create_page_account_details (ModestAccountSettingsDialog *self)
301 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
302 GtkAdjustment *focus_adjustment = NULL;
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);
308 GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
309 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
310 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
312 /* The description widgets: */
313 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
314 /* Do use auto-capitalization: */
315 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
316 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
317 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
318 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
319 gtk_widget_show (self->entry_account_title);
320 connect_for_modified (self, self->entry_account_title);
321 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
322 gtk_widget_show (caption);
324 /* Prevent the use of some characters in the account title,
325 * as required by our UI specification: */
326 GList *list_prevent = NULL;
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 list_prevent = g_list_append (list_prevent, ">");
335 list_prevent = g_list_append (list_prevent, "|");
336 list_prevent = g_list_append (list_prevent, "^");
337 modest_validating_entry_set_unallowed_characters (
338 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
339 g_list_free (list_prevent);
340 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
341 on_entry_invalid_account_title_character, self);
343 /* Set max length as in the UI spec:
344 * The UI spec seems to want us to show a dialog if we hit the maximum. */
345 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
346 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
349 /* The retrieve combobox: */
350 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
351 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
352 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
353 gtk_widget_show (self->combo_retrieve);
354 connect_for_modified (self, self->combo_retrieve);
355 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
356 gtk_widget_show (caption);
358 /* The limit-retrieve combobox: */
359 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
360 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
361 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
362 gtk_widget_show (self->combo_limit_retrieve);
363 connect_for_modified (self, self->combo_limit_retrieve);
364 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
365 gtk_widget_show (caption);
367 /* The leave-messages widgets: */
368 if(!self->checkbox_leave_messages)
369 self->checkbox_leave_messages = gtk_check_button_new ();
370 if (!self->caption_leave_messages) {
371 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
372 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
375 gtk_widget_show (self->checkbox_leave_messages);
376 connect_for_modified (self, self->checkbox_leave_messages);
377 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
378 gtk_widget_show (self->caption_leave_messages);
380 gtk_widget_show (GTK_WIDGET (box));
382 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
383 gtk_widget_show (scrollwin);
385 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
386 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
388 return GTK_WIDGET (scrollwin);
392 get_entered_account_title (ModestAccountSettingsDialog *dialog)
394 const gchar* account_title =
395 gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
396 if (!account_title || (strlen (account_title) == 0))
399 /* Strip it of whitespace at the start and end: */
400 gchar *result = g_strdup (account_title);
401 result = g_strstrip (result);
406 if (strlen (result) == 0) {
417 on_button_signature (GtkButton *button, gpointer user_data)
419 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
421 /* Create the window, if necessary: */
422 if (!(self->signature_dialog)) {
423 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
425 gboolean use_signature = FALSE;
426 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
428 gchar* account_title = get_entered_account_title (self);
429 modest_signature_editor_dialog_set_settings (
430 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
431 use_signature, signature, account_title);
433 g_free (account_title);
434 account_title = NULL;
439 /* Show the window: */
440 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
441 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
442 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
443 gtk_widget_hide (self->signature_dialog);
444 if (response != GTK_RESPONSE_OK) {
445 /* Destroy the widget now, and its data: */
446 gtk_widget_destroy (self->signature_dialog);
447 self->signature_dialog = NULL;
450 /* Mark modified, so we use the dialog's data later: */
451 self->modified = TRUE;
456 create_page_user_details (ModestAccountSettingsDialog *self)
458 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
459 GtkAdjustment *focus_adjustment = NULL;
461 /* Create a size group to be used by all captions.
462 * Note that HildonCaption does not create a default size group if we do not specify one.
463 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
464 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
465 GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
466 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
467 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
469 /* The name widgets: */
470 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
472 /* Auto-capitalization is the default, so let's turn it off: */
473 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
474 /* Set max length as in the UI spec:
475 * The UI spec seems to want us to show a dialog if we hit the maximum. */
476 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
477 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
479 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
480 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
481 gtk_widget_show (self->entry_user_name);
482 connect_for_modified (self, self->entry_user_name);
483 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
484 gtk_widget_show (caption);
487 /* Prevent the use of some characters in the name,
488 * as required by our UI specification: */
489 GList *list_prevent = NULL;
490 list_prevent = g_list_append (list_prevent, "<");
491 list_prevent = g_list_append (list_prevent, ">");
492 modest_validating_entry_set_unallowed_characters (
493 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
494 g_list_free (list_prevent);
495 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
496 on_entry_invalid_fullname_character, self);
498 /* The username widgets: */
499 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
500 /* Auto-capitalization is the default, so let's turn it off: */
501 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
502 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
503 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
504 gtk_widget_show (self->entry_user_username);
505 connect_for_modified (self, self->entry_user_username);
506 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
507 gtk_widget_show (caption);
509 /* Prevent the use of some characters in the username,
510 * as required by our UI specification: */
511 modest_validating_entry_set_unallowed_characters_whitespace (
512 MODEST_VALIDATING_ENTRY (self->entry_user_username));
514 /* Set max length as in the UI spec:
515 * The UI spec seems to want us to show a dialog if we hit the maximum. */
516 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
517 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
520 /* The password widgets: */
521 self->entry_user_password = gtk_entry_new ();
522 /* Auto-capitalization is the default, so let's turn it off: */
523 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
524 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
525 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
526 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
527 caption = create_caption_new_with_asterisk (self, sizegroup,
528 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
529 gtk_widget_show (self->entry_user_password);
530 connect_for_modified (self, self->entry_user_password);
531 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
532 gtk_widget_show (caption);
534 /* The email address widgets: */
535 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
536 /* Auto-capitalization is the default, so let's turn it off: */
537 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
538 caption = create_caption_new_with_asterisk (self, sizegroup,
539 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
540 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
541 gtk_widget_show (self->entry_user_email);
542 connect_for_modified (self, self->entry_user_email);
543 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
544 gtk_widget_show (caption);
546 /* Set max length as in the UI spec:
547 * The UI spec seems to want us to show a dialog if we hit the maximum. */
548 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
549 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
552 /* Signature button: */
553 if (!self->button_signature)
554 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
555 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
556 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
557 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
558 gtk_widget_show (self->button_signature);
559 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
560 gtk_widget_show (caption);
562 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
563 G_CALLBACK (on_button_signature), self);
565 gtk_widget_show (GTK_WIDGET (box));
566 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
567 gtk_widget_show (scrollwin);
569 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
570 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
572 return GTK_WIDGET (scrollwin);
575 /** Change the caption title for the incoming server,
576 * as specified in the UI spec:
578 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
581 (protocol == MODEST_PROTOCOL_STORE_POP ?
582 _("mail_fi_emailtype_pop3") :
583 _("mail_fi_emailtype_imap") );
586 /* Note that this produces a compiler warning,
587 * because the compiler does not know that the translated string will have a %s in it.
588 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
589 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
591 /* This is a mandatory field, so add a *. This is usually done by
592 * create_caption_new_with_asterisk() but we can't use that here. */
593 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
594 g_free (incomingserver_title);
596 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
597 g_free(with_asterisk);
600 /** Change the caption title for the incoming server,
601 * as specified in the UI spec:
603 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
605 /* Fill the combo with appropriately titled choices for POP or IMAP. */
606 /* The choices are the same, but the titles are different, as in the UI spec. */
607 modest_serversecurity_combo_box_fill (
608 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
611 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
613 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
615 /* Create a size group to be used by all captions.
616 * Note that HildonCaption does not create a default size group if we do not specify one.
617 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
618 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
620 /* The incoming server widgets: */
621 if(!self->entry_incomingserver)
622 self->entry_incomingserver = gtk_entry_new ();
623 /* Auto-capitalization is the default, so let's turn it off: */
624 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
626 if (self->caption_incoming)
627 gtk_widget_destroy (self->caption_incoming);
629 /* The caption title will be updated in update_incoming_server_title().
630 * so this default text will never be seen: */
631 /* (Note: Changing the title seems pointless. murrayc) */
632 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
633 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
634 gtk_widget_show (self->entry_incomingserver);
635 connect_for_modified (self, self->entry_incomingserver);
636 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
637 gtk_widget_show (self->caption_incoming);
639 /* The secure connection widgets: */
640 /* This will be filled by update_incoming_server_security_choices(). */
641 if (!self->combo_incoming_security)
642 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
643 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
644 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
645 gtk_widget_show (self->combo_incoming_security);
646 connect_for_modified (self, self->combo_incoming_security);
647 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
648 gtk_widget_show (caption);
650 /* Show a default port number when the security method changes, as per the UI spec: */
651 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
654 /* The port widgets: */
655 if (!self->entry_incoming_port)
656 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
657 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
658 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
659 gtk_widget_show (self->entry_incoming_port);
660 connect_for_modified (self, self->entry_incoming_port);
661 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
662 gtk_widget_show (caption);
664 /* The secure authentication widgets: */
665 if(!self->checkbox_incoming_auth)
666 self->checkbox_incoming_auth = gtk_check_button_new ();
667 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
668 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
669 gtk_widget_show (self->checkbox_incoming_auth);
670 connect_for_modified (self, self->checkbox_incoming_auth);
671 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
672 gtk_widget_show (caption);
674 gtk_widget_show (GTK_WIDGET (box));
676 return GTK_WIDGET (box);
680 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
682 GtkWidget *widget = GTK_WIDGET (user_data);
684 /* Enable the widget only if the toggle button is active: */
685 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
686 gtk_widget_set_sensitive (widget, enable);
689 /* Make the sensitivity of a widget depend on a toggle button.
692 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
694 g_signal_connect (G_OBJECT (button), "toggled",
695 G_CALLBACK (on_toggle_button_changed), widget);
697 /* Set the starting sensitivity: */
698 on_toggle_button_changed (button, widget);
702 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
704 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
706 /* Create the window if necessary: */
707 if (!(self->specific_window)) {
708 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
709 modest_connection_specific_smtp_window_fill_with_connections (
710 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager);
713 /* Show the window: */
714 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
715 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
716 gtk_widget_show (self->specific_window);
717 self->modified = TRUE;
721 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
723 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
725 ModestAuthProtocol protocol_security =
726 modest_secureauth_combo_box_get_active_secureauth (
727 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
728 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
730 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
731 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
735 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
737 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
739 const gint port_number =
740 modest_serversecurity_combo_box_get_active_serversecurity_port (
741 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
743 if(port_number != 0) {
744 hildon_number_editor_set_value (
745 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
750 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
752 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
754 const gint port_number =
755 modest_serversecurity_combo_box_get_active_serversecurity_port (
756 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
758 if(port_number != 0) {
759 hildon_number_editor_set_value (
760 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
765 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
767 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
768 GtkAdjustment *focus_adjustment = NULL;
770 /* Put it all in a scrolled window, so that all widgets can be
771 * accessed even when the on-screen keyboard is visible: */
772 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
773 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
774 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
776 /* Create a size group to be used by all captions.
777 * Note that HildonCaption does not create a default size group if we do not specify one.
778 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
779 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
781 /* The outgoing server widgets: */
782 if (!self->entry_outgoingserver)
783 self->entry_outgoingserver = gtk_entry_new ();
784 /* Auto-capitalization is the default, so let's turn it off: */
785 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
786 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
787 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
788 gtk_widget_show (self->entry_outgoingserver);
789 connect_for_modified (self, self->entry_outgoingserver);
790 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
791 gtk_widget_show (caption);
793 /* The secure authentication widgets: */
794 if (!self->combo_outgoing_auth)
795 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
796 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
797 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
798 gtk_widget_show (self->combo_outgoing_auth);
799 connect_for_modified (self, self->combo_outgoing_auth);
800 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
801 gtk_widget_show (caption);
803 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
804 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
806 /* The username widgets: */
807 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
808 /* Auto-capitalization is the default, so let's turn it off: */
809 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
810 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
811 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
812 gtk_widget_show (self->entry_outgoing_username);
813 connect_for_modified (self, self->entry_outgoing_username);
814 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
815 gtk_widget_show (self->caption_outgoing_username);
817 /* Prevent the use of some characters in the username,
818 * as required by our UI specification: */
819 modest_validating_entry_set_unallowed_characters_whitespace (
820 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
822 /* Set max length as in the UI spec:
823 * The UI spec seems to want us to show a dialog if we hit the maximum. */
824 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
825 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
828 /* The password widgets: */
829 self->entry_outgoing_password = gtk_entry_new ();
830 /* Auto-capitalization is the default, so let's turn it off: */
831 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
832 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
833 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
834 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
835 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
836 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
837 gtk_widget_show (self->entry_outgoing_password);
838 connect_for_modified (self, self->entry_outgoing_password);
839 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
840 gtk_widget_show (self->caption_outgoing_password);
842 /* The secure connection widgets: */
843 /* This will be filled and set with modest_serversecurity_combo_box_fill()
844 * and modest_serversecurity_combo_box_set_active_serversecurity().
846 if (!self->combo_outgoing_security)
848 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
849 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
850 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
851 gtk_widget_show (self->combo_outgoing_security);
852 connect_for_modified (self, self->combo_outgoing_security);
853 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
854 gtk_widget_show (caption);
856 /* Show a default port number when the security method changes, as per the UI spec: */
857 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
859 /* The port widgets: */
860 if (!self->entry_outgoing_port)
861 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
862 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
863 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
864 gtk_widget_show (self->entry_outgoing_port);
865 connect_for_modified (self, self->entry_outgoing_port);
866 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
867 gtk_widget_show (caption);
869 GtkWidget *separator = gtk_hseparator_new ();
870 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
871 gtk_widget_show (separator);
873 /* connection-specific checkbox: */
874 if (!self->checkbox_outgoing_smtp_specific) {
875 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
876 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
879 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
880 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
881 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
882 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
883 gtk_widget_show (caption);
884 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
886 /* Connection-specific SMTP-Severs Edit button: */
887 if (!self->button_outgoing_smtp_servers)
888 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
889 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
890 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
891 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
892 gtk_widget_show (self->button_outgoing_smtp_servers);
893 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
894 gtk_widget_show (caption);
896 /* Only enable the button when the checkbox is checked: */
897 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
898 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
900 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
901 G_CALLBACK (on_button_outgoing_smtp_servers), self);
903 gtk_widget_show (GTK_WIDGET (box));
904 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
905 gtk_widget_show(scrollwin);
907 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
908 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
910 return GTK_WIDGET (scrollwin);
914 check_data (ModestAccountSettingsDialog *self)
916 /* Check that the title is not already in use: */
917 gchar* account_title = get_entered_account_title (self);
919 return FALSE; /* Should be prevented already anyway. */
921 if (strcmp(account_title, self->original_account_title) != 0) {
922 /* Check the changed title: */
923 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
927 /* Warn the user via a dialog: */
928 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
930 g_free (account_title);
935 g_free (account_title);
936 account_title = NULL;
938 /* Check that the email address is valid: */
939 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
940 if ((!email_address) || (strlen(email_address) == 0)) {
944 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
945 /* Warn the user via a dialog: */
946 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
948 /* Return focus to the email address entry: */
949 gtk_widget_grab_focus (self->entry_user_email);
950 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
954 /* make sure the domain name for the incoming server is valid */
955 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
956 if ((!hostname) || (strlen(hostname) == 0)) {
960 if (!modest_text_utils_validate_domain_name (hostname)) {
961 /* Warn the user via a dialog: */
962 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
964 /* Return focus to the email address entry: */
965 gtk_widget_grab_focus (self->entry_incomingserver);
966 gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
970 /* make sure the domain name for the outgoing server is valid */
971 const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
972 if ((!hostname2) || (strlen(hostname2) == 0)) {
976 if (!modest_text_utils_validate_domain_name (hostname2)) {
977 /* Warn the user via a dialog: */
978 hildon_banner_show_information (self->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
980 /* Return focus to the email address entry: */
981 gtk_widget_grab_focus (self->entry_outgoingserver);
982 gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
986 /* Find a suitable authentication method when secure authentication is desired */
988 const gint port_num = hildon_number_editor_get_value (
989 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
990 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
993 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
994 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
996 /* If we use an encrypted protocol then there is no need to encrypt the password */
997 /* I don't think this is a good assumption. It overrides the user's request. murrayc:
998 * if (!modest_protocol_info_is_secure(protocol_security_incoming)) */
1001 if (gtk_toggle_button_get_active (
1002 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
1003 GError *error = NULL;
1005 GList *list_auth_methods =
1006 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
1007 hostname, port_num, username, GTK_WINDOW (self), &error);
1008 if (list_auth_methods) {
1009 /* Use the first supported method.
1010 * TODO: Should we prioritize them, to prefer a particular one? */
1012 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
1014 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(method->data));
1015 // Allow secure methods, e.g MD5 only
1016 if (modest_protocol_info_auth_is_secure(proto))
1018 self->protocol_authentication_incoming = proto;
1022 g_list_free (list_auth_methods);
1025 if (list_auth_methods == NULL ||
1026 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
1028 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
1029 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
1030 hildon_banner_show_information(GTK_WIDGET (self), NULL,
1031 _("Could not discover supported secure authentication methods."));
1034 g_error_free(error);
1036 /* This is a nasty hack. jschmid. */
1037 /* Don't let the dialog close */
1038 /*g_signal_stop_emission_by_name (dialog, "response");*/
1049 on_response (GtkDialog *wizard_dialog,
1053 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
1054 enable_buttons (self);
1056 gboolean prevent_response = FALSE;
1058 /* Warn about unsaved changes: */
1059 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
1060 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1061 _("imum_nc_wizard_confirm_lose_changes")));
1062 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1064 const gint dialog_response = gtk_dialog_run (dialog);
1065 gtk_widget_destroy (GTK_WIDGET (dialog));
1067 if (dialog_response != GTK_RESPONSE_OK)
1068 prevent_response = TRUE;
1070 /* Check for invalid input: */
1071 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1072 prevent_response = TRUE;
1075 if (prevent_response) {
1076 /* This is a nasty hack. murrayc. */
1077 /* Don't let the dialog close */
1078 g_signal_stop_emission_by_name (wizard_dialog, "response");
1082 if (response_id == GTK_RESPONSE_OK) {
1083 /* Try to save the changes if modified (NB #59251): */
1086 const gboolean saved = save_configuration (self);
1088 /* Do not show the account-saved dialog if we are just saving this
1089 * temporarily, because from the user's point of view it will not
1090 * really be saved (saved + enabled) until later
1092 if (modest_account_mgr_get_enabled (self->account_manager,
1093 self->account_name)) {
1094 gchar *incoming_account_name = NULL, *outgoing_account_name = NULL;
1096 incoming_account_name =
1097 modest_account_mgr_get_server_account_name (self->account_manager,
1099 TNY_ACCOUNT_TYPE_STORE);
1100 outgoing_account_name =
1101 modest_account_mgr_get_server_account_name (self->account_manager,
1103 TNY_ACCOUNT_TYPE_TRANSPORT);
1105 if (incoming_account_name) {
1106 modest_account_mgr_notify_account_update (self->account_manager,
1107 incoming_account_name);
1108 g_free (incoming_account_name);
1110 if (outgoing_account_name) {
1111 modest_account_mgr_notify_account_update (self->account_manager,
1112 outgoing_account_name);
1113 g_free (outgoing_account_name);
1116 hildon_banner_show_information(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
1119 hildon_banner_show_information (NULL, NULL, _("mail_ib_setting_failed"));
1126 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
1128 /* Create the notebook to be used by the GtkDialog base class:
1129 * Each page of the notebook will be a page of the wizard: */
1130 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1132 /* Get the account manager object,
1133 * so we can check for existing accounts,
1134 * and create new accounts: */
1135 self->account_manager = modest_runtime_get_account_mgr ();
1136 g_assert (self->account_manager);
1137 g_object_ref (self->account_manager);
1139 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1141 /* Create the common pages,
1143 self->page_account_details = create_page_account_details (self);
1144 self->page_user_details = create_page_user_details (self);
1145 self->page_incoming = create_page_incoming (self);
1146 self->page_outgoing = create_page_outgoing (self);
1148 /* Add the notebook pages: */
1149 gtk_notebook_append_page (self->notebook, self->page_account_details,
1150 gtk_label_new (_("mcen_ti_account_settings_account")));
1151 gtk_notebook_append_page (self->notebook, self->page_user_details,
1152 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1153 gtk_notebook_append_page (self->notebook, self->page_incoming,
1154 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1155 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1156 gtk_label_new (_("mcen_ti_advsetup_sending")));
1158 GtkDialog *dialog = GTK_DIALOG (self);
1159 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1160 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1161 gtk_widget_show (GTK_WIDGET (self->notebook));
1163 /* Add the buttons: */
1164 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1165 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
1167 /* Connect to the dialog's response signal: */
1168 /* We use connect-before
1169 * so we can stop the signal emission,
1170 * to stop the default signal handler from closing the dialog.
1172 g_signal_connect (G_OBJECT (self), "response",
1173 G_CALLBACK (on_response), self);
1175 self->modified = FALSE;
1177 /* When this window is shown, hibernation should not be possible,
1178 * because there is no sensible way to save the state: */
1179 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1180 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1182 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1183 modest_maemo_utils_get_osso_context());
1186 ModestAccountSettingsDialog*
1187 modest_account_settings_dialog_new (void)
1189 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1192 /** Update the UI with the stored account details, so they can be edited.
1193 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1195 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1200 /* Save the account name so we can refer to it later: */
1201 if (dialog->account_name)
1202 g_free (dialog->account_name);
1203 dialog->account_name = g_strdup (account_name);
1206 /* Get the account data for this account name: */
1207 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1209 if (!account_data) {
1210 g_printerr ("modest: failed to get account data for %s\n", account_name);
1214 /* Save the account title so we can refer to it if the user changes it: */
1215 if (dialog->original_account_title)
1216 g_free (dialog->original_account_title);
1217 dialog->original_account_title = g_strdup (account_data->display_name);
1220 if (!(account_data->store_account)) {
1221 g_printerr ("modest: account has no stores: %s\n", account_name);
1225 /* Show the account data in the widgets: */
1227 /* Note that we never show the non-display name in the UI.
1228 * (Though the display name defaults to the non-display name at the start.) */
1229 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1230 account_data->display_name ? account_data->display_name : "");
1232 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1233 account_data->fullname ? account_data->fullname : "");
1234 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1235 account_data->email ? account_data->email : "");
1237 ModestServerAccountData *incoming_account = account_data->store_account;
1239 if (incoming_account)
1240 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1243 gchar *retrieve = modest_account_mgr_get_retrieve_type (dialog->account_manager, account_name);
1245 /* Default to something, though no default is specified in the UI spec: */
1246 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1248 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1251 const gint limit_retrieve = modest_account_mgr_get_retrieve_limit (dialog->account_manager, account_name);
1252 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1255 const gboolean leave_on_server = modest_account_mgr_get_leave_on_server (dialog->account_manager, account_name);
1256 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1258 /* Only show the leave-on-server checkbox for POP,
1259 * as per the UI spec: */
1260 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1261 gtk_widget_hide (dialog->caption_leave_messages);
1263 gtk_widget_show (dialog->caption_leave_messages);
1266 update_incoming_server_security_choices (dialog, incoming_account->proto);
1267 if (incoming_account) {
1268 /* Remember this for later: */
1269 dialog->incoming_protocol = incoming_account->proto;
1271 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1272 incoming_account->username ? incoming_account->username : "");
1273 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1274 incoming_account->password ? incoming_account->password : "");
1276 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1277 incoming_account->hostname ? incoming_account->hostname : "");
1279 /* The UI spec says:
1280 * If secure authentication is unchecked, allow sending username and password also as plain text.
1281 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1282 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1284 const ModestConnectionProtocol security = modest_account_mgr_get_server_account_security (
1285 dialog->account_manager, incoming_account->account_name);
1286 modest_serversecurity_combo_box_set_active_serversecurity (
1287 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1292 - use encrypted passwords
1294 const ModestAuthProtocol secure_auth = modest_account_mgr_get_server_account_secure_auth(
1295 dialog->account_manager, incoming_account->account_name);
1296 dialog->protocol_authentication_incoming = secure_auth;
1297 if (modest_protocol_info_auth_is_secure(secure_auth))
1299 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1304 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1308 update_incoming_server_title (dialog, incoming_account->proto);
1310 const gint port_num = modest_account_mgr_get_server_account_port (dialog->account_manager,
1311 incoming_account->account_name);
1312 if (port_num == 0) {
1313 /* Show the appropriate port number: */
1314 on_combo_incoming_security_changed (
1315 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1317 /* Keep the user-entered port-number,
1318 * or the already-appropriate automatic port number: */
1319 hildon_number_editor_set_value (
1320 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1324 ModestServerAccountData *outgoing_account = account_data->transport_account;
1325 if (outgoing_account) {
1326 /* Remember this for later: */
1327 dialog->outgoing_protocol = outgoing_account->proto;
1329 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1330 outgoing_account->hostname ? outgoing_account->hostname : "");
1332 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1333 outgoing_account->username ? outgoing_account->username : "");
1334 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1335 outgoing_account->password ? outgoing_account->password : "");
1337 /* Get the secure-auth setting: */
1338 const ModestAuthProtocol secure_auth = modest_account_mgr_get_server_account_secure_auth(
1339 dialog->account_manager, outgoing_account->account_name);
1340 modest_secureauth_combo_box_set_active_secureauth (
1341 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1342 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1344 modest_serversecurity_combo_box_fill (
1345 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1347 /* Get the security setting: */
1348 const ModestConnectionProtocol security = modest_account_mgr_get_server_account_security (
1349 dialog->account_manager, outgoing_account->account_name);
1350 modest_serversecurity_combo_box_set_active_serversecurity (
1351 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1353 const gint port_num = modest_account_mgr_get_server_account_port (dialog->account_manager,
1354 outgoing_account->account_name);
1355 if (port_num == 0) {
1356 /* Show the appropriate port number: */
1357 on_combo_outgoing_security_changed (
1358 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1361 /* Keep the user-entered port-number,
1362 * or the already-appropriate automatic port number: */
1363 hildon_number_editor_set_value (
1364 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1367 const gboolean has_specific =
1368 modest_account_mgr_get_use_connection_specific_smtp (
1369 dialog->account_manager, account_name);
1370 gtk_toggle_button_set_active (
1371 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1375 /* Set window title according to account: */
1376 /* TODO: Is this the correct way to find a human-readable name for
1377 * the protocol used? */
1378 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1379 gchar *proto_name = g_utf8_strup(proto_str, -1);
1380 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1382 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1383 g_free (proto_name);
1384 g_free (account_title);
1386 gtk_window_set_title (GTK_WINDOW (dialog), title);
1389 /* account_data->is_enabled, */
1390 /*account_data->is_default, */
1392 /* account_data->store_account->proto */
1394 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1396 /* Unset the modified flag so we can detect changes later: */
1397 dialog->modified = FALSE;
1400 /** Show the User Info tab.
1402 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1404 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1405 if (page_num == -1) {
1406 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1409 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1410 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1412 gtk_widget_show (dialog->page_user_details);
1413 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1414 gtk_widget_show (GTK_WIDGET (dialog));
1415 gtk_notebook_set_current_page (dialog->notebook, page_num);
1419 save_configuration (ModestAccountSettingsDialog *dialog)
1421 g_assert (dialog->account_name);
1423 const gchar* account_name = dialog->account_name;
1425 /* Set the account data from the widgets: */
1426 const gchar* user_fullname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1427 modest_account_mgr_set_user_fullname (dialog->account_manager,
1431 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1432 modest_account_mgr_set_user_email (dialog->account_manager, account_name,
1436 if (dialog->signature_dialog) {
1437 gboolean use_signature = FALSE;
1439 modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1442 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1443 signature, use_signature);
1447 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1448 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1449 modest_account_mgr_set_retrieve_type (dialog->account_manager, account_name, (const gchar*) retrieve);
1452 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1453 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1454 modest_account_mgr_set_retrieve_limit (dialog->account_manager, account_name, limit_retrieve);
1456 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1457 modest_account_mgr_set_leave_on_server (dialog->account_manager, account_name, leave_on_server);
1460 gchar* incoming_account_name =
1461 modest_account_mgr_get_server_account_name (dialog->account_manager,
1463 TNY_ACCOUNT_TYPE_STORE);
1464 g_assert (incoming_account_name);
1466 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1467 modest_account_mgr_set_server_account_hostname (dialog->account_manager, incoming_account_name, hostname);
1469 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1470 modest_account_mgr_set_server_account_username (dialog->account_manager, incoming_account_name, username);
1472 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1473 modest_account_mgr_set_server_account_password (dialog->account_manager, incoming_account_name,
1477 gint port_num = hildon_number_editor_get_value (
1478 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1479 modest_account_mgr_set_server_account_port (dialog->account_manager, incoming_account_name, port_num);
1481 /* The UI spec says:
1482 * If secure authentication is unchecked, allow sending username and password also as plain text.
1483 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1486 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1487 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1488 modest_account_mgr_set_server_account_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1490 modest_account_mgr_set_server_account_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1493 g_free (incoming_account_name);
1496 gchar* outgoing_account_name =
1497 modest_account_mgr_get_server_account_name (dialog->account_manager,
1499 TNY_ACCOUNT_TYPE_TRANSPORT);
1500 g_assert (outgoing_account_name);
1502 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1503 modest_account_mgr_set_server_account_hostname (dialog->account_manager, outgoing_account_name, hostname);
1505 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1506 modest_account_mgr_set_server_account_username (dialog->account_manager, outgoing_account_name,
1509 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1510 modest_account_mgr_set_server_account_password (dialog->account_manager, outgoing_account_name,
1513 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1514 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1515 modest_account_mgr_set_server_account_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1517 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1518 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1519 modest_account_mgr_set_server_account_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1522 port_num = hildon_number_editor_get_value (
1523 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1524 modest_account_mgr_set_server_account_port (dialog->account_manager,
1525 outgoing_account_name,
1527 g_free (outgoing_account_name);
1530 /* Set the changed account title last, to simplify the previous code: */
1531 gchar* account_title = get_entered_account_title (dialog);
1533 return FALSE; /* Should be prevented already anyway. */
1535 /* if (strcmp (account_title, account_name) != 0) { */
1536 modest_account_mgr_set_display_name (dialog->account_manager, account_name, account_title);
1538 g_free (account_title);
1539 account_title = NULL;
1541 /* Save connection-specific SMTP server accounts: */
1542 modest_account_mgr_set_use_connection_specific_smtp(dialog->account_manager, account_name,
1543 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->checkbox_outgoing_smtp_specific)));
1544 if (dialog->specific_window) {
1545 return modest_connection_specific_smtp_window_save_server_accounts (
1546 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window));
1552 static gboolean entry_is_empty (GtkWidget *entry)
1557 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1558 if ((!text) || (strlen(text) == 0))
1561 /* Strip it of whitespace at the start and end: */
1562 gchar *stripped = g_strdup (text);
1563 stripped = g_strstrip (stripped);
1568 const gboolean result = (strlen (stripped) == 0);
1576 enable_buttons (ModestAccountSettingsDialog *self)
1578 gboolean enable_ok = TRUE;
1580 /* The account details title is mandatory: */
1581 if (entry_is_empty(self->entry_account_title))
1584 /* The user details username is mandatory: */
1585 if (entry_is_empty(self->entry_user_username))
1588 /* The user details email address is mandatory: */
1589 if (enable_ok && entry_is_empty (self->entry_user_email))
1592 /* The custom incoming server is mandatory: */
1593 if (entry_is_empty(self->entry_incomingserver))
1596 /* Enable the buttons,
1597 * identifying them via their associated response codes:
1599 GtkDialog *dialog_base = GTK_DIALOG (self);
1600 gtk_dialog_set_response_sensitive (dialog_base,
1606 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1608 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1609 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1612 object_class->get_property = modest_account_settings_dialog_get_property;
1613 object_class->set_property = modest_account_settings_dialog_set_property;
1614 object_class->dispose = modest_account_settings_dialog_dispose;
1615 object_class->finalize = modest_account_settings_dialog_finalize;