[gnome-control-center] network: Tidy up use of modem object in NetDeviceMobile
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Tidy up use of modem object in NetDeviceMobile
- Date: Tue, 5 Nov 2019 23:06:34 +0000 (UTC)
commit 06e38dac90a66c93cdfe0025cf842fd26e14d691
Author: Robert Ancell <robert ancell canonical com>
Date: Wed Oct 23 14:56:18 2019 +1300
network: Tidy up use of modem object in NetDeviceMobile
panels/network/cc-network-panel.c | 43 +++++++---------
panels/network/net-device-mobile.c | 101 +++++++++----------------------------
panels/network/net-device-mobile.h | 5 +-
3 files changed, 44 insertions(+), 105 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 1c3b46212..b443cf09a 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -438,6 +438,7 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
{
NMDeviceType type;
NetDevice *net_device;
+ g_autoptr(GDBusObject) modem_object = NULL;
guint i;
if (!nm_device_get_managed (device))
@@ -464,7 +465,23 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
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 (self->client, device));
+ if (g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager1/Modem/")) {
+ if (self->modem_manager == NULL) {
+ g_warning ("Cannot grab information for modem at %s: No ModemManager
support",
+ nm_device_get_udi (device));
+ return;
+ }
+
+ modem_object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER
(self->modem_manager),
+ nm_device_get_udi (device));
+ if (modem_object == NULL) {
+ g_warning ("Cannot grab information for modem at %s: Not found",
+ nm_device_get_udi (device));
+ return;
+ }
+ }
+
+ net_device = NET_DEVICE (net_device_mobile_new (self->client, device, modem_object));
add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_wired));
break;
case NM_DEVICE_TYPE_BT:
@@ -482,30 +499,6 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
return;
}
- 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;
-
- if (self->modem_manager == NULL) {
- g_warning ("Cannot grab information for modem at %s: No ModemManager support",
- nm_device_get_udi (device));
- return;
- }
-
- modem_object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (self->modem_manager),
- nm_device_get_udi (device));
- if (modem_object == NULL) {
- g_warning ("Cannot grab information for modem at %s: Not found",
- nm_device_get_udi (device));
- return;
- }
-
- /* Set the modem object in the NetDeviceMobile */
- g_object_set (net_device,
- "mm-object", modem_object,
- NULL);
- }
-
/* Add to the devices array */
g_ptr_array_add (self->devices, net_device);
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index d3696d7ff..93ceccbf4 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -62,6 +62,7 @@ struct _NetDeviceMobile
GtkLabel *status_label;
NMClient *client;
+ GDBusObject *modem;
GCancellable *cancellable;
gboolean updating_device;
@@ -83,12 +84,6 @@ enum {
COLUMN_LAST
};
-enum {
- PROP_0,
- PROP_MODEM_OBJECT,
- PROP_LAST
-};
-
G_DEFINE_TYPE (NetDeviceMobile, net_device_mobile, NET_TYPE_DEVICE)
static GtkWidget *
@@ -751,67 +746,6 @@ operator_name_updated (NetDeviceMobile *self)
device_mobile_refresh_operator_name (self);
}
-static void
-net_device_mobile_setup_modem_object (NetDeviceMobile *self)
-{
- MMModem3gpp *modem_3gpp;
-
- if (self->mm_object == NULL)
- return;
-
- /* Load equipment ID initially */
- device_mobile_refresh_equipment_id (self);
-
- /* Follow changes in operator name and load initial values */
- modem_3gpp = mm_object_peek_modem_3gpp (self->mm_object);
- if (modem_3gpp != NULL) {
- g_assert (self->operator_name_updated == 0);
- self->operator_name_updated = g_signal_connect_swapped (modem_3gpp,
- "notify::operator-name",
- G_CALLBACK (operator_name_updated),
- self);
- device_mobile_refresh_operator_name (self);
- }
-}
-
-
-static void
-net_device_mobile_get_property (GObject *device_,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NetDeviceMobile *self = NET_DEVICE_MOBILE (device_);
-
- switch (prop_id) {
- case PROP_MODEM_OBJECT:
- g_value_set_object (value, self->mm_object);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
- break;
- }
-}
-
-static void
-net_device_mobile_set_property (GObject *device_,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- NetDeviceMobile *self = NET_DEVICE_MOBILE (device_);
-
- switch (prop_id) {
- case PROP_MODEM_OBJECT:
- self->mm_object = g_value_dup_object (value);
- net_device_mobile_setup_modem_object (self);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
- break;
- }
-}
-
static void
net_device_mobile_dispose (GObject *object)
{
@@ -821,6 +755,7 @@ net_device_mobile_dispose (GObject *object)
g_clear_object (&self->builder);
g_clear_object (&self->client);
+ g_clear_object (&self->modem);
g_clear_object (&self->cancellable);
g_clear_object (&self->gsm_proxy);
g_clear_object (&self->cdma_proxy);
@@ -843,18 +778,8 @@ net_device_mobile_class_init (NetDeviceMobileClass *klass)
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
object_class->dispose = net_device_mobile_dispose;
- object_class->get_property = net_device_mobile_get_property;
- object_class->set_property = net_device_mobile_set_property;
parent_class->get_widget = device_mobile_get_widget;
parent_class->refresh = device_mobile_refresh;
-
- g_object_class_install_property (object_class,
- PROP_MODEM_OBJECT,
- g_param_spec_object ("mm-object",
- NULL,
- NULL,
- MM_TYPE_OBJECT,
- G_PARAM_READWRITE));
}
static void
@@ -916,7 +841,7 @@ net_device_mobile_init (NetDeviceMobile *self)
}
NetDeviceMobile *
-net_device_mobile_new (NMClient *client, NMDevice *device)
+net_device_mobile_new (NMClient *client, NMDevice *device, GDBusObject *modem)
{
NetDeviceMobile *self;
NMDeviceModemCapabilities caps;
@@ -926,6 +851,26 @@ net_device_mobile_new (NMClient *client, NMDevice *device)
NULL);
self->client = g_object_ref (client);
+ if (modem != NULL) {
+ MMModem3gpp *modem_3gpp;
+
+ self->modem = g_object_ref (modem);
+
+ /* Load equipment ID initially */
+ device_mobile_refresh_equipment_id (self);
+
+ /* Follow changes in operator name and load initial values */
+ modem_3gpp = mm_object_peek_modem_3gpp (self->mm_object);
+ if (modem_3gpp != NULL) {
+ g_assert (self->operator_name_updated == 0);
+ self->operator_name_updated = g_signal_connect_swapped (modem_3gpp,
+ "notify::operator-name",
+ G_CALLBACK
(operator_name_updated),
+ self);
+ device_mobile_refresh_operator_name (self);
+ }
+ }
+
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
/* Only load proxies if we have broadband modems of the OLD ModemManager interface */
diff --git a/panels/network/net-device-mobile.h b/panels/network/net-device-mobile.h
index 2022222bd..94d6f9c2c 100644
--- a/panels/network/net-device-mobile.h
+++ b/panels/network/net-device-mobile.h
@@ -31,7 +31,8 @@ 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 (NMClient *client,
- NMDevice *device);
+NetDeviceMobile *net_device_mobile_new (NMClient *client,
+ NMDevice *device,
+ GDBusObject *modem);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]