Incoming and outgoing security settings share now the same size group
[modest] / src / hildon2 / modest-default-account-settings-dialog.c
index 5482e6d..8e9c8df 100644 (file)
@@ -41,8 +41,6 @@
 #include "modest-account-mgr.h"
 #include "modest-secureauth-picker.h"
 #include "widgets/modest-validating-entry.h"
-#include "modest-retrieve-picker.h"
-#include "modest-limit-retrieve-picker.h"
 #include "modest-text-utils.h"
 #include "modest-account-mgr.h"
 #include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
@@ -54,6 +52,7 @@
 #include <modest-defs.h>
 #include "modest-maemo-utils.h"
 #include "modest-maemo-security-options-view.h"
+#include "modest-ui-actions.h"
 #include "widgets/modest-ui-constants.h"
 #include <tny-account.h>
 #include <tny-status.h>
@@ -70,6 +69,9 @@
 #define PORT_MIN 1
 #define PORT_MAX 65535
 
+#define RESPONSE_DELETE_DUMMY 1
+#define RESPONSE_SIGNATURE_DUMMY 2
+
 static void modest_account_settings_dialog_init (gpointer g, gpointer iface_data);
 
 G_DEFINE_TYPE_EXTENDED (ModestDefaultAccountSettingsDialog, 
@@ -103,8 +105,6 @@ struct _ModestDefaultAccountSettingsDialogPrivate
        
        GtkWidget *page_account_details;
        GtkWidget *entry_account_title;
-       GtkWidget *retrieve_picker;
-       GtkWidget *limit_retrieve_picker;
        GtkWidget *checkbox_leave_messages;
        
        GtkWidget *page_user_details;
@@ -112,8 +112,8 @@ struct _ModestDefaultAccountSettingsDialogPrivate
        GtkWidget *entry_user_username;
        GtkWidget *entry_user_password;
        GtkWidget *entry_user_email;
-/*     GtkWidget *entry_incoming_port; */
        GtkWidget *button_signature;
+       GtkWidget *button_delete;
        
        GtkWidget *page_complete_easysetup;
        
@@ -161,28 +161,25 @@ modest_default_account_settings_dialog_finalize (GObject *object)
 
        self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (object);
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
-       
+
        if (priv->account_name)
                g_free (priv->account_name);
-               
+
        if (priv->original_account_title)
                g_free (priv->original_account_title);
-               
+
        if (priv->account_manager)
                g_object_unref (G_OBJECT (priv->account_manager));
-               
-       if (priv->signature_dialog)
-               gtk_widget_destroy (priv->signature_dialog);
 
        if (priv->settings) {
                g_object_unref (priv->settings);
                priv->settings = NULL;
        }
-       
+
        G_OBJECT_CLASS (modest_default_account_settings_dialog_parent_class)->finalize (object);
 }
 
-static void 
+static void
 set_modified (ModestDefaultAccountSettingsDialog *self, gboolean modified)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
@@ -210,16 +207,16 @@ on_modified_checkbutton_toggled (GtkButton *button, gpointer user_data)
 }
 
 static void
-on_modified_number_editor_changed (HildonNumberEditor *number_editor, gint new_value, gpointer user_data)
+on_modified_number_editor_changed (ModestNumberEditor *number_editor, gint new_value, gpointer user_data)
 {
        set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE);
 }
 
 static void       
-on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
+on_number_editor_notify (ModestNumberEditor *editor, GParamSpec *arg1, gpointer user_data)
 {
        ModestDefaultAccountSettingsDialog *dialog = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
-       gint value = hildon_number_editor_get_value (editor);
+       gint value = modest_number_editor_get_value (editor);
 
        gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, value > 0);
 }
@@ -230,7 +227,7 @@ on_number_editor_notify (HildonNumberEditor *editor, GParamSpec *arg1, gpointer
 static void
 connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widget)
 {
-       if (HILDON_IS_NUMBER_EDITOR (widget)) {
+       if (MODEST_IS_NUMBER_EDITOR (widget)) {
                g_signal_connect (G_OBJECT (widget), "notify::value",
                        G_CALLBACK (on_modified_number_editor_changed), self);
                g_signal_connect (G_OBJECT (widget), "notify", G_CALLBACK (on_number_editor_notify), self);
@@ -257,14 +254,17 @@ on_caption_entry_changed (GtkEditable *editable, gpointer user_data)
 
 static GtkWidget* 
 create_captioned (ModestDefaultAccountSettingsDialog *self,
-                 GtkSizeGroup *group,
+                 GtkSizeGroup *title_sizegroup,
+                 GtkSizeGroup *value_sizegroup,
                  const gchar *label_text,
+                 gboolean use_markup,
                  GtkWidget *control)
 {
 
        GtkWidget *result;
 
-       result = modest_maemo_utils_create_captioned (group, label_text, control);
+       result = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
+                                                     label_text, use_markup, control);
 
        /* Connect to the appropriate changed signal for the widget, 
         * so we can ask for the prev/next buttons to be enabled/disabled appropriately:
@@ -319,22 +319,26 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
        GtkWidget *box;
-       GtkSizeGroup* sizegroup;
+       GtkSizeGroup* title_sizegroup;
+       GtkSizeGroup* value_sizegroup;
+       GtkWidget *hbox;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
        box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
            
        /* The description widgets: */  
        priv->entry_account_title = GTK_WIDGET (modest_validating_entry_new ());
        /* Do use auto-capitalization: */
        hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_account_title), 
                HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_AUTOCAP);
-       GtkWidget *caption = create_captioned (self, sizegroup, _("mcen_fi_account_title"), 
+       GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
+                                              _("mcen_fi_account_title"), FALSE,
                                               priv->entry_account_title);
        gtk_widget_show (priv->entry_account_title);
        connect_for_modified (self, priv->entry_account_title);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
        gtk_widget_show (caption);
        
        /* Prevent the use of some characters in the account title, 
@@ -355,29 +359,14 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
        g_list_free (list_prevent);
        modest_validating_entry_set_func(MODEST_VALIDATING_ENTRY(priv->entry_account_title),
                                         on_entry_invalid_account_title_character, self);
-       
+
        /* Set max length as in the UI spec:
         * The UI spec seems to want us to show a dialog if we hit the maximum. */
        gtk_entry_set_max_length (GTK_ENTRY (priv->entry_account_title), 64);
        modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_account_title), 
                on_entry_max, self);
