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_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
260 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"),
261 "\\ / : * ? \" < > | ^");
262 show_error (GTK_WIDGET (self), message);
266 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
268 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"),
270 show_error (GTK_WIDGET (self), message);
276 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
278 /* ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data); */
279 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
283 create_page_account_details (ModestAccountSettingsDialog *self)
285 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
286 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
287 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
288 gtk_widget_show (label);
290 /* Create a size group to be used by all captions.
291 * Note that HildonCaption does not create a default size group if we do not specify one.
292 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
293 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
295 /* The description widgets: */
296 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
297 /* Do use auto-capitalization: */
298 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
299 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
300 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
301 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
302 gtk_widget_show (self->entry_account_title);
303 connect_for_modified (self, self->entry_account_title);
304 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
305 gtk_widget_show (caption);
307 /* Prevent the use of some characters in the account title,
308 * as required by our UI specification: */
309 GList *list_prevent = NULL;
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 list_prevent = g_list_append (list_prevent, "\"");
316 list_prevent = g_list_append (list_prevent, "<");
317 list_prevent = g_list_append (list_prevent, ">");
318 list_prevent = g_list_append (list_prevent, "|");
319 list_prevent = g_list_append (list_prevent, "^");
320 modest_validating_entry_set_unallowed_characters (
321 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
322 g_list_free (list_prevent);
323 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
324 on_entry_invalid_account_title_character, self);
326 /* Set max length as in the UI spec:
327 * The UI spec seems to want us to show a dialog if we hit the maximum. */
328 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
329 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
332 /* The retrieve combobox: */
333 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
334 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
335 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
336 gtk_widget_show (self->combo_retrieve);
337 connect_for_modified (self, self->combo_retrieve);
338 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
339 gtk_widget_show (caption);
341 /* The limit-retrieve combobox: */
342 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
343 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
344 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
345 gtk_widget_show (self->combo_limit_retrieve);
346 connect_for_modified (self, self->combo_limit_retrieve);
347 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
348 gtk_widget_show (caption);
350 /* The leave-messages widgets: */
351 if(!self->checkbox_leave_messages)
352 self->checkbox_leave_messages = gtk_check_button_new ();
353 if (!self->caption_leave_messages) {
354 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
355 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
358 gtk_widget_show (self->checkbox_leave_messages);
359 connect_for_modified (self, self->checkbox_leave_messages);
360 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
361 gtk_widget_show (self->caption_leave_messages);
363 gtk_widget_show (GTK_WIDGET (box));
365 return GTK_WIDGET (box);
369 on_button_signature (GtkButton *button, gpointer user_data)
371 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
373 /* Create the window, if necessary: */
374 if (!(self->signature_dialog)) {
375 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
377 gboolean use_signature = FALSE;
378 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
380 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
381 modest_signature_editor_dialog_set_settings (
382 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
383 use_signature, signature, account_title);
388 /* Show the window: */
389 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
390 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
391 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
392 gtk_widget_hide (self->signature_dialog);
393 if (response != GTK_RESPONSE_OK) {
394 /* Destroy the widget now, and its data: */
395 gtk_widget_destroy (self->signature_dialog);
396 self->signature_dialog = NULL;
399 /* Mark modified, so we use the dialog's data later: */
400 self->modified = TRUE;
405 create_page_user_details (ModestAccountSettingsDialog *self)
407 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
408 GtkAdjustment *focus_adjustment = NULL;
410 /* Create a size group to be used by all captions.
411 * Note that HildonCaption does not create a default size group if we do not specify one.
412 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
413 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
414 GtkWidget *scrollwin = gtk_scrolled_window_new (NULL, NULL);
415 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
416 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
418 /* The name widgets: */
419 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
421 /* Auto-capitalization is the default, so let's turn it off: */
422 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
423 /* Set max length as in the UI spec:
424 * The UI spec seems to want us to show a dialog if we hit the maximum. */
425 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
426 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
428 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
429 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
430 gtk_widget_show (self->entry_user_name);
431 connect_for_modified (self, self->entry_user_name);
432 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
433 gtk_widget_show (caption);
436 /* Prevent the use of some characters in the name,
437 * as required by our UI specification: */
438 GList *list_prevent = NULL;
439 list_prevent = g_list_append (list_prevent, "<");
440 list_prevent = g_list_append (list_prevent, ">");
441 modest_validating_entry_set_unallowed_characters (
442 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
443 g_list_free (list_prevent);
444 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_user_name),
445 on_entry_invalid_fullname_character, self);
447 /* The username widgets: */
448 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
449 /* Auto-capitalization is the default, so let's turn it off: */
450 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
451 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
452 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
453 gtk_widget_show (self->entry_user_username);
454 connect_for_modified (self, self->entry_user_username);
455 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
456 gtk_widget_show (caption);
458 /* Prevent the use of some characters in the username,
459 * as required by our UI specification: */
460 modest_validating_entry_set_unallowed_characters_whitespace (
461 MODEST_VALIDATING_ENTRY (self->entry_user_username));
463 /* Set max length as in the UI spec:
464 * The UI spec seems to want us to show a dialog if we hit the maximum. */
465 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
466 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
469 /* The password widgets: */
470 self->entry_user_password = gtk_entry_new ();
471 /* Auto-capitalization is the default, so let's turn it off: */
472 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
473 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
474 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
475 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
476 caption = create_caption_new_with_asterisk (self, sizegroup,
477 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
478 gtk_widget_show (self->entry_user_password);
479 connect_for_modified (self, self->entry_user_password);
480 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
481 gtk_widget_show (caption);
483 /* The email address widgets: */
484 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
485 /* Auto-capitalization is the default, so let's turn it off: */
486 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
487 caption = create_caption_new_with_asterisk (self, sizegroup,
488 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
489 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
490 gtk_widget_show (self->entry_user_email);
491 connect_for_modified (self, self->entry_user_email);
492 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
493 gtk_widget_show (caption);
495 /* Set max length as in the UI spec:
496 * The UI spec seems to want us to show a dialog if we hit the maximum. */
497 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
498 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
501 /* Signature button: */
502 if (!self->button_signature)
503 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
504 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
505 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
506 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
507 gtk_widget_show (self->button_signature);
508 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
509 gtk_widget_show (caption);
511 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
512 G_CALLBACK (on_button_signature), self);
514 gtk_widget_show (GTK_WIDGET (box));
515 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrollwin), box);
516 gtk_widget_show (scrollwin);
518 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
519 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
521 return GTK_WIDGET (scrollwin);
524 /** Change the caption title for the incoming server,
525 * as specified in the UI spec:
527 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
530 (protocol == MODEST_PROTOCOL_STORE_POP ?
531 _("mail_fi_emailtype_pop3") :
532 _("mail_fi_emailtype_imap") );
535 /* Note that this produces a compiler warning,
536 * because the compiler does not know that the translated string will have a %s in it.
537 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
538 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
540 /* This is a mandatory field, so add a *. This is usually done by
541 * create_caption_new_with_asterisk() but we can't use that here. */
542 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
543 g_free (incomingserver_title);
545 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
546 g_free(with_asterisk);
549 /** Change the caption title for the incoming server,
550 * as specified in the UI spec:
552 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
554 /* Fill the combo with appropriately titled choices for POP or IMAP. */
555 /* The choices are the same, but the titles are different, as in the UI spec. */
556 modest_serversecurity_combo_box_fill (
557 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
560 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
562 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
564 /* Create a size group to be used by all captions.
565 * Note that HildonCaption does not create a default size group if we do not specify one.
566 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
567 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
569 /* The incoming server widgets: */
570 if(!self->entry_incomingserver)
571 self->entry_incomingserver = gtk_entry_new ();
572 /* Auto-capitalization is the default, so let's turn it off: */
573 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
575 if (self->caption_incoming)
576 gtk_widget_destroy (self->caption_incoming);
578 /* The caption title will be updated in update_incoming_server_title().
579 * so this default text will never be seen: */
580 /* (Note: Changing the title seems pointless. murrayc) */
581 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
582 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
583 gtk_widget_show (self->entry_incomingserver);
584 connect_for_modified (self, self->entry_incomingserver);
585 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
586 gtk_widget_show (self->caption_incoming);
588 /* The secure connection widgets: */
589 /* This will be filled by update_incoming_server_security_choices(). */
590 if (!self->combo_incoming_security)
591 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
592 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
593 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
594 gtk_widget_show (self->combo_incoming_security);
595 connect_for_modified (self, self->combo_incoming_security);
596 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
597 gtk_widget_show (caption);
599 /* Show a default port number when the security method changes, as per the UI spec: */
600 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
603 /* The port widgets: */
604 /* TODO: There are various rules about this in the UI spec. */
605 if (!self->entry_incoming_port)
606 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (1, 65535));
607 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
608 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
609 gtk_widget_show (self->entry_incoming_port);
610 connect_for_modified (self, self->entry_incoming_port);
611 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
612 gtk_widget_show (caption);
614 /* The secure authentication widgets: */
615 if(!self->checkbox_incoming_auth)
616 self->checkbox_incoming_auth = gtk_check_button_new ();
617 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
618 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
619 gtk_widget_show (self->checkbox_incoming_auth);
620 connect_for_modified (self, self->checkbox_incoming_auth);
621 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
622 gtk_widget_show (caption);
624 gtk_widget_show (GTK_WIDGET (box));
626 return GTK_WIDGET (box);
630 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
632 GtkWidget *widget = GTK_WIDGET (user_data);
634 /* Enable the widget only if the toggle button is active: */
635 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
636 gtk_widget_set_sensitive (widget, enable);
639 /* Make the sensitivity of a widget depend on a toggle button.
642 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
644 g_signal_connect (G_OBJECT (button), "toggled",
645 G_CALLBACK (on_toggle_button_changed), widget);
647 /* Set the starting sensitivity: */
648 on_toggle_button_changed (button, widget);
652 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
654 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
656 /* Create the window if necessary: */
657 if (!(self->specific_window)) {
658 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
659 modest_connection_specific_smtp_window_fill_with_connections (
660 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
664 /* Show the window: */
665 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
666 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
667 gtk_widget_show (self->specific_window);
671 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
673 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
675 ModestAuthProtocol protocol_security =
676 modest_secureauth_combo_box_get_active_secureauth (
677 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
678 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
680 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
681 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
685 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
687 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
689 const gint port_number =
690 modest_serversecurity_combo_box_get_active_serversecurity_port (
691 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
693 if(port_number != 0) {
694 hildon_number_editor_set_value (
695 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
700 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
702 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
704 const gint port_number =
705 modest_serversecurity_combo_box_get_active_serversecurity_port (
706 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
708 if(port_number != 0) {
709 hildon_number_editor_set_value (
710 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
715 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
717 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
718 GtkAdjustment *focus_adjustment = NULL;
720 /* Put it all in a scrolled window, so that all widgets can be
721 * accessed even when the on-screen keyboard is visible: */
722 GtkWidget *scrollwin = gtk_scrolled_window_new(NULL, NULL);
723 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
724 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
726 /* Create a size group to be used by all captions.
727 * Note that HildonCaption does not create a default size group if we do not specify one.
728 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
729 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
731 /* The outgoing server widgets: */
732 if (!self->entry_outgoingserver)
733 self->entry_outgoingserver = gtk_entry_new ();
734 /* Auto-capitalization is the default, so let's turn it off: */
735 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
736 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
737 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
738 gtk_widget_show (self->entry_outgoingserver);
739 connect_for_modified (self, self->entry_outgoingserver);
740 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
741 gtk_widget_show (caption);
743 /* The secure authentication widgets: */
744 if (!self->combo_outgoing_auth)
745 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
746 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
747 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
748 gtk_widget_show (self->combo_outgoing_auth);
749 connect_for_modified (self, self->combo_outgoing_auth);
750 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
751 gtk_widget_show (caption);
753 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
754 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
756 /* The username widgets: */
757 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
758 /* Auto-capitalization is the default, so let's turn it off: */
759 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
760 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
761 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
762 gtk_widget_show (self->entry_outgoing_username);
763 connect_for_modified (self, self->entry_outgoing_username);
764 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
765 gtk_widget_show (self->caption_outgoing_username);
767 /* Prevent the use of some characters in the username,
768 * as required by our UI specification: */
769 modest_validating_entry_set_unallowed_characters_whitespace (
770 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
772 /* Set max length as in the UI spec:
773 * The UI spec seems to want us to show a dialog if we hit the maximum. */
774 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
775 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
778 /* The password widgets: */
779 self->entry_outgoing_password = gtk_entry_new ();
780 /* Auto-capitalization is the default, so let's turn it off: */
781 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
782 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
783 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
784 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
785 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
786 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
787 gtk_widget_show (self->entry_outgoing_password);
788 connect_for_modified (self, self->entry_outgoing_password);
789 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
790 gtk_widget_show (self->caption_outgoing_password);
792 /* The secure connection widgets: */
793 /* This will be filled and set with modest_serversecurity_combo_box_fill()
794 * and modest_serversecurity_combo_box_set_active_serversecurity().
796 if (!self->combo_outgoing_security)
798 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
799 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
800 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
801 gtk_widget_show (self->combo_outgoing_security);
802 connect_for_modified (self, self->combo_outgoing_security);
803 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
804 gtk_widget_show (caption);
806 /* Show a default port number when the security method changes, as per the UI spec: */
807 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
809 /* The port widgets: */
810 if (!self->entry_outgoing_port)
811 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (1, 65535));
812 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
813 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
814 gtk_widget_show (self->entry_outgoing_port);
815 connect_for_modified (self, self->entry_outgoing_port);
816 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
817 gtk_widget_show (caption);
819 GtkWidget *separator = gtk_hseparator_new ();
820 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
821 gtk_widget_show (separator);
823 /* connection-specific checkbox: */
824 if (!self->checkbox_outgoing_smtp_specific) {
825 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
826 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
829 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
830 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
831 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
832 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
833 gtk_widget_show (caption);
834 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
836 /* Connection-specific SMTP-Severs Edit button: */
837 if (!self->button_outgoing_smtp_servers)
838 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
839 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
840 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
841 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
842 gtk_widget_show (self->button_outgoing_smtp_servers);
843 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
844 gtk_widget_show (caption);
846 /* Only enable the button when the checkbox is checked: */
847 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
848 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
850 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
851 G_CALLBACK (on_button_outgoing_smtp_servers), self);
853 gtk_widget_show (GTK_WIDGET (box));
854 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrollwin), box);
855 gtk_widget_show(scrollwin);
857 focus_adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrollwin));
858 gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), focus_adjustment);
860 return GTK_WIDGET (scrollwin);
867 check_data (ModestAccountSettingsDialog *self)
869 /* Check that the title is not already in use: */
870 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
871 if ((!account_title) || (strlen(account_title) == 0))
872 return FALSE; /* Should be prevented already anyway. */
874 if (strcmp(account_title, self->original_account_title) != 0) {
875 /* Check the changed title: */
876 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
880 /* Warn the user via a dialog: */
881 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
887 /* Check that the email address is valid: */
888 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
889 if ((!email_address) || (strlen(email_address) == 0))
892 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
893 /* Warn the user via a dialog: */
894 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
895 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
897 /* Return focus to the email address entry: */
898 gtk_widget_grab_focus (self->entry_user_email);
899 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
903 /* make sure the domain name for the incoming server is valid */
904 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
905 if ((!hostname) || (strlen(hostname) == 0))
907 if (!modest_text_utils_validate_domain_name (hostname)) {
908 /* Warn the user via a dialog: */
909 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
910 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
912 /* Return focus to the email address entry: */
913 gtk_widget_grab_focus (self->entry_incomingserver);
914 gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
918 /* make sure the domain name for the outgoing server is valid */
919 const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
920 if ((!hostname2) || (strlen(hostname2) == 0))
922 if (!modest_text_utils_validate_domain_name (hostname2)) {
923 /* Warn the user via a dialog: */
924 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
925 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
927 /* Return focus to the email address entry: */
928 gtk_widget_grab_focus (self->entry_outgoingserver);
929 gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
934 /* Find a suitable authentication method when secure authentication is desired */
936 gint port_num = hildon_number_editor_get_value (
937 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
938 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
940 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
941 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
943 /* If we use an encrypted protocol then there is no need to encrypt the password */
944 if (!modest_protocol_info_is_secure(protocol_security_incoming))
946 if (gtk_toggle_button_get_active (
947 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
948 GError *error = NULL;
949 GList *list_auth_methods =
950 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
951 hostname, port_num, username, GTK_WINDOW (self), &error);
952 if (list_auth_methods) {
953 /* Use the first supported method.
954 * TODO: Should we prioritize them, to prefer a particular one? */
956 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
958 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
959 // Allow secure methods, e.g MD5 only
960 if (modest_protocol_info_auth_is_secure(proto))
962 self->protocol_authentication_incoming = proto;
966 g_list_free (list_auth_methods);
969 if (list_auth_methods == NULL ||
970 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
972 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
973 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
975 show_error (GTK_WIDGET (self), _("Could not discover supported secure authentication methods."));
981 /* This is a nasty hack. jschmid. */
982 /* Don't let the dialog close */
983 /*g_signal_stop_emission_by_name (dialog, "response");*/
997 on_response (GtkDialog *wizard_dialog,
1001 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
1002 enable_buttons (self);
1004 gboolean prevent_response = FALSE;
1006 /* Warn about unsaved changes: */
1007 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
1008 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1009 _("imum_nc_wizard_confirm_lose_changes")));
1010 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1012 const gint dialog_response = gtk_dialog_run (dialog);
1013 gtk_widget_destroy (GTK_WIDGET (dialog));
1015 if (dialog_response != GTK_RESPONSE_OK)
1016 prevent_response = TRUE;
1018 /* Check for invalid input: */
1019 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1020 prevent_response = TRUE;
1023 if (prevent_response) {
1024 /* This is a nasty hack. murrayc. */
1025 /* Don't let the dialog close */
1026 g_signal_stop_emission_by_name (wizard_dialog, "response");
1030 if (response_id == GTK_RESPONSE_OK) {
1031 /* Try to save the changes if modified (NB #59251): */
1034 const gboolean saved = save_configuration (self);
1036 /* Do not show the account-saved dialog if we are just saving this
1037 * temporarily, because from the user's point of view it will not
1038 * really be saved (saved + enabled) until later.
1040 const gboolean enabled =
1041 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
1043 show_error (NULL, _("mcen_ib_advsetup_settings_saved"));
1046 show_error (NULL, _("mail_ib_setting_failed"));
1052 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
1054 /* Create the notebook to be used by the GtkDialog base class:
1055 * Each page of the notebook will be a page of the wizard: */
1056 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1058 /* Get the account manager object,
1059 * so we can check for existing accounts,
1060 * and create new accounts: */
1061 self->account_manager = modest_runtime_get_account_mgr ();
1062 g_assert (self->account_manager);
1063 g_object_ref (self->account_manager);
1065 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1067 /* Create the common pages,
1069 self->page_account_details = create_page_account_details (self);
1070 self->page_user_details = create_page_user_details (self);
1071 self->page_incoming = create_page_incoming (self);
1072 self->page_outgoing = create_page_outgoing (self);
1074 /* Add the notebook pages: */
1075 gtk_notebook_append_page (self->notebook, self->page_account_details,
1076 gtk_label_new (_("mcen_ti_account_settings_account")));
1077 gtk_notebook_append_page (self->notebook, self->page_user_details,
1078 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1079 gtk_notebook_append_page (self->notebook, self->page_incoming,
1080 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1081 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1082 gtk_label_new (_("mcen_ti_advsetup_sending")));
1084 GtkDialog *dialog = GTK_DIALOG (self);
1085 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1086 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1087 gtk_widget_show (GTK_WIDGET (self->notebook));
1089 /* Add the buttons: */
1090 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1091 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1093 /* Connect to the dialog's response signal: */
1094 /* We use connect-before
1095 * so we can stop the signal emission,
1096 * to stop the default signal handler from closing the dialog.
1098 g_signal_connect (G_OBJECT (self), "response",
1099 G_CALLBACK (on_response), self);
1101 self->modified = FALSE;
1103 /* When this window is shown, hibernation should not be possible,
1104 * because there is no sensible way to save the state: */
1105 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1106 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1109 ModestAccountSettingsDialog*
1110 modest_account_settings_dialog_new (void)
1112 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1115 /** Update the UI with the stored account details, so they can be edited.
1116 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1118 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1123 /* Save the account name so we can refer to it later: */
1124 if (dialog->account_name)
1125 g_free (dialog->account_name);
1126 dialog->account_name = g_strdup (account_name);
1129 /* Get the account data for this account name: */
1130 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1132 if (!account_data) {
1133 g_printerr ("modest: failed to get account data for %s\n", account_name);
1137 /* Save the account title so we can refer to it if the user changes it: */
1138 if (dialog->original_account_title)
1139 g_free (dialog->original_account_title);
1140 dialog->original_account_title = g_strdup (account_data->display_name);
1143 if (!(account_data->store_account)) {
1144 g_printerr ("modest: account has no stores: %s\n", account_name);
1148 /* Show the account data in the widgets: */
1150 /* Note that we never show the non-display name in the UI.
1151 * (Though the display name defaults to the non-display name at the start.) */
1152 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1153 account_data->display_name ? account_data->display_name : "");
1155 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1156 account_data->fullname ? account_data->fullname : "");
1157 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1158 account_data->email ? account_data->email : "");
1160 ModestServerAccountData *incoming_account = account_data->store_account;
1162 if (incoming_account)
1163 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1164 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1165 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1167 /* Default to something, though no default is specified in the UI spec: */
1168 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1170 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1173 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1174 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1175 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1178 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1179 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1180 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1182 /* Only show the leave-on-server checkbox for POP,
1183 * as per the UI spec: */
1184 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1185 gtk_widget_hide (dialog->caption_leave_messages);
1187 gtk_widget_show (dialog->caption_leave_messages);
1190 update_incoming_server_security_choices (dialog, incoming_account->proto);
1191 if (incoming_account) {
1192 /* Remember this for later: */
1193 dialog->incoming_protocol = incoming_account->proto;
1195 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1196 incoming_account->username ? incoming_account->username : "");
1197 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1198 incoming_account->password ? incoming_account->password : "");
1200 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1201 incoming_account->hostname ? incoming_account->hostname : "");
1203 /* The UI spec says:
1204 * If secure authentication is unchecked, allow sending username and password also as plain text.
1205 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1206 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1208 const ModestConnectionProtocol security = modest_server_account_get_security (
1209 dialog->account_manager, incoming_account->account_name);
1210 modest_serversecurity_combo_box_set_active_serversecurity (
1211 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1216 - use encrypted passwords
1218 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1219 dialog->account_manager, incoming_account->account_name);
1220 dialog->protocol_authentication_incoming = secure_auth;
1221 if (modest_protocol_info_is_secure(security) ||
1222 modest_protocol_info_auth_is_secure(secure_auth))
1224 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1229 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1233 update_incoming_server_title (dialog, incoming_account->proto);
1235 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1236 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1238 if (port_num == 0) {
1239 /* Show the appropriate port number: */
1240 on_combo_incoming_security_changed (
1241 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1243 /* Keep the user-entered port-number,
1244 * or the already-appropriate automatic port number: */
1245 hildon_number_editor_set_value (
1246 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1250 ModestServerAccountData *outgoing_account = account_data->transport_account;
1251 if (outgoing_account) {
1252 /* Remember this for later: */
1253 dialog->outgoing_protocol = outgoing_account->proto;
1255 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1256 outgoing_account->hostname ? outgoing_account->hostname : "");
1258 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1259 outgoing_account->username ? outgoing_account->username : "");
1260 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1261 outgoing_account->password ? outgoing_account->password : "");
1263 /* Get the secure-auth setting: */
1264 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1265 dialog->account_manager, outgoing_account->account_name);
1266 modest_secureauth_combo_box_set_active_secureauth (
1267 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1268 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1270 modest_serversecurity_combo_box_fill (
1271 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1273 /* Get the security setting: */
1274 const ModestConnectionProtocol security = modest_server_account_get_security (
1275 dialog->account_manager, outgoing_account->account_name);
1276 modest_serversecurity_combo_box_set_active_serversecurity (
1277 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1279 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1280 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1281 if (port_num == 0) {
1282 /* Show the appropriate port number: */
1283 on_combo_outgoing_security_changed (
1284 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1287 /* Keep the user-entered port-number,
1288 * or the already-appropriate automatic port number: */
1289 hildon_number_editor_set_value (
1290 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1293 const gboolean has_specific =
1294 modest_account_mgr_get_has_connection_specific_smtp (
1295 dialog->account_manager,
1297 gtk_toggle_button_set_active (
1298 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1302 /* Set window title according to account: */
1303 /* TODO: Is this the correct way to find a human-readable name for
1304 * the protocol used? */
1305 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1306 gchar *proto_name = g_utf8_strup(proto_str, -1);
1307 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1309 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1310 g_free (proto_name);
1311 g_free (account_title);
1313 gtk_window_set_title (GTK_WINDOW (dialog), title);
1316 /* account_data->is_enabled, */
1317 /*account_data->is_default, */
1319 /* account_data->store_account->proto */
1321 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1323 /* Unset the modified flag so we can detect changes later: */
1324 dialog->modified = FALSE;
1327 /** Show the User Info tab.
1329 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1331 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1332 if (page_num == -1) {
1333 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1336 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1337 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1339 gtk_widget_show (dialog->page_user_details);
1340 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1341 gtk_widget_show (GTK_WIDGET (dialog));
1342 gtk_notebook_set_current_page (dialog->notebook, page_num);
1346 save_configuration (ModestAccountSettingsDialog *dialog)
1348 g_assert (dialog->account_name);
1350 const gchar* account_name = dialog->account_name;
1352 /* Set the account data from the widgets: */
1353 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1354 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1355 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1359 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1360 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1361 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1366 if (dialog->signature_dialog) {
1367 gboolean use_signature = FALSE;
1368 gchar *signature = modest_signature_editor_dialog_get_settings (
1369 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1372 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1373 signature, use_signature);
1377 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1378 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1379 modest_account_mgr_set_string (dialog->account_manager, account_name,
1380 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1383 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1384 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1385 modest_account_mgr_set_int (dialog->account_manager, account_name,
1386 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1388 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1389 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1390 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1395 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1396 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1397 g_assert (incoming_account_name);
1399 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1400 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1401 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1405 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1406 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1408 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1409 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1412 gint port_num = hildon_number_editor_get_value (
1413 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1414 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1415 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1417 /* The UI spec says:
1418 * If secure authentication is unchecked, allow sending username and password also as plain text.
1419 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1422 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1423 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1424 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1426 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1429 g_free (incoming_account_name);
1432 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1433 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1434 g_assert (outgoing_account_name);
1436 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1437 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1438 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1442 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1443 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1446 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1447 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1450 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1451 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1452 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1454 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1455 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1456 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1459 port_num = hildon_number_editor_get_value (
1460 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1461 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1462 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1464 g_free (outgoing_account_name);
1467 /* Set the changed account title last, to simplify the previous code: */
1468 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1469 if ((!account_title) || (strlen(account_title) == 0))
1470 return FALSE; /* Should be prevented already anyway. */
1472 if (strcmp(account_title, account_name) != 0) {
1473 /* Change the title: */
1474 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1475 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1480 /* Save connection-specific SMTP server accounts: */
1481 if (dialog->specific_window) {
1482 return modest_connection_specific_smtp_window_save_server_accounts (
1483 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1489 static gboolean entry_is_empty (GtkWidget *entry)
1494 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1495 if ((!text) || (strlen(text) == 0))
1502 enable_buttons (ModestAccountSettingsDialog *self)
1504 gboolean enable_ok = TRUE;
1506 /* The account details title is mandatory: */
1507 if (entry_is_empty(self->entry_account_title))
1510 /* The user details username is mandatory: */
1511 if (entry_is_empty(self->entry_user_username))
1514 /* The user details email address is mandatory: */
1515 if (enable_ok && entry_is_empty (self->entry_user_email))
1518 /* The custom incoming server is mandatory: */
1519 if (entry_is_empty(self->entry_incomingserver))
1522 /* Enable the buttons,
1523 * identifying them via their associated response codes:
1525 GtkDialog *dialog_base = GTK_DIALOG (self);
1526 gtk_dialog_set_response_sensitive (dialog_base,
1532 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1534 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1535 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1538 object_class->get_property = modest_account_settings_dialog_get_property;
1539 object_class->set_property = modest_account_settings_dialog_set_property;
1540 object_class->dispose = modest_account_settings_dialog_dispose;
1541 object_class->finalize = modest_account_settings_dialog_finalize;
1545 show_error (GtkWidget *parent_widget, const gchar* text)
1547 hildon_banner_show_information(parent_widget, NULL, text);
1550 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_widget, text);
1552 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1559 gtk_dialog_run (dialog);
1560 gtk_widget_destroy (GTK_WIDGET (dialog));