[gnome-control-center] network: Move GtkBuilder code from WirelessSecurity to subclasses



commit 4b182dd7c01db421532fbd70d4aa808f7f653231
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Nov 7 11:48:11 2019 +1300

    network: Move GtkBuilder code from WirelessSecurity to subclasses

 .../network/wireless-security/wireless-security.c  | 14 +---------
 .../network/wireless-security/wireless-security.h  |  4 +--
 panels/network/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 7f9ab9c77..1ad68d73c 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 3c581e07f..d4e44ea10 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 cba45c2c2..9be227db6 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 6e555f9c2..f2f1f7191 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 90fad5d29..0a799e75b 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 a8e7358b9..cb9cff156 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 9e4dac701..e253d17f4 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);
 


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