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"
74 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
76 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
77 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
79 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
81 struct _ModestAccountSettingsDialogPrivate
86 enable_buttons (ModestAccountSettingsDialog *self);
89 save_configuration (ModestAccountSettingsDialog *dialog);
92 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
93 GValue *value, GParamSpec *pspec)
95 switch (property_id) {
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
102 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
103 const GValue *value, GParamSpec *pspec)
105 switch (property_id) {
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
112 modest_account_settings_dialog_dispose (GObject *object)
114 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
115 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
119 modest_account_settings_dialog_finalize (GObject *object)
121 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
123 if (self->account_name)
124 g_free (self->account_name);
126 if (self->original_account_title)
127 g_free (self->original_account_title);
129 if (self->account_manager)
130 g_object_unref (G_OBJECT (self->account_manager));
132 if (self->specific_window)
133 gtk_widget_destroy (self->specific_window);
135 if (self->signature_dialog)
136 gtk_widget_destroy (self->signature_dialog);
138 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
142 show_error (GtkWidget *parent_widget, const gchar* text);
145 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
148 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
151 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
153 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
154 self->modified = TRUE;
158 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
160 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
161 self->modified = TRUE;
165 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
167 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
168 self->modified = TRUE;
172 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
174 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
175 self->modified = TRUE;
178 /* Set a modified boolean whenever the widget is changed,
179 * so we can check for it later.
182 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
184 if (HILDON_IS_NUMBER_EDITOR (widget)) {
185 g_signal_connect (G_OBJECT (widget), "notify::value",
186 G_CALLBACK (on_modified_number_editor_changed), self);
188 else if (GTK_IS_ENTRY (widget)) {
189 g_signal_connect (G_OBJECT (widget), "changed",
190 G_CALLBACK (on_modified_entry_changed), self);
191 } else if (GTK_IS_COMBO_BOX (widget)) {
192 g_signal_connect (G_OBJECT (widget), "changed",
193 G_CALLBACK (on_modified_combobox_changed), self);
194 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
195 g_signal_connect (G_OBJECT (widget), "toggled",
196 G_CALLBACK (on_modified_checkbox_toggled), self);
201 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
203 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
205 enable_buttons(self);
209 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
211 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
213 enable_buttons(self);
216 /** This is a convenience function to create a caption containing a mandatory widget.
217 * When the widget is edited, the enable_buttons() vfunc will be called.
219 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
224 HildonCaptionStatus flag)
226 GtkWidget *caption = NULL;
228 /* Note: Previously, the translated strings already contained the "*",
229 * Comment out this code if they do again.
231 /* Add a * character to indicate mandatory fields,
232 * as specified in our "Email UI Specification": */
233 if (flag == HILDON_CAPTION_MANDATORY) {
234 gchar* title = g_strdup_printf("%s*", value);
235 caption = hildon_caption_new (group, title, control, icon, flag);
239 caption = hildon_caption_new (group, value, control, icon, flag);
241 /* Connect to the appropriate changed signal for the widget,
242 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
244 if (GTK_IS_ENTRY (control)) {
245 g_signal_connect (G_OBJECT (control), "changed",
246 G_CALLBACK (on_caption_entry_changed), self);
249 else if (GTK_IS_COMBO_BOX (control)) {
250 g_signal_connect (G_OBJECT (control), "changed",
251 G_CALLBACK (on_caption_combobox_changed), self);
258 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
260 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
261 /* We could add a special case for whitespace here
262 if (character == NULL) ...
264 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
265 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), character);
266 show_error (GTK_WIDGET (self), message);
270 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
272 /* ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data); */
273 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
277 create_page_account_details (ModestAccountSettingsDialog *self)
279 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
280 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
281 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
282 gtk_widget_show (label);
284 /* Create a size group to be used by all captions.
285 * Note that HildonCaption does not create a default size group if we do not specify one.
286 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
287 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
289 /* The description widgets: */
290 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
291 /* Do use auto-capitalization: */
292 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
293 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
294 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
295 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
296 gtk_widget_show (self->entry_account_title);
297 connect_for_modified (self, self->entry_account_title);
298 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
299 gtk_widget_show (caption);
301 /* Prevent the use of some characters in the account title,
302 * as required by our UI specification: */
303 GList *list_prevent = NULL;
304 list_prevent = g_list_append (list_prevent, "\\");
305 list_prevent = g_list_append (list_prevent, "/");
306 list_prevent = g_list_append (list_prevent, ":");
307 list_prevent = g_list_append (list_prevent, "*");
308 list_prevent = g_list_append (list_prevent, "?");
309 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
310 list_prevent = g_list_append (list_prevent, "“");
311 list_prevent = g_list_append (list_prevent, "<");
312 list_prevent = g_list_append (list_prevent, ">");
313 list_prevent = g_list_append (list_prevent, "|");
314 list_prevent = g_list_append (list_prevent, "^");
315 modest_validating_entry_set_unallowed_characters (
316 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
317 g_list_free (list_prevent);
318 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
319 on_entry_invalid_character, self);
321 /* Set max length as in the UI spec:
322 * The UI spec seems to want us to show a dialog if we hit the maximum. */
323 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
324 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
327 /* The retrieve combobox: */
328 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
329 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
330 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
331 gtk_widget_show (self->combo_retrieve);
332 connect_for_modified (self, self->combo_retrieve);
333 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
334 gtk_widget_show (caption);
336 /* The limit-retrieve combobox: */
337 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
338 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
339 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
340 gtk_widget_show (self->combo_limit_retrieve);
341 connect_for_modified (self, self->combo_limit_retrieve);
342 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
343 gtk_widget_show (caption);
345 /* The leave-messages widgets: */
346 if(!self->checkbox_leave_messages)
347 self->checkbox_leave_messages = gtk_check_button_new ();
348 if (!self->caption_leave_messages) {
349 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
350 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
353 gtk_widget_show (self->checkbox_leave_messages);
354 connect_for_modified (self, self->checkbox_leave_messages);
355 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
356 gtk_widget_show (self->caption_leave_messages);
358 gtk_widget_show (GTK_WIDGET (box));
360 return GTK_WIDGET (box);
364 on_button_signature (GtkButton *button, gpointer user_data)
366 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
368 /* Create the window, if necessary: */
369 if (!(self->signature_dialog)) {
370 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
372 gboolean use_signature = FALSE;
373 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
375 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
376 modest_signature_editor_dialog_set_settings (
377 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
378 use_signature, signature, account_title);
383 /* Show the window: */
384 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
385 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
386 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
387 gtk_widget_hide (self->signature_dialog);
388 if (response != GTK_RESPONSE_OK) {
389 /* Destroy the widget now, and its data: */
390 gtk_widget_destroy (self->signature_dialog);
391 self->signature_dialog = NULL;
394 /* Mark modified, so we use the dialog's data later: */
395 self->modified = TRUE;
400 create_page_user_details (ModestAccountSettingsDialog *self)
402 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
403 GtkAdjustment *focus_adjustment = NULL;
405 /* Create a size group to be used by all captions.
406 * Note that HildonCaption does not create a default size group if we do not specify one.
407 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
408 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
409 GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
410 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
411 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
413 /* The name widgets: */
414 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
415 /* Auto-capitalization is the default, so let's turn it off: */
416 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
417 /* Set max length as in the UI spec:
418 * The UI spec seems to want us to show a dialog if we hit the maximum. */
419 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
420 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
422 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
423 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
424 gtk_widget_show (self->entry_user_name);
425 connect_for_modified (self, self->entry_user_name);
426 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
427 gtk_widget_show (caption);
429 /* Prevent the use of some characters in the name,
430 * as required by our UI specification: */
431 GList *list_prevent = NULL;
432 list_prevent = g_list_append (list_prevent, "<");
433 list_prevent = g_list_append (list_prevent, ">");
434 modest_validating_entry_set_unallowed_characters (
435 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
436 g_list_free (list_prevent);
438 /* The username widgets: */
439 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
440 /* Auto-capitalization is the default, so let's turn it off: */
441 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
442 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
443 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
444 gtk_widget_show (self->entry_user_username);
445 connect_for_modified (self, self->entry_user_username);
446 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
447 gtk_widget_show (caption);
449 /* Prevent the use of some characters in the username,
450 * as required by our UI specification: */
451 modest_validating_entry_set_unallowed_characters_whitespace (
452 MODEST_VALIDATING_ENTRY (self->entry_user_username));
454 /* Set max length as in the UI spec:
455 * The UI spec seems to want us to show a dialog if we hit the maximum. */
456 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
457 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
460 /* The password widgets: */
461 self->entry_user_password = gtk_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_password),
464 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
465 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
466 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
467 caption = create_caption_new_with_asterisk (self, sizegroup,
468 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
469 gtk_widget_show (self->entry_user_password);
470 connect_for_modified (self, self->entry_user_password);
471 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
472 gtk_widget_show (caption);
474 /* The email address widgets: */
475 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
476 /* Auto-capitalization is the default, so let's turn it off: */
477 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
478 caption = create_caption_new_with_asterisk (self, sizegroup,
479 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
480 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
481 gtk_widget_show (self->entry_user_email);
482 connect_for_modified (self, self->entry_user_email);
483 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
484 gtk_widget_show (caption);
486 /* Set max length as in the UI spec:
487 * The UI spec seems to want us to show a dialog if we hit the maximum. */
488 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
489 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
492 /* Signature button: */
493 if (!self->button_signature)
494 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
495 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
496 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
497 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
498 gtk_widget_show (self->button_signature);
499 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
500 gtk_widget_show (caption);
502 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
503 G_CALLBACK (on_button_signature), self);
505 gtk_widget_show (GTK_WIDGET (box));
506 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
507 gtk_widget_show (scrollwin);
509 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
510 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
512 return GTK_WIDGET (scrollwin);
515 /** Change the caption title for the incoming server,
516 * as specified in the UI spec:
518 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
521 (protocol == MODEST_PROTOCOL_STORE_POP ?
522 _("mail_fi_emailtype_pop3") :
523 _("mail_fi_emailtype_imap") );
526 /* Note that this produces a compiler warning,
527 * because the compiler does not know that the translated string will have a %s in it.
528 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
529 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
531 /* This is a mandatory field, so add a *. This is usually done by
532 * create_caption_new_with_asterisk() but we can't use that here. */
533 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
534 g_free (incomingserver_title);
536 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
537 g_free(with_asterisk);
540 /** Change the caption title for the incoming server,
541 * as specified in the UI spec:
543 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
545 /* Fill the combo with appropriately titled choices for POP or IMAP. */
546 /* The choices are the same, but the titles are different, as in the UI spec. */
547 modest_serversecurity_combo_box_fill (
548 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
551 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
553 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
555 /* Create a size group to be used by all captions.
556 * Note that HildonCaption does not create a default size group if we do not specify one.
557 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
558 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
560 /* The incoming server widgets: */
561 if(!self->entry_incomingserver)
562 self->entry_incomingserver = gtk_entry_new ();
563 /* Auto-capitalization is the default, so let's turn it off: */
564 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
566 if (self->caption_incoming)
567 gtk_widget_destroy (self->caption_incoming);
569 /* The caption title will be updated in update_incoming_server_title().
570 * so this default text will never be seen: */
571 /* (Note: Changing the title seems pointless. murrayc) */
572 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
573 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
574 gtk_widget_show (self->entry_incomingserver);
575 connect_for_modified (self, self->entry_incomingserver);
576 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
577 gtk_widget_show (self->caption_incoming);
579 /* The secure connection widgets: */
580 /* This will be filled by update_incoming_server_security_choices(). */
581 if (!self->combo_incoming_security)
582 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
583 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
584 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
585 gtk_widget_show (self->combo_incoming_security);
586 connect_for_modified (self, self->combo_incoming_security);
587 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
588 gtk_widget_show (caption);
590 /* Show a default port number when the security method changes, as per the UI spec: */
591 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
594 /* The port widgets: */
595 /* TODO: There are various rules about this in the UI spec. */
596 if (!self->entry_incoming_port)
597 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (1, 65535));
598 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
599 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
600 gtk_widget_show (self->entry_incoming_port);
601 connect_for_modified (self, self->entry_incoming_port);
602 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
603 gtk_widget_show (caption);
605 /* The secure authentication widgets: */
606 if(!self->checkbox_incoming_auth)
607 self->checkbox_incoming_auth = gtk_check_button_new ();
608 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
609 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
610 gtk_widget_show (self->checkbox_incoming_auth);
611 connect_for_modified (self, self->checkbox_incoming_auth);
612 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
613 gtk_widget_show (caption);
615 gtk_widget_show (GTK_WIDGET (box));
617 return GTK_WIDGET (box);
621 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
623 GtkWidget *widget = GTK_WIDGET (user_data);
625 /* Enable the widget only if the toggle button is active: */
626 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
627 gtk_widget_set_sensitive (widget, enable);
630 /* Make the sensitivity of a widget depend on a toggle button.
633 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
635 g_signal_connect (G_OBJECT (button), "toggled",
636 G_CALLBACK (on_toggle_button_changed), widget);
638 /* Set the starting sensitivity: */
639 on_toggle_button_changed (button, widget);
643 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
645 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
647 /* Create the window if necessary: */
648 if (!(self->specific_window)) {
649 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
650 modest_connection_specific_smtp_window_fill_with_connections (
651 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
655 /* Show the window: */
656 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
657 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
658 gtk_widget_show (self->specific_window);
662 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
664 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
666 ModestAuthProtocol protocol_security =
667 modest_secureauth_combo_box_get_active_secureauth (
668 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
669 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
671 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
672 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
676 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
678 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
680 const gint port_number =
681 modest_serversecurity_combo_box_get_active_serversecurity_port (
682 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
684 if(port_number != 0) {
685 hildon_number_editor_set_value (
686 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
691 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
693 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
695 const gint port_number =
696 modest_serversecurity_combo_box_get_active_serversecurity_port (
697 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
699 if(port_number != 0) {
700 hildon_number_editor_set_value (
701 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
706 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
708 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
709 GtkAdjustment *focus_adjustment = NULL;
711 /* Put it all in a scrolled window, so that all widgets can be
712 * accessed even when the on-screen keyboard is visible: */
713 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
714 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
715 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
717 /* Create a size group to be used by all captions.
718 * Note that HildonCaption does not create a default size group if we do not specify one.
719 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
720 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
722 /* The outgoing server widgets: */
723 if (!self->entry_outgoingserver)
724 self->entry_outgoingserver = gtk_entry_new ();
725 /* Auto-capitalization is the default, so let's turn it off: */
726 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
727 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
728 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
729 gtk_widget_show (self->entry_outgoingserver);
730 connect_for_modified (self, self->entry_outgoingserver);
731 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
732 gtk_widget_show (caption);
734 /* The secure authentication widgets: */
735 if (!self->combo_outgoing_auth)
736 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
737 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
738 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
739 gtk_widget_show (self->combo_outgoing_auth);
740 connect_for_modified (self, self->combo_outgoing_auth);
741 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
742 gtk_widget_show (caption);
744 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
745 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
747 /* The username widgets: */
748 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
749 /* Auto-capitalization is the default, so let's turn it off: */
750 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
751 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
752 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
753 gtk_widget_show (self->entry_outgoing_username);
754 connect_for_modified (self, self->entry_outgoing_username);
755 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
756 gtk_widget_show (self->caption_outgoing_username);
758 /* Prevent the use of some characters in the username,
759 * as required by our UI specification: */
760 modest_validating_entry_set_unallowed_characters_whitespace (
761 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
763 /* Set max length as in the UI spec:
764 * The UI spec seems to want us to show a dialog if we hit the maximum. */
765 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
766 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
769 /* The password widgets: */
770 self->entry_outgoing_password = gtk_entry_new ();
771 /* Auto-capitalization is the default, so let's turn it off: */
772 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
773 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
774 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
775 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
776 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
777 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
778 gtk_widget_show (self->entry_outgoing_password);
779 connect_for_modified (self, self->entry_outgoing_password);
780 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
781 gtk_widget_show (self->caption_outgoing_password);
783 /* The secure connection widgets: */
784 /* This will be filled and set with modest_serversecurity_combo_box_fill()
785 * and modest_serversecurity_combo_box_set_active_serversecurity().
787 if (!self->combo_outgoing_security)
789 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
790 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
791 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
792 gtk_widget_show (self->combo_outgoing_security);
793 connect_for_modified (self, self->combo_outgoing_security);
794 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
795 gtk_widget_show (caption);
797 /* Show a default port number when the security method changes, as per the UI spec: */
798 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
800 /* The port widgets: */
801 if (!self->entry_outgoing_port)
802 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (1, 65535));
803 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
804 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
805 gtk_widget_show (self->entry_outgoing_port);
806 connect_for_modified (self, self->entry_outgoing_port);
807 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
808 gtk_widget_show (caption);
810 GtkWidget *separator = gtk_hseparator_new ();
811 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
812 gtk_widget_show (separator);
814 /* connection-specific checkbox: */
815 if (!self->checkbox_outgoing_smtp_specific) {
816 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
817 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
820 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
821 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
822 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
823 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
824 gtk_widget_show (caption);
825 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
827 /* Connection-specific SMTP-Severs Edit button: */
828 if (!self->button_outgoing_smtp_servers)
829 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
830 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
831 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
832 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
833 gtk_widget_show (self->button_outgoing_smtp_servers);
834 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
835 gtk_widget_show (caption);
837 /* Only enable the button when the checkbox is checked: */
838 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
839 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
841 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
842 G_CALLBACK (on_button_outgoing_smtp_servers), self);
844 gtk_widget_show (GTK_WIDGET (box));
845 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
846 gtk_widget_show(scrollwin);
848 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
849 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
851 return GTK_WIDGET (scrollwin);
855 check_data (ModestAccountSettingsDialog *self)
857 /* Check that the title is not already in use: */
858 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
859 if ((!account_title) || (strlen(account_title) == 0))
860 return FALSE; /* Should be prevented already anyway. */
862 if (strcmp(account_title, self->original_account_title) != 0) {
863 /* Check the changed title: */
864 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
868 /* Warn the user via a dialog: */
869 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
875 /* Check that the email address is valud: */
876 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
877 if ((!email_address) || (strlen(email_address) == 0))
880 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
881 /* Warn the user via a dialog: */
882 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
883 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
885 /* Return focus to the email address entry: */
886 gtk_widget_grab_focus (self->entry_user_email);
887 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
891 /* Find a suitable authentication method when secure authentication is desired */
892 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
893 gint port_num = hildon_number_editor_get_value (
894 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
895 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
897 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
898 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
900 /* If we use an encrypted protocol then there is no need to encrypt the password */
901 if (!modest_protocol_info_is_secure(protocol_security_incoming))
903 if (gtk_toggle_button_get_active (
904 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
905 GError *error = NULL;
906 GList *list_auth_methods =
907 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
908 hostname, port_num, username, GTK_WINDOW (self), &error);
909 if (list_auth_methods) {
910 /* Use the first supported method.
911 * TODO: Should we prioritize them, to prefer a particular one? */
913 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
915 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
916 // Allow secure methods, e.g MD5 only
917 if (modest_protocol_info_auth_is_secure(proto))
919 self->protocol_authentication_incoming = proto;
923 g_list_free (list_auth_methods);
926 if (list_auth_methods == NULL ||
927 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
929 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
930 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
932 show_error (GTK_WIDGET (self), _("Could not discover supported secure authentication methods."));
938 /* This is a nasty hack. jschmid. */
939 /* Don't let the dialog close */
940 /*g_signal_stop_emission_by_name (dialog, "response");*/
946 /* TODO: The UI Spec wants us to check that the servernames are valid,
947 * but does not specify how.
955 on_response (GtkDialog *wizard_dialog,
959 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
960 enable_buttons (self);
962 gboolean prevent_response = FALSE;
964 /* Warn about unsaved changes: */
965 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
966 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
967 _("imum_nc_wizard_confirm_lose_changes")));
968 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
970 const gint dialog_response = gtk_dialog_run (dialog);
971 gtk_widget_destroy (GTK_WIDGET (dialog));
973 if (dialog_response != GTK_RESPONSE_OK)
974 prevent_response = TRUE;
976 /* Check for invalid input: */
977 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
978 prevent_response = TRUE;
981 if (prevent_response) {
982 /* This is a nasty hack. murrayc. */
983 /* Don't let the dialog close */
984 g_signal_stop_emission_by_name (wizard_dialog, "response");
988 if (response_id == GTK_RESPONSE_OK) {
989 /* Try to save the changes if modified (NB #59251): */
992 const gboolean saved = save_configuration (self);
994 /* Do not show the account-saved dialog if we are just saving this
995 * temporarily, because from the user's point of view it will not
996 * really be saved (saved + enabled) until later.
998 const gboolean enabled =
999 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
1001 show_error (GTK_WIDGET (self), _("mcen_ib_advsetup_settings_saved"));
1004 show_error (GTK_WIDGET (self), _("mail_ib_setting_failed"));
1010 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
1012 /* Create the notebook to be used by the GtkDialog base class:
1013 * Each page of the notebook will be a page of the wizard: */
1014 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1016 /* Get the account manager object,
1017 * so we can check for existing accounts,
1018 * and create new accounts: */
1019 self->account_manager = modest_runtime_get_account_mgr ();
1020 g_assert (self->account_manager);
1021 g_object_ref (self->account_manager);
1023 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1025 /* Create the common pages,
1027 self->page_account_details = create_page_account_details (self);
1028 self->page_user_details = create_page_user_details (self);
1029 self->page_incoming = create_page_incoming (self);
1030 self->page_outgoing = create_page_outgoing (self);
1032 /* Add the notebook pages: */
1033 gtk_notebook_append_page (self->notebook, self->page_account_details,
1034 gtk_label_new (_("mcen_ti_account_settings_account")));
1035 gtk_notebook_append_page (self->notebook, self->page_user_details,
1036 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1037 gtk_notebook_append_page (self->notebook, self->page_incoming,
1038 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1039 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1040 gtk_label_new (_("mcen_ti_advsetup_sending")));
1042 GtkDialog *dialog = GTK_DIALOG (self);
1043 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1044 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1045 gtk_widget_show (GTK_WIDGET (self->notebook));
1047 /* Add the buttons: */
1048 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1049 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1051 /* Connect to the dialog's response signal: */
1052 /* We use connect-before
1053 * so we can stop the signal emission,
1054 * to stop the default signal handler from closing the dialog.
1056 g_signal_connect (G_OBJECT (self), "response",
1057 G_CALLBACK (on_response), self);
1059 self->modified = FALSE;
1061 /* When this window is shown, hibernation should not be possible,
1062 * because there is no sensible way to save the state: */
1063 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1064 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1067 ModestAccountSettingsDialog*
1068 modest_account_settings_dialog_new (void)
1070 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1073 /** Update the UI with the stored account details, so they can be edited.
1074 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1076 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1081 /* Save the account name so we can refer to it later: */
1082 if (dialog->account_name)
1083 g_free (dialog->account_name);
1084 dialog->account_name = g_strdup (account_name);
1087 /* Get the account data for this account name: */
1088 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1090 if (!account_data) {
1091 g_printerr ("modest: failed to get account data for %s\n", account_name);
1095 /* Save the account title so we can refer to it if the user changes it: */
1096 if (dialog->original_account_title)
1097 g_free (dialog->original_account_title);
1098 dialog->original_account_title = g_strdup (account_data->display_name);
1101 if (!(account_data->store_account)) {
1102 g_printerr ("modest: account has no stores: %s\n", account_name);
1106 /* Show the account data in the widgets: */
1108 /* Note that we never show the non-display name in the UI.
1109 * (Though the display name defaults to the non-display name at the start.) */
1110 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1111 account_data->display_name ? account_data->display_name : "");
1113 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1114 account_data->fullname ? account_data->fullname : "");
1115 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1116 account_data->email ? account_data->email : "");
1118 ModestServerAccountData *incoming_account = account_data->store_account;
1120 if (incoming_account)
1121 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1122 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1123 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1125 /* Default to something, though no default is specified in the UI spec: */
1126 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1128 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1131 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1132 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1133 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1136 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1137 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1138 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1140 /* Only show the leave-on-server checkbox for POP,
1141 * as per the UI spec: */
1142 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1143 gtk_widget_hide (dialog->caption_leave_messages);
1145 gtk_widget_show (dialog->caption_leave_messages);
1148 update_incoming_server_security_choices (dialog, incoming_account->proto);
1149 if (incoming_account) {
1150 /* Remember this for later: */
1151 dialog->incoming_protocol = incoming_account->proto;
1153 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1154 incoming_account->username ? incoming_account->username : "");
1155 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1156 incoming_account->password ? incoming_account->password : "");
1158 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1159 incoming_account->hostname ? incoming_account->hostname : "");
1161 /* The UI spec says:
1162 * If secure authentication is unchecked, allow sending username and password also as plain text.
1163 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1164 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1166 const ModestConnectionProtocol security = modest_server_account_get_security (
1167 dialog->account_manager, incoming_account->account_name);
1168 modest_serversecurity_combo_box_set_active_serversecurity (
1169 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1174 - use encrypted passwords
1176 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1177 dialog->account_manager, incoming_account->account_name);
1178 dialog->protocol_authentication_incoming = secure_auth;
1179 if (modest_protocol_info_is_secure(security) ||
1180 modest_protocol_info_auth_is_secure(secure_auth))
1182 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1187 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1191 update_incoming_server_title (dialog, incoming_account->proto);
1193 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1194 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1196 if (port_num == 0) {
1197 /* Show the appropriate port number: */
1198 on_combo_incoming_security_changed (
1199 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1201 /* Keep the user-entered port-number,
1202 * or the already-appropriate automatic port number: */
1203 hildon_number_editor_set_value (
1204 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1208 ModestServerAccountData *outgoing_account = account_data->transport_account;
1209 if (outgoing_account) {
1210 /* Remember this for later: */
1211 dialog->outgoing_protocol = outgoing_account->proto;
1213 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1214 outgoing_account->hostname ? outgoing_account->hostname : "");
1216 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1217 outgoing_account->username ? outgoing_account->username : "");
1218 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1219 outgoing_account->password ? outgoing_account->password : "");
1221 /* Get the secure-auth setting: */
1222 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1223 dialog->account_manager, outgoing_account->account_name);
1224 modest_secureauth_combo_box_set_active_secureauth (
1225 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1226 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1228 modest_serversecurity_combo_box_fill (
1229 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1231 /* Get the security setting: */
1232 const ModestConnectionProtocol security = modest_server_account_get_security (
1233 dialog->account_manager, outgoing_account->account_name);
1234 modest_serversecurity_combo_box_set_active_serversecurity (
1235 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1237 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1238 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1239 if (port_num == 0) {
1240 /* Show the appropriate port number: */
1241 on_combo_outgoing_security_changed (
1242 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1245 /* Keep the user-entered port-number,
1246 * or the already-appropriate automatic port number: */
1247 hildon_number_editor_set_value (
1248 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1251 const gboolean has_specific =
1252 modest_account_mgr_get_has_connection_specific_smtp (
1253 dialog->account_manager,
1255 gtk_toggle_button_set_active (
1256 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1260 /* Set window title according to account: */
1261 /* TODO: Is this the correct way to find a human-readable name for
1262 * the protocol used? */
1263 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1264 gchar *proto_name = g_utf8_strup(proto_str, -1);
1265 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1267 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1268 g_free (proto_name);
1269 g_free (account_title);
1271 gtk_window_set_title (GTK_WINDOW (dialog), title);
1274 /* account_data->is_enabled, */
1275 /*account_data->is_default, */
1277 /* account_data->store_account->proto */
1279 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1281 /* Unset the modified flag so we can detect changes later: */
1282 dialog->modified = FALSE;
1285 /** Show the User Info tab.
1287 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1289 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1290 if (page_num == -1) {
1291 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1294 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1295 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1297 gtk_widget_show (dialog->page_user_details);
1298 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1299 gtk_widget_show (GTK_WIDGET (dialog));
1300 gtk_notebook_set_current_page (dialog->notebook, page_num);
1304 save_configuration (ModestAccountSettingsDialog *dialog)
1306 g_assert (dialog->account_name);
1308 const gchar* account_name = dialog->account_name;
1310 /* Set the account data from the widgets: */
1311 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1312 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1313 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1317 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1318 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1319 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1324 if (dialog->signature_dialog) {
1325 gboolean use_signature = FALSE;
1326 gchar *signature = modest_signature_editor_dialog_get_settings (
1327 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1330 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1331 signature, use_signature);
1335 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1336 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1337 modest_account_mgr_set_string (dialog->account_manager, account_name,
1338 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1341 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1342 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1343 modest_account_mgr_set_int (dialog->account_manager, account_name,
1344 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1346 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1347 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1348 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1353 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1354 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1355 g_assert (incoming_account_name);
1357 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1358 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1359 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1363 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1364 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1366 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1367 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1370 gint port_num = hildon_number_editor_get_value (
1371 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1372 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1373 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1375 /* The UI spec says:
1376 * If secure authentication is unchecked, allow sending username and password also as plain text.
1377 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1380 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1381 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1382 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1384 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1387 g_free (incoming_account_name);
1390 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1391 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1392 g_assert (outgoing_account_name);
1394 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1395 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1396 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1400 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1401 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1404 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1405 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1408 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1409 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1410 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1412 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1413 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1414 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1417 port_num = hildon_number_editor_get_value (
1418 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1419 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1420 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1422 g_free (outgoing_account_name);
1425 /* Set the changed account title last, to simplify the previous code: */
1426 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1427 if ((!account_title) || (strlen(account_title) == 0))
1428 return FALSE; /* Should be prevented already anyway. */
1430 if (strcmp(account_title, account_name) != 0) {
1431 /* Change the title: */
1432 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1433 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1438 /* Save connection-specific SMTP server accounts: */
1439 if (dialog->specific_window) {
1440 return modest_connection_specific_smtp_window_save_server_accounts (
1441 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1447 static gboolean entry_is_empty (GtkWidget *entry)
1452 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1453 if ((!text) || (strlen(text) == 0))
1460 enable_buttons (ModestAccountSettingsDialog *self)
1462 gboolean enable_ok = TRUE;
1464 /* The account details title is mandatory: */
1465 if (entry_is_empty(self->entry_account_title))
1468 /* The user details username is mandatory: */
1469 if (entry_is_empty(self->entry_user_username))
1472 /* The user details email address is mandatory: */
1473 if (enable_ok && entry_is_empty (self->entry_user_email))
1476 /* The custom incoming server is mandatory: */
1477 if (entry_is_empty(self->entry_incomingserver))
1480 /* Enable the buttons,
1481 * identifying them via their associated response codes:
1483 GtkDialog *dialog_base = GTK_DIALOG (self);
1484 gtk_dialog_set_response_sensitive (dialog_base,
1490 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1492 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1493 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1496 object_class->get_property = modest_account_settings_dialog_get_property;
1497 object_class->set_property = modest_account_settings_dialog_set_property;
1498 object_class->dispose = modest_account_settings_dialog_dispose;
1499 object_class->finalize = modest_account_settings_dialog_finalize;
1503 show_error (GtkWidget *parent_widget, const gchar* text)
1505 hildon_banner_show_information(parent_widget, NULL, text);
1508 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_widget, text);
1510 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1517 gtk_dialog_run (dialog);
1518 gtk_widget_destroy (GTK_WIDGET (dialog));