[gnome-control-center] network: Move EAPMethod property to a virtual method



commit 2e8226a09c9e380e8804c74507f151794900a06b
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Nov 7 10:03:25 2019 +1300

    network: Move EAPMethod property to a virtual method

 panels/network/wireless-security/eap-method-fast.c  |  8 +++++++-
 panels/network/wireless-security/eap-method-leap.c  | 14 ++++++++++----
 panels/network/wireless-security/eap-method-peap.c  |  8 +++++++-
 .../network/wireless-security/eap-method-simple.c   | 12 +++++++++---
 panels/network/wireless-security/eap-method-tls.c   | 21 +++++++++++++++------
 panels/network/wireless-security/eap-method-ttls.c  |  8 +++++++-
 panels/network/wireless-security/eap-method.c       | 15 ++++++++++++++-
 panels/network/wireless-security/eap-method.h       |  7 +++++--
 .../network/wireless-security/wireless-security.c   |  2 +-
 9 files changed, 75 insertions(+), 20 deletions(-)
---
diff --git a/panels/network/wireless-security/eap-method-fast.c 
b/panels/network/wireless-security/eap-method-fast.c
index f1cbabdff..5f3fc5ad1 100644
--- a/panels/network/wireless-security/eap-method-fast.c
+++ b/panels/network/wireless-security/eap-method-fast.c
@@ -289,6 +289,12 @@ get_default_field (EAPMethod *parent)
        return GTK_WIDGET (self->anon_identity_entry);
 }
 
+static const gchar *
+get_password_flags_name (EAPMethod *parent)
+{
+       return NM_SETTING_802_1X_PASSWORD;
+}
+
 static void
 pac_toggled_cb (EAPMethodFAST *self)
 {
@@ -327,12 +333,12 @@ eap_method_fast_new (WirelessSecurity *ws_parent,
                                  update_secrets,
                                  get_widget,
                                  get_default_field,
+                                 get_password_flags_name,
                                  destroy,
                                  FALSE);
        if (!parent)
                return NULL;
 
-       parent->password_flags_name = NM_SETTING_802_1X_PASSWORD;
        self = (EAPMethodFAST *) parent;
        self->sec_parent = ws_parent;
        self->is_editor = is_editor;
diff --git a/panels/network/wireless-security/eap-method-leap.c 
b/panels/network/wireless-security/eap-method-leap.c
index 6d1791d88..f33a41dea 100644
--- a/panels/network/wireless-security/eap-method-leap.c
+++ b/panels/network/wireless-security/eap-method-leap.c
@@ -109,13 +109,13 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
 
        /* Save 802.1X password flags to the connection */
        secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->password_entry));
-       nm_setting_set_secret_flags (NM_SETTING (s_8021x), parent->password_flags_name,
+       nm_setting_set_secret_flags (NM_SETTING (s_8021x), NM_SETTING_802_1X_PASSWORD,
                                     secret_flags, NULL);
 
        /* Update secret flags and popup when editing the connection */
        if (self->editing_connection)
                nma_utils_update_password_storage (GTK_WIDGET (self->password_entry), secret_flags,
-                                                  NM_SETTING (s_8021x), parent->password_flags_name);
+                                                  NM_SETTING (s_8021x), NM_SETTING_802_1X_PASSWORD);
 }
 
 static void
@@ -142,6 +142,12 @@ get_default_field (EAPMethod *parent)
        return GTK_WIDGET (self->username_entry);
 }
 
+static const gchar *
+get_password_flags_name (EAPMethod *parent)
+{
+       return NM_SETTING_802_1X_PASSWORD;
+}
+
 /* Set the UI fields for user, password and show_password to the
  * values as provided by self->ws_parent. */
 static void
@@ -211,12 +217,12 @@ eap_method_leap_new (WirelessSecurity *ws_parent,
                                  update_secrets,
                                  get_widget,
                                  get_default_field,
+                                 get_password_flags_name,
                                  destroy,
                                  FALSE);
        if (!parent)
                return NULL;
 
-       parent->password_flags_name = NM_SETTING_802_1X_PASSWORD;
        self = (EAPMethodLEAP *) parent;
        self->editing_connection = secrets_only ? FALSE : TRUE;
        self->ws_parent = ws_parent;
