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
87 enable_buttons (ModestAccountSettingsDialog *self);
90 save_configuration (ModestAccountSettingsDialog *dialog);
93 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
94 GValue *value, GParamSpec *pspec)
96 switch (property_id) {
98 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
103 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
104 const GValue *value, GParamSpec *pspec)
106 switch (property_id) {
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
113 modest_account_settings_dialog_dispose (GObject *object)
115 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
116 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
120 modest_account_settings_dialog_finalize (GObject *object)
122 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
124 if (self->account_name)
125 g_free (self->account_name);
127 if (self->original_account_title)
128 g_free (self->original_account_title);
130 if (self->account_manager)
131 g_object_unref (G_OBJECT (self->account_manager));
133 if (self->specific_window)
134 gtk_widget_destroy (self->specific_window);
136 if (self->signature_dialog)
137 gtk_widget_destroy (self->signature_dialog);
139 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
143 show_error (GtkWindow *parent_window, const gchar* text);
146 show_ok (GtkWindow *parent_window, const gchar* text);
149 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
152 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
155 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
157 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
158 self->modified = TRUE;
162 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
164 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
165 self->modified = TRUE;
169 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
171 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
172 self->modified = TRUE;
175 /* Set a modified boolean whenever the widget is changed,
176 * so we can check for it later.
179 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
181 if (GTK_IS_ENTRY (widget)) {
182 g_signal_connect (G_OBJECT (widget), "changed",
183 G_CALLBACK (on_modified_entry_changed), self);
184 } else if (GTK_IS_COMBO_BOX (widget)) {
185 g_signal_connect (G_OBJECT (widget), "changed",
186 G_CALLBACK (on_modified_combobox_changed), self);
187 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
188 g_signal_connect (G_OBJECT (widget), "toggled",
189 G_CALLBACK (on_modified_checkbox_toggled), self);
194 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
196 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
198 enable_buttons(self);
202 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
204 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
206 enable_buttons(self);
209 /** This is a convenience function to create a caption containing a mandatory widget.
210 * When the widget is edited, the enable_buttons() vfunc will be called.
212 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
217 HildonCaptionStatus flag)
219 GtkWidget *caption = NULL;
221 /* Note: Previously, the translated strings already contained the "*",
222 * Comment out this code if they do again.
224 /* Add a * character to indicate mandatory fields,
225 * as specified in our "Email UI Specification": */
226 if (flag == HILDON_CAPTION_MANDATORY) {
227 gchar* title = g_strdup_printf("%s*", value);
228 caption = hildon_caption_new (group, title, control, icon, flag);
232 caption = hildon_caption_new (group, value, control, icon, flag);
234 /* Connect to the appropriate changed signal for the widget,
235 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
237 if (GTK_IS_ENTRY (control)) {
238 g_signal_connect (G_OBJECT (control), "changed",
239 G_CALLBACK (on_caption_entry_changed), self);
242 else if (GTK_IS_COMBO_BOX (control)) {
243 g_signal_connect (G_OBJECT (control), "changed",
244 G_CALLBACK (on_caption_combobox_changed), self);
252 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
254 ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
255 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
259 create_page_account_details (ModestAccountSettingsDialog *self)
261 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
262 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
263 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
264 gtk_widget_show (label);
266 /* Create a size group to be used by all captions.
267 * Note that HildonCaption does not create a default size group if we do not specify one.
268 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
269 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
271 /* The description widgets: */
272 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
273 /* Do use auto-capitalization: */
274 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
275 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
276 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
277 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
278 gtk_widget_show (self->entry_account_title);
279 connect_for_modified (self, self->entry_account_title);
280 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
281 gtk_widget_show (caption);
283 /* Prevent the use of some characters in the account title,
284 * as required by our UI specification: */
285 GList *list_prevent = NULL;
286 list_prevent = g_list_append (list_prevent, "\\");
287 list_prevent = g_list_append (list_prevent, "/");
288 list_prevent = g_list_append (list_prevent, ":");
289 list_prevent = g_list_append (list_prevent, "*");
290 list_prevent = g_list_append (list_prevent, "?");
291 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
292 list_prevent = g_list_append (list_prevent, "“");
293 list_prevent = g_list_append (list_prevent, "<");
294 list_prevent = g_list_append (list_prevent, ">");
295 list_prevent = g_list_append (list_prevent, "|");
296 list_prevent = g_list_append (list_prevent, "^");
297 modest_validating_entry_set_unallowed_characters (
298 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
299 g_list_free (list_prevent);
301 /* Set max length as in the UI spec:
302 * The UI spec seems to want us to show a dialog if we hit the maximum. */
303 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
304 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
307 /* The retrieve combobox: */
308 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
309 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
310 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
311 gtk_widget_show (self->combo_retrieve);
312 connect_for_modified (self, self->combo_retrieve);
313 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
314 gtk_widget_show (caption);
316 /* The limit-retrieve combobox: */
317 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
318 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
319 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
320 gtk_widget_show (self->combo_limit_retrieve);
321 connect_for_modified (self, self->combo_limit_retrieve);
322 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
323 gtk_widget_show (caption);
325 /* The leave-messages widgets: */
326 if(!self->checkbox_leave_messages)
327 self->checkbox_leave_messages = gtk_check_button_new ();
328 if (!self->caption_leave_messages) {
329 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
330 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
333 gtk_widget_show (self->checkbox_leave_messages);
334 connect_for_modified (self, self->checkbox_leave_messages);
335 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
336 gtk_widget_show (self->caption_leave_messages);
338 gtk_widget_show (GTK_WIDGET (box));
340 return GTK_WIDGET (box);
344 on_button_signature (GtkButton *button, gpointer user_data)
346 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
348 /* Create the window, if necessary: */
349 if (!(self->signature_dialog)) {
350 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
352 gboolean use_signature = FALSE;
353 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
355 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
356 modest_signature_editor_dialog_set_settings (
357 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
358 use_signature, signature, account_title);
363 /* Show the window: */
364 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
365 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
366 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
367 gtk_widget_hide (self->signature_dialog);
368 if (response != GTK_RESPONSE_OK) {
369 /* Destroy the widget now, and its data: */
370 gtk_widget_destroy (self->signature_dialog);
371 self->signature_dialog = NULL;
374 /* Mark modified, so we use the dialog's data later: */
375 self->modified = TRUE;
380 create_page_user_details (ModestAccountSettingsDialog *self)
382 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
384 /* Create a size group to be used by all captions.
385 * Note that HildonCaption does not create a default size group if we do not specify one.
386 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
387 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
389 /* The name widgets: */
390 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
391 /* Auto-capitalization is the default, so let's turn it off: */
392 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
393 /* Set max length as in the UI spec:
394 * The UI spec seems to want us to show a dialog if we hit the maximum. */
395 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
396 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
398 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
399 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
400 gtk_widget_show (self->entry_user_name);
401 connect_for_modified (self, self->entry_user_name);
402 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
403 gtk_widget_show (caption);
405 /* Prevent the use of some characters in the name,
406 * as required by our UI specification: */
407 GList *list_prevent = NULL;
408 list_prevent = g_list_append (list_prevent, "<");
409 list_prevent = g_list_append (list_prevent, ">");
410 modest_validating_entry_set_unallowed_characters (
411 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
412 g_list_free (list_prevent);
414 /* The username widgets: */
415 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
416 /* Auto-capitalization is the default, so let's turn it off: */
417 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
418 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
419 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
420 gtk_widget_show (self->entry_user_username);
421 connect_for_modified (self, self->entry_user_username);
422 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
423 gtk_widget_show (caption);
425 /* Prevent the use of some characters in the username,
426 * as required by our UI specification: */
427 modest_validating_entry_set_unallowed_characters_whitespace (
428 MODEST_VALIDATING_ENTRY (self->entry_user_username));
430 /* Set max length as in the UI spec:
431 * The UI spec seems to want us to show a dialog if we hit the maximum. */
432 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
433 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
436 /* The password widgets: */
437 self->entry_user_password = gtk_entry_new ();
438 /* Auto-capitalization is the default, so let's turn it off: */
439 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
440 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
441 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
442 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
443 caption = create_caption_new_with_asterisk (self, sizegroup,
444 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
445 gtk_widget_show (self->entry_user_password);
446 connect_for_modified (self, self->entry_user_password);
447 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
448 gtk_widget_show (caption);
450 /* The email address widgets: */
451 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
452 /* Auto-capitalization is the default, so let's turn it off: */
453 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
454 caption = create_caption_new_with_asterisk (self, sizegroup,
455 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
456 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
457 gtk_widget_show (self->entry_user_email);
458 connect_for_modified (self, self->entry_user_email);
459 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
460 gtk_widget_show (caption);
462 /* Set max length as in the UI spec:
463 * The UI spec seems to want us to show a dialog if we hit the maximum. */
464 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
465 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
468 /* Signature button: */
469 if (!self->button_signature)
470 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
471 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
472 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
473 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
474 gtk_widget_show (self->button_signature);
475 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
476 gtk_widget_show (caption);
478 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
479 G_CALLBACK (on_button_signature), self);
481 gtk_widget_show (GTK_WIDGET (box));
483 return GTK_WIDGET (box);
486 /** Change the caption title for the incoming server,
487 * as specified in the UI spec:
489 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
492 (protocol == MODEST_PROTOCOL_STORE_POP ?
493 _("mail_fi_emailtype_pop3") :
494 _("mail_fi_emailtype_imap") );
497 /* Note that this produces a compiler warning,
498 * because the compiler does not know that the translated string will have a %s in it.
499 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
500 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
502 /* This is a mandatory field, so add a *. This is usually done by
503 * create_caption_new_with_asterisk() but we can't use that here. */
504 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
505 g_free (incomingserver_title);
507 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
508 g_free(with_asterisk);
511 /** Change the caption title for the incoming server,
512 * as specified in the UI spec:
514 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
516 /* Fill the combo with appropriately titled choices for POP or IMAP. */
517 /* The choices are the same, but the titles are different, as in the UI spec. */
518 modest_serversecurity_combo_box_fill (
519 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
522 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
524 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
526 /* Create a size group to be used by all captions.
527 * Note that HildonCaption does not create a default size group if we do not specify one.
528 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
529 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
531 /* The incoming server widgets: */
532 if(!self->entry_incomingserver)
533 self->entry_incomingserver = gtk_entry_new ();
534 /* Auto-capitalization is the default, so let's turn it off: */
535 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
537 if (self->caption_incoming)
538 gtk_widget_destroy (self->caption_incoming);
540 /* The caption title will be updated in update_incoming_server_title().
541 * so this default text will never be seen: */
542 /* (Note: Changing the title seems pointless. murrayc) */
543 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
544 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
545 gtk_widget_show (self->entry_incomingserver);
546 connect_for_modified (self, self->entry_incomingserver);
547 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
548 gtk_widget_show (self->caption_incoming);
550 /* The secure connection widgets: */
551 /* This will be filled by update_incoming_server_security_choices(). */
552 if (!self->combo_incoming_security)
553 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
554 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
555 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
556 gtk_widget_show (self->combo_incoming_security);
557 connect_for_modified (self, self->combo_incoming_security);
558 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
559 gtk_widget_show (caption);
561 /* Show a default port number when the security method changes, as per the UI spec: */
562 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
565 /* The port widgets: */
566 /* TODO: There are various rules about this in the UI spec. */
567 if (!self->entry_incoming_port)
568 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
569 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
570 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
571 gtk_widget_show (self->entry_incoming_port);
572 connect_for_modified (self, self->entry_incoming_port);
573 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
574 gtk_widget_show (caption);
576 /* The secure authentication widgets: */
577 if(!self->checkbox_incoming_auth)
578 self->checkbox_incoming_auth = gtk_check_button_new ();
579 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
580 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
581 gtk_widget_show (self->checkbox_incoming_auth);
582 connect_for_modified (self, self->checkbox_incoming_auth);
583 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
584 gtk_widget_show (caption);
586 gtk_widget_show (GTK_WIDGET (box));
588 return GTK_WIDGET (box);
592 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
594 GtkWidget *widget = GTK_WIDGET (user_data);
596 /* Enable the widget only if the toggle button is active: */
597 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
598 gtk_widget_set_sensitive (widget, enable);
601 /* Make the sensitivity of a widget depend on a toggle button.
604 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
606 g_signal_connect (G_OBJECT (button), "toggled",
607 G_CALLBACK (on_toggle_button_changed), widget);
609 /* Set the starting sensitivity: */
610 on_toggle_button_changed (button, widget);
614 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
616 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
618 /* Create the window if necessary: */
619 if (!(self->specific_window)) {
620 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
621 modest_connection_specific_smtp_window_fill_with_connections (
622 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
626 /* Show the window: */
627 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
628 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
629 gtk_widget_show (self->specific_window);
633 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
635 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
637 ModestAuthProtocol protocol_security =
638 modest_secureauth_combo_box_get_active_secureauth (
639 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
640 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
642 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
643 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
647 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
649 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
651 const gint port_number =
652 modest_serversecurity_combo_box_get_active_serversecurity_port (
653 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
655 if(port_number != 0) {
656 hildon_number_editor_set_value (
657 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
662 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
664 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
666 const gint port_number =
667 modest_serversecurity_combo_box_get_active_serversecurity_port (
668 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
670 if(port_number != 0) {
671 hildon_number_editor_set_value (
672 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
677 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
679 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
681 /* Create a size group to be used by all captions.
682 * Note that HildonCaption does not create a default size group if we do not specify one.
683 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
684 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
686 /* The outgoing server widgets: */
687 if (!self->entry_outgoingserver)
688 self->entry_outgoingserver = gtk_entry_new ();
689 /* Auto-capitalization is the default, so let's turn it off: */
690 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
691 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
692 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
693 gtk_widget_show (self->entry_outgoingserver);
694 connect_for_modified (self, self->entry_outgoingserver);
695 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
696 gtk_widget_show (caption);
698 /* The secure authentication widgets: */
699 if (!self->combo_outgoing_auth)
700 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
701 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
702 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
703 gtk_widget_show (self->combo_outgoing_auth);
704 connect_for_modified (self, self->combo_outgoing_auth);
705 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
706 gtk_widget_show (caption);
708 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
709 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
711 /* The username widgets: */
712 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
713 /* Auto-capitalization is the default, so let's turn it off: */
714 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
715 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
716 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
717 gtk_widget_show (self->entry_outgoing_username);
718 connect_for_modified (self, self->entry_outgoing_username);
719 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
720 gtk_widget_show (self->caption_outgoing_username);
722 /* Prevent the use of some characters in the username,
723 * as required by our UI specification: */
724 modest_validating_entry_set_unallowed_characters_whitespace (
725 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
727 /* Set max length as in the UI spec:
728 * The UI spec seems to want us to show a dialog if we hit the maximum. */
729 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
730 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
733 /* The password widgets: */
734 self->entry_outgoing_password = gtk_entry_new ();
735 /* Auto-capitalization is the default, so let's turn it off: */
736 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
737 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
738 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
739 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
740 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
741 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
742 gtk_widget_show (self->entry_outgoing_password);
743 connect_for_modified (self, self->entry_outgoing_password);
744 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
745 gtk_widget_show (self->caption_outgoing_password);
747 /* The secure connection widgets: */
748 /* This will be filled and set with modest_serversecurity_combo_box_fill()
749 * and modest_serversecurity_combo_box_set_active_serversecurity().
751 if (!self->combo_outgoing_security)
753 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
754 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
755 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
756 gtk_widget_show (self->combo_outgoing_security);
757 connect_for_modified (self, self->combo_outgoing_security);
758 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
759 gtk_widget_show (caption);
761 /* Show a default port number when the security method changes, as per the UI spec: */
762 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
764 /* The port widgets: */
765 if (!self->entry_outgoing_port)
766 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
767 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
768 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
769 gtk_widget_show (self->entry_outgoing_port);
770 connect_for_modified (self, self->entry_outgoing_port);
771 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
772 gtk_widget_show (caption);
774 GtkWidget *separator = gtk_hseparator_new ();
775 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
776 gtk_widget_show (separator);
778 /* connection-specific checkbox: */
779 if (!self->checkbox_outgoing_smtp_specific) {
780 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
781 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
784 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
785 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
786 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
787 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
788 gtk_widget_show (caption);
789 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
791 /* Connection-specific SMTP-Severs Edit button: */
792 if (!self->button_outgoing_smtp_servers)
793 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
794 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
795 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
796 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
797 gtk_widget_show (self->button_outgoing_smtp_servers);
798 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
799 gtk_widget_show (caption);
801 /* Only enable the button when the checkbox is checked: */
802 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
803 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
805 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
806 G_CALLBACK (on_button_outgoing_smtp_servers), self);
808 gtk_widget_show (GTK_WIDGET (box));
810 return GTK_WIDGET (box);
814 check_data (ModestAccountSettingsDialog *self)
816 /* Check that the title is not already in use: */
817 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
818 if ((!account_title) || (strlen(account_title) == 0))
819 return FALSE; /* Should be prevented already anyway. */
821 if (strcmp(account_title, self->original_account_title) != 0) {
822 /* Check the changed title: */
823 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
827 /* Warn the user via a dialog: */
828 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
834 /* Check that the email address is valud: */
835 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
836 if ((!email_address) || (strlen(email_address) == 0))
839 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
840 /* Warn the user via a dialog: */
841 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
842 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
844 /* Return focus to the email address entry: */
845 gtk_widget_grab_focus (self->entry_user_email);
846 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
850 /* Find a suitable authentication method when secure authentication is desired */
851 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
852 gint port_num = hildon_number_editor_get_value (
853 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
854 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
856 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
857 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
859 /* If we use an encrypted protocol then there is no need to encrypt the password */
860 if (!modest_protocol_info_is_secure(protocol_security_incoming))
862 if (gtk_toggle_button_get_active (
863 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
864 GError *error = NULL;
865 GList *list_auth_methods =
866 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
867 hostname, port_num, username, GTK_WINDOW (self), &error);
868 if (list_auth_methods) {
869 /* Use the first supported method.
870 * TODO: Should we prioritize them, to prefer a particular one? */
872 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
874 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
875 // Allow secure methods, e.g MD5 only
876 if (modest_protocol_info_auth_is_secure(proto))
878 self->protocol_authentication_incoming = proto;
882 g_list_free (list_auth_methods);
885 if (list_auth_methods == NULL ||
886 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
888 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
889 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
891 GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(self),
892 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
893 GTK_BUTTONS_OK, (error != NULL) ? error->message : _("Server does not support secure authentication!"));
894 gtk_dialog_run(GTK_DIALOG(error_dialog));
895 gtk_widget_destroy(error_dialog);
898 if(error != NULL) g_error_free(error);
899 /* This is a nasty hack. jschmid. */
900 /* Don't let the dialog close */
901 /*g_signal_stop_emission_by_name (dialog, "response");*/
907 /* TODO: The UI Spec wants us to check that the servernames are valid,
908 * but does not specify how.
916 on_response (GtkDialog *wizard_dialog,
920 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
921 enable_buttons (self);
923 gboolean prevent_response = FALSE;
925 /* Set modified flag when the port number changed */
926 gint port_num = hildon_number_editor_get_value (
927 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
928 if(ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self)->initial_port != port_num)
929 self->modified = TRUE;
931 /* Warn about unsaved changes: */
932 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
933 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
934 _("imum_nc_wizard_confirm_lose_changes")));
935 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
937 const gint dialog_response = gtk_dialog_run (dialog);
938 gtk_widget_destroy (GTK_WIDGET (dialog));
940 if (dialog_response != GTK_RESPONSE_OK)
941 prevent_response = TRUE;
943 /* Check for invalid input: */
944 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
945 prevent_response = TRUE;
948 if (prevent_response) {
949 /* This is a nasty hack. murrayc. */
950 /* Don't let the dialog close */
951 g_signal_stop_emission_by_name (wizard_dialog, "response");
955 if (response_id == GTK_RESPONSE_OK) {
956 /* Try to save the changes if modified (NB #59251): */
959 const gboolean saved = save_configuration (self);
961 /* Do not show the account-saved dialog if we are just saving this
962 * temporarily, because from the user's point of view it will not
963 * really be saved (saved + enabled) until later.
965 const gboolean enabled =
966 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
968 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
971 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
977 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
979 /* Create the notebook to be used by the GtkDialog base class:
980 * Each page of the notebook will be a page of the wizard: */
981 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
983 /* Get the account manager object,
984 * so we can check for existing accounts,
985 * and create new accounts: */
986 self->account_manager = modest_runtime_get_account_mgr ();
987 g_assert (self->account_manager);
988 g_object_ref (self->account_manager);
990 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
992 /* Create the common pages,
994 self->page_account_details = create_page_account_details (self);
995 self->page_user_details = create_page_user_details (self);
996 self->page_incoming = create_page_incoming (self);
997 self->page_outgoing = create_page_outgoing (self);
999 /* Add the notebook pages: */
1000 gtk_notebook_append_page (notebook, self->page_account_details,
1001 gtk_label_new (_("mcen_ti_account_settings_account")));
1002 gtk_notebook_append_page (notebook, self->page_user_details,
1003 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1004 gtk_notebook_append_page (notebook, self->page_incoming,
1005 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1006 gtk_notebook_append_page (notebook, self->page_outgoing,
1007 gtk_label_new (_("mcen_ti_advsetup_sending")));
1009 GtkDialog *dialog = GTK_DIALOG (self);
1010 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
1011 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1012 gtk_widget_show (GTK_WIDGET (notebook));
1014 /* Add the buttons: */
1015 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1016 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1018 /* Connect to the dialog's response signal: */
1019 /* We use connect-before
1020 * so we can stop the signal emission,
1021 * to stop the default signal handler from closing the dialog.
1023 g_signal_connect (G_OBJECT (self), "response",
1024 G_CALLBACK (on_response), self);
1026 self->modified = FALSE;
1028 /* When this window is shown, hibernation should not be possible,
1029 * because there is no sensible way to save the state: */
1030 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1031 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1034 ModestAccountSettingsDialog*
1035 modest_account_settings_dialog_new (void)
1037 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1040 /** Update the UI with the stored account details, so they can be edited.
1041 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1043 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1048 /* Save the account name so we can refer to it later: */
1049 if (dialog->account_name)
1050 g_free (dialog->account_name);
1051 dialog->account_name = g_strdup (account_name);
1054 /* Get the account data for this account name: */
1055 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1057 if (!account_data) {
1058 g_printerr ("modest: failed to get account data for %s\n", account_name);
1062 /* Save the account title so we can refer to it if the user changes it: */
1063 if (dialog->original_account_title)
1064 g_free (dialog->original_account_title);
1065 dialog->original_account_title = g_strdup (account_data->display_name);
1068 if (!(account_data->store_account)) {
1069 g_printerr ("modest: account has no stores: %s\n", account_name);
1073 /* Show the account data in the widgets: */
1075 /* Note that we never show the non-display name in the UI.
1076 * (Though the display name defaults to the non-display name at the start.) */
1077 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1078 account_data->display_name ? account_data->display_name : "");
1080 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1081 account_data->fullname ? account_data->fullname : "");
1082 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1083 account_data->email ? account_data->email : "");
1085 ModestServerAccountData *incoming_account = account_data->store_account;
1087 if (incoming_account)
1088 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1089 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1090 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1092 /* Default to something, though no default is specified in the UI spec: */
1093 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1095 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1098 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1099 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1100 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1103 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1104 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1105 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1107 /* Only show the leave-on-server checkbox for POP,
1108 * as per the UI spec: */
1109 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1110 gtk_widget_hide (dialog->caption_leave_messages);
1112 gtk_widget_show (dialog->caption_leave_messages);
1115 update_incoming_server_security_choices (dialog, incoming_account->proto);
1116 if (incoming_account) {
1117 /* Remember this for later: */
1118 dialog->incoming_protocol = incoming_account->proto;
1120 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1121 incoming_account->username ? incoming_account->username : "");
1122 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1123 incoming_account->password ? incoming_account->password : "");
1125 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1126 incoming_account->hostname ? incoming_account->hostname : "");
1128 /* The UI spec says:
1129 * If secure authentication is unchecked, allow sending username and password also as plain text.
1130 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1131 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1133 const ModestConnectionProtocol security = modest_server_account_get_security (
1134 dialog->account_manager, incoming_account->account_name);
1135 modest_serversecurity_combo_box_set_active_serversecurity (
1136 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1141 - use encrypted passwords
1143 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1144 dialog->account_manager, incoming_account->account_name);
1145 dialog->protocol_authentication_incoming = secure_auth;
1146 if (modest_protocol_info_is_secure(security) ||
1147 modest_protocol_info_auth_is_secure(secure_auth))
1149 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1154 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1158 update_incoming_server_title (dialog, incoming_account->proto);
1160 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1161 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1163 if (port_num == 0) {
1164 /* Show the appropriate port number: */
1165 on_combo_incoming_security_changed (
1166 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1168 /* Keep the user-entered port-number,
1169 * or the already-appropriate automatic port number: */
1170 hildon_number_editor_set_value (
1171 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1174 /* HildonNumberEditor has no changed signal, so we do not get
1175 * notified when the port number changes. Instead we check
1176 * whether the number has changed before the dialog is closed. */
1177 ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(dialog)->initial_port =
1178 hildon_number_editor_get_value (
1179 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1182 ModestServerAccountData *outgoing_account = account_data->transport_account;
1183 if (outgoing_account) {
1184 /* Remember this for later: */
1185 dialog->outgoing_protocol = outgoing_account->proto;
1187 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1188 outgoing_account->hostname ? outgoing_account->hostname : "");
1190 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1191 outgoing_account->username ? outgoing_account->username : "");
1192 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1193 outgoing_account->password ? outgoing_account->password : "");
1195 /* Get the secure-auth setting: */
1196 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1197 dialog->account_manager, outgoing_account->account_name);
1198 modest_secureauth_combo_box_set_active_secureauth (
1199 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1200 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1202 modest_serversecurity_combo_box_fill (
1203 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1205 /* Get the security setting: */
1206 const ModestConnectionProtocol security = modest_server_account_get_security (
1207 dialog->account_manager, outgoing_account->account_name);
1208 modest_serversecurity_combo_box_set_active_serversecurity (
1209 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1211 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1212 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1213 if (port_num == 0) {
1214 /* Show the appropriate port number: */
1215 on_combo_outgoing_security_changed (
1216 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1219 /* Keep the user-entered port-number,
1220 * or the already-appropriate automatic port number: */
1221 hildon_number_editor_set_value (
1222 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1225 const gboolean has_specific =
1226 modest_account_mgr_get_has_connection_specific_smtp (
1227 dialog->account_manager,
1229 gtk_toggle_button_set_active (
1230 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1234 /* Set window title according to account: */
1235 /* TODO: Is this the correct way to find a human-readable name for
1236 * the protocol used? */
1237 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1238 gchar *proto_name = g_utf8_strup(proto_str, -1);
1239 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1241 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1242 g_free (proto_name);
1243 g_free (account_title);
1245 gtk_window_set_title (GTK_WINDOW (dialog), title);
1248 /* account_data->is_enabled, */
1249 /*account_data->is_default, */
1251 /* account_data->store_account->proto */
1253 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1255 /* Unset the modified flag so we can detect changes later: */
1256 dialog->modified = FALSE;
1260 save_configuration (ModestAccountSettingsDialog *dialog)
1262 g_assert (dialog->account_name);
1264 const gchar* account_name = dialog->account_name;
1266 /* Set the account data from the widgets: */
1267 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1268 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1269 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1273 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1274 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1275 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1280 if (dialog->signature_dialog) {
1281 gboolean use_signature = FALSE;
1282 gchar *signature = modest_signature_editor_dialog_get_settings (
1283 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1286 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1287 signature, use_signature);
1291 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1292 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1293 modest_account_mgr_set_string (dialog->account_manager, account_name,
1294 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1297 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1298 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1299 modest_account_mgr_set_int (dialog->account_manager, account_name,
1300 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1302 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1303 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1304 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1309 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1310 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1311 g_assert (incoming_account_name);
1313 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1314 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1315 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1319 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1320 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1322 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1323 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1326 gint port_num = hildon_number_editor_get_value (
1327 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1328 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1329 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1331 /* The UI spec says:
1332 * If secure authentication is unchecked, allow sending username and password also as plain text.
1333 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1336 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1337 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1338 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1340 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1343 g_free (incoming_account_name);
1346 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1347 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1348 g_assert (outgoing_account_name);
1350 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1351 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1352 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1356 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1357 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1360 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1361 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1364 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1365 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1366 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1368 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1369 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1370 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1373 port_num = hildon_number_editor_get_value (
1374 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1375 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1376 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1378 g_free (outgoing_account_name);
1381 /* Set the changed account title last, to simplify the previous code: */
1382 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1383 if ((!account_title) || (strlen(account_title) == 0))
1384 return FALSE; /* Should be prevented already anyway. */
1386 if (strcmp(account_title, account_name) != 0) {
1387 /* Change the title: */
1388 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1389 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1394 /* Save connection-specific SMTP server accounts: */
1395 if (dialog->specific_window) {
1396 return modest_connection_specific_smtp_window_save_server_accounts (
1397 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1403 static gboolean entry_is_empty (GtkWidget *entry)
1408 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1409 if ((!text) || (strlen(text) == 0))
1416 enable_buttons (ModestAccountSettingsDialog *self)
1418 gboolean enable_ok = TRUE;
1420 /* The account details title is mandatory: */
1421 if (entry_is_empty(self->entry_account_title))
1424 /* The user details username is mandatory: */
1425 if (entry_is_empty(self->entry_user_username))
1428 /* The user details email address is mandatory: */
1429 if (enable_ok && entry_is_empty (self->entry_user_email))
1432 /* The custom incoming server is mandatory: */
1433 if (entry_is_empty(self->entry_incomingserver))
1436 /* Enable the buttons,
1437 * identifying them via their associated response codes:
1439 GtkDialog *dialog_base = GTK_DIALOG (self);
1440 gtk_dialog_set_response_sensitive (dialog_base,
1446 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1448 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1449 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1452 object_class->get_property = modest_account_settings_dialog_get_property;
1453 object_class->set_property = modest_account_settings_dialog_set_property;
1454 object_class->dispose = modest_account_settings_dialog_dispose;
1455 object_class->finalize = modest_account_settings_dialog_finalize;
1459 show_error (GtkWindow *parent_window, const gchar* text)
1461 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1463 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1470 gtk_dialog_run (dialog);
1471 gtk_widget_destroy (GTK_WIDGET (dialog));
1475 show_ok (GtkWindow *parent_window, const gchar* text)
1477 /* Don't show a dialog but Banner (NB #59248) */
1478 hildon_banner_show_information(GTK_WIDGET(
1479 gtk_widget_get_parent_window(GTK_WIDGET(parent_window))), NULL, text);