diff --git a/panels/network/net-device-bluetooth.c b/panels/network/net-device-bluetooth.c index 2be157d34..c83721f47 100644 --- a/panels/network/net-device-bluetooth.c +++ b/panels/network/net-device-bluetooth.c @@ -127,12 +127,13 @@ device_off_toggled (NetDeviceBluetooth *self) if (self->updating_device) return; + client = net_object_get_client (NET_OBJECT (self)); + connection = net_device_get_find_connection (client, net_device_get_nm_device (NET_DEVICE (self))); + if (connection == NULL) + return; + active = gtk_switch_get_active (self->device_off_switch); if (active) { - client = net_object_get_client (NET_OBJECT (self)); - connection = net_device_get_find_connection (NET_DEVICE (self)); - if (connection == NULL) - return; nm_client_activate_connection_async (client, connection, net_device_get_nm_device (NET_DEVICE (self)), @@ -140,11 +141,7 @@ device_off_toggled (NetDeviceBluetooth *self) } else { const gchar *uuid; - connection = net_device_get_find_connection (NET_DEVICE (self)); - if (connection == NULL) - return; uuid = nm_connection_get_uuid (connection); - client = net_object_get_client (NET_OBJECT (self)); acs = nm_client_get_active_connections (client); for (i = 0; acs && i < acs->len; i++) { a = (NMActiveConnection*)acs->pdata[i]; @@ -164,7 +161,7 @@ edit_connection (NetDeviceBluetooth *self) g_autoptr(GError) error = NULL; NMConnection *connection; - connection = net_device_get_find_connection (NET_DEVICE (self)); + connection = net_device_get_find_connection (net_object_get_client (NET_OBJECT (self)), net_device_get_nm_device (NET_DEVICE (self))); uuid = nm_connection_get_uuid (connection); cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid); g_debug ("Launching '%s'\n", cmdline); diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c index 6343d1235..fa4168129 100644 --- a/panels/network/net-device-ethernet.c +++ b/panels/network/net-device-ethernet.c @@ -370,7 +370,7 @@ populate_ui (NetDeviceEthernet *self) } g_list_free (children); - connections = net_device_get_valid_connections (NET_DEVICE (self)); + connections = net_device_get_valid_connections (net_object_get_client (NET_OBJECT (self)), net_device_get_nm_device (NET_DEVICE (self))); for (l = connections; l; l = l->next) { NMConnection *connection = l->data; if (!g_hash_table_contains (self->connections, connection)) { @@ -461,7 +461,7 @@ device_off_toggled (NetDeviceEthernet *self) nm_device = net_device_get_nm_device (NET_DEVICE (self)); if (gtk_switch_get_active (self->device_off_switch)) { - connection = net_device_get_find_connection (NET_DEVICE (self)); + connection = net_device_get_find_connection (client, nm_device); if (connection != NULL) { nm_client_activate_connection_async (client, connection, diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c index 461869297..a0c3a1ee3 100644 --- a/panels/network/net-device-mobile.c +++ b/panels/network/net-device-mobile.c @@ -210,7 +210,7 @@ device_add_device_connections (NetDeviceMobile *self, NMConnection *connection; /* get the list of available connections for this device */ - list = net_device_get_valid_connections (NET_DEVICE (self)); + list = net_device_get_valid_connections (net_object_get_client (NET_OBJECT (self)), nm_device); gtk_list_store_clear (liststore); active_connection = nm_device_get_active_connection (nm_device); for (l = list; l; l = g_slist_next (l)) { @@ -398,7 +398,7 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self) gtk_label_set_label (self->status_label, status); /* sensitive for other connection types if the device is currently connected */ - is_connected = net_device_get_find_connection (NET_DEVICE (self)) != NULL; + is_connected = net_device_get_find_connection (net_object_get_client (NET_OBJECT (self)), nm_device) != NULL; gtk_widget_set_sensitive (GTK_WIDGET (self->options_button), is_connected); caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (nm_device)); @@ -495,12 +495,13 @@ device_off_toggled (NetDeviceMobile *self) if (self->updating_device) return; + client = net_object_get_client (NET_OBJECT (self)); + connection = net_device_get_find_connection (client, net_device_get_nm_device (NET_DEVICE (self))); + if (connection == NULL) + return; + active = gtk_switch_get_active (self->device_off_switch); if (active) { - client = net_object_get_client (NET_OBJECT (self)); - connection = net_device_get_find_connection (NET_DEVICE (self)); - if (connection == NULL) - return; nm_client_activate_connection_async (client, connection, net_device_get_nm_device (NET_DEVICE (self)), @@ -508,11 +509,7 @@ device_off_toggled (NetDeviceMobile *self) } else { const gchar *uuid; - connection = net_device_get_find_connection (NET_DEVICE (self)); - if (connection == NULL) - return; uuid = nm_connection_get_uuid (connection); - client = net_object_get_client (NET_OBJECT (self)); acs = nm_client_get_active_connections (client); for (i = 0; acs && i < acs->len; i++) { a = (NMActiveConnection*)acs->pdata[i]; @@ -532,7 +529,7 @@ edit_connection (NetDeviceMobile *self) g_autoptr(GError) error = NULL; NMConnection *connection; - connection = net_device_get_find_connection (NET_DEVICE (self)); + connection = net_device_get_find_connection (net_object_get_client (NET_OBJECT (self)), net_device_get_nm_device (NET_DEVICE (self))); uuid = nm_connection_get_uuid (connection); cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid); g_debug ("Launching '%s'\n", cmdline); diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c index d235c3d84..fc34a8cf9 100644 --- a/panels/network/net-device-wifi.c +++ b/panels/network/net-device-wifi.c @@ -169,17 +169,7 @@ static NMConnection * find_connection_for_device (NetDeviceWifi *self, NMDevice *device) { - g_autoptr(NetDevice) tmp = NULL; - NMConnection *connection; - NMClient *client; - - client = net_object_get_client (NET_OBJECT (self)); - tmp = g_object_new (NET_TYPE_DEVICE, - "client", client, - "nm-device", device, - NULL); - connection = net_device_get_find_connection (tmp); - return connection; + return net_device_get_find_connection (net_object_get_client (NET_OBJECT (self)), device); } static gboolean @@ -726,7 +716,7 @@ net_device_wifi_get_hotspot_connection (NetDeviceWifi *self) GSList *connections, *l; NMConnection *c = NULL; - connections = net_device_get_valid_connections (NET_DEVICE (self)); + connections = net_device_get_valid_connections (net_object_get_client (NET_OBJECT (self)), net_device_get_nm_device (NET_DEVICE (self))); for (l = connections; l; l = l->next) { NMConnection *tmp = l->data; if (is_hotspot_connection (tmp)) { diff --git a/panels/network/net-device.c b/panels/network/net-device.c index 60d937a99..98e2cd076 100644 --- a/panels/network/net-device.c +++ b/panels/network/net-device.c @@ -117,20 +117,19 @@ compare_mac_device_with_mac_connection (NMDevice *device, } NMConnection * -net_device_get_find_connection (NetDevice *self) +net_device_get_find_connection (NMClient *client, NMDevice *device) { - NetDevicePrivate *priv = net_device_get_instance_private (self); GSList *list, *iterator; NMConnection *connection = NULL; NMActiveConnection *ac; /* is the device available in a active connection? */ - ac = nm_device_get_active_connection (priv->nm_device); + ac = nm_device_get_active_connection (device); if (ac) return (NMConnection*) nm_active_connection_get_connection (ac); /* not found in active connections - check all available connections */ - list = net_device_get_valid_connections (self); + list = net_device_get_valid_connections (client, device); if (list != NULL) { /* if list has only one connection, use this connection */ if (g_slist_length (list) == 1) { @@ -141,7 +140,7 @@ net_device_get_find_connection (NetDevice *self) /* is there connection with the MAC address of the device? */ for (iterator = list; iterator; iterator = iterator->next) { connection = iterator->data; - if (compare_mac_device_with_mac_connection (priv->nm_device, + if (compare_mac_device_with_mac_connection (device, connection)) { goto out; } @@ -265,7 +264,7 @@ net_device_init (NetDevice *self) } GSList * -net_device_get_valid_connections (NetDevice *self) +net_device_get_valid_connections (NMClient *client, NMDevice *device) { GSList *valid; NMConnection *connection; @@ -276,10 +275,10 @@ net_device_get_valid_connections (NetDevice *self) GPtrArray *filtered; guint i; - all = nm_client_get_connections (net_object_get_client (NET_OBJECT (self))); - filtered = nm_device_filter_connections (net_device_get_nm_device (self), all); + all = nm_client_get_connections (client); + filtered = nm_device_filter_connections (device, all); - active_connection = nm_device_get_active_connection (net_device_get_nm_device (self)); + active_connection = nm_device_get_active_connection (device); active_uuid = active_connection ? nm_active_connection_get_uuid (active_connection) : NULL; valid = NULL; diff --git a/panels/network/net-device.h b/panels/network/net-device.h index f3f1b8bbe..6760cbdbe 100644 --- a/panels/network/net-device.h +++ b/panels/network/net-device.h @@ -37,9 +37,12 @@ struct _NetDeviceClass NetObjectClass parent_class; }; -NMDevice *net_device_get_nm_device (NetDevice *device); -NMConnection *net_device_get_find_connection (NetDevice *device); +NMDevice *net_device_get_nm_device (NetDevice *device); -GSList *net_device_get_valid_connections (NetDevice *device); +NMConnection *net_device_get_find_connection (NMClient *client, + NMDevice *device); + +GSList *net_device_get_valid_connections (NMClient *client, + NMDevice *device); G_END_DECLS