Incoming and outgoing security settings share now the same size group
[modest] / src / hildon2 / modest-default-account-settings-dialog.c
index 5ff7572..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(). */
@@ -71,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, 
@@ -104,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;
@@ -113,7 +112,6 @@ struct _ModestDefaultAccountSettingsDialogPrivate
        GtkWidget *entry_user_username;
        GtkWidget *entry_user_password;
        GtkWidget *entry_user_email;
-/*     GtkWidget *entry_incoming_port; */
        GtkWidget *button_signature;
        GtkWidget *button_delete;
        
@@ -369,27 +367,6 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self)
                on_entry_max, self);
 
        hbox = gtk_hbox_new (TRUE, 0);
-       /* The retrieve picker: */
-       priv->retrieve_picker = GTK_WIDGET (modest_retrieve_picker_new (MODEST_EDITABLE_SIZE,
-                                                                       HILDON_BUTTON_ARRANGEMENT_VERTICAL));
-       modest_maemo_utils_set_vbutton_layout (title_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 (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,
-                                                                                   HILDON_BUTTON_ARRANGEMENT_VERTICAL));
-       modest_maemo_utils_set_vbutton_layout (value_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 (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: */
        if(!priv->checkbox_leave_messages) {
@@ -441,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);
@@ -482,15 +457,13 @@ on_button_signature (GtkButton *button, gpointer user_data)
        }
 }
 
-static void
-on_button_delete (GtkButton *button, gpointer user_data)
+static gboolean
+delete_button_clicked (ModestDefaultAccountSettingsDialog *self)
 {
-       ModestDefaultAccountSettingsDialog *self;
        ModestDefaultAccountSettingsDialogPrivate *priv;
        gchar *account_title;
        gboolean removed;
 
-       self = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data);
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE (self);
 
        if (priv->modified)
@@ -503,9 +476,7 @@ on_button_delete (GtkButton *button, gpointer user_data)
                                                       (const gchar *) account_title);
        g_free (account_title);
 
-       /* Close window */
-       if (removed)
-               gtk_widget_destroy (GTK_WIDGET (self));
+       return removed;
 }
 
 static GtkWidget*
@@ -521,12 +492,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);
@@ -612,26 +585,20 @@ create_page_user_details (ModestDefaultAccountSettingsDialog *self)
        
        /* Delete button: */
        if (!priv->button_delete)
-               priv->button_delete = gtk_button_new_with_label (_HL("wdgt_bd_delete"));
-       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (self)->action_area), priv->button_delete, 
-                           FALSE, FALSE, 0);
+               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_email_signature"));
-       gtk_box_pack_start (GTK_BOX (GTK_DIALOG (self)->action_area), priv->button_signature, 
-                           FALSE, FALSE, 0);
+               priv->button_signature = gtk_dialog_add_button (GTK_DIALOG (self),
+                                                               _("mcen_bd_email_signature"),
+                                                               RESPONSE_SIGNATURE_DUMMY);
        gtk_widget_show (priv->button_signature);
 
        g_object_unref (title_sizegroup);
        g_object_unref (value_sizegroup);
-               
-       g_signal_connect (G_OBJECT (priv->button_signature), "clicked",
-               G_CALLBACK (on_button_signature), self);
-               
-       g_signal_connect (G_OBJECT (priv->button_delete), "clicked",
-               G_CALLBACK (on_button_delete), self);
-               
+
        gtk_widget_show (GTK_WIDGET (box));
 
        return GTK_WIDGET (box);
@@ -660,23 +627,19 @@ update_incoming_server_title (ModestDefaultAccountSettingsDialog *self,
        g_free (incomingserver_title);
 }
 
-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 *title_sizegroup;
-       GtkSizeGroup *value_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. */
-       title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
-       value_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);
@@ -685,11 +648,11 @@ 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, title_sizegroup, value_sizegroup,
+       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);
@@ -697,18 +660,16 @@ create_page_incoming (ModestDefaultAccountSettingsDialog *self)
        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, title_sizegroup, value_sizegroup);
-       gtk_box_pack_start (GTK_BOX (box), priv->incoming_security, 
+                                                       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 (title_sizegroup);       
-       g_object_unref (value_sizegroup);       
        gtk_widget_show (GTK_WIDGET (box));
-       
+
        return GTK_WIDGET (box);
 }
 
@@ -763,20 +724,16 @@ 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 *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)
@@ -785,7 +742,7 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
        /* 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,
+       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);
@@ -796,7 +753,8 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
        /* Outgoing security widgets */
        priv->outgoing_security = 
                modest_maemo_security_options_view_new (MODEST_SECURITY_OPTIONS_OUTGOING,
-                                                       TRUE, title_sizegroup, value_sizegroup);
+                                                       TRUE, security_title_sizegroup,
+                                                       security_value_sizegroup);
        gtk_box_pack_start (GTK_BOX (box), priv->outgoing_security, 
                            FALSE, FALSE, 0);
        gtk_widget_show (priv->outgoing_security);
@@ -833,9 +791,6 @@ create_page_outgoing (ModestDefaultAccountSettingsDialog *self)
        enable_widget_for_checkbutton (priv->button_outgoing_smtp_servers, 
                GTK_BUTTON (priv->checkbox_outgoing_smtp_specific));
 
-       g_object_unref (title_sizegroup);
-       g_object_unref (value_sizegroup);
-
        g_signal_connect (G_OBJECT (priv->button_outgoing_smtp_servers), "clicked",
                G_CALLBACK (on_button_outgoing_smtp_servers), self);
 
@@ -960,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);
 
@@ -989,7 +959,6 @@ on_response (GtkDialog *wizard_dialog,
        }
 
        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;
@@ -1044,6 +1013,7 @@ modest_default_account_settings_dialog_init (ModestDefaultAccountSettingsDialog
        GtkWidget *pannable;
        GtkWidget *separator;
        GtkWidget *align;
+       GtkSizeGroup *sec_title_sizegroup, *sec_value_sizegroup;
 
        priv = MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG_GET_PRIVATE(self);
 
@@ -1059,16 +1029,23 @@ 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),
                            priv->page_account_details,
@@ -1184,9 +1161,6 @@ 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));
@@ -1197,10 +1171,6 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo
                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);
@@ -1302,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;
@@ -1332,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);