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);
858 check_data (ModestAccountSettingsDialog *self)
860 /* Check that the title is not already in use: */
861 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
862 if ((!account_title) || (strlen(account_title) == 0))
863 return FALSE; /* Should be prevented already anyway. */
865 if (strcmp(account_title, self->original_account_title) != 0) {
866 /* Check the changed title: */
867 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
871 /* Warn the user via a dialog: */
872 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
878 /* Check that the email address is valid: */
879 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
880 if ((!email_address) || (strlen(email_address) == 0))
883 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
884 /* Warn the user via a dialog: */
885 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
886 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
888 /* Return focus to the email address entry: */
889 gtk_widget_grab_focus (self->entry_user_email);
890 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
894 /* make sure the domain name for the incoming server is valid */
895 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
896 if ((!hostname) || (strlen(hostname) == 0))
898 if (!modest_text_utils_validate_domain_name (hostname)) {
899 /* Warn the user via a dialog: */
900 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
901 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
903 /* Return focus to the email address entry: */
904 gtk_widget_grab_focus (self->entry_incomingserver);
905 gtk_editable_select_region (GTK_EDITABLE (self->entry_incomingserver), 0, -1);
909 /* make sure the domain name for the outgoing server is valid */
910 const gchar* hostname2 = gtk_entry_get_text (GTK_ENTRY (self->entry_outgoingserver));
911 if ((!hostname2) || (strlen(hostname2) == 0))
913 if (!modest_text_utils_validate_domain_name (hostname2)) {
914 /* Warn the user via a dialog: */
915 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
916 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
918 /* Return focus to the email address entry: */
919 gtk_widget_grab_focus (self->entry_outgoingserver);
920 gtk_editable_select_region (GTK_EDITABLE (self->entry_outgoingserver), 0, -1);
925 /* Find a suitable authentication method when secure authentication is desired */
927 gint port_num = hildon_number_editor_get_value (
928 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
929 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
931 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
932 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
934 /* If we use an encrypted protocol then there is no need to encrypt the password */
935 if (!modest_protocol_info_is_secure(protocol_security_incoming))
937 if (gtk_toggle_button_get_active (
938 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
939 GError *error = NULL;
940 GList *list_auth_methods =
941 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
942 hostname, port_num, username, GTK_WINDOW (self), &error);
943 if (list_auth_methods) {
944 /* Use the first supported method.
945 * TODO: Should we prioritize them, to prefer a particular one? */
947 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
949 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
950 // Allow secure methods, e.g MD5 only
951 if (modest_protocol_info_auth_is_secure(proto))
953 self->protocol_authentication_incoming = proto;
957 g_list_free (list_auth_methods);
960 if (list_auth_methods == NULL ||
961 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
963 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
964 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
966 show_error (GTK_WIDGET (self), _("Could not discover supported secure authentication methods."));
972 /* This is a nasty hack. jschmid. */
973 /* Don't let the dialog close */
974 /*g_signal_stop_emission_by_name (dialog, "response");*/
988 on_response (GtkDialog *wizard_dialog,
992 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
993 enable_buttons (self);
995 gboolean prevent_response = FALSE;
997 /* Warn about unsaved changes: */
998 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
999 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
1000 _("imum_nc_wizard_confirm_lose_changes")));
1001 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
1003 const gint dialog_response = gtk_dialog_run (dialog);
1004 gtk_widget_destroy (GTK_WIDGET (dialog));
1006 if (dialog_response != GTK_RESPONSE_OK)
1007 prevent_response = TRUE;
1009 /* Check for invalid input: */
1010 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
1011 prevent_response = TRUE;
1014 if (prevent_response) {
1015 /* This is a nasty hack. murrayc. */
1016 /* Don't let the dialog close */
1017 g_signal_stop_emission_by_name (wizard_dialog, "response");
1021 if (response_id == GTK_RESPONSE_OK) {
1022 /* Try to save the changes if modified (NB #59251): */
1025 const gboolean saved = save_configuration (self);
1027 /* Do not show the account-saved dialog if we are just saving this
1028 * temporarily, because from the user's point of view it will not
1029 * really be saved (saved + enabled) until later.
1031 const gboolean enabled =
1032 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
1034 show_error (GTK_WIDGET (self), _("mcen_ib_advsetup_settings_saved"));
1037 show_error (GTK_WIDGET (self), _("mail_ib_setting_failed"));
1043 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
1045 /* Create the notebook to be used by the GtkDialog base class:
1046 * Each page of the notebook will be a page of the wizard: */
1047 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
1049 /* Get the account manager object,
1050 * so we can check for existing accounts,
1051 * and create new accounts: */
1052 self->account_manager = modest_runtime_get_account_mgr ();
1053 g_assert (self->account_manager);
1054 g_object_ref (self->account_manager);
1056 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1058 /* Create the common pages,
1060 self->page_account_details = create_page_account_details (self);
1061 self->page_user_details = create_page_user_details (self);
1062 self->page_incoming = create_page_incoming (self);
1063 self->page_outgoing = create_page_outgoing (self);
1065 /* Add the notebook pages: */
1066 gtk_notebook_append_page (self->notebook, self->page_account_details,
1067 gtk_label_new (_("mcen_ti_account_settings_account")));
1068 gtk_notebook_append_page (self->notebook, self->page_user_details,
1069 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1070 gtk_notebook_append_page (self->notebook, self->page_incoming,
1071 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1072 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1073 gtk_label_new (_("mcen_ti_advsetup_sending")));
1075 GtkDialog *dialog = GTK_DIALOG (self);
1076 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1077 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1078 gtk_widget_show (GTK_WIDGET (self->notebook));
1080 /* Add the buttons: */
1081 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1082 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1084 /* Connect to the dialog's response signal: */
1085 /* We use connect-before
1086 * so we can stop the signal emission,
1087 * to stop the default signal handler from closing the dialog.
1089 g_signal_connect (G_OBJECT (self), "response",
1090 G_CALLBACK (on_response), self);
1092 self->modified = FALSE;
1094 /* When this window is shown, hibernation should not be possible,
1095 * because there is no sensible way to save the state: */
1096 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1097 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1100 ModestAccountSettingsDialog*
1101 modest_account_settings_dialog_new (void)
1103 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1106 /** Update the UI with the stored account details, so they can be edited.
1107 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1109 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1114 /* Save the account name so we can refer to it later: */
1115 if (dialog->account_name)
1116 g_free (dialog->account_name);
1117 dialog->account_name = g_strdup (account_name);
1120 /* Get the account data for this account name: */
1121 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1123 if (!account_data) {
1124 g_printerr ("modest: failed to get account data for %s\n", account_name);
1128 /* Save the account title so we can refer to it if the user changes it: */
1129 if (dialog->original_account_title)
1130 g_free (dialog->original_account_title);
1131 dialog->original_account_title = g_strdup (account_data->display_name);
1134 if (!(account_data->store_account)) {
1135 g_printerr ("modest: account has no stores: %s\n", account_name);
1139 /* Show the account data in the widgets: */
1141 /* Note that we never show the non-display name in the UI.
1142 * (Though the display name defaults to the non-display name at the start.) */
1143 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1144 account_data->display_name ? account_data->display_name : "");
1146 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1147 account_data->fullname ? account_data->fullname : "");
1148 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1149 account_data->email ? account_data->email : "");
1151 ModestServerAccountData *incoming_account = account_data->store_account;
1153 if (incoming_account)
1154 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1155 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1156 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1158 /* Default to something, though no default is specified in the UI spec: */
1159 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1161 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1164 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1165 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1166 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1169 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1170 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1171 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1173 /* Only show the leave-on-server checkbox for POP,
1174 * as per the UI spec: */
1175 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1176 gtk_widget_hide (dialog->caption_leave_messages);
1178 gtk_widget_show (dialog->caption_leave_messages);
1181 update_incoming_server_security_choices (dialog, incoming_account->proto);
1182 if (incoming_account) {
1183 /* Remember this for later: */
1184 dialog->incoming_protocol = incoming_account->proto;
1186 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1187 incoming_account->username ? incoming_account->username : "");
1188 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1189 incoming_account->password ? incoming_account->password : "");
1191 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1192 incoming_account->hostname ? incoming_account->hostname : "");
1194 /* The UI spec says:
1195 * If secure authentication is unchecked, allow sending username and password also as plain text.
1196 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1197 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1199 const ModestConnectionProtocol security = modest_server_account_get_security (
1200 dialog->account_manager, incoming_account->account_name);
1201 modest_serversecurity_combo_box_set_active_serversecurity (
1202 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1207 - use encrypted passwords
1209 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1210 dialog->account_manager, incoming_account->account_name);
1211 dialog->protocol_authentication_incoming = secure_auth;
1212 if (modest_protocol_info_is_secure(security) ||
1213 modest_protocol_info_auth_is_secure(secure_auth))
1215 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1220 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1224 update_incoming_server_title (dialog, incoming_account->proto);
1226 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1227 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1229 if (port_num == 0) {
1230 /* Show the appropriate port number: */
1231 on_combo_incoming_security_changed (
1232 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1234 /* Keep the user-entered port-number,
1235 * or the already-appropriate automatic port number: */
1236 hildon_number_editor_set_value (
1237 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1241 ModestServerAccountData *outgoing_account = account_data->transport_account;
1242 if (outgoing_account) {
1243 /* Remember this for later: */
1244 dialog->outgoing_protocol = outgoing_account->proto;
1246 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1247 outgoing_account->hostname ? outgoing_account->hostname : "");
1249 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1250 outgoing_account->username ? outgoing_account->username : "");
1251 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1252 outgoing_account->password ? outgoing_account->password : "");
1254 /* Get the secure-auth setting: */
1255 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1256 dialog->account_manager, outgoing_account->account_name);
1257 modest_secureauth_combo_box_set_active_secureauth (
1258 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1259 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1261 modest_serversecurity_combo_box_fill (
1262 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1264 /* Get the security setting: */
1265 const ModestConnectionProtocol security = modest_server_account_get_security (
1266 dialog->account_manager, outgoing_account->account_name);
1267 modest_serversecurity_combo_box_set_active_serversecurity (
1268 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1270 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1271 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1272 if (port_num == 0) {
1273 /* Show the appropriate port number: */
1274 on_combo_outgoing_security_changed (
1275 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1278 /* Keep the user-entered port-number,
1279 * or the already-appropriate automatic port number: */
1280 hildon_number_editor_set_value (
1281 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1284 const gboolean has_specific =
1285 modest_account_mgr_get_has_connection_specific_smtp (
1286 dialog->account_manager,
1288 gtk_toggle_button_set_active (
1289 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1293 /* Set window title according to account: */
1294 /* TODO: Is this the correct way to find a human-readable name for
1295 * the protocol used? */
1296 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1297 gchar *proto_name = g_utf8_strup(proto_str, -1);
1298 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1300 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1301 g_free (proto_name);
1302 g_free (account_title);
1304 gtk_window_set_title (GTK_WINDOW (dialog), title);
1307 /* account_data->is_enabled, */
1308 /*account_data->is_default, */
1310 /* account_data->store_account->proto */
1312 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1314 /* Unset the modified flag so we can detect changes later: */
1315 dialog->modified = FALSE;
1318 /** Show the User Info tab.
1320 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1322 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1323 if (page_num == -1) {
1324 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1327 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1328 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1330 gtk_widget_show (dialog->page_user_details);
1331 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1332 gtk_widget_show (GTK_WIDGET (dialog));
1333 gtk_notebook_set_current_page (dialog->notebook, page_num);
1337 save_configuration (ModestAccountSettingsDialog *dialog)
1339 g_assert (dialog->account_name);
1341 const gchar* account_name = dialog->account_name;
1343 /* Set the account data from the widgets: */
1344 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1345 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1346 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1350 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1351 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1352 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1357 if (dialog->signature_dialog) {
1358 gboolean use_signature = FALSE;
1359 gchar *signature = modest_signature_editor_dialog_get_settings (
1360 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1363 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1364 signature, use_signature);
1368 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1369 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1370 modest_account_mgr_set_string (dialog->account_manager, account_name,
1371 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1374 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1375 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1376 modest_account_mgr_set_int (dialog->account_manager, account_name,
1377 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1379 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1380 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1381 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1386 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1387 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1388 g_assert (incoming_account_name);
1390 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1391 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1392 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1396 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1397 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1399 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1400 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1403 gint port_num = hildon_number_editor_get_value (
1404 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1405 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1406 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1408 /* The UI spec says:
1409 * If secure authentication is unchecked, allow sending username and password also as plain text.
1410 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1413 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1414 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1415 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1417 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1420 g_free (incoming_account_name);
1423 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1424 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1425 g_assert (outgoing_account_name);
1427 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1428 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1429 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1433 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1434 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1437 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1438 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1441 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1442 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1443 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1445 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1446 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1447 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1450 port_num = hildon_number_editor_get_value (
1451 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1452 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1453 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1455 g_free (outgoing_account_name);
1458 /* Set the changed account title last, to simplify the previous code: */
1459 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1460 if ((!account_title) || (strlen(account_title) == 0))
1461 return FALSE; /* Should be prevented already anyway. */
1463 if (strcmp(account_title, account_name) != 0) {
1464 /* Change the title: */
1465 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1466 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1471 /* Save connection-specific SMTP server accounts: */
1472 if (dialog->specific_window) {
1473 return modest_connection_specific_smtp_window_save_server_accounts (
1474 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1480 static gboolean entry_is_empty (GtkWidget *entry)
1485 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1486 if ((!text) || (strlen(text) == 0))
1493 enable_buttons (ModestAccountSettingsDialog *self)
1495 gboolean enable_ok = TRUE;
1497 /* The account details title is mandatory: */
1498 if (entry_is_empty(self->entry_account_title))
1501 /* The user details username is mandatory: */
1502 if (entry_is_empty(self->entry_user_username))
1505 /* The user details email address is mandatory: */
1506 if (enable_ok && entry_is_empty (self->entry_user_email))
1509 /* The custom incoming server is mandatory: */
1510 if (entry_is_empty(self->entry_incomingserver))
1513 /* Enable the buttons,
1514 * identifying them via their associated response codes:
1516 GtkDialog *dialog_base = GTK_DIALOG (self);
1517 gtk_dialog_set_response_sensitive (dialog_base,
1523 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1525 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1526 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1529 object_class->get_property = modest_account_settings_dialog_get_property;
1530 object_class->set_property = modest_account_settings_dialog_set_property;
1531 object_class->dispose = modest_account_settings_dialog_dispose;
1532 object_class->finalize = modest_account_settings_dialog_finalize;
1536 show_error (GtkWidget *parent_widget, const gchar* text)
1538 hildon_banner_show_information(parent_widget, NULL, text);
1541 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_widget, text);
1543 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1550 gtk_dialog_run (dialog);
1551 gtk_widget_destroy (GTK_WIDGET (dialog));