network: Tidy up use of modem object in NetDeviceMobile
This commit is contained in:
parent
6207f84ba2
commit
06e38dac90
3 changed files with 44 additions and 105 deletions
|
@ -438,6 +438,7 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
|
||||||
{
|
{
|
||||||
NMDeviceType type;
|
NMDeviceType type;
|
||||||
NetDevice *net_device;
|
NetDevice *net_device;
|
||||||
|
g_autoptr(GDBusObject) modem_object = NULL;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
if (!nm_device_get_managed (device))
|
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));
|
add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_wired));
|
||||||
break;
|
break;
|
||||||
case NM_DEVICE_TYPE_MODEM:
|
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));
|
add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_wired));
|
||||||
break;
|
break;
|
||||||
case NM_DEVICE_TYPE_BT:
|
case NM_DEVICE_TYPE_BT:
|
||||||
|
@ -482,30 +499,6 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
|
||||||
return;
|
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 */
|
/* Add to the devices array */
|
||||||
g_ptr_array_add (self->devices, net_device);
|
g_ptr_array_add (self->devices, net_device);
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ struct _NetDeviceMobile
|
||||||
GtkLabel *status_label;
|
GtkLabel *status_label;
|
||||||
|
|
||||||
NMClient *client;
|
NMClient *client;
|
||||||
|
GDBusObject *modem;
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
|
|
||||||
gboolean updating_device;
|
gboolean updating_device;
|
||||||
|
@ -83,12 +84,6 @@ enum {
|
||||||
COLUMN_LAST
|
COLUMN_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
|
||||||
PROP_0,
|
|
||||||
PROP_MODEM_OBJECT,
|
|
||||||
PROP_LAST
|
|
||||||
};
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (NetDeviceMobile, net_device_mobile, NET_TYPE_DEVICE)
|
G_DEFINE_TYPE (NetDeviceMobile, net_device_mobile, NET_TYPE_DEVICE)
|
||||||
|
|
||||||
static GtkWidget *
|
static GtkWidget *
|
||||||
|
@ -751,67 +746,6 @@ operator_name_updated (NetDeviceMobile *self)
|
||||||
device_mobile_refresh_operator_name (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
|
static void
|
||||||
net_device_mobile_dispose (GObject *object)
|
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->builder);
|
||||||
g_clear_object (&self->client);
|
g_clear_object (&self->client);
|
||||||
|
g_clear_object (&self->modem);
|
||||||
g_clear_object (&self->cancellable);
|
g_clear_object (&self->cancellable);
|
||||||
g_clear_object (&self->gsm_proxy);
|
g_clear_object (&self->gsm_proxy);
|
||||||
g_clear_object (&self->cdma_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);
|
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
object_class->dispose = net_device_mobile_dispose;
|
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->get_widget = device_mobile_get_widget;
|
||||||
parent_class->refresh = device_mobile_refresh;
|
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
|
static void
|
||||||
|
@ -916,7 +841,7 @@ net_device_mobile_init (NetDeviceMobile *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
NetDeviceMobile *
|
NetDeviceMobile *
|
||||||
net_device_mobile_new (NMClient *client, NMDevice *device)
|
net_device_mobile_new (NMClient *client, NMDevice *device, GDBusObject *modem)
|
||||||
{
|
{
|
||||||
NetDeviceMobile *self;
|
NetDeviceMobile *self;
|
||||||
NMDeviceModemCapabilities caps;
|
NMDeviceModemCapabilities caps;
|
||||||
|
@ -926,6 +851,26 @@ net_device_mobile_new (NMClient *client, NMDevice *device)
|
||||||
NULL);
|
NULL);
|
||||||
self->client = g_object_ref (client);
|
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));
|
caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
|
||||||
|
|
||||||
/* Only load proxies if we have broadband modems of the OLD ModemManager interface */
|
/* Only load proxies if we have broadband modems of the OLD ModemManager interface */
|
||||||
|
|
|
@ -32,6 +32,7 @@ G_BEGIN_DECLS
|
||||||
G_DECLARE_FINAL_TYPE (NetDeviceMobile, net_device_mobile, NET, DEVICE_MOBILE, NetDevice)
|
G_DECLARE_FINAL_TYPE (NetDeviceMobile, net_device_mobile, NET, DEVICE_MOBILE, NetDevice)
|
||||||
|
|
||||||
NetDeviceMobile *net_device_mobile_new (NMClient *client,
|
NetDeviceMobile *net_device_mobile_new (NMClient *client,
|
||||||
NMDevice *device);
|
NMDevice *device,
|
||||||
|
GDBusObject *modem);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue