[gnome-control-center] network: Refactor widget reference out using virtual method
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Refactor widget reference out using virtual method
- Date: Tue, 22 Oct 2019 20:16:51 +0000 (UTC)
commit 150e7902e659e87c029be95a9955dd5300a8249a
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Oct 3 21:39:37 2019 +1300
network: Refactor widget reference out using virtual method
.../network/wireless-security/wireless-security.c | 21 ++++++---------------
.../network/wireless-security/wireless-security.h | 15 ++++++++-------
panels/network/wireless-security/ws-dynamic-wep.c | 10 ++++++++--
panels/network/wireless-security/ws-leap.c | 10 ++++++++--
panels/network/wireless-security/ws-wep-key.c | 10 ++++++++--
panels/network/wireless-security/ws-wpa-eap.c | 10 ++++++++--
panels/network/wireless-security/ws-wpa-psk.c | 10 ++++++++--
7 files changed, 54 insertions(+), 32 deletions(-)
---
diff --git a/panels/network/wireless-security/wireless-security.c
b/panels/network/wireless-security/wireless-security.c
index e0f44302f..541b990e4 100644
--- a/panels/network/wireless-security/wireless-security.c
+++ b/panels/network/wireless-security/wireless-security.c
@@ -32,7 +32,6 @@
struct _WirelessSecurityPrivate {
guint32 refcount;
gsize obj_size;
- GtkWidget *ui_widget;
WSChangedFunc changed_notify;
gpointer changed_notify_data;
gboolean adhoc_compatible;
@@ -43,6 +42,7 @@ struct _WirelessSecurityPrivate {
WSAddToSizeGroupFunc add_to_size_group;
WSFillConnectionFunc fill_connection;
+ WSGetWidgetFunc get_widget;
WSUpdateSecretsFunc update_secrets;
WSValidateFunc validate;
WSDestroyFunc destroy;
@@ -70,7 +70,8 @@ wireless_security_get_widget (WirelessSecurity *sec)
WirelessSecurityPrivate *priv = sec->priv;
g_return_val_if_fail (sec != NULL, NULL);
- return priv->ui_widget;
+ g_assert (priv->get_widget);
+ return (*(priv->get_widget)) (sec);
}
void
@@ -181,8 +182,6 @@ wireless_security_unref (WirelessSecurity *sec)
if (sec->builder)
g_object_unref (sec->builder);
- if (priv->ui_widget)
- g_object_unref (priv->ui_widget);
g_slice_free1 (priv->obj_size, sec);
g_free (priv);
}
@@ -190,13 +189,13 @@ wireless_security_unref (WirelessSecurity *sec)
WirelessSecurity *
wireless_security_init (gsize obj_size,
+ WSGetWidgetFunc get_widget,
WSValidateFunc validate,
WSAddToSizeGroupFunc add_to_size_group,
WSFillConnectionFunc fill_connection,
WSUpdateSecretsFunc update_secrets,
WSDestroyFunc destroy,
- const char *ui_resource,
- const char *ui_widget_name)
+ const char *ui_resource)
{
g_autoptr(WirelessSecurity) sec = NULL;
WirelessSecurityPrivate *priv;
@@ -204,7 +203,6 @@ wireless_security_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);
g_type_ensure (WIRELESS_TYPE_SECURITY);
@@ -215,6 +213,7 @@ wireless_security_init (gsize obj_size,
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;
@@ -227,14 +226,6 @@ wireless_security_init (gsize obj_size,
return NULL;
}
- priv->ui_widget = GTK_WIDGET (gtk_builder_get_object (sec->builder, ui_widget_name));
- if (!priv->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 (priv->ui_widget);
-
priv->destroy = destroy;
priv->adhoc_compatible = TRUE;
priv->hotspot_compatible = TRUE;
diff --git a/panels/network/wireless-security/wireless-security.h
b/panels/network/wireless-security/wireless-security.h
index 1546585ba..e43fec7b3 100644
--- a/panels/network/wireless-security/wireless-security.h
+++ b/panels/network/wireless-security/wireless-security.h
@@ -32,11 +32,12 @@ typedef struct _WirelessSecurityPrivate WirelessSecurityPrivate;
typedef void (*WSChangedFunc) (WirelessSecurity *sec, gpointer user_data);
-typedef void (*WSAddToSizeGroupFunc) (WirelessSecurity *sec, GtkSizeGroup *group);
-typedef void (*WSFillConnectionFunc) (WirelessSecurity *sec, NMConnection *connection);
-typedef void (*WSUpdateSecretsFunc) (WirelessSecurity *sec, NMConnection *connection);
-typedef void (*WSDestroyFunc) (WirelessSecurity *sec);
-typedef gboolean (*WSValidateFunc) (WirelessSecurity *sec, GError **error);
+typedef void (*WSAddToSizeGroupFunc) (WirelessSecurity *sec, GtkSizeGroup *group);
+typedef void (*WSFillConnectionFunc) (WirelessSecurity *sec, NMConnection *connection);
+typedef void (*WSUpdateSecretsFunc) (WirelessSecurity *sec, NMConnection *connection);
+typedef void (*WSDestroyFunc) (WirelessSecurity *sec);
+typedef gboolean (*WSValidateFunc) (WirelessSecurity *sec, GError **error);
+typedef GtkWidget* (*WSGetWidgetFunc) (WirelessSecurity *sec);
struct _WirelessSecurity {
WirelessSecurityPrivate *priv;
@@ -104,13 +105,13 @@ GType wireless_security_get_type (void);
#include "ws-dynamic-wep.h"
WirelessSecurity *wireless_security_init (gsize obj_size,
+ WSGetWidgetFunc get_widget,
WSValidateFunc validate,
WSAddToSizeGroupFunc add_to_size_group,
WSFillConnectionFunc fill_connection,
WSUpdateSecretsFunc update_secrets,
WSDestroyFunc destroy,
- const char *ui_resource,
- const char *ui_widget_name);
+ const char *ui_resource);
void wireless_security_changed_cb (GtkWidget *entry, gpointer user_data);
diff --git a/panels/network/wireless-security/ws-dynamic-wep.c
b/panels/network/wireless-security/ws-dynamic-wep.c
index 499734dab..a36d8ea15 100644
--- a/panels/network/wireless-security/ws-dynamic-wep.c
+++ b/panels/network/wireless-security/ws-dynamic-wep.c
@@ -43,6 +43,12 @@ destroy (WirelessSecurity *parent)
g_object_unref (sec->size_group);
}
+static GtkWidget *
+get_widget (WirelessSecurity *parent)
+{
+ return GTK_WIDGET (gtk_builder_get_object (parent->builder, "dynamic_wep_grid"));
+}
+
static gboolean
validate (WirelessSecurity *parent, GError **error)
{
@@ -102,13 +108,13 @@ ws_dynamic_wep_new (NMConnection *connection,
WirelessSecurity *parent;
parent = wireless_security_init (sizeof (WirelessSecurityDynamicWEP),
+ get_widget,
validate,
add_to_size_group,
fill_connection,
update_secrets,
destroy,
- "/org/gnome/ControlCenter/network/ws-dynamic-wep.ui",
- "dynamic_wep_grid")
+ "/org/gnome/ControlCenter/network/ws-dynamic-wep.ui");
if (!parent)
return NULL;
diff --git a/panels/network/wireless-security/ws-leap.c b/panels/network/wireless-security/ws-leap.c
index 9d09491dc..36348ac9d 100644
--- a/panels/network/wireless-security/ws-leap.c
+++ b/panels/network/wireless-security/ws-leap.c
@@ -48,6 +48,12 @@ show_toggled_cb (GtkCheckButton *button, WirelessSecurity *sec)
gtk_entry_set_visibility (GTK_ENTRY (widget), visible);
}
+static GtkWidget *
+get_widget (WirelessSecurity *parent)
+{
+ return GTK_WIDGET (gtk_builder_get_object (parent->builder, "leap_grid"));
+}
+
static gboolean
validate (WirelessSecurity *parent, GError **error)
{
@@ -148,13 +154,13 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only)
NMSettingWirelessSecurity *wsec = NULL;
parent = wireless_security_init (sizeof (WirelessSecurityLEAP),
+ get_widget,
validate,
add_to_size_group,
fill_connection,
update_secrets,
NULL,
- "/org/gnome/ControlCenter/network/ws-leap.ui",
- "leap_grid");
+ "/org/gnome/ControlCenter/network/ws-leap.ui");
if (!parent)
return NULL;
diff --git a/panels/network/wireless-security/ws-wep-key.c b/panels/network/wireless-security/ws-wep-key.c
index 11ea8ad9f..af2e35f5a 100644
--- a/panels/network/wireless-security/ws-wep-key.c
+++ b/panels/network/wireless-security/ws-wep-key.c
@@ -90,6 +90,12 @@ destroy (WirelessSecurity *parent)
memset (sec->keys[i], 0, sizeof (sec->keys[i]));
}
+static GtkWidget *
+get_widget (WirelessSecurity *parent)
+{
+ return GTK_WIDGET (gtk_builder_get_object (parent->builder, "wep_key_grid"));
+}
+
static gboolean
validate (WirelessSecurity *parent, GError **error)
{
@@ -259,13 +265,13 @@ ws_wep_key_new (NMConnection *connection,
gboolean is_shared_key = FALSE;
parent = wireless_security_init (sizeof (WirelessSecurityWEPKey),
+ get_widget,
validate,
add_to_size_group,
fill_connection,
update_secrets,
destroy,
- "/org/gnome/ControlCenter/network/ws-wep-key.ui",
- "wep_key_grid");
+ "/org/gnome/ControlCenter/network/ws-wep-key.ui");
if (!parent)
return NULL;
diff --git a/panels/network/wireless-security/ws-wpa-eap.c b/panels/network/wireless-security/ws-wpa-eap.c
index 029c7e305..740b7f06a 100644
--- a/panels/network/wireless-security/ws-wpa-eap.c
+++ b/panels/network/wireless-security/ws-wpa-eap.c
@@ -44,6 +44,12 @@ destroy (WirelessSecurity *parent)
g_object_unref (sec->size_group);
}
+static GtkWidget *
+get_widget (WirelessSecurity *parent)
+{
+ return GTK_WIDGET (gtk_builder_get_object (parent->builder, "wpa_eap_grid"));
+}
+
static gboolean
validate (WirelessSecurity *parent, GError **error)
{
@@ -103,13 +109,13 @@ ws_wpa_eap_new (NMConnection *connection,
WirelessSecurity *parent;
parent = wireless_security_init (sizeof (WirelessSecurityWPAEAP),
+ get_widget,
validate,
add_to_size_group,
fill_connection,
update_secrets,
destroy,
- "/org/gnome/ControlCenter/network/ws-wpa-eap.ui",
- "wpa_eap_grid");
+ "/org/gnome/ControlCenter/network/ws-wpa-eap.ui");
if (!parent)
return NULL;
diff --git a/panels/network/wireless-security/ws-wpa-psk.c b/panels/network/wireless-security/ws-wpa-psk.c
index a7424ba2b..d80a63ca0 100644
--- a/panels/network/wireless-security/ws-wpa-psk.c
+++ b/panels/network/wireless-security/ws-wpa-psk.c
@@ -39,6 +39,12 @@ struct _WirelessSecurityWPAPSK {
const char *password_flags_name;
};
+static GtkWidget *
+get_widget (WirelessSecurity *parent)
+{
+ return GTK_WIDGET (gtk_builder_get_object (parent->builder, "wpa_psk_grid"));
+}
+
static void
show_toggled_cb (GtkCheckButton *button, WirelessSecurity *sec)
{
@@ -176,13 +182,13 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only)
GtkWidget *widget;
parent = wireless_security_init (sizeof (WirelessSecurityWPAPSK),
+ get_widget,
validate,
add_to_size_group,
fill_connection,
update_secrets,
NULL,
- "/org/gnome/ControlCenter/network/ws-wpa-psk.ui",
- "wpa_psk_grid");
+ "/org/gnome/ControlCenter/network/ws-wpa-psk.ui");
if (!parent)
return NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]