-       
-       /* The retrieve picker: */
-       priv->retrieve_picker = GTK_WIDGET (modest_retrieve_picker_new (MODEST_EDITABLE_SIZE,
-                                                                       MODEST_EDITABLE_ARRANGEMENT));
-       modest_maemo_utils_create_picker_layout (sizegroup, _("mcen_fi_advsetup_retrievetype"), priv->retrieve_picker);
-       
-       gtk_widget_show (priv->retrieve_picker);
-       connect_for_modified (self, priv->retrieve_picker);
-       gtk_box_pack_start (GTK_BOX (box), priv->retrieve_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
-       
-       /* The limit-retrieve picker: */
-       priv->limit_retrieve_picker = GTK_WIDGET (modest_limit_retrieve_picker_new (MODEST_EDITABLE_SIZE,
-                                                                                   MODEST_EDITABLE_ARRANGEMENT));
-       modest_maemo_utils_create_picker_layout (sizegroup, _("mcen_fi_advsetup_limit_retrieve"), priv->limit_retrieve_picker);
-       gtk_widget_show (priv->limit_retrieve_picker);
-       connect_for_modified (self, priv->limit_retrieve_picker);
-       gtk_box_pack_start (GTK_BOX (box), priv->limit_retrieve_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
+
+       hbox = gtk_hbox_new (TRUE, 0);
 
        /* The leave-messages widgets: */
        if(!priv->checkbox_leave_messages) {
@@ -385,13 +374,14 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
                        hildon_check_button_new (HILDON_SIZE_FINGER_HEIGHT);
                gtk_button_set_label (GTK_BUTTON (priv->checkbox_leave_messages),
                                      _("mcen_fi_advsetup_leave_on_server"));
-               gtk_size_group_add_widget (sizegroup, priv->checkbox_leave_messages);
+               gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_leave_messages), 0.0, 0.5);
        }
        connect_for_modified (self, priv->checkbox_leave_messages);
-       gtk_box_pack_start (GTK_BOX (box), priv->checkbox_leave_messages, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), priv->checkbox_leave_messages, FALSE, FALSE, 0);
        gtk_widget_show (priv->checkbox_leave_messages);
 
-       g_object_unref (sizegroup);
+       g_object_unref (title_sizegroup);
+       g_object_unref (value_sizegroup);
        
        gtk_widget_show (GTK_WIDGET (box));
        
@@ -428,19 +418,17 @@ get_entered_account_title (ModestDefaultAccountSettingsDialog *dialog)
 
 
 static void
-on_button_signature (GtkButton *button, gpointer user_data)
+signature_button_clicked (ModestDefaultAccountSettingsDialog *self)
 {
-       ModestDefaultAccountSettingsDialog *self;
        gint response;
        ModestDefaultAccountSettingsDialogPrivate *priv;
 
-       self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
 
        /* Create the window, if necessary: */
        if (!(priv->signature_dialog)) {
                priv->signature_dialog = GTK_WIDGET (modest_signature_editor_dialog_new ());
-       
+
                gboolean use_signature = modest_account_settings_get_use_signature (priv->settings);
                const gchar *signature = modest_account_settings_get_signature(priv->settings);
                gchar* account_title = get_entered_account_title (self);
@@ -469,34 +457,60 @@ on_button_signature (GtkButton *button, gpointer user_data)
        }
 }
 
+static gboolean
+delete_button_clicked (ModestDefaultAccountSettingsDialog *self)
+{
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       gchar *account_title;
+       gboolean removed;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+       if (priv->modified)
+               account_title = g_strdup (priv->original_account_title);
+       else
+               account_title = get_entered_account_title (self);
+
+       removed = modest_ui_actions_on_delete_account (GTK_WINDOW (self),
+                                                      priv->account_name, 
+                                                      (const gchar *) account_title);
+       g_free (account_title);
+
+       return removed;
+}
+
 static GtkWidget*
 create_page_user_details (ModestDefaultAccountSettingsDialog *self)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
        GtkWidget *box;
