Modified webpage: now tinymail repository is in gitorious.
[modest] / src / hildon2 / modest-maemo-security-options-view.c
index a9d7d4e..87bb7e2 100644 (file)
 #include "modest-account-protocol.h"
 #include "widgets/modest-ui-constants.h"
 #include "widgets/modest-validating-entry.h"
-#include "modest-serversecurity-picker.h"
-#include "modest-secureauth-picker.h"
 #include "modest-maemo-utils.h"
-#include <modest-number-editor.h>
 #include "modest-hildon-includes.h"
+#include <modest-toolkit-factory.h>
+#include <modest-toolkit-utils.h>
 
 #define PORT_MIN 1
 #define PORT_MAX 65535
@@ -64,7 +63,9 @@ G_DEFINE_TYPE (ModestMaemoSecurityOptionsView,
 
 static void on_entry_changed (GtkEditable *editable, gpointer user_data);
 
+#ifdef MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
 static void on_valid_changed (ModestNumberEditor *editor, gboolean valid, ModestSecurityOptionsView *self);
+#endif
 
 /* Tracks changes in the incoming security picker */
 static void
@@ -72,7 +73,6 @@ on_security_changed (GtkWidget *widget,
                     ModestMaemoSecurityOptionsView *self)
 {
        ModestSecurityOptionsViewPrivate* ppriv;
-       ModestServersecurityPicker *picker;
        ModestProtocolType proto_type;
        ModestProtocolRegistry *proto_registry;
        gboolean is_secure;
@@ -80,28 +80,18 @@ on_security_changed (GtkWidget *widget,
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
 
        proto_registry = modest_runtime_get_protocol_registry ();
-       picker = MODEST_SERVERSECURITY_PICKER (ppriv->security_view);
-       proto_type = modest_serversecurity_picker_get_active_serversecurity (picker);
+       proto_type = modest_serversecurity_selector_get_active_serversecurity (ppriv->security_view);
 
        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 */
-               modest_togglable_set_active (ppriv->auth_view,
-                                            is_secure);
-               gtk_widget_set_sensitive (ppriv->auth_view, !is_secure);
-       } else {
-
-       }
-
        if (ppriv->full) {
-               gint port_number = 
-                       modest_serversecurity_picker_get_active_serversecurity_port (MODEST_SERVERSECURITY_PICKER (ppriv->security_view));
-               
+               gint port_number =
+                       modest_serversecurity_selector_get_active_serversecurity_port (ppriv->security_view);
+
                if(port_number) {
-                       modest_number_editor_set_value (MODEST_NUMBER_EDITOR (ppriv->port_view), 
-                                                       port_number);
+                       modest_number_entry_set_value (ppriv->port_view,
+                                                      port_number);
                }
        }
 }
@@ -111,7 +101,6 @@ on_auth_changed (GtkWidget *widget,
                 ModestMaemoSecurityOptionsView *self)
 {
        ModestSecurityOptionsViewPrivate* ppriv;
-       ModestSecureauthPicker *picker;
        ModestProtocolRegistry *protocol_registry;
        ModestProtocolType auth_proto;
        gboolean secureauth_used;
@@ -119,16 +108,15 @@ on_auth_changed (GtkWidget *widget,
 
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
        protocol_registry = modest_runtime_get_protocol_registry ();
-       picker = MODEST_SECUREAUTH_PICKER (ppriv->auth_view);
 
-       auth_proto = modest_secureauth_picker_get_active_secureauth (picker);
+       auth_proto = modest_secureauth_selector_get_active_secureauth (ppriv->auth_view);
        secureauth_used = modest_protocol_registry_protocol_type_is_secure (protocol_registry, 
                                                                            auth_proto);
 
        /* Get captions, well dimm the whole widget */
        user_caption = gtk_widget_get_parent (ppriv->user_entry);
        pwd_caption = gtk_widget_get_parent (ppriv->pwd_entry);
-       
+
        /* Enable / disable */
        gtk_widget_set_sensitive (user_caption, secureauth_used);
        gtk_widget_set_sensitive (pwd_caption, secureauth_used);
@@ -147,46 +135,58 @@ create_incoming_security (ModestSecurityOptionsView* self,
 
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
 
-       /* Create widgets for incoming security */
-       ppriv->security_view = GTK_WIDGET (modest_serversecurity_picker_new (MODEST_EDITABLE_SIZE,
-                                                                            HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
-       modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (ppriv->security_view), 
-                                          modest_protocol_registry_get_pop_type_id ());
-       modest_maemo_utils_set_hbutton_layout (title_size_group,
-                                              value_size_group,
-                                              _("mcen_li_emailsetup_secure_connection"), 
-                                              ppriv->security_view);
-
        ppriv->auth_view = modest_toolkit_factory_create_check_button (modest_runtime_get_toolkit_factory (),
                                                                       _("mcen_li_emailsetup_secure_authentication"));
+       gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, 0);
 
-       /* Track changes in UI */
-       g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed",
-                         G_CALLBACK (on_security_changed), self);
+       /* Create widgets for incoming security */
+       ppriv->security_view = modest_toolkit_factory_create_serversecurity_selector (modest_runtime_get_toolkit_factory ());
+       modest_serversecurity_selector_fill (ppriv->security_view,
+                                            modest_protocol_registry_get_pop_type_id ());
+       if (GTK_IS_COMBO_BOX (ppriv->security_view)) {
+               GtkWidget *captioned;
+
+               captioned = modest_toolkit_utils_create_captioned (title_size_group, value_size_group,
+                                                                  _("mcen_li_emailsetup_secure_connection"), FALSE,
+                                                                  ppriv->security_view);
+               g_signal_connect (G_OBJECT (ppriv->security_view), "changed",
+                                 G_CALLBACK (on_security_changed), self);
+               gtk_box_pack_start (GTK_BOX (self), captioned, FALSE, FALSE, 0);
+               gtk_widget_show (captioned);
+       } else {
+               modest_toolkit_utils_set_hbutton_layout (title_size_group,
+                                                        value_size_group,
+                                                        _("mcen_li_emailsetup_secure_connection"), 
+                                                        ppriv->security_view);
+               g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed",
+                                 G_CALLBACK (on_security_changed), self);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
+       }
 
        /* Pack into container & show */
-       gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, 0);
-       gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
        gtk_widget_show (ppriv->security_view);
        gtk_widget_show (ppriv->auth_view);
 
        if (ppriv->full) {
-               ppriv->port_view = GTK_WIDGET (modest_number_editor_new (PORT_MIN, PORT_MAX));
+               ppriv->port_view = modest_toolkit_factory_create_number_entry (modest_runtime_get_toolkit_factory (),
+                                                                              PORT_MIN, PORT_MAX);
                entry_caption =
-                       modest_maemo_utils_create_captioned_with_size_type (title_size_group,
-                                                                           value_size_group,
-                                                                           _("mcen_fi_emailsetup_port"),
-                                                                           FALSE,
-                                                                           ppriv->port_view,
-                                                                           MODEST_EDITABLE_SIZE);
+                       modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
+                                                                             value_size_group,
+                                                                             _("mcen_fi_emailsetup_port"),
+                                                                             FALSE,
+                                                                             ppriv->port_view,
+                                                                             MODEST_EDITABLE_SIZE);
                /* Pack & show widgets */
                gtk_box_pack_start (GTK_BOX (self), entry_caption, FALSE, FALSE, 0);
                gtk_widget_show (ppriv->port_view);
                gtk_widget_show (entry_caption);
 
                /* Track changes in UI */
+#ifdef MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
                g_signal_connect (G_OBJECT (ppriv->port_view), "valid-changed",
                                            G_CALLBACK (on_valid_changed), self);
+#endif
        }
 }
 
@@ -195,7 +195,7 @@ on_entry_max (ModestValidatingEntry *self,
              gpointer user_data)
 {
        modest_platform_information_banner (GTK_WIDGET (self), NULL, 
-                                           _CS("ckdg_ib_maximum_characters_reached"));
+                                           _CS_MAXIMUM_CHARACTERS_REACHED);
 }
 
 /*
@@ -210,7 +210,6 @@ on_entry_changed (GtkEditable *editable,
        ModestSecurityOptionsView* self;
        ModestMaemoSecurityOptionsViewPrivate *priv;
        ModestSecurityOptionsViewPrivate *ppriv;
-       ModestSecureauthPicker *picker;
        gboolean is_secure = FALSE;
        ModestProtocolRegistry *protocol_registry;
 
@@ -220,10 +219,9 @@ on_entry_changed (GtkEditable *editable,
        protocol_registry = modest_runtime_get_protocol_registry ();
 
        /* Check if it's a secure protocol */
-       if (MODEST_IS_SECUREAUTH_PICKER (ppriv->auth_view)) {
+       if (modest_is_secureauth_selector (ppriv->auth_view)) {
                ModestProtocolType auth_proto;
-               picker = MODEST_SECUREAUTH_PICKER (ppriv->auth_view);
-               auth_proto = modest_secureauth_picker_get_active_secureauth (picker);
+               auth_proto = modest_secureauth_selector_get_active_secureauth (ppriv->auth_view);
                is_secure = modest_protocol_registry_protocol_type_is_secure (protocol_registry,
                                                                              auth_proto);
        } else if (modest_is_togglable (ppriv->auth_view)) {
@@ -231,7 +229,7 @@ on_entry_changed (GtkEditable *editable,
        }
 
        if (is_secure &&
-           !g_strcmp0 (hildon_entry_get_text (HILDON_ENTRY (ppriv->user_entry)), "")) {
+           !g_strcmp0 (modest_entry_get_text (ppriv->user_entry), "")) {
                priv->missing_data = TRUE;
        } else {
                priv->missing_data = FALSE;
@@ -239,7 +237,7 @@ on_entry_changed (GtkEditable *editable,
 
        if (!priv->missing_data &&
            ppriv->full &&
-           !modest_number_editor_is_valid (MODEST_NUMBER_EDITOR (ppriv->port_view)))
+           !modest_number_entry_is_valid (ppriv->port_view))
                priv->missing_data = TRUE;
 
        /* Emit a signal to notify if mandatory data is missing */
@@ -247,6 +245,7 @@ on_entry_changed (GtkEditable *editable,
                               priv->missing_data, NULL);
 }
 
+#ifdef MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
 static void
 on_valid_changed (ModestNumberEditor *editor,
                  gboolean valid,
@@ -254,6 +253,7 @@ on_valid_changed (ModestNumberEditor *editor,
 {
        on_entry_changed (NULL, (gpointer) self);
 }
+#endif
 
 static void
 create_outgoing_security (ModestSecurityOptionsView* self,
@@ -261,28 +261,42 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                          GtkSizeGroup *value_size_group)
 {
        ModestSecurityOptionsViewPrivate *ppriv;
-       GtkWidget *user_caption = NULL;
+       GtkWidget *user_caption = NULL, *security_caption = NULL, *auth_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_picker_new (MODEST_EDITABLE_SIZE,
-                                                                            HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
-       modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (ppriv->security_view), 
+       ppriv->security_view = modest_toolkit_factory_create_serversecurity_selector (modest_runtime_get_toolkit_factory ());
+       modest_serversecurity_selector_fill (ppriv->security_view,
                                              MODEST_PROTOCOLS_TRANSPORT_SMTP);
-       modest_maemo_utils_set_hbutton_layout (title_size_group,
-                                              value_size_group,
-                                              _("mcen_li_emailsetup_secure_connection"), 
-                                              ppriv->security_view);
+       if (GTK_IS_COMBO_BOX (ppriv->security_view)) {
+               security_caption = modest_toolkit_utils_create_captioned (title_size_group, value_size_group,
+                                                                         _("mcen_li_emailsetup_secure_connection"), FALSE,
+                                                                         ppriv->security_view);
+               gtk_widget_show (security_caption);
+       } else {
+               modest_toolkit_utils_set_hbutton_layout (title_size_group,
+                                                        value_size_group,
+                                                        _("mcen_li_emailsetup_secure_connection"), 
+                                                        ppriv->security_view);
+               security_caption = ppriv->security_view;
+       }
        
        /* The secure authentication widgets */
-       ppriv->auth_view = GTK_WIDGET (modest_secureauth_picker_new (MODEST_EDITABLE_SIZE,
-                                                                    HILDON_BUTTON_ARRANGEMENT_HORIZONTAL));
-       modest_maemo_utils_set_hbutton_layout (title_size_group,
-                                              value_size_group,
-                                              _("mcen_li_emailsetup_secure_authentication"), 
-                                              ppriv->auth_view);
+       ppriv->auth_view = modest_toolkit_factory_create_secureauth_selector (modest_runtime_get_toolkit_factory ());
+       if (GTK_IS_COMBO_BOX (ppriv->auth_view)) {
+               auth_caption = modest_toolkit_utils_create_captioned (title_size_group, value_size_group,
+                                                                     _("mcen_li_emailsetup_secure_authentication"), FALSE,
+                                                                     ppriv->auth_view);
+               gtk_widget_show (auth_caption);
+       } else {
+               modest_toolkit_utils_set_hbutton_layout (title_size_group,
+                                                        value_size_group,
+                                                        _("mcen_li_emailsetup_secure_authentication"), 
+                                                        ppriv->auth_view);
+               auth_caption = ppriv->auth_view;
+       }
 
        if (ppriv->full) {
                gchar *user_label;
@@ -291,16 +305,18 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                ppriv->user_entry = GTK_WIDGET (modest_validating_entry_new ());
 
                /* Auto-capitalization is the default, so let's turn it off: */
+#ifdef MODEST_TOOLKIT_HILDON2
                hildon_gtk_entry_set_input_mode (GTK_ENTRY (ppriv->user_entry), 
                                                 HILDON_GTK_INPUT_MODE_FULL);
+#endif
 
                user_label = g_strdup_printf("%s*", _("mail_fi_username"));
-               user_caption = modest_maemo_utils_create_captioned_with_size_type (title_size_group,
-                                                                                  value_size_group,
-                                                                                  user_label,
-                                                                                  FALSE,
-                                                                                  ppriv->user_entry,
-                                                                                  MODEST_EDITABLE_SIZE);
+               user_caption = modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
+                                                                                    value_size_group,
+                                                                                    user_label,
+                                                                                    FALSE,
+                                                                                    ppriv->user_entry,
+                                                                                    MODEST_EDITABLE_SIZE);
                g_free (user_label);
        
                /* Prevent the use of some characters. Limit the max
@@ -312,62 +328,77 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                                                      on_entry_max, self);
                
                /* Password widgets */
-               ppriv->pwd_entry = hildon_entry_new (MODEST_EDITABLE_SIZE);
+               ppriv->pwd_entry = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
 
                /* Auto-capitalization is the default, so let's turn it off */
+#ifdef MODEST_TOOLKIT_HILDON2
                hildon_gtk_entry_set_input_mode (GTK_ENTRY (ppriv->pwd_entry),
                                                 HILDON_GTK_INPUT_MODE_FULL | 
                                                 HILDON_GTK_INPUT_MODE_INVISIBLE);
+#endif
                gtk_entry_set_visibility (GTK_ENTRY (ppriv->pwd_entry), FALSE);
 
                pwd_caption =
-                       modest_maemo_utils_create_captioned_with_size_type (title_size_group,
-                                                                           value_size_group,
-                                                                           _("mail_fi_password"),
-                                                                           FALSE,
-                                                                           ppriv->pwd_entry,
-                                                                           MODEST_EDITABLE_SIZE);
-
-               ppriv->port_view = GTK_WIDGET (modest_number_editor_new (PORT_MIN, PORT_MAX));
+                       modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
+                                                                             value_size_group,
+                                                                             _("mail_fi_password"),
+                                                                             FALSE,
+                                                                             ppriv->pwd_entry,
+                                                                             MODEST_EDITABLE_SIZE);
+
+               ppriv->port_view = modest_toolkit_factory_create_number_entry (modest_runtime_get_toolkit_factory (),
+                                                                              PORT_MIN, PORT_MAX);
                port_caption =
-                       modest_maemo_utils_create_captioned_with_size_type (title_size_group,
-                                                                           value_size_group,
-                                                                           _("mcen_fi_emailsetup_port"),
-                                                                           FALSE,
-                                                                           ppriv->port_view,
-                                                                           MODEST_EDITABLE_SIZE);
+                       modest_toolkit_utils_create_captioned_with_size_type (title_size_group,
+                                                                             value_size_group,
+                                                                             _("mcen_fi_emailsetup_port"),
+                                                                             FALSE,
+                                                                             ppriv->port_view,
+                                                                             MODEST_EDITABLE_SIZE);
        }
 
-       /* Track changes in UI */       
-       g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed",
-                         G_CALLBACK (on_security_changed), self);
+       /* Track changes in UI */
+       if (GTK_IS_COMBO_BOX (ppriv->security_view)) {
+               g_signal_connect (G_OBJECT (ppriv->security_view), "changed",
+                                 G_CALLBACK (on_security_changed), self);
+       } else {
+               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), "value-changed",
-                                 G_CALLBACK (on_auth_changed), self);
+               if (GTK_IS_COMBO_BOX (ppriv->auth_view)) {
+                       g_signal_connect (G_OBJECT (ppriv->auth_view), "changed",
+                                         G_CALLBACK (on_auth_changed), self);
+               } else {
+                       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);
+#ifdef MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
                g_signal_connect (G_OBJECT (ppriv->port_view), "valid-changed",
                                            G_CALLBACK (on_valid_changed), self);
+#endif
        }
 
        /* Initialize widgets */
-       modest_serversecurity_picker_set_active_serversecurity (
-               MODEST_SERVERSECURITY_PICKER (ppriv->security_view), 
+       modest_serversecurity_selector_set_active_serversecurity (
+               ppriv->security_view,
                MODEST_PROTOCOLS_CONNECTION_NONE);
-       modest_secureauth_picker_set_active_secureauth (
-          MODEST_SECUREAUTH_PICKER (ppriv->auth_view),
+       modest_secureauth_selector_set_active_secureauth (
+          ppriv->auth_view,
           MODEST_PROTOCOLS_AUTH_NONE);
 
        /* Pack into container */
        if (ppriv->full) {
-               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), auth_caption, FALSE, FALSE, 0);
                gtk_box_pack_start (GTK_BOX (self), user_caption, FALSE, FALSE, 0);
                gtk_box_pack_start (GTK_BOX (self), pwd_caption, FALSE, FALSE, 0);
-               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), security_caption, FALSE, FALSE, 0);
                gtk_box_pack_start (GTK_BOX (self), port_caption, FALSE, FALSE, 0);
        } else {
-               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, FALSE, FALSE, 0);
-               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), auth_caption, FALSE, FALSE, 0);
+               gtk_box_pack_start (GTK_BOX (self), security_caption, FALSE, FALSE, 0);
        }
 
        /* Show widgets */
@@ -439,8 +470,8 @@ modest_maemo_security_options_view_load_settings (ModestSecurityOptionsView* sel
        } else if (ppriv->full) {
                /* Keep the user-entered port-number, or the
                 * already-appropriate automatic port number */
-               modest_number_editor_set_value (MODEST_NUMBER_EDITOR (ppriv->port_view), 
-                                               port_number);
+               modest_number_entry_set_value (ppriv->port_view,
+                                              port_number);
        }
        /* Frees */
        g_object_unref (server_settings);
@@ -462,9 +493,9 @@ modest_maemo_security_options_view_save_settings (ModestSecurityOptionsView* sel
                server_settings = modest_account_settings_get_transport_settings (settings);
 
        if (ppriv->full) {
-               server_port = modest_number_editor_get_value (MODEST_NUMBER_EDITOR (ppriv->port_view));
+               server_port = modest_number_entry_get_value (ppriv->port_view);
        } else {
-               server_port = modest_serversecurity_picker_get_active_serversecurity_port (MODEST_SERVERSECURITY_PICKER (ppriv->security_view));
+               server_port = modest_serversecurity_selector_get_active_serversecurity_port (ppriv->security_view);
        }
 
        modest_server_account_settings_set_port (server_settings, server_port);
@@ -493,7 +524,7 @@ modest_maemo_security_options_view_changed (ModestSecurityOptionsView* self,
                server_settings = modest_account_settings_get_transport_settings (settings);
        
        server_port = 
-               modest_number_editor_get_value (MODEST_NUMBER_EDITOR (ppriv->port_view));
+               modest_number_entry_get_value (ppriv->port_view);
 
        /* Frees */
        g_object_unref (server_settings);