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), _("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 GtkWidget* error_dialog = gtk_message_dialog_new(GTK_WINDOW(self),
902 GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
903 GTK_BUTTONS_OK, (error != NULL) ? error->message : _("Server does not support secure authentication!"));
904 gtk_dialog_run(GTK_DIALOG(error_dialog));
905 gtk_widget_destroy(error_dialog);
908 if(error != NULL) g_error_free(error);
909 /* This is a nasty hack. jschmid. */
910 /* Don't let the dialog close */
911 /*g_signal_stop_emission_by_name (dialog, "response");*/
917 /* TODO: The UI Spec wants us to check that the servernames are valid,
918 * but does not specify how.
926 on_response (GtkDialog *wizard_dialog,
930 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
931 enable_buttons (self);
933 gboolean prevent_response = FALSE;
935 /* Warn about unsaved changes: */
936 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
937 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
938 _("imum_nc_wizard_confirm_lose_changes")));
939 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
941 const gint dialog_response = gtk_dialog_run (dialog);
942 gtk_widget_destroy (GTK_WIDGET (dialog));
944 if (dialog_response != GTK_RESPONSE_OK)
945 prevent_response = TRUE;
947 /* Check for invalid input: */
948 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
949 prevent_response = TRUE;
952 if (prevent_response) {
953 /* This is a nasty hack. murrayc. */
954 /* Don't let the dialog close */
955 g_signal_stop_emission_by_name (wizard_dialog, "response");
959 if (response_id == GTK_RESPONSE_OK) {
960 /* Try to save the changes if modified (NB #59251): */
963 const gboolean saved = save_configuration (self);
965 /* Do not show the account-saved dialog if we are just saving this
966 * temporarily, because from the user's point of view it will not
967 * really be saved (saved + enabled) until later.
969 const gboolean enabled =
970 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
972 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
975 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
981 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
983 /* Create the notebook to be used by the GtkDialog base class:
984 * Each page of the notebook will be a page of the wizard: */
985 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
987 /* Get the account manager object,
988 * so we can check for existing accounts,
989 * and create new accounts: */
990 self->account_manager = modest_runtime_get_account_mgr ();
991 g_assert (self->account_manager);
992 g_object_ref (self->account_manager);
994 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
996 /* Create the common pages,
998 self->page_account_details = create_page_account_details (self);
999 self->page_user_details = create_page_user_details (self);
1000 self->page_incoming = create_page_incoming (self);
1001 self->page_outgoing = create_page_outgoing (self);
1003 /* Add the notebook pages: */
1004 gtk_notebook_append_page (notebook, self->page_account_details,
1005 gtk_label_new (_("mcen_ti_account_settings_account")));
1006 gtk_notebook_append_page (notebook, self->page_user_details,
1007 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1008 gtk_notebook_append_page (notebook, self->page_incoming,
1009 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1010 gtk_notebook_append_page (notebook, self->page_outgoing,
1011 gtk_label_new (_("mcen_ti_advsetup_sending")));
1013 GtkDialog *dialog = GTK_DIALOG (self);
1014 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
1015 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1016 gtk_widget_show (GTK_WIDGET (notebook));
1018 /* Add the buttons: */
1019 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1020 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1022 /* Connect to the dialog's response signal: */
1023 /* We use connect-before
1024 * so we can stop the signal emission,
1025 * to stop the default signal handler from closing the dialog.
1027 g_signal_connect (G_OBJECT (self), "response",
1028 G_CALLBACK (on_response), self);
1030 self->modified = FALSE;
1032 /* When this window is shown, hibernation should not be possible,
1033 * because there is no sensible way to save the state: */
1034 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1035 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1038 ModestAccountSettingsDialog*
1039 modest_account_settings_dialog_new (void)
1041 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1044 /** Update the UI with the stored account details, so they can be edited.
1045 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1047 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1052 /* Save the account name so we can refer to it later: */
1053 if (dialog->account_name)
1054 g_free (dialog->account_name);
1055 dialog->account_name = g_strdup (account_name);
1058 /* Get the account data for this account name: */
1059 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1061 if (!account_data) {
1062 g_printerr ("modest: failed to get account data for %s\n", account_name);
1066 /* Save the account title so we can refer to it if the user changes it: */
1067 if (dialog->original_account_title)
1068 g_free (dialog->original_account_title);
1069 dialog->original_account_title = g_strdup (account_data->display_name);
1072 if (!(account_data->store_account)) {
1073 g_printerr ("modest: account has no stores: %s\n", account_name);
1077 /* Show the account data in the widgets: */
1079 /* Note that we never show the non-display name in the UI.
1080 * (Though the display name defaults to the non-display name at the start.) */
1081 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1082 account_data->display_name ? account_data->display_name : "");
1084 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1085 account_data->fullname ? account_data->fullname : "");
1086 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1087 account_data->email ? account_data->email : "");
1089 ModestServerAccountData *incoming_account = account_data->store_account;
1091 if (incoming_account)
1092 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1093 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1094 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1096 /* Default to something, though no default is specified in the UI spec: */
1097 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1099 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1102 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1103 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1104 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1107 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1108 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1109 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1111 /* Only show the leave-on-server checkbox for POP,
1112 * as per the UI spec: */
1113 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1114 gtk_widget_hide (dialog->caption_leave_messages);
1116 gtk_widget_show (dialog->caption_leave_messages);
1119 update_incoming_server_security_choices (dialog, incoming_account->proto);
1120 if (incoming_account) {
1121 /* Remember this for later: */
1122 dialog->incoming_protocol = incoming_account->proto;
1124 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1125 incoming_account->username ? incoming_account->username : "");
1126 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1127 incoming_account->password ? incoming_account->password : "");
1129 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1130 incoming_account->hostname ? incoming_account->hostname : "");
1132 /* The UI spec says:
1133 * If secure authentication is unchecked, allow sending username and password also as plain text.
1134 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1135 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1137 const ModestConnectionProtocol security = modest_server_account_get_security (
1138 dialog->account_manager, incoming_account->account_name);
1139 modest_serversecurity_combo_box_set_active_serversecurity (
1140 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1145 - use encrypted passwords
1147 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1148 dialog->account_manager, incoming_account->account_name);
1149 dialog->protocol_authentication_incoming = secure_auth;
1150 if (modest_protocol_info_is_secure(security) ||
1151 modest_protocol_info_auth_is_secure(secure_auth))
1153 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1158 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1162 update_incoming_server_title (dialog, incoming_account->proto);
1164 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1165 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1167 if (port_num == 0) {
1168 /* Show the appropriate port number: */
1169 on_combo_incoming_security_changed (
1170 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1172 /* Keep the user-entered port-number,
1173 * or the already-appropriate automatic port number: */
1174 hildon_number_editor_set_value (
1175 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1179 ModestServerAccountData *outgoing_account = account_data->transport_account;
1180 if (outgoing_account) {
1181 /* Remember this for later: */
1182 dialog->outgoing_protocol = outgoing_account->proto;
1184 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1185 outgoing_account->hostname ? outgoing_account->hostname : "");
1187 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1188 outgoing_account->username ? outgoing_account->username : "");
1189 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1190 outgoing_account->password ? outgoing_account->password : "");
1192 /* Get the secure-auth setting: */
1193 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1194 dialog->account_manager, outgoing_account->account_name);
1195 modest_secureauth_combo_box_set_active_secureauth (
1196 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1197 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1199 modest_serversecurity_combo_box_fill (
1200 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1202 /* Get the security setting: */
1203 const ModestConnectionProtocol security = modest_server_account_get_security (
1204 dialog->account_manager, outgoing_account->account_name);
1205 modest_serversecurity_combo_box_set_active_serversecurity (
1206 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1208 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1209 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1210 if (port_num == 0) {
1211 /* Show the appropriate port number: */
1212 on_combo_outgoing_security_changed (
1213 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1216 /* Keep the user-entered port-number,
1217 * or the already-appropriate automatic port number: */
1218 hildon_number_editor_set_value (
1219 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1222 const gboolean has_specific =
1223 modest_account_mgr_get_has_connection_specific_smtp (
1224 dialog->account_manager,
1226 gtk_toggle_button_set_active (
1227 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1231 /* Set window title according to account: */
1232 /* TODO: Is this the correct way to find a human-readable name for
1233 * the protocol used? */
1234 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1235 gchar *proto_name = g_utf8_strup(proto_str, -1);
1236 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1238 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1239 g_free (proto_name);
1240 g_free (account_title);
1242 gtk_window_set_title (GTK_WINDOW (dialog), title);
1245 /* account_data->is_enabled, */
1246 /*account_data->is_default, */
1248 /* account_data->store_account->proto */
1250 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1252 /* Unset the modified flag so we can detect changes later: */
1253 dialog->modified = FALSE;
1257 save_configuration (ModestAccountSettingsDialog *dialog)
1259 g_assert (dialog->account_name);
1261 const gchar* account_name = dialog->account_name;
1263 /* Set the account data from the widgets: */
1264 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1265 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1266 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1270 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1271 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1272 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1277 if (dialog->signature_dialog) {
1278 gboolean use_signature = FALSE;
1279 gchar *signature = modest_signature_editor_dialog_get_settings (
1280 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1283 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1284 signature, use_signature);
1288 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1289 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1290 modest_account_mgr_set_string (dialog->account_manager, account_name,
1291 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1294 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1295 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1296 modest_account_mgr_set_int (dialog->account_manager, account_name,
1297 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1299 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1300 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1301 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1306 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1307 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1308 g_assert (incoming_account_name);
1310 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1311 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1312 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1316 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1317 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1319 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1320 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1323 gint port_num = hildon_number_editor_get_value (
1324 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1325 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1326 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1328 /* The UI spec says:
1329 * If secure authentication is unchecked, allow sending username and password also as plain text.
1330 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1333 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1334 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1335 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1337 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1340 g_free (incoming_account_name);
1343 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1344 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1345 g_assert (outgoing_account_name);
1347 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1348 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1349 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1353 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1354 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1357 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1358 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1361 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1362 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1363 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1365 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1366 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1367 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1370 port_num = hildon_number_editor_get_value (
1371 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1372 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1373 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1375 g_free (outgoing_account_name);
1378 /* Set the changed account title last, to simplify the previous code: */
1379 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1380 if ((!account_title) || (strlen(account_title) == 0))
1381 return FALSE; /* Should be prevented already anyway. */
1383 if (strcmp(account_title, account_name) != 0) {
1384 /* Change the title: */
1385 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1386 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1391 /* Save connection-specific SMTP server accounts: */
1392 if (dialog->specific_window) {
1393 return modest_connection_specific_smtp_window_save_server_accounts (
1394 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1400 static gboolean entry_is_empty (GtkWidget *entry)
1405 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1406 if ((!text) || (strlen(text) == 0))
1413 enable_buttons (ModestAccountSettingsDialog *self)
1415 gboolean enable_ok = TRUE;
1417 /* The account details title is mandatory: */
1418 if (entry_is_empty(self->entry_account_title))
1421 /* The user details username is mandatory: */
1422 if (entry_is_empty(self->entry_user_username))
1425 /* The user details email address is mandatory: */
1426 if (enable_ok && entry_is_empty (self->entry_user_email))
1429 /* The custom incoming server is mandatory: */
1430 if (entry_is_empty(self->entry_incomingserver))
1433 /* Enable the buttons,
1434 * identifying them via their associated response codes:
1436 GtkDialog *dialog_base = GTK_DIALOG (self);
1437 gtk_dialog_set_response_sensitive (dialog_base,
1443 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1445 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1446 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1449 object_class->get_property = modest_account_settings_dialog_get_property;
1450 object_class->set_property = modest_account_settings_dialog_set_property;
1451 object_class->dispose = modest_account_settings_dialog_dispose;
1452 object_class->finalize = modest_account_settings_dialog_finalize;
1456 show_error (GtkWindow *parent_window, const gchar* text)
1458 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1460 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1467 gtk_dialog_run (dialog);
1468 gtk_widget_destroy (GTK_WIDGET (dialog));
1472 show_ok (GtkWindow *parent_window, const gchar* text)
1474 /* Don't show a dialog but Banner (NB #59248) */
1475 hildon_banner_show_information(GTK_WIDGET(
1476 gtk_widget_get_parent_window(GTK_WIDGET(parent_window))), NULL, text);