-       GtkSizeGroup* sizegroup;
+       GtkSizeGroup* title_sizegroup;
+       GtkSizeGroup* value_sizegroup;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
 
        box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
-       sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-        
+       title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
        /* The name widgets: */
        priv->entry_user_name = GTK_WIDGET (modest_validating_entry_new ());
 
        /* Auto-capitalization is the default, so let's turn it off: */
-       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name), HILDON_GTK_INPUT_MODE_FULL);
+       hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_name),
+                                        HILDON_GTK_INPUT_MODE_FULL |
+                                        HILDON_GTK_INPUT_MODE_AUTOCAP);
        /* Set max length as in the UI spec:
         * The UI spec seems to want us to show a dialog if we hit the maximum. */
        gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_name), 64);
        modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_name), 
                on_entry_max, self);
        GtkWidget *caption = 
-               create_captioned (self, sizegroup, 
-                                 _("mcen_li_emailsetup_name"), priv->entry_user_name);
+               create_captioned (self, title_sizegroup, value_sizegroup,
+                                 _("mcen_li_emailsetup_name"), FALSE, priv->entry_user_name);
        gtk_widget_show (priv->entry_user_name);
        connect_for_modified (self, priv->entry_user_name);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
        gtk_widget_show (caption);
 
 
@@ -515,11 +529,12 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
        priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
        /* Auto-capitalization is the default, so let's turn it off: */
        hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
-       caption = create_captioned (self, sizegroup, _("mail_fi_username"), 
+       caption = create_captioned (self, title_sizegroup, value_sizegroup,
+                                   _("mail_fi_username"), FALSE,
                                    priv->entry_user_username);
        gtk_widget_show (priv->entry_user_username);
        connect_for_modified (self, priv->entry_user_username);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
        gtk_widget_show (caption);
        
        /* Prevent the use of some characters in the username, 
@@ -543,23 +558,23 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
                HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
        gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
        /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
-       caption = create_captioned (self, sizegroup, 
-                                   _("mail_fi_password"), priv->entry_user_password);
+       caption = create_captioned (self, title_sizegroup, value_sizegroup,
+                                   _("mail_fi_password"), FALSE, priv->entry_user_password);
        gtk_widget_show (priv->entry_user_password);
        connect_for_modified (self, priv->entry_user_password);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
        gtk_widget_show (caption);
        
        /* The email address widgets: */        
        priv->entry_user_email = GTK_WIDGET (modest_validating_entry_new ());
        /* Auto-capitalization is the default, so let's turn it off: */
        hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_email), HILDON_GTK_INPUT_MODE_FULL);
-       caption = create_captioned (self, sizegroup, 
-                                   _("mcen_li_emailsetup_email_address"), priv->entry_user_email);
+       caption = create_captioned (self, title_sizegroup, value_sizegroup,
+                                   _("mcen_li_emailsetup_email_address"), FALSE, priv->entry_user_email);
        gtk_entry_set_text (GTK_ENTRY (priv->entry_user_email), MODEST_EXAMPLE_EMAIL_ADDRESS); /* Default text. */
        gtk_widget_show (priv->entry_user_email);
        connect_for_modified (self, priv->entry_user_email);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
        gtk_widget_show (caption);
        
        /* Set max length as in the UI spec:
@@ -568,19 +583,22 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
        modest_validating_entry_set_max_func (MODEST_VALIDATING_ENTRY (priv->entry_user_email), 
                on_entry_max, self);
        
+       /* Delete button: */
+       if (!priv->button_delete)
+               priv->button_delete = gtk_dialog_add_button (GTK_DIALOG (self),
+                                                            _HL("wdgt_bd_delete"),
+                                                            RESPONSE_DELETE_DUMMY);
+
        /* Signature button: */
        if (!priv->button_signature)
-               priv->button_signature = gtk_button_new_with_label (_("mcen_bd_edit"));
-       caption = create_captioned (self, sizegroup, _("mcen_fi_email_signature"), priv->button_signature);
+               priv->button_signature = gtk_dialog_add_button (GTK_DIALOG (self),
+                                                               _("mcen_bd_email_signature"),
+                                                               RESPONSE_SIGNATURE_DUMMY);
        gtk_widget_show (priv->button_signature);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
 
-       g_object_unref (sizegroup);
-               
-       g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
-               G_CALLBACK (on_button_signature), self);
-               
+       g_object_unref (title_sizegroup);
+       g_object_unref (value_sizegroup);
+
        gtk_widget_show (GTK_WIDGET (box));
 
        return GTK_WIDGET (box);
@@ -595,7 +613,6 @@ update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
        ModestProtocol *protocol;
        const gchar *protocol_display_name;
        gchar* incomingserver_title;
-       gchar *with_asterisk;
        ModestDefaultAccountSettingsDialogPrivate *priv;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
@@ -603,33 +620,26 @@ update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
        protocol_registry = modest_runtime_get_protocol_registry ();
        protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, protocol_type);
        protocol_display_name = modest_protocol_get_display_name (protocol);
-       incomingserver_title = g_strdup_printf(_("mcen_li_emailsetup_servertype"), 
-                                              protocol_display_name);
+       incomingserver_title = g_strconcat(_("mcen_li_emailsetup_servertype"), "*", 
+                                          "\n<small>(", protocol_display_name, ")</small>", NULL);
        
