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 (GtkWindow *parent_window, const gchar* text);
145 show_ok (GtkWindow *parent_window, const gchar* text);
148 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
151 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
154 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
156 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
157 self->modified = TRUE;
161 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
163 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
164 self->modified = TRUE;
168 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
170 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
171 self->modified = TRUE;
175 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
177 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
178 self->modified = TRUE;
181 /* Set a modified boolean whenever the widget is changed,
182 * so we can check for it later.
185 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
187 if (HILDON_IS_NUMBER_EDITOR (widget)) {
188 g_signal_connect (G_OBJECT (widget), "notify::value",
189 G_CALLBACK (on_modified_number_editor_changed), self);
191 else if (GTK_IS_ENTRY (widget)) {
192 g_signal_connect (G_OBJECT (widget), "changed",
193 G_CALLBACK (on_modified_entry_changed), self);
194 } else if (GTK_IS_COMBO_BOX (widget)) {
195 g_signal_connect (G_OBJECT (widget), "changed",
196 G_CALLBACK (on_modified_combobox_changed), self);
197 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
198 g_signal_connect (G_OBJECT (widget), "toggled",
199 G_CALLBACK (on_modified_checkbox_toggled), self);
204 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
206 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
208 enable_buttons(self);
212 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
214 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
216 enable_buttons(self);
219 /** This is a convenience function to create a caption containing a mandatory widget.
220 * When the widget is edited, the enable_buttons() vfunc will be called.
222 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
227 HildonCaptionStatus flag)
229 GtkWidget *caption = NULL;
231 /* Note: Previously, the translated strings already contained the "*",
232 * Comment out this code if they do again.
234 /* Add a * character to indicate mandatory fields,
235 * as specified in our "Email UI Specification": */
236 if (flag == HILDON_CAPTION_MANDATORY) {
237 gchar* title = g_strdup_printf("%s*", value);
238 caption = hildon_caption_new (group, title, control, icon, flag);
242 caption = hildon_caption_new (group, value, control, icon, flag);
244 /* Connect to the appropriate changed signal for the widget,
245 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
247 if (GTK_IS_ENTRY (control)) {
248 g_signal_connect (G_OBJECT (control), "changed",
249 G_CALLBACK (on_caption_entry_changed), self);
252 else if (GTK_IS_COMBO_BOX (control)) {
253 g_signal_connect (G_OBJECT (control), "changed",
254 G_CALLBACK (on_caption_combobox_changed), self);
262 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
264 ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
265 show_error (GTK_WINDOW (dialog), _CS("ckdg_ib_maximum_characters_reached"));
269 create_page_account_details (ModestAccountSettingsDialog *self)
271 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
272 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
273 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
274 gtk_widget_show (label);
276 /* Create a size group to be used by all captions.
277 * Note that HildonCaption does not create a default size group if we do not specify one.
278 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
279 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
281 /* The description widgets: */
282 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
283 /* Do use auto-capitalization: */
284 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
285 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
286 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
287 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
288 gtk_widget_show (self->entry_account_title);
289 connect_for_modified (self, self->entry_account_title);
290 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
291 gtk_widget_show (caption);
293 /* Prevent the use of some characters in the account title,
294 * as required by our UI specification: */
295 GList *list_prevent = NULL;
296 list_prevent = g_list_append (list_prevent, "\\");
297 list_prevent = g_list_append (list_prevent, "/");
298 list_prevent = g_list_append (list_prevent, ":");
299 list_prevent = g_list_append (list_prevent, "*");
300 list_prevent = g_list_append (list_prevent, "?");
301 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
302 list_prevent = g_list_append (list_prevent, "“");
303 list_prevent = g_list_append (list_prevent, "<");
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 modest_validating_entry_set_unallowed_characters (
308 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
309 g_list_free (list_prevent);
311 /* Set max length as in the UI spec:
312 * The UI spec seems to want us to show a dialog if we hit the maximum. */
313 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
314 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
317 /* The retrieve combobox: */
318 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
319 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
320 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
321 gtk_widget_show (self->combo_retrieve);
322 connect_for_modified (self, self->combo_retrieve);
323 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
324 gtk_widget_show (caption);
326 /* The limit-retrieve combobox: */
327 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
328 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
329 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
330 gtk_widget_show (self->combo_limit_retrieve);
331 connect_for_modified (self, self->combo_limit_retrieve);
332 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
333 gtk_widget_show (caption);
335 /* The leave-messages widgets: */
336 if(!self->checkbox_leave_messages)
337 self->checkbox_leave_messages = gtk_check_button_new ();
338 if (!self->caption_leave_messages) {
339 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
340 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
343 gtk_widget_show (self->checkbox_leave_messages);
344 connect_for_modified (self, self->checkbox_leave_messages);
345 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
346 gtk_widget_show (self->caption_leave_messages);
348 gtk_widget_show (GTK_WIDGET (box));
350 return GTK_WIDGET (box);
354 on_button_signature (GtkButton *button, gpointer user_data)
356 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
358 /* Create the window, if necessary: */
359 if (!(self->signature_dialog)) {
360 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
362 gboolean use_signature = FALSE;
363 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
365 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
366 modest_signature_editor_dialog_set_settings (
367 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
368 use_signature, signature, account_title);
373 /* Show the window: */
374 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
375 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
376 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
377 gtk_widget_hide (self->signature_dialog);
378 if (response != GTK_RESPONSE_OK) {
379 /* Destroy the widget now, and its data: */
380 gtk_widget_destroy (self->signature_dialog);
381 self->signature_dialog = NULL;
384 /* Mark modified, so we use the dialog's data later: */
385 self->modified = TRUE;
390 create_page_user_details (ModestAccountSettingsDialog *self)
392 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
394 /* Create a size group to be used by all captions.
395 * Note that HildonCaption does not create a default size group if we do not specify one.
396 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
397 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
399 /* The name widgets: */
400 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
401 /* Auto-capitalization is the default, so let's turn it off: */
402 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
403 /* Set max length as in the UI spec:
404 * The UI spec seems to want us to show a dialog if we hit the maximum. */
405 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
406 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
408 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
409 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
410 gtk_widget_show (self->entry_user_name);
411 connect_for_modified (self, self->entry_user_name);
412 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
413 gtk_widget_show (caption);
415 /* Prevent the use of some characters in the name,
416 * as required by our UI specification: */
417 GList *list_prevent = NULL;
418 list_prevent = g_list_append (list_prevent, "<");
419 list_prevent = g_list_append (list_prevent, ">");
420 modest_validating_entry_set_unallowed_characters (
421 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
422 g_list_free (list_prevent);
424 /* The username widgets: */
425 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
426 /* Auto-capitalization is the default, so let's turn it off: */
427 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
428 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
429 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
430 gtk_widget_show (self->entry_user_username);
431 connect_for_modified (self, self->entry_user_username);
432 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
433 gtk_widget_show (caption);
435 /* Prevent the use of some characters in the username,
436 * as required by our UI specification: */
437 modest_validating_entry_set_unallowed_characters_whitespace (
438 MODEST_VALIDATING_ENTRY (self->entry_user_username));
440 /* Set max length as in the UI spec:
441 * The UI spec seems to want us to show a dialog if we hit the maximum. */
442 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
443 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
446 /* The password widgets: */
447 self->entry_user_password = gtk_entry_new ();
448 /* Auto-capitalization is the default, so let's turn it off: */
449 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
450 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
451 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
452 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
453 caption = create_caption_new_with_asterisk (self, sizegroup,
454 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
455 gtk_widget_show (self->entry_user_password);
456 connect_for_modified (self, self->entry_user_password);
457 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
458 gtk_widget_show (caption);
460 /* The email address widgets: */
461 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
462 /* Auto-capitalization is the default, so let's turn it off: */
463 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
464 caption = create_caption_new_with_asterisk (self, sizegroup,
465 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
466 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
467 gtk_widget_show (self->entry_user_email);
468 connect_for_modified (self, self->entry_user_email);
469 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
470 gtk_widget_show (caption);
472 /* Set max length as in the UI spec:
473 * The UI spec seems to want us to show a dialog if we hit the maximum. */
474 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
475 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
478 /* Signature button: */
479 if (!self->button_signature)
480 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
481 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
482 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
483 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
484 gtk_widget_show (self->button_signature);
485 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
486 gtk_widget_show (caption);
488 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
489 G_CALLBACK (on_button_signature), self);
491 gtk_widget_show (GTK_WIDGET (box));
493 return GTK_WIDGET (box);
496 /** Change the caption title for the incoming server,
497 * as specified in the UI spec:
499 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
502 (protocol == MODEST_PROTOCOL_STORE_POP ?
503 _("mail_fi_emailtype_pop3") :
504 _("mail_fi_emailtype_imap") );
507 /* Note that this produces a compiler warning,
508 * because the compiler does not know that the translated string will have a %s in it.
509 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
510 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
512 /* This is a mandatory field, so add a *. This is usually done by
513 * create_caption_new_with_asterisk() but we can't use that here. */
514 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
515 g_free (incomingserver_title);
517 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
518 g_free(with_asterisk);
521 /** Change the caption title for the incoming server,
522 * as specified in the UI spec:
524 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
526 /* Fill the combo with appropriately titled choices for POP or IMAP. */
527 /* The choices are the same, but the titles are different, as in the UI spec. */
528 modest_serversecurity_combo_box_fill (
529 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
532 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
534 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
536 /* Create a size group to be used by all captions.
537 * Note that HildonCaption does not create a default size group if we do not specify one.
538 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
539 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
541 /* The incoming server widgets: */
542 if(!self->entry_incomingserver)
543 self->entry_incomingserver = gtk_entry_new ();
544 /* Auto-capitalization is the default, so let's turn it off: */
545 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
547 if (self->caption_incoming)
548 gtk_widget_destroy (self->caption_incoming);
550 /* The caption title will be updated in update_incoming_server_title().
551 * so this default text will never be seen: */
552 /* (Note: Changing the title seems pointless. murrayc) */
553 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
554 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
555 gtk_widget_show (self->entry_incomingserver);
556 connect_for_modified (self, self->entry_incomingserver);
557 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
558 gtk_widget_show (self->caption_incoming);
560 /* The secure connection widgets: */
561 /* This will be filled by update_incoming_server_security_choices(). */
562 if (!self->combo_incoming_security)
563 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
564 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
565 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
566 gtk_widget_show (self->combo_incoming_security);
567 connect_for_modified (self, self->combo_incoming_security);
568 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
569 gtk_widget_show (caption);
571 /* Show a default port number when the security method changes, as per the UI spec: */
572 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
575 /* The port widgets: */
576 /* TODO: There are various rules about this in the UI spec. */
577 if (!self->entry_incoming_port)
578 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
579 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
580 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
581 gtk_widget_show (self->entry_incoming_port);
582 connect_for_modified (self, self->entry_incoming_port);
583 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
584 gtk_widget_show (caption);
586 /* The secure authentication widgets: */
587 if(!self->checkbox_incoming_auth)
588 self->checkbox_incoming_auth = gtk_check_button_new ();
589 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
590 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
591 gtk_widget_show (self->checkbox_incoming_auth);
592 connect_for_modified (self, self->checkbox_incoming_auth);
593 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
594 gtk_widget_show (caption);
596 gtk_widget_show (GTK_WIDGET (box));
598 return GTK_WIDGET (box);
602 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
604 GtkWidget *widget = GTK_WIDGET (user_data);
606 /* Enable the widget only if the toggle button is active: */
607 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
608 gtk_widget_set_sensitive (widget, enable);
611 /* Make the sensitivity of a widget depend on a toggle button.
614 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
616 g_signal_connect (G_OBJECT (button), "toggled",
617 G_CALLBACK (on_toggle_button_changed), widget);
619 /* Set the starting sensitivity: */
620 on_toggle_button_changed (button, widget);
624 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
626 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
628 /* Create the window if necessary: */
629 if (!(self->specific_window)) {
630 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
631 modest_connection_specific_smtp_window_fill_with_connections (
632 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
636 /* Show the window: */
637 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
638 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
639 gtk_widget_show (self->specific_window);
643 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
645 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
647 ModestAuthProtocol protocol_security =
648 modest_secureauth_combo_box_get_active_secureauth (
649 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
650 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
652 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
653 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
657 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
659 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
661 const gint port_number =
662 modest_serversecurity_combo_box_get_active_serversecurity_port (
663 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
665 if(port_number != 0) {
666 hildon_number_editor_set_value (
667 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
672 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
674 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
676 const gint port_number =
677 modest_serversecurity_combo_box_get_active_serversecurity_port (
678 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
680 if(port_number != 0) {
681 hildon_number_editor_set_value (
682 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
687 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
689 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
691 /* Create a size group to be used by all captions.
692 * Note that HildonCaption does not create a default size group if we do not specify one.
693 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
694 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
696 /* The outgoing server widgets: */
697 if (!self->entry_outgoingserver)
698 self->entry_outgoingserver = gtk_entry_new ();
699 /* Auto-capitalization is the default, so let's turn it off: */
700 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
701 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
702 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
703 gtk_widget_show (self->entry_outgoingserver);
704 connect_for_modified (self, self->entry_outgoingserver);
705 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
706 gtk_widget_show (caption);
708 /* The secure authentication widgets: */
709 if (!self->combo_outgoing_auth)
710 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
711 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
712 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
713 gtk_widget_show (self->combo_outgoing_auth);
714 connect_for_modified (self, self->combo_outgoing_auth);
715 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
716 gtk_widget_show (caption);
718 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
719 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
721 /* The username widgets: */
722 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
723 /* Auto-capitalization is the default, so let's turn it off: */
724 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
725 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
726 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
727 gtk_widget_show (self->entry_outgoing_username);
728 connect_for_modified (self, self->entry_outgoing_username);
729 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
730 gtk_widget_show (self->caption_outgoing_username);
732 /* Prevent the use of some characters in the username,
733 * as required by our UI specification: */
734 modest_validating_entry_set_unallowed_characters_whitespace (
735 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
737 /* Set max length as in the UI spec:
738 * The UI spec seems to want us to show a dialog if we hit the maximum. */
739 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
740 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
743 /* The password widgets: */
744 self->entry_outgoing_password = gtk_entry_new ();
745 /* Auto-capitalization is the default, so let's turn it off: */
746 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
747 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
748 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
749 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
750 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
751 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
752 gtk_widget_show (self->entry_outgoing_password);
753 connect_for_modified (self, self->entry_outgoing_password);
754 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
755 gtk_widget_show (self->caption_outgoing_password);
757 /* The secure connection widgets: */
758 /* This will be filled and set with modest_serversecurity_combo_box_fill()
759 * and modest_serversecurity_combo_box_set_active_serversecurity().
761 if (!self->combo_outgoing_security)
763 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
764 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
765 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
766 gtk_widget_show (self->combo_outgoing_security);
767 connect_for_modified (self, self->combo_outgoing_security);
768 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
769 gtk_widget_show (caption);
771 /* Show a default port number when the security method changes, as per the UI spec: */
772 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
774 /* The port widgets: */
775 if (!self->entry_outgoing_port)
776 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
777 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
778 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
779 gtk_widget_show (self->entry_outgoing_port);
780 connect_for_modified (self, self->entry_outgoing_port);
781 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
782 gtk_widget_show (caption);
784 GtkWidget *separator = gtk_hseparator_new ();
785 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
786 gtk_widget_show (separator);
788 /* connection-specific checkbox: */
789 if (!self->checkbox_outgoing_smtp_specific) {
790 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
791 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
794 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
795 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
796 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
797 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
798 gtk_widget_show (caption);
799 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
801 /* Connection-specific SMTP-Severs Edit button: */
802 if (!self->button_outgoing_smtp_servers)
803 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
804 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
805 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
806 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
807 gtk_widget_show (self->button_outgoing_smtp_servers);
808 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
809 gtk_widget_show (caption);
811 /* Only enable the button when the checkbox is checked: */
812 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
813 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
815 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
816 G_CALLBACK (on_button_outgoing_smtp_servers), self);
818 gtk_widget_show (GTK_WIDGET (box));
820 return GTK_WIDGET (box);
824 check_data (ModestAccountSettingsDialog *self)
826 /* Check that the title is not already in use: */
827 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
828 if ((!account_title) || (strlen(account_title) == 0))
829 return FALSE; /* Should be prevented already anyway. */
831 if (strcmp(account_title, self->original_account_title) != 0) {
832 /* Check the changed title: */
833 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
837 /* Warn the user via a dialog: */
838 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
844 /* Check that the email address is valud: */
845 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
846 if ((!email_address) || (strlen(email_address) == 0))
849 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
850 /* Warn the user via a dialog: */
851 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
852 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
854 /* Return focus to the email address entry: */
855 gtk_widget_grab_focus (self->entry_user_email);
856 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
860 /* Find a suitable authentication method when secure authentication is desired */
861 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
862 gint port_num = hildon_number_editor_get_value (
863 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
864 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
866 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
867 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
869 /* If we use an encrypted protocol then there is no need to encrypt the password */
870 if (!modest_protocol_info_is_secure(protocol_security_incoming))
872 if (gtk_toggle_button_get_active (
873 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
874 GError *error = NULL;
875 GList *list_auth_methods =
876 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
877 hostname, port_num, username, GTK_WINDOW (self), &error);
878 if (list_auth_methods) {
879 /* Use the first supported method.
880 * TODO: Should we prioritize them, to prefer a particular one? */
882 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
884 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
885 // Allow secure methods, e.g MD5 only
886 if (modest_protocol_info_auth_is_secure(proto))
888 self->protocol_authentication_incoming = proto;
892 g_list_free (list_auth_methods);
895 if (list_auth_methods == NULL ||
896 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
898 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
899 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
901 show_error (GTK_WINDOW (self), _("Could not discover supported secure authentication methods."));
907 /* This is a nasty hack. jschmid. */
908 /* Don't let the dialog close */
909 /*g_signal_stop_emission_by_name (dialog, "response");*/
915 /* TODO: The UI Spec wants us to check that the servernames are valid,
916 * but does not specify how.
924 on_response (GtkDialog *wizard_dialog,
928 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
929 enable_buttons (self);
931 gboolean prevent_response = FALSE;
933 /* Warn about unsaved changes: */
934 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
935 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
936 _("imum_nc_wizard_confirm_lose_changes")));
937 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
939 const gint dialog_response = gtk_dialog_run (dialog);
940 gtk_widget_destroy (GTK_WIDGET (dialog));
942 if (dialog_response != GTK_RESPONSE_OK)
943 prevent_response = TRUE;
945 /* Check for invalid input: */
946 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
947 prevent_response = TRUE;
950 if (prevent_response) {
951 /* This is a nasty hack. murrayc. */
952 /* Don't let the dialog close */
953 g_signal_stop_emission_by_name (wizard_dialog, "response");
957 if (response_id == GTK_RESPONSE_OK) {
958 /* Try to save the changes if modified (NB #59251): */
961 const gboolean saved = save_configuration (self);
963 /* Do not show the account-saved dialog if we are just saving this
964 * temporarily, because from the user's point of view it will not
965 * really be saved (saved + enabled) until later.
967 const gboolean enabled =
968 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
970 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
973 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
979 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
981 /* Create the notebook to be used by the GtkDialog base class:
982 * Each page of the notebook will be a page of the wizard: */
983 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
985 /* Get the account manager object,
986 * so we can check for existing accounts,
987 * and create new accounts: */
988 self->account_manager = modest_runtime_get_account_mgr ();
989 g_assert (self->account_manager);
990 g_object_ref (self->account_manager);
992 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
994 /* Create the common pages,
996 self->page_account_details = create_page_account_details (self);
997 self->page_user_details = create_page_user_details (self);
998 self->page_incoming = create_page_incoming (self);
999 self->page_outgoing = create_page_outgoing (self);
1001 /* Add the notebook pages: */
1002 gtk_notebook_append_page (self->notebook, self->page_account_details,
1003 gtk_label_new (_("mcen_ti_account_settings_account")));
1004 gtk_notebook_append_page (self->notebook, self->page_user_details,
1005 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1006 gtk_notebook_append_page (self->notebook, self->page_incoming,
1007 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1008 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1009 gtk_label_new (_("mcen_ti_advsetup_sending")));
1011 GtkDialog *dialog = GTK_DIALOG (self);
1012 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1013 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1014 gtk_widget_show (GTK_WIDGET (self->notebook));
1016 /* Add the buttons: */
1017 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1018 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1020 /* Connect to the dialog's response signal: */
1021 /* We use connect-before
1022 * so we can stop the signal emission,
1023 * to stop the default signal handler from closing the dialog.
1025 g_signal_connect (G_OBJECT (self), "response",
1026 G_CALLBACK (on_response), self);
1028 self->modified = FALSE;
1030 /* When this window is shown, hibernation should not be possible,
1031 * because there is no sensible way to save the state: */
1032 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1033 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1036 ModestAccountSettingsDialog*
1037 modest_account_settings_dialog_new (void)
1039 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1042 /** Update the UI with the stored account details, so they can be edited.
1043 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1045 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1050 /* Save the account name so we can refer to it later: */
1051 if (dialog->account_name)
1052 g_free (dialog->account_name);
1053 dialog->account_name = g_strdup (account_name);
1056 /* Get the account data for this account name: */
1057 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1059 if (!account_data) {
1060 g_printerr ("modest: failed to get account data for %s\n", account_name);
1064 /* Save the account title so we can refer to it if the user changes it: */
1065 if (dialog->original_account_title)
1066 g_free (dialog->original_account_title);
1067 dialog->original_account_title = g_strdup (account_data->display_name);
1070 if (!(account_data->store_account)) {
1071 g_printerr ("modest: account has no stores: %s\n", account_name);
1075 /* Show the account data in the widgets: */
1077 /* Note that we never show the non-display name in the UI.
1078 * (Though the display name defaults to the non-display name at the start.) */
1079 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1080 account_data->display_name ? account_data->display_name : "");
1082 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1083 account_data->fullname ? account_data->fullname : "");
1084 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1085 account_data->email ? account_data->email : "");
1087 ModestServerAccountData *incoming_account = account_data->store_account;
1089 if (incoming_account)
1090 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1091 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1092 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1094 /* Default to something, though no default is specified in the UI spec: */
1095 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1097 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1100 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1101 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1102 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1105 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1106 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1107 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1109 /* Only show the leave-on-server checkbox for POP,
1110 * as per the UI spec: */
1111 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1112 gtk_widget_hide (dialog->caption_leave_messages);
1114 gtk_widget_show (dialog->caption_leave_messages);
1117 update_incoming_server_security_choices (dialog, incoming_account->proto);
1118 if (incoming_account) {
1119 /* Remember this for later: */
1120 dialog->incoming_protocol = incoming_account->proto;
1122 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1123 incoming_account->username ? incoming_account->username : "");
1124 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1125 incoming_account->password ? incoming_account->password : "");
1127 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1128 incoming_account->hostname ? incoming_account->hostname : "");
1130 /* The UI spec says:
1131 * If secure authentication is unchecked, allow sending username and password also as plain text.
1132 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1133 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1135 const ModestConnectionProtocol security = modest_server_account_get_security (
1136 dialog->account_manager, incoming_account->account_name);
1137 modest_serversecurity_combo_box_set_active_serversecurity (
1138 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1143 - use encrypted passwords
1145 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1146 dialog->account_manager, incoming_account->account_name);
1147 dialog->protocol_authentication_incoming = secure_auth;
1148 if (modest_protocol_info_is_secure(security) ||
1149 modest_protocol_info_auth_is_secure(secure_auth))
1151 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1156 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1160 update_incoming_server_title (dialog, incoming_account->proto);
1162 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1163 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1165 if (port_num == 0) {
1166 /* Show the appropriate port number: */
1167 on_combo_incoming_security_changed (
1168 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1170 /* Keep the user-entered port-number,
1171 * or the already-appropriate automatic port number: */
1172 hildon_number_editor_set_value (
1173 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1177 ModestServerAccountData *outgoing_account = account_data->transport_account;
1178 if (outgoing_account) {
1179 /* Remember this for later: */
1180 dialog->outgoing_protocol = outgoing_account->proto;
1182 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1183 outgoing_account->hostname ? outgoing_account->hostname : "");
1185 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1186 outgoing_account->username ? outgoing_account->username : "");
1187 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1188 outgoing_account->password ? outgoing_account->password : "");
1190 /* Get the secure-auth setting: */
1191 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1192 dialog->account_manager, outgoing_account->account_name);
1193 modest_secureauth_combo_box_set_active_secureauth (
1194 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1195 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1197 modest_serversecurity_combo_box_fill (
1198 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1200 /* Get the security setting: */
1201 const ModestConnectionProtocol security = modest_server_account_get_security (
1202 dialog->account_manager, outgoing_account->account_name);
1203 modest_serversecurity_combo_box_set_active_serversecurity (
1204 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1206 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1207 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1208 if (port_num == 0) {
1209 /* Show the appropriate port number: */
1210 on_combo_outgoing_security_changed (
1211 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1214 /* Keep the user-entered port-number,
1215 * or the already-appropriate automatic port number: */
1216 hildon_number_editor_set_value (
1217 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1220 const gboolean has_specific =
1221 modest_account_mgr_get_has_connection_specific_smtp (
1222 dialog->account_manager,
1224 gtk_toggle_button_set_active (
1225 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1229 /* Set window title according to account: */
1230 /* TODO: Is this the correct way to find a human-readable name for
1231 * the protocol used? */
1232 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1233 gchar *proto_name = g_utf8_strup(proto_str, -1);
1234 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1236 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1237 g_free (proto_name);
1238 g_free (account_title);
1240 gtk_window_set_title (GTK_WINDOW (dialog), title);
1243 /* account_data->is_enabled, */
1244 /*account_data->is_default, */
1246 /* account_data->store_account->proto */
1248 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1250 /* Unset the modified flag so we can detect changes later: */
1251 dialog->modified = FALSE;
1254 /** Show the User Info tab.
1256 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1258 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1259 if (page_num == -1) {
1260 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1263 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1264 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1266 gtk_widget_show (dialog->page_user_details);
1267 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1268 gtk_widget_show (GTK_WIDGET (dialog));
1269 gtk_notebook_set_current_page (dialog->notebook, page_num);
1273 save_configuration (ModestAccountSettingsDialog *dialog)
1275 g_assert (dialog->account_name);
1277 const gchar* account_name = dialog->account_name;
1279 /* Set the account data from the widgets: */
1280 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1281 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1282 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1286 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1287 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1288 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1293 if (dialog->signature_dialog) {
1294 gboolean use_signature = FALSE;
1295 gchar *signature = modest_signature_editor_dialog_get_settings (
1296 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1299 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1300 signature, use_signature);
1304 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1305 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1306 modest_account_mgr_set_string (dialog->account_manager, account_name,
1307 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1310 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1311 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1312 modest_account_mgr_set_int (dialog->account_manager, account_name,
1313 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1315 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1316 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1317 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1322 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1323 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1324 g_assert (incoming_account_name);
1326 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1327 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1328 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1332 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1333 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1335 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1336 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1339 gint port_num = hildon_number_editor_get_value (
1340 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1341 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1342 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1344 /* The UI spec says:
1345 * If secure authentication is unchecked, allow sending username and password also as plain text.
1346 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1349 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1350 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1351 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1353 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1356 g_free (incoming_account_name);
1359 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1360 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1361 g_assert (outgoing_account_name);
1363 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1364 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1365 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1369 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1370 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1373 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1374 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1377 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1378 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1379 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1381 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1382 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1383 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1386 port_num = hildon_number_editor_get_value (
1387 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1388 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1389 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1391 g_free (outgoing_account_name);
1394 /* Set the changed account title last, to simplify the previous code: */
1395 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1396 if ((!account_title) || (strlen(account_title) == 0))
1397 return FALSE; /* Should be prevented already anyway. */
1399 if (strcmp(account_title, account_name) != 0) {
1400 /* Change the title: */
1401 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1402 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1407 /* Save connection-specific SMTP server accounts: */
1408 if (dialog->specific_window) {
1409 return modest_connection_specific_smtp_window_save_server_accounts (
1410 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1416 static gboolean entry_is_empty (GtkWidget *entry)
1421 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1422 if ((!text) || (strlen(text) == 0))
1429 enable_buttons (ModestAccountSettingsDialog *self)
1431 gboolean enable_ok = TRUE;
1433 /* The account details title is mandatory: */
1434 if (entry_is_empty(self->entry_account_title))
1437 /* The user details username is mandatory: */
1438 if (entry_is_empty(self->entry_user_username))
1441 /* The user details email address is mandatory: */
1442 if (enable_ok && entry_is_empty (self->entry_user_email))
1445 /* The custom incoming server is mandatory: */
1446 if (entry_is_empty(self->entry_incomingserver))
1449 /* Enable the buttons,
1450 * identifying them via their associated response codes:
1452 GtkDialog *dialog_base = GTK_DIALOG (self);
1453 gtk_dialog_set_response_sensitive (dialog_base,
1459 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1461 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1462 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1465 object_class->get_property = modest_account_settings_dialog_get_property;
1466 object_class->set_property = modest_account_settings_dialog_set_property;
1467 object_class->dispose = modest_account_settings_dialog_dispose;
1468 object_class->finalize = modest_account_settings_dialog_finalize;
1472 show_error (GtkWindow *parent_window, const gchar* text)
1474 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1476 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1483 gtk_dialog_run (dialog);
1484 gtk_widget_destroy (GTK_WIDGET (dialog));
1488 show_ok (GtkWindow *parent_window, const gchar* text)
1490 /* Don't show a dialog but Banner (NB #59248) */
1491 hildon_banner_show_information(GTK_WIDGET(
1492 gtk_widget_get_parent_window(GTK_WIDGET(parent_window))), NULL, text);