Do not disable editing authentication method checkbox if the connection protocol...
[modest] / src / hildon2 / modest-maemo-security-options-view.c
index 0d244cd..90a9e66 100644 (file)
@@ -65,6 +65,8 @@ G_DEFINE_TYPE (ModestMaemoSecurityOptionsView,
 
 static void on_entry_changed (GtkEditable *editable, gpointer user_data);
 
+static void on_valid_changed (ModestNumberEditor *editor, gboolean valid, ModestSecurityOptionsView *self);
+
 /* Tracks changes in the incoming security picker */
 static void
 on_security_changed (GtkWidget *widget, 
@@ -85,19 +87,10 @@ on_security_changed (GtkWidget *widget,
        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 */
-               hildon_check_button_set_active (HILDON_CHECK_BUTTON (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));
-               
+
                if(port_number) {
                        modest_number_editor_set_value (MODEST_NUMBER_EDITOR (ppriv->port_view), 
                                                        port_number);
@@ -127,7 +120,7 @@ on_auth_changed (GtkWidget *widget,
        /* 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);
@@ -151,7 +144,7 @@ create_incoming_security (ModestSecurityOptionsView* self,
                                                                             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, 
+       modest_maemo_utils_set_hbutton_layout (title_size_group,
                                               value_size_group,
                                               _("mcen_li_emailsetup_secure_connection"), 
                                               ppriv->security_view);
@@ -172,15 +165,21 @@ create_incoming_security (ModestSecurityOptionsView* self,
 
        if (ppriv->full) {
                ppriv->port_view = GTK_WIDGET (modest_number_editor_new (PORT_MIN, PORT_MAX));
-               entry_caption = modest_maemo_utils_create_captioned (title_size_group,
-                                                                    value_size_group,
-                                                                    _("mcen_fi_emailsetup_port"),
-                                                                    FALSE,
-                                                                    ppriv->port_view);
+               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);
                /* 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 */
+               g_signal_connect (G_OBJECT (ppriv->port_view), "valid-changed",
+                                           G_CALLBACK (on_valid_changed), self);
        }
 }
 
@@ -204,9 +203,8 @@ on_entry_changed (GtkEditable *editable,
        ModestSecurityOptionsView* self;
        ModestMaemoSecurityOptionsViewPrivate *priv;
        ModestSecurityOptionsViewPrivate *ppriv;
-       ModestProtocolType auth_proto;
        ModestSecureauthPicker *picker;
-       gboolean is_secure;
+       gboolean is_secure = FALSE;
        ModestProtocolRegistry *protocol_registry;
 
        self = MODEST_SECURITY_OPTIONS_VIEW (user_data);
@@ -214,14 +212,19 @@ on_entry_changed (GtkEditable *editable,
        ppriv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
        protocol_registry = modest_runtime_get_protocol_registry ();
 
-       /* Outgoing username is mandatory if outgoing auth is secure */
-       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);
+       /* Check if it's a secure protocol */
+       if (MODEST_IS_SECUREAUTH_PICKER (ppriv->auth_view)) {
+               ModestProtocolType auth_proto;
+               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);
+       } else if (HILDON_IS_CHECK_BUTTON (ppriv->auth_view)) {
+               is_secure = hildon_check_button_get_active (HILDON_CHECK_BUTTON (ppriv->auth_view));
+       }
 
        if (is_secure &&
-           !g_ascii_strcasecmp (hildon_entry_get_text (HILDON_ENTRY (ppriv->user_entry)), "")) {
+           !g_strcmp0 (hildon_entry_get_text (HILDON_ENTRY (ppriv->user_entry)), "")) {
                priv->missing_data = TRUE;
        } else {
                priv->missing_data = FALSE;
@@ -237,7 +240,7 @@ on_entry_changed (GtkEditable *editable,
                               priv->missing_data, NULL);
 }
 
-void
+static void
 on_valid_changed (ModestNumberEditor *editor,
                  gboolean valid,
                  ModestSecurityOptionsView *self)
@@ -285,11 +288,12 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                                                 HILDON_GTK_INPUT_MODE_FULL);
 
                user_label = g_strdup_printf("%s*", _("mail_fi_username"));
-               user_caption = modest_maemo_utils_create_captioned (title_size_group,
-                                                                   value_size_group,
-                                                                   user_label,
-                                                                   FALSE,
-                                                                   ppriv->user_entry);
+               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);
                g_free (user_label);
        
                /* Prevent the use of some characters. Limit the max
@@ -309,18 +313,22 @@ create_outgoing_security (ModestSecurityOptionsView* self,
                                                 HILDON_GTK_INPUT_MODE_INVISIBLE);
                gtk_entry_set_visibility (GTK_ENTRY (ppriv->pwd_entry), FALSE);
 
-               pwd_caption = modest_maemo_utils_create_captioned (title_size_group,
-                                                                  value_size_group,
-                                                                  _("mail_fi_password"), 
-                                                                  FALSE,
-                                                                  ppriv->pwd_entry);
+               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));
-               port_caption = modest_maemo_utils_create_captioned (title_size_group,
-                                                                   value_size_group,
-                                                                   _("mcen_fi_emailsetup_port"), 
-                                                                   FALSE,
-                                                                   ppriv->port_view);
+               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);
        }
 
        /* Track changes in UI */       
@@ -345,14 +353,14 @@ create_outgoing_security (ModestSecurityOptionsView* self,
 
        /* Pack into container */
        if (ppriv->full) {
-               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), ppriv->security_view, FALSE, FALSE, MODEST_MARGIN_HALF);
-               gtk_box_pack_start (GTK_BOX (self), port_caption, FALSE, FALSE, MODEST_MARGIN_HALF);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, 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), port_caption, FALSE, FALSE, 0);
        } else {
-               gtk_box_pack_start (GTK_BOX (self), ppriv->auth_view, 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, 0);
+               gtk_box_pack_start (GTK_BOX (self), ppriv->security_view, FALSE, FALSE, 0);
        }
 
        /* Show widgets */