-       /* This is a mandatory field, so add a *. This is usually done by
-        * create_caption_new_with_asterisk() but we can't use that here. */
-       with_asterisk = g_strconcat (incomingserver_title, "*", NULL);
+       modest_maemo_utils_captioned_set_label (priv->caption_incoming, incomingserver_title, TRUE);
        g_free (incomingserver_title);
-       
-       g_object_set (G_OBJECT (priv->caption_incoming), "label", with_asterisk, NULL);
-       g_free (with_asterisk);
 }
 
-static GtkWidget* 
-create_page_incoming (ModestDefaultAccountSettingsDialog *self)
+/* The size groups passed as arguments are only used by the security settings */
+static GtkWidget*
+create_page_incoming (ModestDefaultAccountSettingsDialog *self,
+                     GtkSizeGroup *security_title_sizegroup,
+                     GtkSizeGroup *security_value_sizegroup)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
        GtkWidget *box;
-       GtkSizeGroup *sizegroup;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
 
-       box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE); 
-       /* Create a size group to be used by all captions.
-        * Note that HildonCaption does not create a default size group if we do not specify one.
-        * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
-       sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-        
+       box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
+
        /* The incoming server widgets: */
        if(!priv->entry_incomingserver)
                priv->entry_incomingserver = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
@@ -638,29 +648,28 @@ create_page_incoming (ModestDefaultAccountSettingsDialog *self)
 
        if (priv->caption_incoming)
                gtk_widget_destroy (priv->caption_incoming);
-          
+
        /* The caption title will be updated in update_incoming_server_title().
         * so this default text will never be seen: */
        /* (Note: Changing the title seems pointless. murrayc) */
-       priv->caption_incoming = create_captioned (self, sizegroup, 
-                                                  "Incoming Server", priv->entry_incomingserver);
+       priv->caption_incoming = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
+                                                  "Incoming Server", FALSE, priv->entry_incomingserver);
        gtk_widget_show (priv->entry_incomingserver);
        connect_for_modified (self, priv->entry_incomingserver);
-       gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), priv->caption_incoming, FALSE, FALSE, 0);
        gtk_widget_show (priv->caption_incoming);
 
        /* Incoming security widgets */
-       priv->incoming_security = 
+       priv->incoming_security =
                modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
-                                                       TRUE, sizegroup);
-       gtk_box_pack_start (GTK_BOX (box), priv->incoming_security, 
-                           FALSE, FALSE, MODEST_MARGIN_HALF);
+                                                       TRUE, security_title_sizegroup,
+                                                       security_value_sizegroup);
+       gtk_box_pack_start (GTK_BOX (box), priv->incoming_security,
+                           FALSE, FALSE, 0);
 
        gtk_widget_show (priv->incoming_security);
-
-       g_object_unref (sizegroup);     
        gtk_widget_show (GTK_WIDGET (box));
-       
+
        return GTK_WIDGET (box);
 }
 
@@ -681,7 +690,7 @@ enable_widget_for_checkbutton (GtkWidget *widget, GtkButton* button)
 {
        g_signal_connect (G_OBJECT (button), "clicked",
                G_CALLBACK (on_check_button_clicked), widget);
-       
+
        /* Set the starting sensitivity: */
        on_check_button_clicked (button, widget);
 }
@@ -699,10 +708,9 @@ on_button_outgoing_smtp_servers (GtkButton *button, gpointer user_data)
        smtp_win = modest_connection_specific_smtp_window_new ();
        modest_connection_specific_smtp_window_fill_with_connections (smtp_win, priv->account_manager);
 
-       /* Show the window: */  
+       /* Show the window: */
        modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (smtp_win), GTK_WINDOW (self));
        gtk_widget_show (GTK_WIDGET (smtp_win));
-       priv->modified = TRUE;
 }
 
 static void
@@ -716,79 +724,78 @@ on_missing_mandatory_data (ModestSecurityOptionsView *security_view,
                                           !missing);
 }
 
-static GtkWidget* 
-create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
+static GtkWidget*
+create_page_outgoing (ModestDefaultAccountSettingsDialog *self,
+                     GtkSizeGroup *security_title_sizegroup,
+                     GtkSizeGroup *security_value_sizegroup)
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
+       gchar *smtp_caption_label;
        GtkWidget *box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
-       
-       /* Create a size group to be used by all captions.
-        * Note that HildonCaption does not create a default size group if we do not specify one.
-        * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
-       GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-        
        /* The outgoing server widgets: */
        if (!priv->entry_outgoingserver)
                priv->entry_outgoingserver = 
                        hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
        /* Auto-capitalization is the default, so let's turn it off: */
        hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
-       GtkWidget *caption = create_captioned (self, sizegroup, 
-                                              _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver);
+       smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
+       GtkWidget *caption = create_captioned (self, security_title_sizegroup, security_value_sizegroup,
+                                              smtp_caption_label, TRUE, priv->entry_outgoingserver);
+       g_free (smtp_caption_label);
        gtk_widget_show (priv->entry_outgoingserver);
        connect_for_modified (self, priv->entry_outgoingserver);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 0);
        gtk_widget_show (caption);
 
        /* Outgoing security widgets */
        priv->outgoing_security = 
                modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