@@ -247,7 +253,7 @@ eap_method_leap_new (WirelessSecurity *ws_parent,
        /* Create password-storage popup menu for password entry under entry's secondary icon */
        if (connection)
                s_8021x = nm_connection_get_setting_802_1x (connection);
-       nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) s_8021x, 
parent->password_flags_name,
+       nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) s_8021x, 
NM_SETTING_802_1X_PASSWORD,
                                          FALSE, secrets_only);
 
        g_signal_connect_swapped (self->show_password_check, "toggled", G_CALLBACK (show_toggled_cb), self);
diff --git a/panels/network/wireless-security/eap-method-peap.c 
b/panels/network/wireless-security/eap-method-peap.c
index 17619dbd0..3514c4911 100644
--- a/panels/network/wireless-security/eap-method-peap.c
+++ b/panels/network/wireless-security/eap-method-peap.c
@@ -309,6 +309,12 @@ get_default_field (EAPMethod *parent)
        return GTK_WIDGET (self->anon_identity_entry);
 }
 
+static const gchar *
+get_password_flags_name (EAPMethod *parent)
+{
+       return NM_SETTING_802_1X_PASSWORD;
+}
+
 static void
 changed_cb (EAPMethodPEAP *self)
 {
@@ -335,12 +341,12 @@ eap_method_peap_new (WirelessSecurity *ws_parent,
                                  update_secrets,
                                  get_widget,
                                  get_default_field,
+                                 get_password_flags_name,
                                  destroy,
                                  FALSE);
        if (!parent)
                return NULL;
 
-       parent->password_flags_name = NM_SETTING_802_1X_PASSWORD;
        self = (EAPMethodPEAP *) parent;
        self->sec_parent = ws_parent;
        self->is_editor = is_editor;
diff --git a/panels/network/wireless-security/eap-method-simple.c 
b/panels/network/wireless-security/eap-method-simple.c
index e0f513e65..594e95640 100644
--- a/panels/network/wireless-security/eap-method-simple.c
+++ b/panels/network/wireless-security/eap-method-simple.c
@@ -178,7 +178,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
        /* Update secret flags and popup when editing the connection */
        if (!(self->flags & EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY)) {
                nma_utils_update_password_storage (GTK_WIDGET (self->password_entry), flags,
-                                                  NM_SETTING (s_8021x), parent->password_flags_name);
+                                                  NM_SETTING (s_8021x), NM_SETTING_802_1X_PASSWORD);
        }
 }
 
@@ -206,6 +206,12 @@ get_default_field (EAPMethod *parent)
        return GTK_WIDGET (self->username_entry);
 }
 
+static const gchar *
+get_password_flags_name (EAPMethod *parent)
+{
+       return NM_SETTING_802_1X_PASSWORD;
+}
+
 static gboolean
 stuff_changed (EAPMethodSimple *self)
 {
@@ -308,12 +314,12 @@ eap_method_simple_new (WirelessSecurity *ws_parent,
                                  update_secrets,
                                  get_widget,
                                  get_default_field,
+                                 get_password_flags_name,
                                  destroy,
                                  flags & EAP_METHOD_SIMPLE_FLAG_PHASE2);
        if (!parent)
                return NULL;
 
-       parent->password_flags_name = NM_SETTING_802_1X_PASSWORD;
        self = (EAPMethodSimple *) parent;
        self->ws_parent = ws_parent;
        self->flags = flags;
@@ -346,7 +352,7 @@ eap_method_simple_new (WirelessSecurity *ws_parent,
        /* Create password-storage popup menu for password entry under entry's secondary icon */
        if (connection)
                s_8021x = nm_connection_get_setting_802_1x (connection);
-       nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) s_8021x, 
parent->password_flags_name,
+       nma_utils_setup_password_storage (GTK_WIDGET (self->password_entry), 0, (NMSetting *) s_8021x, 
NM_SETTING_802_1X_PASSWORD,
                                          FALSE, flags & EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY);
 
        g_signal_connect_swapped (self->password_entry, "notify::secondary-icon-name", G_CALLBACK 
(password_storage_changed), self);
diff --git a/panels/network/wireless-security/eap-method-tls.c 
b/panels/network/wireless-security/eap-method-tls.c
index 6c3fb8cea..58550a82d 100644
--- a/panels/network/wireless-security/eap-method-tls.c
+++ b/panels/network/wireless-security/eap-method-tls.c
@@ -50,6 +50,7 @@ struct _EAPMethodTLS {
        GtkFileChooserButton *user_cert_button;
        GtkLabel             *user_cert_label;
 
+       const gchar *password_flags_name;
        WirelessSecurity *sec_parent;
        gboolean editing_connection;
 };
@@ -196,13 +197,13 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
 
        /* Save 802.1X password flags to the connection */
        secret_flags = nma_utils_menu_to_secret_flags (GTK_WIDGET (self->private_key_password_entry));
-       nm_setting_set_secret_flags (NM_SETTING (s_8021x), parent->password_flags_name,
+       nm_setting_set_secret_flags (NM_SETTING (s_8021x), self->password_flags_name,
                                     secret_flags, NULL);
 
        /* Update secret flags and popup when editing the connection */
        if (self->editing_connection) {
                nma_utils_update_password_storage (GTK_WIDGET (self->private_key_password_entry), 
secret_flags,
-                                                  NM_SETTING (s_8021x), parent->password_flags_name);
+                                                  NM_SETTING (s_8021x), self->password_flags_name);
        }
 
        /* TLS client certificate */
@@ -418,6 +419,13 @@ get_default_field (EAPMethod *parent)
        return GTK_WIDGET (self->identity_entry);
 }
 
