1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "modest-account-settings-dialog.h"
32 #include <glib/gi18n.h>
33 #include <gtk/gtknotebook.h>
34 #include <gtk/gtkvbox.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkcombobox.h>
37 #include <gtk/gtkentry.h>
38 #include <gtk/gtkbutton.h>
39 #include <gtk/gtkcheckbutton.h>
40 #include <gtk/gtkmessagedialog.h>
41 #include <gtk/gtkstock.h>
42 #include "modest-hildon-includes.h"
44 #include "widgets/modest-serversecurity-combo-box.h"
45 #include "widgets/modest-secureauth-combo-box.h"
46 #include "widgets/modest-validating-entry.h"
47 #include "widgets/modest-retrieve-combo-box.h"
48 #include "widgets/modest-limit-retrieve-combo-box.h"
49 #include "modest-text-utils.h"
50 #include "modest-account-mgr.h"
51 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
52 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
53 #include "modest-protocol-info.h"
54 #include "maemo/modest-connection-specific-smtp-window.h"
55 #include "maemo/modest-signature-editor-dialog.h"
56 #include "maemo/modest-maemo-utils.h"
57 #include "widgets/modest-ui-constants.h"
59 #include <tny-camel-transport-account.h>
60 #include <tny-camel-imap-store-account.h>
61 #include <tny-camel-pop-store-account.h>
62 #include <tny-status.h>
64 #include <gconf/gconf-client.h>
65 #include <string.h> /* For strlen(). */
67 /* Include config.h so that _() works: */
72 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
74 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
76 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
77 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
79 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
81 struct _ModestAccountSettingsDialogPrivate
86 enable_buttons (ModestAccountSettingsDialog *self);
89 save_configuration (ModestAccountSettingsDialog *dialog);
92 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
93 GValue *value, GParamSpec *pspec)
95 switch (property_id) {
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
102 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
103 const GValue *value, GParamSpec *pspec)
105 switch (property_id) {
107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
112 modest_account_settings_dialog_dispose (GObject *object)
114 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
115 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
119 modest_account_settings_dialog_finalize (GObject *object)
121 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
123 if (self->account_name)
124 g_free (self->account_name);
126 if (self->original_account_title)
127 g_free (self->original_account_title);
129 if (self->account_manager)
130 g_object_unref (G_OBJECT (self->account_manager));
132 if (self->specific_window)
133 gtk_widget_destroy (self->specific_window);
135 if (self->signature_dialog)
136 gtk_widget_destroy (self->signature_dialog);
138 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
142 show_error (GtkWidget *parent_widget, const gchar* text);
145 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data);
148 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data);
151 on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data)
153 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
154 self->modified = TRUE;
158 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
160 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
161 self->modified = TRUE;
165 on_modified_checkbox_toggled (GtkToggleButton *togglebutton, gpointer user_data)
167 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
168 self->modified = TRUE;
172 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
174 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
175 self->modified = TRUE;
178 /* Set a modified boolean whenever the widget is changed,
179 * so we can check for it later.
182 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
184 if (HILDON_IS_NUMBER_EDITOR (widget)) {
185 g_signal_connect (G_OBJECT (widget), "notify::value",
186 G_CALLBACK (on_modified_number_editor_changed), self);
188 else if (GTK_IS_ENTRY (widget)) {
189 g_signal_connect (G_OBJECT (widget), "changed",
190 G_CALLBACK (on_modified_entry_changed), self);
191 } else if (GTK_IS_COMBO_BOX (widget)) {
192 g_signal_connect (G_OBJECT (widget), "changed",
193 G_CALLBACK (on_modified_combobox_changed), self);
194 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
195 g_signal_connect (G_OBJECT (widget), "toggled",
196 G_CALLBACK (on_modified_checkbox_toggled), self);
201 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
203 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
205 enable_buttons(self);
209 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
211 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
213 enable_buttons(self);
216 /** This is a convenience function to create a caption containing a mandatory widget.
217 * When the widget is edited, the enable_buttons() vfunc will be called.
219 static GtkWidget* create_caption_new_with_asterisk(ModestAccountSettingsDialog *self,
224 HildonCaptionStatus flag)
226 GtkWidget *caption = NULL;
228 /* Note: Previously, the translated strings already contained the "*",
229 * Comment out this code if they do again.
231 /* Add a * character to indicate mandatory fields,
232 * as specified in our "Email UI Specification": */
233 if (flag == HILDON_CAPTION_MANDATORY) {
234 gchar* title = g_strdup_printf("%s*", value);
235 caption = hildon_caption_new (group, title, control, icon, flag);
239 caption = hildon_caption_new (group, value, control, icon, flag);
241 /* Connect to the appropriate changed signal for the widget,
242 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
244 if (GTK_IS_ENTRY (control)) {
245 g_signal_connect (G_OBJECT (control), "changed",
246 G_CALLBACK (on_caption_entry_changed), self);
249 else if (GTK_IS_COMBO_BOX (control)) {
250 g_signal_connect (G_OBJECT (control), "changed",
251 G_CALLBACK (on_caption_combobox_changed), self);
258 on_entry_invalid_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
260 /* ModestEasysetupWizardDialog *dialog = MODEST_EASYSETUP_WIZARD_DIALOG (user_data); */
261 /* We could add a special case for whitespace here
262 if (character == NULL) ...
264 /* TODO: Should this show just this one bad character or all the not-allowed characters? */
265 gchar *message = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), character);
266 show_error (GTK_WIDGET (self), message);
270 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
272 /* ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data); */
273 show_error (GTK_WIDGET (self), _CS("ckdg_ib_maximum_characters_reached"));
277 create_page_account_details (ModestAccountSettingsDialog *self)
279 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
280 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
281 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
282 gtk_widget_show (label);
284 /* Create a size group to be used by all captions.
285 * Note that HildonCaption does not create a default size group if we do not specify one.
286 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
287 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
289 /* The description widgets: */
290 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
291 /* Do use auto-capitalization: */
292 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
293 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
294 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
295 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
296 gtk_widget_show (self->entry_account_title);
297 connect_for_modified (self, self->entry_account_title);
298 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
299 gtk_widget_show (caption);
301 /* Prevent the use of some characters in the account title,
302 * as required by our UI specification: */
303 GList *list_prevent = NULL;
304 list_prevent = g_list_append (list_prevent, "\\");
305 list_prevent = g_list_append (list_prevent, "/");
306 list_prevent = g_list_append (list_prevent, ":");
307 list_prevent = g_list_append (list_prevent, "*");
308 list_prevent = g_list_append (list_prevent, "?");
309 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
310 list_prevent = g_list_append (list_prevent, "“");
311 list_prevent = g_list_append (list_prevent, "<");
312 list_prevent = g_list_append (list_prevent, ">");
313 list_prevent = g_list_append (list_prevent, "|");
314 list_prevent = g_list_append (list_prevent, "^");
315 modest_validating_entry_set_unallowed_characters (
316 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
317 g_list_free (list_prevent);
318 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(self->entry_account_title),
319 on_entry_invalid_character, self);
321 /* Set max length as in the UI spec:
322 * The UI spec seems to want us to show a dialog if we hit the maximum. */
323 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
324 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
327 /* The retrieve combobox: */
328 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
329 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
330 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
331 gtk_widget_show (self->combo_retrieve);
332 connect_for_modified (self, self->combo_retrieve);
333 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
334 gtk_widget_show (caption);
336 /* The limit-retrieve combobox: */
337 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
338 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
339 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
340 gtk_widget_show (self->combo_limit_retrieve);
341 connect_for_modified (self, self->combo_limit_retrieve);
342 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
343 gtk_widget_show (caption);
345 /* The leave-messages widgets: */
346 if(!self->checkbox_leave_messages)
347 self->checkbox_leave_messages = gtk_check_button_new ();
348 if (!self->caption_leave_messages) {
349 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
350 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
353 gtk_widget_show (self->checkbox_leave_messages);
354 connect_for_modified (self, self->checkbox_leave_messages);
355 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
356 gtk_widget_show (self->caption_leave_messages);
358 gtk_widget_show (GTK_WIDGET (box));
360 return GTK_WIDGET (box);
364 on_button_signature (GtkButton *button, gpointer user_data)
366 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
368 /* Create the window, if necessary: */
369 if (!(self->signature_dialog)) {
370 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
372 gboolean use_signature = FALSE;
373 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
375 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
376 modest_signature_editor_dialog_set_settings (
377 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
378 use_signature, signature, account_title);
383 /* Show the window: */
384 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
385 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
386 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
387 gtk_widget_hide (self->signature_dialog);
388 if (response != GTK_RESPONSE_OK) {
389 /* Destroy the widget now, and its data: */
390 gtk_widget_destroy (self->signature_dialog);
391 self->signature_dialog = NULL;
394 /* Mark modified, so we use the dialog's data later: */
395 self->modified = TRUE;
400 create_page_user_details (ModestAccountSettingsDialog *self)
402 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
404 /* Create a size group to be used by all captions.
405 * Note that HildonCaption does not create a default size group if we do not specify one.
406 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
407 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
409 /* The name widgets: */
410 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
411 /* Auto-capitalization is the default, so let's turn it off: */
412 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
413 /* Set max length as in the UI spec:
414 * The UI spec seems to want us to show a dialog if we hit the maximum. */
415 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
416 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
418 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
419 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
420 gtk_widget_show (self->entry_user_name);
421 connect_for_modified (self, self->entry_user_name);
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 name,
426 * as required by our UI specification: */
427 GList *list_prevent = NULL;
428 list_prevent = g_list_append (list_prevent, "<");
429 list_prevent = g_list_append (list_prevent, ">");
430 modest_validating_entry_set_unallowed_characters (
431 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
432 g_list_free (list_prevent);
434 /* The username widgets: */
435 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
436 /* Auto-capitalization is the default, so let's turn it off: */
437 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
438 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
439 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
440 gtk_widget_show (self->entry_user_username);
441 connect_for_modified (self, self->entry_user_username);
442 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
443 gtk_widget_show (caption);
445 /* Prevent the use of some characters in the username,
446 * as required by our UI specification: */
447 modest_validating_entry_set_unallowed_characters_whitespace (
448 MODEST_VALIDATING_ENTRY (self->entry_user_username));
450 /* Set max length as in the UI spec:
451 * The UI spec seems to want us to show a dialog if we hit the maximum. */
452 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
453 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
456 /* The password widgets: */
457 self->entry_user_password = gtk_entry_new ();
458 /* Auto-capitalization is the default, so let's turn it off: */
459 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
460 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
461 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
462 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
463 caption = create_caption_new_with_asterisk (self, sizegroup,
464 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
465 gtk_widget_show (self->entry_user_password);
466 connect_for_modified (self, self->entry_user_password);
467 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
468 gtk_widget_show (caption);
470 /* The email address widgets: */
471 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
472 /* Auto-capitalization is the default, so let's turn it off: */
473 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
474 caption = create_caption_new_with_asterisk (self, sizegroup,
475 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
476 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
477 gtk_widget_show (self->entry_user_email);
478 connect_for_modified (self, self->entry_user_email);
479 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
480 gtk_widget_show (caption);
482 /* Set max length as in the UI spec:
483 * The UI spec seems to want us to show a dialog if we hit the maximum. */
484 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
485 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
488 /* Signature button: */
489 if (!self->button_signature)
490 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
491 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
492 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
493 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
494 gtk_widget_show (self->button_signature);
495 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
496 gtk_widget_show (caption);
498 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
499 G_CALLBACK (on_button_signature), self);
501 gtk_widget_show (GTK_WIDGET (box));
503 return GTK_WIDGET (box);
506 /** Change the caption title for the incoming server,
507 * as specified in the UI spec:
509 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
512 (protocol == MODEST_PROTOCOL_STORE_POP ?
513 _("mail_fi_emailtype_pop3") :
514 _("mail_fi_emailtype_imap") );
517 /* Note that this produces a compiler warning,
518 * because the compiler does not know that the translated string will have a %s in it.
519 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
520 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
522 /* This is a mandatory field, so add a *. This is usually done by
523 * create_caption_new_with_asterisk() but we can't use that here. */
524 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
525 g_free (incomingserver_title);
527 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
528 g_free(with_asterisk);
531 /** Change the caption title for the incoming server,
532 * as specified in the UI spec:
534 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
536 /* Fill the combo with appropriately titled choices for POP or IMAP. */
537 /* The choices are the same, but the titles are different, as in the UI spec. */
538 modest_serversecurity_combo_box_fill (
539 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
542 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
544 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
546 /* Create a size group to be used by all captions.
547 * Note that HildonCaption does not create a default size group if we do not specify one.
548 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
549 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
551 /* The incoming server widgets: */
552 if(!self->entry_incomingserver)
553 self->entry_incomingserver = gtk_entry_new ();
554 /* Auto-capitalization is the default, so let's turn it off: */
555 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
557 if (self->caption_incoming)
558 gtk_widget_destroy (self->caption_incoming);
560 /* The caption title will be updated in update_incoming_server_title().
561 * so this default text will never be seen: */
562 /* (Note: Changing the title seems pointless. murrayc) */
563 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
564 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
565 gtk_widget_show (self->entry_incomingserver);
566 connect_for_modified (self, self->entry_incomingserver);
567 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
568 gtk_widget_show (self->caption_incoming);
570 /* The secure connection widgets: */
571 /* This will be filled by update_incoming_server_security_choices(). */
572 if (!self->combo_incoming_security)
573 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
574 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
575 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
576 gtk_widget_show (self->combo_incoming_security);
577 connect_for_modified (self, self->combo_incoming_security);
578 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
579 gtk_widget_show (caption);
581 /* Show a default port number when the security method changes, as per the UI spec: */
582 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
585 /* The port widgets: */
586 /* TODO: There are various rules about this in the UI spec. */
587 if (!self->entry_incoming_port)
588 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
589 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
590 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
591 gtk_widget_show (self->entry_incoming_port);
592 connect_for_modified (self, self->entry_incoming_port);
593 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
594 gtk_widget_show (caption);
596 /* The secure authentication widgets: */
597 if(!self->checkbox_incoming_auth)
598 self->checkbox_incoming_auth = gtk_check_button_new ();
599 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
600 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
601 gtk_widget_show (self->checkbox_incoming_auth);
602 connect_for_modified (self, self->checkbox_incoming_auth);
603 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
604 gtk_widget_show (caption);
606 gtk_widget_show (GTK_WIDGET (box));
608 return GTK_WIDGET (box);
612 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
614 GtkWidget *widget = GTK_WIDGET (user_data);
616 /* Enable the widget only if the toggle button is active: */
617 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
618 gtk_widget_set_sensitive (widget, enable);
621 /* Make the sensitivity of a widget depend on a toggle button.
624 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
626 g_signal_connect (G_OBJECT (button), "toggled",
627 G_CALLBACK (on_toggle_button_changed), widget);
629 /* Set the starting sensitivity: */
630 on_toggle_button_changed (button, widget);
634 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
636 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
638 /* Create the window if necessary: */
639 if (!(self->specific_window)) {
640 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
641 modest_connection_specific_smtp_window_fill_with_connections (
642 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
646 /* Show the window: */
647 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
648 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
649 gtk_widget_show (self->specific_window);
653 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
655 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
657 ModestAuthProtocol protocol_security =
658 modest_secureauth_combo_box_get_active_secureauth (
659 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
660 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
662 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
663 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
667 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
669 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
671 const gint port_number =
672 modest_serversecurity_combo_box_get_active_serversecurity_port (
673 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
675 if(port_number != 0) {
676 hildon_number_editor_set_value (
677 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
682 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
684 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
686 const gint port_number =
687 modest_serversecurity_combo_box_get_active_serversecurity_port (
688 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
690 if(port_number != 0) {
691 hildon_number_editor_set_value (
692 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
697 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
699 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
701 /* Create a size group to be used by all captions.
702 * Note that HildonCaption does not create a default size group if we do not specify one.
703 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
704 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
706 /* The outgoing server widgets: */
707 if (!self->entry_outgoingserver)
708 self->entry_outgoingserver = gtk_entry_new ();
709 /* Auto-capitalization is the default, so let's turn it off: */
710 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
711 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
712 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
713 gtk_widget_show (self->entry_outgoingserver);
714 connect_for_modified (self, self->entry_outgoingserver);
715 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
716 gtk_widget_show (caption);
718 /* The secure authentication widgets: */
719 if (!self->combo_outgoing_auth)
720 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
721 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
722 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
723 gtk_widget_show (self->combo_outgoing_auth);
724 connect_for_modified (self, self->combo_outgoing_auth);
725 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
726 gtk_widget_show (caption);
728 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
729 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
731 /* The username widgets: */
732 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
733 /* Auto-capitalization is the default, so let's turn it off: */
734 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
735 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
736 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
737 gtk_widget_show (self->entry_outgoing_username);
738 connect_for_modified (self, self->entry_outgoing_username);
739 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
740 gtk_widget_show (self->caption_outgoing_username);
742 /* Prevent the use of some characters in the username,
743 * as required by our UI specification: */
744 modest_validating_entry_set_unallowed_characters_whitespace (
745 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
747 /* Set max length as in the UI spec:
748 * The UI spec seems to want us to show a dialog if we hit the maximum. */
749 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
750 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
753 /* The password widgets: */
754 self->entry_outgoing_password = gtk_entry_new ();
755 /* Auto-capitalization is the default, so let's turn it off: */
756 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
757 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
758 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
759 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
760 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
761 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
762 gtk_widget_show (self->entry_outgoing_password);
763 connect_for_modified (self, self->entry_outgoing_password);
764 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
765 gtk_widget_show (self->caption_outgoing_password);
767 /* The secure connection widgets: */
768 /* This will be filled and set with modest_serversecurity_combo_box_fill()
769 * and modest_serversecurity_combo_box_set_active_serversecurity().
771 if (!self->combo_outgoing_security)
773 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
774 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
775 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
776 gtk_widget_show (self->combo_outgoing_security);
777 connect_for_modified (self, self->combo_outgoing_security);
778 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
779 gtk_widget_show (caption);
781 /* Show a default port number when the security method changes, as per the UI spec: */
782 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
784 /* The port widgets: */
785 if (!self->entry_outgoing_port)
786 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
787 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
788 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
789 gtk_widget_show (self->entry_outgoing_port);
790 connect_for_modified (self, self->entry_outgoing_port);
791 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
792 gtk_widget_show (caption);
794 GtkWidget *separator = gtk_hseparator_new ();
795 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
796 gtk_widget_show (separator);
798 /* connection-specific checkbox: */
799 if (!self->checkbox_outgoing_smtp_specific) {
800 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
801 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
804 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
805 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
806 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
807 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
808 gtk_widget_show (caption);
809 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
811 /* Connection-specific SMTP-Severs Edit button: */
812 if (!self->button_outgoing_smtp_servers)
813 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
814 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
815 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
816 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
817 gtk_widget_show (self->button_outgoing_smtp_servers);
818 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
819 gtk_widget_show (caption);
821 /* Only enable the button when the checkbox is checked: */
822 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
823 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
825 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
826 G_CALLBACK (on_button_outgoing_smtp_servers), self);
828 gtk_widget_show (GTK_WIDGET (box));
830 return GTK_WIDGET (box);
834 check_data (ModestAccountSettingsDialog *self)
836 /* Check that the title is not already in use: */
837 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
838 if ((!account_title) || (strlen(account_title) == 0))
839 return FALSE; /* Should be prevented already anyway. */
841 if (strcmp(account_title, self->original_account_title) != 0) {
842 /* Check the changed title: */
843 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
847 /* Warn the user via a dialog: */
848 hildon_banner_show_information(NULL, NULL, _("mail_ib_account_name_already_existing"));
854 /* Check that the email address is valud: */
855 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
856 if ((!email_address) || (strlen(email_address) == 0))
859 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
860 /* Warn the user via a dialog: */
861 /*show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));*/
862 hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_email"));
864 /* Return focus to the email address entry: */
865 gtk_widget_grab_focus (self->entry_user_email);
866 gtk_editable_select_region (GTK_EDITABLE (self->entry_user_email), 0, -1);
870 /* Find a suitable authentication method when secure authentication is desired */
871 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (self->entry_incomingserver));
872 gint port_num = hildon_number_editor_get_value (
873 HILDON_NUMBER_EDITOR (self->entry_incoming_port));
874 const gchar* username = gtk_entry_get_text (GTK_ENTRY (self->entry_user_username));
876 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
877 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
879 /* If we use an encrypted protocol then there is no need to encrypt the password */
880 if (!modest_protocol_info_is_secure(protocol_security_incoming))
882 if (gtk_toggle_button_get_active (
883 GTK_TOGGLE_BUTTON (self->checkbox_incoming_auth))) {
884 GError *error = NULL;
885 GList *list_auth_methods =
886 modest_maemo_utils_get_supported_secure_authentication_methods (self->incoming_protocol,
887 hostname, port_num, username, GTK_WINDOW (self), &error);
888 if (list_auth_methods) {
889 /* Use the first supported method.
890 * TODO: Should we prioritize them, to prefer a particular one? */
892 for (method = list_auth_methods; method != NULL; method = g_list_next(method))
894 ModestAuthProtocol proto = (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
895 // Allow secure methods, e.g MD5 only
896 if (modest_protocol_info_auth_is_secure(proto))
898 self->protocol_authentication_incoming = proto;
902 g_list_free (list_auth_methods);
905 if (list_auth_methods == NULL ||
906 !modest_protocol_info_auth_is_secure(self->protocol_authentication_incoming))
908 if(error == NULL || error->domain != modest_maemo_utils_get_supported_secure_authentication_error_quark() ||
909 error->code != MODEST_MAEMO_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED)
911 show_error (GTK_WIDGET (self), _("Could not discover supported secure authentication methods."));
917 /* This is a nasty hack. jschmid. */
918 /* Don't let the dialog close */
919 /*g_signal_stop_emission_by_name (dialog, "response");*/
925 /* TODO: The UI Spec wants us to check that the servernames are valid,
926 * but does not specify how.
934 on_response (GtkDialog *wizard_dialog,
938 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
939 enable_buttons (self);
941 gboolean prevent_response = FALSE;
943 /* Warn about unsaved changes: */
944 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
945 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
946 _("imum_nc_wizard_confirm_lose_changes")));
947 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
949 const gint dialog_response = gtk_dialog_run (dialog);
950 gtk_widget_destroy (GTK_WIDGET (dialog));
952 if (dialog_response != GTK_RESPONSE_OK)
953 prevent_response = TRUE;
955 /* Check for invalid input: */
956 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
957 prevent_response = TRUE;
960 if (prevent_response) {
961 /* This is a nasty hack. murrayc. */
962 /* Don't let the dialog close */
963 g_signal_stop_emission_by_name (wizard_dialog, "response");
967 if (response_id == GTK_RESPONSE_OK) {
968 /* Try to save the changes if modified (NB #59251): */
971 const gboolean saved = save_configuration (self);
973 /* Do not show the account-saved dialog if we are just saving this
974 * temporarily, because from the user's point of view it will not
975 * really be saved (saved + enabled) until later.
977 const gboolean enabled =
978 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
980 show_error (GTK_WIDGET (self), _("mcen_ib_advsetup_settings_saved"));
983 show_error (GTK_WIDGET (self), _("mail_ib_setting_failed"));
989 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
991 /* Create the notebook to be used by the GtkDialog base class:
992 * Each page of the notebook will be a page of the wizard: */
993 self->notebook = GTK_NOTEBOOK (gtk_notebook_new());
995 /* Get the account manager object,
996 * so we can check for existing accounts,
997 * and create new accounts: */
998 self->account_manager = modest_runtime_get_account_mgr ();
999 g_assert (self->account_manager);
1000 g_object_ref (self->account_manager);
1002 self->protocol_authentication_incoming = MODEST_PROTOCOL_AUTH_PASSWORD;
1004 /* Create the common pages,
1006 self->page_account_details = create_page_account_details (self);
1007 self->page_user_details = create_page_user_details (self);
1008 self->page_incoming = create_page_incoming (self);
1009 self->page_outgoing = create_page_outgoing (self);
1011 /* Add the notebook pages: */
1012 gtk_notebook_append_page (self->notebook, self->page_account_details,
1013 gtk_label_new (_("mcen_ti_account_settings_account")));
1014 gtk_notebook_append_page (self->notebook, self->page_user_details,
1015 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
1016 gtk_notebook_append_page (self->notebook, self->page_incoming,
1017 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
1018 gtk_notebook_append_page (self->notebook, self->page_outgoing,
1019 gtk_label_new (_("mcen_ti_advsetup_sending")));
1021 GtkDialog *dialog = GTK_DIALOG (self);
1022 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (self->notebook));
1023 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1024 gtk_widget_show (GTK_WIDGET (self->notebook));
1026 /* Add the buttons: */
1027 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
1028 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
1030 /* Connect to the dialog's response signal: */
1031 /* We use connect-before
1032 * so we can stop the signal emission,
1033 * to stop the default signal handler from closing the dialog.
1035 g_signal_connect (G_OBJECT (self), "response",
1036 G_CALLBACK (on_response), self);
1038 self->modified = FALSE;
1040 /* When this window is shown, hibernation should not be possible,
1041 * because there is no sensible way to save the state: */
1042 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1043 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1046 ModestAccountSettingsDialog*
1047 modest_account_settings_dialog_new (void)
1049 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
1052 /** Update the UI with the stored account details, so they can be edited.
1053 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1055 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
1060 /* Save the account name so we can refer to it later: */
1061 if (dialog->account_name)
1062 g_free (dialog->account_name);
1063 dialog->account_name = g_strdup (account_name);
1066 /* Get the account data for this account name: */
1067 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
1069 if (!account_data) {
1070 g_printerr ("modest: failed to get account data for %s\n", account_name);
1074 /* Save the account title so we can refer to it if the user changes it: */
1075 if (dialog->original_account_title)
1076 g_free (dialog->original_account_title);
1077 dialog->original_account_title = g_strdup (account_data->display_name);
1080 if (!(account_data->store_account)) {
1081 g_printerr ("modest: account has no stores: %s\n", account_name);
1085 /* Show the account data in the widgets: */
1087 /* Note that we never show the non-display name in the UI.
1088 * (Though the display name defaults to the non-display name at the start.) */
1089 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1090 account_data->display_name ? account_data->display_name : "");
1092 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1093 account_data->fullname ? account_data->fullname : "");
1094 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1095 account_data->email ? account_data->email : "");
1097 ModestServerAccountData *incoming_account = account_data->store_account;
1099 if (incoming_account)
1100 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1101 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1102 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1104 /* Default to something, though no default is specified in the UI spec: */
1105 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1107 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1110 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1111 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1112 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1115 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1116 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1117 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1119 /* Only show the leave-on-server checkbox for POP,
1120 * as per the UI spec: */
1121 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1122 gtk_widget_hide (dialog->caption_leave_messages);
1124 gtk_widget_show (dialog->caption_leave_messages);
1127 update_incoming_server_security_choices (dialog, incoming_account->proto);
1128 if (incoming_account) {
1129 /* Remember this for later: */
1130 dialog->incoming_protocol = incoming_account->proto;
1132 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1133 incoming_account->username ? incoming_account->username : "");
1134 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1135 incoming_account->password ? incoming_account->password : "");
1137 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1138 incoming_account->hostname ? incoming_account->hostname : "");
1140 /* The UI spec says:
1141 * If secure authentication is unchecked, allow sending username and password also as plain text.
1142 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1143 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1145 const ModestConnectionProtocol security = modest_server_account_get_security (
1146 dialog->account_manager, incoming_account->account_name);
1147 modest_serversecurity_combo_box_set_active_serversecurity (
1148 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1153 - use encrypted passwords
1155 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1156 dialog->account_manager, incoming_account->account_name);
1157 dialog->protocol_authentication_incoming = secure_auth;
1158 if (modest_protocol_info_is_secure(security) ||
1159 modest_protocol_info_auth_is_secure(secure_auth))
1161 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1166 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1170 update_incoming_server_title (dialog, incoming_account->proto);
1172 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1173 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1175 if (port_num == 0) {
1176 /* Show the appropriate port number: */
1177 on_combo_incoming_security_changed (
1178 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1180 /* Keep the user-entered port-number,
1181 * or the already-appropriate automatic port number: */
1182 hildon_number_editor_set_value (
1183 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1187 ModestServerAccountData *outgoing_account = account_data->transport_account;
1188 if (outgoing_account) {
1189 /* Remember this for later: */
1190 dialog->outgoing_protocol = outgoing_account->proto;
1192 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1193 outgoing_account->hostname ? outgoing_account->hostname : "");
1195 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1196 outgoing_account->username ? outgoing_account->username : "");
1197 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1198 outgoing_account->password ? outgoing_account->password : "");
1200 /* Get the secure-auth setting: */
1201 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1202 dialog->account_manager, outgoing_account->account_name);
1203 modest_secureauth_combo_box_set_active_secureauth (
1204 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1205 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1207 modest_serversecurity_combo_box_fill (
1208 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1210 /* Get the security setting: */
1211 const ModestConnectionProtocol security = modest_server_account_get_security (
1212 dialog->account_manager, outgoing_account->account_name);
1213 modest_serversecurity_combo_box_set_active_serversecurity (
1214 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1216 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1217 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1218 if (port_num == 0) {
1219 /* Show the appropriate port number: */
1220 on_combo_outgoing_security_changed (
1221 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1224 /* Keep the user-entered port-number,
1225 * or the already-appropriate automatic port number: */
1226 hildon_number_editor_set_value (
1227 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1230 const gboolean has_specific =
1231 modest_account_mgr_get_has_connection_specific_smtp (
1232 dialog->account_manager,
1234 gtk_toggle_button_set_active (
1235 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1239 /* Set window title according to account: */
1240 /* TODO: Is this the correct way to find a human-readable name for
1241 * the protocol used? */
1242 const gchar* proto_str = modest_protocol_info_get_transport_store_protocol_name (dialog->incoming_protocol);
1243 gchar *proto_name = g_utf8_strup(proto_str, -1);
1244 gchar *account_title = modest_account_mgr_get_display_name(dialog->account_manager, account_name);
1246 gchar *title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1247 g_free (proto_name);
1248 g_free (account_title);
1250 gtk_window_set_title (GTK_WINDOW (dialog), title);
1253 /* account_data->is_enabled, */
1254 /*account_data->is_default, */
1256 /* account_data->store_account->proto */
1258 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1260 /* Unset the modified flag so we can detect changes later: */
1261 dialog->modified = FALSE;
1264 /** Show the User Info tab.
1266 void modest_account_settings_dialog_switch_to_user_info (ModestAccountSettingsDialog *dialog)
1268 const gint page_num = gtk_notebook_page_num (dialog->notebook, dialog->page_user_details);
1269 if (page_num == -1) {
1270 g_warning ("%s: notebook page not found.\n", __FUNCTION__);
1273 /* Ensure that the widget is visible so that gtk_notebook_set_current_page() works: */
1274 /* TODO: even this hack (recommened by the GTK+ documentation) doesn't seem to work. */
1276 gtk_widget_show (dialog->page_user_details);
1277 gtk_widget_show (GTK_WIDGET (dialog->notebook));
1278 gtk_widget_show (GTK_WIDGET (dialog));
1279 gtk_notebook_set_current_page (dialog->notebook, page_num);
1283 save_configuration (ModestAccountSettingsDialog *dialog)
1285 g_assert (dialog->account_name);
1287 const gchar* account_name = dialog->account_name;
1289 /* Set the account data from the widgets: */
1290 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1291 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1292 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1296 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1297 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1298 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1303 if (dialog->signature_dialog) {
1304 gboolean use_signature = FALSE;
1305 gchar *signature = modest_signature_editor_dialog_get_settings (
1306 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1309 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1310 signature, use_signature);
1314 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1315 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1316 modest_account_mgr_set_string (dialog->account_manager, account_name,
1317 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1320 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1321 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1322 modest_account_mgr_set_int (dialog->account_manager, account_name,
1323 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1325 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1326 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1327 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1332 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1333 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1334 g_assert (incoming_account_name);
1336 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1337 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1338 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1342 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1343 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1345 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1346 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1349 gint port_num = hildon_number_editor_get_value (
1350 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1351 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1352 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1354 /* The UI spec says:
1355 * If secure authentication is unchecked, allow sending username and password also as plain text.
1356 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1359 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1360 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1361 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1363 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, dialog->protocol_authentication_incoming);
1366 g_free (incoming_account_name);
1369 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1370 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1371 g_assert (outgoing_account_name);
1373 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1374 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1375 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1379 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1380 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1383 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1384 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1387 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1388 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1389 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1391 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1392 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1393 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1396 port_num = hildon_number_editor_get_value (
1397 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1398 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1399 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1401 g_free (outgoing_account_name);
1404 /* Set the changed account title last, to simplify the previous code: */
1405 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1406 if ((!account_title) || (strlen(account_title) == 0))
1407 return FALSE; /* Should be prevented already anyway. */
1409 if (strcmp(account_title, account_name) != 0) {
1410 /* Change the title: */
1411 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1412 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1417 /* Save connection-specific SMTP server accounts: */
1418 if (dialog->specific_window) {
1419 return modest_connection_specific_smtp_window_save_server_accounts (
1420 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1426 static gboolean entry_is_empty (GtkWidget *entry)
1431 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1432 if ((!text) || (strlen(text) == 0))
1439 enable_buttons (ModestAccountSettingsDialog *self)
1441 gboolean enable_ok = TRUE;
1443 /* The account details title is mandatory: */
1444 if (entry_is_empty(self->entry_account_title))
1447 /* The user details username is mandatory: */
1448 if (entry_is_empty(self->entry_user_username))
1451 /* The user details email address is mandatory: */
1452 if (enable_ok && entry_is_empty (self->entry_user_email))
1455 /* The custom incoming server is mandatory: */
1456 if (entry_is_empty(self->entry_incomingserver))
1459 /* Enable the buttons,
1460 * identifying them via their associated response codes:
1462 GtkDialog *dialog_base = GTK_DIALOG (self);
1463 gtk_dialog_set_response_sensitive (dialog_base,
1469 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1471 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1472 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1475 object_class->get_property = modest_account_settings_dialog_get_property;
1476 object_class->set_property = modest_account_settings_dialog_set_property;
1477 object_class->dispose = modest_account_settings_dialog_dispose;
1478 object_class->finalize = modest_account_settings_dialog_finalize;
1482 show_error (GtkWidget *parent_widget, const gchar* text)
1484 hildon_banner_show_information(parent_widget, NULL, text);
1487 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_widget, text);
1489 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1496 gtk_dialog_run (dialog);
1497 gtk_widget_destroy (GTK_WIDGET (dialog));