-                                                       TRUE, sizegroup);
+                                                       TRUE, security_title_sizegroup,
+                                                       security_value_sizegroup);
        gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security, 
-                           FALSE, FALSE, MODEST_MARGIN_HALF);
+                           FALSE, FALSE, 0);
        gtk_widget_show (priv->outgoing_security);
        g_signal_connect (priv->outgoing_security, "missing-mandatory-data",
                          G_CALLBACK (on_missing_mandatory_data), self);
 
        GtkWidget *separator = gtk_hseparator_new ();
-       gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, MODEST_MARGIN_DEFAULT);
        gtk_widget_show (separator);
-       
+
        /* connection-specific checkbox: */
        if (!priv->checkbox_outgoing_smtp_specific) {
                priv->checkbox_outgoing_smtp_specific = hildon_check_button_new (MODEST_EDITABLE_SIZE);
                hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_outgoing_smtp_specific), 
                        FALSE);
+               gtk_button_set_label (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific),
+                                     _("mcen_fi_advsetup_connection_smtp"));
+               gtk_button_set_alignment (GTK_BUTTON (priv->checkbox_outgoing_smtp_specific), 0.0, 0.5);
        }
-       caption = create_captioned (self, sizegroup, _("mcen_fi_advsetup_connection_smtp"), 
-                                   priv->checkbox_outgoing_smtp_specific);
        gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
+       gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific, 
+                           FALSE, FALSE, 0);
        connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
-       
+
        /* Connection-specific SMTP-Severs Edit button: */
        if (!priv->button_outgoing_smtp_servers)
-               priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_edit"));
-       caption = create_captioned (self, sizegroup, _("mcen_fi_advsetup_optional_smtp"), 
-                                   priv->button_outgoing_smtp_servers);
+               priv->button_outgoing_smtp_servers = gtk_button_new_with_label (_("mcen_bd_advsetup_optional_smtp"));
+       hildon_gtk_widget_set_theme_size (priv->button_outgoing_smtp_servers, 
+                                         HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);  
        gtk_widget_show (priv->button_outgoing_smtp_servers);
-       gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_widget_show (caption);
-       
+       gtk_box_pack_start (GTK_BOX (box), priv->button_outgoing_smtp_servers, FALSE, FALSE, 0);
+
        /* Only enable the button when the checkbox is checked: */
        enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers, 
                GTK_BUTTON (priv->checkbox_outgoing_smtp_specific));
 
-       g_object_unref (sizegroup);
-               
        g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
                G_CALLBACK (on_button_outgoing_smtp_servers), self);
-               
+
        gtk_widget_show (GTK_WIDGET (box));
-       
+
        return GTK_WIDGET (box);
 }
        
@@ -874,11 +881,31 @@ check_data (ModestDefaultAccountSettingsDialog *self)
                gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
                return FALSE;
        }
-       
+
        return TRUE;
 }
 
-static void 
+static gboolean
+on_delete_event (GtkWidget *widget,
+                 GdkEvent  *event,
+                 gpointer   user_data)
+{
+       ModestDefaultAccountSettingsDialog *self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
+       ModestDefaultAccountSettingsDialogPrivate *priv;
+       ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
+
+       priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
+
+       /* Check if security widgets changed */
+       incoming_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
+       outgoing_sec = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
+
+       return modest_security_options_view_changed (incoming_sec, priv->settings) ||
+               modest_security_options_view_changed (outgoing_sec, priv->settings) ||
+               priv->modified;
+}
+
+static void
 on_response (GtkDialog *wizard_dialog,
             gint response_id,
             gpointer user_data)
