From 0189d5001fd126f2353d36e170f07efcd0b7ba50 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 15:43:51 +1300 Subject: [PATCH 01/39] network: Make function for common code --- .../wireless-security/wireless-security.c | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index d671c278b5..d5897299b9 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -360,20 +360,31 @@ wireless_security_clear_ciphers (NMConnection *connection) nm_setting_wireless_security_clear_groups (s_wireless_sec); } +static EAPMethod * +get_active_method (GtkComboBox *combo) +{ + GtkTreeModel *model; + GtkTreeIter iter; + EAPMethod *eap; + + model = gtk_combo_box_get_model (combo); + if (!gtk_combo_box_get_active_iter (combo, &iter)) + return NULL; + + gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); + return eap; +} + void ws_802_1x_add_to_size_group (GtkSizeGroup *size_group, GtkLabel *label, GtkComboBox *combo) { - GtkTreeModel *model; - GtkTreeIter iter; g_autoptr(EAPMethod) eap = NULL; gtk_size_group_add_widget (size_group, GTK_WIDGET (label)); - model = gtk_combo_box_get_model (combo); - gtk_combo_box_get_active_iter (combo, &iter); - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); + eap = get_active_method (combo); g_assert (eap); eap_method_add_to_size_group (eap, size_group); } @@ -381,14 +392,10 @@ ws_802_1x_add_to_size_group (GtkSizeGroup *size_group, gboolean ws_802_1x_validate (GtkComboBox *combo, GError **error) { - GtkTreeModel *model; - GtkTreeIter iter; g_autoptr(EAPMethod) eap = NULL; gboolean valid = FALSE; - model = gtk_combo_box_get_model (combo); - gtk_combo_box_get_active_iter (combo, &iter); - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); + eap = get_active_method (combo); g_assert (eap); valid = eap_method_validate (eap, error); return valid; @@ -402,8 +409,6 @@ ws_802_1x_auth_combo_changed (GtkWidget *combo, { g_autoptr(EAPMethod) eap = NULL; GList *elt, *children; - GtkTreeModel *model; - GtkTreeIter iter; GtkWidget *eap_widget; GtkWidget *eap_default_widget = NULL; @@ -412,9 +417,7 @@ ws_802_1x_auth_combo_changed (GtkWidget *combo, for (elt = children; elt; elt = g_list_next (elt)) gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data)); - model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo)); - gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter); - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); + eap = get_active_method (GTK_COMBO_BOX (combo)); g_assert (eap); eap_widget = eap_method_get_widget (eap); @@ -580,13 +583,9 @@ ws_802_1x_fill_connection (GtkComboBox *combo, NMSetting8021x *s_8021x; NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; g_autoptr(EAPMethod) eap = NULL; - GtkTreeModel *model; - GtkTreeIter iter; /* Get the EAPMethod object */ - model = gtk_combo_box_get_model (combo); - gtk_combo_box_get_active_iter (combo, &iter); - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); + eap = get_active_method (combo); g_assert (eap); /* Get previous pasword flags, if any. Otherwise default to agent-owned secrets */ -- GitLab From f2111a85f54886c304b411fb4eb609979a392aeb Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 09:56:00 +1300 Subject: [PATCH 02/39] network: Simplify helper function --- .../wireless-security/wireless-security.c | 11 +--------- .../wireless-security/wireless-security.h | 4 +--- .../wireless-security/ws-dynamic-wep.c | 20 ++++++++++--------- panels/network/wireless-security/ws-wpa-eap.c | 20 ++++++++++--------- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index d5897299b9..199cd1f779 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -402,7 +402,7 @@ ws_802_1x_validate (GtkComboBox *combo, GError **error) } void -ws_802_1x_auth_combo_changed (GtkWidget *combo, +ws_802_1x_auth_combo_changed (GtkComboBox *combo, WirelessSecurity *self, GtkBox *vbox, GtkSizeGroup *size_group) @@ -441,8 +441,6 @@ ws_802_1x_auth_combo_changed (GtkWidget *combo, void ws_802_1x_auth_combo_init (WirelessSecurity *self, GtkComboBox *combo, - GtkLabel *label, - GCallback auth_combo_changed_cb, NMConnection *connection, gboolean is_editor, gboolean secrets_only) @@ -566,13 +564,6 @@ ws_802_1x_auth_combo_init (WirelessSecurity *self, gtk_combo_box_set_model (combo, GTK_TREE_MODEL (auth_model)); gtk_combo_box_set_active (combo, active < 0 ? 0 : (guint32) active); - - g_signal_connect (G_OBJECT (combo), "changed", auth_combo_changed_cb, self); - - if (secrets_only) { - gtk_widget_hide (GTK_WIDGET (combo)); - gtk_widget_hide (GTK_WIDGET (label)); - } } void diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 065a8fc8e9..6db979a1d4 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -111,13 +111,11 @@ void wireless_security_clear_ciphers (NMConnection *connection); void ws_802_1x_auth_combo_init (WirelessSecurity *sec, GtkComboBox *combo, - GtkLabel *label, - GCallback auth_combo_changed_cb, NMConnection *connection, gboolean is_editor, gboolean secrets_only); -void ws_802_1x_auth_combo_changed (GtkWidget *combo, +void ws_802_1x_auth_combo_changed (GtkComboBox *combo, WirelessSecurity *sec, GtkBox *vbox, GtkSizeGroup *size_group); diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index 46fa9eda1d..85ff5502ef 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -88,13 +88,10 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) } static void -auth_combo_changed_cb (GtkWidget *combo, gpointer user_data) +auth_combo_changed_cb (WirelessSecurityDynamicWEP *self) { - WirelessSecurity *parent = WIRELESS_SECURITY (user_data); - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; - - ws_802_1x_auth_combo_changed (combo, - parent, + ws_802_1x_auth_combo_changed (self->auth_combo, + WIRELESS_SECURITY (self), self->method_box, self->size_group); } @@ -128,12 +125,17 @@ ws_dynamic_wep_new (NMConnection *connection, ws_802_1x_auth_combo_init (parent, self->auth_combo, - self->auth_label, - (GCallback) auth_combo_changed_cb, connection, is_editor, secrets_only); - auth_combo_changed_cb (GTK_WIDGET (self->auth_combo), (gpointer) parent); + + if (secrets_only) { + gtk_widget_hide (GTK_WIDGET (self->auth_combo)); + gtk_widget_hide (GTK_WIDGET (self->auth_label)); + } + + g_signal_connect_object (G_OBJECT (self->auth_combo), "changed", G_CALLBACK (auth_combo_changed_cb), self, G_CONNECT_SWAPPED); + auth_combo_changed_cb (self); return self; } diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 02c5eb26be..f090c7a13a 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -89,13 +89,10 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) } static void -auth_combo_changed_cb (GtkWidget *combo, gpointer user_data) +auth_combo_changed_cb (WirelessSecurityWPAEAP *self) { - WirelessSecurity *parent = WIRELESS_SECURITY (user_data); - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; - - ws_802_1x_auth_combo_changed (combo, - parent, + ws_802_1x_auth_combo_changed (self->auth_combo, + WIRELESS_SECURITY (self), self->method_box, self->size_group); } @@ -129,12 +126,17 @@ ws_wpa_eap_new (NMConnection *connection, ws_802_1x_auth_combo_init (parent, self->auth_combo, - self->auth_label, - (GCallback) auth_combo_changed_cb, connection, is_editor, secrets_only); - auth_combo_changed_cb (GTK_WIDGET (self->auth_combo), parent); + + if (secrets_only) { + gtk_widget_hide (GTK_WIDGET (self->auth_combo)); + gtk_widget_hide (GTK_WIDGET (self->auth_label)); + } + + g_signal_connect_object (G_OBJECT (self->auth_combo), "changed", G_CALLBACK (auth_combo_changed_cb), self, G_CONNECT_SWAPPED); + auth_combo_changed_cb (self); return self; } -- GitLab From 69a5b8750bc1823a1ee9a055aa0029c388874d91 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 15:34:51 +1300 Subject: [PATCH 03/39] network: Simplify helper function --- panels/network/wireless-security/wireless-security.c | 3 --- panels/network/wireless-security/wireless-security.h | 1 - panels/network/wireless-security/ws-dynamic-wep.c | 3 ++- panels/network/wireless-security/ws-wpa-eap.c | 3 ++- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index 199cd1f779..1c7106b95d 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -377,13 +377,10 @@ get_active_method (GtkComboBox *combo) void ws_802_1x_add_to_size_group (GtkSizeGroup *size_group, - GtkLabel *label, GtkComboBox *combo) { g_autoptr(EAPMethod) eap = NULL; - gtk_size_group_add_widget (size_group, GTK_WIDGET (label)); - eap = get_active_method (combo); g_assert (eap); eap_method_add_to_size_group (eap, size_group); diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 6db979a1d4..97570906d9 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -123,7 +123,6 @@ void ws_802_1x_auth_combo_changed (GtkComboBox *combo, gboolean ws_802_1x_validate (GtkComboBox *combo, GError **error); void ws_802_1x_add_to_size_group (GtkSizeGroup *size_group, - GtkLabel *label, GtkComboBox *combo); void ws_802_1x_fill_connection (GtkComboBox *combo, diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index 85ff5502ef..c04ff5e010 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -70,7 +70,8 @@ add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) g_clear_object (&self->size_group); self->size_group = g_object_ref (group); - ws_802_1x_add_to_size_group (self->size_group, self->auth_label, self->auth_combo); + gtk_size_group_add_widget (self->size_group, GTK_WIDGET (self->auth_label)); + ws_802_1x_add_to_size_group (self->size_group, self->auth_combo); } static void diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index f090c7a13a..86b5665827 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -71,7 +71,8 @@ add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) g_clear_object (&self->size_group); self->size_group = g_object_ref (group); - ws_802_1x_add_to_size_group (self->size_group, self->auth_label, self->auth_combo); + gtk_size_group_add_widget (self->size_group, GTK_WIDGET (self->auth_label)); + ws_802_1x_add_to_size_group (self->size_group, self->auth_combo); } static void -- GitLab From 08b26a93a75c90e2f040adb6cd07fa1a853c2281 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 16:17:58 +1300 Subject: [PATCH 04/39] network: Simplify helper functions --- .../wireless-security/wireless-security.c | 37 ++++--------------- .../wireless-security/wireless-security.h | 5 +-- .../wireless-security/ws-dynamic-wep.c | 4 +- panels/network/wireless-security/ws-wpa-eap.c | 4 +- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index 1c7106b95d..d1c92797b8 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -360,12 +360,12 @@ wireless_security_clear_ciphers (NMConnection *connection) nm_setting_wireless_security_clear_groups (s_wireless_sec); } -static EAPMethod * -get_active_method (GtkComboBox *combo) +EAPMethod * +ws_802_1x_auth_combo_get_eap (GtkComboBox *combo) { GtkTreeModel *model; GtkTreeIter iter; - EAPMethod *eap; + g_autoptr(EAPMethod) eap = NULL; model = gtk_combo_box_get_model (combo); if (!gtk_combo_box_get_active_iter (combo, &iter)) @@ -375,36 +375,13 @@ get_active_method (GtkComboBox *combo) return eap; } -void -ws_802_1x_add_to_size_group (GtkSizeGroup *size_group, - GtkComboBox *combo) -{ - g_autoptr(EAPMethod) eap = NULL; - - eap = get_active_method (combo); - g_assert (eap); - eap_method_add_to_size_group (eap, size_group); -} - -gboolean -ws_802_1x_validate (GtkComboBox *combo, GError **error) -{ - g_autoptr(EAPMethod) eap = NULL; - gboolean valid = FALSE; - - eap = get_active_method (combo); - g_assert (eap); - valid = eap_method_validate (eap, error); - return valid; -} - void ws_802_1x_auth_combo_changed (GtkComboBox *combo, WirelessSecurity *self, GtkBox *vbox, GtkSizeGroup *size_group) { - g_autoptr(EAPMethod) eap = NULL; + EAPMethod *eap; GList *elt, *children; GtkWidget *eap_widget; GtkWidget *eap_default_widget = NULL; @@ -414,7 +391,7 @@ ws_802_1x_auth_combo_changed (GtkComboBox *combo, for (elt = children; elt; elt = g_list_next (elt)) gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data)); - eap = get_active_method (GTK_COMBO_BOX (combo)); + eap = ws_802_1x_auth_combo_get_eap (GTK_COMBO_BOX (combo)); g_assert (eap); eap_widget = eap_method_get_widget (eap); @@ -570,10 +547,10 @@ ws_802_1x_fill_connection (GtkComboBox *combo, NMSettingWirelessSecurity *s_wireless_sec; NMSetting8021x *s_8021x; NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE; - g_autoptr(EAPMethod) eap = NULL; + EAPMethod *eap; /* Get the EAPMethod object */ - eap = get_active_method (combo); + eap = ws_802_1x_auth_combo_get_eap (combo); g_assert (eap); /* Get previous pasword flags, if any. Otherwise default to agent-owned secrets */ diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 97570906d9..272eb76719 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -120,10 +120,9 @@ void ws_802_1x_auth_combo_changed (GtkComboBox *combo, GtkBox *vbox, GtkSizeGroup *size_group); -gboolean ws_802_1x_validate (GtkComboBox *combo, GError **error); +#include "eap-method.h" -void ws_802_1x_add_to_size_group (GtkSizeGroup *size_group, - GtkComboBox *combo); +EAPMethod *ws_802_1x_auth_combo_get_eap (GtkComboBox *combo); void ws_802_1x_fill_connection (GtkComboBox *combo, NMConnection *connection); diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index c04ff5e010..d48357ba8b 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -59,7 +59,7 @@ static gboolean validate (WirelessSecurity *parent, GError **error) { WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; - return ws_802_1x_validate (self->auth_combo, error); + return eap_method_validate (ws_802_1x_auth_combo_get_eap (self->auth_combo), error); } static void @@ -71,7 +71,7 @@ add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) self->size_group = g_object_ref (group); gtk_size_group_add_widget (self->size_group, GTK_WIDGET (self->auth_label)); - ws_802_1x_add_to_size_group (self->size_group, self->auth_combo); + eap_method_add_to_size_group (ws_802_1x_auth_combo_get_eap (self->auth_combo), self->size_group); } static void diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 86b5665827..9d1d35b584 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -60,7 +60,7 @@ static gboolean validate (WirelessSecurity *parent, GError **error) { WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; - return ws_802_1x_validate (self->auth_combo, error); + return eap_method_validate (ws_802_1x_auth_combo_get_eap (self->auth_combo), error); } static void @@ -72,7 +72,7 @@ add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) self->size_group = g_object_ref (group); gtk_size_group_add_widget (self->size_group, GTK_WIDGET (self->auth_label)); - ws_802_1x_add_to_size_group (self->size_group, self->auth_combo); + eap_method_add_to_size_group (ws_802_1x_auth_combo_get_eap (self->auth_combo), self->size_group); } static void -- GitLab From 1c2d2ca79bebc23a07f8c99d59d451bcd720c06a Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 16:23:59 +1300 Subject: [PATCH 05/39] network: Simplify helper --- panels/network/wireless-security/wireless-security.c | 3 --- panels/network/wireless-security/wireless-security.h | 1 - panels/network/wireless-security/ws-dynamic-wep.c | 3 ++- panels/network/wireless-security/ws-wpa-eap.c | 3 ++- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index d1c92797b8..e109683e45 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -377,7 +377,6 @@ ws_802_1x_auth_combo_get_eap (GtkComboBox *combo) void ws_802_1x_auth_combo_changed (GtkComboBox *combo, - WirelessSecurity *self, GtkBox *vbox, GtkSizeGroup *size_group) { @@ -408,8 +407,6 @@ ws_802_1x_auth_combo_changed (GtkComboBox *combo, if (eap_default_widget) gtk_widget_grab_focus (eap_default_widget); } - - wireless_security_notify_changed (WIRELESS_SECURITY (self)); } void diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 272eb76719..d8f9211f53 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -116,7 +116,6 @@ void ws_802_1x_auth_combo_init (WirelessSecurity *sec, gboolean secrets_only); void ws_802_1x_auth_combo_changed (GtkComboBox *combo, - WirelessSecurity *sec, GtkBox *vbox, GtkSizeGroup *size_group); diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index d48357ba8b..739b295918 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -92,9 +92,10 @@ static void auth_combo_changed_cb (WirelessSecurityDynamicWEP *self) { ws_802_1x_auth_combo_changed (self->auth_combo, - WIRELESS_SECURITY (self), self->method_box, self->size_group); + + wireless_security_notify_changed (WIRELESS_SECURITY (self)); } WirelessSecurityDynamicWEP * diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 9d1d35b584..489295bba9 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -93,9 +93,10 @@ static void auth_combo_changed_cb (WirelessSecurityWPAEAP *self) { ws_802_1x_auth_combo_changed (self->auth_combo, - WIRELESS_SECURITY (self), self->method_box, self->size_group); + + wireless_security_notify_changed (WIRELESS_SECURITY (self)); } WirelessSecurityWPAEAP * -- GitLab From ac566aaaf3e8d24915f2c38c5825a9c218ae7d74 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 09:45:22 +1300 Subject: [PATCH 06/39] network: Remove unused function --- .../wireless-security/wireless-security.c | 25 ------------------- .../wireless-security/wireless-security.h | 4 --- 2 files changed, 29 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index e109683e45..5750047fd3 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -567,28 +567,3 @@ ws_802_1x_fill_connection (GtkComboBox *combo, eap_method_fill_connection (eap, connection, secret_flags); } - -void -ws_802_1x_update_secrets (GtkComboBox *combo, - NMConnection *connection) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - g_return_if_fail (combo != NULL); - g_return_if_fail (connection != NULL); - - model = gtk_combo_box_get_model (combo); - - /* Let each EAP method try to update its secrets */ - if (gtk_tree_model_get_iter_first (model, &iter)) { - do { - g_autoptr(EAPMethod) eap = NULL; - - gtk_tree_model_get (model, &iter, AUTH_METHOD_COLUMN, &eap, -1); - if (eap) - eap_method_update_secrets (eap, connection); - } while (gtk_tree_model_iter_next (model, &iter)); - } -} - diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index d8f9211f53..15424ac2cd 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -126,10 +126,6 @@ EAPMethod *ws_802_1x_auth_combo_get_eap (GtkComboBox *combo); void ws_802_1x_fill_connection (GtkComboBox *combo, NMConnection *connection); -void ws_802_1x_update_secrets (GtkComboBox *combo, - NMConnection *connection); - G_DEFINE_AUTOPTR_CLEANUP_FUNC (WirelessSecurity, wireless_security_unref) #endif /* WIRELESS_SECURITY_H */ - -- GitLab From 13211f9f4d3f0ed114d5f1ef1297c467f585f8c6 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 10:05:00 +1300 Subject: [PATCH 07/39] network: Remove unused variable --- panels/network/wireless-security/eap-method.h | 1 - 1 file changed, 1 deletion(-) diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index 9f2f898b0d..695b0fdc51 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -44,7 +44,6 @@ struct _EAPMethod { const char *password_flags_name; gboolean phase2; - gboolean secrets_only; EMAddToSizeGroupFunc add_to_size_group; EMFillConnectionFunc fill_connection; -- GitLab From 08b922f09da28698cc24f9332554673deafd4a6e Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 13:41:23 +1300 Subject: [PATCH 08/39] network: Merge public method that is only used internally once --- .../wireless-security/wireless-security.c | 44 +++++++------------ .../wireless-security/wireless-security.h | 2 - 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index 5750047fd3..6909283a24 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -319,32 +319,6 @@ wireless_security_set_userpass (WirelessSecurity *self, priv->show_password = show_password; } -void -wireless_security_set_userpass_802_1x (WirelessSecurity *self, - NMConnection *connection) -{ - const char *user = NULL, *password = NULL; - gboolean always_ask = FALSE, show_password = FALSE; - NMSetting8021x *setting; - NMSettingSecretFlags flags; - - if (!connection) - goto set; - - setting = nm_connection_get_setting_802_1x (connection); - if (!setting) - goto set; - - user = nm_setting_802_1x_get_identity (setting); - password = nm_setting_802_1x_get_password (setting); - - if (nm_setting_get_secret_flags (NM_SETTING (setting), NM_SETTING_802_1X_PASSWORD, &flags, NULL)) - always_ask = !!(flags & NM_SETTING_SECRET_FLAG_NOT_SAVED); - -set: - wireless_security_set_userpass (self, user, password, always_ask, show_password); -} - void wireless_security_clear_ciphers (NMConnection *connection) { @@ -416,6 +390,8 @@ ws_802_1x_auth_combo_init (WirelessSecurity *self, gboolean is_editor, gboolean secrets_only) { + const gchar *user = NULL, *password = NULL; + gboolean always_ask = FALSE; g_autoptr(GtkListStore) auth_model = NULL; GtkTreeIter iter; g_autoptr(EAPMethodTLS) em_tls = NULL; @@ -446,7 +422,21 @@ ws_802_1x_auth_combo_init (WirelessSecurity *self, } /* initialize WirelessSecurity userpass from connection (clear if no connection) */ - wireless_security_set_userpass_802_1x (self, connection); + if (connection) { + NMSetting8021x *setting; + + setting = nm_connection_get_setting_802_1x (connection); + if (setting) { + NMSettingSecretFlags flags; + + user = nm_setting_802_1x_get_identity (setting); + password = nm_setting_802_1x_get_password (setting); + + if (nm_setting_get_secret_flags (NM_SETTING (setting), NM_SETTING_802_1X_PASSWORD, &flags, NULL)) + always_ask = !!(flags & NM_SETTING_SECRET_FLAG_NOT_SAVED); + } + } + wireless_security_set_userpass (self, user, password, always_ask, FALSE); auth_model = gtk_list_store_new (2, G_TYPE_STRING, eap_method_get_type ()); diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 15424ac2cd..ea2d56ba46 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -83,8 +83,6 @@ void wireless_security_set_userpass (WirelessSecurity *sec, const char *password, gboolean always_ask, gboolean show_password); -void wireless_security_set_userpass_802_1x (WirelessSecurity *sec, - NMConnection *connection); WirelessSecurity *wireless_security_ref (WirelessSecurity *sec); -- GitLab From 0478abe46cca7c6a4c8bd78a56bd02bdc643d07f Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 13:39:21 +1300 Subject: [PATCH 09/39] network: Remove unused hotspot_compatible property --- .../wireless-security/wireless-security.c | 22 ------------------- .../wireless-security/wireless-security.h | 5 ----- .../wireless-security/ws-dynamic-wep.c | 1 - panels/network/wireless-security/ws-leap.c | 1 - panels/network/wireless-security/ws-wpa-eap.c | 1 - 5 files changed, 30 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index 6909283a24..d67f3d7606 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -35,7 +35,6 @@ struct _WirelessSecurityPrivate { WSChangedFunc changed_notify; gpointer changed_notify_data; gboolean adhoc_compatible; - gboolean hotspot_compatible; char *username, *password; gboolean always_ask, show_password; @@ -211,7 +210,6 @@ wireless_security_init (gsize obj_size, priv->destroy = destroy; priv->adhoc_compatible = TRUE; - priv->hotspot_compatible = TRUE; return g_steal_pointer (&self); } @@ -236,26 +234,6 @@ wireless_security_adhoc_compatible (WirelessSecurity *self) return priv->adhoc_compatible; } -void -wireless_security_set_hotspot_compatible (WirelessSecurity *self, gboolean hotspot_compatible) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_if_fail (self != NULL); - - priv->hotspot_compatible = hotspot_compatible; -} - -gboolean -wireless_security_hotspot_compatible (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_val_if_fail (self != NULL, FALSE); - - return priv->hotspot_compatible; -} - const gchar * wireless_security_get_username (WirelessSecurity *self) { diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index ea2d56ba46..3c581e07f9 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -65,11 +65,6 @@ void wireless_security_set_adhoc_compatible (WirelessSecurity *sec, gboolean wireless_security_adhoc_compatible (WirelessSecurity *sec); -void wireless_security_set_hotspot_compatible (WirelessSecurity *sec, - gboolean hotspot_compatible); - -gboolean wireless_security_hotspot_compatible (WirelessSecurity *sec); - const gchar *wireless_security_get_username (WirelessSecurity *sec); const gchar *wireless_security_get_password (WirelessSecurity *sec); diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index 739b295918..cba45c2c2a 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -123,7 +123,6 @@ ws_dynamic_wep_new (NMConnection *connection, self->method_box = GTK_BOX (gtk_builder_get_object (parent->builder, "method_box")); wireless_security_set_adhoc_compatible (parent, FALSE); - wireless_security_set_hotspot_compatible (parent, FALSE); ws_802_1x_auth_combo_init (parent, self->auth_combo, diff --git a/panels/network/wireless-security/ws-leap.c b/panels/network/wireless-security/ws-leap.c index 0e5ef7c72b..6e555f9c2a 100644 --- a/panels/network/wireless-security/ws-leap.c +++ b/panels/network/wireless-security/ws-leap.c @@ -175,7 +175,6 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only) } wireless_security_set_adhoc_compatible (parent, FALSE); - wireless_security_set_hotspot_compatible (parent, FALSE); self = (WirelessSecurityLEAP *) parent; self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD; diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 489295bba9..9eebee6170 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -124,7 +124,6 @@ ws_wpa_eap_new (NMConnection *connection, self->method_box = GTK_BOX (gtk_builder_get_object (parent->builder, "method_box")); wireless_security_set_adhoc_compatible (parent, FALSE); - wireless_security_set_hotspot_compatible (parent, FALSE); ws_802_1x_auth_combo_init (parent, self->auth_combo, -- GitLab From 71785b9109bcbb92ea01b273dfd300af93349d13 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 09:47:39 +1300 Subject: [PATCH 10/39] network: Make a method private --- panels/network/wireless-security/eap-method.c | 14 ++------------ panels/network/wireless-security/eap-method.h | 2 -- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c index 2030e954ac..34a2a0cb45 100644 --- a/panels/network/wireless-security/eap-method.c +++ b/panels/network/wireless-security/eap-method.c @@ -91,16 +91,6 @@ eap_method_fill_connection (EAPMethod *self, return (*(self->fill_connection)) (self, connection, flags); } -void -eap_method_update_secrets (EAPMethod *self, NMConnection *connection) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (connection != NULL); - - if (self->update_secrets) - self->update_secrets (self, connection); -} - void eap_method_phase2_update_secrets_helper (EAPMethod *self, NMConnection *connection, @@ -121,8 +111,8 @@ eap_method_phase2_update_secrets_helper (EAPMethod *self, g_autoptr(EAPMethod) eap = NULL; gtk_tree_model_get (model, &iter, column, &eap, -1); - if (eap) - eap_method_update_secrets (eap, connection); + if (eap && eap->update_secrets) + eap->update_secrets (self, connection); } while (gtk_tree_model_iter_next (model, &iter)); } } diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index 695b0fdc51..dc3c35b8d2 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -65,8 +65,6 @@ void eap_method_fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); -void eap_method_update_secrets (EAPMethod *method, NMConnection *connection); - EAPMethod *eap_method_ref (EAPMethod *method); void eap_method_unref (EAPMethod *method); -- GitLab From 6d35ec3160716de11a582bd4c23cc9a249b12fad Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 10:10:21 +1300 Subject: [PATCH 11/39] network: Fix up header includes --- panels/network/wireless-security/eap-method-fast.c | 2 ++ panels/network/wireless-security/eap-method-leap.c | 1 + panels/network/wireless-security/eap-method-peap.c | 2 ++ panels/network/wireless-security/eap-method-simple.c | 1 + panels/network/wireless-security/eap-method-tls.c | 1 + panels/network/wireless-security/eap-method-ttls.c | 2 ++ panels/network/wireless-security/eap-method.h | 7 ------- panels/network/wireless-security/wireless-security.c | 6 ++++++ 8 files changed, 15 insertions(+), 7 deletions(-) diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index 858c049cb8..ebfaa52471 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -26,6 +26,8 @@ #include #include "eap-method.h" +#include "eap-method-fast.h" +#include "eap-method-simple.h" #include "wireless-security.h" #include "utils.h" #include "helpers.h" diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index 48cede21bf..c8de02b05c 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -26,6 +26,7 @@ #include #include "eap-method.h" +#include "eap-method-leap.h" #include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" diff --git a/panels/network/wireless-security/eap-method-peap.c b/panels/network/wireless-security/eap-method-peap.c index a70aaccced..b2a6029f9c 100644 --- a/panels/network/wireless-security/eap-method-peap.c +++ b/panels/network/wireless-security/eap-method-peap.c @@ -26,6 +26,8 @@ #include #include "eap-method.h" +#include "eap-method-peap.h" +#include "eap-method-simple.h" #include "wireless-security.h" #include "utils.h" diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index 59b49a40d4..4e42476521 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -26,6 +26,7 @@ #include #include "eap-method.h" +#include "eap-method-simple.h" #include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" diff --git a/panels/network/wireless-security/eap-method-tls.c b/panels/network/wireless-security/eap-method-tls.c index ffc6632b39..ecf4c0ef93 100644 --- a/panels/network/wireless-security/eap-method-tls.c +++ b/panels/network/wireless-security/eap-method-tls.c @@ -26,6 +26,7 @@ #include #include "eap-method.h" +#include "eap-method-tls.h" #include "wireless-security.h" #include "helpers.h" #include "nma-ui-utils.h" diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c index c474f7795d..aeecc33b64 100644 --- a/panels/network/wireless-security/eap-method-ttls.c +++ b/panels/network/wireless-security/eap-method-ttls.c @@ -26,6 +26,8 @@ #include #include "eap-method.h" +#include "eap-method-simple.h" +#include "eap-method-ttls.h" #include "wireless-security.h" #include "utils.h" diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index dc3c35b8d2..68d2bcead8 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -73,13 +73,6 @@ GType eap_method_get_type (void); /* Below for internal use only */ -#include "eap-method-tls.h" -#include "eap-method-leap.h" -#include "eap-method-fast.h" -#include "eap-method-ttls.h" -#include "eap-method-peap.h" -#include "eap-method-simple.h" - EAPMethod *eap_method_init (gsize obj_size, EMValidateFunc validate, EMAddToSizeGroupFunc add_to_size_group, diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index d67f3d7606..e4f41c7c04 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -27,6 +27,12 @@ #include "wireless-security.h" #include "wireless-security-resources.h" #include "eap-method.h" +#include "eap-method-fast.h" +#include "eap-method-leap.h" +#include "eap-method-peap.h" +#include "eap-method-simple.h" +#include "eap-method-tls.h" +#include "eap-method-ttls.h" #include "utils.h" struct _WirelessSecurityPrivate { -- GitLab From 5c3fd6417cfcb2dd5f5833c670ced371fc3453a0 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Wed, 6 Nov 2019 22:18:40 +1300 Subject: [PATCH 12/39] network: Add a method to stop a class peeking inside the GtkBuilder object of another --- .../connection-editor/ce-page-8021x-security.c | 16 ++++++++-------- panels/network/wireless-security/ws-wpa-eap.c | 5 +++++ panels/network/wireless-security/ws-wpa-eap.h | 10 +++++++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/panels/network/connection-editor/ce-page-8021x-security.c b/panels/network/connection-editor/ce-page-8021x-security.c index e38e2a71ea..a1ec4eca8f 100644 --- a/panels/network/connection-editor/ce-page-8021x-security.c +++ b/panels/network/connection-editor/ce-page-8021x-security.c @@ -41,7 +41,7 @@ struct _CEPage8021xSecurity { NMConnection *connection; GtkWidget *security_widget; - WirelessSecurity *security; + WirelessSecurityWPAEAP *security; GtkSizeGroup *group; gboolean initial_have_8021x; }; @@ -74,14 +74,14 @@ finish_setup (CEPage8021xSecurity *self, gpointer unused, GError *error, gpointe self->group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); - self->security = (WirelessSecurity *) ws_wpa_eap_new (self->connection, TRUE, FALSE); + self->security = ws_wpa_eap_new (self->connection, TRUE, FALSE); if (!self->security) { g_warning ("Could not load 802.1x user interface."); return; } - wireless_security_set_changed_notify (self->security, stuff_changed, self); - self->security_widget = wireless_security_get_widget (self->security); + wireless_security_set_changed_notify (WIRELESS_SECURITY (self->security), stuff_changed, self); + self->security_widget = wireless_security_get_widget (WIRELESS_SECURITY (self->security)); parent = gtk_widget_get_parent (self->security_widget); if (parent) gtk_container_remove (GTK_CONTAINER (parent), self->security_widget); @@ -91,7 +91,7 @@ finish_setup (CEPage8021xSecurity *self, gpointer unused, GError *error, gpointe gtk_widget_set_sensitive (self->security_widget, self->initial_have_8021x); gtk_size_group_add_widget (self->group, GTK_WIDGET (self->security_label)); - wireless_security_add_to_size_group (self->security, self->group); + wireless_security_add_to_size_group (WIRELESS_SECURITY (self->security), self->group); gtk_container_add (GTK_CONTAINER (self->box), self->security_widget); @@ -124,7 +124,7 @@ ce_page_8021x_security_validate (CEPage *cepage, NMConnection *connection, GErro NMSetting *s_8021x; /* FIXME: get failed property and error out of wireless security objects */ - valid = wireless_security_validate (self->security, error); + valid = wireless_security_validate (WIRELESS_SECURITY (self->security), error); if (valid) { g_autoptr(NMConnection) tmp_connection = NULL; NMSetting *s_con; @@ -139,7 +139,7 @@ ce_page_8021x_security_validate (CEPage *cepage, NMConnection *connection, GErro s_con = nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION); nm_connection_add_setting (tmp_connection, nm_setting_duplicate (s_con)); - ws_802_1x_fill_connection (GTK_COMBO_BOX (gtk_builder_get_object (self->security->builder, "auth_combo")), tmp_connection); + ws_802_1x_fill_connection (ws_wpa_eap_get_auth_combo (self->security), tmp_connection); s_8021x = nm_connection_get_setting (tmp_connection, NM_TYPE_SETTING_802_1X); nm_connection_add_setting (connection, NM_SETTING (g_object_ref (s_8021x))); @@ -164,7 +164,7 @@ ce_page_8021x_security_dispose (GObject *object) CEPage8021xSecurity *self = CE_PAGE_8021X_SECURITY (object); g_clear_object (&self->connection); - g_clear_pointer (&self->security, wireless_security_unref); + g_clear_pointer ((WirelessSecurity**) &self->security, wireless_security_unref); g_clear_object (&self->group); G_OBJECT_CLASS (ce_page_8021x_security_parent_class)->dispose (object); diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 9eebee6170..a8e7358b9c 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -142,3 +142,8 @@ ws_wpa_eap_new (NMConnection *connection, return self; } +GtkComboBox * +ws_wpa_eap_get_auth_combo (WirelessSecurityWPAEAP *self) +{ + return self->auth_combo; +} diff --git a/panels/network/wireless-security/ws-wpa-eap.h b/panels/network/wireless-security/ws-wpa-eap.h index 0ebff700c7..b5c1f9d4e2 100644 --- a/panels/network/wireless-security/ws-wpa-eap.h +++ b/panels/network/wireless-security/ws-wpa-eap.h @@ -23,10 +23,14 @@ #ifndef WS_WPA_EAP_H #define WS_WPA_EAP_H +#include + typedef struct _WirelessSecurityWPAEAP WirelessSecurityWPAEAP; -WirelessSecurityWPAEAP * ws_wpa_eap_new (NMConnection *connection, - gboolean is_editor, - gboolean secrets_only); +WirelessSecurityWPAEAP *ws_wpa_eap_new (NMConnection *connection, + gboolean is_editor, + gboolean secrets_only); + +GtkComboBox *ws_wpa_eap_get_auth_combo (WirelessSecurityWPAEAP *sec); #endif /* WS_WPA_EAP_H */ -- GitLab From b936955ff31612fa57d0da59efd8661cb460b0ac Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 09:09:02 +1300 Subject: [PATCH 13/39] network: Access widgets via a virtual method, not the GtkBuilder IDs --- .../wireless-security/eap-method-fast.c | 20 ++++++++++++-- .../wireless-security/eap-method-leap.c | 18 +++++++++++-- .../wireless-security/eap-method-peap.c | 22 ++++++++++++--- .../wireless-security/eap-method-simple.c | 18 +++++++++++-- .../wireless-security/eap-method-tls.c | 22 ++++++++++++--- .../wireless-security/eap-method-ttls.c | 20 ++++++++++++-- panels/network/wireless-security/eap-method.c | 27 +++++++++---------- panels/network/wireless-security/eap-method.h | 11 +++++--- .../wireless-security/wireless-security.c | 10 +++---- 9 files changed, 130 insertions(+), 38 deletions(-) diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index ebfaa52471..e5363e862a 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -40,6 +40,7 @@ struct _EAPMethodFAST { GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; + GtkGrid *grid; GtkComboBox *inner_auth_combo; GtkLabel *inner_auth_label; GtkBox *inner_auth_box; @@ -272,6 +273,20 @@ update_secrets (EAPMethod *parent, NMConnection *connection) I_METHOD_COLUMN); } +static GtkWidget * +get_widget (EAPMethod *parent) +{ + EAPMethodFAST *self = (EAPMethodFAST *) parent; + return GTK_WIDGET (self->grid); +} + +static GtkWidget * +get_default_field (EAPMethod *parent) +{ + EAPMethodFAST *self = (EAPMethodFAST *) parent; + return GTK_WIDGET (self->anon_identity_entry); +} + static void pac_toggled_cb (EAPMethodFAST *self) { @@ -307,10 +322,10 @@ eap_method_fast_new (WirelessSecurity *ws_parent, add_to_size_group, fill_connection, update_secrets, + get_widget, + get_default_field, destroy, "/org/gnome/ControlCenter/network/eap-method-fast.ui", - "grid", - "anon_identity_entry", FALSE); if (!parent) return NULL; @@ -322,6 +337,7 @@ eap_method_fast_new (WirelessSecurity *ws_parent, self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "anon_identity_entry")); self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "anon_identity_label")); + self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index c8de02b05c..f324ca9f30 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -127,6 +127,20 @@ update_secrets (EAPMethod *parent, NMConnection *connection) (HelperSecretFunc) nm_setting_802_1x_get_password); } +static GtkWidget * +get_widget (EAPMethod *parent) +{ + EAPMethodLEAP *self = (EAPMethodLEAP *) parent; + return GTK_WIDGET (self->grid); +} + +static GtkWidget * +get_default_field (EAPMethod *parent) +{ + EAPMethodLEAP *self = (EAPMethodLEAP *) parent; + return GTK_WIDGET (self->username_entry); +} + /* Set the UI fields for user, password and show_password to the * values as provided by self->ws_parent. */ static void @@ -192,10 +206,10 @@ eap_method_leap_new (WirelessSecurity *ws_parent, add_to_size_group, fill_connection, update_secrets, + get_widget, + get_default_field, destroy, "/org/gnome/ControlCenter/network/eap-method-leap.ui", - "grid", - "username_entry", FALSE); if (!parent) return NULL; diff --git a/panels/network/wireless-security/eap-method-peap.c b/panels/network/wireless-security/eap-method-peap.c index b2a6029f9c..7c5ae556d5 100644 --- a/panels/network/wireless-security/eap-method-peap.c +++ b/panels/network/wireless-security/eap-method-peap.c @@ -42,6 +42,7 @@ struct _EAPMethodPEAP { GtkFileChooserButton *ca_cert_button; GtkLabel *ca_cert_label; GtkCheckButton *ca_cert_not_required_check; + GtkGrid *grid; GtkBox *inner_auth_box; GtkComboBox *inner_auth_combo; GtkLabel *inner_auth_label; @@ -292,6 +293,20 @@ update_secrets (EAPMethod *parent, NMConnection *connection) I_METHOD_COLUMN); } +static GtkWidget * +get_widget (EAPMethod *parent) +{ + EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + return GTK_WIDGET (self->grid); +} + +static GtkWidget * +get_default_field (EAPMethod *parent) +{ + EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + return GTK_WIDGET (self->anon_identity_entry); +} + static void changed_cb (EAPMethodPEAP *self) { @@ -315,10 +330,10 @@ eap_method_peap_new (WirelessSecurity *ws_parent, add_to_size_group, fill_connection, update_secrets, + get_widget, + get_default_field, destroy, "/org/gnome/ControlCenter/network/eap-method-peap.ui", - "grid", - "anon_identity_entry", FALSE); if (!parent) return NULL; @@ -333,9 +348,10 @@ eap_method_peap_new (WirelessSecurity *ws_parent, self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_button")); self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "ca_cert_label")); self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); + self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); + self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); self->version_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "version_combo")); self->version_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "version_label")); diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index 4e42476521..9e2a2c039f 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -191,6 +191,20 @@ update_secrets (EAPMethod *parent, NMConnection *connection) (HelperSecretFunc) nm_setting_802_1x_get_password); } +static GtkWidget * +get_widget (EAPMethod *parent) +{ + EAPMethodSimple *self = (EAPMethodSimple *) parent; + return GTK_WIDGET (self->grid); +} + +static GtkWidget * +get_default_field (EAPMethod *parent) +{ + EAPMethodSimple *self = (EAPMethodSimple *) parent; + return GTK_WIDGET (self->username_entry); +} + static gboolean stuff_changed (EAPMethodSimple *self) { @@ -289,10 +303,10 @@ eap_method_simple_new (WirelessSecurity *ws_parent, add_to_size_group, fill_connection, update_secrets, + get_widget, + get_default_field, destroy, "/org/gnome/ControlCenter/network/eap-method-simple.ui", - "grid", - "username_entry", flags & EAP_METHOD_SIMPLE_FLAG_PHASE2); if (!parent) return NULL; diff --git a/panels/network/wireless-security/eap-method-tls.c b/panels/network/wireless-security/eap-method-tls.c index ecf4c0ef93..1a3e08511f 100644 --- a/panels/network/wireless-security/eap-method-tls.c +++ b/panels/network/wireless-security/eap-method-tls.c @@ -38,6 +38,7 @@ struct _EAPMethodTLS { GtkFileChooserButton *ca_cert_button; GtkLabel *ca_cert_label; GtkCheckButton *ca_cert_not_required_check; + GtkGrid *grid; GtkEntry *identity_entry; GtkLabel *identity_label; GtkFileChooserButton *private_key_button; @@ -264,7 +265,7 @@ private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean cha GtkWidget *toplevel; GtkWindow *parent_window = NULL; - toplevel = gtk_widget_get_toplevel (parent->ui_widget); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->grid)); if (gtk_widget_is_toplevel (toplevel)) parent_window = GTK_WINDOW (toplevel); @@ -395,6 +396,20 @@ update_secrets (EAPMethod *parent, NMConnection *connection) } } +static GtkWidget * +get_widget (EAPMethod *parent) +{ + EAPMethodTLS *self = (EAPMethodTLS *) parent; + return GTK_WIDGET (self->grid); +} + +static GtkWidget * +get_default_field (EAPMethod *parent) +{ + EAPMethodTLS *self = (EAPMethodTLS *) parent; + return GTK_WIDGET (self->identity_entry); +} + EAPMethodTLS * eap_method_tls_new (WirelessSecurity *ws_parent, NMConnection *connection, @@ -411,10 +426,10 @@ eap_method_tls_new (WirelessSecurity *ws_parent, add_to_size_group, fill_connection, update_secrets, + get_widget, + get_default_field, NULL, "/org/gnome/ControlCenter/network/eap-method-tls.ui", - "grid", - "identity_entry", phase2); if (!parent) return NULL; @@ -429,6 +444,7 @@ eap_method_tls_new (WirelessSecurity *ws_parent, self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_button")); self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "ca_cert_label")); self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); + self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); self->identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "identity_entry")); self->identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "identity_label")); self->private_key_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "private_key_button")); diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c index aeecc33b64..697a37de82 100644 --- a/panels/network/wireless-security/eap-method-ttls.c +++ b/panels/network/wireless-security/eap-method-ttls.c @@ -44,6 +44,7 @@ struct _EAPMethodTTLS { GtkCheckButton *ca_cert_not_required_check; GtkEntry *domain_match_entry; GtkLabel *domain_match_label; + GtkGrid *grid; GtkComboBox *inner_auth_combo; GtkLabel *inner_auth_label; GtkBox *inner_auth_box; @@ -345,6 +346,20 @@ update_secrets (EAPMethod *parent, NMConnection *connection) I_METHOD_COLUMN); } +static GtkWidget * +get_widget (EAPMethod *parent) +{ + EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + return GTK_WIDGET (self->grid); +} + +static GtkWidget * +get_default_field (EAPMethod *parent) +{ + EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + return GTK_WIDGET (self->anon_identity_entry); +} + static void changed_cb (EAPMethodTTLS *self) { @@ -368,10 +383,10 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, add_to_size_group, fill_connection, update_secrets, + get_widget, + get_default_field, destroy, "/org/gnome/ControlCenter/network/eap-method-ttls.ui", - "grid", - "anon_identity_entry", FALSE); if (!parent) return NULL; @@ -388,6 +403,7 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); self->domain_match_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "domain_match_entry")); self->domain_match_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "domain_match_label")); + self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c index 34a2a0cb45..5b65126c11 100644 --- a/panels/network/wireless-security/eap-method.c +++ b/panels/network/wireless-security/eap-method.c @@ -52,7 +52,15 @@ eap_method_get_widget (EAPMethod *self) { g_return_val_if_fail (self != NULL, NULL); - return self->ui_widget; + return self->get_widget (self); +} + +GtkWidget * +eap_method_get_default_field (EAPMethod *self) +{ + g_return_val_if_fail (self != NULL, NULL); + + return self->get_default_field (self); } gboolean @@ -123,10 +131,10 @@ eap_method_init (gsize obj_size, EMAddToSizeGroupFunc add_to_size_group, EMFillConnectionFunc fill_connection, EMUpdateSecretsFunc update_secrets, + EMGetWidgetFunc get_widget, + EMGetWidgetFunc get_default_field, EMDestroyFunc destroy, const char *ui_resource, - const char *ui_widget_name, - const char *default_field, gboolean phase2) { g_autoptr(EAPMethod) self = NULL; @@ -134,7 +142,6 @@ eap_method_init (gsize obj_size, g_return_val_if_fail (obj_size > 0, NULL); g_return_val_if_fail (ui_resource != NULL, NULL); - g_return_val_if_fail (ui_widget_name != NULL, NULL); self = g_slice_alloc0 (obj_size); g_assert (self); @@ -145,7 +152,8 @@ eap_method_init (gsize obj_size, self->add_to_size_group = add_to_size_group; self->fill_connection = fill_connection; self->update_secrets = update_secrets; - self->default_field = default_field; + self->get_widget = get_widget; + self->get_default_field = get_default_field; self->phase2 = phase2; self->builder = gtk_builder_new (); @@ -155,14 +163,6 @@ eap_method_init (gsize obj_size, return NULL; } - self->ui_widget = GTK_WIDGET (gtk_builder_get_object (self->builder, ui_widget_name)); - if (!self->ui_widget) { - g_warning ("Couldn't load UI widget '%s' from UI file %s", - ui_widget_name, ui_resource); - return NULL; - } - g_object_ref_sink (self->ui_widget); - self->destroy = destroy; return g_steal_pointer (&self); @@ -191,7 +191,6 @@ eap_method_unref (EAPMethod *self) self->destroy (self); g_clear_object (&self->builder); - g_clear_object (&self->ui_widget); g_slice_free1 (self->obj_size, self); } diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index 68d2bcead8..1b0f62dc27 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -32,15 +32,14 @@ typedef void (*EMFillConnectionFunc) (EAPMethod *method, NMConnection *co typedef void (*EMUpdateSecretsFunc) (EAPMethod *method, NMConnection *connection); typedef void (*EMDestroyFunc) (EAPMethod *method); typedef gboolean (*EMValidateFunc) (EAPMethod *method, GError **error); +typedef GtkWidget* (*EMGetWidgetFunc) (EAPMethod *method); struct _EAPMethod { guint32 refcount; gsize obj_size; GtkBuilder *builder; - GtkWidget *ui_widget; - const char *default_field; const char *password_flags_name; gboolean phase2; @@ -49,6 +48,8 @@ struct _EAPMethod { EMFillConnectionFunc fill_connection; EMUpdateSecretsFunc update_secrets; EMValidateFunc validate; + EMGetWidgetFunc get_widget; + EMGetWidgetFunc get_default_field; EMDestroyFunc destroy; }; @@ -57,6 +58,8 @@ struct _EAPMethod { GtkWidget *eap_method_get_widget (EAPMethod *method); +GtkWidget *eap_method_get_default_field (EAPMethod *method); + gboolean eap_method_validate (EAPMethod *method, GError **error); void eap_method_add_to_size_group (EAPMethod *method, GtkSizeGroup *group); @@ -78,10 +81,10 @@ EAPMethod *eap_method_init (gsize obj_size, EMAddToSizeGroupFunc add_to_size_group, EMFillConnectionFunc fill_connection, EMUpdateSecretsFunc update_secrets, + EMGetWidgetFunc get_widget, + EMGetWidgetFunc get_default_field, EMDestroyFunc destroy, const char *ui_resource, - const char *ui_widget_name, - const char *default_field, gboolean phase2); GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey); diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index e4f41c7c04..99c9c9b8df 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -341,7 +341,7 @@ ws_802_1x_auth_combo_changed (GtkComboBox *combo, EAPMethod *eap; GList *elt, *children; GtkWidget *eap_widget; - GtkWidget *eap_default_widget = NULL; + GtkWidget *eap_default_field; /* Remove any previous wireless security widgets */ children = gtk_container_get_children (GTK_CONTAINER (vbox)); @@ -360,11 +360,9 @@ ws_802_1x_auth_combo_changed (GtkComboBox *combo, gtk_container_add (GTK_CONTAINER (vbox), eap_widget); /* Refocus the EAP method's default widget */ - if (eap->default_field) { - eap_default_widget = GTK_WIDGET (gtk_builder_get_object (eap->builder, eap->default_field)); - if (eap_default_widget) - gtk_widget_grab_focus (eap_default_widget); - } + eap_default_field = eap_method_get_default_field (eap); + if (eap_default_field) + gtk_widget_grab_focus (eap_default_field); } void -- GitLab From 113bead8798f9797d43cd7a37ef95bafd2c4c80d Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 09:26:20 +1300 Subject: [PATCH 14/39] network: Move GtkBuilder code from EAPMethod to subclasses --- .../wireless-security/eap-method-fast.c | 30 ++++++++----- .../wireless-security/eap-method-leap.c | 22 +++++++--- .../wireless-security/eap-method-peap.c | 32 +++++++++----- .../wireless-security/eap-method-simple.c | 22 +++++++--- .../wireless-security/eap-method-tls.c | 44 ++++++++++++------- .../wireless-security/eap-method-ttls.c | 32 +++++++++----- panels/network/wireless-security/eap-method.c | 13 ------ panels/network/wireless-security/eap-method.h | 3 -- 8 files changed, 118 insertions(+), 80 deletions(-) diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index e5363e862a..f1cbabdff6 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -38,6 +38,7 @@ struct _EAPMethodFAST { EAPMethod parent; + GtkBuilder *builder; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; GtkGrid *grid; @@ -59,6 +60,7 @@ destroy (EAPMethod *parent) { EAPMethodFAST *self = (EAPMethodFAST *) parent; + g_clear_object (&self->builder); g_clear_object (&self->size_group); } @@ -316,6 +318,7 @@ eap_method_fast_new (WirelessSecurity *ws_parent, NMSetting8021x *s_8021x = NULL; const char *filename; gboolean provisioning_enabled = TRUE; + g_autoptr(GError) error = NULL; parent = eap_method_init (sizeof (EAPMethodFAST), validate, @@ -325,7 +328,6 @@ eap_method_fast_new (WirelessSecurity *ws_parent, get_widget, get_default_field, destroy, - "/org/gnome/ControlCenter/network/eap-method-fast.ui", FALSE); if (!parent) return NULL; @@ -335,16 +337,22 @@ eap_method_fast_new (WirelessSecurity *ws_parent, self->sec_parent = ws_parent; self->is_editor = is_editor; - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "anon_identity_label")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); - self->pac_file_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "pac_file_button")); - self->pac_file_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "pac_file_label")); - self->pac_provision_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "pac_provision_check")); - self->pac_provision_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "pac_provision_combo")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-fast.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "anon_identity_entry")); + self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (self->builder, "anon_identity_label")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "inner_auth_combo")); + self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "inner_auth_label")); + self->inner_auth_box = GTK_BOX (gtk_builder_get_object (self->builder, "inner_auth_box")); + self->pac_file_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "pac_file_button")); + self->pac_file_label = GTK_LABEL (gtk_builder_get_object (self->builder, "pac_file_label")); + self->pac_provision_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "pac_provision_check")); + self->pac_provision_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "pac_provision_combo")); if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index f324ca9f30..6d1791d88c 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -35,6 +35,7 @@ struct _EAPMethodLEAP { EAPMethod parent; + GtkBuilder *builder; GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; @@ -180,6 +181,7 @@ destroy (EAPMethod *parent) { EAPMethodLEAP *self = (EAPMethodLEAP *) parent; + g_clear_object (&self->builder); g_signal_handlers_disconnect_by_data (self->grid, self); g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent); @@ -200,6 +202,7 @@ eap_method_leap_new (WirelessSecurity *ws_parent, EAPMethodLEAP *self; EAPMethod *parent; NMSetting8021x *s_8021x = NULL; + g_autoptr(GError) error = NULL; parent = eap_method_init (sizeof (EAPMethodLEAP), validate, @@ -209,7 +212,6 @@ eap_method_leap_new (WirelessSecurity *ws_parent, get_widget, get_default_field, destroy, - "/org/gnome/ControlCenter/network/eap-method-leap.ui", FALSE); if (!parent) return NULL; @@ -219,12 +221,18 @@ eap_method_leap_new (WirelessSecurity *ws_parent, self->editing_connection = secrets_only ? FALSE : TRUE; self->ws_parent = ws_parent; - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")); - self->password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->username_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "username_entry")); - self->username_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "username_label")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-leap.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password_entry")); + self->password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "password_label")); + self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); + self->username_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "username_entry")); + self->username_label = GTK_LABEL (gtk_builder_get_object (self->builder, "username_label")); g_signal_connect_swapped (self->grid, "realize", G_CALLBACK (widgets_realized), self); g_signal_connect_swapped (self->grid, "unrealize", G_CALLBACK (widgets_unrealized), self); diff --git a/panels/network/wireless-security/eap-method-peap.c b/panels/network/wireless-security/eap-method-peap.c index 7c5ae556d5..17619dbd08 100644 --- a/panels/network/wireless-security/eap-method-peap.c +++ b/panels/network/wireless-security/eap-method-peap.c @@ -37,6 +37,7 @@ struct _EAPMethodPEAP { EAPMethod parent; + GtkBuilder *builder; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; GtkFileChooserButton *ca_cert_button; @@ -59,6 +60,7 @@ destroy (EAPMethod *parent) { EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + g_clear_object (&self->builder); g_clear_object (&self->size_group); } @@ -324,6 +326,7 @@ eap_method_peap_new (WirelessSecurity *ws_parent, GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; + g_autoptr(GError) error = NULL; parent = eap_method_init (sizeof (EAPMethodPEAP), validate, @@ -333,7 +336,6 @@ eap_method_peap_new (WirelessSecurity *ws_parent, get_widget, get_default_field, destroy, - "/org/gnome/ControlCenter/network/eap-method-peap.ui", FALSE); if (!parent) return NULL; @@ -343,17 +345,23 @@ eap_method_peap_new (WirelessSecurity *ws_parent, self->sec_parent = ws_parent; self->is_editor = is_editor; - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "anon_identity_label")); - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); - self->version_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "version_combo")); - self->version_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "version_label")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-peap.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "anon_identity_entry")); + self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (self->builder, "anon_identity_label")); + self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_button")); + self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (self->builder, "ca_cert_label")); + self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_not_required_check")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->inner_auth_box = GTK_BOX (gtk_builder_get_object (self->builder, "inner_auth_box")); + self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "inner_auth_combo")); + self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "inner_auth_label")); + self->version_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "version_combo")); + self->version_label = GTK_LABEL (gtk_builder_get_object (self->builder, "version_label")); if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index 9e2a2c039f..e0f513e65d 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -35,6 +35,7 @@ struct _EAPMethodSimple { EAPMethod parent; + GtkBuilder *builder; GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; @@ -273,6 +274,7 @@ destroy (EAPMethod *parent) { EAPMethodSimple *self = (EAPMethodSimple *) parent; + g_clear_object (&self->builder); g_signal_handlers_disconnect_by_data (self->grid, self); g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent); @@ -297,6 +299,7 @@ eap_method_simple_new (WirelessSecurity *ws_parent, EAPMethod *parent; EAPMethodSimple *self; NMSetting8021x *s_8021x = NULL; + g_autoptr(GError) error = NULL; parent = eap_method_init (sizeof (EAPMethodSimple), validate, @@ -306,7 +309,6 @@ eap_method_simple_new (WirelessSecurity *ws_parent, get_widget, get_default_field, destroy, - "/org/gnome/ControlCenter/network/eap-method-simple.ui", flags & EAP_METHOD_SIMPLE_FLAG_PHASE2); if (!parent) return NULL; @@ -318,12 +320,18 @@ eap_method_simple_new (WirelessSecurity *ws_parent, self->type = type; g_assert (type < EAP_METHOD_SIMPLE_TYPE_LAST); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "password_label")); - self->username_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "username_label")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")); - self->show_password_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->username_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "username_entry")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-simple.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "password_label")); + self->username_label = GTK_LABEL (gtk_builder_get_object (self->builder, "username_label")); + self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password_entry")); + self->show_password_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); + self->username_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "username_entry")); g_signal_connect_swapped (self->grid, "realize", G_CALLBACK (widgets_realized), self); g_signal_connect_swapped (self->grid, "unrealize", G_CALLBACK (widgets_unrealized), self); diff --git a/panels/network/wireless-security/eap-method-tls.c b/panels/network/wireless-security/eap-method-tls.c index 1a3e08511f..6c3fb8cea4 100644 --- a/panels/network/wireless-security/eap-method-tls.c +++ b/panels/network/wireless-security/eap-method-tls.c @@ -35,6 +35,7 @@ struct _EAPMethodTLS { EAPMethod parent; + GtkBuilder *builder; GtkFileChooserButton *ca_cert_button; GtkLabel *ca_cert_label; GtkCheckButton *ca_cert_not_required_check; @@ -53,6 +54,13 @@ struct _EAPMethodTLS { gboolean editing_connection; }; +static void +destroy (EAPMethod *parent) +{ + EAPMethodTLS *self = (EAPMethodTLS *) parent; + + g_clear_object (&self->builder); +} static void show_toggled_cb (EAPMethodTLS *self) @@ -420,6 +428,7 @@ eap_method_tls_new (WirelessSecurity *ws_parent, EAPMethod *parent; NMSetting8021x *s_8021x = NULL; gboolean ca_not_required = FALSE; + g_autoptr(GError) error = NULL; parent = eap_method_init (sizeof (EAPMethodTLS), validate, @@ -428,8 +437,7 @@ eap_method_tls_new (WirelessSecurity *ws_parent, update_secrets, get_widget, get_default_field, - NULL, - "/org/gnome/ControlCenter/network/eap-method-tls.ui", + destroy, phase2); if (!parent) return NULL; @@ -441,19 +449,25 @@ eap_method_tls_new (WirelessSecurity *ws_parent, self->sec_parent = ws_parent; self->editing_connection = secrets_only ? FALSE : TRUE; - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "identity_entry")); - self->identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "identity_label")); - self->private_key_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "private_key_button")); - self->private_key_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "private_key_label")); - self->private_key_password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "private_key_password_entry")); - self->private_key_password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "private_key_password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->user_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "user_cert_button")); - self->user_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "user_cert_label")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-tls.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_button")); + self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (self->builder, "ca_cert_label")); + self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_not_required_check")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->identity_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "identity_entry")); + self->identity_label = GTK_LABEL (gtk_builder_get_object (self->builder, "identity_label")); + self->private_key_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "private_key_button")); + self->private_key_label = GTK_LABEL (gtk_builder_get_object (self->builder, "private_key_label")); + self->private_key_password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "private_key_password_entry")); + self->private_key_password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "private_key_password_label")); + self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); + self->user_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "user_cert_button")); + self->user_cert_label = GTK_LABEL (gtk_builder_get_object (self->builder, "user_cert_label")); if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c index 697a37de82..e2e20c11c4 100644 --- a/panels/network/wireless-security/eap-method-ttls.c +++ b/panels/network/wireless-security/eap-method-ttls.c @@ -37,6 +37,7 @@ struct _EAPMethodTTLS { EAPMethod parent; + GtkBuilder *builder; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; GtkFileChooserButton *ca_cert_button; @@ -59,6 +60,7 @@ destroy (EAPMethod *parent) { EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + g_clear_object (&self->builder); g_clear_object (&self->size_group); } @@ -377,6 +379,7 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; + g_autoptr(GError) error = NULL; parent = eap_method_init (sizeof (EAPMethodTTLS), validate, @@ -386,7 +389,6 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, get_widget, get_default_field, destroy, - "/org/gnome/ControlCenter/network/eap-method-ttls.ui", FALSE); if (!parent) return NULL; @@ -396,17 +398,23 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, self->sec_parent = ws_parent; self->is_editor = is_editor; - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "anon_identity_label")); - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "ca_cert_not_required_check")); - self->domain_match_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "domain_match_entry")); - self->domain_match_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "domain_match_label")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "inner_auth_label")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (parent->builder, "inner_auth_box")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-ttls.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "anon_identity_entry")); + self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (self->builder, "anon_identity_label")); + self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_button")); + self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (self->builder, "ca_cert_label")); + self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_not_required_check")); + self->domain_match_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "domain_match_entry")); + self->domain_match_label = GTK_LABEL (gtk_builder_get_object (self->builder, "domain_match_label")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "inner_auth_combo")); + self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "inner_auth_label")); + self->inner_auth_box = GTK_BOX (gtk_builder_get_object (self->builder, "inner_auth_box")); if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c index 5b65126c11..4444f85579 100644 --- a/panels/network/wireless-security/eap-method.c +++ b/panels/network/wireless-security/eap-method.c @@ -134,14 +134,11 @@ eap_method_init (gsize obj_size, EMGetWidgetFunc get_widget, EMGetWidgetFunc get_default_field, EMDestroyFunc destroy, - const char *ui_resource, gboolean phase2) { g_autoptr(EAPMethod) self = NULL; - g_autoptr(GError) error = NULL; g_return_val_if_fail (obj_size > 0, NULL); - g_return_val_if_fail (ui_resource != NULL, NULL); self = g_slice_alloc0 (obj_size); g_assert (self); @@ -155,14 +152,6 @@ eap_method_init (gsize obj_size, self->get_widget = get_widget; self->get_default_field = get_default_field; self->phase2 = phase2; - - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, ui_resource, &error)) { - g_warning ("Couldn't load UI builder resource %s: %s", - ui_resource, error->message); - return NULL; - } - self->destroy = destroy; return g_steal_pointer (&self); @@ -190,8 +179,6 @@ eap_method_unref (EAPMethod *self) if (self->destroy) self->destroy (self); - g_clear_object (&self->builder); - g_slice_free1 (self->obj_size, self); } } diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index 1b0f62dc27..5ef1a96924 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -38,8 +38,6 @@ struct _EAPMethod { guint32 refcount; gsize obj_size; - GtkBuilder *builder; - const char *password_flags_name; gboolean phase2; @@ -84,7 +82,6 @@ EAPMethod *eap_method_init (gsize obj_size, EMGetWidgetFunc get_widget, EMGetWidgetFunc get_default_field, EMDestroyFunc destroy, - const char *ui_resource, gboolean phase2); GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey); -- GitLab From 2e8226a09c9e380e8804c74507f151794900a06b Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 10:03:25 +1300 Subject: [PATCH 15/39] network: Move EAPMethod property to a virtual method --- .../wireless-security/eap-method-fast.c | 8 ++++++- .../wireless-security/eap-method-leap.c | 14 +++++++++---- .../wireless-security/eap-method-peap.c | 8 ++++++- .../wireless-security/eap-method-simple.c | 12 ++++++++--- .../wireless-security/eap-method-tls.c | 21 +++++++++++++------ .../wireless-security/eap-method-ttls.c | 8 ++++++- panels/network/wireless-security/eap-method.c | 15 ++++++++++++- panels/network/wireless-security/eap-method.h | 7 +++++-- .../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 f1cbabdff6..5f3fc5ad12 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 6d1791d88c..f33a41deac 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 17619dbd08..3514c4911e 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 e0f513e65d..594e95640c 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 6c3fb8cea4..58550a82d3 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 e2e20c11c4..8295357f58 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 4444f85579..721b80cea7 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 5ef1a96924..bd8875a8cd 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 99c9c9b8df..e8c4a7a272 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; -- GitLab From 426896b7a2c97cdaf0ba39c2071edc91770bfde7 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 10:20:34 +1300 Subject: [PATCH 16/39] network: Move EAPMethod property to a virtual method --- .../wireless-security/eap-method-fast.c | 4 ++-- .../wireless-security/eap-method-leap.c | 4 ++-- .../wireless-security/eap-method-peap.c | 4 ++-- .../wireless-security/eap-method-simple.c | 15 ++++++++---- .../wireless-security/eap-method-tls.c | 23 +++++++++++++------ .../wireless-security/eap-method-ttls.c | 4 ++-- panels/network/wireless-security/eap-method.c | 21 +++++++++++++---- panels/network/wireless-security/eap-method.h | 10 ++++---- 8 files changed, 57 insertions(+), 28 deletions(-) diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index 5f3fc5ad12..475ea1008f 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -334,8 +334,8 @@ eap_method_fast_new (WirelessSecurity *ws_parent, get_widget, get_default_field, get_password_flags_name, - destroy, - FALSE); + NULL, + destroy); if (!parent) return NULL; diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index f33a41deac..ef427eafc5 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -218,8 +218,8 @@ eap_method_leap_new (WirelessSecurity *ws_parent, get_widget, get_default_field, get_password_flags_name, - destroy, - FALSE); + NULL, + destroy); if (!parent) return NULL; diff --git a/panels/network/wireless-security/eap-method-peap.c b/panels/network/wireless-security/eap-method-peap.c index 3514c4911e..25b700f18b 100644 --- a/panels/network/wireless-security/eap-method-peap.c +++ b/panels/network/wireless-security/eap-method-peap.c @@ -342,8 +342,8 @@ eap_method_peap_new (WirelessSecurity *ws_parent, get_widget, get_default_field, get_password_flags_name, - destroy, - FALSE); + NULL, + destroy); if (!parent) return NULL; diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index 594e95640c..599b440f63 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -140,11 +140,11 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla /* If this is the main EAP method, clear any existing methods because the * user-selected on will replace it. */ - if (parent->phase2 == FALSE) + if (eap_method_get_phase2 (parent) == FALSE) nm_setting_802_1x_clear_eap_methods (s_8021x); eap_type = &eap_table[self->type]; - if (parent->phase2) { + if (eap_method_get_phase2 (parent)) { /* If the outer EAP method (TLS, TTLS, PEAP, etc) allows inner/phase2 * EAP methods (which only TTLS allows) *and* the inner/phase2 method * supports being an inner EAP method, then set PHASE2_AUTHEAP. @@ -212,6 +212,13 @@ get_password_flags_name (EAPMethod *parent) return NM_SETTING_802_1X_PASSWORD; } +static const gboolean +get_phase2 (EAPMethod *parent) +{ + EAPMethodSimple *self = (EAPMethodSimple *) parent; + return self->flags & EAP_METHOD_SIMPLE_FLAG_PHASE2; +} + static gboolean stuff_changed (EAPMethodSimple *self) { @@ -315,8 +322,8 @@ eap_method_simple_new (WirelessSecurity *ws_parent, get_widget, get_default_field, get_password_flags_name, - destroy, - flags & EAP_METHOD_SIMPLE_FLAG_PHASE2); + get_phase2, + destroy); if (!parent) return NULL; diff --git a/panels/network/wireless-security/eap-method-tls.c b/panels/network/wireless-security/eap-method-tls.c index 58550a82d3..13e85689af 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; + gboolean phase2; const gchar *password_flags_name; WirelessSecurity *sec_parent; gboolean editing_connection; @@ -172,7 +173,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla s_8021x = nm_connection_get_setting_802_1x (connection); g_assert (s_8021x); - if (parent->phase2) + if (self->phase2) g_object_set (s_8021x, NM_SETTING_802_1X_PHASE2_AUTH, "tls", NULL); else nm_setting_802_1x_add_eap_method (s_8021x, "tls"); @@ -185,7 +186,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla pk_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->private_key_button)); g_assert (pk_filename); - if (parent->phase2) { + if (self->phase2) { g_autoptr(GError) error = NULL; if (!nm_setting_802_1x_set_phase2_private_key (s_8021x, pk_filename, password, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error)) g_warning ("Couldn't read phase2 private key '%s': %s", pk_filename, error ? error->message : "(unknown)"); @@ -217,7 +218,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla g_assert (cc_filename); format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - if (parent->phase2) { + if (self->phase2) { g_autoptr(GError) error = NULL; if (!nm_setting_802_1x_set_phase2_client_cert (s_8021x, cc_filename, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error)) g_warning ("Couldn't read phase2 client certificate '%s': %s", cc_filename, error ? error->message : "(unknown)"); @@ -232,7 +233,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla ca_filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button)); format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; - if (parent->phase2) { + if (self->phase2) { g_autoptr(GError) error = NULL; if (!nm_setting_802_1x_set_phase2_ca_cert (s_8021x, ca_filename, NM_SETTING_802_1X_CK_SCHEME_PATH, &format, &error)) { g_warning ("Couldn't read phase2 CA certificate '%s': %s", ca_filename, error ? error->message : "(unknown)"); @@ -381,7 +382,7 @@ update_secrets (EAPMethod *parent, NMConnection *connection) PathFunc path_func; const char *filename; - if (parent->phase2) { + if (self->phase2) { password_func = (HelperSecretFunc) nm_setting_802_1x_get_phase2_private_key_password; scheme_func = nm_setting_802_1x_get_phase2_private_key_scheme; path_func = nm_setting_802_1x_get_phase2_private_key_path; @@ -426,6 +427,13 @@ get_password_flags_name (EAPMethod *parent) return self->password_flags_name; } +static gboolean +get_phase2 (EAPMethod *parent) +{ + EAPMethodTLS *self = (EAPMethodTLS *) parent; + return self->phase2; +} + EAPMethodTLS * eap_method_tls_new (WirelessSecurity *ws_parent, NMConnection *connection, @@ -446,12 +454,13 @@ eap_method_tls_new (WirelessSecurity *ws_parent, get_widget, get_default_field, get_password_flags_name, - destroy, - phase2); + get_phase2, + destroy); if (!parent) return NULL; self = (EAPMethodTLS *) parent; + self->phase2 = phase2; self->password_flags_name = phase2 ? NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD : NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD; diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c index 8295357f58..9a9553dec4 100644 --- a/panels/network/wireless-security/eap-method-ttls.c +++ b/panels/network/wireless-security/eap-method-ttls.c @@ -395,8 +395,8 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, get_widget, get_default_field, get_password_flags_name, - destroy, - FALSE); + NULL, + destroy); if (!parent) return NULL; diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c index 721b80cea7..3bad3d9b66 100644 --- a/panels/network/wireless-security/eap-method.c +++ b/panels/network/wireless-security/eap-method.c @@ -74,6 +74,17 @@ eap_method_get_password_flags_name (EAPMethod *self) return NULL; } +gboolean +eap_method_get_phase2 (EAPMethod *self) +{ + g_return_val_if_fail (self != NULL, FALSE); + + if (self->get_phase2) + return self->get_phase2 (self); + else + return FALSE; +} + gboolean eap_method_validate (EAPMethod *self, GError **error) { @@ -145,8 +156,8 @@ eap_method_init (gsize obj_size, EMGetWidgetFunc get_widget, EMGetWidgetFunc get_default_field, EMGetStringFunc get_password_flags_name, - EMDestroyFunc destroy, - gboolean phase2) + EMGetBooleanFunc get_phase2, + EMDestroyFunc destroy) { g_autoptr(EAPMethod) self = NULL; @@ -164,8 +175,8 @@ eap_method_init (gsize obj_size, self->get_widget = get_widget; self->get_default_field = get_default_field; self->get_password_flags_name = get_password_flags_name; + self->get_phase2 = get_phase2; self->destroy = destroy; - self->phase2 = phase2; return g_steal_pointer (&self); } @@ -528,7 +539,7 @@ eap_method_ca_cert_ignore_set (EAPMethod *self, if (s_8021x) { ignore = !ca_cert_error && filename == NULL; g_object_set_data (G_OBJECT (s_8021x), - self->phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG, + eap_method_get_phase2 (self) ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG, GUINT_TO_POINTER (ignore)); } } @@ -549,7 +560,7 @@ eap_method_ca_cert_ignore_get (EAPMethod *self, NMConnection *connection) s_8021x = nm_connection_get_setting_802_1x (connection); if (s_8021x) { return !!g_object_get_data (G_OBJECT (s_8021x), - self->phase2 ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG); + eap_method_get_phase2 (self) ? IGNORE_PHASE2_CA_CERT_TAG : IGNORE_CA_CERT_TAG); } return FALSE; } diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index bd8875a8cd..199dbfc066 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -34,13 +34,12 @@ typedef void (*EMDestroyFunc) (EAPMethod *method); typedef gboolean (*EMValidateFunc) (EAPMethod *method, GError **error); typedef GtkWidget* (*EMGetWidgetFunc) (EAPMethod *method); typedef const gchar* (*EMGetStringFunc) (EAPMethod *method); +typedef gboolean (*EMGetBooleanFunc) (EAPMethod *method); struct _EAPMethod { guint32 refcount; gsize obj_size; - gboolean phase2; - EMAddToSizeGroupFunc add_to_size_group; EMFillConnectionFunc fill_connection; EMUpdateSecretsFunc update_secrets; @@ -48,6 +47,7 @@ struct _EAPMethod { EMGetWidgetFunc get_widget; EMGetWidgetFunc get_default_field; EMGetStringFunc get_password_flags_name; + EMGetBooleanFunc get_phase2; EMDestroyFunc destroy; }; @@ -60,6 +60,8 @@ GtkWidget *eap_method_get_default_field (EAPMethod *method); const gchar *eap_method_get_password_flags_name (EAPMethod *method); +gboolean eap_method_get_phase2 (EAPMethod *method); + gboolean eap_method_validate (EAPMethod *method, GError **error); void eap_method_add_to_size_group (EAPMethod *method, GtkSizeGroup *group); @@ -84,8 +86,8 @@ EAPMethod *eap_method_init (gsize obj_size, EMGetWidgetFunc get_widget, EMGetWidgetFunc get_default_field, EMGetStringFunc get_password_flags_name, - EMDestroyFunc destroy, - gboolean phase2); + EMGetBooleanFunc get_phase2, + EMDestroyFunc destroy); GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey); -- GitLab From 5006342308bf9c9523a9753f3d45ed38be8eddf4 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 10:21:54 +1300 Subject: [PATCH 17/39] network: Convert EAPMethod to an interface and make the subclasses GObjects --- .../wireless-security/eap-method-fast.c | 54 +++++--- .../wireless-security/eap-method-fast.h | 15 +-- .../wireless-security/eap-method-leap.c | 54 +++++--- .../wireless-security/eap-method-leap.h | 13 +- .../wireless-security/eap-method-peap.c | 86 +++++++----- .../wireless-security/eap-method-peap.h | 13 +- .../wireless-security/eap-method-simple.c | 89 ++++++++----- .../wireless-security/eap-method-simple.h | 15 +-- .../wireless-security/eap-method-tls.c | 125 ++++++++++-------- .../wireless-security/eap-method-tls.h | 13 +- .../wireless-security/eap-method-ttls.c | 86 +++++++----- .../wireless-security/eap-method-ttls.h | 13 +- panels/network/wireless-security/eap-method.c | 100 +++----------- panels/network/wireless-security/eap-method.h | 65 +++------ 14 files changed, 368 insertions(+), 373 deletions(-) diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index 475ea1008f..df8bf77df0 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -36,7 +36,7 @@ #define I_METHOD_COLUMN 1 struct _EAPMethodFAST { - EAPMethod parent; + GObject parent; GtkBuilder *builder; GtkEntry *anon_identity_entry; @@ -55,13 +55,20 @@ struct _EAPMethodFAST { gboolean is_editor; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodFAST, eap_method_fast, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + static void -destroy (EAPMethod *parent) +eap_method_fast_dispose (GObject *object) { - EAPMethodFAST *self = (EAPMethodFAST *) parent; + EAPMethodFAST *self = EAP_METHOD_FAST (object); g_clear_object (&self->builder); g_clear_object (&self->size_group); + + G_OBJECT_CLASS (eap_method_fast_parent_class)->dispose (object); } static gboolean @@ -312,13 +319,37 @@ changed_cb (EAPMethodFAST *self) wireless_security_notify_changed (self->sec_parent); } +static void +eap_method_fast_init (EAPMethodFAST *self) +{ +} + +static void +eap_method_fast_class_init (EAPMethodFASTClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = eap_method_fast_dispose; +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_widget = get_widget; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; +} + EAPMethodFAST * eap_method_fast_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only) { - EAPMethod *parent; EAPMethodFAST *self; GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; @@ -326,20 +357,7 @@ eap_method_fast_new (WirelessSecurity *ws_parent, gboolean provisioning_enabled = TRUE; g_autoptr(GError) error = NULL; - parent = eap_method_init (sizeof (EAPMethodFAST), - validate, - add_to_size_group, - fill_connection, - update_secrets, - get_widget, - get_default_field, - get_password_flags_name, - NULL, - destroy); - if (!parent) - return NULL; - - self = (EAPMethodFAST *) parent; + self = g_object_new (eap_method_fast_get_type (), NULL); self->sec_parent = ws_parent; self->is_editor = is_editor; diff --git a/panels/network/wireless-security/eap-method-fast.h b/panels/network/wireless-security/eap-method-fast.h index c19722058a..4401f5315d 100644 --- a/panels/network/wireless-security/eap-method-fast.h +++ b/panels/network/wireless-security/eap-method-fast.h @@ -20,20 +20,19 @@ * (C) Copyright 2012 Red Hat, Inc. */ -#ifndef EAP_METHOD_FAST_H -#define EAP_METHOD_FAST_H +#pragma once + +#include #include "wireless-security.h" -typedef struct _EAPMethodFAST EAPMethodFAST; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodFAST, eap_method_fast, EAP, METHOD_FAST, GObject) EAPMethodFAST *eap_method_fast_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only); -static void eap_method_fast_unref (EAPMethodFAST *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodFAST, eap_method_fast_unref) - -#endif /* EAP_METHOD_FAST_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index ef427eafc5..fe5997f0b0 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -33,7 +33,7 @@ #include "utils.h" struct _EAPMethodLEAP { - EAPMethod parent; + GObject parent; GtkBuilder *builder; GtkGrid *grid; @@ -48,6 +48,11 @@ struct _EAPMethodLEAP { gboolean editing_connection; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodLEAP, eap_method_leap, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + static void show_toggled_cb (EAPMethodLEAP *self) { @@ -183,15 +188,17 @@ widgets_unrealized (EAPMethodLEAP *self) } static void -destroy (EAPMethod *parent) +eap_method_leap_dispose (GObject *object) { - EAPMethodLEAP *self = (EAPMethodLEAP *) parent; + EAPMethodLEAP *self = EAP_METHOD_LEAP (object); g_clear_object (&self->builder); g_signal_handlers_disconnect_by_data (self->grid, self); g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->show_password_check, self); + + G_OBJECT_CLASS (eap_method_leap_parent_class)->dispose (object); } static void @@ -200,30 +207,41 @@ changed_cb (EAPMethodLEAP *self) wireless_security_notify_changed (self->ws_parent); } +static void +eap_method_leap_init (EAPMethodLEAP *self) +{ +} + +static void +eap_method_leap_class_init (EAPMethodLEAPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = eap_method_leap_dispose; +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_widget = get_widget; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; +} + EAPMethodLEAP * eap_method_leap_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean secrets_only) { EAPMethodLEAP *self; - EAPMethod *parent; NMSetting8021x *s_8021x = NULL; g_autoptr(GError) error = NULL; - parent = eap_method_init (sizeof (EAPMethodLEAP), - validate, - add_to_size_group, - fill_connection, - update_secrets, - get_widget, - get_default_field, - get_password_flags_name, - NULL, - destroy); - if (!parent) - return NULL; - - self = (EAPMethodLEAP *) parent; + self = g_object_new (eap_method_leap_get_type (), NULL); self->editing_connection = secrets_only ? FALSE : TRUE; self->ws_parent = ws_parent; diff --git a/panels/network/wireless-security/eap-method-leap.h b/panels/network/wireless-security/eap-method-leap.h index 2d205d7190..b8522ebabf 100644 --- a/panels/network/wireless-security/eap-method-leap.h +++ b/panels/network/wireless-security/eap-method-leap.h @@ -20,19 +20,16 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_LEAP_H -#define EAP_METHOD_LEAP_H +#pragma once #include "wireless-security.h" -typedef struct _EAPMethodLEAP EAPMethodLEAP; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodLEAP, eap_method_leap, EAP, METHOD_LEAP, GObject) EAPMethodLEAP *eap_method_leap_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean secrets_only); -static void eap_method_leap_unref (EAPMethodLEAP *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodLEAP, eap_method_leap_unref) - -#endif /* EAP_METHOD_LEAP_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-peap.c b/panels/network/wireless-security/eap-method-peap.c index 25b700f18b..70e1b3e8cb 100644 --- a/panels/network/wireless-security/eap-method-peap.c +++ b/panels/network/wireless-security/eap-method-peap.c @@ -35,7 +35,7 @@ #define I_METHOD_COLUMN 1 struct _EAPMethodPEAP { - EAPMethod parent; + GObject parent; GtkBuilder *builder; GtkEntry *anon_identity_entry; @@ -55,19 +55,26 @@ struct _EAPMethodPEAP { gboolean is_editor; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodPEAP, eap_method_peap, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + static void -destroy (EAPMethod *parent) +eap_method_peap_dispose (GObject *object) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + EAPMethodPEAP *self = EAP_METHOD_PEAP (object); g_clear_object (&self->builder); g_clear_object (&self->size_group); + + G_OBJECT_CLASS (eap_method_peap_parent_class)->dispose (object); } static gboolean -validate (EAPMethod *parent, GError **error) +validate (EAPMethod *method, GError **error) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); GtkTreeModel *model; GtkTreeIter iter; g_autoptr(EAPMethod) eap = NULL; @@ -102,9 +109,9 @@ ca_cert_not_required_toggled (EAPMethodPEAP *self) } static void -add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) +add_to_size_group (EAPMethod *method, GtkSizeGroup *group) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); GtkTreeModel *model; GtkTreeIter iter; g_autoptr(EAPMethod) eap = NULL; @@ -126,9 +133,9 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) } static void -fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) +fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); NMSetting8021x *s_8021x; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *text; @@ -154,7 +161,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla g_warning ("Couldn't read CA certificate '%s': %s", filename, error ? error->message : "(unknown)"); ca_cert_error = TRUE; } - eap_method_ca_cert_ignore_set (parent, connection, filename, ca_cert_error); + eap_method_ca_cert_ignore_set (method, connection, filename, ca_cert_error); peapver_active = gtk_combo_box_get_active (self->version_combo); switch (peapver_active) { @@ -286,31 +293,31 @@ inner_auth_combo_init (EAPMethodPEAP *self, } static void -update_secrets (EAPMethod *parent, NMConnection *connection) +update_secrets (EAPMethod *method, NMConnection *connection) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; - eap_method_phase2_update_secrets_helper (parent, + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); + eap_method_phase2_update_secrets_helper (method, connection, self->inner_auth_combo, I_METHOD_COLUMN); } static GtkWidget * -get_widget (EAPMethod *parent) +get_widget (EAPMethod *method) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); return GTK_WIDGET (self->grid); } static GtkWidget * -get_default_field (EAPMethod *parent) +get_default_field (EAPMethod *method) { - EAPMethodPEAP *self = (EAPMethodPEAP *) parent; + EAPMethodPEAP *self = EAP_METHOD_PEAP (method); return GTK_WIDGET (self->anon_identity_entry); } static const gchar * -get_password_flags_name (EAPMethod *parent) +get_password_flags_name (EAPMethod *method) { return NM_SETTING_802_1X_PASSWORD; } @@ -321,33 +328,44 @@ changed_cb (EAPMethodPEAP *self) wireless_security_notify_changed (self->sec_parent); } +static void +eap_method_peap_init (EAPMethodPEAP *self) +{ +} + +static void +eap_method_peap_class_init (EAPMethodPEAPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = eap_method_peap_dispose; +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_widget = get_widget; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; +} + EAPMethodPEAP * eap_method_peap_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only) { - EAPMethod *parent; EAPMethodPEAP *self; GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; g_autoptr(GError) error = NULL; - parent = eap_method_init (sizeof (EAPMethodPEAP), - validate, - add_to_size_group, - fill_connection, - update_secrets, - get_widget, - get_default_field, - get_password_flags_name, - NULL, - destroy); - if (!parent) - return NULL; - - self = (EAPMethodPEAP *) parent; + self = g_object_new (eap_method_peap_get_type (), NULL); self->sec_parent = ws_parent; self->is_editor = is_editor; @@ -388,7 +406,7 @@ eap_method_peap_new (WirelessSecurity *ws_parent, gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->ca_cert_button), filename); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), - !filename && eap_method_ca_cert_ignore_get (parent, connection)); + !filename && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection)); } inner_auth_combo_init (self, connection, s_8021x, secrets_only); diff --git a/panels/network/wireless-security/eap-method-peap.h b/panels/network/wireless-security/eap-method-peap.h index 45625fb933..64952c6892 100644 --- a/panels/network/wireless-security/eap-method-peap.h +++ b/panels/network/wireless-security/eap-method-peap.h @@ -20,20 +20,17 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_PEAP_H -#define EAP_METHOD_PEAP_H +#pragma once #include "wireless-security.h" -typedef struct _EAPMethodPEAP EAPMethodPEAP; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodPEAP, eap_method_peap, EAP, METHOD_PEAP, GObject) EAPMethodPEAP *eap_method_peap_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only); -static void eap_method_peap_unref (EAPMethodPEAP *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodPEAP, eap_method_peap_unref) - -#endif /* EAP_METHOD_PEAP_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index 599b440f63..2eabf64d7d 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -33,7 +33,7 @@ #include "utils.h" struct _EAPMethodSimple { - EAPMethod parent; + GObject parent; GtkBuilder *builder; GtkGrid *grid; @@ -51,6 +51,11 @@ struct _EAPMethodSimple { guint idle_func_id; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodSimple, eap_method_simple, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + static void show_toggled_cb (EAPMethodSimple *self) { @@ -68,9 +73,9 @@ always_ask_selected (GtkEntry *passwd_entry) } static gboolean -validate (EAPMethod *parent, GError **error) +validate (EAPMethod *method, GError **error) { - EAPMethodSimple *self = (EAPMethodSimple *)parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); const char *text; gboolean ret = TRUE; @@ -101,9 +106,9 @@ validate (EAPMethod *parent, GError **error) } static void -add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) +add_to_size_group (EAPMethod *method, GtkSizeGroup *group) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); gtk_size_group_add_widget (group, GTK_WIDGET (self->username_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label)); } @@ -126,9 +131,9 @@ static const EapType eap_table[EAP_METHOD_SIMPLE_TYPE_LAST] = { }; static void -fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags prev_flags) +fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags prev_flags) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); NMSetting8021x *s_8021x; gboolean not_saved = FALSE; NMSettingSecretFlags flags; @@ -140,11 +145,11 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla /* If this is the main EAP method, clear any existing methods because the * user-selected on will replace it. */ - if (eap_method_get_phase2 (parent) == FALSE) + if (eap_method_get_phase2 (method) == FALSE) nm_setting_802_1x_clear_eap_methods (s_8021x); eap_type = &eap_table[self->type]; - if (eap_method_get_phase2 (parent)) { + if (eap_method_get_phase2 (method)) { /* If the outer EAP method (TLS, TTLS, PEAP, etc) allows inner/phase2 * EAP methods (which only TTLS allows) *and* the inner/phase2 method * supports being an inner EAP method, then set PHASE2_AUTHEAP. @@ -183,9 +188,9 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla } static void -update_secrets (EAPMethod *parent, NMConnection *connection) +update_secrets (EAPMethod *method, NMConnection *connection) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); helper_fill_secret_entry (connection, self->password_entry, NM_TYPE_SETTING_802_1X, @@ -193,29 +198,29 @@ update_secrets (EAPMethod *parent, NMConnection *connection) } static GtkWidget * -get_widget (EAPMethod *parent) +get_widget (EAPMethod *method) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); return GTK_WIDGET (self->grid); } static GtkWidget * -get_default_field (EAPMethod *parent) +get_default_field (EAPMethod *method) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); return GTK_WIDGET (self->username_entry); } static const gchar * -get_password_flags_name (EAPMethod *parent) +get_password_flags_name (EAPMethod *method) { return NM_SETTING_802_1X_PASSWORD; } static const gboolean -get_phase2 (EAPMethod *parent) +get_phase2 (EAPMethod *method) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); return self->flags & EAP_METHOD_SIMPLE_FLAG_PHASE2; } @@ -283,9 +288,9 @@ widgets_unrealized (EAPMethodSimple *self) } static void -destroy (EAPMethod *parent) +eap_method_simple_dispose (GObject *object) { - EAPMethodSimple *self = (EAPMethodSimple *) parent; + EAPMethodSimple *self = EAP_METHOD_SIMPLE (object); g_clear_object (&self->builder); g_signal_handlers_disconnect_by_data (self->grid, self); @@ -295,6 +300,8 @@ destroy (EAPMethod *parent) g_signal_handlers_disconnect_by_data (self->show_password_check, self); nm_clear_g_source (&self->idle_func_id); + + G_OBJECT_CLASS (eap_method_simple_parent_class)->dispose (object); } static void @@ -303,31 +310,43 @@ changed_cb (EAPMethodSimple *self) wireless_security_notify_changed (self->ws_parent); } +static void +eap_method_simple_init (EAPMethodSimple *self) +{ +} + +static void +eap_method_simple_class_init (EAPMethodSimpleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = eap_method_simple_dispose; +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_widget = get_widget; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; + iface->get_phase2 = get_phase2; +} + EAPMethodSimple * eap_method_simple_new (WirelessSecurity *ws_parent, NMConnection *connection, EAPMethodSimpleType type, EAPMethodSimpleFlags flags) { - EAPMethod *parent; EAPMethodSimple *self; NMSetting8021x *s_8021x = NULL; g_autoptr(GError) error = NULL; - parent = eap_method_init (sizeof (EAPMethodSimple), - validate, - add_to_size_group, - fill_connection, - update_secrets, - get_widget, - get_default_field, - get_password_flags_name, - get_phase2, - destroy); - if (!parent) - return NULL; - - self = (EAPMethodSimple *) parent; + self = g_object_new (eap_method_simple_get_type (), NULL); self->ws_parent = ws_parent; self->flags = flags; self->type = type; diff --git a/panels/network/wireless-security/eap-method-simple.h b/panels/network/wireless-security/eap-method-simple.h index 8a2c3400ed..be418dd091 100644 --- a/panels/network/wireless-security/eap-method-simple.h +++ b/panels/network/wireless-security/eap-method-simple.h @@ -20,11 +20,14 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_SIMPLE_H -#define EAP_METHOD_SIMPLE_H +#pragma once #include "wireless-security.h" +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodSimple, eap_method_simple, EAP, METHOD_SIMPLE, GObject) + typedef enum { /* NOTE: when updating this table, also update eap_methods[] */ EAP_METHOD_SIMPLE_TYPE_PAP = 0, @@ -52,15 +55,9 @@ typedef enum { EAP_METHOD_SIMPLE_FLAG_SECRETS_ONLY = 0x08 } EAPMethodSimpleFlags; -typedef struct _EAPMethodSimple EAPMethodSimple; - EAPMethodSimple *eap_method_simple_new (WirelessSecurity *ws_parent, NMConnection *connection, EAPMethodSimpleType type, EAPMethodSimpleFlags flags); -static void eap_method_simple_unref (EAPMethodSimple *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodSimple, eap_method_simple_unref) - -#endif /* EAP_METHOD_SIMPLE_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-tls.c b/panels/network/wireless-security/eap-method-tls.c index 13e85689af..8263d56e61 100644 --- a/panels/network/wireless-security/eap-method-tls.c +++ b/panels/network/wireless-security/eap-method-tls.c @@ -33,7 +33,7 @@ #include "utils.h" struct _EAPMethodTLS { - EAPMethod parent; + GObject parent; GtkBuilder *builder; GtkFileChooserButton *ca_cert_button; @@ -56,12 +56,19 @@ struct _EAPMethodTLS { gboolean editing_connection; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodTLS, eap_method_tls, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + static void -destroy (EAPMethod *parent) +eap_method_tls_dispose (GObject *object) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (object); g_clear_object (&self->builder); + + G_OBJECT_CLASS (eap_method_tls_parent_class)->dispose (object); } static void @@ -74,9 +81,9 @@ show_toggled_cb (EAPMethodTLS *self) } static gboolean -validate (EAPMethod *parent, GError **error) +validate (EAPMethod *method, GError **error) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *password, *identity; g_autoptr(GError) ca_cert_error = NULL; @@ -146,9 +153,9 @@ ca_cert_not_required_toggled (EAPMethodTLS *self) } static void -add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) +add_to_size_group (EAPMethod *method, GtkSizeGroup *group) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); gtk_size_group_add_widget (group, GTK_WIDGET (self->ca_cert_not_required_check)); gtk_size_group_add_widget (group, GTK_WIDGET (self->identity_label)); @@ -159,9 +166,9 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) } static void -fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) +fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; NMSetting8021x *s_8021x; NMSettingSecretFlags secret_flags; @@ -246,13 +253,12 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla ca_cert_error = TRUE; } } - eap_method_ca_cert_ignore_set (parent, connection, ca_filename, ca_cert_error); + eap_method_ca_cert_ignore_set (method, connection, ca_filename, ca_cert_error); } static void -private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean changed) +private_key_picker_helper (EAPMethodTLS *self, const char *filename, gboolean changed) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; g_autoptr(NMSetting8021x) setting = NULL; NMSetting8021xCKFormat cert_format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *password; @@ -296,12 +302,12 @@ private_key_picker_helper (EAPMethod *parent, const char *filename, gboolean cha static void private_key_picker_file_set_cb (GtkWidget *chooser, gpointer user_data) { - EAPMethod *parent = (EAPMethod *) user_data; + EAPMethodTLS *self = user_data; g_autofree gchar *filename = NULL; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); if (filename) - private_key_picker_helper (parent, filename, TRUE); + private_key_picker_helper (self, filename, TRUE); } static void reset_filter (GtkWidget *widget, GParamSpec *spec, gpointer user_data) @@ -323,10 +329,10 @@ changed_cb (EAPMethodTLS *self) } static void -setup_filepicker (GtkFileChooserButton *button, +setup_filepicker (EAPMethodTLS *self, + GtkFileChooserButton *button, const char *title, WirelessSecurity *ws_parent, - EAPMethod *parent, NMSetting8021x *s_8021x, SchemeFunc scheme_func, PathFunc path_func, @@ -353,12 +359,12 @@ setup_filepicker (GtkFileChooserButton *button, if (privkey) { g_signal_connect (button, "selection-changed", (GCallback) private_key_picker_file_set_cb, - parent); + self); if (filename) - private_key_picker_helper (parent, filename, FALSE); + private_key_picker_helper (self, filename, FALSE); } - g_signal_connect_swapped (button, "selection-changed", G_CALLBACK (changed_cb), parent); + g_signal_connect_swapped (button, "selection-changed", G_CALLBACK (changed_cb), self); filter = eap_method_default_file_chooser_filter_new (privkey); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (button), filter); @@ -373,9 +379,9 @@ setup_filepicker (GtkFileChooserButton *button, } static void -update_secrets (EAPMethod *parent, NMConnection *connection) +update_secrets (EAPMethod *method, NMConnection *connection) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); NMSetting8021x *s_8021x; HelperSecretFunc password_func; SchemeFunc scheme_func; @@ -407,33 +413,59 @@ update_secrets (EAPMethod *parent, NMConnection *connection) } static GtkWidget * -get_widget (EAPMethod *parent) +get_widget (EAPMethod *method) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); return GTK_WIDGET (self->grid); } static GtkWidget * -get_default_field (EAPMethod *parent) +get_default_field (EAPMethod *method) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); return GTK_WIDGET (self->identity_entry); } static const gchar * -get_password_flags_name (EAPMethod *parent) +get_password_flags_name (EAPMethod *method) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); return self->password_flags_name; } static gboolean -get_phase2 (EAPMethod *parent) +get_phase2 (EAPMethod *method) { - EAPMethodTLS *self = (EAPMethodTLS *) parent; + EAPMethodTLS *self = EAP_METHOD_TLS (method); return self->phase2; } +static void +eap_method_tls_init (EAPMethodTLS *self) +{ +} + +static void +eap_method_tls_class_init (EAPMethodTLSClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = eap_method_tls_dispose; +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_widget = get_widget; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; + iface->get_phase2 = get_phase2; +} + EAPMethodTLS * eap_method_tls_new (WirelessSecurity *ws_parent, NMConnection *connection, @@ -441,25 +473,11 @@ eap_method_tls_new (WirelessSecurity *ws_parent, gboolean secrets_only) { EAPMethodTLS *self; - EAPMethod *parent; NMSetting8021x *s_8021x = NULL; gboolean ca_not_required = FALSE; g_autoptr(GError) error = NULL; - parent = eap_method_init (sizeof (EAPMethodTLS), - validate, - add_to_size_group, - fill_connection, - update_secrets, - get_widget, - get_default_field, - get_password_flags_name, - get_phase2, - destroy); - if (!parent) - return NULL; - - self = (EAPMethodTLS *) parent; + self = g_object_new (eap_method_tls_get_type (), NULL); self->phase2 = phase2; self->password_flags_name = phase2 ? NM_SETTING_802_1X_PHASE2_PRIVATE_KEY_PASSWORD : @@ -496,32 +514,35 @@ eap_method_tls_new (WirelessSecurity *ws_parent, if (s_8021x && nm_setting_802_1x_get_identity (s_8021x)) gtk_entry_set_text (self->identity_entry, nm_setting_802_1x_get_identity (s_8021x)); - setup_filepicker (self->user_cert_button, + setup_filepicker (self, + self->user_cert_button, _("Choose your personal certificate"), - ws_parent, parent, s_8021x, + ws_parent, s_8021x, phase2 ? nm_setting_802_1x_get_phase2_client_cert_scheme : nm_setting_802_1x_get_client_cert_scheme, phase2 ? nm_setting_802_1x_get_phase2_client_cert_path : nm_setting_802_1x_get_client_cert_path, FALSE, TRUE); - setup_filepicker (self->ca_cert_button, + setup_filepicker (self, + self->ca_cert_button, _("Choose a Certificate Authority certificate"), - ws_parent, parent, s_8021x, + ws_parent, s_8021x, phase2 ? nm_setting_802_1x_get_phase2_ca_cert_scheme : nm_setting_802_1x_get_ca_cert_scheme, phase2 ? nm_setting_802_1x_get_phase2_ca_cert_path : nm_setting_802_1x_get_ca_cert_path, FALSE, FALSE); - setup_filepicker (self->private_key_button, + setup_filepicker (self, + self->private_key_button, _("Choose your private key"), - ws_parent, parent, s_8021x, + ws_parent, s_8021x, phase2 ? nm_setting_802_1x_get_phase2_private_key_scheme : nm_setting_802_1x_get_private_key_scheme, phase2 ? nm_setting_802_1x_get_phase2_private_key_path : nm_setting_802_1x_get_private_key_path, TRUE, FALSE); - if (connection && eap_method_ca_cert_ignore_get (parent, connection)) + if (connection && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection)) ca_not_required = !gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (self->ca_cert_button)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), ca_not_required); /* Fill secrets, if any */ if (connection) - update_secrets (parent, connection); + update_secrets (EAP_METHOD (self), connection); g_signal_connect_swapped (self->private_key_password_entry, "changed", G_CALLBACK (changed_cb), self); diff --git a/panels/network/wireless-security/eap-method-tls.h b/panels/network/wireless-security/eap-method-tls.h index 341580f093..3507b0ffcc 100644 --- a/panels/network/wireless-security/eap-method-tls.h +++ b/panels/network/wireless-security/eap-method-tls.h @@ -20,20 +20,17 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_TLS_H -#define EAP_METHOD_TLS_H +#pragma once #include "wireless-security.h" -typedef struct _EAPMethodTLS EAPMethodTLS; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodTLS, eap_method_tls, EAP, METHOD_TLS, GObject) EAPMethodTLS *eap_method_tls_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean phase2, gboolean secrets_only); -static void eap_method_tls_unref (EAPMethodTLS *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodTLS, eap_method_tls_unref) - -#endif /* EAP_METHOD_TLS_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c index 9a9553dec4..e21c2f83ec 100644 --- a/panels/network/wireless-security/eap-method-ttls.c +++ b/panels/network/wireless-security/eap-method-ttls.c @@ -35,7 +35,7 @@ #define I_METHOD_COLUMN 1 struct _EAPMethodTTLS { - EAPMethod parent; + GObject parent; GtkBuilder *builder; GtkEntry *anon_identity_entry; @@ -55,19 +55,26 @@ struct _EAPMethodTTLS { gboolean is_editor; }; +static void eap_method_iface_init (EAPMethodInterface *); + +G_DEFINE_TYPE_WITH_CODE (EAPMethodTTLS, eap_method_ttls, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) + static void -destroy (EAPMethod *parent) +eap_method_ttls_dispose (GObject *object) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + EAPMethodTTLS *self = EAP_METHOD_TTLS (object); g_clear_object (&self->builder); g_clear_object (&self->size_group); + + G_OBJECT_CLASS (eap_method_ttls_parent_class)->dispose (object); } static gboolean -validate (EAPMethod *parent, GError **error) +validate (EAPMethod *method, GError **error) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); GtkTreeModel *model; GtkTreeIter iter; g_autoptr(EAPMethod) eap = NULL; @@ -102,9 +109,9 @@ ca_cert_not_required_toggled (EAPMethodTTLS *self) } static void -add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) +add_to_size_group (EAPMethod *method, GtkSizeGroup *group) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); GtkTreeModel *model; GtkTreeIter iter; g_autoptr(EAPMethod) eap = NULL; @@ -126,9 +133,9 @@ add_to_size_group (EAPMethod *parent, GtkSizeGroup *group) } static void -fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFlags flags) +fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); NMSetting8021x *s_8021x; NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; const char *text; @@ -157,7 +164,7 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla g_warning ("Couldn't read CA certificate '%s': %s", filename, error ? error->message : "(unknown)"); ca_cert_error = TRUE; } - eap_method_ca_cert_ignore_set (parent, connection, filename, ca_cert_error); + eap_method_ca_cert_ignore_set (method, connection, filename, ca_cert_error); model = gtk_combo_box_get_model (self->inner_auth_combo); gtk_combo_box_get_active_iter (self->inner_auth_combo, &iter); @@ -339,31 +346,31 @@ inner_auth_combo_init (EAPMethodTTLS *self, } static void -update_secrets (EAPMethod *parent, NMConnection *connection) +update_secrets (EAPMethod *method, NMConnection *connection) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; - eap_method_phase2_update_secrets_helper (parent, + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); + eap_method_phase2_update_secrets_helper (method, connection, self->inner_auth_combo, I_METHOD_COLUMN); } static GtkWidget * -get_widget (EAPMethod *parent) +get_widget (EAPMethod *method) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); return GTK_WIDGET (self->grid); } static GtkWidget * -get_default_field (EAPMethod *parent) +get_default_field (EAPMethod *method) { - EAPMethodTTLS *self = (EAPMethodTTLS *) parent; + EAPMethodTTLS *self = EAP_METHOD_TTLS (method); return GTK_WIDGET (self->anon_identity_entry); } static const gchar * -get_password_flags_name (EAPMethod *parent) +get_password_flags_name (EAPMethod *method) { return NM_SETTING_802_1X_PASSWORD; } @@ -374,33 +381,44 @@ changed_cb (EAPMethodTTLS *self) wireless_security_notify_changed (self->sec_parent); } +static void +eap_method_ttls_init (EAPMethodTTLS *self) +{ +} + +static void +eap_method_ttls_class_init (EAPMethodTTLSClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = eap_method_ttls_dispose; +} + +static void +eap_method_iface_init (EAPMethodInterface *iface) +{ + iface->validate = validate; + iface->add_to_size_group = add_to_size_group; + iface->fill_connection = fill_connection; + iface->update_secrets = update_secrets; + iface->get_widget = get_widget; + iface->get_default_field = get_default_field; + iface->get_password_flags_name = get_password_flags_name; +} + EAPMethodTTLS * eap_method_ttls_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only) { - EAPMethod *parent; EAPMethodTTLS *self; GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; g_autoptr(GError) error = NULL; - parent = eap_method_init (sizeof (EAPMethodTTLS), - validate, - add_to_size_group, - fill_connection, - update_secrets, - get_widget, - get_default_field, - get_password_flags_name, - NULL, - destroy); - if (!parent) - return NULL; - - self = (EAPMethodTTLS *) parent; + self = g_object_new (eap_method_ttls_get_type (), NULL); self->sec_parent = ws_parent; self->is_editor = is_editor; @@ -441,7 +459,7 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (self->ca_cert_button), filename); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->ca_cert_not_required_check), - !filename && eap_method_ca_cert_ignore_get (parent, connection)); + !filename && eap_method_ca_cert_ignore_get (EAP_METHOD (self), connection)); } if (s_8021x && nm_setting_802_1x_get_anonymous_identity (s_8021x)) diff --git a/panels/network/wireless-security/eap-method-ttls.h b/panels/network/wireless-security/eap-method-ttls.h index 836a6d9e6a..58af578059 100644 --- a/panels/network/wireless-security/eap-method-ttls.h +++ b/panels/network/wireless-security/eap-method-ttls.h @@ -20,20 +20,17 @@ * (C) Copyright 2007 - 2010 Red Hat, Inc. */ -#ifndef EAP_METHOD_TTLS_H -#define EAP_METHOD_TTLS_H +#pragma once #include "wireless-security.h" -typedef struct _EAPMethodTTLS EAPMethodTTLS; +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (EAPMethodTTLS, eap_method_ttls, EAP, METHOD_TTLS, GObject) EAPMethodTTLS *eap_method_ttls_new (WirelessSecurity *ws_parent, NMConnection *connection, gboolean is_editor, gboolean secrets_only); -static void eap_method_ttls_unref (EAPMethodTTLS *method) { eap_method_unref (EAP_METHOD (method)); } -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethodTTLS, eap_method_ttls_unref) - -#endif /* EAP_METHOD_TTLS_H */ - +G_END_DECLS diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c index 3bad3d9b66..e1a147c03f 100644 --- a/panels/network/wireless-security/eap-method.c +++ b/panels/network/wireless-security/eap-method.c @@ -33,18 +33,11 @@ #include "utils.h" #include "helpers.h" -GType -eap_method_get_type (void) -{ - static GType type_id = 0; - - if (!type_id) { - type_id = g_boxed_type_register_static ("CcEAPMethod", - (GBoxedCopyFunc) eap_method_ref, - (GBoxedFreeFunc) eap_method_unref); - } +G_DEFINE_INTERFACE (EAPMethod, eap_method, G_TYPE_OBJECT) - return type_id; +static void +eap_method_default_init (EAPMethodInterface *iface) +{ } GtkWidget * @@ -52,7 +45,7 @@ eap_method_get_widget (EAPMethod *self) { g_return_val_if_fail (self != NULL, NULL); - return self->get_widget (self); + return EAP_METHOD_GET_IFACE (self)->get_widget (self); } GtkWidget * @@ -60,7 +53,7 @@ eap_method_get_default_field (EAPMethod *self) { g_return_val_if_fail (self != NULL, NULL); - return self->get_default_field (self); + return EAP_METHOD_GET_IFACE (self)->get_default_field (self); } const gchar * @@ -68,8 +61,8 @@ 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); + if (EAP_METHOD_GET_IFACE (self)->get_password_flags_name) + return EAP_METHOD_GET_IFACE (self)->get_password_flags_name (self); else return NULL; } @@ -79,8 +72,8 @@ eap_method_get_phase2 (EAPMethod *self) { g_return_val_if_fail (self != NULL, FALSE); - if (self->get_phase2) - return self->get_phase2 (self); + if (EAP_METHOD_GET_IFACE (self)->get_phase2) + return EAP_METHOD_GET_IFACE (self)->get_phase2 (self); else return FALSE; } @@ -92,8 +85,7 @@ eap_method_validate (EAPMethod *self, GError **error) g_return_val_if_fail (self != NULL, FALSE); - g_assert (self->validate); - result = (*(self->validate)) (self, error); + result = (*(EAP_METHOD_GET_IFACE (self)->validate)) (self, error); if (!result && error && !*error) g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("undefined error in 802.1X security (wpa-eap)")); return result; @@ -105,8 +97,7 @@ eap_method_add_to_size_group (EAPMethod *self, GtkSizeGroup *group) g_return_if_fail (self != NULL); g_return_if_fail (group != NULL); - g_assert (self->add_to_size_group); - return (*(self->add_to_size_group)) (self, group); + return (*(EAP_METHOD_GET_IFACE (self)->add_to_size_group)) (self, group); } void @@ -117,8 +108,7 @@ eap_method_fill_connection (EAPMethod *self, g_return_if_fail (self != NULL); g_return_if_fail (connection != NULL); - g_assert (self->fill_connection); - return (*(self->fill_connection)) (self, connection, flags); + return (*(EAP_METHOD_GET_IFACE (self)->fill_connection)) (self, connection, flags); } void @@ -141,72 +131,12 @@ eap_method_phase2_update_secrets_helper (EAPMethod *self, g_autoptr(EAPMethod) eap = NULL; gtk_tree_model_get (model, &iter, column, &eap, -1); - if (eap && eap->update_secrets) - eap->update_secrets (self, connection); + if (eap && EAP_METHOD_GET_IFACE (eap)->update_secrets) + EAP_METHOD_GET_IFACE (eap)->update_secrets (self, connection); } while (gtk_tree_model_iter_next (model, &iter)); } } -EAPMethod * -eap_method_init (gsize obj_size, - EMValidateFunc validate, - EMAddToSizeGroupFunc add_to_size_group, - EMFillConnectionFunc fill_connection, - EMUpdateSecretsFunc update_secrets, - EMGetWidgetFunc get_widget, - EMGetWidgetFunc get_default_field, - EMGetStringFunc get_password_flags_name, - EMGetBooleanFunc get_phase2, - EMDestroyFunc destroy) -{ - g_autoptr(EAPMethod) self = NULL; - - g_return_val_if_fail (obj_size > 0, NULL); - - self = g_slice_alloc0 (obj_size); - g_assert (self); - - self->refcount = 1; - self->obj_size = obj_size; - self->validate = validate; - self->add_to_size_group = add_to_size_group; - self->fill_connection = fill_connection; - self->update_secrets = update_secrets; - self->get_widget = get_widget; - self->get_default_field = get_default_field; - self->get_password_flags_name = get_password_flags_name; - self->get_phase2 = get_phase2; - self->destroy = destroy; - - return g_steal_pointer (&self); -} - - -EAPMethod * -eap_method_ref (EAPMethod *self) -{ - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (self->refcount > 0, NULL); - - self->refcount++; - return self; -} - -void -eap_method_unref (EAPMethod *self) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (self->refcount > 0); - - self->refcount--; - if (self->refcount == 0) { - if (self->destroy) - self->destroy (self); - - g_slice_free1 (self->obj_size, self); - } -} - gboolean eap_method_validate_filepicker (GtkFileChooser *chooser, guint32 item_type, diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index 199dbfc066..3910a9e9f1 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -20,39 +20,27 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef EAP_METHOD_H -#define EAP_METHOD_H +#pragma once +#include #include -typedef struct _EAPMethod EAPMethod; - -typedef void (*EMAddToSizeGroupFunc) (EAPMethod *method, GtkSizeGroup *group); -typedef void (*EMFillConnectionFunc) (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); -typedef void (*EMUpdateSecretsFunc) (EAPMethod *method, NMConnection *connection); -typedef void (*EMDestroyFunc) (EAPMethod *method); -typedef gboolean (*EMValidateFunc) (EAPMethod *method, GError **error); -typedef GtkWidget* (*EMGetWidgetFunc) (EAPMethod *method); -typedef const gchar* (*EMGetStringFunc) (EAPMethod *method); -typedef gboolean (*EMGetBooleanFunc) (EAPMethod *method); - -struct _EAPMethod { - guint32 refcount; - gsize obj_size; - - EMAddToSizeGroupFunc add_to_size_group; - EMFillConnectionFunc fill_connection; - EMUpdateSecretsFunc update_secrets; - EMValidateFunc validate; - EMGetWidgetFunc get_widget; - EMGetWidgetFunc get_default_field; - EMGetStringFunc get_password_flags_name; - EMGetBooleanFunc get_phase2; - EMDestroyFunc destroy; -}; +G_BEGIN_DECLS + +G_DECLARE_INTERFACE (EAPMethod, eap_method, EAP, METHOD, GObject) -#define EAP_METHOD(x) ((EAPMethod *) x) +struct _EAPMethodInterface { + GTypeInterface g_iface; + void (*add_to_size_group) (EAPMethod *method, GtkSizeGroup *group); + void (*fill_connection) (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); + void (*update_secrets) (EAPMethod *method, NMConnection *connection); + gboolean (*validate) (EAPMethod *method, GError **error); + GtkWidget* (*get_widget) (EAPMethod *method); + GtkWidget* (*get_default_field) (EAPMethod *method); + const gchar* (*get_password_flags_name) (EAPMethod *method); + gboolean (*get_phase2) (EAPMethod *method); +}; GtkWidget *eap_method_get_widget (EAPMethod *method); @@ -70,25 +58,8 @@ void eap_method_fill_connection (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); -EAPMethod *eap_method_ref (EAPMethod *method); - -void eap_method_unref (EAPMethod *method); - -GType eap_method_get_type (void); - /* Below for internal use only */ -EAPMethod *eap_method_init (gsize obj_size, - EMValidateFunc validate, - EMAddToSizeGroupFunc add_to_size_group, - EMFillConnectionFunc fill_connection, - EMUpdateSecretsFunc update_secrets, - EMGetWidgetFunc get_widget, - EMGetWidgetFunc get_default_field, - EMGetStringFunc get_password_flags_name, - EMGetBooleanFunc get_phase2, - EMDestroyFunc destroy); - GtkFileFilter * eap_method_default_file_chooser_filter_new (gboolean privkey); gboolean eap_method_is_encrypted_private_key (const char *path); @@ -122,6 +93,4 @@ gboolean eap_method_ca_cert_ignore_get (EAPMethod *method, NMConnection *connect void eap_method_ca_cert_ignore_save (NMConnection *connection); void eap_method_ca_cert_ignore_load (NMConnection *connection); -G_DEFINE_AUTOPTR_CLEANUP_FUNC (EAPMethod, eap_method_unref) - -#endif /* EAP_METHOD_H */ +G_END_DECLS -- GitLab From 0f1cff9130eb32b0b78557415a77ad14f957d44e Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 11:35:25 +1300 Subject: [PATCH 18/39] network: Convert EAPMethod classes to GtkTemplates --- .../wireless-security/eap-method-fast.c | 55 +++++---------- .../wireless-security/eap-method-fast.h | 3 +- .../wireless-security/eap-method-fast.ui | 4 +- .../wireless-security/eap-method-leap.c | 45 +++++-------- .../wireless-security/eap-method-leap.h | 5 +- .../wireless-security/eap-method-leap.ui | 4 +- .../wireless-security/eap-method-peap.c | 57 ++++++---------- .../wireless-security/eap-method-peap.h | 5 +- .../wireless-security/eap-method-peap.ui | 4 +- .../wireless-security/eap-method-simple.c | 45 +++++-------- .../wireless-security/eap-method-simple.h | 5 +- .../wireless-security/eap-method-simple.ui | 4 +- .../wireless-security/eap-method-tls.c | 67 ++++++------------- .../wireless-security/eap-method-tls.h | 5 +- .../wireless-security/eap-method-tls.ui | 4 +- .../wireless-security/eap-method-ttls.c | 57 ++++++---------- .../wireless-security/eap-method-ttls.h | 5 +- .../wireless-security/eap-method-ttls.ui | 4 +- panels/network/wireless-security/eap-method.c | 8 --- panels/network/wireless-security/eap-method.h | 5 +- .../wireless-security/wireless-security.c | 8 +-- 21 files changed, 143 insertions(+), 256 deletions(-) diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index df8bf77df0..a88d67e91a 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -36,12 +36,10 @@ #define I_METHOD_COLUMN 1 struct _EAPMethodFAST { - GObject parent; + GtkGrid parent; - GtkBuilder *builder; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; - GtkGrid *grid; GtkComboBox *inner_auth_combo; GtkLabel *inner_auth_label; GtkBox *inner_auth_box; @@ -57,7 +55,7 @@ struct _EAPMethodFAST { static void eap_method_iface_init (EAPMethodInterface *); -G_DEFINE_TYPE_WITH_CODE (EAPMethodFAST, eap_method_fast, G_TYPE_OBJECT, +G_DEFINE_TYPE_WITH_CODE (EAPMethodFAST, eap_method_fast, GTK_TYPE_GRID, G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) static void @@ -65,7 +63,6 @@ eap_method_fast_dispose (GObject *object) { EAPMethodFAST *self = EAP_METHOD_FAST (object); - g_clear_object (&self->builder); g_clear_object (&self->size_group); G_OBJECT_CLASS (eap_method_fast_parent_class)->dispose (object); @@ -185,7 +182,6 @@ inner_auth_combo_changed_cb (EAPMethodFAST *self) GList *elt, *children; GtkTreeModel *model; GtkTreeIter iter; - GtkWidget *eap_widget; /* Remove any previous wireless security widgets */ children = gtk_container_get_children (GTK_CONTAINER (self->inner_auth_box)); @@ -198,13 +194,10 @@ inner_auth_combo_changed_cb (EAPMethodFAST *self) gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1); g_assert (eap); - eap_widget = eap_method_get_widget (eap); - g_assert (eap_widget); - gtk_widget_unparent (eap_widget); - + gtk_widget_unparent (GTK_WIDGET (eap)); if (self->size_group) eap_method_add_to_size_group (eap, self->size_group); - gtk_container_add (GTK_CONTAINER (self->inner_auth_box), eap_widget); + gtk_container_add (GTK_CONTAINER (self->inner_auth_box), g_object_ref (GTK_WIDGET (eap))); wireless_security_notify_changed (self->sec_parent); } @@ -282,13 +275,6 @@ update_secrets (EAPMethod *parent, NMConnection *connection) I_METHOD_COLUMN); } -static GtkWidget * -get_widget (EAPMethod *parent) -{ - EAPMethodFAST *self = (EAPMethodFAST *) parent; - return GTK_WIDGET (self->grid); -} - static GtkWidget * get_default_field (EAPMethod *parent) { @@ -322,14 +308,28 @@ changed_cb (EAPMethodFAST *self) static void eap_method_fast_init (EAPMethodFAST *self) { + gtk_widget_init_template (GTK_WIDGET (self)); } static void eap_method_fast_class_init (EAPMethodFASTClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->dispose = eap_method_fast_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-fast.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, anon_identity_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, anon_identity_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, inner_auth_combo); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, inner_auth_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, inner_auth_box); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, pac_file_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, pac_file_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, pac_provision_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodFAST, pac_provision_combo); } static void @@ -339,7 +339,6 @@ eap_method_iface_init (EAPMethodInterface *iface) iface->add_to_size_group = add_to_size_group; iface->fill_connection = fill_connection; iface->update_secrets = update_secrets; - iface->get_widget = get_widget; iface->get_default_field = get_default_field; iface->get_password_flags_name = get_password_flags_name; } @@ -355,29 +354,11 @@ eap_method_fast_new (WirelessSecurity *ws_parent, NMSetting8021x *s_8021x = NULL; const char *filename; gboolean provisioning_enabled = TRUE; - g_autoptr(GError) error = NULL; self = g_object_new (eap_method_fast_get_type (), NULL); self->sec_parent = ws_parent; self->is_editor = is_editor; - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-fast.ui", &error)) { - g_warning ("Couldn't load UI builder resource: %s", error->message); - return NULL; - } - - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (self->builder, "anon_identity_label")); - self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "inner_auth_label")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (self->builder, "inner_auth_box")); - self->pac_file_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "pac_file_button")); - self->pac_file_label = GTK_LABEL (gtk_builder_get_object (self->builder, "pac_file_label")); - self->pac_provision_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "pac_provision_check")); - self->pac_provision_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "pac_provision_combo")); - if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); diff --git a/panels/network/wireless-security/eap-method-fast.h b/panels/network/wireless-security/eap-method-fast.h index 4401f5315d..474571d577 100644 --- a/panels/network/wireless-security/eap-method-fast.h +++ b/panels/network/wireless-security/eap-method-fast.h @@ -22,13 +22,14 @@ #pragma once +#include #include #include "wireless-security.h" G_BEGIN_DECLS -G_DECLARE_FINAL_TYPE (EAPMethodFAST, eap_method_fast, EAP, METHOD_FAST, GObject) +G_DECLARE_FINAL_TYPE (EAPMethodFAST, eap_method_fast, EAP, METHOD_FAST, GtkGrid) EAPMethodFAST *eap_method_fast_new (WirelessSecurity *ws_parent, NMConnection *connection, diff --git a/panels/network/wireless-security/eap-method-fast.ui b/panels/network/wireless-security/eap-method-fast.ui index c6470d1ed1..28964b427e 100644 --- a/panels/network/wireless-security/eap-method-fast.ui +++ b/panels/network/wireless-security/eap-method-fast.ui @@ -29,7 +29,7 @@ - + diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index fe5997f0b0..55e818b495 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -33,10 +33,8 @@ #include "utils.h" struct _EAPMethodLEAP { - GObject parent; + GtkGrid parent; - GtkBuilder *builder; - GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; GtkCheckButton *show_password_check; @@ -50,7 +48,7 @@ struct _EAPMethodLEAP { static void eap_method_iface_init (EAPMethodInterface *); -G_DEFINE_TYPE_WITH_CODE (EAPMethodLEAP, eap_method_leap, G_TYPE_OBJECT, +G_DEFINE_TYPE_WITH_CODE (EAPMethodLEAP, eap_method_leap, GTK_TYPE_GRID, G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) static void @@ -133,13 +131,6 @@ update_secrets (EAPMethod *parent, NMConnection *connection) (HelperSecretFunc) nm_setting_802_1x_get_password); } -static GtkWidget * -get_widget (EAPMethod *parent) -{ - EAPMethodLEAP *self = (EAPMethodLEAP *) parent; - return GTK_WIDGET (self->grid); -} - static GtkWidget * get_default_field (EAPMethod *parent) { @@ -192,8 +183,7 @@ eap_method_leap_dispose (GObject *object) { EAPMethodLEAP *self = EAP_METHOD_LEAP (object); - g_clear_object (&self->builder); - g_signal_handlers_disconnect_by_data (self->grid, self); + g_signal_handlers_disconnect_by_data (self, self); g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->show_password_check, self); @@ -210,14 +200,24 @@ changed_cb (EAPMethodLEAP *self) static void eap_method_leap_init (EAPMethodLEAP *self) { + gtk_widget_init_template (GTK_WIDGET (self)); } static void eap_method_leap_class_init (EAPMethodLEAPClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->dispose = eap_method_leap_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-leap.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, password_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, password_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, show_password_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, username_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodLEAP, username_label); } static void @@ -227,7 +227,6 @@ eap_method_iface_init (EAPMethodInterface *iface) iface->add_to_size_group = add_to_size_group; iface->fill_connection = fill_connection; iface->update_secrets = update_secrets; - iface->get_widget = get_widget; iface->get_default_field = get_default_field; iface->get_password_flags_name = get_password_flags_name; } @@ -239,27 +238,13 @@ eap_method_leap_new (WirelessSecurity *ws_parent, { EAPMethodLEAP *self; NMSetting8021x *s_8021x = NULL; - g_autoptr(GError) error = NULL; self = g_object_new (eap_method_leap_get_type (), NULL); self->editing_connection = secrets_only ? FALSE : TRUE; self->ws_parent = ws_parent; - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-leap.ui", &error)) { - g_warning ("Couldn't load UI builder resource: %s", error->message); - return NULL; - } - - self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password_entry")); - self->password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); - self->username_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "username_entry")); - self->username_label = GTK_LABEL (gtk_builder_get_object (self->builder, "username_label")); - - g_signal_connect_swapped (self->grid, "realize", G_CALLBACK (widgets_realized), self); - g_signal_connect_swapped (self->grid, "unrealize", G_CALLBACK (widgets_unrealized), self); + g_signal_connect_swapped (self, "realize", G_CALLBACK (widgets_realized), self); + g_signal_connect_swapped (self, "unrealize", G_CALLBACK (widgets_unrealized), self); g_signal_connect_swapped (self->username_entry, "changed", G_CALLBACK (changed_cb), self); diff --git a/panels/network/wireless-security/eap-method-leap.h b/panels/network/wireless-security/eap-method-leap.h index b8522ebabf..5b34916431 100644 --- a/panels/network/wireless-security/eap-method-leap.h +++ b/panels/network/wireless-security/eap-method-leap.h @@ -22,11 +22,14 @@ #pragma once +#include +#include + #include "wireless-security.h" G_BEGIN_DECLS -G_DECLARE_FINAL_TYPE (EAPMethodLEAP, eap_method_leap, EAP, METHOD_LEAP, GObject) +G_DECLARE_FINAL_TYPE (EAPMethodLEAP, eap_method_leap, EAP, METHOD_LEAP, GtkGrid) EAPMethodLEAP *eap_method_leap_new (WirelessSecurity *ws_parent, NMConnection *connection, diff --git a/panels/network/wireless-security/eap-method-leap.ui b/panels/network/wireless-security/eap-method-leap.ui index b08802c15e..4e289fba84 100644 --- a/panels/network/wireless-security/eap-method-leap.ui +++ b/panels/network/wireless-security/eap-method-leap.ui @@ -1,7 +1,7 @@ - + diff --git a/panels/network/wireless-security/eap-method-peap.c b/panels/network/wireless-security/eap-method-peap.c index 70e1b3e8cb..3b4353bb20 100644 --- a/panels/network/wireless-security/eap-method-peap.c +++ b/panels/network/wireless-security/eap-method-peap.c @@ -35,15 +35,13 @@ #define I_METHOD_COLUMN 1 struct _EAPMethodPEAP { - GObject parent; + GtkGrid parent; - GtkBuilder *builder; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; GtkFileChooserButton *ca_cert_button; GtkLabel *ca_cert_label; GtkCheckButton *ca_cert_not_required_check; - GtkGrid *grid; GtkBox *inner_auth_box; GtkComboBox *inner_auth_combo; GtkLabel *inner_auth_label; @@ -57,7 +55,7 @@ struct _EAPMethodPEAP { static void eap_method_iface_init (EAPMethodInterface *); -G_DEFINE_TYPE_WITH_CODE (EAPMethodPEAP, eap_method_peap, G_TYPE_OBJECT, +G_DEFINE_TYPE_WITH_CODE (EAPMethodPEAP, eap_method_peap, GTK_TYPE_GRID, G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) static void @@ -65,7 +63,6 @@ eap_method_peap_dispose (GObject *object) { EAPMethodPEAP *self = EAP_METHOD_PEAP (object); - g_clear_object (&self->builder); g_clear_object (&self->size_group); G_OBJECT_CLASS (eap_method_peap_parent_class)->dispose (object); @@ -191,7 +188,6 @@ inner_auth_combo_changed_cb (EAPMethodPEAP *self) GList *elt, *children; GtkTreeModel *model; GtkTreeIter iter; - GtkWidget *eap_widget; /* Remove any previous wireless security widgets */ children = gtk_container_get_children (GTK_CONTAINER (self->inner_auth_box)); @@ -203,13 +199,10 @@ inner_auth_combo_changed_cb (EAPMethodPEAP *self) gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1); g_assert (eap); - eap_widget = eap_method_get_widget (eap); - g_assert (eap_widget); - gtk_widget_unparent (eap_widget); - + gtk_widget_unparent (GTK_WIDGET (eap)); if (self->size_group) eap_method_add_to_size_group (eap, self->size_group); - gtk_container_add (GTK_CONTAINER (self->inner_auth_box), eap_widget); + gtk_container_add (GTK_CONTAINER (self->inner_auth_box), g_object_ref (GTK_WIDGET (eap))); wireless_security_notify_changed (self->sec_parent); } @@ -302,13 +295,6 @@ update_secrets (EAPMethod *method, NMConnection *connection) I_METHOD_COLUMN); } -static GtkWidget * -get_widget (EAPMethod *method) -{ - EAPMethodPEAP *self = EAP_METHOD_PEAP (method); - return GTK_WIDGET (self->grid); -} - static GtkWidget * get_default_field (EAPMethod *method) { @@ -331,14 +317,29 @@ changed_cb (EAPMethodPEAP *self) static void eap_method_peap_init (EAPMethodPEAP *self) { + gtk_widget_init_template (GTK_WIDGET (self)); } static void eap_method_peap_class_init (EAPMethodPEAPClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->dispose = eap_method_peap_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-peap.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, anon_identity_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, anon_identity_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, ca_cert_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, ca_cert_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, ca_cert_not_required_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, inner_auth_box); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, inner_auth_combo); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, inner_auth_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, version_combo); + gtk_widget_class_bind_template_child (widget_class, EAPMethodPEAP, version_label); } static void @@ -348,7 +349,6 @@ eap_method_iface_init (EAPMethodInterface *iface) iface->add_to_size_group = add_to_size_group; iface->fill_connection = fill_connection; iface->update_secrets = update_secrets; - iface->get_widget = get_widget; iface->get_default_field = get_default_field; iface->get_password_flags_name = get_password_flags_name; } @@ -363,30 +363,11 @@ eap_method_peap_new (WirelessSecurity *ws_parent, GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; - g_autoptr(GError) error = NULL; self = g_object_new (eap_method_peap_get_type (), NULL); self->sec_parent = ws_parent; self->is_editor = is_editor; - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-peap.ui", &error)) { - g_warning ("Couldn't load UI builder resource: %s", error->message); - return NULL; - } - - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (self->builder, "anon_identity_label")); - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (self->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_not_required_check")); - self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (self->builder, "inner_auth_box")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "inner_auth_label")); - self->version_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "version_combo")); - self->version_label = GTK_LABEL (gtk_builder_get_object (self->builder, "version_label")); - if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); diff --git a/panels/network/wireless-security/eap-method-peap.h b/panels/network/wireless-security/eap-method-peap.h index 64952c6892..b79641799f 100644 --- a/panels/network/wireless-security/eap-method-peap.h +++ b/panels/network/wireless-security/eap-method-peap.h @@ -22,11 +22,14 @@ #pragma once +#include +#include + #include "wireless-security.h" G_BEGIN_DECLS -G_DECLARE_FINAL_TYPE (EAPMethodPEAP, eap_method_peap, EAP, METHOD_PEAP, GObject) +G_DECLARE_FINAL_TYPE (EAPMethodPEAP, eap_method_peap, EAP, METHOD_PEAP, GtkGrid) EAPMethodPEAP *eap_method_peap_new (WirelessSecurity *ws_parent, NMConnection *connection, diff --git a/panels/network/wireless-security/eap-method-peap.ui b/panels/network/wireless-security/eap-method-peap.ui index 8190d48985..baa6c5cb66 100644 --- a/panels/network/wireless-security/eap-method-peap.ui +++ b/panels/network/wireless-security/eap-method-peap.ui @@ -29,7 +29,7 @@ - + diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index 2eabf64d7d..1125838771 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -33,10 +33,8 @@ #include "utils.h" struct _EAPMethodSimple { - GObject parent; + GtkGrid parent; - GtkBuilder *builder; - GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; GtkToggleButton *show_password_check; @@ -53,7 +51,7 @@ struct _EAPMethodSimple { static void eap_method_iface_init (EAPMethodInterface *); -G_DEFINE_TYPE_WITH_CODE (EAPMethodSimple, eap_method_simple, G_TYPE_OBJECT, +G_DEFINE_TYPE_WITH_CODE (EAPMethodSimple, eap_method_simple, GTK_TYPE_GRID, G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) static void @@ -197,13 +195,6 @@ update_secrets (EAPMethod *method, NMConnection *connection) (HelperSecretFunc) nm_setting_802_1x_get_password); } -static GtkWidget * -get_widget (EAPMethod *method) -{ - EAPMethodSimple *self = EAP_METHOD_SIMPLE (method); - return GTK_WIDGET (self->grid); -} - static GtkWidget * get_default_field (EAPMethod *method) { @@ -292,8 +283,7 @@ eap_method_simple_dispose (GObject *object) { EAPMethodSimple *self = EAP_METHOD_SIMPLE (object); - g_clear_object (&self->builder); - g_signal_handlers_disconnect_by_data (self->grid, self); + g_signal_handlers_disconnect_by_data (self, self); g_signal_handlers_disconnect_by_data (self->username_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self->ws_parent); g_signal_handlers_disconnect_by_data (self->password_entry, self); @@ -313,14 +303,24 @@ changed_cb (EAPMethodSimple *self) static void eap_method_simple_init (EAPMethodSimple *self) { + gtk_widget_init_template (GTK_WIDGET (self)); } static void eap_method_simple_class_init (EAPMethodSimpleClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->dispose = eap_method_simple_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-simple.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, password_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, username_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, password_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, show_password_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodSimple, username_entry); } static void @@ -330,7 +330,6 @@ eap_method_iface_init (EAPMethodInterface *iface) iface->add_to_size_group = add_to_size_group; iface->fill_connection = fill_connection; iface->update_secrets = update_secrets; - iface->get_widget = get_widget; iface->get_default_field = get_default_field; iface->get_password_flags_name = get_password_flags_name; iface->get_phase2 = get_phase2; @@ -344,7 +343,6 @@ eap_method_simple_new (WirelessSecurity *ws_parent, { EAPMethodSimple *self; NMSetting8021x *s_8021x = NULL; - g_autoptr(GError) error = NULL; self = g_object_new (eap_method_simple_get_type (), NULL); self->ws_parent = ws_parent; @@ -352,21 +350,8 @@ eap_method_simple_new (WirelessSecurity *ws_parent, self->type = type; g_assert (type < EAP_METHOD_SIMPLE_TYPE_LAST); - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-simple.ui", &error)) { - g_warning ("Couldn't load UI builder resource: %s", error->message); - return NULL; - } - - self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); - self->password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "password_label")); - self->username_label = GTK_LABEL (gtk_builder_get_object (self->builder, "username_label")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password_entry")); - self->show_password_check = GTK_TOGGLE_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); - self->username_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "username_entry")); - - g_signal_connect_swapped (self->grid, "realize", G_CALLBACK (widgets_realized), self); - g_signal_connect_swapped (self->grid, "unrealize", G_CALLBACK (widgets_unrealized), self); + g_signal_connect_swapped (self, "realize", G_CALLBACK (widgets_realized), self); + g_signal_connect_swapped (self, "unrealize", G_CALLBACK (widgets_unrealized), self); g_signal_connect_swapped (self->username_entry, "changed", G_CALLBACK (changed_cb), self); diff --git a/panels/network/wireless-security/eap-method-simple.h b/panels/network/wireless-security/eap-method-simple.h index be418dd091..527b7dbc45 100644 --- a/panels/network/wireless-security/eap-method-simple.h +++ b/panels/network/wireless-security/eap-method-simple.h @@ -22,11 +22,14 @@ #pragma once +#include +#include + #include "wireless-security.h" G_BEGIN_DECLS -G_DECLARE_FINAL_TYPE (EAPMethodSimple, eap_method_simple, EAP, METHOD_SIMPLE, GObject) +G_DECLARE_FINAL_TYPE (EAPMethodSimple, eap_method_simple, EAP, METHOD_SIMPLE, GtkGrid) typedef enum { /* NOTE: when updating this table, also update eap_methods[] */ diff --git a/panels/network/wireless-security/eap-method-simple.ui b/panels/network/wireless-security/eap-method-simple.ui index 00799ac93f..7a0a9a6775 100644 --- a/panels/network/wireless-security/eap-method-simple.ui +++ b/panels/network/wireless-security/eap-method-simple.ui @@ -1,7 +1,7 @@ - + diff --git a/panels/network/wireless-security/eap-method-tls.c b/panels/network/wireless-security/eap-method-tls.c index 8263d56e61..15c615c7d5 100644 --- a/panels/network/wireless-security/eap-method-tls.c +++ b/panels/network/wireless-security/eap-method-tls.c @@ -33,13 +33,11 @@ #include "utils.h" struct _EAPMethodTLS { - GObject parent; + GtkGrid parent; - GtkBuilder *builder; GtkFileChooserButton *ca_cert_button; GtkLabel *ca_cert_label; GtkCheckButton *ca_cert_not_required_check; - GtkGrid *grid; GtkEntry *identity_entry; GtkLabel *identity_label; GtkFileChooserButton *private_key_button; @@ -58,19 +56,9 @@ struct _EAPMethodTLS { static void eap_method_iface_init (EAPMethodInterface *); -G_DEFINE_TYPE_WITH_CODE (EAPMethodTLS, eap_method_tls, G_TYPE_OBJECT, +G_DEFINE_TYPE_WITH_CODE (EAPMethodTLS, eap_method_tls, GTK_TYPE_GRID, G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) -static void -eap_method_tls_dispose (GObject *object) -{ - EAPMethodTLS *self = EAP_METHOD_TLS (object); - - g_clear_object (&self->builder); - - G_OBJECT_CLASS (eap_method_tls_parent_class)->dispose (object); -} - static void show_toggled_cb (EAPMethodTLS *self) { @@ -281,7 +269,7 @@ private_key_picker_helper (EAPMethodTLS *self, const char *filename, gboolean ch GtkWidget *toplevel; GtkWindow *parent_window = NULL; - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->grid)); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self)); if (gtk_widget_is_toplevel (toplevel)) parent_window = GTK_WINDOW (toplevel); @@ -412,13 +400,6 @@ update_secrets (EAPMethod *method, NMConnection *connection) } } -static GtkWidget * -get_widget (EAPMethod *method) -{ - EAPMethodTLS *self = EAP_METHOD_TLS (method); - return GTK_WIDGET (self->grid); -} - static GtkWidget * get_default_field (EAPMethod *method) { @@ -443,14 +424,28 @@ get_phase2 (EAPMethod *method) static void eap_method_tls_init (EAPMethodTLS *self) { + gtk_widget_init_template (GTK_WIDGET (self)); } static void eap_method_tls_class_init (EAPMethodTLSClass *klass) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = eap_method_tls_dispose; + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-tls.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, ca_cert_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, ca_cert_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, ca_cert_not_required_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, identity_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, identity_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, private_key_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, private_key_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, private_key_password_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, private_key_password_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, show_password_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, user_cert_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTLS, user_cert_label); } static void @@ -460,7 +455,6 @@ eap_method_iface_init (EAPMethodInterface *iface) iface->add_to_size_group = add_to_size_group; iface->fill_connection = fill_connection; iface->update_secrets = update_secrets; - iface->get_widget = get_widget; iface->get_default_field = get_default_field; iface->get_password_flags_name = get_password_flags_name; iface->get_phase2 = get_phase2; @@ -475,7 +469,6 @@ eap_method_tls_new (WirelessSecurity *ws_parent, EAPMethodTLS *self; NMSetting8021x *s_8021x = NULL; gboolean ca_not_required = FALSE; - g_autoptr(GError) error = NULL; self = g_object_new (eap_method_tls_get_type (), NULL); self->phase2 = phase2; @@ -485,26 +478,6 @@ eap_method_tls_new (WirelessSecurity *ws_parent, self->sec_parent = ws_parent; self->editing_connection = secrets_only ? FALSE : TRUE; - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-tls.ui", &error)) { - g_warning ("Couldn't load UI builder resource: %s", error->message); - return NULL; - } - - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (self->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_not_required_check")); - self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); - self->identity_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "identity_entry")); - self->identity_label = GTK_LABEL (gtk_builder_get_object (self->builder, "identity_label")); - self->private_key_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "private_key_button")); - self->private_key_label = GTK_LABEL (gtk_builder_get_object (self->builder, "private_key_label")); - self->private_key_password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "private_key_password_entry")); - self->private_key_password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "private_key_password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); - self->user_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "user_cert_button")); - self->user_cert_label = GTK_LABEL (gtk_builder_get_object (self->builder, "user_cert_label")); - if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); diff --git a/panels/network/wireless-security/eap-method-tls.h b/panels/network/wireless-security/eap-method-tls.h index 3507b0ffcc..fff224565d 100644 --- a/panels/network/wireless-security/eap-method-tls.h +++ b/panels/network/wireless-security/eap-method-tls.h @@ -22,11 +22,14 @@ #pragma once +#include +#include + #include "wireless-security.h" G_BEGIN_DECLS -G_DECLARE_FINAL_TYPE (EAPMethodTLS, eap_method_tls, EAP, METHOD_TLS, GObject) +G_DECLARE_FINAL_TYPE (EAPMethodTLS, eap_method_tls, EAP, METHOD_TLS, GtkGrid) EAPMethodTLS *eap_method_tls_new (WirelessSecurity *ws_parent, NMConnection *connection, diff --git a/panels/network/wireless-security/eap-method-tls.ui b/panels/network/wireless-security/eap-method-tls.ui index 194ac41e56..28698f4573 100644 --- a/panels/network/wireless-security/eap-method-tls.ui +++ b/panels/network/wireless-security/eap-method-tls.ui @@ -1,7 +1,7 @@ - + diff --git a/panels/network/wireless-security/eap-method-ttls.c b/panels/network/wireless-security/eap-method-ttls.c index e21c2f83ec..67ba854a61 100644 --- a/panels/network/wireless-security/eap-method-ttls.c +++ b/panels/network/wireless-security/eap-method-ttls.c @@ -35,9 +35,8 @@ #define I_METHOD_COLUMN 1 struct _EAPMethodTTLS { - GObject parent; + GtkGrid parent; - GtkBuilder *builder; GtkEntry *anon_identity_entry; GtkLabel *anon_identity_label; GtkFileChooserButton *ca_cert_button; @@ -45,7 +44,6 @@ struct _EAPMethodTTLS { GtkCheckButton *ca_cert_not_required_check; GtkEntry *domain_match_entry; GtkLabel *domain_match_label; - GtkGrid *grid; GtkComboBox *inner_auth_combo; GtkLabel *inner_auth_label; GtkBox *inner_auth_box; @@ -57,7 +55,7 @@ struct _EAPMethodTTLS { static void eap_method_iface_init (EAPMethodInterface *); -G_DEFINE_TYPE_WITH_CODE (EAPMethodTTLS, eap_method_ttls, G_TYPE_OBJECT, +G_DEFINE_TYPE_WITH_CODE (EAPMethodTTLS, eap_method_ttls, GTK_TYPE_GRID, G_IMPLEMENT_INTERFACE (eap_method_get_type (), eap_method_iface_init)) static void @@ -65,7 +63,6 @@ eap_method_ttls_dispose (GObject *object) { EAPMethodTTLS *self = EAP_METHOD_TTLS (object); - g_clear_object (&self->builder); g_clear_object (&self->size_group); G_OBJECT_CLASS (eap_method_ttls_parent_class)->dispose (object); @@ -181,7 +178,6 @@ inner_auth_combo_changed_cb (EAPMethodTTLS *self) GList *elt, *children; GtkTreeModel *model; GtkTreeIter iter; - GtkWidget *eap_widget; /* Remove any previous wireless security widgets */ children = gtk_container_get_children (GTK_CONTAINER (self->inner_auth_box)); @@ -194,13 +190,10 @@ inner_auth_combo_changed_cb (EAPMethodTTLS *self) gtk_tree_model_get (model, &iter, I_METHOD_COLUMN, &eap, -1); g_assert (eap); - eap_widget = eap_method_get_widget (eap); - g_assert (eap_widget); - gtk_widget_unparent (eap_widget); - + gtk_widget_unparent (GTK_WIDGET (eap)); if (self->size_group) eap_method_add_to_size_group (eap, self->size_group); - gtk_container_add (GTK_CONTAINER (self->inner_auth_box), eap_widget); + gtk_container_add (GTK_CONTAINER (self->inner_auth_box), g_object_ref (GTK_WIDGET (eap))); wireless_security_notify_changed (self->sec_parent); } @@ -355,13 +348,6 @@ update_secrets (EAPMethod *method, NMConnection *connection) I_METHOD_COLUMN); } -static GtkWidget * -get_widget (EAPMethod *method) -{ - EAPMethodTTLS *self = EAP_METHOD_TTLS (method); - return GTK_WIDGET (self->grid); -} - static GtkWidget * get_default_field (EAPMethod *method) { @@ -384,14 +370,29 @@ changed_cb (EAPMethodTTLS *self) static void eap_method_ttls_init (EAPMethodTTLS *self) { + gtk_widget_init_template (GTK_WIDGET (self)); } static void eap_method_ttls_class_init (EAPMethodTTLSClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); object_class->dispose = eap_method_ttls_dispose; + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/ControlCenter/network/eap-method-ttls.ui"); + + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, anon_identity_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, anon_identity_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, ca_cert_button); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, ca_cert_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, ca_cert_not_required_check); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, domain_match_entry); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, domain_match_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, inner_auth_combo); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, inner_auth_label); + gtk_widget_class_bind_template_child (widget_class, EAPMethodTTLS, inner_auth_box); } static void @@ -401,7 +402,6 @@ eap_method_iface_init (EAPMethodInterface *iface) iface->add_to_size_group = add_to_size_group; iface->fill_connection = fill_connection; iface->update_secrets = update_secrets; - iface->get_widget = get_widget; iface->get_default_field = get_default_field; iface->get_password_flags_name = get_password_flags_name; } @@ -416,30 +416,11 @@ eap_method_ttls_new (WirelessSecurity *ws_parent, GtkFileFilter *filter; NMSetting8021x *s_8021x = NULL; const char *filename; - g_autoptr(GError) error = NULL; self = g_object_new (eap_method_ttls_get_type (), NULL); self->sec_parent = ws_parent; self->is_editor = is_editor; - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/eap-method-ttls.ui", &error)) { - g_warning ("Couldn't load UI builder resource: %s", error->message); - return NULL; - } - - self->anon_identity_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "anon_identity_entry")); - self->anon_identity_label = GTK_LABEL (gtk_builder_get_object (self->builder, "anon_identity_label")); - self->ca_cert_button = GTK_FILE_CHOOSER_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_button")); - self->ca_cert_label = GTK_LABEL (gtk_builder_get_object (self->builder, "ca_cert_label")); - self->ca_cert_not_required_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "ca_cert_not_required_check")); - self->domain_match_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "domain_match_entry")); - self->domain_match_label = GTK_LABEL (gtk_builder_get_object (self->builder, "domain_match_label")); - self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); - self->inner_auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "inner_auth_combo")); - self->inner_auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "inner_auth_label")); - self->inner_auth_box = GTK_BOX (gtk_builder_get_object (self->builder, "inner_auth_box")); - if (connection) s_8021x = nm_connection_get_setting_802_1x (connection); diff --git a/panels/network/wireless-security/eap-method-ttls.h b/panels/network/wireless-security/eap-method-ttls.h index 58af578059..9a0be55efa 100644 --- a/panels/network/wireless-security/eap-method-ttls.h +++ b/panels/network/wireless-security/eap-method-ttls.h @@ -22,11 +22,14 @@ #pragma once +#include +#include + #include "wireless-security.h" G_BEGIN_DECLS -G_DECLARE_FINAL_TYPE (EAPMethodTTLS, eap_method_ttls, EAP, METHOD_TTLS, GObject) +G_DECLARE_FINAL_TYPE (EAPMethodTTLS, eap_method_ttls, EAP, METHOD_TTLS, GtkGrid) EAPMethodTTLS *eap_method_ttls_new (WirelessSecurity *ws_parent, NMConnection *connection, diff --git a/panels/network/wireless-security/eap-method-ttls.ui b/panels/network/wireless-security/eap-method-ttls.ui index 519d99379f..e36fc8bb8d 100644 --- a/panels/network/wireless-security/eap-method-ttls.ui +++ b/panels/network/wireless-security/eap-method-ttls.ui @@ -12,7 +12,7 @@ - + diff --git a/panels/network/wireless-security/eap-method.c b/panels/network/wireless-security/eap-method.c index e1a147c03f..c309609b71 100644 --- a/panels/network/wireless-security/eap-method.c +++ b/panels/network/wireless-security/eap-method.c @@ -40,14 +40,6 @@ eap_method_default_init (EAPMethodInterface *iface) { } -GtkWidget * -eap_method_get_widget (EAPMethod *self) -{ - g_return_val_if_fail (self != NULL, NULL); - - return EAP_METHOD_GET_IFACE (self)->get_widget (self); -} - GtkWidget * eap_method_get_default_field (EAPMethod *self) { diff --git a/panels/network/wireless-security/eap-method.h b/panels/network/wireless-security/eap-method.h index 3910a9e9f1..4c23b5858f 100644 --- a/panels/network/wireless-security/eap-method.h +++ b/panels/network/wireless-security/eap-method.h @@ -27,7 +27,7 @@ G_BEGIN_DECLS -G_DECLARE_INTERFACE (EAPMethod, eap_method, EAP, METHOD, GObject) +G_DECLARE_INTERFACE (EAPMethod, eap_method, EAP, METHOD, GtkGrid) struct _EAPMethodInterface { GTypeInterface g_iface; @@ -36,14 +36,11 @@ struct _EAPMethodInterface { void (*fill_connection) (EAPMethod *method, NMConnection *connection, NMSettingSecretFlags flags); void (*update_secrets) (EAPMethod *method, NMConnection *connection); gboolean (*validate) (EAPMethod *method, GError **error); - GtkWidget* (*get_widget) (EAPMethod *method); GtkWidget* (*get_default_field) (EAPMethod *method); const gchar* (*get_password_flags_name) (EAPMethod *method); gboolean (*get_phase2) (EAPMethod *method); }; -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); diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index e8c4a7a272..7f9ab9c771 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -340,7 +340,6 @@ ws_802_1x_auth_combo_changed (GtkComboBox *combo, { EAPMethod *eap; GList *elt, *children; - GtkWidget *eap_widget; GtkWidget *eap_default_field; /* Remove any previous wireless security widgets */ @@ -351,13 +350,10 @@ ws_802_1x_auth_combo_changed (GtkComboBox *combo, eap = ws_802_1x_auth_combo_get_eap (GTK_COMBO_BOX (combo)); g_assert (eap); - eap_widget = eap_method_get_widget (eap); - g_assert (eap_widget); - gtk_widget_unparent (eap_widget); - + gtk_widget_unparent (GTK_WIDGET (eap)); if (size_group) eap_method_add_to_size_group (eap, size_group); - gtk_container_add (GTK_CONTAINER (vbox), eap_widget); + gtk_container_add (GTK_CONTAINER (vbox), g_object_ref (GTK_WIDGET (eap))); /* Refocus the EAP method's default widget */ eap_default_field = eap_method_get_default_field (eap); -- GitLab From 4b182dd7c01db421532fbd70d4aa808f7f653231 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 11:48:11 +1300 Subject: [PATCH 19/39] network: Move GtkBuilder code from WirelessSecurity to subclasses --- .../wireless-security/wireless-security.c | 14 +-------- .../wireless-security/wireless-security.h | 4 +-- .../wireless-security/ws-dynamic-wep.c | 20 ++++++++---- panels/network/wireless-security/ws-leap.c | 31 ++++++++++++++----- panels/network/wireless-security/ws-wep-key.c | 28 +++++++++++------ panels/network/wireless-security/ws-wpa-eap.c | 21 ++++++++----- panels/network/wireless-security/ws-wpa-psk.c | 31 ++++++++++++++----- 7 files changed, 94 insertions(+), 55 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index 7f9ab9c771..1ad68d73c7 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -171,7 +171,6 @@ wireless_security_unref (WirelessSecurity *self) g_clear_pointer (&priv->username, g_free); g_clear_pointer (&priv->password, g_free); - g_clear_object (&self->builder); g_slice_free1 (priv->obj_size, self); g_free (priv); } @@ -183,15 +182,12 @@ wireless_security_init (gsize obj_size, WSValidateFunc validate, WSAddToSizeGroupFunc add_to_size_group, WSFillConnectionFunc fill_connection, - WSDestroyFunc destroy, - const char *ui_resource) + WSDestroyFunc destroy) { g_autoptr(WirelessSecurity) self = NULL; WirelessSecurityPrivate *priv; - g_autoptr(GError) error = NULL; g_return_val_if_fail (obj_size > 0, NULL); - g_return_val_if_fail (ui_resource != NULL, NULL); g_type_ensure (WIRELESS_TYPE_SECURITY); @@ -206,14 +202,6 @@ wireless_security_init (gsize obj_size, priv->validate = validate; priv->add_to_size_group = add_to_size_group; priv->fill_connection = fill_connection; - - self->builder = gtk_builder_new (); - if (!gtk_builder_add_from_resource (self->builder, ui_resource, &error)) { - g_warning ("Couldn't load UI builder resource %s: %s", - ui_resource, error->message); - return NULL; - } - priv->destroy = destroy; priv->adhoc_compatible = TRUE; diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 3c581e07f9..d4e44ea10f 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -40,7 +40,6 @@ typedef GtkWidget* (*WSGetWidgetFunc) (WirelessSecurity *sec); struct _WirelessSecurity { WirelessSecurityPrivate *priv; - GtkBuilder *builder; }; #define WIRELESS_SECURITY(x) ((WirelessSecurity *) x) @@ -92,8 +91,7 @@ WirelessSecurity *wireless_security_init (gsize obj_size, WSValidateFunc validate, WSAddToSizeGroupFunc add_to_size_group, WSFillConnectionFunc fill_connection, - WSDestroyFunc destroy, - const char *ui_resource); + WSDestroyFunc destroy); void wireless_security_notify_changed (WirelessSecurity *sec); diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index cba45c2c2a..9be227db6c 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -32,6 +32,7 @@ struct _WirelessSecurityDynamicWEP { WirelessSecurity parent; + GtkBuilder *builder; GtkComboBox *auth_combo; GtkLabel *auth_label; GtkGrid *grid; @@ -45,6 +46,7 @@ destroy (WirelessSecurity *parent) { WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + g_clear_object (&self->builder); g_clear_object (&self->size_group); } @@ -105,22 +107,28 @@ ws_dynamic_wep_new (NMConnection *connection, { WirelessSecurity *parent; WirelessSecurityDynamicWEP *self; + g_autoptr(GError) error = NULL; parent = wireless_security_init (sizeof (WirelessSecurityDynamicWEP), get_widget, validate, add_to_size_group, fill_connection, - destroy, - "/org/gnome/ControlCenter/network/ws-dynamic-wep.ui"); + destroy); if (!parent) return NULL; self = (WirelessSecurityDynamicWEP *) parent; - self->auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "auth_combo")); - self->auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "auth_label")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->method_box = GTK_BOX (gtk_builder_get_object (parent->builder, "method_box")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-dynamic-wep.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "auth_combo")); + self->auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "auth_label")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->method_box = GTK_BOX (gtk_builder_get_object (self->builder, "method_box")); wireless_security_set_adhoc_compatible (parent, FALSE); diff --git a/panels/network/wireless-security/ws-leap.c b/panels/network/wireless-security/ws-leap.c index 6e555f9c2a..f2f1f71916 100644 --- a/panels/network/wireless-security/ws-leap.c +++ b/panels/network/wireless-security/ws-leap.c @@ -33,6 +33,7 @@ struct _WirelessSecurityLEAP { WirelessSecurity parent; + GtkBuilder *builder; GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; @@ -44,6 +45,14 @@ struct _WirelessSecurityLEAP { const char *password_flags_name; }; +static void +destroy (WirelessSecurity *parent) +{ + WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + + g_clear_object (&self->builder); +} + static void show_toggled_cb (WirelessSecurityLEAP *self) { @@ -151,14 +160,14 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only) WirelessSecurity *parent; WirelessSecurityLEAP *self; NMSettingWirelessSecurity *wsec = NULL; + g_autoptr(GError) error = NULL; parent = wireless_security_init (sizeof (WirelessSecurityLEAP), get_widget, validate, add_to_size_group, fill_connection, - NULL, - "/org/gnome/ControlCenter/network/ws-leap.ui"); + destroy); if (!parent) return NULL; @@ -179,12 +188,18 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only) self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD; - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")); - self->password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->username_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "username_entry")); - self->username_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "username_label")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-leap.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password_entry")); + self->password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "password_label")); + self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); + self->username_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "username_entry")); + self->username_label = GTK_LABEL (gtk_builder_get_object (self->builder, "username_label")); g_signal_connect_swapped (self->password_entry, "changed", G_CALLBACK (changed_cb), self); diff --git a/panels/network/wireless-security/ws-wep-key.c b/panels/network/wireless-security/ws-wep-key.c index 90fad5d29a..0a799e75b3 100644 --- a/panels/network/wireless-security/ws-wep-key.c +++ b/panels/network/wireless-security/ws-wep-key.c @@ -33,6 +33,7 @@ struct _WirelessSecurityWEPKey { WirelessSecurity parent; + GtkBuilder *builder; GtkComboBox *auth_method_combo; GtkLabel *auth_method_label; GtkGrid *grid; @@ -89,6 +90,7 @@ destroy (WirelessSecurity *parent) WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; int i; + g_clear_object (&self->builder); for (i = 0; i < 4; i++) memset (self->keys[i], 0, sizeof (self->keys[i])); } @@ -264,26 +266,32 @@ ws_wep_key_new (NMConnection *connection, guint8 default_key_idx = 0; gboolean is_adhoc = adhoc_create; gboolean is_shared_key = FALSE; + g_autoptr(GError) error = NULL; parent = wireless_security_init (sizeof (WirelessSecurityWEPKey), get_widget, validate, add_to_size_group, fill_connection, - destroy, - "/org/gnome/ControlCenter/network/ws-wep-key.ui"); + destroy); if (!parent) return NULL; self = (WirelessSecurityWEPKey *) parent; - self->auth_method_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "auth_method_combo")); - self->auth_method_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "auth_method_label")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->key_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "key_entry")); - self->key_index_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "key_index_combo")); - self->key_index_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "key_index_label")); - self->key_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "key_label")); - self->show_key_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_key_check")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wep-key.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->auth_method_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "auth_method_combo")); + self->auth_method_label = GTK_LABEL (gtk_builder_get_object (self->builder, "auth_method_label")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->key_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "key_entry")); + self->key_index_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "key_index_combo")); + self->key_index_label = GTK_LABEL (gtk_builder_get_object (self->builder, "key_index_label")); + self->key_label = GTK_LABEL (gtk_builder_get_object (self->builder, "key_label")); + self->show_key_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_key_check")); self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_WEP_KEY0; diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index a8e7358b9c..cb9cff1564 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -32,6 +32,7 @@ struct _WirelessSecurityWPAEAP { WirelessSecurity parent; + GtkBuilder *builder; GtkComboBox *auth_combo; GtkLabel *auth_label; GtkGrid *grid; @@ -40,12 +41,12 @@ struct _WirelessSecurityWPAEAP { GtkSizeGroup *size_group; }; - static void destroy (WirelessSecurity *parent) { WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + g_clear_object (&self->builder); g_clear_object (&self->size_group); } @@ -106,22 +107,28 @@ ws_wpa_eap_new (NMConnection *connection, { WirelessSecurity *parent; WirelessSecurityWPAEAP *self; + g_autoptr(GError) error = NULL; parent = wireless_security_init (sizeof (WirelessSecurityWPAEAP), get_widget, validate, add_to_size_group, fill_connection, - destroy, - "/org/gnome/ControlCenter/network/ws-wpa-eap.ui"); + destroy); if (!parent) return NULL; self = (WirelessSecurityWPAEAP *) parent; - self->auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "auth_combo")); - self->auth_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "auth_label")); - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->method_box = GTK_BOX (gtk_builder_get_object (parent->builder, "method_box")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wpa-eap.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->auth_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "auth_combo")); + self->auth_label = GTK_LABEL (gtk_builder_get_object (self->builder, "auth_label")); + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->method_box = GTK_BOX (gtk_builder_get_object (self->builder, "method_box")); wireless_security_set_adhoc_compatible (parent, FALSE); diff --git a/panels/network/wireless-security/ws-wpa-psk.c b/panels/network/wireless-security/ws-wpa-psk.c index 9e4dac7011..e253d17f47 100644 --- a/panels/network/wireless-security/ws-wpa-psk.c +++ b/panels/network/wireless-security/ws-wpa-psk.c @@ -36,6 +36,7 @@ struct _WirelessSecurityWPAPSK { WirelessSecurity parent; + GtkBuilder *builder; GtkGrid *grid; GtkEntry *password_entry; GtkLabel *password_label; @@ -47,6 +48,14 @@ struct _WirelessSecurityWPAPSK { const char *password_flags_name; }; +static void +destroy (WirelessSecurity *parent) +{ + WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + + g_clear_object (&self->builder); +} + static GtkWidget * get_widget (WirelessSecurity *parent) { @@ -181,24 +190,30 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only) WirelessSecurity *parent; WirelessSecurityWPAPSK *self; NMSetting *setting = NULL; + g_autoptr(GError) error = NULL; parent = wireless_security_init (sizeof (WirelessSecurityWPAPSK), get_widget, validate, add_to_size_group, fill_connection, - NULL, - "/org/gnome/ControlCenter/network/ws-wpa-psk.ui"); + destroy); if (!parent) return NULL; self = (WirelessSecurityWPAPSK *) parent; - self->grid = GTK_GRID (gtk_builder_get_object (parent->builder, "grid")); - self->password_entry = GTK_ENTRY (gtk_builder_get_object (parent->builder, "password_entry")); - self->password_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "password_label")); - self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (parent->builder, "show_password_check")); - self->type_combo = GTK_COMBO_BOX (gtk_builder_get_object (parent->builder, "type_combo")); - self->type_label = GTK_LABEL (gtk_builder_get_object (parent->builder, "type_label")); + self->builder = gtk_builder_new (); + if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wpa-psk.ui", &error)) { + g_warning ("Couldn't load UI builder resource: %s", error->message); + return NULL; + } + + self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); + self->password_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "password_entry")); + self->password_label = GTK_LABEL (gtk_builder_get_object (self->builder, "password_label")); + self->show_password_check = GTK_CHECK_BUTTON (gtk_builder_get_object (self->builder, "show_password_check")); + self->type_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "type_combo")); + self->type_label = GTK_LABEL (gtk_builder_get_object (self->builder, "type_label")); wireless_security_set_adhoc_compatible (parent, FALSE); -- GitLab From 3d06da2d30dceb6d3126a5d931aac96a21e64925 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 12:37:34 +1300 Subject: [PATCH 20/39] network: Convert WirelessSecurity into a GObject --- .../ce-page-8021x-security.c | 2 +- .../connection-editor/ce-page-security.c | 4 +- .../wireless-security/wireless-security.c | 178 ++++++------------ .../wireless-security/wireless-security.h | 41 +--- .../wireless-security/ws-dynamic-wep.c | 57 +++--- .../wireless-security/ws-dynamic-wep.h | 13 +- panels/network/wireless-security/ws-leap.c | 69 ++++--- panels/network/wireless-security/ws-leap.h | 13 +- panels/network/wireless-security/ws-wep-key.c | 58 +++--- panels/network/wireless-security/ws-wep-key.h | 13 +- panels/network/wireless-security/ws-wpa-eap.c | 57 +++--- panels/network/wireless-security/ws-wpa-eap.h | 13 +- panels/network/wireless-security/ws-wpa-psk.c | 71 +++---- panels/network/wireless-security/ws-wpa-psk.h | 13 +- 14 files changed, 295 insertions(+), 307 deletions(-) diff --git a/panels/network/connection-editor/ce-page-8021x-security.c b/panels/network/connection-editor/ce-page-8021x-security.c index a1ec4eca8f..19f8ef3c50 100644 --- a/panels/network/connection-editor/ce-page-8021x-security.c +++ b/panels/network/connection-editor/ce-page-8021x-security.c @@ -164,7 +164,7 @@ ce_page_8021x_security_dispose (GObject *object) CEPage8021xSecurity *self = CE_PAGE_8021X_SECURITY (object); g_clear_object (&self->connection); - g_clear_pointer ((WirelessSecurity**) &self->security, wireless_security_unref); + g_clear_object (&self->security); g_clear_object (&self->group); G_OBJECT_CLASS (ce_page_8021x_security_parent_class)->dispose (object); diff --git a/panels/network/connection-editor/ce-page-security.c b/panels/network/connection-editor/ce-page-security.c index f716d7ef4e..23cfd3276e 100644 --- a/panels/network/connection-editor/ce-page-security.c +++ b/panels/network/connection-editor/ce-page-security.c @@ -194,7 +194,7 @@ add_security_item (CEPageSecurity *self, S_SEC_COLUMN, sec, S_ADHOC_VALID_COLUMN, adhoc_valid, -1); - wireless_security_unref (sec); + g_object_unref (sec); } static void @@ -250,7 +250,7 @@ finish_setup (CEPageSecurity *self) if (sws) default_type = get_default_type_for_security (sws); - sec_model = gtk_list_store_new (3, G_TYPE_STRING, WIRELESS_TYPE_SECURITY, G_TYPE_BOOLEAN); + sec_model = gtk_list_store_new (3, G_TYPE_STRING, wireless_security_get_type (), G_TYPE_BOOLEAN); if (nm_utils_security_valid (NMU_SEC_NONE, dev_caps, FALSE, is_adhoc, 0, 0, 0)) { gtk_list_store_insert_with_values (sec_model, &iter, -1, diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index 1ad68d73c7..dbc9d346f6 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -35,47 +35,56 @@ #include "eap-method-ttls.h" #include "utils.h" -struct _WirelessSecurityPrivate { - guint32 refcount; - gsize obj_size; +typedef struct { WSChangedFunc changed_notify; gpointer changed_notify_data; gboolean adhoc_compatible; char *username, *password; gboolean always_ask, show_password; +} WirelessSecurityPrivate; - WSAddToSizeGroupFunc add_to_size_group; - WSFillConnectionFunc fill_connection; - WSGetWidgetFunc get_widget; - WSValidateFunc validate; - WSDestroyFunc destroy; -}; +G_DEFINE_TYPE_WITH_PRIVATE (WirelessSecurity, wireless_security, G_TYPE_OBJECT) -GType -wireless_security_get_type (void) +static void +wireless_security_dispose (GObject *object) { - static GType type_id = 0; + WirelessSecurity *self = WIRELESS_SECURITY (object); + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - if (!type_id) { - g_resources_register (wireless_security_get_resource ()); + if (priv->password) + memset (priv->password, 0, strlen (priv->password)); - type_id = g_boxed_type_register_static ("CcWirelessSecurity", - (GBoxedCopyFunc) wireless_security_ref, - (GBoxedFreeFunc) wireless_security_unref); - } + g_clear_pointer (&priv->username, g_free); + g_clear_pointer (&priv->password, g_free); + + G_OBJECT_CLASS (wireless_security_parent_class)->dispose (object); +} + +void +wireless_security_init (WirelessSecurity *self) +{ + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); + + g_resources_register (wireless_security_get_resource ()); - return type_id; + priv->adhoc_compatible = TRUE; +} + +void +wireless_security_class_init (WirelessSecurityClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = wireless_security_dispose; } GtkWidget * wireless_security_get_widget (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; - g_return_val_if_fail (self != NULL, NULL); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), NULL); - g_assert (priv->get_widget); - return (*(priv->get_widget)) (self); + return WIRELESS_SECURITY_GET_CLASS (self)->get_widget (self); } void @@ -83,8 +92,9 @@ wireless_security_set_changed_notify (WirelessSecurity *self, WSChangedFunc func, gpointer user_data) { - WirelessSecurityPrivate *priv = self->priv; - g_return_if_fail (self != NULL); + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); + + g_return_if_fail (WIRELESS_IS_SECURITY (self)); priv->changed_notify = func; priv->changed_notify_data = user_data; @@ -93,7 +103,7 @@ wireless_security_set_changed_notify (WirelessSecurity *self, void wireless_security_notify_changed (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); if (priv->changed_notify) (*(priv->changed_notify)) (self, priv->changed_notify_data); @@ -102,14 +112,12 @@ wireless_security_notify_changed (WirelessSecurity *self) gboolean wireless_security_validate (WirelessSecurity *self, GError **error) { - WirelessSecurityPrivate *priv = self->priv; gboolean result; - g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); g_return_val_if_fail (!error || !*error, FALSE); - g_assert (priv->validate); - result = (*(priv->validate)) (self, error); + result = WIRELESS_SECURITY_GET_CLASS (self)->validate (self, error); if (!result && error && !*error) g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Unknown error validating 802.1X security")); return result; @@ -118,102 +126,28 @@ wireless_security_validate (WirelessSecurity *self, GError **error) void wireless_security_add_to_size_group (WirelessSecurity *self, GtkSizeGroup *group) { - WirelessSecurityPrivate *priv = self->priv; + g_return_if_fail (WIRELESS_IS_SECURITY (self)); + g_return_if_fail (GTK_IS_SIZE_GROUP (group)); - g_return_if_fail (self != NULL); - g_return_if_fail (group != NULL); - - g_assert (priv->add_to_size_group); - return (*(priv->add_to_size_group)) (self, group); + return WIRELESS_SECURITY_GET_CLASS (self)->add_to_size_group (self, group); } void wireless_security_fill_connection (WirelessSecurity *self, NMConnection *connection) { - WirelessSecurityPrivate *priv = self->priv; - - g_return_if_fail (self != NULL); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); g_return_if_fail (connection != NULL); - g_assert (priv->fill_connection); - return (*(priv->fill_connection)) (self, connection); -} - -WirelessSecurity * -wireless_security_ref (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (priv->refcount > 0, NULL); - - priv->refcount++; - return self; -} - -void -wireless_security_unref (WirelessSecurity *self) -{ - WirelessSecurityPrivate *priv = self->priv; - - g_return_if_fail (self != NULL); - g_return_if_fail (priv->refcount > 0); - - priv->refcount--; - if (priv->refcount == 0) { - if (priv->destroy) - priv->destroy (self); - - if (priv->password) - memset (priv->password, 0, strlen (priv->password)); - - g_clear_pointer (&priv->username, g_free); - g_clear_pointer (&priv->password, g_free); - - g_slice_free1 (priv->obj_size, self); - g_free (priv); - } -} - -WirelessSecurity * -wireless_security_init (gsize obj_size, - WSGetWidgetFunc get_widget, - WSValidateFunc validate, - WSAddToSizeGroupFunc add_to_size_group, - WSFillConnectionFunc fill_connection, - WSDestroyFunc destroy) -{ - g_autoptr(WirelessSecurity) self = NULL; - WirelessSecurityPrivate *priv; - - g_return_val_if_fail (obj_size > 0, NULL); - - g_type_ensure (WIRELESS_TYPE_SECURITY); - - self = g_slice_alloc0 (obj_size); - g_assert (self); - self->priv = priv = g_new0 (WirelessSecurityPrivate, 1); - - priv->refcount = 1; - priv->obj_size = obj_size; - - priv->get_widget = get_widget; - priv->validate = validate; - priv->add_to_size_group = add_to_size_group; - priv->fill_connection = fill_connection; - priv->destroy = destroy; - priv->adhoc_compatible = TRUE; - - return g_steal_pointer (&self); + return WIRELESS_SECURITY_GET_CLASS (self)->fill_connection (self, connection); } void wireless_security_set_adhoc_compatible (WirelessSecurity *self, gboolean adhoc_compatible) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_if_fail (self != NULL); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); priv->adhoc_compatible = adhoc_compatible; } @@ -221,9 +155,9 @@ wireless_security_set_adhoc_compatible (WirelessSecurity *self, gboolean adhoc_c gboolean wireless_security_adhoc_compatible (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); return priv->adhoc_compatible; } @@ -231,9 +165,9 @@ wireless_security_adhoc_compatible (WirelessSecurity *self) const gchar * wireless_security_get_username (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_val_if_fail (self != NULL, NULL); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), NULL); return priv->username; } @@ -241,9 +175,9 @@ wireless_security_get_username (WirelessSecurity *self) const gchar * wireless_security_get_password (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_val_if_fail (self != NULL, NULL); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), NULL); return priv->password; } @@ -251,9 +185,9 @@ wireless_security_get_password (WirelessSecurity *self) gboolean wireless_security_get_always_ask (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); return priv->always_ask; } @@ -261,9 +195,9 @@ wireless_security_get_always_ask (WirelessSecurity *self) gboolean wireless_security_get_show_password (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); return priv->show_password; } @@ -275,7 +209,7 @@ wireless_security_set_userpass (WirelessSecurity *self, gboolean always_ask, gboolean show_password) { - WirelessSecurityPrivate *priv = self->priv; + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); g_clear_pointer (&priv->username, g_free); priv->username = g_strdup (user); diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index d4e44ea10f..3b82eb6c69 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -20,31 +20,25 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WIRELESS_SECURITY_H -#define WIRELESS_SECURITY_H +#pragma once #include -#define WIRELESS_TYPE_SECURITY (wireless_security_get_type ()) +G_BEGIN_DECLS -typedef struct _WirelessSecurity WirelessSecurity; -typedef struct _WirelessSecurityPrivate WirelessSecurityPrivate; +G_DECLARE_DERIVABLE_TYPE (WirelessSecurity, wireless_security, WIRELESS, SECURITY, GObject) typedef void (*WSChangedFunc) (WirelessSecurity *sec, gpointer user_data); -typedef void (*WSAddToSizeGroupFunc) (WirelessSecurity *sec, GtkSizeGroup *group); -typedef void (*WSFillConnectionFunc) (WirelessSecurity *sec, NMConnection *connection); -typedef void (*WSDestroyFunc) (WirelessSecurity *sec); -typedef gboolean (*WSValidateFunc) (WirelessSecurity *sec, GError **error); -typedef GtkWidget* (*WSGetWidgetFunc) (WirelessSecurity *sec); +struct _WirelessSecurityClass { + GObjectClass parent_class; -struct _WirelessSecurity { - WirelessSecurityPrivate *priv; + void (*add_to_size_group) (WirelessSecurity *sec, GtkSizeGroup *group); + void (*fill_connection) (WirelessSecurity *sec, NMConnection *connection); + gboolean (*validate) (WirelessSecurity *sec, GError **error); + GtkWidget* (*get_widget) (WirelessSecurity *sec); }; -#define WIRELESS_SECURITY(x) ((WirelessSecurity *) x) - - GtkWidget *wireless_security_get_widget (WirelessSecurity *sec); void wireless_security_set_changed_notify (WirelessSecurity *sec, @@ -78,21 +72,8 @@ void wireless_security_set_userpass (WirelessSecurity *sec, gboolean always_ask, gboolean show_password); -WirelessSecurity *wireless_security_ref (WirelessSecurity *sec); - -void wireless_security_unref (WirelessSecurity *sec); - -GType wireless_security_get_type (void); - /* Below for internal use only */ -WirelessSecurity *wireless_security_init (gsize obj_size, - WSGetWidgetFunc get_widget, - WSValidateFunc validate, - WSAddToSizeGroupFunc add_to_size_group, - WSFillConnectionFunc fill_connection, - WSDestroyFunc destroy); - void wireless_security_notify_changed (WirelessSecurity *sec); void wireless_security_clear_ciphers (NMConnection *connection); @@ -117,6 +98,4 @@ EAPMethod *ws_802_1x_auth_combo_get_eap (GtkComboBox *combo); void ws_802_1x_fill_connection (GtkComboBox *combo, NMConnection *connection); -G_DEFINE_AUTOPTR_CLEANUP_FUNC (WirelessSecurity, wireless_security_unref) - -#endif /* WIRELESS_SECURITY_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index 9be227db6c..46e1dabcb8 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -41,33 +41,37 @@ struct _WirelessSecurityDynamicWEP { GtkSizeGroup *size_group; }; +G_DEFINE_TYPE (WirelessSecurityDynamicWEP, ws_dynamic_wep, wireless_security_get_type ()) + static void -destroy (WirelessSecurity *parent) +ws_dynamic_wep_dispose (GObject *object) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (object); g_clear_object (&self->builder); g_clear_object (&self->size_group); + + G_OBJECT_CLASS (ws_dynamic_wep_parent_class)->dispose (object); } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (security); return GTK_WIDGET (self->grid); } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (security); return eap_method_validate (ws_802_1x_auth_combo_get_eap (self->auth_combo), error); } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (security); g_clear_object (&self->size_group); self->size_group = g_object_ref (group); @@ -77,9 +81,9 @@ add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityDynamicWEP *self = (WirelessSecurityDynamicWEP *) parent; + WirelessSecurityDynamicWEP *self = WS_DYNAMIC_WEP (security); NMSettingWirelessSecurity *s_wireless_sec; ws_802_1x_fill_connection (self->auth_combo, connection); @@ -100,24 +104,33 @@ auth_combo_changed_cb (WirelessSecurityDynamicWEP *self) wireless_security_notify_changed (WIRELESS_SECURITY (self)); } +void +ws_dynamic_wep_init (WirelessSecurityDynamicWEP *self) +{ +} + +void +ws_dynamic_wep_class_init (WirelessSecurityDynamicWEPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_dynamic_wep_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; +} + WirelessSecurityDynamicWEP * ws_dynamic_wep_new (NMConnection *connection, gboolean is_editor, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityDynamicWEP *self; g_autoptr(GError) error = NULL; - parent = wireless_security_init (sizeof (WirelessSecurityDynamicWEP), - get_widget, - validate, - add_to_size_group, - fill_connection, - destroy); - if (!parent) - return NULL; - self = (WirelessSecurityDynamicWEP *) parent; + self = g_object_new (ws_dynamic_wep_get_type (), NULL); self->builder = gtk_builder_new (); if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-dynamic-wep.ui", &error)) { @@ -130,9 +143,9 @@ ws_dynamic_wep_new (NMConnection *connection, self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); self->method_box = GTK_BOX (gtk_builder_get_object (self->builder, "method_box")); - wireless_security_set_adhoc_compatible (parent, FALSE); + wireless_security_set_adhoc_compatible (WIRELESS_SECURITY (self), FALSE); - ws_802_1x_auth_combo_init (parent, + ws_802_1x_auth_combo_init (WIRELESS_SECURITY (self), self->auth_combo, connection, is_editor, diff --git a/panels/network/wireless-security/ws-dynamic-wep.h b/panels/network/wireless-security/ws-dynamic-wep.h index e2e5f6a113..95fdf0de8d 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.h +++ b/panels/network/wireless-security/ws-dynamic-wep.h @@ -20,13 +20,18 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_DYNAMIC_WEP_H -#define WS_DYNAMIC_WEP_H +#pragma once -typedef struct _WirelessSecurityDynamicWEP WirelessSecurityDynamicWEP; +#include + +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityDynamicWEP, ws_dynamic_wep, WS, DYNAMIC_WEP, WirelessSecurity) WirelessSecurityDynamicWEP *ws_dynamic_wep_new (NMConnection *connection, gboolean is_editor, gboolean secrets_only); -#endif /* WS_DYNAMIC_WEP_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/ws-leap.c b/panels/network/wireless-security/ws-leap.c index f2f1f71916..11cc34cc07 100644 --- a/panels/network/wireless-security/ws-leap.c +++ b/panels/network/wireless-security/ws-leap.c @@ -45,12 +45,16 @@ struct _WirelessSecurityLEAP { const char *password_flags_name; }; +G_DEFINE_TYPE (WirelessSecurityLEAP, ws_leap, wireless_security_get_type ()) + static void -destroy (WirelessSecurity *parent) +ws_leap_dispose (GObject *object) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (object); g_clear_object (&self->builder); + + G_OBJECT_CLASS (ws_leap_parent_class)->dispose (object); } static void @@ -63,16 +67,16 @@ show_toggled_cb (WirelessSecurityLEAP *self) } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (security); return GTK_WIDGET (self->grid); } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (security); const char *text; gboolean ret = TRUE; @@ -98,17 +102,17 @@ validate (WirelessSecurity *parent, GError **error) } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (security); gtk_size_group_add_widget (group, GTK_WIDGET (self->username_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label)); } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; + WirelessSecurityLEAP *self = WS_LEAP (security); NMSettingWirelessSecurity *s_wireless_sec; NMSettingSecretFlags secret_flags; const char *leap_password = NULL, *leap_username = NULL; @@ -139,37 +143,37 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) } static void -update_secrets (WirelessSecurity *parent, NMConnection *connection) +changed_cb (WirelessSecurityLEAP *self) { - WirelessSecurityLEAP *self = (WirelessSecurityLEAP *) parent; - helper_fill_secret_entry (connection, - self->password_entry, - NM_TYPE_SETTING_WIRELESS_SECURITY, - (HelperSecretFunc) nm_setting_wireless_security_get_leap_password); + wireless_security_notify_changed ((WirelessSecurity *) self); } -static void -changed_cb (WirelessSecurityLEAP *self) +void +ws_leap_init (WirelessSecurityLEAP *self) { - wireless_security_notify_changed ((WirelessSecurity *) self); +} + +void +ws_leap_class_init (WirelessSecurityLEAPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_leap_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; } WirelessSecurityLEAP * ws_leap_new (NMConnection *connection, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityLEAP *self; NMSettingWirelessSecurity *wsec = NULL; g_autoptr(GError) error = NULL; - parent = wireless_security_init (sizeof (WirelessSecurityLEAP), - get_widget, - validate, - add_to_size_group, - fill_connection, - destroy); - if (!parent) - return NULL; + self = g_object_new (ws_leap_get_type (), NULL); if (connection) { wsec = nm_connection_get_setting_wireless_security (connection); @@ -183,8 +187,8 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only) } } - wireless_security_set_adhoc_compatible (parent, FALSE); - self = (WirelessSecurityLEAP *) parent; + wireless_security_set_adhoc_compatible (WIRELESS_SECURITY (self), FALSE); + self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD; @@ -208,7 +212,10 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only) FALSE, secrets_only); if (wsec) - update_secrets (WIRELESS_SECURITY (self), connection); + helper_fill_secret_entry (connection, + self->password_entry, + NM_TYPE_SETTING_WIRELESS_SECURITY, + (HelperSecretFunc) nm_setting_wireless_security_get_leap_password); g_signal_connect_swapped (self->username_entry, "changed", G_CALLBACK (changed_cb), self); if (wsec) diff --git a/panels/network/wireless-security/ws-leap.h b/panels/network/wireless-security/ws-leap.h index fedc06d664..33abc60627 100644 --- a/panels/network/wireless-security/ws-leap.h +++ b/panels/network/wireless-security/ws-leap.h @@ -20,11 +20,16 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_LEAP_H -#define WS_LEAP_H +#pragma once -typedef struct _WirelessSecurityLEAP WirelessSecurityLEAP; +#include + +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityLEAP, ws_leap, WS, LEAP, WirelessSecurity) WirelessSecurityLEAP * ws_leap_new (NMConnection *connection, gboolean secrets_only); -#endif /* WS_LEAP_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/ws-wep-key.c b/panels/network/wireless-security/ws-wep-key.c index 0a799e75b3..f394c7c59d 100644 --- a/panels/network/wireless-security/ws-wep-key.c +++ b/panels/network/wireless-security/ws-wep-key.c @@ -51,6 +51,8 @@ struct _WirelessSecurityWEPKey { guint8 cur_index; }; +G_DEFINE_TYPE (WirelessSecurityWEPKey, ws_wep_key, wireless_security_get_type ()) + static void show_toggled_cb (WirelessSecurityWEPKey *self) { @@ -85,27 +87,29 @@ key_index_combo_changed_cb (WirelessSecurityWEPKey *self) } static void -destroy (WirelessSecurity *parent) +ws_wep_key_dispose (GObject *object) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (object); int i; g_clear_object (&self->builder); for (i = 0; i < 4; i++) memset (self->keys[i], 0, sizeof (self->keys[i])); + + G_OBJECT_CLASS (ws_wep_key_parent_class)->dispose (object); } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (security); return GTK_WIDGET (self->grid); } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (security); const char *key; int i; @@ -154,18 +158,18 @@ validate (WirelessSecurity *parent, GError **error) } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (security); gtk_size_group_add_widget (group, GTK_WIDGET (self->auth_method_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->key_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->key_index_label)); } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; + WirelessSecurityWEPKey *self = WS_WEP_KEY (security); NMSettingWirelessSecurity *s_wsec; NMSettingSecretFlags secret_flags; gint auth_alg; @@ -229,9 +233,8 @@ wep_entry_filter_cb (WirelessSecurityWEPKey *self, } static void -update_secrets (WirelessSecurity *parent, NMConnection *connection) +update_secrets (WirelessSecurityWEPKey *self, NMConnection *connection) { - WirelessSecurityWEPKey *self = (WirelessSecurityWEPKey *) parent; NMSettingWirelessSecurity *s_wsec; const char *tmp; int i; @@ -253,13 +256,30 @@ changed_cb (WirelessSecurityWEPKey *self) wireless_security_notify_changed ((WirelessSecurity *) self); } +void +ws_wep_key_init (WirelessSecurityWEPKey *self) +{ +} + +void +ws_wep_key_class_init (WirelessSecurityWEPKeyClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_wep_key_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; +} + WirelessSecurityWEPKey * ws_wep_key_new (NMConnection *connection, NMWepKeyType type, gboolean adhoc_create, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityWEPKey *self; NMSettingWirelessSecurity *s_wsec = NULL; NMSetting *setting = NULL; @@ -268,15 +288,7 @@ ws_wep_key_new (NMConnection *connection, gboolean is_shared_key = FALSE; g_autoptr(GError) error = NULL; - parent = wireless_security_init (sizeof (WirelessSecurityWEPKey), - get_widget, - validate, - add_to_size_group, - fill_connection, - destroy); - if (!parent) - return NULL; - self = (WirelessSecurityWEPKey *) parent; + self = g_object_new (ws_wep_key_get_type (), NULL); self->builder = gtk_builder_new (); if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wep-key.ui", &error)) { @@ -344,7 +356,7 @@ ws_wep_key_new (NMConnection *connection, /* Fill the key entry with the key for that index */ if (connection) - update_secrets (WIRELESS_SECURITY (self), connection); + update_secrets (self, connection); g_signal_connect_swapped (self->show_key_check, "toggled", G_CALLBACK (show_toggled_cb), self); diff --git a/panels/network/wireless-security/ws-wep-key.h b/panels/network/wireless-security/ws-wep-key.h index 604eba6bb8..85003e2e6b 100644 --- a/panels/network/wireless-security/ws-wep-key.h +++ b/panels/network/wireless-security/ws-wep-key.h @@ -20,14 +20,19 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_WEP_KEY_H -#define WS_WEP_KEY_H +#pragma once -typedef struct _WirelessSecurityWEPKey WirelessSecurityWEPKey; +#include + +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityWEPKey, ws_wep_key, WS, WEP_KEY, WirelessSecurity) WirelessSecurityWEPKey *ws_wep_key_new (NMConnection *connection, NMWepKeyType type, gboolean adhoc_create, gboolean secrets_only); -#endif /* WS_WEP_KEY_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index cb9cff1564..943b72e9c8 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -41,33 +41,37 @@ struct _WirelessSecurityWPAEAP { GtkSizeGroup *size_group; }; +G_DEFINE_TYPE (WirelessSecurityWPAEAP, ws_wpa_eap, wireless_security_get_type ()) + static void -destroy (WirelessSecurity *parent) +ws_wpa_eap_dispose (GObject *object) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (object); g_clear_object (&self->builder); g_clear_object (&self->size_group); + + G_OBJECT_CLASS (ws_wpa_eap_parent_class)->dispose (object); } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (security); return GTK_WIDGET (self->grid); } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (security); return eap_method_validate (ws_802_1x_auth_combo_get_eap (self->auth_combo), error); } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (security); g_clear_object (&self->size_group); self->size_group = g_object_ref (group); @@ -77,9 +81,9 @@ add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityWPAEAP *self = (WirelessSecurityWPAEAP *) parent; + WirelessSecurityWPAEAP *self = WS_WPA_EAP (security); NMSettingWirelessSecurity *s_wireless_sec; ws_802_1x_fill_connection (self->auth_combo, connection); @@ -100,24 +104,33 @@ auth_combo_changed_cb (WirelessSecurityWPAEAP *self) wireless_security_notify_changed (WIRELESS_SECURITY (self)); } +void +ws_wpa_eap_init (WirelessSecurityWPAEAP *self) +{ +} + +void +ws_wpa_eap_class_init (WirelessSecurityWPAEAPClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_wpa_eap_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; +} + WirelessSecurityWPAEAP * ws_wpa_eap_new (NMConnection *connection, gboolean is_editor, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityWPAEAP *self; g_autoptr(GError) error = NULL; - parent = wireless_security_init (sizeof (WirelessSecurityWPAEAP), - get_widget, - validate, - add_to_size_group, - fill_connection, - destroy); - if (!parent) - return NULL; - self = (WirelessSecurityWPAEAP *) parent; + self = g_object_new (ws_wpa_eap_get_type (), NULL); self->builder = gtk_builder_new (); if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wpa-eap.ui", &error)) { @@ -130,9 +143,9 @@ ws_wpa_eap_new (NMConnection *connection, self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); self->method_box = GTK_BOX (gtk_builder_get_object (self->builder, "method_box")); - wireless_security_set_adhoc_compatible (parent, FALSE); + wireless_security_set_adhoc_compatible (WIRELESS_SECURITY (self), FALSE); - ws_802_1x_auth_combo_init (parent, + ws_802_1x_auth_combo_init (WIRELESS_SECURITY (self), self->auth_combo, connection, is_editor, diff --git a/panels/network/wireless-security/ws-wpa-eap.h b/panels/network/wireless-security/ws-wpa-eap.h index b5c1f9d4e2..605a1debe6 100644 --- a/panels/network/wireless-security/ws-wpa-eap.h +++ b/panels/network/wireless-security/ws-wpa-eap.h @@ -20,12 +20,15 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_WPA_EAP_H -#define WS_WPA_EAP_H +#pragma once -#include +#include -typedef struct _WirelessSecurityWPAEAP WirelessSecurityWPAEAP; +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityWPAEAP, ws_wpa_eap, WS, WPA_EAP, WirelessSecurity) WirelessSecurityWPAEAP *ws_wpa_eap_new (NMConnection *connection, gboolean is_editor, @@ -33,4 +36,4 @@ WirelessSecurityWPAEAP *ws_wpa_eap_new (NMConnection *connection, GtkComboBox *ws_wpa_eap_get_auth_combo (WirelessSecurityWPAEAP *sec); -#endif /* WS_WPA_EAP_H */ +G_END_DECLS diff --git a/panels/network/wireless-security/ws-wpa-psk.c b/panels/network/wireless-security/ws-wpa-psk.c index e253d17f47..000d90038d 100644 --- a/panels/network/wireless-security/ws-wpa-psk.c +++ b/panels/network/wireless-security/ws-wpa-psk.c @@ -48,18 +48,22 @@ struct _WirelessSecurityWPAPSK { const char *password_flags_name; }; +G_DEFINE_TYPE (WirelessSecurityWPAPSK, ws_wpa_psk, wireless_security_get_type ()) + static void -destroy (WirelessSecurity *parent) +ws_wpa_psk_dispose (GObject *object) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (object); g_clear_object (&self->builder); + + G_OBJECT_CLASS (ws_wpa_psk_parent_class)->dispose (object); } static GtkWidget * -get_widget (WirelessSecurity *parent) +get_widget (WirelessSecurity *security) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (security); return GTK_WIDGET (self->grid); } @@ -73,9 +77,9 @@ show_toggled_cb (WirelessSecurityWPAPSK *self) } static gboolean -validate (WirelessSecurity *parent, GError **error) +validate (WirelessSecurity *security, GError **error) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (security); const char *key; gsize len; int i; @@ -106,17 +110,17 @@ validate (WirelessSecurity *parent, GError **error) } static void -add_to_size_group (WirelessSecurity *parent, GtkSizeGroup *group) +add_to_size_group (WirelessSecurity *security, GtkSizeGroup *group) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (security); gtk_size_group_add_widget (group, GTK_WIDGET (self->type_label)); gtk_size_group_add_widget (group, GTK_WIDGET (self->password_label)); } static void -fill_connection (WirelessSecurity *parent, NMConnection *connection) +fill_connection (WirelessSecurity *security, NMConnection *connection) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; + WirelessSecurityWPAPSK *self = WS_WPA_PSK (security); const char *key; NMSettingWireless *s_wireless; NMSettingWirelessSecurity *s_wireless_sec; @@ -169,38 +173,37 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection) } static void -update_secrets (WirelessSecurity *parent, NMConnection *connection) +changed_cb (WirelessSecurityWPAPSK *self) { - WirelessSecurityWPAPSK *self = (WirelessSecurityWPAPSK *) parent; - helper_fill_secret_entry (connection, - self->password_entry, - NM_TYPE_SETTING_WIRELESS_SECURITY, - (HelperSecretFunc) nm_setting_wireless_security_get_psk); + wireless_security_notify_changed ((WirelessSecurity *) self); } -static void -changed_cb (WirelessSecurityWPAPSK *self) +void +ws_wpa_psk_init (WirelessSecurityWPAPSK *self) { - wireless_security_notify_changed ((WirelessSecurity *) self); +} + +void +ws_wpa_psk_class_init (WirelessSecurityWPAPSKClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + WirelessSecurityClass *ws_class = WIRELESS_SECURITY_CLASS (klass); + + object_class->dispose = ws_wpa_psk_dispose; + ws_class->get_widget = get_widget; + ws_class->validate = validate; + ws_class->add_to_size_group = add_to_size_group; + ws_class->fill_connection = fill_connection; } WirelessSecurityWPAPSK * ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only) { - WirelessSecurity *parent; WirelessSecurityWPAPSK *self; NMSetting *setting = NULL; g_autoptr(GError) error = NULL; - parent = wireless_security_init (sizeof (WirelessSecurityWPAPSK), - get_widget, - validate, - add_to_size_group, - fill_connection, - destroy); - if (!parent) - return NULL; - self = (WirelessSecurityWPAPSK *) parent; + self = g_object_new (ws_wpa_psk_get_type (), NULL); self->builder = gtk_builder_new (); if (!gtk_builder_add_from_resource (self->builder, "/org/gnome/ControlCenter/network/ws-wpa-psk.ui", &error)) { @@ -215,7 +218,7 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only) self->type_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "type_combo")); self->type_label = GTK_LABEL (gtk_builder_get_object (self->builder, "type_label")); - wireless_security_set_adhoc_compatible (parent, FALSE); + wireless_security_set_adhoc_compatible (WIRELESS_SECURITY (self), FALSE); self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_PSK; @@ -230,8 +233,12 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only) FALSE, secrets_only); /* Fill secrets, if any */ - if (connection) - update_secrets (WIRELESS_SECURITY (self), connection); + if (connection) { + helper_fill_secret_entry (connection, + self->password_entry, + NM_TYPE_SETTING_WIRELESS_SECURITY, + (HelperSecretFunc) nm_setting_wireless_security_get_psk); + } g_signal_connect_swapped (self->show_password_check, "toggled", G_CALLBACK (show_toggled_cb), self); diff --git a/panels/network/wireless-security/ws-wpa-psk.h b/panels/network/wireless-security/ws-wpa-psk.h index 8b84ed8563..d2c4a5bd22 100644 --- a/panels/network/wireless-security/ws-wpa-psk.h +++ b/panels/network/wireless-security/ws-wpa-psk.h @@ -20,11 +20,16 @@ * Copyright 2007 - 2014 Red Hat, Inc. */ -#ifndef WS_WPA_PSK_H -#define WS_WPA_PSK_H +#pragma once -typedef struct _WirelessSecurityWPAPSK WirelessSecurityWPAPSK; +#include + +#include "wireless-security.h" + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE (WirelessSecurityWPAPSK, ws_wpa_psk, WS, WPA_PSK, WirelessSecurity) WirelessSecurityWPAPSK * ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only); -#endif /* WS_WEP_KEY_H */ +G_END_DECLS -- GitLab From 125d971ebeaaab64efbe05d2d115a9cc18e10124 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 13:50:45 +1300 Subject: [PATCH 21/39] network: Replace a callback with a signal --- .../ce-page-8021x-security.c | 6 +-- .../connection-editor/ce-page-security.c | 6 +-- .../wireless-security/wireless-security.c | 37 +++++++++---------- .../wireless-security/wireless-security.h | 6 --- 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/panels/network/connection-editor/ce-page-8021x-security.c b/panels/network/connection-editor/ce-page-8021x-security.c index 19f8ef3c50..2e5f57f110 100644 --- a/panels/network/connection-editor/ce-page-8021x-security.c +++ b/panels/network/connection-editor/ce-page-8021x-security.c @@ -59,9 +59,9 @@ enable_toggled (CEPage8021xSecurity *self) } static void -stuff_changed (WirelessSecurity *sec, gpointer user_data) +security_item_changed_cb (CEPage8021xSecurity *self) { - ce_page_changed (CE_PAGE (user_data)); + ce_page_changed (CE_PAGE (self)); } static void @@ -80,7 +80,7 @@ finish_setup (CEPage8021xSecurity *self, gpointer unused, GError *error, gpointe return; } - wireless_security_set_changed_notify (WIRELESS_SECURITY (self->security), stuff_changed, self); + g_signal_connect_object (WIRELESS_SECURITY (self->security), "changed", G_CALLBACK (security_item_changed_cb), self, G_CONNECT_SWAPPED); self->security_widget = wireless_security_get_widget (WIRELESS_SECURITY (self->security)); parent = gtk_widget_get_parent (self->security_widget); if (parent) diff --git a/panels/network/connection-editor/ce-page-security.c b/panels/network/connection-editor/ce-page-security.c index 23cfd3276e..e2532696aa 100644 --- a/panels/network/connection-editor/ce-page-security.c +++ b/panels/network/connection-editor/ce-page-security.c @@ -174,9 +174,9 @@ security_combo_changed (CEPageSecurity *self) } static void -stuff_changed_cb (WirelessSecurity *sec, gpointer user_data) +security_item_changed_cb (CEPageSecurity *self) { - ce_page_changed (CE_PAGE (user_data)); + ce_page_changed (CE_PAGE (self)); } static void @@ -187,7 +187,7 @@ add_security_item (CEPageSecurity *self, const char *text, gboolean adhoc_valid) { - wireless_security_set_changed_notify (sec, stuff_changed_cb, self); + g_signal_connect_object (sec, "changed", G_CALLBACK (security_item_changed_cb), self, G_CONNECT_SWAPPED); gtk_list_store_append (model, iter); gtk_list_store_set (model, iter, S_NAME_COLUMN, text, diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index dbc9d346f6..0fff7e2185 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -36,16 +36,20 @@ #include "utils.h" typedef struct { - WSChangedFunc changed_notify; - gpointer changed_notify_data; gboolean adhoc_compatible; - char *username, *password; gboolean always_ask, show_password; } WirelessSecurityPrivate; G_DEFINE_TYPE_WITH_PRIVATE (WirelessSecurity, wireless_security, G_TYPE_OBJECT) +enum { + CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + static void wireless_security_dispose (GObject *object) { @@ -77,6 +81,15 @@ wireless_security_class_init (WirelessSecurityClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = wireless_security_dispose; + + signals[CHANGED] = + g_signal_new ("changed", + G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } GtkWidget * @@ -87,26 +100,12 @@ wireless_security_get_widget (WirelessSecurity *self) return WIRELESS_SECURITY_GET_CLASS (self)->get_widget (self); } -void -wireless_security_set_changed_notify (WirelessSecurity *self, - WSChangedFunc func, - gpointer user_data) -{ - WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - - g_return_if_fail (WIRELESS_IS_SECURITY (self)); - - priv->changed_notify = func; - priv->changed_notify_data = user_data; -} - void wireless_security_notify_changed (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); - if (priv->changed_notify) - (*(priv->changed_notify)) (self, priv->changed_notify_data); + g_signal_emit (self, signals[CHANGED], 0); } gboolean diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 3b82eb6c69..6604954ea7 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -28,8 +28,6 @@ G_BEGIN_DECLS G_DECLARE_DERIVABLE_TYPE (WirelessSecurity, wireless_security, WIRELESS, SECURITY, GObject) -typedef void (*WSChangedFunc) (WirelessSecurity *sec, gpointer user_data); - struct _WirelessSecurityClass { GObjectClass parent_class; @@ -41,10 +39,6 @@ struct _WirelessSecurityClass { GtkWidget *wireless_security_get_widget (WirelessSecurity *sec); -void wireless_security_set_changed_notify (WirelessSecurity *sec, - WSChangedFunc func, - gpointer user_data); - gboolean wireless_security_validate (WirelessSecurity *sec, GError **error); void wireless_security_add_to_size_group (WirelessSecurity *sec, -- GitLab From e5ae62a6a303fad49aeb385b556bbb943ee2c2cc Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 7 Nov 2019 13:58:30 +1300 Subject: [PATCH 22/39] network: Convert WirelessSecurity property to a virtual method --- .../wireless-security/wireless-security.c | 24 ++++--------------- .../wireless-security/wireless-security.h | 4 +--- .../wireless-security/ws-dynamic-wep.c | 9 +++++-- panels/network/wireless-security/ws-leap.c | 9 +++++-- panels/network/wireless-security/ws-wpa-eap.c | 9 +++++-- panels/network/wireless-security/ws-wpa-psk.c | 9 +++++-- 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index 0fff7e2185..fed7e20250 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -36,7 +36,6 @@ #include "utils.h" typedef struct { - gboolean adhoc_compatible; char *username, *password; gboolean always_ask, show_password; } WirelessSecurityPrivate; @@ -68,11 +67,7 @@ wireless_security_dispose (GObject *object) void wireless_security_init (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_resources_register (wireless_security_get_resource ()); - - priv->adhoc_compatible = TRUE; } void @@ -141,24 +136,13 @@ wireless_security_fill_connection (WirelessSecurity *self, return WIRELESS_SECURITY_GET_CLASS (self)->fill_connection (self, connection); } -void -wireless_security_set_adhoc_compatible (WirelessSecurity *self, gboolean adhoc_compatible) -{ - WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - - g_return_if_fail (WIRELESS_IS_SECURITY (self)); - - priv->adhoc_compatible = adhoc_compatible; -} - gboolean wireless_security_adhoc_compatible (WirelessSecurity *self) { - WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - - g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); - - return priv->adhoc_compatible; + if (WIRELESS_SECURITY_GET_CLASS (self)->adhoc_compatible) + return WIRELESS_SECURITY_GET_CLASS (self)->adhoc_compatible (self); + else + return TRUE; } const gchar * diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 6604954ea7..fbe0fd4d29 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -34,6 +34,7 @@ struct _WirelessSecurityClass { void (*add_to_size_group) (WirelessSecurity *sec, GtkSizeGroup *group); void (*fill_connection) (WirelessSecurity *sec, NMConnection *connection); gboolean (*validate) (WirelessSecurity *sec, GError **error); + gboolean (*adhoc_compatible) (WirelessSecurity *sec); GtkWidget* (*get_widget) (WirelessSecurity *sec); }; @@ -47,9 +48,6 @@ void wireless_security_add_to_size_group (WirelessSecurity *sec, void wireless_security_fill_connection (WirelessSecurity *sec, NMConnection *connection); -void wireless_security_set_adhoc_compatible (WirelessSecurity *sec, - gboolean adhoc_compatible); - gboolean wireless_security_adhoc_compatible (WirelessSecurity *sec); const gchar *wireless_security_get_username (WirelessSecurity *sec); diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index 46e1dabcb8..ae3d1b3faa 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -94,6 +94,12 @@ fill_connection (WirelessSecurity *security, NMConnection *connection) g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL); } +static gboolean +adhoc_compatible (WirelessSecurity *security) +{ + return FALSE; +} + static void auth_combo_changed_cb (WirelessSecurityDynamicWEP *self) { @@ -120,6 +126,7 @@ ws_dynamic_wep_class_init (WirelessSecurityDynamicWEPClass *klass) ws_class->validate = validate; ws_class->add_to_size_group = add_to_size_group; ws_class->fill_connection = fill_connection; + ws_class->adhoc_compatible = adhoc_compatible; } WirelessSecurityDynamicWEP * @@ -143,8 +150,6 @@ ws_dynamic_wep_new (NMConnection *connection, self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); self->method_box = GTK_BOX (gtk_builder_get_object (self->builder, "method_box")); - wireless_security_set_adhoc_compatible (WIRELESS_SECURITY (self), FALSE); - ws_802_1x_auth_combo_init (WIRELESS_SECURITY (self), self->auth_combo, connection, diff --git a/panels/network/wireless-security/ws-leap.c b/panels/network/wireless-security/ws-leap.c index 11cc34cc07..f8e148b736 100644 --- a/panels/network/wireless-security/ws-leap.c +++ b/panels/network/wireless-security/ws-leap.c @@ -142,6 +142,12 @@ fill_connection (WirelessSecurity *security, NMConnection *connection) NM_SETTING (s_wireless_sec), self->password_flags_name); } +static gboolean +adhoc_compatible (WirelessSecurity *security) +{ + return FALSE; +} + static void changed_cb (WirelessSecurityLEAP *self) { @@ -164,6 +170,7 @@ ws_leap_class_init (WirelessSecurityLEAPClass *klass) ws_class->validate = validate; ws_class->add_to_size_group = add_to_size_group; ws_class->fill_connection = fill_connection; + ws_class->adhoc_compatible = adhoc_compatible; } WirelessSecurityLEAP * @@ -187,8 +194,6 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only) } } - wireless_security_set_adhoc_compatible (WIRELESS_SECURITY (self), FALSE); - self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD; diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 943b72e9c8..868235393d 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -94,6 +94,12 @@ fill_connection (WirelessSecurity *security, NMConnection *connection) g_object_set (s_wireless_sec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); } +static gboolean +adhoc_compatible (WirelessSecurity *security) +{ + return FALSE; +} + static void auth_combo_changed_cb (WirelessSecurityWPAEAP *self) { @@ -120,6 +126,7 @@ ws_wpa_eap_class_init (WirelessSecurityWPAEAPClass *klass) ws_class->validate = validate; ws_class->add_to_size_group = add_to_size_group; ws_class->fill_connection = fill_connection; + ws_class->adhoc_compatible = adhoc_compatible; } WirelessSecurityWPAEAP * @@ -143,8 +150,6 @@ ws_wpa_eap_new (NMConnection *connection, self->grid = GTK_GRID (gtk_builder_get_object (self->builder, "grid")); self->method_box = GTK_BOX (gtk_builder_get_object (self->builder, "method_box")); - wireless_security_set_adhoc_compatible (WIRELESS_SECURITY (self), FALSE); - ws_802_1x_auth_combo_init (WIRELESS_SECURITY (self), self->auth_combo, connection, diff --git a/panels/network/wireless-security/ws-wpa-psk.c b/panels/network/wireless-security/ws-wpa-psk.c index 000d90038d..3081ba7aab 100644 --- a/panels/network/wireless-security/ws-wpa-psk.c +++ b/panels/network/wireless-security/ws-wpa-psk.c @@ -172,6 +172,12 @@ fill_connection (WirelessSecurity *security, NMConnection *connection) } } +static gboolean +adhoc_compatible (WirelessSecurity *security) +{ + return FALSE; +} + static void changed_cb (WirelessSecurityWPAPSK *self) { @@ -194,6 +200,7 @@ ws_wpa_psk_class_init (WirelessSecurityWPAPSKClass *klass) ws_class->validate = validate; ws_class->add_to_size_group = add_to_size_group; ws_class->fill_connection = fill_connection; + ws_class->adhoc_compatible = adhoc_compatible; } WirelessSecurityWPAPSK * @@ -218,8 +225,6 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only) self->type_combo = GTK_COMBO_BOX (gtk_builder_get_object (self->builder, "type_combo")); self->type_label = GTK_LABEL (gtk_builder_get_object (self->builder, "type_label")); - wireless_security_set_adhoc_compatible (WIRELESS_SECURITY (self), FALSE); - self->editing_connection = secrets_only ? FALSE : TRUE; self->password_flags_name = NM_SETTING_WIRELESS_SECURITY_PSK; -- GitLab From 131e89e690526876873527834514575d7fc10d23 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 10:10:18 +1300 Subject: [PATCH 23/39] network: Split up a combined setter into multiple methods --- .../wireless-security/eap-method-leap.c | 8 +-- .../wireless-security/eap-method-simple.c | 9 ++- .../wireless-security/wireless-security.c | 67 +++++++++++++------ .../wireless-security/wireless-security.h | 14 ++-- 4 files changed, 61 insertions(+), 37 deletions(-) diff --git a/panels/network/wireless-security/eap-method-leap.c b/panels/network/wireless-security/eap-method-leap.c index 55e818b495..e7b2ff91ca 100644 --- a/panels/network/wireless-security/eap-method-leap.c +++ b/panels/network/wireless-security/eap-method-leap.c @@ -171,11 +171,9 @@ widgets_realized (EAPMethodLEAP *self) static void widgets_unrealized (EAPMethodLEAP *self) { - wireless_security_set_userpass (self->ws_parent, - gtk_entry_get_text (self->username_entry), - gtk_entry_get_text (self->password_entry), - (gboolean) -1, - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check))); + wireless_security_set_username (self->ws_parent, gtk_entry_get_text (self->username_entry)); + wireless_security_set_password (self->ws_parent, gtk_entry_get_text (self->password_entry)); + wireless_security_set_show_password (self->ws_parent, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check))); } static void diff --git a/panels/network/wireless-security/eap-method-simple.c b/panels/network/wireless-security/eap-method-simple.c index 1125838771..01b1ef3dec 100644 --- a/panels/network/wireless-security/eap-method-simple.c +++ b/panels/network/wireless-security/eap-method-simple.c @@ -271,11 +271,10 @@ widgets_realized (EAPMethodSimple *self) static void widgets_unrealized (EAPMethodSimple *self) { - wireless_security_set_userpass (self->ws_parent, - gtk_entry_get_text (self->username_entry), - gtk_entry_get_text (self->password_entry), - always_ask_selected (self->password_entry), - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check))); + wireless_security_set_username (self->ws_parent, gtk_entry_get_text (self->username_entry)); + wireless_security_set_password (self->ws_parent, gtk_entry_get_text (self->password_entry)); + wireless_security_set_always_ask (self->ws_parent, always_ask_selected (self->password_entry)); + wireless_security_set_show_password (self->ws_parent, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->show_password_check))); } static void diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index fed7e20250..4a388bb073 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -145,6 +145,17 @@ wireless_security_adhoc_compatible (WirelessSecurity *self) return TRUE; } +void +wireless_security_set_username (WirelessSecurity *self, const gchar *username) +{ + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); + + g_return_if_fail (WIRELESS_IS_SECURITY (self)); + + g_clear_pointer (&priv->username, g_free); + priv->username = g_strdup (username); +} + const gchar * wireless_security_get_username (WirelessSecurity *self) { @@ -155,6 +166,20 @@ wireless_security_get_username (WirelessSecurity *self) return priv->username; } +void +wireless_security_set_password (WirelessSecurity *self, const gchar *password) +{ + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); + + g_return_if_fail (WIRELESS_IS_SECURITY (self)); + + if (priv->password) + memset (priv->password, 0, strlen (priv->password)); + + g_clear_pointer (&priv->password, g_free); + priv->password = g_strdup (password); +} + const gchar * wireless_security_get_password (WirelessSecurity *self) { @@ -165,47 +190,44 @@ wireless_security_get_password (WirelessSecurity *self) return priv->password; } -gboolean -wireless_security_get_always_ask (WirelessSecurity *self) +void +wireless_security_set_always_ask (WirelessSecurity *self, gboolean always_ask) { WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); - return priv->always_ask; + priv->always_ask = always_ask; } gboolean -wireless_security_get_show_password (WirelessSecurity *self) +wireless_security_get_always_ask (WirelessSecurity *self) { WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); - return priv->show_password; + return priv->always_ask; } void -wireless_security_set_userpass (WirelessSecurity *self, - const char *user, - const char *password, - gboolean always_ask, - gboolean show_password) +wireless_security_set_show_password (WirelessSecurity *self, gboolean show_password) { WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - g_clear_pointer (&priv->username, g_free); - priv->username = g_strdup (user); + g_return_if_fail (WIRELESS_IS_SECURITY (self)); - if (priv->password) - memset (priv->password, 0, strlen (priv->password)); + priv->show_password = show_password; +} - g_clear_pointer (&priv->password, g_free); - priv->password = g_strdup (password); +gboolean +wireless_security_get_show_password (WirelessSecurity *self) +{ + WirelessSecurityPrivate *priv = wireless_security_get_instance_private (self); - if (always_ask != (gboolean) -1) - priv->always_ask = always_ask; - priv->show_password = show_password; + g_return_val_if_fail (WIRELESS_IS_SECURITY (self), FALSE); + + return priv->show_password; } void @@ -319,7 +341,10 @@ ws_802_1x_auth_combo_init (WirelessSecurity *self, always_ask = !!(flags & NM_SETTING_SECRET_FLAG_NOT_SAVED); } } - wireless_security_set_userpass (self, user, password, always_ask, FALSE); + wireless_security_set_username (self, user); + wireless_security_set_password (self, password); + wireless_security_set_always_ask (self, always_ask); + wireless_security_set_show_password (self, FALSE); auth_model = gtk_list_store_new (2, G_TYPE_STRING, eap_method_get_type ()); diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index fbe0fd4d29..5ba8a8b549 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -50,19 +50,21 @@ void wireless_security_fill_connection (WirelessSecurity *sec, gboolean wireless_security_adhoc_compatible (WirelessSecurity *sec); +void wireless_security_set_username (WirelessSecurity *sec, const gchar *username); + const gchar *wireless_security_get_username (WirelessSecurity *sec); +void wireless_security_set_password (WirelessSecurity *sec, const gchar *password); + const gchar *wireless_security_get_password (WirelessSecurity *sec); +void wireless_security_set_always_ask (WirelessSecurity *sec, gboolean always_ask); + gboolean wireless_security_get_always_ask (WirelessSecurity *sec); -gboolean wireless_security_get_show_password (WirelessSecurity *sec); +void wireless_security_set_show_password (WirelessSecurity *sec, gboolean show_password); -void wireless_security_set_userpass (WirelessSecurity *sec, - const char *user, - const char *password, - gboolean always_ask, - gboolean show_password); +gboolean wireless_security_get_show_password (WirelessSecurity *sec); /* Below for internal use only */ -- GitLab From f8068545604853ff93f670776e75e69954c3ff1f Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 16:33:44 +1300 Subject: [PATCH 24/39] network: Remove a helper function This makes more sense to be in the two cases it is used. It should be refactored away in the future. --- .../wireless-security/wireless-security.c | 28 ------------------- .../wireless-security/wireless-security.h | 4 --- .../wireless-security/ws-dynamic-wep.c | 24 ++++++++++++++-- panels/network/wireless-security/ws-wpa-eap.c | 24 ++++++++++++++-- 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index 4a388bb073..f4801a0961 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -260,34 +260,6 @@ ws_802_1x_auth_combo_get_eap (GtkComboBox *combo) return eap; } -void -ws_802_1x_auth_combo_changed (GtkComboBox *combo, - GtkBox *vbox, - GtkSizeGroup *size_group) -{ - EAPMethod *eap; - GList *elt, *children; - GtkWidget *eap_default_field; - - /* Remove any previous wireless security widgets */ - children = gtk_container_get_children (GTK_CONTAINER (vbox)); - for (elt = children; elt; elt = g_list_next (elt)) - gtk_container_remove (GTK_CONTAINER (vbox), GTK_WIDGET (elt->data)); - - eap = ws_802_1x_auth_combo_get_eap (GTK_COMBO_BOX (combo)); - g_assert (eap); - - gtk_widget_unparent (GTK_WIDGET (eap)); - if (size_group) - eap_method_add_to_size_group (eap, size_group); - gtk_container_add (GTK_CONTAINER (vbox), g_object_ref (GTK_WIDGET (eap))); - - /* Refocus the EAP method's default widget */ - eap_default_field = eap_method_get_default_field (eap); - if (eap_default_field) - gtk_widget_grab_focus (eap_default_field); -} - void ws_802_1x_auth_combo_init (WirelessSecurity *self, GtkComboBox *combo, diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index 5ba8a8b549..ffa6b30148 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -81,10 +81,6 @@ void ws_802_1x_auth_combo_init (WirelessSecurity *sec, gboolean is_editor, gboolean secrets_only); -void ws_802_1x_auth_combo_changed (GtkComboBox *combo, - GtkBox *vbox, - GtkSizeGroup *size_group); - #include "eap-method.h" EAPMethod *ws_802_1x_auth_combo_get_eap (GtkComboBox *combo); diff --git a/panels/network/wireless-security/ws-dynamic-wep.c b/panels/network/wireless-security/ws-dynamic-wep.c index ae3d1b3faa..1d1e2fc0a2 100644 --- a/panels/network/wireless-security/ws-dynamic-wep.c +++ b/panels/network/wireless-security/ws-dynamic-wep.c @@ -103,9 +103,27 @@ adhoc_compatible (WirelessSecurity *security) static void auth_combo_changed_cb (WirelessSecurityDynamicWEP *self) { - ws_802_1x_auth_combo_changed (self->auth_combo, - self->method_box, - self->size_group); + EAPMethod *eap; + GList *elt, *children; + GtkWidget *eap_default_field; + + /* Remove any previous wireless security widgets */ + children = gtk_container_get_children (GTK_CONTAINER (self->method_box)); + for (elt = children; elt; elt = g_list_next (elt)) + gtk_container_remove (GTK_CONTAINER (self->method_box), GTK_WIDGET (elt->data)); + + eap = ws_802_1x_auth_combo_get_eap (self->auth_combo); + g_assert (eap); + + gtk_widget_unparent (GTK_WIDGET (eap)); + if (self->size_group) + eap_method_add_to_size_group (eap, self->size_group); + gtk_container_add (GTK_CONTAINER (self->method_box), g_object_ref (GTK_WIDGET (eap))); + + /* Refocus the EAP method's default widget */ + eap_default_field = eap_method_get_default_field (eap); + if (eap_default_field) + gtk_widget_grab_focus (eap_default_field); wireless_security_notify_changed (WIRELESS_SECURITY (self)); } diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c index 868235393d..f8fa7ff0d5 100644 --- a/panels/network/wireless-security/ws-wpa-eap.c +++ b/panels/network/wireless-security/ws-wpa-eap.c @@ -103,9 +103,27 @@ adhoc_compatible (WirelessSecurity *security) static void auth_combo_changed_cb (WirelessSecurityWPAEAP *self) { - ws_802_1x_auth_combo_changed (self->auth_combo, - self->method_box, - self->size_group); + EAPMethod *eap; + GList *elt, *children; + GtkWidget *eap_default_field; + + /* Remove any previous wireless security widgets */ + children = gtk_container_get_children (GTK_CONTAINER (self->method_box)); + for (elt = children; elt; elt = g_list_next (elt)) + gtk_container_remove (GTK_CONTAINER (self->method_box), GTK_WIDGET (elt->data)); + + eap = ws_802_1x_auth_combo_get_eap (self->auth_combo); + g_assert (eap); + + gtk_widget_unparent (GTK_WIDGET (eap)); + if (self->size_group) + eap_method_add_to_size_group (eap, self->size_group); + gtk_container_add (GTK_CONTAINER (self->method_box), g_object_ref (GTK_WIDGET (eap))); + + /* Refocus the EAP method's default widget */ + eap_default_field = eap_method_get_default_field (eap); + if (eap_default_field) + gtk_widget_grab_focus (eap_default_field); wireless_security_notify_changed (WIRELESS_SECURITY (self)); } -- GitLab From 737e5829d668e71dc8663878f7dd24c0166ac2dc Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Fri, 8 Nov 2019 16:54:13 +1300 Subject: [PATCH 25/39] network: Move private defines out of public header --- panels/network/wireless-security/wireless-security.c | 3 +++ panels/network/wireless-security/wireless-security.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/panels/network/wireless-security/wireless-security.c b/panels/network/wireless-security/wireless-security.c index f4801a0961..1a0738b959 100644 --- a/panels/network/wireless-security/wireless-security.c +++ b/panels/network/wireless-security/wireless-security.c @@ -49,6 +49,9 @@ enum { static guint signals[LAST_SIGNAL] = { 0 }; +#define AUTH_NAME_COLUMN 0 +#define AUTH_METHOD_COLUMN 1 + static void wireless_security_dispose (GObject *object) { diff --git a/panels/network/wireless-security/wireless-security.h b/panels/network/wireless-security/wireless-security.h index ffa6b30148..55f51c393c 100644 --- a/panels/network/wireless-security/wireless-security.h +++ b/panels/network/wireless-security/wireless-security.h @@ -72,9 +72,6 @@ void wireless_security_notify_changed (WirelessSecurity *sec); void wireless_security_clear_ciphers (NMConnection *connection); -#define AUTH_NAME_COLUMN 0 -#define AUTH_METHOD_COLUMN 1 - void ws_802_1x_auth_combo_init (WirelessSecurity *sec, GtkComboBox *combo, NMConnection *connection, -- GitLab From 748a5086406697b5310f72ad2eaea23ac18d155c Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Mon, 11 Nov 2019 11:24:07 +1300 Subject: [PATCH 26/39] network: Make EAP widgets not visible by default This makes them more consistent with other widgets. --- panels/network/wireless-security/eap-method-fast.c | 1 + panels/network/wireless-security/eap-method-fast.ui | 1 - panels/network/wireless-security/eap-method-leap.ui | 1 - panels/network/wireless-security/eap-method-peap.c | 1 + panels/network/wireless-security/eap-method-peap.ui | 1 - panels/network/wireless-security/eap-method-simple.ui | 1 - panels/network/wireless-security/eap-method-tls.ui | 1 - panels/network/wireless-security/eap-method-ttls.c | 1 + panels/network/wireless-security/eap-method-ttls.ui | 1 - panels/network/wireless-security/ws-dynamic-wep.c | 1 + panels/network/wireless-security/ws-wpa-eap.c | 1 + 11 files changed, 5 insertions(+), 6 deletions(-) diff --git a/panels/network/wireless-security/eap-method-fast.c b/panels/network/wireless-security/eap-method-fast.c index a88d67e91a..acb4b6f5bc 100644 --- a/panels/network/wireless-security/eap-method-fast.c +++ b/panels/network/wireless-security/eap-method-fast.c @@ -197,6 +197,7 @@ inner_auth_combo_changed_cb (EAPMethodFAST *self) gtk_widget_unparent (GTK_WIDGET (eap)); if (self->size_group) eap_method_add_to_size_group (eap, self->size_group); + gtk_widget_show (GTK_WIDGET (eap)); gtk_container_add (GTK_CONTAINER (self->inner_auth_box), g_object_ref (GTK_WIDGET (eap))); wireless_security_notify_changed (self->sec_parent); diff --git a/panels/network/wireless-security/eap-method-fast.ui b/panels/network/wireless-security/eap-method-fast.ui index 28964b427e..0a89636154 100644 --- a/panels/network/wireless-security/eap-method-fast.ui +++ b/panels/network/wireless-security/eap-method-fast.ui @@ -30,7 +30,6 @@