[gnome-control-center] network: Access widgets via a virtual method, not the GtkBuilder IDs
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Access widgets via a virtual method, not the GtkBuilder IDs
- Date: Wed, 27 Nov 2019 22:10:34 +0000 (UTC)
commit b936955ff31612fa57d0da59efd8661cb460b0ac
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Nov 7 09:09:02 2019 +1300
network: Access widgets via a virtual method, not the GtkBuilder IDs
panels/network/wireless-security/eap-method-fast.c | 20 ++++++++++++++--
panels/network/wireless-security/eap-method-leap.c | 18 +++++++++++++--
panels/network/wireless-security/eap-method-peap.c | 22 +++++++++++++++---
.../network/wireless-security/eap-method-simple.c | 18 +++++++++++++--
panels/network/wireless-security/eap-method-tls.c | 22 +++++++++++++++---
panels/network/wireless-security/eap-method-ttls.c | 20 ++++++++++++++--
panels/network/wireless-security/eap-method.c | 27 +++++++++++-----------
panels/network/wireless-security/eap-method.h | 11 +++++----
.../network/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 ebfaa5247..e5363e862 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 c8de02b05..f324ca9f3 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 b2a6029f9..7c5ae556d 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 4e4247652..9e2a2c039 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 ecf4c0ef9..1a3e08511 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 aeecc33b6..697a37de8 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 34a2a0cb4..5b65126c1 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 68d2bcead..1b0f62dc2 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 e4f41c7c0..99c9c9b8d 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]