@@ -888,6 +915,21 @@ on_response (GtkDialog *wizard_dialog,
        gboolean prevent_response = FALSE, sec_changed;
        ModestSecurityOptionsView *incoming_sec, *outgoing_sec;
 
+       /* Dummy and delete buttons have a response id because they're
+          added with gtk_dialog_add_button in order to get the proper
+          theme */
+       if (response_id == RESPONSE_SIGNATURE_DUMMY) {
+               signature_button_clicked (self);
+               g_signal_stop_emission_by_name (wizard_dialog, "response");
+               return;
+       }
+
+       if (response_id == RESPONSE_DELETE_DUMMY) {
+               if (!delete_button_clicked (self))
+                       g_signal_stop_emission_by_name (wizard_dialog, "response");
+               return;
+       }
+
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
        enable_buttons (self);
 
@@ -899,14 +941,15 @@ on_response (GtkDialog *wizard_dialog,
                modest_security_options_view_changed (outgoing_sec, priv->settings);
 
        /* Warn about unsaved changes: */
-       if (response_id == GTK_RESPONSE_CANCEL && (priv->modified || sec_changed)) {
+       if ((response_id == GTK_RESPONSE_CANCEL || response_id == GTK_RESPONSE_DELETE_EVENT) && 
+           (priv->modified || sec_changed)) {
                GtkDialog *dialog = GTK_DIALOG (hildon_note_new_confirmation (GTK_WINDOW (self), 
                        _("imum_nc_wizard_confirm_lose_changes")));
                /* TODO: These button names will be ambiguous, and not specified in the UI specification. */
-                
+
                 const gint dialog_response = gtk_dialog_run (dialog);
                 gtk_widget_destroy (GTK_WIDGET (dialog));
-                
+
                if (dialog_response != GTK_RESPONSE_OK)
                        prevent_response = TRUE;
        }
@@ -914,16 +957,15 @@ on_response (GtkDialog *wizard_dialog,
        else if (response_id != GTK_RESPONSE_CANCEL && !check_data (self)) {
                prevent_response = TRUE;
        }
-               
+
        if (prevent_response) {
-               /* This is a nasty hack. murrayc. */
                /* Don't let the dialog close */
                g_signal_stop_emission_by_name (wizard_dialog, "response");
-               return; 
+               return;
        } else {
                modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), FALSE);
        }
-               
+
        if (response_id == GTK_RESPONSE_OK) {
                /* Try to save the changes if modified (NB #59251): */
                if (priv->modified || sec_changed) {
@@ -943,7 +985,7 @@ on_response (GtkDialog *wizard_dialog,
                                        transport_settings = modest_account_settings_get_transport_settings (priv->settings);
                                        store_account_name = modest_server_account_settings_get_account_name (store_settings);
                                        transport_account_name = modest_server_account_settings_get_account_name (transport_settings);
-                                       
+
                                        if (store_account_name) {
                                                modest_account_mgr_notify_account_update (priv->account_manager, 
                                                                                          store_account_name);
@@ -954,7 +996,7 @@ on_response (GtkDialog *wizard_dialog,
                                        }
                                        g_object_unref (store_settings);
                                        g_object_unref (transport_settings);
-                                       
+
                                        modest_platform_information_banner(NULL, NULL, _("mcen_ib_advsetup_settings_saved"));
                                }
                        } else {
@@ -969,13 +1011,16 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
 {
        ModestDefaultAccountSettingsDialogPrivate *priv;
        GtkWidget *pannable;
+       GtkWidget *separator;
+       GtkWidget *align;
+       GtkSizeGroup *sec_title_sizegroup, *sec_value_sizegroup;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
 
        priv->incoming_security = NULL;
        priv->outgoing_security = NULL;
 
-       priv->main_container = gtk_vbox_new (FALSE, MODEST_MARGIN_DOUBLE);
+       priv->main_container = gtk_vbox_new (FALSE, 0);
        priv->settings = modest_account_settings_new ();
 
        /* Get the account manager object, 
@@ -984,56 +1029,69 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
        priv->account_manager = modest_runtime_get_account_mgr ();
        g_assert (priv->account_manager);
        g_object_ref (priv->account_manager);
-       
+
        priv->protocol_authentication_incoming = MODEST_PROTOCOLS_AUTH_PASSWORD;
 
-    /* Create the common pages, 
-     */
+       /* Create the common pages */
        priv->page_account_details = create_page_account_details (self);
        priv->page_user_details = create_page_user_details (self);
-       priv->page_incoming = create_page_incoming (self);
-       priv->page_outgoing = create_page_outgoing (self);
-       
+
+       /* Create size groups for security settings */
+       sec_title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+       sec_value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+
+       /* Create incoming and outgoing "pages" */
+       priv->page_incoming = create_page_incoming (self, sec_title_sizegroup, sec_value_sizegroup);
+       priv->page_outgoing = create_page_outgoing (self, sec_title_sizegroup, sec_value_sizegroup);
+       g_object_unref (sec_title_sizegroup);
+       g_object_unref (sec_value_sizegroup);
+
        /* Add the notebook pages: */
        gtk_box_pack_start (GTK_BOX (priv->main_container),
-                           modest_maemo_utils_create_group_box (_("mcen_ti_account_settings_account"),
-                                                                priv->page_account_details),
+                           priv->page_account_details,
                            FALSE, FALSE, 0);
        gtk_box_pack_start (GTK_BOX (priv->main_container),
-                           modest_maemo_utils_create_group_box (_("mcen_ti_account_settings_userinfo"),
-                                                                priv->page_user_details),
+                           priv->page_user_details,
                            FALSE, FALSE, 0);
 
+       separator = gtk_hseparator_new ();
+       gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
+                           FALSE, FALSE, MODEST_MARGIN_DEFAULT);
+       gtk_widget_show (separator);
        gtk_box_pack_start (GTK_BOX (priv->main_container),
-                           modest_maemo_utils_create_group_box (_("mcen_ti_advsetup_retrieval"),
-                                                                priv->page_incoming),
+                           priv->page_incoming,
                            FALSE, FALSE, 0);
+       separator = gtk_hseparator_new ();
+       gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
+                           FALSE, FALSE, MODEST_MARGIN_DEFAULT);
+       gtk_widget_show (separator);
        gtk_box_pack_start (GTK_BOX (priv->main_container),
-                           modest_maemo_utils_create_group_box (_("mcen_ti_advsetup_sending"),
-                                                                priv->page_outgoing),
+                           priv->page_outgoing,
                            FALSE, FALSE, 0);
                
        GtkDialog *dialog = GTK_DIALOG (self);
        pannable = hildon_pannable_area_new ();
-       hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), priv->main_container);
+       g_object_set (G_OBJECT (pannable), "initial-hint", TRUE, NULL);
+
+       align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
+       gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
+       gtk_widget_show (align);
+       gtk_container_add (GTK_CONTAINER (align), priv->main_container);
+       
+       hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), align);
        gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (pannable));