+static const gchar *
+get_password_flags_name (EAPMethod *parent)
+{
+       EAPMethodTLS *self = (EAPMethodTLS *) parent;
+       return self->password_flags_name;
+}
+
 EAPMethodTLS *
 eap_method_tls_new (WirelessSecurity *ws_parent,
                     NMConnection *connection,
@@ -437,15 +445,16 @@ eap_method_tls_new (WirelessSecurity *ws_parent,
                                  update_secrets,
                                  get_widget,
                                  get_default_field,
+                                 get_password_flags_name,
                                  destroy,
                                  phase2);
        if (!parent)
                return NULL;
 
-       parent->password_flags_name = phase2 ?
-                                       NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD :
-                                       NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD;
        self = (EAPMethodTLS *) parent;
+       self->password_flags_name = phase2 ?
+                                   NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD :
+                                   NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD;
        self->sec_parent = ws_parent;
        self->editing_connection = secrets_only ? FALSE : TRUE;
 
@@ -508,7 +517,7 @@ eap_method_tls_new (WirelessSecurity *ws_parent,
        g_signal_connect_swapped (self->private_key_password_entry, "changed", G_CALLBACK (changed_cb), self);
 
        /* Create password-storage popup menu for password entry under entry's secondary icon */
-       nma_utils_setup_password_storage (GTK_WIDGET (self->private_key_password_entry), 0, (NMSetting *) 
s_8021x, parent->password_flags_name,
+       nma_utils_setup_password_storage (GTK_WIDGET (self->private_key_password_entry), 0, (NMSetting *) 
s_8021x, self->password_flags_name,
                                          FALSE, secrets_only);
 
        g_signal_connect_swapped (self->show_password_check, "toggled", G_CALLBACK (show_toggled_cb), self);
diff --git a/panels/network/wireless-security/eap-method-ttls.c 
b/panels/network/wireless-security/eap-method-ttls.c
index e2e20c11c..8295357f5 100644
--- a/panels/network/wireless-security/eap-method-ttls.c
+++ b/panels/network/wireless-security/eap-method-ttls.c
@@ -362,6 +362,12 @@ get_default_field (EAPMethod *parent)
        return GTK_WIDGET (self->anon_identity_entry);
 }
 
+static const gchar *
+get_password_flags_name (EAPMethod *parent)
+{
+       return NM_SETTING_802_1X_PASSWORD;
+}
+
 static void
 changed_cb (EAPMethodTTLS *self)
 {
@@ -388,12 +394,12 @@ eap_method_ttls_new (WirelessSecurity *ws_parent,
                                  update_secrets,
                                  get_widget,
                                  get_default_field,
+                                 get_password_flags_name,
                                  destroy,
                                  FALSE);
        if (!parent)
                return NULL;
 
-       parent->password_flags_name = NM_SETTING_802_1X_PASSWORD;
        self = (EAPMethodTTLS *) parent;
        self->sec_parent = ws_parent;
        self->is_editor = is_editor;
diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c
index 4444f8557..721b80cea 100644
--- a/panels/network/wireless-security/eap-method.c
+++ b/panels/network/wireless-security/eap-method.c
@@ -63,6 +63,17 @@ eap_method_get_default_field (EAPMethod *self)
        return self->get_default_field (self);
 }
 
+const gchar *
+eap_method_get_password_flags_name (EAPMethod *self)
+{
+       g_return_val_if_fail (self != NULL, NULL);
+
+       if (self->get_password_flags_name)
+               return self->get_password_flags_name (self);
+       else
+               return NULL;
+}
+
 gboolean
 eap_method_validate (EAPMethod *self, GError **error)
 {
@@ -133,6 +144,7 @@ eap_method_init (gsize obj_size,
                  EMUpdateSecretsFunc update_secrets,
                  EMGetWidgetFunc get_widget,
                  EMGetWidgetFunc get_default_field,
+                 EMGetStringFunc get_password_flags_name,
                  EMDestroyFunc destroy,
                  gboolean phase2)
 {
@@ -151,8 +163,9 @@ eap_method_init (gsize obj_size,
        self->update_secrets = update_secrets;
        self->get_widget = get_widget;
        self->get_default_field = get_default_field;
-       self->phase2 = phase2;
+       self->get_password_flags_name = get_password_flags_name;
        self->destroy = destroy;
+       self->phase2 = phase2;
 
        return g_steal_pointer (&self);
 }
diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h
index 5ef1a9692..bd8875a8c 100644
--- a/panels/network/wireless-security/eap-method.h
+++ b/panels/network/wireless-security/eap-method.h
@@ -33,13 +33,12 @@ typedef void        (*EMUpdateSecretsFunc)  (EAPMethod *method, NMConnection *co
 typedef void        (*EMDestroyFunc)        (EAPMethod *method);
 typedef gboolean    (*EMValidateFunc)       (EAPMethod *method, GError **error);
 typedef GtkWidget*  (*EMGetWidgetFunc)      (EAPMethod *method);
+typedef const gchar* (*EMGetStringFunc)     (EAPMethod *method);
 
 struct _EAPMethod {
        guint32 refcount;
        gsize obj_size;
 
-       const char *password_flags_name;
-
        gboolean phase2;
 
        EMAddToSizeGroupFunc add_to_size_group;
@@ -48,6 +47,7 @@ struct _EAPMethod {
        EMValidateFunc validate;
        EMGetWidgetFunc get_widget;
        EMGetWidgetFunc get_default_field;
+       EMGetStringFunc get_password_flags_name;
        EMDestroyFunc destroy;
 };
 
@@ -58,6 +58,8 @@ GtkWidget *eap_method_get_widget (EAPMethod *method);
 
 GtkWidget *eap_method_get_default_field (EAPMethod *method);
 
+const gchar *eap_method_get_password_flags_name (EAPMethod *method);
+
 gboolean eap_method_validate (EAPMethod *method, GError **error);
 
 void eap_method_add_to_size_group (EAPMethod *method, GtkSizeGroup *group);
@@ -81,6 +83,7 @@ EAPMethod *eap_method_init (gsize obj_size,
                             EMUpdateSecretsFunc update_secrets,
                             EMGetWidgetFunc get_widget,
                             EMGetWidgetFunc get_default_field,
+                            EMGetStringFunc get_password_flags_name,
                             EMDestroyFunc destroy,
                             gboolean phase2);
 
diff --git a/panels/network/wireless-security/wireless-security.c 
b/panels/network/wireless-security/wireless-security.c
index 99c9c9b8d..e8c4a7a27 100644
--- a/panels/network/wireless-security/wireless-security.c
+++ b/panels/network/wireless-security/wireless-security.c
@@ -525,7 +525,7 @@ ws_802_1x_fill_connection (GtkComboBox *combo,
        /* Get previous pasword flags, if any. Otherwise default to agent-owned secrets */
        s_8021x = nm_connection_get_setting_802_1x (connection);
        if (s_8021x)
-               nm_setting_get_secret_flags (NM_SETTING (s_8021x), eap->password_flags_name, &secret_flags, 
NULL);
+               nm_setting_get_secret_flags (NM_SETTING (s_8021x), eap_method_get_password_flags_name (eap), 
&secret_flags, NULL);
        else
                secret_flags = NM_SETTING_SECRET_FLAG_AGENT_OWNED;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]