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 caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
327 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
328 gtk_widget_show (self->checkbox_leave_messages);
329 connect_for_modified (self, self->checkbox_leave_messages);
330 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
331 gtk_widget_show (caption);
333 gtk_widget_show (GTK_WIDGET (box));
335 return GTK_WIDGET (box);
339 on_button_signature (GtkButton *button, gpointer user_data)
341 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
343 /* Create the window, if necessary: */
344 if (!(self->signature_dialog)) {
345 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
347 gboolean use_signature = FALSE;
348 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
350 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
351 modest_signature_editor_dialog_set_settings (
352 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
353 use_signature, signature, account_title);
358 /* Show the window: */
359 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
360 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
361 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
362 gtk_widget_hide (self->signature_dialog);
363 if (response != GTK_RESPONSE_OK) {
364 /* Destroy the widget now, and its data: */
365 gtk_widget_destroy (self->signature_dialog);
366 self->signature_dialog = NULL;
369 /* Mark modified, so we use the dialog's data later: */
370 self->modified = TRUE;
375 create_page_user_details (ModestAccountSettingsDialog *self)
377 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
379 /* Create a size group to be used by all captions.
380 * Note that HildonCaption does not create a default size group if we do not specify one.
381 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
382 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
384 /* The name widgets: */
385 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
386 /* Auto-capitalization is the default, so let's turn it off: */
387 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
388 /* Set max length as in the UI spec:
389 * The UI spec seems to want us to show a dialog if we hit the maximum. */
390 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
391 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
393 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
394 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
395 gtk_widget_show (self->entry_user_name);
396 connect_for_modified (self, self->entry_user_name);
397 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
398 gtk_widget_show (caption);
400 /* Prevent the use of some characters in the name,
401 * as required by our UI specification: */
402 GList *list_prevent = NULL;
403 list_prevent = g_list_append (list_prevent, "<");
404 list_prevent = g_list_append (list_prevent, ">");
405 modest_validating_entry_set_unallowed_characters (
406 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
407 g_list_free (list_prevent);
409 /* The username widgets: */
410 self->entry_user_username = 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_username), HILDON_GTK_INPUT_MODE_FULL);
413 caption = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
414 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
415 gtk_widget_show (self->entry_user_username);
416 connect_for_modified (self, self->entry_user_username);
417 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
418 gtk_widget_show (caption);
420 /* Prevent the use of some characters in the username,
421 * as required by our UI specification: */
422 modest_validating_entry_set_unallowed_characters_whitespace (
423 MODEST_VALIDATING_ENTRY (self->entry_user_username));
425 /* Set max length as in the UI spec:
426 * The UI spec seems to want us to show a dialog if we hit the maximum. */
427 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
428 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
431 /* The password widgets: */
432 self->entry_user_password = gtk_entry_new ();
433 /* Auto-capitalization is the default, so let's turn it off: */
434 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
435 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
436 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
437 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
438 caption = create_caption_new_with_asterix (self, sizegroup,
439 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
440 gtk_widget_show (self->entry_user_password);
441 connect_for_modified (self, self->entry_user_password);
442 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
443 gtk_widget_show (caption);
445 /* The email address widgets: */
446 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
447 /* Auto-capitalization is the default, so let's turn it off: */
448 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
449 caption = create_caption_new_with_asterix (self, sizegroup,
450 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
451 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
452 gtk_widget_show (self->entry_user_email);
453 connect_for_modified (self, self->entry_user_email);
454 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
455 gtk_widget_show (caption);
457 /* Set max length as in the UI spec:
458 * The UI spec seems to want us to show a dialog if we hit the maximum. */
459 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
460 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
463 /* Signature button: */
464 if (!self->button_signature)
465 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
466 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
467 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
468 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
469 gtk_widget_show (self->button_signature);
470 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
471 gtk_widget_show (caption);
473 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
474 G_CALLBACK (on_button_signature), self);
476 gtk_widget_show (GTK_WIDGET (box));
478 return GTK_WIDGET (box);
481 /** Change the caption title for the incoming server,
482 * as specified in the UI spec:
484 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
487 (protocol == MODEST_PROTOCOL_STORE_POP ?
488 _("mail_fi_emailtype_pop3") :
489 _("mail_fi_emailtype_imap") );
492 /* Note that this produces a compiler warning,
493 * because the compiler does not know that the translated string will have a %s in it.
494 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
495 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
496 g_object_set (G_OBJECT (self->caption_incoming), "label", incomingserver_title, NULL);
497 g_free(incomingserver_title);
500 /** Change the caption title for the incoming server,
501 * as specified in the UI spec:
503 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
505 /* Fill the combo with appropriately titled choices for POP or IMAP. */
506 /* The choices are the same, but the titles are different, as in the UI spec. */
507 modest_serversecurity_combo_box_fill (
508 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
511 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
513 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
515 /* Create a size group to be used by all captions.
516 * Note that HildonCaption does not create a default size group if we do not specify one.
517 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
518 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
520 /* The incoming server widgets: */
521 if(!self->entry_incomingserver)
522 self->entry_incomingserver = gtk_entry_new ();
523 /* Auto-capitalization is the default, so let's turn it off: */
524 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
526 if (self->caption_incoming)
527 gtk_widget_destroy (self->caption_incoming);
529 /* The caption title will be updated in update_incoming_server_title().
530 * so this default text will never be seen: */
531 /* (Note: Changing the title seems pointless. murrayc) */
532 self->caption_incoming = create_caption_new_with_asterix (self, sizegroup,
533 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
534 gtk_widget_show (self->entry_incomingserver);
535 connect_for_modified (self, self->entry_incomingserver);
536 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
537 gtk_widget_show (self->caption_incoming);
539 /* The secure connection widgets: */
540 /* This will be filled by update_incoming_server_security_choices(). */
541 if (!self->combo_incoming_security)
542 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
543 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
544 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
545 gtk_widget_show (self->combo_incoming_security);
546 connect_for_modified (self, self->combo_incoming_security);
547 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
548 gtk_widget_show (caption);
550 /* Show a default port number when the security method changes, as per the UI spec: */
551 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
554 /* The port widgets: */
555 /* TODO: There are various rules about this in the UI spec. */
556 if (!self->entry_incoming_port)
557 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
558 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
559 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
560 gtk_widget_show (self->entry_incoming_port);
561 connect_for_modified (self, self->entry_incoming_port);
562 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
563 gtk_widget_show (caption);
565 /* The secure authentication widgets: */
566 if(!self->checkbox_incoming_auth)
567 self->checkbox_incoming_auth = gtk_check_button_new ();
568 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
569 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
570 gtk_widget_show (self->checkbox_incoming_auth);
571 connect_for_modified (self, self->checkbox_incoming_auth);
572 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
573 gtk_widget_show (caption);
575 gtk_widget_show (GTK_WIDGET (box));
577 return GTK_WIDGET (box);
581 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
583 GtkWidget *widget = GTK_WIDGET (user_data);
585 /* Enable the widget only if the toggle button is active: */
586 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
587 gtk_widget_set_sensitive (widget, enable);
590 /* Make the sensitivity of a widget depend on a toggle button.
593 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
595 g_signal_connect (G_OBJECT (button), "toggled",
596 G_CALLBACK (on_toggle_button_changed), widget);
598 /* Set the starting sensitivity: */
599 on_toggle_button_changed (button, widget);
603 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
605 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
607 /* Create the window if necessary: */
608 if (!(self->specific_window)) {
609 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
610 modest_connection_specific_smtp_window_fill_with_connections (
611 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
615 /* Show the window: */
616 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
617 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
618 gtk_widget_show (self->specific_window);
622 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
624 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
626 ModestAuthProtocol protocol_security =
627 modest_secureauth_combo_box_get_active_secureauth (
628 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
629 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
631 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
632 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
636 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
638 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
640 const gint port_number =
641 modest_serversecurity_combo_box_get_active_serversecurity_port (
642 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
644 if(port_number != 0) {
645 hildon_number_editor_set_value (
646 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
651 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
653 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
655 const gint port_number =
656 modest_serversecurity_combo_box_get_active_serversecurity_port (
657 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
659 if(port_number != 0) {
660 hildon_number_editor_set_value (
661 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
666 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
668 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
670 /* Create a size group to be used by all captions.
671 * Note that HildonCaption does not create a default size group if we do not specify one.
672 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
673 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
675 /* The outgoing server widgets: */
676 if (!self->entry_outgoingserver)
677 self->entry_outgoingserver = gtk_entry_new ();
678 /* Auto-capitalization is the default, so let's turn it off: */
679 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
680 GtkWidget *caption = create_caption_new_with_asterix (self, sizegroup,
681 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
682 gtk_widget_show (self->entry_outgoingserver);
683 connect_for_modified (self, self->entry_outgoingserver);
684 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
685 gtk_widget_show (caption);
687 /* The secure authentication widgets: */
688 if (!self->combo_outgoing_auth)
689 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
690 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
691 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
692 gtk_widget_show (self->combo_outgoing_auth);
693 connect_for_modified (self, self->combo_outgoing_auth);
694 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
695 gtk_widget_show (caption);
697 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
698 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
700 /* The username widgets: */
701 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
702 /* Auto-capitalization is the default, so let's turn it off: */
703 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
704 self->caption_outgoing_username = create_caption_new_with_asterix (self, sizegroup, _("mail_fi_username"),
705 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
706 gtk_widget_show (self->entry_outgoing_username);
707 connect_for_modified (self, self->entry_outgoing_username);
708 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
709 gtk_widget_show (self->caption_outgoing_username);
711 /* Prevent the use of some characters in the username,
712 * as required by our UI specification: */
713 modest_validating_entry_set_unallowed_characters_whitespace (
714 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
716 /* Set max length as in the UI spec:
717 * The UI spec seems to want us to show a dialog if we hit the maximum. */
718 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
719 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
722 /* The password widgets: */
723 self->entry_outgoing_password = gtk_entry_new ();
724 /* Auto-capitalization is the default, so let's turn it off: */
725 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
726 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
727 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
728 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
729 self->caption_outgoing_password = create_caption_new_with_asterix (self, sizegroup,
730 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
731 gtk_widget_show (self->entry_outgoing_password);
732 connect_for_modified (self, self->entry_outgoing_password);
733 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
734 gtk_widget_show (self->caption_outgoing_password);
736 /* The secure connection widgets: */
737 /* This will be filled and set with modest_serversecurity_combo_box_fill()
738 * and modest_serversecurity_combo_box_set_active_serversecurity().
740 if (!self->combo_outgoing_security)
741 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
742 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
743 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
744 gtk_widget_show (self->combo_outgoing_security);
745 connect_for_modified (self, self->combo_outgoing_security);
746 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
747 gtk_widget_show (caption);
749 /* Show a default port number when the security method changes, as per the UI spec: */
750 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
752 /* The port widgets: */
753 if (!self->entry_outgoing_port)
754 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
755 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
756 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
757 gtk_widget_show (self->entry_outgoing_port);
758 connect_for_modified (self, self->entry_outgoing_port);
759 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
760 gtk_widget_show (caption);
762 GtkWidget *separator = gtk_hseparator_new ();
763 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
764 gtk_widget_show (separator);
766 /* connection-specific checkbox: */
767 if (!self->checkbox_outgoing_smtp_specific) {
768 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
769 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
772 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
773 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
774 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
775 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
776 gtk_widget_show (caption);
777 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
779 /* Connection-specific SMTP-Severs Edit button: */
780 if (!self->button_outgoing_smtp_servers)
781 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
782 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
783 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
784 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
785 gtk_widget_show (self->button_outgoing_smtp_servers);
786 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
787 gtk_widget_show (caption);
789 /* Only enable the button when the checkbox is checked: */
790 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
791 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
793 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
794 G_CALLBACK (on_button_outgoing_smtp_servers), self);
797 gtk_widget_show (GTK_WIDGET (box));
799 return GTK_WIDGET (box);
803 check_data (ModestAccountSettingsDialog *self)
805 /* Check that the title is not already in use: */
806 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
807 if ((!account_title) || (strlen(account_title) == 0))
808 return FALSE; /* Should be prevented already anyway. */
810 if (strcmp(account_title, self->original_account_title) != 0) {
811 /* Check the changed title: */
812 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
816 /* Warn the user via a dialog: */
817 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
823 /* Check that the email address is valud: */
824 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
825 if ((!email_address) || (strlen(email_address) == 0))
828 if (!modest_text_utils_validate_email_address (email_address)) {
829 /* Warn the user via a dialog: */
830 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
832 /* Return focus to the email address entry: */
833 gtk_widget_grab_focus (self->entry_user_email);
838 /* TODO: The UI Spec wants us to check that the servernames are valid,
839 * but does not specify how.
847 on_response (GtkDialog *wizard_dialog,
851 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
852 enable_buttons (self);
854 gboolean prevent_response = FALSE;
856 /* Warn about unsaved changes: */
857 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
858 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
859 _("imum_nc_wizard_confirm_lose_changes")));
860 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
862 const gint dialog_response = gtk_dialog_run (dialog);
863 gtk_widget_destroy (GTK_WIDGET (dialog));
865 if (dialog_response != GTK_RESPONSE_OK)
866 prevent_response = TRUE;
868 /* Check for invalid input: */
869 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
870 prevent_response = TRUE;
873 if (prevent_response) {
874 /* This is a nasty hack. murrayc. */
875 /* Don't let the dialog close */
876 g_signal_stop_emission_by_name (wizard_dialog, "response");
880 if (response_id == GTK_RESPONSE_OK) {
881 /* Try to save the changes: */
882 const gboolean saved = save_configuration (self);
884 /* Do not show the account-saved dialog if we are just saving this
885 * temporarily, because from the user's point of view it will not
886 * really be saved (saved + enabled) until later.
888 const gboolean enabled =
889 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
891 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
894 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
899 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
901 /* Create the notebook to be used by the GtkDialog base class:
902 * Each page of the notebook will be a page of the wizard: */
903 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
906 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
908 /* Get the account manager object,
909 * so we can check for existing accounts,
910 * and create new accounts: */
911 self->account_manager = modest_runtime_get_account_mgr ();
912 g_assert (self->account_manager);
913 g_object_ref (self->account_manager);
915 /* Create the common pages,
917 self->page_account_details = create_page_account_details (self);
918 self->page_user_details = create_page_user_details (self);
919 self->page_incoming = create_page_incoming (self);
920 self->page_outgoing = create_page_outgoing (self);
922 /* Add the notebook pages: */
923 gtk_notebook_append_page (notebook, self->page_account_details,
924 gtk_label_new (_("mcen_ti_account_settings_account")));
925 gtk_notebook_append_page (notebook, self->page_user_details,
926 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
927 gtk_notebook_append_page (notebook, self->page_incoming,
928 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
929 gtk_notebook_append_page (notebook, self->page_outgoing,
930 gtk_label_new (_("mcen_ti_advsetup_sending")));
932 GtkDialog *dialog = GTK_DIALOG (self);
933 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
934 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
935 gtk_widget_show (GTK_WIDGET (notebook));
937 /* Add the buttons: */
938 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
939 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
941 /* Connect to the dialog's response signal: */
942 /* We use connect-before
943 * so we can stop the signal emission,
944 * to stop the default signal handler from closing the dialog.
946 g_signal_connect (G_OBJECT (self), "response",
947 G_CALLBACK (on_response), self);
949 self->modified = FALSE;
951 /* When this window is shown, hibernation should not be possible,
952 * because there is no sensible way to save the state: */
953 modest_window_mgr_prevent_hibernation_while_window_is_shown (
954 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
957 ModestAccountSettingsDialog*
958 modest_account_settings_dialog_new (void)
960 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
963 /** Update the UI with the stored account details, so they can be edited.
964 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
966 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
971 /* Save the account name so we can refer to it later: */
972 if (dialog->account_name)
973 g_free (dialog->account_name);
974 dialog->account_name = g_strdup (account_name);
977 /* Get the account data for this account name: */
978 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
981 g_printerr ("modest: failed to get account data for %s\n", account_name);
985 /* Save the account title so we can refer to it if the user changes it: */
986 if (dialog->original_account_title)
987 g_free (dialog->original_account_title);
988 dialog->original_account_title = g_strdup (account_data->display_name);
991 if (!(account_data->store_account)) {
992 g_printerr ("modest: account has no stores: %s\n", account_name);
996 /* Show the account data in the widgets: */
998 /* Note that we never show the non-display name in the UI.
999 * (Though the display name defaults to the non-display name at the start.) */
1000 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1001 account_data->display_name ? account_data->display_name : "");
1003 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1004 account_data->fullname ? account_data->fullname : "");
1005 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1006 account_data->email ? account_data->email : "");
1008 ModestServerAccountData *incoming_account = account_data->store_account;
1010 if (incoming_account)
1011 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1012 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1013 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1015 /* Default to something, though no default is specified in the UI spec: */
1016 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1018 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1021 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1022 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1023 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1026 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1027 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1028 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1030 /* Only show the leave-on-server checkbox for POP,
1031 * as per the UI spec: */
1032 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1033 gtk_widget_hide (dialog->checkbox_leave_messages);
1035 gtk_widget_show (dialog->checkbox_leave_messages);
1038 if (incoming_account) {
1039 /* Remember this for later: */
1040 dialog->incoming_protocol = incoming_account->proto;
1042 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1043 incoming_account->username ? incoming_account->username : "");
1044 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1045 incoming_account->password ? incoming_account->password : "");
1047 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1048 incoming_account->hostname ? incoming_account->hostname : "");
1050 /* The UI spec says:
1051 * If secure authentication is unchecked, allow sending username and password also as plain text.
1052 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1053 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1055 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1056 dialog->account_manager, incoming_account->account_name);
1057 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1058 secure_auth != MODEST_PROTOCOL_AUTH_PASSWORD);
1059 /* Note that MODEST_PROTOCOL_AUTH_PLAIN should probably never be used. */
1061 update_incoming_server_title (dialog, incoming_account->proto);
1062 update_incoming_server_security_choices (dialog, incoming_account->proto);
1064 const ModestConnectionProtocol security = modest_server_account_get_security (
1065 dialog->account_manager, incoming_account->account_name);
1066 modest_serversecurity_combo_box_set_active_serversecurity (
1067 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1069 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1070 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1071 hildon_number_editor_set_value (
1072 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1076 ModestServerAccountData *outgoing_account = account_data->transport_account;
1077 if (outgoing_account) {
1078 /* Remember this for later: */
1079 dialog->outgoing_protocol = outgoing_account->proto;
1081 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1082 outgoing_account->hostname ? outgoing_account->hostname : "");
1084 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1085 outgoing_account->username ? outgoing_account->username : "");
1086 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1087 outgoing_account->password ? outgoing_account->password : "");
1089 /* Get the secure-auth setting: */
1090 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1091 dialog->account_manager, outgoing_account->account_name);
1092 modest_secureauth_combo_box_set_active_secureauth (
1093 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1094 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1096 modest_serversecurity_combo_box_fill (
1097 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1099 /* Get the security setting: */
1100 const ModestConnectionProtocol security = modest_server_account_get_security (
1101 dialog->account_manager, outgoing_account->account_name);
1102 modest_serversecurity_combo_box_set_active_serversecurity (
1103 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1105 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1106 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1107 hildon_number_editor_set_value (
1108 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1111 /* account_data->is_enabled, */
1112 /*account_data->is_default, */
1114 /* account_data->store_account->proto */
1116 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1118 /* Unset the modified flag so we can detect changes later: */
1119 dialog->modified = FALSE;
1122 static GList* get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto,
1123 const gchar* hostname, gint port, GtkWindow *parent_window);
1126 save_configuration (ModestAccountSettingsDialog *dialog)
1128 g_assert (dialog->account_name);
1130 const gchar* account_name = dialog->account_name;
1132 /* Set the account data from the widgets: */
1133 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1134 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1135 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1139 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1140 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1141 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1146 if (dialog->signature_dialog) {
1147 gboolean use_signature = FALSE;
1148 gchar *signature = modest_signature_editor_dialog_get_settings (
1149 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1152 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1153 signature, use_signature);
1157 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1158 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1159 modest_account_mgr_set_string (dialog->account_manager, account_name,
1160 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1163 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1164 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1165 modest_account_mgr_set_int (dialog->account_manager, account_name,
1166 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1168 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1169 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1170 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1175 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1176 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1177 g_assert (incoming_account_name);
1179 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1180 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1181 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1185 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1186 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1188 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1189 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1192 gint port_num = hildon_number_editor_get_value (
1193 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1194 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1195 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1197 /* The UI spec says:
1198 * If secure authentication is unchecked, allow sending username and password also as plain text.
1199 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1201 ModestAuthProtocol protocol_authentication_incoming =
1202 MODEST_PROTOCOL_AUTH_PASSWORD;
1203 if (gtk_toggle_button_get_active (
1204 GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))) {
1205 GList *list_auth_methods =
1206 get_supported_secure_authentication_methods (dialog->incoming_protocol,
1207 hostname, port_num, GTK_WINDOW (dialog));
1208 if (list_auth_methods) {
1209 /* Use the first supported method.
1210 * TODO: Should we prioritize them, to prefer a particular one? */
1211 protocol_authentication_incoming =
1212 (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
1213 g_list_free (list_auth_methods);
1216 g_warning ("%s: get_supported_secure_authentication_methods() returned NULL.\n", __FUNCTION__);
1220 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1223 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1224 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1225 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1229 g_free (incoming_account_name);
1232 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1233 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1234 g_assert (outgoing_account_name);
1236 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1237 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1238 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1242 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1243 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1246 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1247 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1250 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1251 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1252 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1254 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1255 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1256 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1259 port_num = hildon_number_editor_get_value (
1260 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1261 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1262 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1264 g_free (outgoing_account_name);
1267 /* Set the changed account title last, to simplify the previous code: */
1268 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1269 if ((!account_title) || (strlen(account_title) == 0))
1270 return FALSE; /* Should be prevented already anyway. */
1272 if (strcmp(account_title, account_name) != 0) {
1273 /* Change the title: */
1274 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1275 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1280 /* Save connection-specific SMTP server accounts: */
1281 if (dialog->specific_window)
1282 return modest_connection_specific_smtp_window_save_server_accounts (
1283 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1288 static gboolean entry_is_empty (GtkWidget *entry)
1293 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1294 if ((!text) || (strlen(text) == 0))
1301 enable_buttons (ModestAccountSettingsDialog *self)
1303 gboolean enable_ok = TRUE;
1305 /* The account details title is mandatory: */
1306 if (entry_is_empty(self->entry_account_title))
1309 /* The user details username is mandatory: */
1310 if (entry_is_empty(self->entry_user_username))
1313 /* The user details email address is mandatory: */
1314 if (enable_ok && entry_is_empty (self->entry_user_email))
1317 /* The custom incoming server is mandatory: */
1318 if (entry_is_empty(self->entry_incomingserver))
1321 /* Enable the buttons,
1322 * identifying them via their associated response codes:
1324 GtkDialog *dialog_base = GTK_DIALOG (self);
1325 gtk_dialog_set_response_sensitive (dialog_base,
1331 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1333 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1334 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1337 object_class->get_property = modest_account_settings_dialog_get_property;
1338 object_class->set_property = modest_account_settings_dialog_set_property;
1339 object_class->dispose = modest_account_settings_dialog_dispose;
1340 object_class->finalize = modest_account_settings_dialog_finalize;
1344 show_error (GtkWindow *parent_window, const gchar* text)
1346 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1348 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1355 gtk_dialog_run (dialog);
1356 gtk_widget_destroy (GTK_WIDGET (dialog));
1360 show_ok (GtkWindow *parent_window, const gchar* text)
1362 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1364 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1371 gtk_dialog_run (dialog);
1372 gtk_widget_destroy (GTK_WIDGET (dialog));
1375 /* TODO: Enable this when tinymail has the API: */
1381 } ModestGetSupportedAuthInfo;
1383 static void on_camel_account_get_supported_secure_authentication_status (
1384 GObject *self, TnyStatus *status, gpointer user_data)
1386 printf ("DEBUG: %s.\n", __FUNCTION__);
1390 on_camel_account_get_supported_secure_authentication (
1391 TnyCamelAccount *self, gboolean cancelled,
1392 GList *auth_types, GError **err,
1395 printf ("DEBUG: %s.\n", __FUNCTION__);
1397 ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
1398 g_return_if_fail (info);
1401 printf ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__);
1402 info->finished = TRUE; /* We are blocking, waiting for this. */
1406 ModestPairList* pairs = modest_protocol_info_get_protocol_auth_pair_list ();
1408 /* Get the enum value for the strings: */
1409 GList *result = NULL;
1410 GList* iter = auth_types;
1412 const gchar *auth_name = (const gchar*)iter->data;
1413 printf("DEBUG: %s: auth_name=%s\n", __FUNCTION__, auth_name);
1414 ModestPair *matching = modest_pair_list_find_by_first_as_string (pairs,
1417 g_list_append (result, GINT_TO_POINTER((ModestConnectionProtocol)matching->second));
1419 iter = g_list_next (iter);
1422 g_list_free (auth_types);
1424 modest_pair_list_free (pairs);
1426 info->result = result;
1427 info->finished = TRUE; /* We are blocking, waiting for this. */
1432 static GList* get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto,
1433 const gchar* hostname, gint port, GtkWindow *parent_window)
1437 /* TODO: Enable this when tinymail has the API: */
1439 g_return_val_if_fail (proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN, NULL);
1442 result = g_list_append (result, GINT_TO_POINTER (MODEST_PROTOCOL_AUTH_CRAMMD5));
1445 /* Create a TnyCamelAccount so we can use
1446 * tny_camel_account_get_supported_secure_authentication(): */
1447 TnyAccount * tny_account = NULL;
1449 case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
1450 case MODEST_PROTOCOL_TRANSPORT_SMTP:
1451 tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ()); break;
1452 case MODEST_PROTOCOL_STORE_POP:
1453 tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ()); break;
1454 case MODEST_PROTOCOL_STORE_IMAP:
1455 tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ()); break;
1456 case MODEST_PROTOCOL_STORE_MAILDIR:
1457 case MODEST_PROTOCOL_STORE_MBOX:
1458 tny_account = TNY_ACCOUNT(tny_camel_store_account_new()); break;
1464 g_printerr ("%s could not create tny account.", __FUNCTION__);
1468 /* Set proto, so that the prepare_func() vfunc will work when we call
1470 /* TODO: Why isn't this done in account_new()? */
1471 tny_account_set_proto (tny_account,
1472 modest_protocol_info_get_transport_store_protocol_name(proto));
1474 /* Set the session for the account, so we can use it: */
1475 ModestTnyAccountStore *account_store = modest_runtime_get_account_store ();
1476 TnySessionCamel *session =
1477 modest_tny_account_store_get_session (TNY_ACCOUNT_STORE (account_store));
1478 g_return_val_if_fail (session, NULL);
1479 tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
1481 tny_account_set_hostname (tny_account, hostname);
1484 tny_account_set_port (tny_account, port);
1487 /* Ask camel to ask the server, asynchronously: */
1488 ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo);
1489 info->finished = FALSE;
1490 info->result = NULL;
1492 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window,
1493 _("Asking the server for supported secure authentication mechanisms.")));
1494 gtk_dialog_run (dialog);
1496 printf ("DEBUG: %s: STARTING.\n", __FUNCTION__);
1497 tny_camel_account_get_supported_secure_authentication (
1498 TNY_CAMEL_ACCOUNT (tny_account),
1499 on_camel_account_get_supported_secure_authentication,
1500 on_camel_account_get_supported_secure_authentication_status,
1503 printf ("DEBUG: %s: AFTER STARTING.\n", __FUNCTION__);
1505 /* Block until the callback has been called,
1506 * driving the main context, so that the (idle handler) callback can be
1507 * called, and so that our dialog is clickable: */
1508 while (!(info->finished)) {
1509 printf ("DEBUG: %s: finished is FALSE.\n", __FUNCTION__);
1510 if (g_main_context_pending (NULL)) {
1511 printf ("DEBUG: iterating\n");
1512 g_main_context_iteration (NULL, FALSE);
1513 printf ("DEBUG: after iterating\n");
1517 printf ("DEBUG: %s: FINISHED.\n", __FUNCTION__);
1519 gtk_widget_destroy (GTK_WIDGET (dialog));
1521 GList *result = info->result;
1522 g_slice_free (ModestGetSupportedAuthInfo, info);