-       gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), MODEST_MARGIN_HALF);
        gtk_widget_show (GTK_WIDGET (priv->main_container));
        gtk_widget_show (GTK_WIDGET (pannable));
         
     /* Add the buttons: */
-    gtk_dialog_add_button (GTK_DIALOG(self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
-
-    gtk_window_set_default_size (GTK_WINDOW (self), -1, 340);
-    
-    /* Connect to the dialog's response signal: */
-    /* We use connect-before 
-     * so we can stop the signal emission, 
-     * to stop the default signal handler from closing the dialog.
-     */
-    g_signal_connect (G_OBJECT (self), "response",
-            G_CALLBACK (on_response), self); 
-            
+       gtk_dialog_add_button (GTK_DIALOG(self), _HL("wdgt_bd_save"), GTK_RESPONSE_OK);
+
+    gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
+
+    /* Connect to the dialog's "response" and "delete-event" signals */
+    g_signal_connect (G_OBJECT (self), "response", G_CALLBACK (on_response), self); 
+    g_signal_connect (G_OBJECT (self), "delete-event", G_CALLBACK (on_delete_event), self); 
+
     priv->modified = FALSE;
 
     /* When this window is shown, hibernation should not be possible, 
@@ -1045,8 +1103,6 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
      * while sending messages causes an error dialog and we have a lock */
     modest_tny_account_store_set_send_mail_blocked (modest_runtime_get_account_store (), TRUE);
 
-    hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_accountsettings",
-                                   modest_maemo_utils_get_osso_context());
 }
 
 ModestAccountSettingsDialog*
@@ -1067,7 +1123,6 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
        ModestProtocolRegistry *protocol_registry;
        const gchar *account_name, *server_account_name;
        ModestDefaultAccountSettingsDialogPrivate *priv;
-       gboolean username_known;
 
        g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS_DIALOG (dialog));
        g_return_if_fail (MODEST_IS_ACCOUNT_SETTINGS (settings));
@@ -1075,27 +1130,29 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (dialog);
        protocol_registry = modest_runtime_get_protocol_registry ();
 
-       incoming_account = modest_account_settings_get_store_settings (settings);
-       outgoing_account = modest_account_settings_get_transport_settings (settings);
-
        account_name = modest_account_settings_get_account_name (settings);
-               
+
        /* Save the account name so we can refer to it later: */
        if (priv->account_name)
                g_free (priv->account_name);
        priv->account_name = g_strdup (account_name);
 
+       if (priv->account_name)
+               gtk_widget_show (priv->button_delete);
+       else
+               gtk_widget_hide (priv->button_delete);
+
        if (priv->settings)
                g_object_unref (priv->settings);
        priv->settings = g_object_ref (settings);
-       
+
        /* Save the account title so we can refer to it if the user changes it: */
        if (priv->original_account_title)
                g_free (priv->original_account_title);
        priv->original_account_title = g_strdup (modest_account_settings_get_display_name (settings));
-       
+
        /* Show the account data in the widgets: */
-       
+
        /* Note that we never show the non-display name in the UI.
         * (Though the display name defaults to the non-display name at the start.) */
        gtk_entry_set_text( GTK_ENTRY (priv->entry_account_title),
@@ -1104,24 +1161,16 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
                            null_means_empty (modest_account_settings_get_fullname (settings)));
        gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email), 
                            null_means_empty (modest_account_settings_get_email_address (settings)));
-       modest_limit_retrieve_picker_set_active_limit_retrieve (
-               MODEST_LIMIT_RETRIEVE_PICKER (priv->limit_retrieve_picker), 
-               modest_account_settings_get_retrieve_limit (settings));
-       
-       
+
        hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->checkbox_leave_messages), 
                                        modest_account_settings_get_leave_messages_on_server (settings));
-       
 
+       incoming_account = modest_account_settings_get_store_settings (settings);
        if (incoming_account) {
                const gchar *username, *password, *hostname, *proto_str, *account_title;
                gchar *proto_name, *title;
                ModestProtocolType incoming_protocol;
 
-               modest_retrieve_picker_fill (MODEST_RETRIEVE_PICKER (priv->retrieve_picker), modest_server_account_settings_get_protocol (incoming_account));
-               modest_retrieve_picker_set_active_retrieve_conf (MODEST_RETRIEVE_PICKER (priv->retrieve_picker), 
-                                                                modest_account_settings_get_retrieve_type (settings));
-               
                if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry,
                                                                                 modest_server_account_settings_get_protocol (incoming_account))) {
                        gtk_widget_hide (priv->checkbox_leave_messages);
@@ -1131,7 +1180,7 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
 
                /* Remember this for later: */
                incoming_protocol = modest_server_account_settings_get_protocol (incoming_account);;
-               
+
                hostname = modest_server_account_settings_get_hostname (incoming_account);
                username = modest_server_account_settings_get_username (incoming_account);
                password = modest_server_account_settings_get_password (incoming_account);
@@ -1139,7 +1188,7 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
                                    null_means_empty (username));
                gtk_entry_set_text( GTK_ENTRY (priv->entry_user_password), 
                                    null_means_empty (password));
