[gnome-control-center] network: Simplify net_object_add_to_stack function
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Simplify net_object_add_to_stack function
- Date: Tue, 5 Nov 2019 23:05:49 +0000 (UTC)
commit 76de0ce4086b486dd92251b5eec97377b6760024
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Oct 23 11:47:50 2019 +1300
network: Simplify net_object_add_to_stack function
Except in the WiFi case it was creating a stack with one child.
All the non-WiFi cases had the same logic.
panels/network/cc-network-panel.c | 48 +++++++++++++----------------------
panels/network/cc-wifi-panel.c | 6 ++++-
panels/network/net-device-bluetooth.c | 9 +++----
panels/network/net-device-ethernet.c | 8 +++---
panels/network/net-device-mobile.c | 8 +++---
panels/network/net-device-wifi.c | 14 +++-------
panels/network/net-object.c | 22 +++++++---------
panels/network/net-object.h | 6 ++---
panels/network/net-proxy.c | 9 +++----
panels/network/net-vpn.c | 9 +++----
10 files changed, 53 insertions(+), 86 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 3c4d5f780..8288e8144 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -57,7 +57,7 @@ struct _CcNetworkPanel
CcPanel parent;
GCancellable *cancellable;
- GHashTable *device_to_stack;
+ GHashTable *device_to_widget;
GPtrArray *devices;
NMClient *client;
MMManager *modem_manager;
@@ -215,7 +215,7 @@ cc_network_panel_dispose (GObject *object)
g_clear_object (&self->client);
g_clear_object (&self->modem_manager);
- g_clear_pointer (&self->device_to_stack, g_hash_table_destroy);
+ g_clear_pointer (&self->device_to_widget, g_hash_table_destroy);
g_clear_pointer (&self->devices, g_ptr_array_unref);
G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object);
@@ -240,12 +240,12 @@ cc_network_panel_get_help_uri (CcPanel *self)
static void
object_removed_cb (CcNetworkPanel *self, NetObject *object)
{
- GtkWidget *stack;
+ GtkWidget *widget;
/* remove device */
- stack = g_hash_table_lookup (self->device_to_stack, object);
- if (stack != NULL)
- gtk_widget_destroy (stack);
+ widget = g_hash_table_lookup (self->device_to_widget, object);
+ if (widget != NULL)
+ gtk_widget_destroy (widget);
}
GPtrArray *
@@ -431,18 +431,14 @@ update_bluetooth_section (CcNetworkPanel *self)
gtk_widget_set_visible (self->container_bluetooth, n_bluetooth > 0);
}
-static GtkWidget *
-add_device_stack (CcNetworkPanel *self, NetObject *object)
+static void
+add_object (CcNetworkPanel *self, NetObject *object, GtkContainer *container)
{
- GtkWidget *stack;
-
- stack = gtk_stack_new ();
- gtk_widget_show (stack);
- g_hash_table_insert (self->device_to_stack, object, stack);
-
- net_object_add_to_stack (object, GTK_STACK (stack), self->sizegroup);
+ GtkWidget *widget;
- return stack;
+ widget = net_object_get_widget (object, self->sizegroup);
+ g_hash_table_insert (self->device_to_widget, object, widget);
+ gtk_container_add (container, widget);
}
static void
@@ -451,7 +447,6 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
NMDeviceType type;
NetDevice *net_device;
const char *udi;
- GtkWidget *stack;
if (!nm_device_get_managed (device))
return;
@@ -475,8 +470,7 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
self->client,
device,
nm_device_get_udi (device)));
- stack = add_device_stack (self, NET_OBJECT (net_device));
- gtk_container_add (GTK_CONTAINER (self->box_wired), stack);
+ add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_wired));
break;
case NM_DEVICE_TYPE_MODEM:
net_device = NET_DEVICE (net_device_mobile_new (CC_PANEL (self),
@@ -484,8 +478,7 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
self->client,
device,
nm_device_get_udi (device)));
- stack = add_device_stack (self, NET_OBJECT (net_device));
- gtk_container_add (GTK_CONTAINER (self->box_wired), stack);
+ add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_wired));
break;
case NM_DEVICE_TYPE_BT:
net_device = NET_DEVICE (net_device_bluetooth_new (CC_PANEL (self),
@@ -493,8 +486,7 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
self->client,
device,
nm_device_get_udi (device)));
- stack = add_device_stack (self, NET_OBJECT (net_device));
- gtk_container_add (GTK_CONTAINER (self->box_bluetooth), stack);
+ add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_bluetooth));
break;
/* For Wi-Fi and VPN we handle connections separately; we correctly manage
@@ -569,14 +561,12 @@ panel_remove_device (CcNetworkPanel *self, NMDevice *device)
static void
panel_add_proxy_device (CcNetworkPanel *self)
{
- GtkWidget *stack;
NetProxy *proxy;
proxy = net_proxy_new ();
/* add proxy to stack */
- stack = add_device_stack (self, NET_OBJECT (proxy));
- gtk_container_add (GTK_CONTAINER (self->box_proxy), stack);
+ add_object (self, NET_OBJECT (proxy), GTK_CONTAINER (self->box_proxy));
/* add proxy to device list */
net_object_set_title (NET_OBJECT (proxy), _("Network proxy"));
@@ -687,7 +677,6 @@ find_net_object_by_id (CcNetworkPanel *self, const gchar *id)
static void
panel_add_vpn_device (CcNetworkPanel *self, NMConnection *connection)
{
- GtkWidget *stack;
NetVpn *net_vpn;
const gchar *id;
@@ -705,8 +694,7 @@ panel_add_vpn_device (CcNetworkPanel *self, NMConnection *connection)
G_CALLBACK (object_removed_cb), self, G_CONNECT_SWAPPED);
/* add as a panel */
- stack = add_device_stack (self, NET_OBJECT (net_vpn));
- gtk_container_add (GTK_CONTAINER (self->box_vpn), stack);
+ add_object (self, NET_OBJECT (net_vpn), GTK_CONTAINER (self->box_vpn));
net_object_set_title (NET_OBJECT (net_vpn), nm_connection_get_id (connection));
@@ -852,7 +840,7 @@ cc_network_panel_init (CcNetworkPanel *self)
self->cancellable = g_cancellable_new ();
self->devices = g_ptr_array_new_with_free_func (g_object_unref);
- self->device_to_stack = g_hash_table_new (g_direct_hash, g_direct_equal);
+ self->device_to_widget = g_hash_table_new (g_direct_hash, g_direct_equal);
/* add the virtual proxy device */
panel_add_proxy_device (self);
diff --git a/panels/network/cc-wifi-panel.c b/panels/network/cc-wifi-panel.c
index ca631ded1..2ef0ab440 100644
--- a/panels/network/cc-wifi-panel.c
+++ b/panels/network/cc-wifi-panel.c
@@ -150,6 +150,7 @@ add_wifi_device (CcWifiPanel *self,
{
GtkWidget *header_widget;
NetDeviceWifi *net_device;
+ GtkWidget *widget;
/* Only manage Wi-Fi devices */
if (!NM_IS_DEVICE_WIFI (device) || !nm_device_get_managed (device))
@@ -173,7 +174,10 @@ add_wifi_device (CcWifiPanel *self,
update_devices_names (self);
/* Needs to be added after the device is added to the self->devices array */
- net_object_add_to_stack (NET_OBJECT (net_device), self->stack, self->sizegroup);
+ widget = net_object_get_widget (NET_OBJECT (net_device), self->sizegroup);
+ gtk_stack_add_titled (self->stack, widget,
+ net_object_get_id (NET_OBJECT (net_device)),
+ nm_device_get_description (device));
}
static void
diff --git a/panels/network/net-device-bluetooth.c b/panels/network/net-device-bluetooth.c
index 3ef3d17cb..3276e1265 100644
--- a/panels/network/net-device-bluetooth.c
+++ b/panels/network/net-device-bluetooth.c
@@ -56,14 +56,11 @@ net_device_bluetooth_set_show_separator (NetDeviceBluetooth *self,
}
static GtkWidget *
-device_bluetooth_add_to_stack (NetObject *object,
- GtkStack *stack,
- GtkSizeGroup *heading_size_group)
+device_bluetooth_get_widget (NetObject *object,
+ GtkSizeGroup *heading_size_group)
{
NetDeviceBluetooth *self = NET_DEVICE_BLUETOOTH (object);
- /* add widgets to size group */
- gtk_stack_add_named (stack, GTK_WIDGET (self->box), net_object_get_id (object));
return GTK_WIDGET (self->box);
}
@@ -203,7 +200,7 @@ net_device_bluetooth_class_init (NetDeviceBluetoothClass *klass)
object_class->finalize = net_device_bluetooth_finalize;
object_class->constructed = net_device_bluetooth_constructed;
- parent_class->add_to_stack = device_bluetooth_add_to_stack;
+ parent_class->get_widget = device_bluetooth_get_widget;
parent_class->refresh = device_bluetooth_refresh;
}
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index 55eab37cd..4142ee1ff 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -58,13 +58,11 @@ struct _NetDeviceEthernet
G_DEFINE_TYPE (NetDeviceEthernet, net_device_ethernet, NET_TYPE_DEVICE)
static GtkWidget *
-device_ethernet_add_to_stack (NetObject *object,
- GtkStack *stack,
- GtkSizeGroup *heading_size_group)
+device_ethernet_get_widget (NetObject *object,
+ GtkSizeGroup *heading_size_group)
{
NetDeviceEthernet *self = NET_DEVICE_ETHERNET (object);
- gtk_stack_add_named (stack, GTK_WIDGET (self->box), net_object_get_id (object));
return GTK_WIDGET (self->box);
}
@@ -560,7 +558,7 @@ net_device_ethernet_class_init (NetDeviceEthernetClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
obj_class->refresh = device_ethernet_refresh;
- obj_class->add_to_stack = device_ethernet_add_to_stack;
+ obj_class->get_widget = device_ethernet_get_widget;
object_class->constructed = device_ethernet_constructed;
object_class->finalize = device_ethernet_finalize;
}
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index 424de6481..519490063 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -89,9 +89,8 @@ enum {
G_DEFINE_TYPE (NetDeviceMobile, net_device_mobile, NET_TYPE_DEVICE)
static GtkWidget *
-device_mobile_proxy_add_to_stack (NetObject *object,
- GtkStack *stack,
- GtkSizeGroup *heading_size_group)
+device_mobile_get_widget (NetObject *object,
+ GtkSizeGroup *heading_size_group)
{
NetDeviceMobile *self = NET_DEVICE_MOBILE (object);
@@ -99,7 +98,6 @@ device_mobile_proxy_add_to_stack (NetObject *object,
gtk_size_group_add_widget (heading_size_group, GTK_WIDGET (self->imei_heading_label));
gtk_size_group_add_widget (heading_size_group, GTK_WIDGET (self->network_label));
- gtk_stack_add_named (stack, GTK_WIDGET (self->box), net_object_get_id (object));
return GTK_WIDGET (self->box);
}
@@ -914,7 +912,7 @@ net_device_mobile_class_init (NetDeviceMobileClass *klass)
object_class->constructed = net_device_mobile_constructed;
object_class->get_property = net_device_mobile_get_property;
object_class->set_property = net_device_mobile_set_property;
- parent_class->add_to_stack = device_mobile_proxy_add_to_stack;
+ parent_class->get_widget = device_mobile_get_widget;
parent_class->refresh = device_mobile_refresh;
g_object_class_install_property (object_class,
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index f057e7c56..62bb071bd 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -128,19 +128,11 @@ net_device_wifi_get_title_widget (NetDeviceWifi *self)
}
static GtkWidget *
-device_wifi_proxy_add_to_stack (NetObject *object,
- GtkStack *stack,
- GtkSizeGroup *heading_size_group)
+device_wifi_proxy_get_widget (NetObject *object,
+ GtkSizeGroup *heading_size_group)
{
- NMDevice *nmdevice;
NetDeviceWifi *self = NET_DEVICE_WIFI (object);
- nmdevice = net_device_get_nm_device (NET_DEVICE (object));
-
- gtk_stack_add_titled (stack, GTK_WIDGET (self->notebook),
- net_object_get_id (object),
- nm_device_get_description (nmdevice));
-
return GTK_WIDGET (self->notebook);
}
@@ -1025,7 +1017,7 @@ net_device_wifi_class_init (NetDeviceWifiClass *klass)
object_class->finalize = net_device_wifi_finalize;
object_class->constructed = net_device_wifi_constructed;
object_class->get_property = net_device_wifi_get_property;
- parent_class->add_to_stack = device_wifi_proxy_add_to_stack;
+ parent_class->get_widget = device_wifi_proxy_get_widget;
parent_class->refresh = device_wifi_refresh;
g_object_class_install_property (object_class,
diff --git a/panels/network/net-object.c b/panels/network/net-object.c
index c67cafc72..905dc70c6 100644
--- a/panels/network/net-object.c
+++ b/panels/network/net-object.c
@@ -142,24 +142,20 @@ net_object_get_panel (NetObject *self)
}
GtkWidget *
-net_object_add_to_stack (NetObject *self,
- GtkStack *stack,
- GtkSizeGroup *heading_size_group)
+net_object_get_widget (NetObject *self,
+ GtkSizeGroup *heading_size_group)
{
GtkWidget *widget;
NetObjectClass *klass = NET_OBJECT_GET_CLASS (self);
NetObjectPrivate *priv = net_object_get_instance_private (self);
- if (klass->add_to_stack != NULL) {
- widget = klass->add_to_stack (self, stack, heading_size_group);
- g_object_set_data_full (G_OBJECT (widget),
- "NetObject::id",
- g_strdup (priv->id),
- g_free);
- return widget;
- }
- g_debug ("no klass->add_to_stack for %s", priv->id);
- return NULL;
+ widget = klass->get_widget (self, heading_size_group);
+ g_object_set_data_full (G_OBJECT (widget),
+ "NetObject::id",
+ g_strdup (priv->id),
+ g_free);
+
+ return widget;
}
void
diff --git a/panels/network/net-object.h b/panels/network/net-object.h
index af8f3eaa0..636f9ba82 100644
--- a/panels/network/net-object.h
+++ b/panels/network/net-object.h
@@ -38,8 +38,7 @@ struct _NetObjectClass
GObjectClass parent_class;
/* vtable */
- GtkWidget *(*add_to_stack) (NetObject *object,
- GtkStack *stack,
+ GtkWidget *(*get_widget) (NetObject *object,
GtkSizeGroup *heading_size_group);
void (*refresh) (NetObject *object);
};
@@ -56,8 +55,7 @@ CcNetworkPanel *net_object_get_panel (NetObject *object)
void net_object_emit_changed (NetObject *object);
void net_object_emit_removed (NetObject *object);
void net_object_refresh (NetObject *object);
-GtkWidget *net_object_add_to_stack (NetObject *object,
- GtkStack *stack,
+GtkWidget *net_object_get_widget (NetObject *object,
GtkSizeGroup *heading_size_group);
G_END_DECLS
diff --git a/panels/network/net-proxy.c b/panels/network/net-proxy.c
index a24cd1ba5..6f1b7db5b 100644
--- a/panels/network/net-proxy.c
+++ b/panels/network/net-proxy.c
@@ -193,14 +193,13 @@ show_dialog_cb (NetProxy *self)
}
static GtkWidget *
-net_proxy_add_to_stack (NetObject *object,
- GtkStack *stack,
- GtkSizeGroup *heading_size_group)
+net_proxy_get_widget (NetObject *object,
+ GtkSizeGroup *heading_size_group)
{
NetProxy *self = NET_PROXY (object);
gtk_size_group_add_widget (heading_size_group, GTK_WIDGET (self->main_widget));
- gtk_stack_add_named (stack, GTK_WIDGET (self->main_widget), net_object_get_id (object));
+
return GTK_WIDGET (self->main_widget);
}
@@ -224,7 +223,7 @@ net_proxy_class_init (NetProxyClass *klass)
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
object_class->finalize = net_proxy_finalize;
- parent_class->add_to_stack = net_proxy_add_to_stack;
+ parent_class->get_widget = net_proxy_get_widget;
}
static gboolean
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index 08fe7d1aa..512d90ded 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -137,14 +137,11 @@ net_vpn_set_connection (NetVpn *self, NMConnection *connection)
}
static GtkWidget *
-vpn_proxy_add_to_stack (NetObject *object,
- GtkStack *stack,
- GtkSizeGroup *heading_size_group)
+vpn_proxy_get_widget (NetObject *object,
+ GtkSizeGroup *heading_size_group)
{
NetVpn *self = NET_VPN (object);
- /* add widgets to size group */
- gtk_stack_add_named (stack, GTK_WIDGET (self->box), net_object_get_id (object));
return GTK_WIDGET (self->box);
}
@@ -376,7 +373,7 @@ net_vpn_class_init (NetVpnClass *klass)
object_class->set_property = net_vpn_set_property;
object_class->constructed = net_vpn_constructed;
object_class->finalize = net_vpn_finalize;
- parent_class->add_to_stack = vpn_proxy_add_to_stack;
+ parent_class->get_widget = vpn_proxy_get_widget;
parent_class->refresh = vpn_proxy_refresh;
pspec = g_param_spec_object ("connection", NULL, NULL,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]