[gnome-control-center] network: Replace g_object_new with constructors
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Replace g_object_new with constructors
- Date: Tue, 5 Nov 2019 23:05:18 +0000 (UTC)
commit 0c92c7b4615e2bb2c5078cc39242bae1c2132552
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Oct 23 10:49:03 2019 +1300
network: Replace g_object_new with constructors
panels/network/cc-network-panel.c | 43 ++++++++++++++++++------------------
panels/network/cc-wifi-panel.c | 20 ++++++++---------
panels/network/net-device-ethernet.c | 16 ++++++++++++++
panels/network/net-device-ethernet.h | 6 +++++
panels/network/net-device-mobile.c | 16 ++++++++++++++
panels/network/net-device-mobile.h | 6 +++++
panels/network/net-device-simple.c | 17 +++++++++++++-
panels/network/net-device-simple.h | 18 ++++++++++-----
panels/network/net-device-wifi.c | 16 ++++++++++++++
panels/network/net-device-wifi.h | 11 +++++++--
panels/network/net-vpn.c | 14 ++++++++++++
panels/network/net-vpn.h | 9 ++++++--
12 files changed, 148 insertions(+), 44 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 0970bb590..80ecb7f0a 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -450,7 +450,6 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
{
NMDeviceType type;
NetDevice *net_device;
- GType device_g_type;
const char *udi;
GtkWidget *stack;
@@ -471,13 +470,25 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
switch (type) {
case NM_DEVICE_TYPE_ETHERNET:
case NM_DEVICE_TYPE_INFINIBAND:
- device_g_type = NET_TYPE_DEVICE_ETHERNET;
+ net_device = NET_DEVICE (net_device_ethernet_new (CC_PANEL (self),
+ self->cancellable,
+ self->client,
+ device,
+ nm_device_get_udi (device)));
break;
case NM_DEVICE_TYPE_MODEM:
- device_g_type = NET_TYPE_DEVICE_MOBILE;
+ net_device = NET_DEVICE (net_device_mobile_new (CC_PANEL (self),
+ self->cancellable,
+ self->client,
+ device,
+ nm_device_get_udi (device)));
break;
case NM_DEVICE_TYPE_BT:
- device_g_type = NET_TYPE_DEVICE_SIMPLE;
+ net_device = NET_DEVICE (net_device_simple_new (CC_PANEL (self),
+ self->cancellable,
+ self->client,
+ device,
+ nm_device_get_udi (device)));
break;
/* For Wi-Fi and VPN we handle connections separately; we correctly manage
@@ -490,15 +501,6 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
return;
}
- /* create device */
- net_device = g_object_new (device_g_type,
- "panel", self,
- "cancellable", self->cancellable,
- "client", self->client,
- "nm-device", device,
- "id", nm_device_get_udi (device),
- NULL);
-
if (type == NM_DEVICE_TYPE_MODEM &&
g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager1/Modem/")) {
g_autoptr(GDBusObject) modem_object = NULL;
@@ -523,9 +525,8 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
NULL);
}
- /* add as a panel */
stack = add_device_stack (self, NET_OBJECT (net_device));
- if (device_g_type == NET_TYPE_DEVICE_SIMPLE)
+ if (type == NM_DEVICE_TYPE_BT)
gtk_container_add (GTK_CONTAINER (self->box_simple), stack);
else
gtk_container_add (GTK_CONTAINER (self->box_wired), stack);
@@ -536,7 +537,7 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
/* Update the device_simple section if we're adding a simple
* device. This is a temporary solution though, for these will
* be handled by the future Mobile Broadband panel */
- if (device_g_type == NET_TYPE_DEVICE_SIMPLE)
+ if (type == NM_DEVICE_TYPE_BT)
update_simple_section (self);
g_signal_connect_object (net_device, "removed",
@@ -696,12 +697,10 @@ panel_add_vpn_device (CcNetworkPanel *self, NMConnection *connection)
return;
/* add as a VPN object */
- net_vpn = g_object_new (NET_TYPE_VPN,
- "panel", self,
- "id", id,
- "connection", connection,
- "client", self->client,
- NULL);
+ net_vpn = net_vpn_new (CC_PANEL (self),
+ id,
+ connection,
+ self->client);
g_signal_connect_object (net_vpn, "removed",
G_CALLBACK (object_removed_cb), self, G_CONNECT_SWAPPED);
diff --git a/panels/network/cc-wifi-panel.c b/panels/network/cc-wifi-panel.c
index 86841f8a1..ca631ded1 100644
--- a/panels/network/cc-wifi-panel.c
+++ b/panels/network/cc-wifi-panel.c
@@ -149,25 +149,23 @@ add_wifi_device (CcWifiPanel *self,
NMDevice *device)
{
GtkWidget *header_widget;
- NetObject *net_device;
+ NetDeviceWifi *net_device;
/* Only manage Wi-Fi devices */
if (!NM_IS_DEVICE_WIFI (device) || !nm_device_get_managed (device))
return;
/* Create the NetDevice */
- net_device = g_object_new (NET_TYPE_DEVICE_WIFI,
- "panel", self,
- "cancellable", self->cancellable,
- "client", self->client,
- "nm-device", device,
- "id", nm_device_get_udi (device),
- NULL);
+ net_device = net_device_wifi_new (CC_PANEL (self),
+ self->cancellable,
+ self->client,
+ device,
+ nm_device_get_udi (device));
/* And add to the header widgets */
- header_widget = net_device_wifi_get_header_widget (NET_DEVICE_WIFI (net_device));
+ header_widget = net_device_wifi_get_header_widget (net_device);
- gtk_stack_add_named (self->header_stack, header_widget, net_object_get_id (net_device));
+ gtk_stack_add_named (self->header_stack, header_widget, net_object_get_id (NET_OBJECT (net_device)));
/* Setup custom title properties */
g_ptr_array_add (self->devices, net_device);
@@ -175,7 +173,7 @@ 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_device, self->stack, self->sizegroup);
+ net_object_add_to_stack (NET_OBJECT (net_device), self->stack, self->sizegroup);
}
static void
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index a7c7216eb..a9694b262 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -605,3 +605,19 @@ net_device_ethernet_init (NetDeviceEthernet *self)
g_signal_connect (self, "notify::title", G_CALLBACK (device_title_changed), NULL);
}
+
+NetDeviceEthernet *
+net_device_ethernet_new (CcPanel *panel,
+ GCancellable *cancellable,
+ NMClient *client,
+ NMDevice *device,
+ const gchar *id)
+{
+ return g_object_new (NET_TYPE_DEVICE_ETHERNET,
+ "panel", panel,
+ "cancellable", cancellable,
+ "client", client,
+ "nm-device", device,
+ "id", id,
+ NULL);
+}
diff --git a/panels/network/net-device-ethernet.h b/panels/network/net-device-ethernet.h
index d8b087fcc..7d1190839 100644
--- a/panels/network/net-device-ethernet.h
+++ b/panels/network/net-device-ethernet.h
@@ -30,4 +30,10 @@ G_BEGIN_DECLS
#define NET_TYPE_DEVICE_ETHERNET (net_device_ethernet_get_type ())
G_DECLARE_FINAL_TYPE (NetDeviceEthernet, net_device_ethernet, NET, DEVICE_ETHERNET, NetDeviceSimple)
+NetDeviceEthernet *net_device_ethernet_new (CcPanel *panel,
+ GCancellable *cancellable,
+ NMClient *client,
+ NMDevice *device,
+ const gchar *id);
+
G_END_DECLS
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index c76adeb0c..424de6481 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -981,3 +981,19 @@ net_device_mobile_init (NetDeviceMobile *self)
G_CALLBACK (edit_connection), self);
gtk_widget_set_visible (GTK_WIDGET (self->options_button), g_find_program_in_path
("nm-connection-editor") != NULL);
}
+
+NetDeviceMobile *
+net_device_mobile_new (CcPanel *panel,
+ GCancellable *cancellable,
+ NMClient *client,
+ NMDevice *device,
+ const gchar *id)
+{
+ return g_object_new (NET_TYPE_DEVICE_MOBILE,
+ "panel", panel,
+ "cancellable", cancellable,
+ "client", client,
+ "nm-device", device,
+ "id", id,
+ NULL);
+}
diff --git a/panels/network/net-device-mobile.h b/panels/network/net-device-mobile.h
index 2ab30deab..673d4309d 100644
--- a/panels/network/net-device-mobile.h
+++ b/panels/network/net-device-mobile.h
@@ -31,4 +31,10 @@ G_BEGIN_DECLS
#define NET_TYPE_DEVICE_MOBILE (net_device_mobile_get_type ())
G_DECLARE_FINAL_TYPE (NetDeviceMobile, net_device_mobile, NET, DEVICE_MOBILE, NetDevice)
+NetDeviceMobile *net_device_mobile_new (CcPanel *panel,
+ GCancellable *cancellable,
+ NMClient *client,
+ NMDevice *device,
+ const gchar *id);
+
G_END_DECLS
diff --git a/panels/network/net-device-simple.c b/panels/network/net-device-simple.c
index 451481400..4856416aa 100644
--- a/panels/network/net-device-simple.c
+++ b/panels/network/net-device-simple.c
@@ -253,6 +253,22 @@ net_device_simple_init (NetDeviceSimple *self)
gtk_widget_set_visible (GTK_WIDGET (priv->options_button), g_find_program_in_path
("nm-connection-editor") != NULL);
}
+NetDeviceSimple *
+net_device_simple_new (CcPanel *panel,
+ GCancellable *cancellable,
+ NMClient *client,
+ NMDevice *device,
+ const gchar *id)
+{
+ return g_object_new (NET_TYPE_DEVICE_SIMPLE,
+ "panel", panel,
+ "cancellable", cancellable,
+ "client", client,
+ "nm-device", device,
+ "id", id,
+ NULL);
+}
+
char *
net_device_simple_get_speed (NetDeviceSimple *self)
{
@@ -290,4 +306,3 @@ net_device_simple_add_row (NetDeviceSimple *self,
gtk_grid_attach (priv->grid, value, 1, top_attach, 1, 1);
gtk_widget_show (value);
}
-
diff --git a/panels/network/net-device-simple.h b/panels/network/net-device-simple.h
index edd6dd271..885869f1f 100644
--- a/panels/network/net-device-simple.h
+++ b/panels/network/net-device-simple.h
@@ -38,13 +38,19 @@ struct _NetDeviceSimpleClass
char *(*get_speed) (NetDeviceSimple *device_simple);
};
-char *net_device_simple_get_speed (NetDeviceSimple *device_simple);
+NetDeviceSimple *net_device_simple_new (CcPanel *panel,
+ GCancellable *cancellable,
+ NMClient *client,
+ NMDevice *device,
+ const gchar *id);
-void net_device_simple_add_row (NetDeviceSimple *device_simple,
- const char *label,
- const char *property_name);
+char *net_device_simple_get_speed (NetDeviceSimple *device_simple);
-void net_device_simple_set_show_separator (NetDeviceSimple *device_simple,
- gboolean show_separator);
+void net_device_simple_add_row (NetDeviceSimple *device_simple,
+ const char *label,
+ const char *property_name);
+
+void net_device_simple_set_show_separator (NetDeviceSimple *device_simple,
+ gboolean show_separator);
G_END_DECLS
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 49bec8587..f057e7c56 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -99,6 +99,22 @@ enum {
G_DEFINE_TYPE (NetDeviceWifi, net_device_wifi, NET_TYPE_DEVICE)
+NetDeviceWifi *
+net_device_wifi_new (CcPanel *panel,
+ GCancellable *cancellable,
+ NMClient *client,
+ NMDevice *device,
+ const gchar *id)
+{
+ return g_object_new (NET_TYPE_DEVICE_WIFI,
+ "panel", panel,
+ "cancellable", cancellable,
+ "client", client,
+ "nm-device", device,
+ "id", id,
+ NULL);
+}
+
GtkWidget *
net_device_wifi_get_header_widget (NetDeviceWifi *self)
{
diff --git a/panels/network/net-device-wifi.h b/panels/network/net-device-wifi.h
index 2bf78a0ec..ada9a40ec 100644
--- a/panels/network/net-device-wifi.h
+++ b/panels/network/net-device-wifi.h
@@ -30,8 +30,15 @@ G_BEGIN_DECLS
#define NET_TYPE_DEVICE_WIFI (net_device_wifi_get_type ())
G_DECLARE_FINAL_TYPE (NetDeviceWifi, net_device_wifi, NET, DEVICE_WIFI, NetDevice)
-GtkWidget *net_device_wifi_get_header_widget (NetDeviceWifi *device_wifi);
-GtkWidget *net_device_wifi_get_title_widget (NetDeviceWifi *device_wifi);
+NetDeviceWifi *net_device_wifi_new (CcPanel *panel,
+ GCancellable *cancellable,
+ NMClient *client,
+ NMDevice *device,
+ const gchar *id);
+
+GtkWidget *net_device_wifi_get_header_widget (NetDeviceWifi *device_wifi);
+
+GtkWidget *net_device_wifi_get_title_widget (NetDeviceWifi *device_wifi);
G_END_DECLS
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index 91232827e..08fe7d1aa 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -60,6 +60,20 @@ G_DEFINE_TYPE (NetVpn, net_vpn, NET_TYPE_OBJECT)
static void nm_device_refresh_vpn_ui (NetVpn *self);
+NetVpn *
+net_vpn_new (CcPanel *panel,
+ const gchar *id,
+ NMConnection *connection,
+ NMClient *client)
+{
+ return g_object_new (NET_TYPE_VPN,
+ "panel", panel,
+ "id", id,
+ "connection", connection,
+ "client", client,
+ NULL);
+}
+
void
net_vpn_set_show_separator (NetVpn *self,
gboolean show_separator)
diff --git a/panels/network/net-vpn.h b/panels/network/net-vpn.h
index 049a4dcc7..7c3e975af 100644
--- a/panels/network/net-vpn.h
+++ b/panels/network/net-vpn.h
@@ -31,7 +31,12 @@ G_BEGIN_DECLS
#define NET_TYPE_VPN (net_vpn_get_type ())
G_DECLARE_FINAL_TYPE (NetVpn, net_vpn, NET, VPN, NetObject)
-void net_vpn_set_show_separator (NetVpn *self,
- gboolean show_separator);
+NetVpn *net_vpn_new (CcPanel *panel,
+ const gchar *id,
+ NMConnection *connection,
+ NMClient *client);
+
+void net_vpn_set_show_separator (NetVpn *self,
+ gboolean show_separator);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]