-                       
+
                gtk_entry_set_text( GTK_ENTRY (priv->entry_incomingserver), 
                                    null_means_empty (hostname));
 
@@ -1148,24 +1197,24 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
                            MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security), 
                            settings);
                gtk_widget_show (priv->incoming_security);
-                                       
+
                /* Update the incoming label */
                update_incoming_server_title (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (dialog), 
                                              incoming_protocol);
-               
+
                /* Set window title according to account */
                proto_str = modest_protocol_get_display_name (modest_protocol_registry_get_protocol_by_type (protocol_registry, incoming_protocol));
                proto_name = g_utf8_strup (proto_str, -1);
                account_title = modest_account_settings_get_display_name(settings);
                title = g_strdup_printf(_("mcen_ti_account_settings"), proto_name, account_title);
-               
+
                gtk_window_set_title (GTK_WINDOW (dialog), title);
 
                g_free (proto_name);
                g_free (title);
                g_object_unref (incoming_account);
        }
-       
+
        outgoing_account = modest_account_settings_get_transport_settings (settings);
        if (outgoing_account) {
                const gchar *hostname;
@@ -1200,14 +1249,17 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
        /* Switch to user page */
        /* Check if we allow changes or not */
        server_account_name = modest_server_account_settings_get_account_name (incoming_account);
-       username_known = 
-               modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
-                                                                             server_account_name);
-       gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
-       gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
-       modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
-                                                    !username_known);
-
+       if (server_account_name) {
+               gboolean username_known;
+
+               username_known =
+                       modest_account_mgr_get_server_account_username_has_succeeded (priv->account_manager,
+                                                                                     server_account_name);
+               gtk_widget_set_sensitive (priv->entry_user_username, !username_known);
+               gtk_widget_set_sensitive (priv->entry_incomingserver, !username_known);
+               modest_security_options_view_enable_changes (MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
+                                                            !username_known);
+       }
 
        /* Unset the modified flag so we can detect changes later: */
        priv->modified = FALSE;
@@ -1220,8 +1272,6 @@ save_configuration (ModestDefaultAccountSettingsDialog *dialog)
        const gchar* emailaddress;
        ModestServerAccountSettings *store_settings;
        ModestServerAccountSettings *transport_settings;
-       ModestAccountRetrieveType retrieve_type;
-       gint retrieve_limit;
        gboolean leave_on_server;
        const gchar* hostname;
        const gchar* username;
@@ -1250,15 +1300,7 @@ save_configuration (ModestDefaultAccountSettingsDialog *dialog)
                modest_account_settings_set_use_signature (priv->settings, use_signature);
                modest_account_settings_set_signature (priv->settings, signature);
        }
-       
-       retrieve_type = modest_retrieve_picker_get_active_retrieve_conf (
-               MODEST_RETRIEVE_PICKER (priv->retrieve_picker));
-       modest_account_settings_set_retrieve_type (priv->settings, retrieve_type);
-       
-       retrieve_limit = modest_limit_retrieve_picker_get_active_limit_retrieve (
-               MODEST_LIMIT_RETRIEVE_PICKER (priv->limit_retrieve_picker));
-       modest_account_settings_set_retrieve_limit (priv->settings, retrieve_limit);
-       
+
        leave_on_server = hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->checkbox_leave_messages));
        modest_account_settings_set_leave_messages_on_server (priv->settings, leave_on_server); 
 
@@ -1341,10 +1383,11 @@ enable_buttons (ModestDefaultAccountSettingsDialog *self)
 {
        gboolean enable_ok = TRUE;
        ModestProtocolRegistry *protocol_registry;
+       ModestSecurityOptionsView *sec_view;
        ModestDefaultAccountSettingsDialogPrivate *priv;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
-       
+
        /* The account details title is mandatory: */
        if (entry_is_empty(priv->entry_account_title))
                enable_ok = FALSE;
@@ -1352,7 +1395,7 @@ enable_buttons (ModestDefaultAccountSettingsDialog *self)
        /* The user details username is mandatory: */
        if (enable_ok && entry_is_empty(priv->entry_user_username))
                enable_ok = FALSE;
-               
+
        /* The user details email address is mandatory: */
        if (enable_ok && entry_is_empty (priv->entry_user_email))
                enable_ok = FALSE;
@@ -1361,12 +1404,22 @@ enable_buttons (ModestDefaultAccountSettingsDialog *self)
        if (enable_ok && entry_is_empty(priv->entry_incomingserver))
                enable_ok = FALSE;
 
+       sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security);
+       if (enable_ok &&
+           modest_security_options_view_has_missing_mandatory_data (sec_view))
+               enable_ok = FALSE;
+
        /* The custom outgoing server is mandatory: */
        if (enable_ok && entry_is_empty(priv->entry_outgoingserver))
                enable_ok = FALSE;
 
+       sec_view = MODEST_SECURITY_OPTIONS_VIEW (priv->outgoing_security);
+       if (enable_ok &&
+           modest_security_options_view_has_missing_mandatory_data (sec_view))
+               enable_ok = FALSE;
+
        protocol_registry = modest_runtime_get_protocol_registry ();
-                       
+
        /* Enable the buttons, 
         * identifying them via their associated response codes:
         */