* Fill in the incoming security options
[modest] / src / hildon2 / modest-maemo-security-options-view.c
index 5d7dbde..2038b5f 100644 (file)
 #include "modest-account-protocol.h"
 #include "widgets/modest-ui-constants.h"
 #include "widgets/modest-validating-entry.h"
-#include "widgets/modest-serversecurity-combo-box.h"
-#include "widgets/modest-secureauth-combo-box.h"
-#include "modest-easysetup-servertype-combo-box.h"
-#ifdef MODEST_HAVE_HILDON0_WIDGETS
-#include <hildon-widgets/hildon-caption.h>
-#include <hildon-widgets/hildon-number-editor.h>
-#else
-#include <hildon/hildon-caption.h>
+#include "modest-serversecurity-picker.h"
+#include "modest-secureauth-picker.h"
+#include "modest-maemo-utils.h"
 #include <hildon/hildon-number-editor.h>
-#endif /*MODEST_HAVE_HILDON0_WIDGETS*/
+#include <hildon/hildon-check-button.h>
+#include "modest-hildon-includes.h"
 
 #define PORT_MIN 1
 #define PORT_MAX 65535
 
-typedef struct _ModestMaemoSecurityOptionsViewPrivate ModestMaemoSecurityOptionsViewPrivate;
-struct _ModestMaemoSecurityOptionsViewPrivate {
-};
-
-#define MODEST_MAEMO_SECURITY_OPTIONS_VIEW_GET_PRIVATE(o) \
-       (G_TYPE_INSTANCE_GET_PRIVATE((o), \
-                                    MODEST_TYPE_MAEMO_SECURITY_OPTIONS_VIEW, \
-                                    ModestMaemoSecurityOptionsViewPrivate))
-
 static void modest_maemo_security_options_view_init (ModestMaemoSecurityOptionsView *obj);
 static void modest_maemo_security_options_view_finalize (GObject *obj);
 static void modest_maemo_security_options_view_class_init (ModestMaemoSecurityOptionsViewClass *klass);
