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 "maemo/modest-connection-specific-smtp-window.h"
54 #include "maemo/modest-signature-editor-dialog.h"
55 #include "widgets/modest-ui-constants.h"
57 #include <tny-camel-transport-account.h>
58 #include <tny-camel-imap-store-account.h>
59 #include <tny-camel-pop-store-account.h>
61 #include <gconf/gconf-client.h>
62 #include <string.h> /* For strlen(). */
64 /* Include config.h so that _() works: */
69 #define EXAMPLE_EMAIL_ADDRESS "first.last@provider.com"
71 G_DEFINE_TYPE (ModestAccountSettingsDialog, modest_account_settings_dialog, GTK_TYPE_DIALOG);
73 #define ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
74 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, ModestAccountSettingsDialogPrivate))
76 typedef struct _ModestAccountSettingsDialogPrivate ModestAccountSettingsDialogPrivate;
78 struct _ModestAccountSettingsDialogPrivate
83 enable_buttons (ModestAccountSettingsDialog *self);
86 save_configuration (ModestAccountSettingsDialog *dialog);
89 modest_account_settings_dialog_get_property (GObject *object, guint property_id,
90 GValue *value, GParamSpec *pspec)
92 switch (property_id) {
94 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
99 modest_account_settings_dialog_set_property (GObject *object, guint property_id,
100 const GValue *value, GParamSpec *pspec)
102 switch (property_id) {
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
109 modest_account_settings_dialog_dispose (GObject *object)
111 if (G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose)
112 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->dispose (object);
116 modest_account_settings_dialog_finalize (GObject *object)
118 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (object);
120 if (self->account_name)
121 g_free (self->account_name);
123 if (self->original_account_title)
124 g_free (self->original_account_title);
126 if (self->account_manager)
127 g_object_unref (G_OBJECT (self->account_manager));
129 if (self->specific_window)
130 gtk_widget_destroy (self->specific_window);
132 if (self->signature_dialog)
133 gtk_widget_destroy (self->signature_dialog);
135 G_OBJECT_CLASS (modest_account_settings_dialog_parent_class)->finalize (object);
139 show_error (GtkWindow *parent_window, const gchar* text);
142 show_ok (GtkWindow *parent_window, 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;
171 /* Set a modified boolean whenever the widget is changed,
172 * so we can check for it later.
175 connect_for_modified (ModestAccountSettingsDialog *self, GtkWidget *widget)
177 if (GTK_IS_ENTRY (widget)) {
178 g_signal_connect (G_OBJECT (widget), "changed",
179 G_CALLBACK (on_modified_entry_changed), self);
180 } else if (GTK_IS_COMBO_BOX (widget)) {
181 g_signal_connect (G_OBJECT (widget), "changed",
182 G_CALLBACK (on_modified_combobox_changed), self);
183 } else if (GTK_IS_TOGGLE_BUTTON (widget)) {
184 g_signal_connect (G_OBJECT (widget), "toggled",
185 G_CALLBACK (on_modified_checkbox_toggled), self);
190 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
192 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
194 enable_buttons(self);
198 on_caption_combobox_changed (GtkComboBox *widget, gpointer user_data)
200 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
202 enable_buttons(self);
205 /** This is a convenience function to create a caption containing a mandatory widget.
206 * When the widget is edited, the enable_buttons() vfunc will be called.
208 static GtkWidget* create_caption_new_with_asterix(ModestAccountSettingsDialog *self,
213 HildonCaptionStatus flag)
215 GtkWidget *caption = hildon_caption_new (group, value, control, icon, flag);
217 /* The translated strings seem to already contain the *,
218 * but this code can be used if that is not true in future.
221 /* Add a * character to indicate mandatory fields,
222 * as specified in our "Email UI Specification": */
223 if (flag == HILDON_CAPTION_MANDATORY) {
224 gchar* title = g_strdup_printf("%s*", value);
225 caption = hildon_caption_new (group, title, control, icon, flag);
229 caption = hildon_caption_new (group, value, control, icon, flag);
232 /* Connect to the appropriate changed signal for the widget,
233 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
235 if (GTK_IS_ENTRY (control)) {
236 g_signal_connect (G_OBJECT (control), "changed",
237 G_CALLBACK (on_caption_entry_changed), self);
240 else if (GTK_IS_COMBO_BOX (control)) {
241 g_signal_connect (G_OBJECT (control), "changed",
242 G_CALLBACK (on_caption_combobox_changed), self);
250 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
252 ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
253 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
257 create_page_account_details (ModestAccountSettingsDialog *self)
259 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
260 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
261 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
262 gtk_widget_show (label);
264 /* Create a size group to be used by all captions.
265 * Note that HildonCaption does not create a default size group if we do not specify one.
266 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
267 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
269 /* The description widgets: */
270 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
271 /* Do use auto-capitalization: */
272 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
273 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
274 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_account_title"),
275 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
276 gtk_widget_show (self->entry_account_title);
277 connect_for_modified (self, self->entry_account_title);
278 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
279 gtk_widget_show (caption);
281 /* Prevent the use of some characters in the account title,
282 * as required by our UI specification: */
283 GList *list_prevent = NULL;
284 list_prevent = g_list_append (list_prevent, "\\");
285 list_prevent = g_list_append (list_prevent, "/");
286 list_prevent = g_list_append (list_prevent, ":");
287 list_prevent = g_list_append (list_prevent, "*");
288 list_prevent = g_list_append (list_prevent, "?");
289 list_prevent = g_list_append (list_prevent, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
290 list_prevent = g_list_append (list_prevent, "“");
291 list_prevent = g_list_append (list_prevent, "<");
292 list_prevent = g_list_append (list_prevent, ">");
293 list_prevent = g_list_append (list_prevent, "|");
294 list_prevent = g_list_append (list_prevent, "^");
295 modest_validating_entry_set_unallowed_characters (
296 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
297 g_list_free (list_prevent);
299 /* Set max length as in the UI spec:
300 * The UI spec seems to want us to show a dialog if we hit the maximum. */
301 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
302 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
305 /* The retrieve combobox: */
306 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
307 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
308 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
309 gtk_widget_show (self->combo_retrieve);
310 connect_for_modified (self, self->combo_retrieve);
311 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
312 gtk_widget_show (caption);
314 /* The limit-retrieve combobox: */
315 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
316 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
317 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
318 gtk_widget_show (self->combo_limit_retrieve);
319 connect_for_modified (self, self->combo_limit_retrieve);
320 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
321 gtk_widget_show (caption);
323 /* The leave-messages widgets: */
324 if(!self->checkbox_leave_messages)
325 self->checkbox_leave_messages = gtk_check_button_new ();
326 if (!self->caption_leave_messages) {
327 self->caption_leave_messages = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
328 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
331 gtk_widget_show (self->checkbox_leave_messages);
332 connect_for_modified (self, self->checkbox_leave_messages);
333 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
334 gtk_widget_show (self->caption_leave_messages);
336 gtk_widget_show (GTK_WIDGET (box));
338 return GTK_WIDGET (box);
342 on_button_signature (GtkButton *button, gpointer user_data)
344 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
346 /* Create the window, if necessary: */
347 if (!(self->signature_dialog)) {
348 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
350 gboolean use_signature = FALSE;
351 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
353 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
354 modest_signature_editor_dialog_set_settings (
355 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
356 use_signature, signature, account_title);
361 /* Show the window: */
362 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
363 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
364 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
365 gtk_widget_hide (self->signature_dialog);
366 if (response != GTK_RESPONSE_OK) {
367 /* Destroy the widget now, and its data: */
368 gtk_widget_destroy (self->signature_dialog);
369 self->signature_dialog = NULL;
372 /* Mark modified, so we use the dialog's data later: */
373 self->modified = TRUE;
378 create_page_user_details (ModestAccountSettingsDialog *self)
380 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
382 /* Create a size group to be used by all captions.
383 * Note that HildonCaption does not create a default size group if we do not specify one.
384 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
385 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
387 /* The name widgets: */
388 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
389 /* Auto-capitalization is the default, so let's turn it off: */
390 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
391 /* Set max length as in the UI spec:
392 * The UI spec seems to want us to show a dialog if we hit the maximum. */
393 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
394 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
396 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
397 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
398 gtk_widget_show (self->entry_user_name);
399 connect_for_modified (self, self->entry_user_name);
400 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
401 gtk_widget_show (caption);
403 /* Prevent the use of some characters in the name,
404 * as required by our UI specification: */
405 GList *list_prevent = NULL;
406 list_prevent = g_list_append (list_prevent, "<");
407 list_prevent = g_list_append (list_prevent, ">");
408 modest_validating_entry_set_unallowed_characters (
409 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
410 g_list_free (list_prevent);
412 /* The username widgets: */
413 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
414 /* Auto-capitalization is the default, so let's turn it off: */
415 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
416 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
417 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
418 gtk_widget_show (self->entry_user_username);
419 connect_for_modified (self, self->entry_user_username);
420 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
421 gtk_widget_show (caption);
423 /* Prevent the use of some characters in the username,
424 * as required by our UI specification: */
425 modest_validating_entry_set_unallowed_characters_whitespace (
426 MODEST_VALIDATING_ENTRY (self->entry_user_username));
428 /* Set max length as in the UI spec:
429 * The UI spec seems to want us to show a dialog if we hit the maximum. */
430 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
431 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
434 /* The password widgets: */
435 self->entry_user_password = gtk_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_password),
438 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
439 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
440 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
441 caption = create_caption_new_with_asterix (self, sizegroup,
442 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
443 gtk_widget_show (self->entry_user_password);
444 connect_for_modified (self, self->entry_user_password);
445 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
446 gtk_widget_show (caption);
448 /* The email address widgets: */
449 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
450 /* Auto-capitalization is the default, so let's turn it off: */
451 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
452 caption = create_caption_new_with_asterix (self, sizegroup,
453 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
454 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
455 gtk_widget_show (self->entry_user_email);
456 connect_for_modified (self, self->entry_user_email);
457 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
458 gtk_widget_show (caption);
460 /* Set max length as in the UI spec:
461 * The UI spec seems to want us to show a dialog if we hit the maximum. */
462 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
463 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
466 /* Signature button: */
467 if (!self->button_signature)
468 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
469 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
470 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
471 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
472 gtk_widget_show (self->button_signature);
473 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
474 gtk_widget_show (caption);
476 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
477 G_CALLBACK (on_button_signature), self);
479 gtk_widget_show (GTK_WIDGET (box));
481 return GTK_WIDGET (box);
484 /** Change the caption title for the incoming server,
485 * as specified in the UI spec:
487 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
490 (protocol == MODEST_PROTOCOL_STORE_POP ?
491 _("mail_fi_emailtype_pop3") :
492 _("mail_fi_emailtype_imap") );
495 /* Note that this produces a compiler warning,
496 * because the compiler does not know that the translated string will have a %s in it.
497 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
498 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
499 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
500 g_free(incomingserver_title);
503 /** Change the caption title for the incoming server,
504 * as specified in the UI spec:
506 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
508 /* Fill the combo with appropriately titled choices for POP or IMAP. */
509 /* The choices are the same, but the titles are different, as in the UI spec. */
510 modest_serversecurity_combo_box_fill (
511 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
514 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
516 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
518 /* Create a size group to be used by all captions.
519 * Note that HildonCaption does not create a default size group if we do not specify one.
520 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
521 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
523 /* The incoming server widgets: */
524 if(!self->entry_incomingserver)
525 self->entry_incomingserver = gtk_entry_new ();
526 /* Auto-capitalization is the default, so let's turn it off: */
527 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
529 if (self->caption_incoming)
530 gtk_widget_destroy (self->caption_incoming);
532 /* The caption title will be updated in update_incoming_server_title().
533 * so this default text will never be seen: */
534 /* (Note: Changing the title seems pointless. murrayc) */
535 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
536 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
537 gtk_widget_show (self->entry_incomingserver);
538 connect_for_modified (self, self->entry_incomingserver);
539 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
540 gtk_widget_show (self->caption_incoming);
542 /* The secure connection widgets: */
543 /* This will be filled by update_incoming_server_security_choices(). */
544 if (!self->combo_incoming_security)
545 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
546 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
547 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
548 gtk_widget_show (self->combo_incoming_security);
549 connect_for_modified (self, self->combo_incoming_security);
550 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
551 gtk_widget_show (caption);
553 /* Show a default port number when the security method changes, as per the UI spec: */
554 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
557 /* The port widgets: */
558 /* TODO: There are various rules about this in the UI spec. */
559 if (!self->entry_incoming_port)
560 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
561 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
562 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
563 gtk_widget_show (self->entry_incoming_port);
564 connect_for_modified (self, self->entry_incoming_port);
565 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
566 gtk_widget_show (caption);
568 /* The secure authentication widgets: */
569 if(!self->checkbox_incoming_auth)
570 self->checkbox_incoming_auth = gtk_check_button_new ();
571 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
572 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
573 gtk_widget_show (self->checkbox_incoming_auth);
574 connect_for_modified (self, self->checkbox_incoming_auth);
575 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
576 gtk_widget_show (caption);
578 gtk_widget_show (GTK_WIDGET (box));
580 return GTK_WIDGET (box);
584 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
586 GtkWidget *widget = GTK_WIDGET (user_data);
588 /* Enable the widget only if the toggle button is active: */
589 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
590 gtk_widget_set_sensitive (widget, enable);
593 /* Make the sensitivity of a widget depend on a toggle button.
596 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
598 g_signal_connect (G_OBJECT (button), "toggled",
599 G_CALLBACK (on_toggle_button_changed), widget);
601 /* Set the starting sensitivity: */
602 on_toggle_button_changed (button, widget);
606 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
608 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
610 /* Create the window if necessary: */
611 if (!(self->specific_window)) {
612 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
613 modest_connection_specific_smtp_window_fill_with_connections (
614 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
618 /* Show the window: */
619 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
620 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
621 gtk_widget_show (self->specific_window);
625 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
627 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
629 ModestAuthProtocol protocol_security =
630 modest_secureauth_combo_box_get_active_secureauth (
631 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
632 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
634 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
635 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
639 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
641 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
643 const gint port_number =
644 modest_serversecurity_combo_box_get_active_serversecurity_port (
645 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
647 if(port_number != 0) {
648 hildon_number_editor_set_value (
649 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
654 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
656 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
658 const gint port_number =
659 modest_serversecurity_combo_box_get_active_serversecurity_port (
660 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
662 if(port_number != 0) {
663 hildon_number_editor_set_value (
664 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
669 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
671 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
673 /* Create a size group to be used by all captions.
674 * Note that HildonCaption does not create a default size group if we do not specify one.
675 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
676 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
678 /* The outgoing server widgets: */
679 if (!self->entry_outgoingserver)
680 self->entry_outgoingserver = gtk_entry_new ();
681 /* Auto-capitalization is the default, so let's turn it off: */
682 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
683 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
684 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
685 gtk_widget_show (self->entry_outgoingserver);
686 connect_for_modified (self, self->entry_outgoingserver);
687 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
688 gtk_widget_show (caption);
690 /* The secure authentication widgets: */
691 if (!self->combo_outgoing_auth)
692 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
693 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
694 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
695 gtk_widget_show (self->combo_outgoing_auth);
696 connect_for_modified (self, self->combo_outgoing_auth);
697 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
698 gtk_widget_show (caption);
700 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
701 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
703 /* The username widgets: */
704 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
705 /* Auto-capitalization is the default, so let's turn it off: */
706 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
707 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
708 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
709 gtk_widget_show (self->entry_outgoing_username);
710 connect_for_modified (self, self->entry_outgoing_username);
711 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
712 gtk_widget_show (self->caption_outgoing_username);
714 /* Prevent the use of some characters in the username,
715 * as required by our UI specification: */
716 modest_validating_entry_set_unallowed_characters_whitespace (
717 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
719 /* Set max length as in the UI spec:
720 * The UI spec seems to want us to show a dialog if we hit the maximum. */
721 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
722 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
725 /* The password widgets: */
726 self->entry_outgoing_password = gtk_entry_new ();
727 /* Auto-capitalization is the default, so let's turn it off: */
728 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
729 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
730 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
731 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
732 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
733 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
734 gtk_widget_show (self->entry_outgoing_password);
735 connect_for_modified (self, self->entry_outgoing_password);
736 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
737 gtk_widget_show (self->caption_outgoing_password);
739 /* The secure connection widgets: */
740 /* This will be filled and set with modest_serversecurity_combo_box_fill()
741 * and modest_serversecurity_combo_box_set_active_serversecurity().
743 if (!self->combo_outgoing_security)
744 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
745 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
746 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
747 gtk_widget_show (self->combo_outgoing_security);
748 connect_for_modified (self, self->combo_outgoing_security);
749 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
750 gtk_widget_show (caption);
752 /* Show a default port number when the security method changes, as per the UI spec: */
753 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
755 /* The port widgets: */
756 if (!self->entry_outgoing_port)
757 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
758 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
759 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
760 gtk_widget_show (self->entry_outgoing_port);
761 connect_for_modified (self, self->entry_outgoing_port);
762 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
763 gtk_widget_show (caption);
765 GtkWidget *separator = gtk_hseparator_new ();
766 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
767 gtk_widget_show (separator);
769 /* connection-specific checkbox: */
770 if (!self->checkbox_outgoing_smtp_specific) {
771 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
772 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
775 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
776 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
777 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
778 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
779 gtk_widget_show (caption);
780 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
782 /* Connection-specific SMTP-Severs Edit button: */
783 if (!self->button_outgoing_smtp_servers)
784 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
785 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
786 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
787 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
788 gtk_widget_show (self->button_outgoing_smtp_servers);
789 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
790 gtk_widget_show (caption);
792 /* Only enable the button when the checkbox is checked: */
793 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
794 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
796 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
797 G_CALLBACK (on_button_outgoing_smtp_servers), self);
799 gtk_widget_show (GTK_WIDGET (box));
801 return GTK_WIDGET (box);
805 check_data (ModestAccountSettingsDialog *self)
807 /* Check that the title is not already in use: */
808 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
809 if ((!account_title) || (strlen(account_title) == 0))
810 return FALSE; /* Should be prevented already anyway. */
812 if (strcmp(account_title, self->original_account_title) != 0) {
813 /* Check the changed title: */
814 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
818 /* Warn the user via a dialog: */
819 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
825 /* Check that the email address is valud: */
826 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
827 if ((!email_address) || (strlen(email_address) == 0))
830 if (!modest_text_utils_validate_email_address (email_address)) {
831 /* Warn the user via a dialog: */
832 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
834 /* Return focus to the email address entry: */
835 gtk_widget_grab_focus (self->entry_user_email);
840 /* TODO: The UI Spec wants us to check that the servernames are valid,
841 * but does not specify how.
849 on_response (GtkDialog *wizard_dialog,
853 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
854 enable_buttons (self);
856 gboolean prevent_response = FALSE;
858 /* Warn about unsaved changes: */
859 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
860 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
861 _("imum_nc_wizard_confirm_lose_changes")));
862 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
864 const gint dialog_response = gtk_dialog_run (dialog);
865 gtk_widget_destroy (GTK_WIDGET (dialog));
867 if (dialog_response != GTK_RESPONSE_OK)
868 prevent_response = TRUE;
870 /* Check for invalid input: */
871 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
872 prevent_response = TRUE;
875 if (prevent_response) {
876 /* This is a nasty hack. murrayc. */
877 /* Don't let the dialog close */
878 g_signal_stop_emission_by_name (wizard_dialog, "response");
882 if (response_id == GTK_RESPONSE_OK) {
883 /* Try to save the changes: */
884 const gboolean saved = save_configuration (self);
886 /* Do not show the account-saved dialog if we are just saving this
887 * temporarily, because from the user's point of view it will not
888 * really be saved (saved + enabled) until later.
890 const gboolean enabled =
891 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
893 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
896 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
901 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
903 /* Create the notebook to be used by the GtkDialog base class:
904 * Each page of the notebook will be a page of the wizard: */
905 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
908 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
910 /* Get the account manager object,
911 * so we can check for existing accounts,
912 * and create new accounts: */
913 self->account_manager = modest_runtime_get_account_mgr ();
914 g_assert (self->account_manager);
915 g_object_ref (self->account_manager);
917 /* Create the common pages,
919 self->page_account_details = create_page_account_details (self);
920 self->page_user_details = create_page_user_details (self);
921 self->page_incoming = create_page_incoming (self);
922 self->page_outgoing = create_page_outgoing (self);
924 /* Add the notebook pages: */
925 gtk_notebook_append_page (notebook, self->page_account_details,
926 gtk_label_new (_("mcen_ti_account_settings_account")));
927 gtk_notebook_append_page (notebook, self->page_user_details,
928 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
929 gtk_notebook_append_page (notebook, self->page_incoming,
930 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
931 gtk_notebook_append_page (notebook, self->page_outgoing,
932 gtk_label_new (_("mcen_ti_advsetup_sending")));
934 GtkDialog *dialog = GTK_DIALOG (self);
935 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
936 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
937 gtk_widget_show (GTK_WIDGET (notebook));
939 /* Add the buttons: */
940 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
941 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
943 /* Connect to the dialog's response signal: */
944 /* We use connect-before
945 * so we can stop the signal emission,
946 * to stop the default signal handler from closing the dialog.
948 g_signal_connect (G_OBJECT (self), "response",
949 G_CALLBACK (on_response), self);
951 self->modified = FALSE;
953 /* When this window is shown, hibernation should not be possible,
954 * because there is no sensible way to save the state: */
955 modest_window_mgr_prevent_hibernation_while_window_is_shown (
956 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
959 ModestAccountSettingsDialog*
960 modest_account_settings_dialog_new (void)
962 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
965 /** Update the UI with the stored account details, so they can be edited.
966 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
968 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
973 /* Save the account name so we can refer to it later: */
974 if (dialog->account_name)
975 g_free (dialog->account_name);
976 dialog->account_name = g_strdup (account_name);
979 /* Get the account data for this account name: */
980 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
983 g_printerr ("modest: failed to get account data for %s\n", account_name);
987 /* Save the account title so we can refer to it if the user changes it: */
988 if (dialog->original_account_title)
989 g_free (dialog->original_account_title);
990 dialog->original_account_title = g_strdup (account_data->display_name);
993 if (!(account_data->store_account)) {
994 g_printerr ("modest: account has no stores: %s\n", account_name);
998 /* Show the account data in the widgets: */
1000 /* Note that we never show the non-display name in the UI.
1001 * (Though the display name defaults to the non-display name at the start.) */
1002 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1003 account_data->display_name ? account_data->display_name : "");
1005 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1006 account_data->fullname ? account_data->fullname : "");
1007 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1008 account_data->email ? account_data->email : "");
1010 ModestServerAccountData *incoming_account = account_data->store_account;
1012 if (incoming_account)
1013 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1014 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1015 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1017 /* Default to something, though no default is specified in the UI spec: */
1018 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1020 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1023 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1024 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1025 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1028 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1029 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1030 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1032 /* Only show the leave-on-server checkbox for POP,
1033 * as per the UI spec: */
1034 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1035 gtk_widget_hide (dialog->caption_leave_messages);
1037 gtk_widget_show (dialog->caption_leave_messages);
1040 if (incoming_account) {
1041 /* Remember this for later: */
1042 dialog->incoming_protocol = incoming_account->proto;
1044 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1045 incoming_account->username ? incoming_account->username : "");
1046 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1047 incoming_account->password ? incoming_account->password : "");
1049 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1050 incoming_account->hostname ? incoming_account->hostname : "");
1052 /* The UI spec says:
1053 * If secure authentication is unchecked, allow sending username and password also as plain text.
1054 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1055 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1057 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1058 dialog->account_manager, incoming_account->account_name);
1059 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1060 secure_auth != MODEST_PROTOCOL_AUTH_PASSWORD);
1061 /* Note that MODEST_PROTOCOL_AUTH_PLAIN should probably never be used. */
1063 update_incoming_server_title (dialog, incoming_account->proto);
1064 update_incoming_server_security_choices (dialog, incoming_account->proto);
1066 const ModestConnectionProtocol security = modest_server_account_get_security (
1067 dialog->account_manager, incoming_account->account_name);
1068 modest_serversecurity_combo_box_set_active_serversecurity (
1069 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1071 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1072 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1074 if (port_num == 0) {
1075 /* Show the appropriate port number: */
1076 on_combo_incoming_security_changed (
1077 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1079 /* Keep the user-entered port-number,
1080 * or the already-appropriate automatic port number: */
1081 hildon_number_editor_set_value (
1082 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1086 ModestServerAccountData *outgoing_account = account_data->transport_account;
1087 if (outgoing_account) {
1088 /* Remember this for later: */
1089 dialog->outgoing_protocol = outgoing_account->proto;
1091 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1092 outgoing_account->hostname ? outgoing_account->hostname : "");
1094 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1095 outgoing_account->username ? outgoing_account->username : "");
1096 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1097 outgoing_account->password ? outgoing_account->password : "");
1099 /* Get the secure-auth setting: */
1100 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1101 dialog->account_manager, outgoing_account->account_name);
1102 modest_secureauth_combo_box_set_active_secureauth (
1103 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1104 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1106 modest_serversecurity_combo_box_fill (
1107 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1109 /* Get the security setting: */
1110 const ModestConnectionProtocol security = modest_server_account_get_security (
1111 dialog->account_manager, outgoing_account->account_name);
1112 modest_serversecurity_combo_box_set_active_serversecurity (
1113 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1115 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1116 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1117 if (port_num == 0) {
1118 /* Show the appropriate port number: */
1119 on_combo_outgoing_security_changed (
1120 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1123 /* Keep the user-entered port-number,
1124 * or the already-appropriate automatic port number: */
1125 hildon_number_editor_set_value (
1126 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1129 const gboolean has_specific =
1130 modest_account_mgr_get_has_connection_specific_smtp (
1131 dialog->account_manager,
1133 gtk_toggle_button_set_active (
1134 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1138 /* account_data->is_enabled, */
1139 /*account_data->is_default, */
1141 /* account_data->store_account->proto */
1143 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1145 /* Unset the modified flag so we can detect changes later: */
1146 dialog->modified = FALSE;
1149 static GList* get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto,
1150 const gchar* hostname, gint port, GtkWindow *parent_window);
1153 save_configuration (ModestAccountSettingsDialog *dialog)
1155 g_assert (dialog->account_name);
1157 const gchar* account_name = dialog->account_name;
1159 /* Set the account data from the widgets: */
1160 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1161 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1162 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1166 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1167 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1168 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1173 if (dialog->signature_dialog) {
1174 gboolean use_signature = FALSE;
1175 gchar *signature = modest_signature_editor_dialog_get_settings (
1176 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1179 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1180 signature, use_signature);
1184 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1185 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1186 modest_account_mgr_set_string (dialog->account_manager, account_name,
1187 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1190 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1191 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1192 modest_account_mgr_set_int (dialog->account_manager, account_name,
1193 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1195 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1196 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1197 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1202 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1203 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1204 g_assert (incoming_account_name);
1206 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1207 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1208 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1212 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1213 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1215 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1216 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1219 gint port_num = hildon_number_editor_get_value (
1220 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1221 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1222 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1224 /* The UI spec says:
1225 * If secure authentication is unchecked, allow sending username and password also as plain text.
1226 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1228 ModestAuthProtocol protocol_authentication_incoming =
1229 MODEST_PROTOCOL_AUTH_PASSWORD;
1230 if (gtk_toggle_button_get_active (
1231 GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))) {
1232 GList *list_auth_methods =
1233 get_supported_secure_authentication_methods (dialog->incoming_protocol,
1234 hostname, port_num, GTK_WINDOW (dialog));
1235 if (list_auth_methods) {
1236 /* Use the first supported method.
1237 * TODO: Should we prioritize them, to prefer a particular one? */
1238 protocol_authentication_incoming =
1239 (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
1240 g_list_free (list_auth_methods);
1243 g_warning ("%s: get_supported_secure_authentication_methods() returned NULL.\n", __FUNCTION__);
1247 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1250 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1251 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1252 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1256 g_free (incoming_account_name);
1259 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1260 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1261 g_assert (outgoing_account_name);
1263 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1264 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1265 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1269 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1270 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1273 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1274 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1277 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1278 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1279 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1281 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1282 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1283 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1286 port_num = hildon_number_editor_get_value (
1287 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1288 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1289 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1291 g_free (outgoing_account_name);
1294 /* Set the changed account title last, to simplify the previous code: */
1295 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1296 if ((!account_title) || (strlen(account_title) == 0))
1297 return FALSE; /* Should be prevented already anyway. */
1299 if (strcmp(account_title, account_name) != 0) {
1300 /* Change the title: */
1301 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1302 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1307 /* Save connection-specific SMTP server accounts: */
1308 if (dialog->specific_window) {
1309 return modest_connection_specific_smtp_window_save_server_accounts (
1310 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1316 static gboolean entry_is_empty (GtkWidget *entry)
1321 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1322 if ((!text) || (strlen(text) == 0))
1329 enable_buttons (ModestAccountSettingsDialog *self)
1331 gboolean enable_ok = TRUE;
1333 /* The account details title is mandatory: */
1334 if (entry_is_empty(self->entry_account_title))
1337 /* The user details username is mandatory: */
1338 if (entry_is_empty(self->entry_user_username))
1341 /* The user details email address is mandatory: */
1342 if (enable_ok && entry_is_empty (self->entry_user_email))
1345 /* The custom incoming server is mandatory: */
1346 if (entry_is_empty(self->entry_incomingserver))
1349 /* Enable the buttons,
1350 * identifying them via their associated response codes:
1352 GtkDialog *dialog_base = GTK_DIALOG (self);
1353 gtk_dialog_set_response_sensitive (dialog_base,
1359 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1361 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1362 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1365 object_class->get_property = modest_account_settings_dialog_get_property;
1366 object_class->set_property = modest_account_settings_dialog_set_property;
1367 object_class->dispose = modest_account_settings_dialog_dispose;
1368 object_class->finalize = modest_account_settings_dialog_finalize;
1372 show_error (GtkWindow *parent_window, const gchar* text)
1374 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1376 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1383 gtk_dialog_run (dialog);
1384 gtk_widget_destroy (GTK_WIDGET (dialog));
1388 show_ok (GtkWindow *parent_window, const gchar* text)
1390 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1392 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1399 gtk_dialog_run (dialog);
1400 gtk_widget_destroy (GTK_WIDGET (dialog));
1403 /* TODO: Enable this when tinymail has the API: */
1409 } ModestGetSupportedAuthInfo;
1411 static void on_camel_account_get_supported_secure_authentication_status (
1412 GObject *self, TnyStatus *status, gpointer user_data)
1414 printf ("DEBUG: %s.\n", __FUNCTION__);
1418 on_camel_account_get_supported_secure_authentication (
1419 TnyCamelAccount *self, gboolean cancelled,
1420 GList *auth_types, GError **err,
1423 printf ("DEBUG: %s.\n", __FUNCTION__);
1425 ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
1426 g_return_if_fail (info);
1429 printf ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__);
1430 info->finished = TRUE; /* We are blocking, waiting for this. */
1434 ModestPairList* pairs = modest_protocol_info_get_protocol_auth_pair_list ();
1436 /* Get the enum value for the strings: */
1437 GList *result = NULL;
1438 GList* iter = auth_types;
1440 const gchar *auth_name = (const gchar*)iter->data;
1441 printf("DEBUG: %s: auth_name=%s\n", __FUNCTION__, auth_name);
1442 ModestPair *matching = modest_pair_list_find_by_first_as_string (pairs,
1445 g_list_append (result, GINT_TO_POINTER((ModestConnectionProtocol)matching->second));
1447 iter = g_list_next (iter);
1450 g_list_free (auth_types);
1452 modest_pair_list_free (pairs);
1454 info->result = result;
1455 info->finished = TRUE; /* We are blocking, waiting for this. */
1460 static GList* get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto,
1461 const gchar* hostname, gint port, GtkWindow *parent_window)
1465 /* TODO: Enable this when tinymail has the API: */
1467 g_return_val_if_fail (proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN, NULL);
1470 result = g_list_append (result, GINT_TO_POINTER (MODEST_PROTOCOL_AUTH_CRAMMD5));
1473 /* Create a TnyCamelAccount so we can use
1474 * tny_camel_account_get_supported_secure_authentication(): */
1475 TnyAccount * tny_account = NULL;
1477 case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
1478 case MODEST_PROTOCOL_TRANSPORT_SMTP:
1479 tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ()); break;
1480 case MODEST_PROTOCOL_STORE_POP:
1481 tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ()); break;
1482 case MODEST_PROTOCOL_STORE_IMAP:
1483 tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ()); break;
1484 case MODEST_PROTOCOL_STORE_MAILDIR:
1485 case MODEST_PROTOCOL_STORE_MBOX:
1486 tny_account = TNY_ACCOUNT(tny_camel_store_account_new()); break;
1492 g_printerr ("%s could not create tny account.", __FUNCTION__);
1496 /* Set proto, so that the prepare_func() vfunc will work when we call
1498 /* TODO: Why isn't this done in account_new()? */
1499 tny_account_set_proto (tny_account,
1500 modest_protocol_info_get_transport_store_protocol_name(proto));
1502 /* Set the session for the account, so we can use it: */
1503 ModestTnyAccountStore *account_store = modest_runtime_get_account_store ();
1504 TnySessionCamel *session =
1505 modest_tny_account_store_get_session (TNY_ACCOUNT_STORE (account_store));
1506 g_return_val_if_fail (session, NULL);
1507 tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
1509 tny_account_set_hostname (tny_account, hostname);
1512 tny_account_set_port (tny_account, port);
1515 /* Ask camel to ask the server, asynchronously: */
1516 ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo);
1517 info->finished = FALSE;
1518 info->result = NULL;
1520 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window,
1521 _("Asking the server for supported secure authentication mechanisms.")));
1522 gtk_dialog_run (dialog);
1524 printf ("DEBUG: %s: STARTING.\n", __FUNCTION__);
1525 tny_camel_account_get_supported_secure_authentication (
1526 TNY_CAMEL_ACCOUNT (tny_account),
1527 on_camel_account_get_supported_secure_authentication,
1528 on_camel_account_get_supported_secure_authentication_status,
1531 printf ("DEBUG: %s: AFTER STARTING.\n", __FUNCTION__);
1533 /* Block until the callback has been called,
1534 * driving the main context, so that the (idle handler) callback can be
1535 * called, and so that our dialog is clickable: */
1536 while (!(info->finished)) {
1537 printf ("DEBUG: %s: finished is FALSE.\n", __FUNCTION__);
1538 if (g_main_context_pending (NULL)) {
1539 printf ("DEBUG: iterating\n");
1540 g_main_context_iteration (NULL, FALSE);
1541 printf ("DEBUG: after iterating\n");
1545 printf ("DEBUG: %s: FINISHED.\n", __FUNCTION__);
1547 gtk_widget_destroy (GTK_WIDGET (dialog));
1549 GList *result = info->result;
1550 g_slice_free (ModestGetSupportedAuthInfo, info);