Fixes NB#112513, show the proper account title when opening folders window from notif...
[modest] / src / hildon2 / modest-default-account-settings-dialog.c
index 8bcab9c..ae5b991 100644 (file)
@@ -173,9 +173,6 @@ modest_default_account_settings_dialog_finalize (GObject *object)
        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;
@@ -343,7 +340,7 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
                                               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, 
@@ -380,7 +377,7 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
 
        gtk_widget_show (priv->retrieve_picker);
        connect_for_modified (self, priv->retrieve_picker);
-       gtk_box_pack_start (GTK_BOX (hbox), priv->retrieve_picker, TRUE, TRUE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (hbox), priv->retrieve_picker, TRUE, TRUE, 0);
 
        /* The limit-retrieve picker: */
        priv->limit_retrieve_picker = GTK_WIDGET (modest_limit_retrieve_picker_new (MODEST_EDITABLE_SIZE,
@@ -390,8 +387,8 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
                                               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 (hbox), priv->limit_retrieve_picker, TRUE, TRUE, MODEST_MARGIN_HALF);
-       gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, MODEST_MARGIN_HALF);
+       gtk_box_pack_start (GTK_BOX (hbox), priv->limit_retrieve_picker, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (box), hbox, FALSE, FALSE, 0);
        gtk_widget_show (hbox);
 
        /* The leave-messages widgets: */
@@ -403,7 +400,7 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
                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 (title_sizegroup);
@@ -496,7 +493,10 @@ on_button_delete (GtkButton *button, gpointer user_data)
        self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
 
-       account_title = get_entered_account_title (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, 
@@ -521,12 +521,14 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
        box = gtk_vbox_new (FALSE, MODEST_MARGIN_NONE);
        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);
@@ -537,7 +539,7 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
                                  _("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);
 
 
@@ -561,7 +563,7 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
                                    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, 
@@ -589,7 +591,7 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
                                    _("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: */        
@@ -601,7 +603,7 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
        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:
@@ -646,7 +648,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);
@@ -654,16 +655,11 @@ 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* 
@@ -699,7 +695,7 @@ create_page_incoming (ModestDefaultAccountSettingsDialog *self)
                                                   "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 */
@@ -707,7 +703,7 @@ create_page_incoming (ModestDefaultAccountSettingsDialog *self)
                modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_INCOMING,
                                                        TRUE, title_sizegroup, value_sizegroup);
        gtk_box_pack_start (GTK_BOX (box), priv->incoming_security, 
-                           FALSE, FALSE, MODEST_MARGIN_HALF);
+                           FALSE, FALSE, 0);
 
        gtk_widget_show (priv->incoming_security);
 
@@ -735,7 +731,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);
 }
@@ -753,10 +749,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
@@ -774,27 +769,30 @@ static GtkWidget*
 create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
 {
        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 *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
        GtkSizeGroup *value_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);
+       smtp_caption_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
        GtkWidget *caption = create_captioned (self, title_sizegroup, value_sizegroup,
-                                              _("mcen_li_emailsetup_smtp"), FALSE, priv->entry_outgoingserver);
+                                              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 */
@@ -802,13 +800,13 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
                modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
                                                        TRUE, title_sizegroup, 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: */
@@ -822,7 +820,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
        }
        gtk_widget_show (priv->checkbox_outgoing_smtp_specific);
        gtk_box_pack_start (GTK_BOX (box), priv->checkbox_outgoing_smtp_specific, 
-                           FALSE, FALSE, MODEST_MARGIN_HALF);
+                           FALSE, FALSE, 0);
        connect_for_modified (self, priv->checkbox_outgoing_smtp_specific);
 
        /* Connection-specific SMTP-Severs Edit button: */
@@ -831,7 +829,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
        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), priv->button_outgoing_smtp_servers, FALSE, FALSE, MODEST_MARGIN_HALF);
+       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, 
@@ -1047,13 +1045,14 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
        ModestDefaultAccountSettingsDialogPrivate *priv;
        GtkWidget *pannable;
        GtkWidget *separator;
+       GtkWidget *align;
 
        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, 
@@ -1082,14 +1081,14 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
 
        separator = gtk_hseparator_new ();
        gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
-                           FALSE, FALSE, 0);
+                           FALSE, FALSE, MODEST_MARGIN_DEFAULT);
        gtk_widget_show (separator);
        gtk_box_pack_start (GTK_BOX (priv->main_container),
                            priv->page_incoming,
                            FALSE, FALSE, 0);
        separator = gtk_hseparator_new ();
        gtk_box_pack_start (GTK_BOX (priv->main_container), separator,
-                           FALSE, FALSE, 0);
+                           FALSE, FALSE, MODEST_MARGIN_DEFAULT);
        gtk_widget_show (separator);
        gtk_box_pack_start (GTK_BOX (priv->main_container),
                            priv->page_outgoing,
@@ -1098,16 +1097,21 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
        GtkDialog *dialog = GTK_DIALOG (self);
        pannable = hildon_pannable_area_new ();
        g_object_set (G_OBJECT (pannable), "initial-hint", TRUE, NULL);
-       hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), priv->main_container);
+
+       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), _HL("wdgt_bd_save"), GTK_RESPONSE_OK);
 
-    gtk_window_set_default_size (GTK_WINDOW (self), -1, 340);
+    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); 
@@ -1144,7 +1148,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));
@@ -1152,11 +1155,8 @@ 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);
@@ -1170,14 +1170,14 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
        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),
@@ -1189,12 +1189,11 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
        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;
@@ -1203,7 +1202,7 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
                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);
@@ -1213,7 +1212,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);
@@ -1221,7 +1220,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));
 
@@ -1230,24 +1229,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;
@@ -1282,14 +1281,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;
@@ -1423,10 +1425,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;
@@ -1434,7 +1437,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;
@@ -1443,12 +1446,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:
         */