@@ -68,13 +55,13 @@ G_DEFINE_TYPE (ModestMaemoSecurityOptionsView,
 
 static void on_entry_changed (GtkEditable *editable, gpointer user_data);
 
-/* Tracks changes in the incoming security combo box */
+/* Tracks changes in the incoming security picker */
 static void
 on_security_changed (GtkWidget *widget, 
                     ModestMaemoSecurityOptionsView *self)
 {
        ModestSecurityOptionsViewPrivate* ppriv;
-       ModestServersecurityComboBox *combo;
+       ModestServersecurityPicker *picker;
        ModestProtocolType proto_type;
        ModestProtocolRegistry *proto_registry;
        gboolean is_secure;
@@ -82,16 +69,16 @@ on_security_changed (GtkWidget *widget,
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
 
        proto_registry = modest_runtime_get_protocol_registry ();
-       combo = MODEST_SERVERSECURITY_COMBO_BOX (ppriv->security_view);
-       proto_type = modest_serversecurity_combo_box_get_active_serversecurity (combo);
+       picker = MODEST_SERVERSECURITY_PICKER (ppriv->security_view);
+       proto_type = modest_serversecurity_picker_get_active_serversecurity (picker);
 
        is_secure = modest_protocol_registry_protocol_type_has_tag (proto_registry, proto_type, 
                                                                    MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS);
 
        if (MODEST_SECURITY_OPTIONS_VIEW (self)->type == MODEST_SECURITY_OPTIONS_INCOMING) {
                /* Activate and dim checkbutton if it's secure */
-               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ppriv->auth_view), 
-                                             is_secure);
+               hildon_check_button_set_active (HILDON_CHECK_BUTTON (ppriv->auth_view), 
+                                               is_secure);
                gtk_widget_set_sensitive (ppriv->auth_view, !is_secure);
        } else {
 
@@ -99,7 +86,7 @@ on_security_changed (GtkWidget *widget,
 
        if (ppriv->full) {
                gint port_number = 
-                       modest_serversecurity_combo_box_get_active_serversecurity_port (MODEST_SERVERSECURITY_COMBO_BOX (ppriv->security_view));
+                       modest_serversecurity_picker_get_active_serversecurity_port (MODEST_SERVERSECURITY_PICKER (ppriv->security_view));
                
                if(port_number) {
                        hildon_number_editor_set_value (HILDON_NUMBER_EDITOR (ppriv->port_view), 
@@ -113,7 +100,7 @@ on_auth_changed (GtkWidget *widget,
                 ModestMaemoSecurityOptionsView *self)
 {
        ModestSecurityOptionsViewPrivate* ppriv;
-       ModestSecureauthComboBox *combo;
+       ModestSecureauthPicker *picker;
        ModestProtocolRegistry *protocol_registry;
        ModestProtocolType auth_proto;
        gboolean secureauth_used;
@@ -121,9 +108,9 @@ on_auth_changed (GtkWidget *widget,
 
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
        protocol_registry = modest_runtime_get_protocol_registry ();
-       combo = MODEST_SECUREAUTH_COMBO_BOX (ppriv->auth_view);
+       picker = MODEST_SECUREAUTH_PICKER (ppriv->auth_view);
 
-       auth_proto = modest_secureauth_combo_box_get_active_secureauth (combo);
+       auth_proto = modest_secureauth_picker_get_active_secureauth (picker);
        secureauth_used = modest_protocol_registry_protocol_type_is_secure (protocol_registry, 
                                                                            auth_proto);
 
@@ -144,39 +131,40 @@ create_incoming_security (ModestSecurityOptionsView* self,
                          GtkSizeGroup *size_group)
 {
        ModestSecurityOptionsViewPrivate *ppriv;
-       GtkWidget *combo_caption, *check_caption, *entry_caption = NULL;
+       GtkWidget *entry_caption = NULL;
 
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
 
        /* Create widgets for incoming security */
-       ppriv->security_view = GTK_WIDGET (modest_serversecurity_combo_box_new ());
-       combo_caption = hildon_caption_new (size_group, _("mcen_li_emailsetup_secure_connection"),
-                                           ppriv->security_view, NULL, 
-                                           HILDON_CAPTION_OPTIONAL);
+       ppriv->security_view = GTK_WIDGET (modest_serversecurity_picker_new (MODEST_EDITABLE_SIZE,
+                                                                            MODEST_EDITABLE_ARRANGEMENT));
+       modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (ppriv->security_view), 
+                                          modest_protocol_registry_get_pop_type_id ());
+       modest_maemo_utils_create_picker_layout (size_group, 
+                                                _("mcen_li_emailsetup_secure_connection"), 
+                                                ppriv->security_view);
 
        if (ppriv->full) {              
                ppriv->port_view = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
-               entry_caption = hildon_caption_new (size_group, _("mcen_fi_emailsetup_port"), 
-                                                   ppriv->port_view, NULL, 
-                                                   HILDON_CAPTION_OPTIONAL);
+               entry_caption = modest_maemo_utils_create_captioned (size_group, _("mcen_fi_emailsetup_port"), 
+                                                                    ppriv->port_view);
        }
 
-       ppriv->auth_view = gtk_check_button_new ();
-       check_caption = 
-               hildon_caption_new (size_group, _("mcen_li_emailsetup_secure_authentication"),
-                                   ppriv->auth_view, NULL, HILDON_CAPTION_OPTIONAL);
+       ppriv->auth_view = hildon_check_button_new (MODEST_EDITABLE_SIZE);
+       gtk_button_set_label (GTK_BUTTON (ppriv->auth_view), _("mcen_li_emailsetup_secure_authentication"));
+       gtk_size_group_add_widget (size_group, ppriv->auth_view);
 
        /* Track changes in UI */       
-       g_signal_connect (G_OBJECT (ppriv->security_view), "changed",
+       g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed",
                          G_CALLBACK (on_security_changed), self);
 
        /* Pack into container */
-       gtk_box_pack_start (GTK_BOX (self), combo_caption,
+       gtk_box_pack_start (GTK_BOX (self), ppriv->security_view,
                            FALSE, FALSE, MODEST_MARGIN_HALF);
        if (ppriv->full)
                gtk_box_pack_start (GTK_BOX (self), entry_caption, 
                                    FALSE, FALSE, MODEST_MARGIN_HALF);
-       gtk_box_pack_start (GTK_BOX (self), check_caption,
+       gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view,
                            FALSE, FALSE, MODEST_MARGIN_HALF);
 
        /* Show widgets */
@@ -186,8 +174,6 @@ create_incoming_security (ModestSecurityOptionsView* self,
        }
        gtk_widget_show (ppriv->security_view);
        gtk_widget_show (ppriv->auth_view);
-       gtk_widget_show (combo_caption);
-       gtk_widget_show (check_caption);
 }
 
 static void
@@ -199,7 +185,7 @@ on_entry_max (ModestValidatingEntry *self,
 }
 
 /*
- * TODO: call this whenever the auth combo changes. If we set it
+ * TODO: call this whenever the auth picker changes. If we set it
  * explicitely at the beggining to a value then there is no need to
  * call this handler directly at the beginning
  */
@@ -210,7 +196,7 @@ on_entry_changed (GtkEditable *editable,
        ModestSecurityOptionsView* self;
        ModestSecurityOptionsViewPrivate *ppriv;
        ModestProtocolType auth_proto;
-       ModestSecureauthComboBox *combo;
+       ModestSecureauthPicker *picker;
        gboolean is_secure, missing;
        ModestProtocolRegistry *protocol_registry;
 
@@ -219,8 +205,8 @@ on_entry_changed (GtkEditable *editable,
        protocol_registry = modest_runtime_get_protocol_registry ();
 
        /* Outgoing username is mandatory if outgoing auth is secure */
-       combo = MODEST_SECUREAUTH_COMBO_BOX (ppriv->auth_view);
-       auth_proto = modest_secureauth_combo_box_get_active_secureauth (combo);
+       picker = MODEST_SECUREAUTH_PICKER (ppriv->auth_view);
+       auth_proto = modest_secureauth_picker_get_active_secureauth (picker);
        is_secure = modest_protocol_registry_protocol_type_is_secure (protocol_registry, 
                                                                      auth_proto);
 
@@ -241,22 +227,24 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                          GtkSizeGroup *size_group)
 {
        ModestSecurityOptionsViewPrivate *ppriv;
-       GtkWidget *sec_caption, *auth_caption, *user_caption = NULL;
+       GtkWidget *user_caption = NULL;
        GtkWidget *pwd_caption = NULL, *port_caption = NULL;
 
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
        
        /* The secure connection widgets */
-       ppriv->security_view = GTK_WIDGET (modest_serversecurity_combo_box_new ());
-       modest_serversecurity_combo_box_fill (MODEST_SERVERSECURITY_COMBO_BOX (ppriv->security_view), 
+       ppriv->security_view = GTK_WIDGET (modest_serversecurity_picker_new (MODEST_EDITABLE_SIZE,
+                                                                            MODEST_EDITABLE_ARRANGEMENT));
+       modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (ppriv->security_view), 
                                              MODEST_PROTOCOLS_TRANSPORT_SMTP);
-       sec_caption = hildon_caption_new (size_group, _("mcen_li_emailsetup_secure_connection"),
-                                     ppriv->security_view, NULL, HILDON_CAPTION_OPTIONAL);
+       modest_maemo_utils_create_picker_layout (size_group, _("mcen_li_emailsetup_secure_connection"), 
+                                                ppriv->security_view);
        
        /* The secure authentication widgets */
-       ppriv->auth_view = GTK_WIDGET (modest_secureauth_combo_box_new ());
-       auth_caption = hildon_caption_new (size_group, _("mcen_li_emailsetup_secure_authentication"),
-                                          ppriv->auth_view, NULL, HILDON_CAPTION_OPTIONAL);
+       ppriv->auth_view = GTK_WIDGET (modest_secureauth_picker_new (MODEST_EDITABLE_SIZE,
+                                                                    MODEST_EDITABLE_ARRANGEMENT));
+       modest_maemo_utils_create_picker_layout (size_group, _("mcen_li_emailsetup_secure_authentication"), 
+                                                ppriv->auth_view);
 
        if (ppriv->full) {
                gchar *user_label;
@@ -269,9 +257,8 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                                                 HILDON_GTK_INPUT_MODE_FULL);
 
                user_label = g_strdup_printf("%s*", _("mail_fi_username"));
-               user_caption = hildon_caption_new (size_group, user_label, 
-                                                  ppriv->user_entry, NULL, 
-                                                  HILDON_CAPTION_MANDATORY);
+               user_caption = modest_maemo_utils_create_captioned (size_group, user_label, 
+                                                                   ppriv->user_entry);
                g_free (user_label);
        
                /* Prevent the use of some characters. Limit the max
@@ -291,45 +278,43 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                                                 HILDON_GTK_INPUT_MODE_INVISIBLE);
                gtk_entry_set_visibility (GTK_ENTRY (ppriv->pwd_entry), FALSE);
 
-               pwd_caption = hildon_caption_new (size_group, _("mail_fi_password"), 
-                                                 ppriv->pwd_entry, NULL, 
-                                                 HILDON_CAPTION_OPTIONAL);
+               pwd_caption = modest_maemo_utils_create_captioned (size_group, _("mail_fi_password"), 
+                                                                  ppriv->pwd_entry);
 
                ppriv->port_view = GTK_WIDGET (hildon_number_editor_new (PORT_MIN, PORT_MAX));
-               port_caption = hildon_caption_new (size_group, _("mcen_fi_emailsetup_port"), 
-                                                   ppriv->port_view, NULL, 
-                                                   HILDON_CAPTION_OPTIONAL);
+               port_caption = modest_maemo_utils_create_captioned (size_group, _("mcen_fi_emailsetup_port"), 
+                                                                   ppriv->port_view);
        }
 
        /* Track changes in UI */       
-       g_signal_connect (G_OBJECT (ppriv->security_view), "changed",
+       g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed",
                          G_CALLBACK (on_security_changed), self);
        if (ppriv->full) {
-               g_signal_connect (G_OBJECT (ppriv->auth_view), "changed",
+               g_signal_connect (G_OBJECT (ppriv->auth_view), "value-changed",
                                  G_CALLBACK (on_auth_changed), self);
                g_signal_connect (G_OBJECT (ppriv->user_entry), "changed",
                                  G_CALLBACK (on_entry_changed), self);
        }
 
        /* Initialize widgets */
-       modest_serversecurity_combo_box_set_active_serversecurity (
-               MODEST_SERVERSECURITY_COMBO_BOX (ppriv->security_view), 
+       modest_serversecurity_picker_set_active_serversecurity (
+               MODEST_SERVERSECURITY_PICKER (ppriv->security_view), 
                MODEST_PROTOCOLS_CONNECTION_NONE);
-       modest_secureauth_combo_box_set_active_secureauth (
-          MODEST_SECUREAUTH_COMBO_BOX (ppriv->auth_view),
+       modest_secureauth_picker_set_active_secureauth (
+          MODEST_SECUREAUTH_PICKER (ppriv->auth_view),
           MODEST_PROTOCOLS_AUTH_NONE);
 
        /* Pack into container */
        if (ppriv->full) {
-               gtk_box_pack_start (GTK_BOX (self), auth_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, MODEST_MARGIN_HALF);
                gtk_box_pack_start (GTK_BOX (self), user_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
                gtk_box_pack_start (GTK_BOX (self), pwd_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-               gtk_box_pack_start (GTK_BOX (self), sec_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, MODEST_MARGIN_HALF);
                gtk_box_pack_start (GTK_BOX (self), port_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
        } else {
                /* The order is different */
-               gtk_box_pack_start (GTK_BOX (self), sec_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
-               gtk_box_pack_start (GTK_BOX (self), auth_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, MODEST_MARGIN_HALF);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, MODEST_MARGIN_HALF);
        }
 
        /* Show widgets */
@@ -343,8 +328,6 @@ create_outgoing_security (ModestSecurityOptionsView* self,
        }
        gtk_widget_show (ppriv->security_view);
        gtk_widget_show (ppriv->auth_view);
-       gtk_widget_show (sec_caption);
-       gtk_widget_show (auth_caption);
 }
 
 GtkWidget *    
@@ -417,7 +400,7 @@ modest_maemo_security_options_view_save_settings (ModestSecurityOptionsView* sel
        if (ppriv->full) {
                server_port = hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (ppriv->port_view));
        } else {
-               server_port = modest_serversecurity_combo_box_get_active_serversecurity_port (MODEST_SERVERSECURITY_COMBO_BOX (ppriv->security_view));
+               server_port = modest_serversecurity_picker_get_active_serversecurity_port (MODEST_SERVERSECURITY_PICKER (ppriv->security_view));
        }
 
        modest_server_account_settings_set_port (server_settings, server_port);
@@ -476,7 +459,6 @@ modest_maemo_security_options_view_class_init (ModestMaemoSecurityOptionsViewCla
 
        modest_maemo_security_options_view_parent_class = g_type_class_peek_parent (klass);
 
-       g_type_class_add_private (gobject_class, sizeof (ModestMaemoSecurityOptionsViewPrivate));
        gobject_class->finalize = modest_maemo_security_options_view_finalize;
 
        MODEST_SECURITY_OPTIONS_VIEW_CLASS (klass)->load_settings =