1 /* Copyright (c) 2008, 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 <glib/gi18n.h>
32 #include <gtk/gtkvbox.h>
33 #include <gtk/gtklabel.h>
34 #include <gtk/gtkentry.h>
35 #include <gtk/gtkbutton.h>
36 #include <gtk/gtkcheckbutton.h>
37 #include <gtk/gtkmessagedialog.h>
38 #include <gtk/gtkstock.h>
39 #include "modest-hildon-includes.h"
40 #include "modest-default-account-settings-dialog.h"
41 #include "modest-account-mgr.h"
42 #include "modest-secureauth-picker.h"
43 #include "widgets/modest-validating-entry.h"
44 #include "modest-retrieve-picker.h"
45 #include "modest-limit-retrieve-picker.h"
46 #include "modest-text-utils.h"
47 #include "modest-account-mgr.h"
48 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
49 #include <modest-server-account-settings.h>
50 #include "modest-runtime.h" /* For modest_runtime_get_account_mgr(). */
51 #include "modest-connection-specific-smtp-window.h"
52 #include "modest-signature-editor-dialog.h"
53 #include <modest-utils.h>
54 #include <modest-defs.h>
55 #include "modest-maemo-utils.h"
56 #include "modest-maemo-security-options-view.h"
57 #include "widgets/modest-ui-constants.h"
58 #include <tny-account.h>
59 #include <tny-status.h>
61 #include <gconf/gconf-client.h>
62 #include <string.h> /* For strlen(). */
65 /* Include config.h so that _() works: */
71 #define PORT_MAX 65535
73 static void modest_account_settings_dialog_init (gpointer g, gpointer iface_data);
75 G_DEFINE_TYPE_EXTENDED (ModestDefaultAccountSettingsDialog,
76 modest_default_account_settings_dialog,
79 G_IMPLEMENT_INTERFACE (MODEST_TYPE_ACCOUNT_SETTINGS_DIALOG,
80 modest_account_settings_dialog_init));
82 #define MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(o) \
83 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, ModestDefaultAccountSettingsDialogPrivate))
85 typedef struct _ModestDefaultAccountSettingsDialogPrivate ModestDefaultAccountSettingsDialogPrivate;
87 struct _ModestDefaultAccountSettingsDialogPrivate
89 /* Used by derived widgets to query existing accounts,
90 * and to create new accounts: */
91 ModestAccountMgr *account_manager;
92 ModestAccountSettings *settings;
95 gchar * account_name; /* This may not change. It is not user visible. */
96 ModestProtocolType incoming_protocol; /* This may not change. */
97 ModestProtocolType outgoing_protocol; /* This may not change. */
98 gchar * original_account_title;
100 ModestProtocolType protocol_authentication_incoming;
102 GtkWidget *main_container;
104 GtkWidget *page_account_details;
105 GtkWidget *entry_account_title;
106 GtkWidget *retrieve_picker;
107 GtkWidget *limit_retrieve_picker;
108 GtkWidget *caption_leave_messages;
109 GtkWidget *checkbox_leave_messages;
111 GtkWidget *page_user_details;
112 GtkWidget *entry_user_name;
113 GtkWidget *entry_user_username;
114 GtkWidget *entry_user_password;
115 GtkWidget *entry_user_email;
116 /* GtkWidget *entry_incoming_port; */
117 GtkWidget *button_signature;
119 GtkWidget *page_complete_easysetup;
121 GtkWidget *page_incoming;
122 GtkWidget *caption_incoming;
123 GtkWidget *entry_incomingserver;
125 GtkWidget *page_outgoing;
126 GtkWidget *entry_outgoingserver;
127 GtkWidget *checkbox_outgoing_smtp_specific;
128 GtkWidget *button_outgoing_smtp_servers;
130 GtkWidget *signature_dialog;
132 GtkWidget *incoming_security;
133 GtkWidget *outgoing_security;
137 enable_buttons (ModestDefaultAccountSettingsDialog *self);
140 save_configuration (ModestDefaultAccountSettingsDialog *dialog);
142 static const gchar * null_means_empty (const gchar * str);
145 null_means_empty (const gchar * str)
147 return str ? str : "";
151 modest_default_account_settings_dialog_dispose (GObject *object)
153 if (G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose)
154 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->dispose (object);
158 modest_default_account_settings_dialog_finalize (GObject *object)
160 ModestDefaultAccountSettingsDialog *self;
161 ModestDefaultAccountSettingsDialogPrivate *priv;
163 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
164 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
166 if (priv->account_name)
167 g_free (priv->account_name);
169 if (priv->original_account_title)
170 g_free (priv->original_account_title);
172 if (priv->account_manager)
173 g_object_unref (G_OBJECT (priv->account_manager));
175 if (priv->signature_dialog)
176 gtk_widget_destroy (priv->signature_dialog);
178 if (priv->settings) {
179 g_object_unref (priv->settings);
180 priv->settings = NULL;
183 G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
187 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
189 ModestDefaultAccountSettingsDialogPrivate *priv;
191 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
192 priv->modified = modified;
196 on_modified_picker_changed (HildonPickerButton *widget, gpointer user_data)
198 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
202 on_modified_entry_changed (GtkEditable *editable, gpointer user_data)
204 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
208 on_modified_checkbutton_clicked (GtkButton *button, gpointer user_data)
210 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
214 on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
216 set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
220 on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
222 ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
223 gint value = hildon_number_editor_get_value (editor);
225 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
228 /* Set a modified boolean whenever the widget is changed,
229 * so we can check for it later.
232 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
234 if (HILDON_IS_NUMBER_EDITOR (widget)) {
235 g_signal_connect (G_OBJECT (widget), "notify::value",
236 G_CALLBACK (on_modified_number_editor_changed), self);
237 g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
239 else if (GTK_IS_ENTRY (widget)) {
240 g_signal_connect (G_OBJECT (widget), "changed",
241 G_CALLBACK (on_modified_entry_changed), self);
242 } else if (HILDON_IS_PICKER_BUTTON (widget)) {
243 g_signal_connect (G_OBJECT (widget), "value-changed",
244 G_CALLBACK (on_modified_picker_changed), self);
245 } else if (GTK_IS_BUTTON (widget)) {
246 g_signal_connect (G_OBJECT (widget), "clicked",
247 G_CALLBACK (on_modified_checkbutton_clicked), self);
252 on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
254 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
256 enable_buttons(self);
260 create_captioned (ModestDefaultAccountSettingsDialog *self,
262 const gchar *label_text,
268 result = modest_maemo_utils_create_captioned (group, label_text, control);
270 /* Connect to the appropriate changed signal for the widget,
271 * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
273 if (GTK_IS_ENTRY (control)) {
274 g_signal_connect (G_OBJECT (control), "changed",
275 G_CALLBACK (on_caption_entry_changed), self);
283 on_entry_invalid_account_title_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
287 tmp = g_strndup (account_title_forbidden_chars, ACCOUNT_TITLE_FORBIDDEN_CHARS_LENGTH);
288 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
290 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
297 on_entry_invalid_fullname_character (ModestValidatingEntry *self, const gchar* character, gpointer user_data)
301 tmp = g_strndup (user_name_forbidden_chars, USER_NAME_FORBIDDEN_CHARS_LENGTH);
302 msg = g_strdup_printf (_CS("ckdg_ib_illegal_characters_entered"), tmp);
304 modest_platform_information_banner (GTK_WIDGET (self), NULL, msg);
312 on_entry_max (ModestValidatingEntry *self, gpointer user_data)
314 modest_platform_information_banner (GTK_WIDGET (self), NULL,
315 _CS("ckdg_ib_maximum_characters_reached"));
319 create_page_account_details (ModestDefaultAccountSettingsDialog *self)
321 ModestDefaultAccountSettingsDialogPrivate *priv;
323 GtkSizeGroup* sizegroup;
325 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
326 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
327 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
329 /* The description widgets: */
330 priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
331 /* Do use auto-capitalization: */
332 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title),
333 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
334 GtkWidget *caption = create_captioned (self, sizegroup, _("mcen_fi_account_title"),
335 priv->entry_account_title);
336 gtk_widget_show (priv->entry_account_title);
337 connect_for_modified (self, priv->entry_account_title);
338 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
339 gtk_widget_show (caption);
341 /* Prevent the use of some characters in the account title,
342 * as required by our UI specification: */
343 GList *list_prevent = NULL;
344 list_prevent = g_list_append (list_prevent, "\\");
345 list_prevent = g_list_append (list_prevent, "/");
346 list_prevent = g_list_append (list_prevent, ":");
347 list_prevent = g_list_append (list_prevent, "*");
348 list_prevent = g_list_append (list_prevent, "?");
349 list_prevent = g_list_append (list_prevent, "\"");
350 list_prevent = g_list_append (list_prevent, "<");
351 list_prevent = g_list_append (list_prevent, ">");
352 list_prevent = g_list_append (list_prevent, "|");
353 list_prevent = g_list_append (list_prevent, "^");
354 modest_validating_entry_set_unallowed_characters (
355 MODEST_VALIDATING_ENTRY (priv->entry_account_title), list_prevent);
356 g_list_free (list_prevent);
357 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
358 on_entry_invalid_account_title_character, self);
360 /* Set max length as in the UI spec:
361 * The UI spec seems to want us to show a dialog if we hit the maximum. */
362 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
363 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title),
366 /* The retrieve picker: */
367 priv->retrieve_picker = GTK_WIDGET (modest_retrieve_picker_new (MODEST_EDITABLE_SIZE,
368 MODEST_EDITABLE_ARRANGEMENT));
369 modest_maemo_utils_create_picker_layout (sizegroup, _("mcen_fi_advsetup_retrievetype"), priv->retrieve_picker);
371 gtk_widget_show (priv->retrieve_picker);
372 connect_for_modified (self, priv->retrieve_picker);
373 gtk_box_pack_start (GTK_BOX (box), priv->retrieve_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
375 /* The limit-retrieve picker: */
376 priv->limit_retrieve_picker = GTK_WIDGET (modest_limit_retrieve_picker_new (MODEST_EDITABLE_SIZE,
377 MODEST_EDITABLE_ARRANGEMENT));
378 modest_maemo_utils_create_picker_layout (sizegroup, _("mcen_fi_advsetup_limit_retrieve"), priv->limit_retrieve_picker);
379 gtk_widget_show (priv->limit_retrieve_picker);
380 connect_for_modified (self, priv->limit_retrieve_picker);
381 gtk_box_pack_start (GTK_BOX (box), priv->limit_retrieve_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
383 /* The leave-messages widgets: */
384 if(!priv->checkbox_leave_messages)
385 priv->checkbox_leave_messages = gtk_check_button_new ();
386 if (!priv->caption_leave_messages) {
387 priv->caption_leave_messages =
388 create_captioned (self, sizegroup, _("mcen_fi_advsetup_leave_on_server"),
389 priv->checkbox_leave_messages);
392 gtk_widget_show (priv->checkbox_leave_messages);
393 connect_for_modified (self, priv->checkbox_leave_messages);
394 gtk_box_pack_start (GTK_BOX (box), priv->caption_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
395 gtk_widget_show (priv->caption_leave_messages);
397 g_object_unref (sizegroup);
399 gtk_widget_show (GTK_WIDGET (box));
401 return GTK_WIDGET (box);
405 get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
407 ModestDefaultAccountSettingsDialogPrivate *priv;
408 const gchar* account_title;
410 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
411 account_title = gtk_entry_get_text (GTK_ENTRY (priv->entry_account_title));
413 if (!account_title || (strlen (account_title) == 0))
416 /* Strip it of whitespace at the start and end: */
417 gchar *result = g_strdup (account_title);
418 result = g_strstrip (result);
423 if (strlen (result) == 0) {
434 on_button_signature (GtkButton *button, gpointer user_data)
436 ModestDefaultAccountSettingsDialog *self;
438 ModestDefaultAccountSettingsDialogPrivate *priv;
440 self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
441 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
443 /* Create the window, if necessary: */
444 if (!(priv->signature_dialog)) {
445 priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
447 gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
448 const gchar *signature = modest_account_settings_get_signature(priv->settings);
449 gchar* account_title = get_entered_account_title (self);
450 modest_signature_editor_dialog_set_settings (
451 MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
452 use_signature, signature, account_title);
454 g_free (account_title);
455 account_title = NULL;
459 /* Show the window: */
460 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
461 GTK_WINDOW (priv->signature_dialog), GTK_WINDOW (self));
463 response = gtk_dialog_run (GTK_DIALOG (priv->signature_dialog));
464 gtk_widget_hide (priv->signature_dialog);
465 if (response != GTK_RESPONSE_OK) {
466 /* Destroy the widget now, and its data: */
467 gtk_widget_destroy (priv->signature_dialog);
468 priv->signature_dialog = NULL;
470 /* Mark modified, so we use the dialog's data later: */
471 priv->modified = TRUE;
476 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
478 ModestDefaultAccountSettingsDialogPrivate *priv;
480 GtkSizeGroup* sizegroup;
482 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
484 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
485 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
487 /* The name widgets: */
488 priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
490 /* Auto-capitalization is the default, so let's turn it off: */
491 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
492 /* Set max length as in the UI spec:
493 * The UI spec seems to want us to show a dialog if we hit the maximum. */
494 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
495 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name),
498 create_captioned (self, sizegroup,
499 _("mcen_li_emailsetup_name"), priv->entry_user_name);
500 gtk_widget_show (priv->entry_user_name);
501 connect_for_modified (self, priv->entry_user_name);
502 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
503 gtk_widget_show (caption);
506 /* Prevent the use of some characters in the name,
507 * as required by our UI specification: */
508 GList *list_prevent = NULL;
509 list_prevent = g_list_append (list_prevent, "<");
510 list_prevent = g_list_append (list_prevent, ">");
511 modest_validating_entry_set_unallowed_characters (
512 MODEST_VALIDATING_ENTRY (priv->entry_user_name), list_prevent);
513 g_list_free (list_prevent);
514 modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_user_name),
515 on_entry_invalid_fullname_character, self);
517 /* The username widgets: */
518 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
519 /* Auto-capitalization is the default, so let's turn it off: */
520 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
521 caption = create_captioned (self, sizegroup, _("mail_fi_username"),
522 priv->entry_user_username);
523 gtk_widget_show (priv->entry_user_username);
524 connect_for_modified (self, priv->entry_user_username);
525 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
526 gtk_widget_show (caption);
528 /* Prevent the use of some characters in the username,
529 * as required by our UI specification: */
530 modest_validating_entry_set_unallowed_characters_whitespace (
531 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
532 modest_validating_entry_set_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
533 modest_utils_on_entry_invalid_character,
536 /* Set max length as in the UI spec:
537 * The UI spec seems to want us to show a dialog if we hit the maximum. */
538 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
539 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_username),
542 /* The password widgets: */
543 priv->entry_user_password = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
544 /* Auto-capitalization is the default, so let's turn it off: */
545 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
546 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
547 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
548 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
549 caption = create_captioned (self, sizegroup,
550 _("mail_fi_password"), priv->entry_user_password);
551 gtk_widget_show (priv->entry_user_password);
552 connect_for_modified (self, priv->entry_user_password);
553 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
554 gtk_widget_show (caption);
556 /* The email address widgets: */
557 priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
558 /* Auto-capitalization is the default, so let's turn it off: */
559 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
560 caption = create_captioned (self, sizegroup,
561 _("mcen_li_emailsetup_email_address"), priv->entry_user_email);
562 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
563 gtk_widget_show (priv->entry_user_email);
564 connect_for_modified (self, priv->entry_user_email);
565 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
566 gtk_widget_show (caption);
568 /* Set max length as in the UI spec:
569 * The UI spec seems to want us to show a dialog if we hit the maximum. */
570 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_email), 64);
571 modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email),
574 /* Signature button: */
575 if (!priv->button_signature)
576 priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
577 caption = create_captioned (self, sizegroup, _("mcen_fi_email_signature"), priv->button_signature);
578 gtk_widget_show (priv->button_signature);
579 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
580 gtk_widget_show (caption);
582 g_object_unref (sizegroup);
584 g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
585 G_CALLBACK (on_button_signature), self);
587 gtk_widget_show (GTK_WIDGET (box));
589 return GTK_WIDGET (box);
592 /* Change the caption title for the incoming server */
594 update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
595 ModestProtocolType protocol_type)
597 ModestProtocolRegistry *protocol_registry;
598 ModestProtocol *protocol;
599 const gchar *protocol_display_name;
600 gchar* incomingserver_title;
601 gchar *with_asterisk;
602 ModestDefaultAccountSettingsDialogPrivate *priv;
604 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
606 protocol_registry = modest_runtime_get_protocol_registry ();
607 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
608 protocol_display_name = modest_protocol_get_display_name (protocol);
609 incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"),
610 protocol_display_name);
612 /* This is a mandatory field, so add a *. This is usually done by
613 * create_caption_new_with_asterisk() but we can't use that here. */
614 with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
615 g_free (incomingserver_title);
617 g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
618 g_free (with_asterisk);
622 create_page_incoming (ModestDefaultAccountSettingsDialog *self)
624 ModestDefaultAccountSettingsDialogPrivate *priv;
626 GtkSizeGroup *sizegroup;
628 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
630 box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
631 /* Create a size group to be used by all captions.
632 * Note that HildonCaption does not create a default size group if we do not specify one.
633 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
634 sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
636 /* The incoming server widgets: */
637 if(!priv->entry_incomingserver)
638 priv->entry_incomingserver = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
639 /* Auto-capitalization is the default, so let's turn it off: */
640 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_incomingserver), HILDON_GTK_INPUT_MODE_FULL);
642 if (priv->caption_incoming)
643 gtk_widget_destroy (priv->caption_incoming);
645 /* The caption title will be updated in update_incoming_server_title().
646 * so this default text will never be seen: */
647 /* (Note: Changing the title seems pointless. murrayc) */
648 priv->caption_incoming = create_captioned (self, sizegroup,
649 "Incoming Server", priv->entry_incomingserver);
650 gtk_widget_show (priv->entry_incomingserver);
651 connect_for_modified (self, priv->entry_incomingserver);
652 gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
653 gtk_widget_show (priv->caption_incoming);
655 /* Incoming security widgets */
656 priv->incoming_security =
657 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
659 gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
660 FALSE, FALSE, MODEST_MARGIN_HALF);
662 gtk_widget_show (priv->incoming_security);
664 g_object_unref (sizegroup);
665 gtk_widget_show (GTK_WIDGET (box));
667 return GTK_WIDGET (box);
671 on_check_button_clicked (GtkButton *button, gpointer user_data)
673 GtkWidget *widget = GTK_WIDGET (user_data);
675 /* Enable the widget only if the check button is active: */
676 const gboolean enable = hildon_check_button_get_active (button);
677 gtk_widget_set_sensitive (widget, enable);
680 /* Make the sensitivity of a widget depend on a check button.
683 enable_widget_for_checkbutton (GtkWidget *widget, GtkButton* button)
685 g_signal_connect (G_OBJECT (button), "clicked",
686 G_CALLBACK (on_check_button_clicked), widget);
688 /* Set the starting sensitivity: */
689 on_check_button_clicked (button, widget);
693 on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
695 ModestDefaultAccountSettingsDialog * self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
696 ModestConnectionSpecificSmtpWindow *smtp_win;
697 ModestDefaultAccountSettingsDialogPrivate *priv;
699 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
701 /* Create the window if necessary: */
702 smtp_win = modest_connection_specific_smtp_window_new ();
703 modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
705 /* Show the window: */
706 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win), GTK_WINDOW (self));
707 gtk_widget_show (GTK_WIDGET (smtp_win));
708 priv->modified = TRUE;
712 on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
716 /* Disable the OK button */
717 gtk_dialog_set_response_sensitive (GTK_DIALOG (user_data),
723 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
725 ModestDefaultAccountSettingsDialogPrivate *priv;
726 GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
728 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
730 /* Create a size group to be used by all captions.
731 * Note that HildonCaption does not create a default size group if we do not specify one.
732 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
733 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
735 /* The outgoing server widgets: */
736 if (!priv->entry_outgoingserver)
737 priv->entry_outgoingserver =
738 hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
739 /* Auto-capitalization is the default, so let's turn it off: */
740 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
741 GtkWidget *caption = create_captioned (self, sizegroup,
742 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver);
743 gtk_widget_show (priv->entry_outgoingserver);
744 connect_for_modified (self, priv->entry_outgoingserver);
745 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
746 gtk_widget_show (caption);
748 /* Outgoing security widgets */
749 priv->outgoing_security =
750 modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
752 gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security,
753 FALSE, FALSE, MODEST_MARGIN_HALF);
754 gtk_widget_show (priv->outgoing_security);
755 g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
756 G_CALLBACK (on_missing_mandatory_data), self);
758 GtkWidget *separator = gtk_hseparator_new ();
759 gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
760 gtk_widget_show (separator);
762 /* connection-specific checkbox: */
763 if (!priv->checkbox_outgoing_smtp_specific) {
764 priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (MODEST_EDITABLE_SIZE);
765 hildon_check_button_set_active (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
768 caption = create_captioned (self, sizegroup, _("mcen_fi_advsetup_connection_smtp"),
769 priv->checkbox_outgoing_smtp_specific);
770 gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
771 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
772 gtk_widget_show (caption);
773 connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
775 /* Connection-specific SMTP-Severs Edit button: */
776 if (!priv->button_outgoing_smtp_servers)
777 priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
778 caption = create_captioned (self, sizegroup, _("mcen_fi_advsetup_optional_smtp"),
779 priv->button_outgoing_smtp_servers);
780 gtk_widget_show (priv->button_outgoing_smtp_servers);
781 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
782 gtk_widget_show (caption);
784 /* Only enable the button when the checkbox is checked: */
785 enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers,
786 GTK_BUTTON (priv->checkbox_outgoing_smtp_specific));
788 g_object_unref (sizegroup);
790 g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
791 G_CALLBACK (on_button_outgoing_smtp_servers), self);
793 gtk_widget_show (GTK_WIDGET (box));
795 return GTK_WIDGET (box);
799 check_data (ModestDefaultAccountSettingsDialog *self)
801 gchar* account_title;
802 const gchar* email_address;
803 const gchar* hostname;
804 const gchar* hostname2;
805 ModestDefaultAccountSettingsDialogPrivate *priv;
807 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
809 /* Check that the title is not already in use: */
810 account_title = get_entered_account_title (self);
812 return FALSE; /* Should be prevented already anyway. */
814 if (strcmp(account_title, priv->original_account_title) != 0) {
815 gboolean name_in_use;
817 /* Check the changed title: */
818 name_in_use = modest_account_mgr_account_with_display_name_exists (priv->account_manager,
822 /* Warn the user via a dialog: */
823 modest_platform_information_banner(NULL, NULL, _("mail_ib_account_name_already_existing"));
825 g_free (account_title);
830 g_free (account_title);
831 account_title = NULL;
833 /* Check that the email address is valid: */
834 email_address = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
835 if ((!email_address) || (strlen(email_address) == 0)) {
839 if (!modest_text_utils_validate_email_address (email_address, NULL)) {
840 /* Warn the user via a dialog: */
841 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_email"));
843 /* Return focus to the email address entry: */
844 gtk_widget_grab_focus (priv->entry_user_email);
845 gtk_editable_select_region (GTK_EDITABLE (priv->entry_user_email), 0, -1);
849 /* make sure the domain name for the incoming server is valid */
850 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
851 if ((!hostname) || (strlen(hostname) == 0)) {
855 if (!modest_text_utils_validate_domain_name (hostname)) {
856 /* Warn the user via a dialog: */
857 modest_platform_information_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
859 /* Return focus to the email address entry: */
860 gtk_widget_grab_focus (priv->entry_incomingserver);
861 gtk_editable_select_region (GTK_EDITABLE (priv->entry_incomingserver), 0, -1);
865 /* make sure the domain name for the outgoing server is valid */
866 hostname2 = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
867 if ((!hostname2) || (strlen(hostname2) == 0)) {
871 if (!modest_text_utils_validate_domain_name (hostname2)) {
872 /* Warn the user via a dialog: */
873 modest_platform_information_banner (priv->entry_outgoingserver, NULL, _("mcen_ib_invalid_servername"));
875 /* Return focus to the email address entry: */
876 gtk_widget_grab_focus (priv->entry_outgoingserver);
877 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
885 on_response (GtkDialog *wizard_dialog,
889 ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (wizard_dialog);
890 ModestDefaultAccountSettingsDialogPrivate *priv;
891 gboolean prevent_response = FALSE, sec_changed;
892 ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
894 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
895 enable_buttons (self);
897 /* Check if security widgets changed */
898 incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
899 outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
901 modest_security_options_view_changed (incoming_sec, priv->settings) ||
902 modest_security_options_view_changed (outgoing_sec, priv->settings);
904 /* Warn about unsaved changes: */
905 if (response_id == GTK_RESPONSE_CANCEL && (priv->modified || sec_changed)) {
906 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self),
907 _("imum_nc_wizard_confirm_lose_changes")));
908 /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
910 const gint dialog_response = gtk_dialog_run (dialog);
911 gtk_widget_destroy (GTK_WIDGET (dialog));
913 if (dialog_response != GTK_RESPONSE_OK)
914 prevent_response = TRUE;
916 /* Check for invalid input: */
917 else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
918 prevent_response = TRUE;
921 if (prevent_response) {
922 /* This is a nasty hack. murrayc. */
923 /* Don't let the dialog close */
924 g_signal_stop_emission_by_name (wizard_dialog, "response");
927 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
930 if (response_id == GTK_RESPONSE_OK) {
931 /* Try to save the changes if modified (NB #59251): */
932 if (priv->modified || sec_changed) {
933 if (save_configuration (self)) {
934 /* Do not show the account-saved dialog if we are just saving this
935 * temporarily, because from the user's point of view it will not
936 * really be saved (saved + enabled) until later
938 if (modest_account_settings_get_account_name (priv->settings) != NULL) {
939 ModestServerAccountSettings *store_settings;
940 ModestServerAccountSettings *transport_settings;
941 const gchar *store_account_name;
942 const gchar *transport_account_name;
945 store_settings = modest_account_settings_get_store_settings (priv->settings);
946 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
947 store_account_name = modest_server_account_settings_get_account_name (store_settings);
948 transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
950 if (store_account_name) {
951 modest_account_mgr_notify_account_update (priv->account_manager,
954 if (transport_account_name) {
955 modest_account_mgr_notify_account_update (priv->account_manager,
956 transport_account_name);
958 g_object_unref (store_settings);
959 g_object_unref (transport_settings);
961 modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
964 modest_platform_information_banner (NULL, NULL, _("mail_ib_setting_failed"));
971 modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog *self)
973 ModestDefaultAccountSettingsDialogPrivate *priv;
976 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
978 priv->incoming_security = NULL;
979 priv->outgoing_security = NULL;
981 priv->main_container = gtk_vbox_new (FALSE, MODEST_MARGIN_DOUBLE);
982 priv->settings = modest_account_settings_new ();
984 /* Get the account manager object,
985 * so we can check for existing accounts,
986 * and create new accounts: */
987 priv->account_manager = modest_runtime_get_account_mgr ();
988 g_assert (priv->account_manager);
989 g_object_ref (priv->account_manager);
991 priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
993 /* Create the common pages,
995 priv->page_account_details = create_page_account_details (self);
996 priv->page_user_details = create_page_user_details (self);
997 priv->page_incoming = create_page_incoming (self);
998 priv->page_outgoing = create_page_outgoing (self);
1000 /* Add the notebook pages: */
1001 gtk_box_pack_start (GTK_BOX (priv->main_container),
1002 modest_maemo_utils_create_group_box (_("mcen_ti_account_settings_account"),
1003 priv->page_account_details),
1005 gtk_box_pack_start (GTK_BOX (priv->main_container),
1006 modest_maemo_utils_create_group_box (_("mcen_ti_account_settings_userinfo"),
1007 priv->page_user_details),
1010 gtk_box_pack_start (GTK_BOX (priv->main_container),
1011 modest_maemo_utils_create_group_box (_("mcen_ti_advsetup_retrieval"),
1012 priv->page_incoming),
1014 gtk_box_pack_start (GTK_BOX (priv->main_container),
1015 modest_maemo_utils_create_group_box (_("mcen_ti_advsetup_sending"),
1016 priv->page_outgoing),
1019 GtkDialog *dialog = GTK_DIALOG (self);
1020 pannable = hildon_pannable_area_new ();
1021 hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), priv->main_container);
1022 gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (pannable));
1023 gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
1024 gtk_widget_show (GTK_WIDGET (priv->main_container));
1025 gtk_widget_show (GTK_WIDGET (pannable));
1027 /* Add the buttons: */
1028 gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
1030 gtk_window_set_default_size (GTK_WINDOW (self), -1, 340);
1032 /* Connect to the dialog's response signal: */
1033 /* We use connect-before
1034 * so we can stop the signal emission,
1035 * to stop the default signal handler from closing the dialog.
1037 g_signal_connect (G_OBJECT (self), "response",
1038 G_CALLBACK (on_response), self);
1040 priv->modified = FALSE;
1042 /* When this window is shown, hibernation should not be possible,
1043 * because there is no sensible way to save the state: */
1044 modest_window_mgr_prevent_hibernation_while_window_is_shown (
1045 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
1047 /* Prevent sending mails while editing an account, to avoid hangs on unprotected locks
1048 * while sending messages causes an error dialog and we have a lock */
1049 modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
1051 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
1052 modest_maemo_utils_get_osso_context());
1055 ModestAccountSettingsDialog*
1056 modest_default_account_settings_dialog_new (void)
1058 return g_object_new (MODEST_TYPE_DEFAULT_ACCOUNT_SETTINGS_DIALOG, NULL);
1061 /** Update the UI with the stored account details, so they can be edited.
1062 * @account_name: Name of the account, which should contain incoming and outgoing server accounts.
1065 modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialog *dialog,
1066 ModestAccountSettings *settings)
1068 ModestServerAccountSettings *incoming_account;
1069 ModestServerAccountSettings *outgoing_account;
1070 ModestProtocolRegistry *protocol_registry;
1071 const gchar *account_name, *server_account_name;
1072 ModestDefaultAccountSettingsDialogPrivate *priv;
1073 gboolean username_known;
1075 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
1076 g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
1078 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1079 protocol_registry = modest_runtime_get_protocol_registry ();
1081 incoming_account = modest_account_settings_get_store_settings (settings);
1082 outgoing_account = modest_account_settings_get_transport_settings (settings);
1084 account_name = modest_account_settings_get_account_name (settings);
1086 /* Save the account name so we can refer to it later: */
1087 if (priv->account_name)
1088 g_free (priv->account_name);
1089 priv->account_name = g_strdup (account_name);
1092 g_object_unref (priv->settings);
1093 priv->settings = g_object_ref (settings);
1095 /* Save the account title so we can refer to it if the user changes it: */
1096 if (priv->original_account_title)
1097 g_free (priv->original_account_title);
1098 priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
1100 /* Show the account data in the widgets: */
1102 /* Note that we never show the non-display name in the UI.
1103 * (Though the display name defaults to the non-display name at the start.) */
1104 gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
1105 null_means_empty (modest_account_settings_get_display_name (settings)));
1106 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_name),
1107 null_means_empty (modest_account_settings_get_fullname (settings)));
1108 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email),
1109 null_means_empty (modest_account_settings_get_email_address (settings)));
1110 modest_limit_retrieve_picker_set_active_limit_retrieve (
1111 MODEST_LIMIT_RETRIEVE_PICKER (priv->limit_retrieve_picker),
1112 modest_account_settings_get_retrieve_limit (settings));
1115 hildon_check_button_set_active (GTK_BUTTON (priv->checkbox_leave_messages),
1116 modest_account_settings_get_leave_messages_on_server (settings));
1119 if (incoming_account) {
1120 const gchar *username, *password, *hostname, *proto_str, *account_title;
1121 gchar *proto_name, *title;
1122 ModestProtocolType incoming_protocol;
1124 modest_retrieve_picker_fill (MODEST_RETRIEVE_PICKER (priv->retrieve_picker), modest_server_account_settings_get_protocol (incoming_account));
1125 modest_retrieve_picker_set_active_retrieve_conf (MODEST_RETRIEVE_PICKER (priv->retrieve_picker),
1126 modest_account_settings_get_retrieve_type (settings));
1128 if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
1129 modest_server_account_settings_get_protocol (incoming_account))) {
1130 gtk_widget_hide (priv->caption_leave_messages);
1132 gtk_widget_show (priv->caption_leave_messages);
1135 /* Remember this for later: */
1136 incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
1138 hostname = modest_server_account_settings_get_hostname (incoming_account);
1139 username = modest_server_account_settings_get_username (incoming_account);
1140 password = modest_server_account_settings_get_password (incoming_account);
1141 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_username),
1142 null_means_empty (username));
1143 gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password),
1144 null_means_empty (password));
1146 gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver),
1147 null_means_empty (hostname));
1149 /* Load security settings */
1150 modest_security_options_view_load_settings (
1151 MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1153 gtk_widget_show (priv->incoming_security);
1155 /* Update the incoming label */
1156 update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog),
1159 /* Set window title according to account */
1160 proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
1161 proto_name = g_utf8_strup (proto_str, -1);
1162 account_title = modest_account_settings_get_display_name(settings);
1163 title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
1165 gtk_window_set_title (GTK_WINDOW (dialog), title);
1167 g_free (proto_name);
1169 g_object_unref (incoming_account);
1172 outgoing_account = modest_account_settings_get_transport_settings (settings);
1173 if (outgoing_account) {
1174 const gchar *hostname;
1175 const gchar *username;
1176 const gchar *password;
1177 ModestProtocolType outgoing_protocol;
1179 /* Remember this for later: */
1181 modest_server_account_settings_get_protocol (outgoing_account);
1183 hostname = modest_server_account_settings_get_hostname (outgoing_account);
1184 username = modest_server_account_settings_get_username (outgoing_account);
1185 password = modest_server_account_settings_get_password (outgoing_account);
1186 gtk_entry_set_text( GTK_ENTRY (priv->entry_outgoingserver),
1187 null_means_empty (hostname));
1189 /* Load security settings */
1190 modest_security_options_view_load_settings (
1191 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1193 gtk_widget_show (priv->outgoing_security);
1195 const gboolean has_specific =
1196 modest_account_settings_get_use_connection_specific_smtp (settings);
1197 hildon_check_button_set_active (
1198 GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
1200 g_object_unref (outgoing_account);
1203 /* Switch to user page */
1204 /* Check if we allow changes or not */
1205 server_account_name = modest_server_account_settings_get_account_name (incoming_account);
1207 modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
1208 server_account_name);
1209 gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
1210 gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
1211 modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1215 /* Unset the modified flag so we can detect changes later: */
1216 priv->modified = FALSE;
1220 save_configuration (ModestDefaultAccountSettingsDialog *dialog)
1222 const gchar* user_fullname;
1223 const gchar* emailaddress;
1224 ModestServerAccountSettings *store_settings;
1225 ModestServerAccountSettings *transport_settings;
1226 ModestAccountRetrieveType retrieve_type;
1227 gint retrieve_limit;
1228 gboolean leave_on_server;
1229 const gchar* hostname;
1230 const gchar* username;
1231 const gchar* password;
1232 gchar* account_title;
1233 ModestDefaultAccountSettingsDialogPrivate *priv;
1234 const gchar* account_name;
1236 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
1237 account_name = priv->account_name;
1239 /* Set the account data from the widgets: */
1240 user_fullname = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_name));
1241 modest_account_settings_set_fullname (priv->settings, user_fullname);
1243 emailaddress = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_email));
1244 modest_account_settings_set_email_address (priv->settings, emailaddress);
1247 if (priv->signature_dialog) {
1248 gboolean use_signature = FALSE;
1250 signature = modest_signature_editor_dialog_get_settings (MODEST_SIGNATURE_EDITOR_DIALOG (priv->signature_dialog),
1253 modest_account_settings_set_use_signature (priv->settings, use_signature);
1254 modest_account_settings_set_signature (priv->settings, signature);
1257 retrieve_type = modest_retrieve_picker_get_active_retrieve_conf (
1258 MODEST_RETRIEVE_PICKER (priv->retrieve_picker));
1259 modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
1261 retrieve_limit = modest_limit_retrieve_picker_get_active_limit_retrieve (
1262 MODEST_LIMIT_RETRIEVE_PICKER (priv->limit_retrieve_picker));
1263 modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
1265 leave_on_server = hildon_check_button_get_active (GTK_BUTTON (priv->checkbox_leave_messages));
1266 modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server);
1268 store_settings = modest_account_settings_get_store_settings (priv->settings);
1270 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_incomingserver));
1271 modest_server_account_settings_set_hostname (store_settings, hostname);
1273 username = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username));
1274 modest_server_account_settings_set_username (store_settings, username);
1276 password = gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password));
1277 modest_server_account_settings_set_password (store_settings, password);
1279 /* Save security settings */
1280 modest_security_options_view_save_settings (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
1283 g_object_unref (store_settings);
1286 transport_settings = modest_account_settings_get_transport_settings (priv->settings);
1288 hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
1289 modest_server_account_settings_set_hostname (transport_settings, hostname);
1291 /* Save security settings */
1292 modest_security_options_view_save_settings (
1293 MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security),
1296 /* Set the changed account title last, to simplify the previous code: */
1297 account_title = get_entered_account_title (dialog);
1299 return FALSE; /* Should be prevented already anyway. */
1301 /* if (strcmp (account_title, account_name) != 0) { */
1302 modest_account_settings_set_display_name (priv->settings, account_title);
1304 g_free (account_title);
1305 account_title = NULL;
1307 /* Save connection-specific SMTP server accounts: */
1308 modest_account_settings_set_use_connection_specific_smtp
1310 hildon_check_button_get_active(GTK_BUTTON(priv->checkbox_outgoing_smtp_specific)));
1312 /* this configuration is not persistent, we should not save */
1313 if (account_name != NULL)
1314 modest_account_mgr_save_account_settings (priv->account_manager, priv->settings);
1319 static gboolean entry_is_empty (GtkWidget *entry)
1324 const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
1325 if ((!text) || (strlen(text) == 0))
1328 /* Strip it of whitespace at the start and end: */
1329 gchar *stripped = g_strdup (text);
1330 stripped = g_strstrip (stripped);
1335 const gboolean result = (strlen (stripped) == 0);
1343 enable_buttons (ModestDefaultAccountSettingsDialog *self)
1345 gboolean enable_ok = TRUE;
1346 ModestProtocolRegistry *protocol_registry;
1347 ModestDefaultAccountSettingsDialogPrivate *priv;
1349 priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
1351 /* The account details title is mandatory: */
1352 if (entry_is_empty(priv->entry_account_title))
1355 /* The user details username is mandatory: */
1356 if (enable_ok && entry_is_empty(priv->entry_user_username))
1359 /* The user details email address is mandatory: */
1360 if (enable_ok && entry_is_empty (priv->entry_user_email))
1363 /* The custom incoming server is mandatory: */
1364 if (enable_ok && entry_is_empty(priv->entry_incomingserver))
1367 /* The custom outgoing server is mandatory: */
1368 if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
1371 protocol_registry = modest_runtime_get_protocol_registry ();
1373 /* Enable the buttons,
1374 * identifying them via their associated response codes:
1376 GtkDialog *dialog_base = GTK_DIALOG (self);
1377 gtk_dialog_set_response_sensitive (dialog_base,
1383 modest_default_account_settings_dialog_class_init (ModestDefaultAccountSettingsDialogClass *klass)
1385 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1386 g_type_class_add_private (klass, sizeof (ModestDefaultAccountSettingsDialogPrivate));
1388 object_class->dispose = modest_default_account_settings_dialog_dispose;
1389 object_class->finalize = modest_default_account_settings_dialog_finalize;
1393 modest_account_settings_dialog_init (gpointer g_iface, gpointer iface_data)
1395 ModestAccountSettingsDialogClass *iface = (ModestAccountSettingsDialogClass *) g_iface;
1397 iface->load_settings = modest_default_account_settings_dialog_load_settings;