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_asterisk(ModestAccountSettingsDialog *self,
213 HildonCaptionStatus flag)
215 GtkWidget *caption = NULL;
217 /* Note: Previously, the translated strings already contained the "*",
218 * Comment out this code if they do again.
220 /* Add a * character to indicate mandatory fields,
221 * as specified in our "Email UI Specification": */
222 if (flag == HILDON_CAPTION_MANDATORY) {
223 gchar* title = g_strdup_printf("%s*", value);
224 caption = hildon_caption_new (group, title, control, icon, flag);
228 caption = hildon_caption_new (group, value, control, icon, flag);
230 /* Connect to the appropriate changed signal for the widget,
231 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
233 if (GTK_IS_ENTRY (control)) {
234 g_signal_connect (G_OBJECT (control), "changed",
235 G_CALLBACK (on_caption_entry_changed), self);
238 else if (GTK_IS_COMBO_BOX (control)) {
239 g_signal_connect (G_OBJECT (control), "changed",
240 G_CALLBACK (on_caption_combobox_changed), self);
248 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
250 ModestAccountSettingsDialog *dialog = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
251 show_error (GTK_WINDOW (dialog), _("ckdg_ib_maximum_characters_reached"));
255 create_page_account_details (ModestAccountSettingsDialog *self)
257 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
258 GtkWidget *label = gtk_label_new(_("mcen_ia_accountdetails"));
259 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, MODEST_MARGIN_HALF);
260 gtk_widget_show (label);
262 /* Create a size group to be used by all captions.
263 * Note that HildonCaption does not create a default size group if we do not specify one.
264 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
265 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
267 /* The description widgets: */
268 self->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
269 /* Do use auto-capitalization: */
270 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_account_title),
271 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
272 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_account_title"),
273 self->entry_account_title, NULL, HILDON_CAPTION_MANDATORY);
274 gtk_widget_show (self->entry_account_title);
275 connect_for_modified (self, self->entry_account_title);
276 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
277 gtk_widget_show (caption);
279 /* Prevent the use of some characters in the account title,
280 * as required by our UI specification: */
281 GList *list_prevent = NULL;
282 list_prevent = g_list_append (list_prevent, "\\");
283 list_prevent = g_list_append (list_prevent, "/");
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, "\""); /* The UI spec mentions “, but maybe means ", maybe both. */
288 list_prevent = g_list_append (list_prevent, "“");
289 list_prevent = g_list_append (list_prevent, "<");
290 list_prevent = g_list_append (list_prevent, ">");
291 list_prevent = g_list_append (list_prevent, "|");
292 list_prevent = g_list_append (list_prevent, "^");
293 modest_validating_entry_set_unallowed_characters (
294 MODEST_VALIDATING_ENTRY (self->entry_account_title), list_prevent);
295 g_list_free (list_prevent);
297 /* Set max length as in the UI spec:
298 * The UI spec seems to want us to show a dialog if we hit the maximum. */
299 gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
300 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_account_title),
303 /* The retrieve combobox: */
304 self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
305 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
306 self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
307 gtk_widget_show (self->combo_retrieve);
308 connect_for_modified (self, self->combo_retrieve);
309 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
310 gtk_widget_show (caption);
312 /* The limit-retrieve combobox: */
313 self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
314 caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
315 self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
316 gtk_widget_show (self->combo_limit_retrieve);
317 connect_for_modified (self, self->combo_limit_retrieve);
318 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
319 gtk_widget_show (caption);
321 /* The leave-messages widgets: */
322 if(!self->checkbox_leave_messages)
323 self->checkbox_leave_messages = gtk_check_button_new ();
324 if (!self->caption_leave_messages) {
325 self->caption_leave_messages = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
326 self->checkbox_leave_messages, NULL, HILDON_CAPTION_MANDATORY);
329 gtk_widget_show (self->checkbox_leave_messages);
330 connect_for_modified (self, self->checkbox_leave_messages);
331 gtk_box_pack_start (GTK_BOX (box), self->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
332 gtk_widget_show (self->caption_leave_messages);
334 gtk_widget_show (GTK_WIDGET (box));
336 return GTK_WIDGET (box);
340 on_button_signature (GtkButton *button, gpointer user_data)
342 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
344 /* Create the window, if necessary: */
345 if (!(self->signature_dialog)) {
346 self->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
348 gboolean use_signature = FALSE;
349 gchar *signature = modest_account_mgr_get_signature(self->account_manager, self->account_name,
351 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
352 modest_signature_editor_dialog_set_settings (
353 MODEST_SIGNATURE_EDITOR_DIALOG (self->signature_dialog),
354 use_signature, signature, account_title);
359 /* Show the window: */
360 gtk_window_set_transient_for (GTK_WINDOW (self->signature_dialog), GTK_WINDOW (self));
361 gtk_window_set_modal (GTK_WINDOW (self->signature_dialog), TRUE);
362 const gint response = gtk_dialog_run (GTK_DIALOG (self->signature_dialog));
363 gtk_widget_hide (self->signature_dialog);
364 if (response != GTK_RESPONSE_OK) {
365 /* Destroy the widget now, and its data: */
366 gtk_widget_destroy (self->signature_dialog);
367 self->signature_dialog = NULL;
370 /* Mark modified, so we use the dialog's data later: */
371 self->modified = TRUE;
376 create_page_user_details (ModestAccountSettingsDialog *self)
378 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
380 /* Create a size group to be used by all captions.
381 * Note that HildonCaption does not create a default size group if we do not specify one.
382 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
383 GtkSizeGroup* sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
385 /* The name widgets: */
386 self->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
387 /* Auto-capitalization is the default, so let's turn it off: */
388 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
389 /* Set max length as in the UI spec:
390 * The UI spec seems to want us to show a dialog if we hit the maximum. */
391 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_name), 64);
392 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_name),
394 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
395 _("mcen_li_emailsetup_name"), self->entry_user_name, NULL, HILDON_CAPTION_OPTIONAL);
396 gtk_widget_show (self->entry_user_name);
397 connect_for_modified (self, self->entry_user_name);
398 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
399 gtk_widget_show (caption);
401 /* Prevent the use of some characters in the name,
402 * as required by our UI specification: */
403 GList *list_prevent = NULL;
404 list_prevent = g_list_append (list_prevent, "<");
405 list_prevent = g_list_append (list_prevent, ">");
406 modest_validating_entry_set_unallowed_characters (
407 MODEST_VALIDATING_ENTRY (self->entry_user_name), list_prevent);
408 g_list_free (list_prevent);
410 /* The username widgets: */
411 self->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
412 /* Auto-capitalization is the default, so let's turn it off: */
413 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
414 caption = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
415 self->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
416 gtk_widget_show (self->entry_user_username);
417 connect_for_modified (self, self->entry_user_username);
418 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
419 gtk_widget_show (caption);
421 /* Prevent the use of some characters in the username,
422 * as required by our UI specification: */
423 modest_validating_entry_set_unallowed_characters_whitespace (
424 MODEST_VALIDATING_ENTRY (self->entry_user_username));
426 /* Set max length as in the UI spec:
427 * The UI spec seems to want us to show a dialog if we hit the maximum. */
428 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_username), 64);
429 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_username),
432 /* The password widgets: */
433 self->entry_user_password = gtk_entry_new ();
434 /* Auto-capitalization is the default, so let's turn it off: */
435 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_password),
436 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
437 gtk_entry_set_visibility (GTK_ENTRY (self->entry_user_password), FALSE);
438 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_user_password), '*'); */
439 caption = create_caption_new_with_asterisk (self, sizegroup,
440 _("mail_fi_password"), self->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
441 gtk_widget_show (self->entry_user_password);
442 connect_for_modified (self, self->entry_user_password);
443 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
444 gtk_widget_show (caption);
446 /* The email address widgets: */
447 self->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
448 /* Auto-capitalization is the default, so let's turn it off: */
449 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
450 caption = create_caption_new_with_asterisk (self, sizegroup,
451 _("mcen_li_emailsetup_email_address"), self->entry_user_email, NULL, HILDON_CAPTION_MANDATORY);
452 gtk_entry_set_text (GTK_ENTRY (self->entry_user_email), EXAMPLE_EMAIL_ADDRESS); /* Default text. */
453 gtk_widget_show (self->entry_user_email);
454 connect_for_modified (self, self->entry_user_email);
455 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
456 gtk_widget_show (caption);
458 /* Set max length as in the UI spec:
459 * The UI spec seems to want us to show a dialog if we hit the maximum. */
460 gtk_entry_set_max_length (GTK_ENTRY (self->entry_user_email), 64);
461 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_user_email),
464 /* Signature button: */
465 if (!self->button_signature)
466 self->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
467 caption = hildon_caption_new (sizegroup, _("mcen_fi_email_signature"),
468 self->button_signature, NULL, HILDON_CAPTION_OPTIONAL);
469 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
470 gtk_widget_show (self->button_signature);
471 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
472 gtk_widget_show (caption);
474 g_signal_connect (G_OBJECT (self->button_signature), "clicked",
475 G_CALLBACK (on_button_signature), self);
477 gtk_widget_show (GTK_WIDGET (box));
479 return GTK_WIDGET (box);
482 /** Change the caption title for the incoming server,
483 * as specified in the UI spec:
485 static void update_incoming_server_title (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
488 (protocol == MODEST_PROTOCOL_STORE_POP ?
489 _("mail_fi_emailtype_pop3") :
490 _("mail_fi_emailtype_imap") );
493 /* Note that this produces a compiler warning,
494 * because the compiler does not know that the translated string will have a %s in it.
495 * I do not see a way to avoid the warning while still using these Logical IDs. murrayc. */
496 gchar* incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), type);
498 /* This is a mandatory field, so add a *. This is usually done by
499 * create_caption_new_with_asterisk() but we can't use that here. */
500 gchar *with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
501 g_free (incomingserver_title);
503 g_object_set (G_OBJECT (self->caption_incoming), "label", with_asterisk, NULL);
504 g_free(with_asterisk);
507 /** Change the caption title for the incoming server,
508 * as specified in the UI spec:
510 static void update_incoming_server_security_choices (ModestAccountSettingsDialog *self, ModestTransportStoreProtocol protocol)
512 /* Fill the combo with appropriately titled choices for POP or IMAP. */
513 /* The choices are the same, but the titles are different, as in the UI spec. */
514 modest_serversecurity_combo_box_fill (
515 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security), protocol);
518 static GtkWidget* create_page_incoming (ModestAccountSettingsDialog *self)
520 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
522 /* Create a size group to be used by all captions.
523 * Note that HildonCaption does not create a default size group if we do not specify one.
524 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
525 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
527 /* The incoming server widgets: */
528 if(!self->entry_incomingserver)
529 self->entry_incomingserver = gtk_entry_new ();
530 /* Auto-capitalization is the default, so let's turn it off: */
531 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
533 if (self->caption_incoming)
534 gtk_widget_destroy (self->caption_incoming);
536 /* The caption title will be updated in update_incoming_server_title().
537 * so this default text will never be seen: */
538 /* (Note: Changing the title seems pointless. murrayc) */
539 self->caption_incoming = create_caption_new_with_asterisk (self, sizegroup,
540 "Incoming Server", self->entry_incomingserver, NULL, HILDON_CAPTION_MANDATORY);
541 gtk_widget_show (self->entry_incomingserver);
542 connect_for_modified (self, self->entry_incomingserver);
543 gtk_box_pack_start (GTK_BOX (box), self->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
544 gtk_widget_show (self->caption_incoming);
546 /* The secure connection widgets: */
547 /* This will be filled by update_incoming_server_security_choices(). */
548 if (!self->combo_incoming_security)
549 self->combo_incoming_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
550 GtkWidget *caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
551 self->combo_incoming_security, NULL, HILDON_CAPTION_OPTIONAL);
552 gtk_widget_show (self->combo_incoming_security);
553 connect_for_modified (self, self->combo_incoming_security);
554 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
555 gtk_widget_show (caption);
557 /* Show a default port number when the security method changes, as per the UI spec: */
558 g_signal_connect (G_OBJECT (self->combo_incoming_security), "changed", (GCallback)on_combo_incoming_security_changed, self);
561 /* The port widgets: */
562 /* TODO: There are various rules about this in the UI spec. */
563 if (!self->entry_incoming_port)
564 self->entry_incoming_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
565 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
566 self->entry_incoming_port, NULL, HILDON_CAPTION_OPTIONAL);
567 gtk_widget_show (self->entry_incoming_port);
568 connect_for_modified (self, self->entry_incoming_port);
569 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
570 gtk_widget_show (caption);
572 /* The secure authentication widgets: */
573 if(!self->checkbox_incoming_auth)
574 self->checkbox_incoming_auth = gtk_check_button_new ();
575 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
576 self->checkbox_incoming_auth, NULL, HILDON_CAPTION_OPTIONAL);
577 gtk_widget_show (self->checkbox_incoming_auth);
578 connect_for_modified (self, self->checkbox_incoming_auth);
579 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
580 gtk_widget_show (caption);
582 gtk_widget_show (GTK_WIDGET (box));
584 return GTK_WIDGET (box);
588 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
590 GtkWidget *widget = GTK_WIDGET (user_data);
592 /* Enable the widget only if the toggle button is active: */
593 const gboolean enable = gtk_toggle_button_get_active (togglebutton);
594 gtk_widget_set_sensitive (widget, enable);
597 /* Make the sensitivity of a widget depend on a toggle button.
600 enable_widget_for_togglebutton (GtkWidget *widget, GtkToggleButton* button)
602 g_signal_connect (G_OBJECT (button), "toggled",
603 G_CALLBACK (on_toggle_button_changed), widget);
605 /* Set the starting sensitivity: */
606 on_toggle_button_changed (button, widget);
610 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
612 ModestAccountSettingsDialog * self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
614 /* Create the window if necessary: */
615 if (!(self->specific_window)) {
616 self->specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
617 modest_connection_specific_smtp_window_fill_with_connections (
618 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (self->specific_window), self->account_manager,
622 /* Show the window: */
623 gtk_window_set_transient_for (GTK_WINDOW (self->specific_window), GTK_WINDOW (self));
624 gtk_window_set_modal (GTK_WINDOW (self->specific_window), TRUE);
625 gtk_widget_show (self->specific_window);
629 on_combo_outgoing_auth_changed (GtkComboBox *widget, gpointer user_data)
631 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
633 ModestAuthProtocol protocol_security =
634 modest_secureauth_combo_box_get_active_secureauth (
635 MODEST_SECUREAUTH_COMBO_BOX (self->combo_outgoing_auth));
636 const gboolean secureauth_used = protocol_security != MODEST_PROTOCOL_AUTH_NONE;
638 gtk_widget_set_sensitive (self->caption_outgoing_username, secureauth_used);
639 gtk_widget_set_sensitive (self->caption_outgoing_password, secureauth_used);
643 on_combo_outgoing_security_changed (GtkComboBox *widget, gpointer user_data)
645 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
647 const gint port_number =
648 modest_serversecurity_combo_box_get_active_serversecurity_port (
649 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_outgoing_security));
651 if(port_number != 0) {
652 hildon_number_editor_set_value (
653 HILDON_NUMBER_EDITOR (self->entry_outgoing_port), port_number);
658 on_combo_incoming_security_changed (GtkComboBox *widget, gpointer user_data)
660 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (user_data);
662 const gint port_number =
663 modest_serversecurity_combo_box_get_active_serversecurity_port (
664 MODEST_SERVERSECURITY_COMBO_BOX (self->combo_incoming_security));
666 if(port_number != 0) {
667 hildon_number_editor_set_value (
668 HILDON_NUMBER_EDITOR (self->entry_incoming_port), port_number);
673 static GtkWidget* create_page_outgoing (ModestAccountSettingsDialog *self)
675 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
677 /* Create a size group to be used by all captions.
678 * Note that HildonCaption does not create a default size group if we do not specify one.
679 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
680 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
682 /* The outgoing server widgets: */
683 if (!self->entry_outgoingserver)
684 self->entry_outgoingserver = gtk_entry_new ();
685 /* Auto-capitalization is the default, so let's turn it off: */
686 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
687 GtkWidget *caption = create_caption_new_with_asterisk (self, sizegroup,
688 _("mcen_li_emailsetup_smtp"), self->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
689 gtk_widget_show (self->entry_outgoingserver);
690 connect_for_modified (self, self->entry_outgoingserver);
691 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
692 gtk_widget_show (caption);
694 /* The secure authentication widgets: */
695 if (!self->combo_outgoing_auth)
696 self->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
697 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
698 self->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
699 gtk_widget_show (self->combo_outgoing_auth);
700 connect_for_modified (self, self->combo_outgoing_auth);
701 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
702 gtk_widget_show (caption);
704 /* Dim the outgoing username and password when no secure authentication is used, as per the UI spec: */
705 g_signal_connect (G_OBJECT (self->combo_outgoing_auth), "changed", (GCallback)on_combo_outgoing_auth_changed, self);
707 /* The username widgets: */
708 self->entry_outgoing_username = GTK_WIDGET (modest_validating_entry_new ());
709 /* Auto-capitalization is the default, so let's turn it off: */
710 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_username), HILDON_GTK_INPUT_MODE_FULL);
711 self->caption_outgoing_username = create_caption_new_with_asterisk (self, sizegroup, _("mail_fi_username"),
712 self->entry_outgoing_username, NULL, HILDON_CAPTION_MANDATORY);
713 gtk_widget_show (self->entry_outgoing_username);
714 connect_for_modified (self, self->entry_outgoing_username);
715 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_username, FALSE, FALSE, MODEST_MARGIN_HALF);
716 gtk_widget_show (self->caption_outgoing_username);
718 /* Prevent the use of some characters in the username,
719 * as required by our UI specification: */
720 modest_validating_entry_set_unallowed_characters_whitespace (
721 MODEST_VALIDATING_ENTRY (self->entry_outgoing_username));
723 /* Set max length as in the UI spec:
724 * The UI spec seems to want us to show a dialog if we hit the maximum. */
725 gtk_entry_set_max_length (GTK_ENTRY (self->entry_outgoing_username), 64);
726 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (self->entry_outgoing_username),
729 /* The password widgets: */
730 self->entry_outgoing_password = gtk_entry_new ();
731 /* Auto-capitalization is the default, so let's turn it off: */
732 hildon_gtk_entry_set_input_mode (GTK_ENTRY (self->entry_outgoing_password),
733 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
734 gtk_entry_set_visibility (GTK_ENTRY (self->entry_outgoing_password), FALSE);
735 /* gtk_entry_set_invisible_char (GTK_ENTRY (self->entry_outgoing_password), '*'); */
736 self->caption_outgoing_password = create_caption_new_with_asterisk (self, sizegroup,
737 _("mail_fi_password"), self->entry_outgoing_password, NULL, HILDON_CAPTION_OPTIONAL);
738 gtk_widget_show (self->entry_outgoing_password);
739 connect_for_modified (self, self->entry_outgoing_password);
740 gtk_box_pack_start (GTK_BOX (box), self->caption_outgoing_password, FALSE, FALSE, MODEST_MARGIN_HALF);
741 gtk_widget_show (self->caption_outgoing_password);
743 /* The secure connection widgets: */
744 /* This will be filled and set with modest_serversecurity_combo_box_fill()
745 * and modest_serversecurity_combo_box_set_active_serversecurity().
747 if (!self->combo_outgoing_security)
748 self->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
749 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
750 self->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
751 gtk_widget_show (self->combo_outgoing_security);
752 connect_for_modified (self, self->combo_outgoing_security);
753 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
754 gtk_widget_show (caption);
756 /* Show a default port number when the security method changes, as per the UI spec: */
757 g_signal_connect (G_OBJECT (self->combo_outgoing_security), "changed", (GCallback)on_combo_outgoing_security_changed, self);
759 /* The port widgets: */
760 if (!self->entry_outgoing_port)
761 self->entry_outgoing_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
762 caption = hildon_caption_new (sizegroup, _("mcen_fi_emailsetup_port"),
763 self->entry_outgoing_port, NULL, HILDON_CAPTION_OPTIONAL);
764 gtk_widget_show (self->entry_outgoing_port);
765 connect_for_modified (self, self->entry_outgoing_port);
766 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
767 gtk_widget_show (caption);
769 GtkWidget *separator = gtk_hseparator_new ();
770 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
771 gtk_widget_show (separator);
773 /* connection-specific checkbox: */
774 if (!self->checkbox_outgoing_smtp_specific) {
775 self->checkbox_outgoing_smtp_specific = gtk_check_button_new ();
776 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific),
779 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_connection_smtp"),
780 self->checkbox_outgoing_smtp_specific, NULL, HILDON_CAPTION_OPTIONAL);
781 gtk_widget_show (self->checkbox_outgoing_smtp_specific);
782 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
783 gtk_widget_show (caption);
784 connect_for_modified (self, self->checkbox_outgoing_smtp_specific);
786 /* Connection-specific SMTP-Severs Edit button: */
787 if (!self->button_outgoing_smtp_servers)
788 self->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
789 caption = hildon_caption_new (sizegroup, _("mcen_fi_advsetup_optional_smtp"),
790 self->button_outgoing_smtp_servers, NULL, HILDON_CAPTION_OPTIONAL);
791 hildon_caption_set_child_expand (HILDON_CAPTION (caption), FALSE);
792 gtk_widget_show (self->button_outgoing_smtp_servers);
793 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
794 gtk_widget_show (caption);
796 /* Only enable the button when the checkbox is checked: */
797 enable_widget_for_togglebutton (self->button_outgoing_smtp_servers,
798 GTK_TOGGLE_BUTTON (self->checkbox_outgoing_smtp_specific));
800 g_signal_connect (G_OBJECT (self->button_outgoing_smtp_servers), "clicked",
801 G_CALLBACK (on_button_outgoing_smtp_servers), self);
803 gtk_widget_show (GTK_WIDGET (box));
805 return GTK_WIDGET (box);
809 check_data (ModestAccountSettingsDialog *self)
811 /* Check that the title is not already in use: */
812 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (self->entry_account_title));
813 if ((!account_title) || (strlen(account_title) == 0))
814 return FALSE; /* Should be prevented already anyway. */
816 if (strcmp(account_title, self->original_account_title) != 0) {
817 /* Check the changed title: */
818 const gboolean name_in_use = modest_account_mgr_account_with_display_name_exists (self->account_manager,
822 /* Warn the user via a dialog: */
823 show_error (GTK_WINDOW (self), _("mail_ib_account_name_already_existing"));
829 /* Check that the email address is valud: */
830 const gchar* email_address = gtk_entry_get_text (GTK_ENTRY (self->entry_user_email));
831 if ((!email_address) || (strlen(email_address) == 0))
834 if (!modest_text_utils_validate_email_address (email_address)) {
835 /* Warn the user via a dialog: */
836 show_error (GTK_WINDOW (self), _("mcen_ib_invalid_email"));
838 /* Return focus to the email address entry: */
839 gtk_widget_grab_focus (self->entry_user_email);
844 /* TODO: The UI Spec wants us to check that the servernames are valid,
845 * but does not specify how.
853 on_response (GtkDialog *wizard_dialog,
857 ModestAccountSettingsDialog *self = MODEST_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
858 enable_buttons (self);
860 gboolean prevent_response = FALSE;
862 /* Warn about unsaved changes: */
863 if (response_id == GTK_RESPONSE_CANCEL && self->modified) {
864 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
865 _("imum_nc_wizard_confirm_lose_changes")));
866 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
868 const gint dialog_response = gtk_dialog_run (dialog);
869 gtk_widget_destroy (GTK_WIDGET (dialog));
871 if (dialog_response != GTK_RESPONSE_OK)
872 prevent_response = TRUE;
874 /* Check for invalid input: */
875 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
876 prevent_response = TRUE;
879 if (prevent_response) {
880 /* This is a nasty hack. murrayc. */
881 /* Don't let the dialog close */
882 g_signal_stop_emission_by_name (wizard_dialog, "response");
886 if (response_id == GTK_RESPONSE_OK) {
887 /* Try to save the changes: */
888 const gboolean saved = save_configuration (self);
890 /* Do not show the account-saved dialog if we are just saving this
891 * temporarily, because from the user's point of view it will not
892 * really be saved (saved + enabled) until later.
894 const gboolean enabled =
895 modest_account_mgr_get_enabled (self->account_manager, self->account_name);
897 show_ok (GTK_WINDOW (self), _("mcen_ib_advsetup_settings_saved"));
900 show_error (GTK_WINDOW (self), _("mail_ib_setting_failed"));
905 modest_account_settings_dialog_init (ModestAccountSettingsDialog *self)
907 /* Create the notebook to be used by the GtkDialog base class:
908 * Each page of the notebook will be a page of the wizard: */
909 GtkNotebook *notebook = GTK_NOTEBOOK (gtk_notebook_new());
912 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_emailsetup"));
914 /* Get the account manager object,
915 * so we can check for existing accounts,
916 * and create new accounts: */
917 self->account_manager = modest_runtime_get_account_mgr ();
918 g_assert (self->account_manager);
919 g_object_ref (self->account_manager);
921 /* Create the common pages,
923 self->page_account_details = create_page_account_details (self);
924 self->page_user_details = create_page_user_details (self);
925 self->page_incoming = create_page_incoming (self);
926 self->page_outgoing = create_page_outgoing (self);
928 /* Add the notebook pages: */
929 gtk_notebook_append_page (notebook, self->page_account_details,
930 gtk_label_new (_("mcen_ti_account_settings_account")));
931 gtk_notebook_append_page (notebook, self->page_user_details,
932 gtk_label_new (_("mcen_ti_account_settings_userinfo")));
933 gtk_notebook_append_page (notebook, self->page_incoming,
934 gtk_label_new (_("mcen_ti_advsetup_retrieval")));
935 gtk_notebook_append_page (notebook, self->page_outgoing,
936 gtk_label_new (_("mcen_ti_advsetup_sending")));
938 GtkDialog *dialog = GTK_DIALOG (self);
939 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (notebook));
940 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
941 gtk_widget_show (GTK_WIDGET (notebook));
943 /* Add the buttons: */
944 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_OK, GTK_RESPONSE_OK);
945 gtk_dialog_add_button (GTK_DIALOG(self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
947 /* Connect to the dialog's response signal: */
948 /* We use connect-before
949 * so we can stop the signal emission,
950 * to stop the default signal handler from closing the dialog.
952 g_signal_connect (G_OBJECT (self), "response",
953 G_CALLBACK (on_response), self);
955 self->modified = FALSE;
957 /* When this window is shown, hibernation should not be possible,
958 * because there is no sensible way to save the state: */
959 modest_window_mgr_prevent_hibernation_while_window_is_shown (
960 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
963 ModestAccountSettingsDialog*
964 modest_account_settings_dialog_new (void)
966 return g_object_new (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG, NULL);
969 /** Update the UI with the stored account details, so they can be edited.
970 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
972 void modest_account_settings_dialog_set_account_name (ModestAccountSettingsDialog *dialog, const gchar* account_name)
977 /* Save the account name so we can refer to it later: */
978 if (dialog->account_name)
979 g_free (dialog->account_name);
980 dialog->account_name = g_strdup (account_name);
983 /* Get the account data for this account name: */
984 ModestAccountData *account_data = modest_account_mgr_get_account_data (dialog->account_manager,
987 g_printerr ("modest: failed to get account data for %s\n", account_name);
991 /* Save the account title so we can refer to it if the user changes it: */
992 if (dialog->original_account_title)
993 g_free (dialog->original_account_title);
994 dialog->original_account_title = g_strdup (account_data->display_name);
997 if (!(account_data->store_account)) {
998 g_printerr ("modest: account has no stores: %s\n", account_name);
1002 /* Show the account data in the widgets: */
1004 /* Note that we never show the non-display name in the UI.
1005 * (Though the display name defaults to the non-display name at the start.) */
1006 gtk_entry_set_text( GTK_ENTRY (dialog->entry_account_title),
1007 account_data->display_name ? account_data->display_name : "");
1009 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_name),
1010 account_data->fullname ? account_data->fullname : "");
1011 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
1012 account_data->email ? account_data->email : "");
1014 ModestServerAccountData *incoming_account = account_data->store_account;
1016 if (incoming_account)
1017 modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
1018 gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
1019 MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
1021 /* Default to something, though no default is specified in the UI spec: */
1022 retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
1024 modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
1027 const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
1028 MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
1029 modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
1032 const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
1033 MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
1034 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
1036 /* Only show the leave-on-server checkbox for POP,
1037 * as per the UI spec: */
1038 if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
1039 gtk_widget_hide (dialog->caption_leave_messages);
1041 gtk_widget_show (dialog->caption_leave_messages);
1044 if (incoming_account) {
1045 /* Remember this for later: */
1046 dialog->incoming_protocol = incoming_account->proto;
1048 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
1049 incoming_account->username ? incoming_account->username : "");
1050 gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_password),
1051 incoming_account->password ? incoming_account->password : "");
1053 gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
1054 incoming_account->hostname ? incoming_account->hostname : "");
1056 /* The UI spec says:
1057 * If secure authentication is unchecked, allow sending username and password also as plain text.
1058 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1059 * TODO: Do we need to discover which of these (SSL, TLS, CRAM-MD5) is supported?
1061 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1062 dialog->account_manager, incoming_account->account_name);
1063 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
1064 secure_auth != MODEST_PROTOCOL_AUTH_PASSWORD);
1065 /* Note that MODEST_PROTOCOL_AUTH_PLAIN should probably never be used. */
1067 update_incoming_server_title (dialog, incoming_account->proto);
1068 update_incoming_server_security_choices (dialog, incoming_account->proto);
1070 const ModestConnectionProtocol security = modest_server_account_get_security (
1071 dialog->account_manager, incoming_account->account_name);
1072 modest_serversecurity_combo_box_set_active_serversecurity (
1073 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security), security);
1075 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, incoming_account->account_name,
1076 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1078 if (port_num == 0) {
1079 /* Show the appropriate port number: */
1080 on_combo_incoming_security_changed (
1081 GTK_COMBO_BOX (dialog->combo_incoming_security), dialog);
1083 /* Keep the user-entered port-number,
1084 * or the already-appropriate automatic port number: */
1085 hildon_number_editor_set_value (
1086 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port), port_num);
1090 ModestServerAccountData *outgoing_account = account_data->transport_account;
1091 if (outgoing_account) {
1092 /* Remember this for later: */
1093 dialog->outgoing_protocol = outgoing_account->proto;
1095 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoingserver),
1096 outgoing_account->hostname ? outgoing_account->hostname : "");
1098 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_username),
1099 outgoing_account->username ? outgoing_account->username : "");
1100 gtk_entry_set_text( GTK_ENTRY (dialog->entry_outgoing_password),
1101 outgoing_account->password ? outgoing_account->password : "");
1103 /* Get the secure-auth setting: */
1104 const ModestAuthProtocol secure_auth = modest_server_account_get_secure_auth(
1105 dialog->account_manager, outgoing_account->account_name);
1106 modest_secureauth_combo_box_set_active_secureauth (
1107 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
1108 on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
1110 modest_serversecurity_combo_box_fill (
1111 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), outgoing_account->proto);
1113 /* Get the security setting: */
1114 const ModestConnectionProtocol security = modest_server_account_get_security (
1115 dialog->account_manager, outgoing_account->account_name);
1116 modest_serversecurity_combo_box_set_active_serversecurity (
1117 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security), security);
1119 const gint port_num = modest_account_mgr_get_int (dialog->account_manager, outgoing_account->account_name,
1120 MODEST_ACCOUNT_PORT, TRUE /* server account */);
1121 if (port_num == 0) {
1122 /* Show the appropriate port number: */
1123 on_combo_outgoing_security_changed (
1124 GTK_COMBO_BOX (dialog->combo_outgoing_security), dialog);
1127 /* Keep the user-entered port-number,
1128 * or the already-appropriate automatic port number: */
1129 hildon_number_editor_set_value (
1130 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port), port_num);
1133 const gboolean has_specific =
1134 modest_account_mgr_get_has_connection_specific_smtp (
1135 dialog->account_manager,
1137 gtk_toggle_button_set_active (
1138 GTK_TOGGLE_BUTTON (dialog->checkbox_outgoing_smtp_specific),
1142 /* account_data->is_enabled, */
1143 /*account_data->is_default, */
1145 /* account_data->store_account->proto */
1147 modest_account_mgr_free_account_data (dialog->account_manager, account_data);
1149 /* Unset the modified flag so we can detect changes later: */
1150 dialog->modified = FALSE;
1153 static GList* get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto,
1154 const gchar* hostname, gint port, GtkWindow *parent_window);
1157 save_configuration (ModestAccountSettingsDialog *dialog)
1159 g_assert (dialog->account_name);
1161 const gchar* account_name = dialog->account_name;
1163 /* Set the account data from the widgets: */
1164 const gchar* user_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_name));
1165 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1166 MODEST_ACCOUNT_FULLNAME, user_name, FALSE /* not server account */);
1170 const gchar* emailaddress = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_email));
1171 test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1172 MODEST_ACCOUNT_EMAIL, emailaddress, FALSE /* not server account */);
1177 if (dialog->signature_dialog) {
1178 gboolean use_signature = FALSE;
1179 gchar *signature = modest_signature_editor_dialog_get_settings (
1180 MODEST_SIGNATURE_EDITOR_DIALOG (dialog->signature_dialog),
1183 modest_account_mgr_set_signature(dialog->account_manager, account_name,
1184 signature, use_signature);
1188 gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
1189 MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
1190 modest_account_mgr_set_string (dialog->account_manager, account_name,
1191 MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
1194 const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
1195 MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
1196 modest_account_mgr_set_int (dialog->account_manager, account_name,
1197 MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
1199 const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
1200 test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
1201 MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
1206 gchar* incoming_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1207 MODEST_ACCOUNT_STORE_ACCOUNT, FALSE /* not server account */);
1208 g_assert (incoming_account_name);
1210 const gchar* hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_incomingserver));
1211 test = modest_account_mgr_set_string (dialog->account_manager, incoming_account_name,
1212 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1216 const gchar* username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_username));
1217 modest_server_account_set_username (dialog->account_manager, incoming_account_name, username);
1219 const gchar* password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_user_password));
1220 modest_server_account_set_password (dialog->account_manager, incoming_account_name, password);
1223 gint port_num = hildon_number_editor_get_value (
1224 HILDON_NUMBER_EDITOR (dialog->entry_incoming_port));
1225 modest_account_mgr_set_int (dialog->account_manager, incoming_account_name,
1226 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1228 /* The UI spec says:
1229 * If secure authentication is unchecked, allow sending username and password also as plain text.
1230 * If secure authentication is checked, require one of the secure methods during connection: SSL, TLS, CRAM-MD5 etc.
1232 ModestAuthProtocol protocol_authentication_incoming =
1233 MODEST_PROTOCOL_AUTH_PASSWORD;
1234 if (gtk_toggle_button_get_active (
1235 GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth))) {
1236 GList *list_auth_methods =
1237 get_supported_secure_authentication_methods (dialog->incoming_protocol,
1238 hostname, port_num, GTK_WINDOW (dialog));
1239 if (list_auth_methods) {
1240 /* Use the first supported method.
1241 * TODO: Should we prioritize them, to prefer a particular one? */
1242 protocol_authentication_incoming =
1243 (ModestAuthProtocol)(GPOINTER_TO_INT(list_auth_methods->data));
1244 g_list_free (list_auth_methods);
1247 g_warning ("%s: get_supported_secure_authentication_methods() returned NULL.\n", __FUNCTION__);
1251 modest_server_account_set_secure_auth (dialog->account_manager, incoming_account_name, protocol_authentication_incoming);
1254 const ModestConnectionProtocol protocol_security_incoming = modest_serversecurity_combo_box_get_active_serversecurity (
1255 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_incoming_security));
1256 modest_server_account_set_security (dialog->account_manager, incoming_account_name, protocol_security_incoming);
1260 g_free (incoming_account_name);
1263 gchar* outgoing_account_name = modest_account_mgr_get_string (dialog->account_manager, account_name,
1264 MODEST_ACCOUNT_TRANSPORT_ACCOUNT, FALSE /* not server account */);
1265 g_assert (outgoing_account_name);
1267 hostname = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoingserver));
1268 test = modest_account_mgr_set_string (dialog->account_manager, outgoing_account_name,
1269 MODEST_ACCOUNT_HOSTNAME, hostname, TRUE /* server account */);
1273 username = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_username));
1274 modest_server_account_set_username (dialog->account_manager, outgoing_account_name,
1277 password = gtk_entry_get_text (GTK_ENTRY (dialog->entry_outgoing_password));
1278 modest_server_account_set_password (dialog->account_manager, outgoing_account_name,
1281 const ModestConnectionProtocol protocol_security_outgoing = modest_serversecurity_combo_box_get_active_serversecurity (
1282 MODEST_SERVERSECURITY_COMBO_BOX (dialog->combo_outgoing_security));
1283 modest_server_account_set_security (dialog->account_manager, outgoing_account_name, protocol_security_outgoing);
1285 const ModestAuthProtocol protocol_authentication_outgoing = modest_secureauth_combo_box_get_active_secureauth (
1286 MODEST_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth));
1287 modest_server_account_set_secure_auth (dialog->account_manager, outgoing_account_name, protocol_authentication_outgoing);
1290 port_num = hildon_number_editor_get_value (
1291 HILDON_NUMBER_EDITOR (dialog->entry_outgoing_port));
1292 modest_account_mgr_set_int (dialog->account_manager, outgoing_account_name,
1293 MODEST_ACCOUNT_PORT, port_num, TRUE /* server account */);
1295 g_free (outgoing_account_name);
1298 /* Set the changed account title last, to simplify the previous code: */
1299 const gchar* account_title = gtk_entry_get_text (GTK_ENTRY (dialog->entry_account_title));
1300 if ((!account_title) || (strlen(account_title) == 0))
1301 return FALSE; /* Should be prevented already anyway. */
1303 if (strcmp(account_title, account_name) != 0) {
1304 /* Change the title: */
1305 gboolean test = modest_account_mgr_set_string (dialog->account_manager, account_name,
1306 MODEST_ACCOUNT_DISPLAY_NAME, account_title, FALSE /* not server account */);
1311 /* Save connection-specific SMTP server accounts: */
1312 if (dialog->specific_window) {
1313 return modest_connection_specific_smtp_window_save_server_accounts (
1314 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (dialog->specific_window), account_name);
1320 static gboolean entry_is_empty (GtkWidget *entry)
1325 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1326 if ((!text) || (strlen(text) == 0))
1333 enable_buttons (ModestAccountSettingsDialog *self)
1335 gboolean enable_ok = TRUE;
1337 /* The account details title is mandatory: */
1338 if (entry_is_empty(self->entry_account_title))
1341 /* The user details username is mandatory: */
1342 if (entry_is_empty(self->entry_user_username))
1345 /* The user details email address is mandatory: */
1346 if (enable_ok && entry_is_empty (self->entry_user_email))
1349 /* The custom incoming server is mandatory: */
1350 if (entry_is_empty(self->entry_incomingserver))
1353 /* Enable the buttons,
1354 * identifying them via their associated response codes:
1356 GtkDialog *dialog_base = GTK_DIALOG (self);
1357 gtk_dialog_set_response_sensitive (dialog_base,
1363 modest_account_settings_dialog_class_init (ModestAccountSettingsDialogClass *klass)
1365 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1366 g_type_class_add_private (klass, sizeof (ModestAccountSettingsDialogPrivate));
1369 object_class->get_property = modest_account_settings_dialog_get_property;
1370 object_class->set_property = modest_account_settings_dialog_set_property;
1371 object_class->dispose = modest_account_settings_dialog_dispose;
1372 object_class->finalize = modest_account_settings_dialog_finalize;
1376 show_error (GtkWindow *parent_window, const gchar* text)
1378 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1380 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1387 gtk_dialog_run (dialog);
1388 gtk_widget_destroy (GTK_WIDGET (dialog));
1392 show_ok (GtkWindow *parent_window, const gchar* text)
1394 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text));
1396 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
1403 gtk_dialog_run (dialog);
1404 gtk_widget_destroy (GTK_WIDGET (dialog));
1407 /* TODO: Enable this when tinymail has the API: */
1413 } ModestGetSupportedAuthInfo;
1415 static void on_camel_account_get_supported_secure_authentication_status (
1416 GObject *self, TnyStatus *status, gpointer user_data)
1418 printf ("DEBUG: %s.\n", __FUNCTION__);
1422 on_camel_account_get_supported_secure_authentication (
1423 TnyCamelAccount *self, gboolean cancelled,
1424 GList *auth_types, GError **err,
1427 printf ("DEBUG: %s.\n", __FUNCTION__);
1429 ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
1430 g_return_if_fail (info);
1433 printf ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__);
1434 info->finished = TRUE; /* We are blocking, waiting for this. */
1438 ModestPairList* pairs = modest_protocol_info_get_protocol_auth_pair_list ();
1440 /* Get the enum value for the strings: */
1441 GList *result = NULL;
1442 GList* iter = auth_types;
1444 const gchar *auth_name = (const gchar*)iter->data;
1445 printf("DEBUG: %s: auth_name=%s\n", __FUNCTION__, auth_name);
1446 ModestPair *matching = modest_pair_list_find_by_first_as_string (pairs,
1449 g_list_append (result, GINT_TO_POINTER((ModestConnectionProtocol)matching->second));
1451 iter = g_list_next (iter);
1454 g_list_free (auth_types);
1456 modest_pair_list_free (pairs);
1458 info->result = result;
1459 info->finished = TRUE; /* We are blocking, waiting for this. */
1464 static GList* get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto,
1465 const gchar* hostname, gint port, GtkWindow *parent_window)
1469 /* TODO: Enable this when tinymail has the API: */
1471 g_return_val_if_fail (proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN, NULL);
1474 result = g_list_append (result, GINT_TO_POINTER (MODEST_PROTOCOL_AUTH_CRAMMD5));
1477 /* Create a TnyCamelAccount so we can use
1478 * tny_camel_account_get_supported_secure_authentication(): */
1479 TnyAccount * tny_account = NULL;
1481 case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
1482 case MODEST_PROTOCOL_TRANSPORT_SMTP:
1483 tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ()); break;
1484 case MODEST_PROTOCOL_STORE_POP:
1485 tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ()); break;
1486 case MODEST_PROTOCOL_STORE_IMAP:
1487 tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ()); break;
1488 case MODEST_PROTOCOL_STORE_MAILDIR:
1489 case MODEST_PROTOCOL_STORE_MBOX:
1490 tny_account = TNY_ACCOUNT(tny_camel_store_account_new()); break;
1496 g_printerr ("%s could not create tny account.", __FUNCTION__);
1500 /* Set proto, so that the prepare_func() vfunc will work when we call
1502 /* TODO: Why isn't this done in account_new()? */
1503 tny_account_set_proto (tny_account,
1504 modest_protocol_info_get_transport_store_protocol_name(proto));
1506 /* Set the session for the account, so we can use it: */
1507 ModestTnyAccountStore *account_store = modest_runtime_get_account_store ();
1508 TnySessionCamel *session =
1509 modest_tny_account_store_get_session (TNY_ACCOUNT_STORE (account_store));
1510 g_return_val_if_fail (session, NULL);
1511 tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
1513 tny_account_set_hostname (tny_account, hostname);
1516 tny_account_set_port (tny_account, port);
1519 /* Ask camel to ask the server, asynchronously: */
1520 ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo);
1521 info->finished = FALSE;
1522 info->result = NULL;
1524 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window,
1525 _("Asking the server for supported secure authentication mechanisms.")));
1526 gtk_dialog_run (dialog);
1528 printf ("DEBUG: %s: STARTING.\n", __FUNCTION__);
1529 tny_camel_account_get_supported_secure_authentication (
1530 TNY_CAMEL_ACCOUNT (tny_account),
1531 on_camel_account_get_supported_secure_authentication,
1532 on_camel_account_get_supported_secure_authentication_status,
1535 printf ("DEBUG: %s: AFTER STARTING.\n", __FUNCTION__);
1537 /* Block until the callback has been called,
1538 * driving the main context, so that the (idle handler) callback can be
1539 * called, and so that our dialog is clickable: */
1540 while (!(info->finished)) {
1541 printf ("DEBUG: %s: finished is FALSE.\n", __FUNCTION__);
1542 if (g_main_context_pending (NULL)) {
1543 printf ("DEBUG: iterating\n");
1544 g_main_context_iteration (NULL, FALSE);
1545 printf ("DEBUG: after iterating\n");
1549 printf ("DEBUG: %s: FINISHED.\n", __FUNCTION__);
1551 gtk_widget_destroy (GTK_WIDGET (dialog));
1553 GList *result = info->result;
1554 g_slice_free (ModestGetSupportedAuthInfo, info);