[gnome-control-center] network: Remove net_device_get_nm_device



commit 1c92cf4844662b73b939a2c80b37832e73e9f6d3
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Oct 24 13:04:14 2019 +1300

    network: Remove net_device_get_nm_device

 panels/network/cc-network-panel.c     | 85 +++++++++++++++++++-------------
 panels/network/cc-wifi-panel.c        |  8 +--
 panels/network/net-device-bluetooth.c | 25 ++++++----
 panels/network/net-device-bluetooth.h |  4 +-
 panels/network/net-device-ethernet.c  | 57 ++++++++++------------
 panels/network/net-device-ethernet.h  |  6 ++-
 panels/network/net-device-mobile.c    | 55 +++++++++------------
 panels/network/net-device-mobile.h    |  8 +--
 panels/network/net-device-wifi.c      | 92 +++++++++++++----------------------
 panels/network/net-device-wifi.h      |  6 ++-
 panels/network/net-device.c           | 84 +-------------------------------
 panels/network/net-device.h           |  2 -
 12 files changed, 168 insertions(+), 264 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 15b088f85..aaafea5d8 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -56,10 +56,13 @@ struct _CcNetworkPanel
 {
         CcPanel           parent;
 
+        GPtrArray        *bluetooth_devices;
+        GPtrArray        *ethernet_devices;
+        GPtrArray        *mobile_devices;
+        GPtrArray        *vpns;
         GHashTable       *device_to_widget;
-        GPtrArray        *devices;
         GHashTable       *nm_device_to_device;
-        GPtrArray        *vpns;
+
         NMClient         *client;
         MMManager        *modem_manager;
         GtkSizeGroup     *sizegroup;
@@ -206,10 +209,12 @@ cc_network_panel_dispose (GObject *object)
         g_clear_object (&self->client);
         g_clear_object (&self->modem_manager);
 
+        g_clear_pointer (&self->bluetooth_devices, g_ptr_array_unref);
+        g_clear_pointer (&self->ethernet_devices, g_ptr_array_unref);
+        g_clear_pointer (&self->mobile_devices, g_ptr_array_unref);
+        g_clear_pointer (&self->vpns, g_ptr_array_unref);
         g_clear_pointer (&self->device_to_widget, g_hash_table_destroy);
-        g_clear_pointer (&self->devices, g_ptr_array_unref);
         g_clear_pointer (&self->nm_device_to_device, g_hash_table_destroy);
-        g_clear_pointer (&self->vpns, g_ptr_array_unref);
 
         G_OBJECT_CLASS (cc_network_panel_parent_class)->dispose (object);
 }
@@ -253,15 +258,20 @@ panel_refresh_device_titles (CcNetworkPanel *self)
 
         ndarray = g_ptr_array_new ();
         nmdarray = g_ptr_array_new ();
-        for (i = 0; i < self->devices->len; i++) {
-                NetDevice *device = g_ptr_array_index (self->devices, i);
-                NMDevice *nm_device;
-
-                nm_device = net_device_get_nm_device (device);
-                if (nm_device != NULL) {
-                        g_ptr_array_add (ndarray, device);
-                        g_ptr_array_add (nmdarray, nm_device);
-                }
+        for (i = 0; i < self->bluetooth_devices->len; i++) {
+                NetDeviceBluetooth *device = g_ptr_array_index (self->bluetooth_devices, i);
+                g_ptr_array_add (ndarray, device);
+                g_ptr_array_add (nmdarray, net_device_bluetooth_get_device (device));
+        }
+        for (i = 0; i < self->ethernet_devices->len; i++) {
+                NetDeviceEthernet *device = g_ptr_array_index (self->ethernet_devices, i);
+                g_ptr_array_add (ndarray, device);
+                g_ptr_array_add (nmdarray, net_device_ethernet_get_device (device));
+        }
+        for (i = 0; i < self->mobile_devices->len; i++) {
+                NetDeviceMobile *device = g_ptr_array_index (self->mobile_devices, i);
+                g_ptr_array_add (ndarray, device);
+                g_ptr_array_add (nmdarray, net_device_mobile_get_device (device));
         }
 
         if (ndarray->len == 0)
@@ -336,18 +346,23 @@ handle_argv (CcNetworkPanel *self)
         if (self->arg_operation == OPERATION_NULL)
                 return;
 
-        for (i = 0; i < self->devices->len; i++) {
-                NetDevice *net_device = g_ptr_array_index (self->devices, i);
-                NMDevice *device;
-
-                device = net_device_get_nm_device (net_device);
-                if (handle_argv_for_device (self, device))
+        for (i = 0; i < self->bluetooth_devices->len; i++) {
+                NetDeviceBluetooth *device = g_ptr_array_index (self->bluetooth_devices, i);
+                if (handle_argv_for_device (self, net_device_bluetooth_get_device (device)))
+                        return;
+        }
+        for (i = 0; i < self->ethernet_devices->len; i++) {
+                NetDeviceEthernet *device = g_ptr_array_index (self->ethernet_devices, i);
+                if (handle_argv_for_device (self, net_device_ethernet_get_device (device)))
+                        return;
+        }
+        for (i = 0; i < self->mobile_devices->len; i++) {
+                NetDeviceMobile *device = g_ptr_array_index (self->mobile_devices, i);
+                if (handle_argv_for_device (self, net_device_mobile_get_device (device)))
                         return;
         }
-
         for (i = 0; i < self->vpns->len; i++) {
                 NetVpn *vpn = g_ptr_array_index (self->vpns, i);
-
                 if (handle_argv_for_connection (self, net_vpn_get_connection (vpn)))
                         return;
         }
@@ -377,19 +392,14 @@ update_vpn_section (CcNetworkPanel *self)
 static void
 update_bluetooth_section (CcNetworkPanel *self)
 {
-        guint i, n_bluetooth;
-
-        for (i = 0, n_bluetooth = 0; i < self->devices->len; i++) {
-                NetObject *net_object = g_ptr_array_index (self->devices, i);
-
-                if (!NET_IS_DEVICE_BLUETOOTH (net_object))
-                        continue;
+        guint i;
 
-                net_device_bluetooth_set_show_separator (NET_DEVICE_BLUETOOTH (net_object), n_bluetooth > 0);
-                n_bluetooth++;
+        for (i = 0; i < self->bluetooth_devices->len; i++) {
+                NetDeviceBluetooth *device = g_ptr_array_index (self->bluetooth_devices, i);
+                net_device_bluetooth_set_show_separator (device, i > 0);
         }
 
-        gtk_widget_set_visible (self->container_bluetooth, n_bluetooth > 0);
+        gtk_widget_set_visible (self->container_bluetooth, self->bluetooth_devices->len > 0);
 }
 
 static void
@@ -428,6 +438,7 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
         case NM_DEVICE_TYPE_INFINIBAND:
                 net_device = NET_DEVICE (net_device_ethernet_new (self->client, device));
                 add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_wired));
+                g_ptr_array_add (self->ethernet_devices, net_device);
                 break;
         case NM_DEVICE_TYPE_MODEM:
                 if (g_str_has_prefix (nm_device_get_udi (device), "/org/freedesktop/ModemManager1/Modem/")) {
@@ -448,10 +459,12 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
 
                 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));
+                g_ptr_array_add (self->mobile_devices, net_device);
                 break;
         case NM_DEVICE_TYPE_BT:
                 net_device = NET_DEVICE (net_device_bluetooth_new (self->client, device));
                 add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_bluetooth));
+                g_ptr_array_add (self->bluetooth_devices, net_device);
                 break;
 
         /* For Wi-Fi and VPN we handle connections separately; we correctly manage
@@ -464,8 +477,6 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
                 return;
         }
 
-        /* Add to the devices array */
-        g_ptr_array_add (self->devices, net_device);
         g_hash_table_insert (self->nm_device_to_device, device, net_device);
 
         /* Update the device_bluetooth section if we're adding a bluetooth
@@ -489,7 +500,9 @@ panel_remove_device (CcNetworkPanel *self, NMDevice *device)
 
         /* NMObject will not fire the "removed" signal, so handle the UI removal explicitly */
         object_removed_cb (self, NET_OBJECT (net_device));
-        g_ptr_array_remove (self->devices, net_device);
+        g_ptr_array_remove (self->bluetooth_devices, net_device);
+        g_ptr_array_remove (self->ethernet_devices, net_device);
+        g_ptr_array_remove (self->mobile_devices, net_device);
         g_hash_table_remove (self->nm_device_to_device, device);
 
         /* update vpn widgets */
@@ -756,7 +769,9 @@ cc_network_panel_init (CcNetworkPanel *self)
 
         gtk_widget_init_template (GTK_WIDGET (self));
 
-        self->devices = g_ptr_array_new_with_free_func (g_object_unref);
+        self->bluetooth_devices = g_ptr_array_new_with_free_func (g_object_unref);
+        self->ethernet_devices = g_ptr_array_new_with_free_func (g_object_unref);
+        self->mobile_devices = g_ptr_array_new_with_free_func (g_object_unref);
         self->vpns = g_ptr_array_new_with_free_func (g_object_unref);
         self->device_to_widget = g_hash_table_new (g_direct_hash, g_direct_equal);
         self->nm_device_to_device = g_hash_table_new (g_direct_hash, g_direct_equal);
diff --git a/panels/network/cc-wifi-panel.c b/panels/network/cc-wifi-panel.c
index 6434783b6..542ececc0 100644
--- a/panels/network/cc-wifi-panel.c
+++ b/panels/network/cc-wifi-panel.c
@@ -290,7 +290,7 @@ update_devices_names (CcWifiPanel *self)
           NMDevice *device;
 
           net_device = g_ptr_array_index (self->devices, i);
-          device = net_device_get_nm_device (NET_DEVICE (net_device));
+          device = net_device_wifi_get_device (net_device);
 
           net_object_set_title (NET_OBJECT (net_device), nm_device_get_description (device));
         }
@@ -328,7 +328,7 @@ handle_argv_for_device (CcWifiPanel *self, NetDeviceWifi *net_device)
   gboolean ret;
 
   toplevel = cc_shell_get_toplevel (cc_panel_get_shell (CC_PANEL (self)));
-  device = net_device_get_nm_device (NET_DEVICE (net_device));
+  device = net_device_wifi_get_device (net_device);
   ret = FALSE;
 
   if (self->arg_operation == OPERATION_CREATE_WIFI)
@@ -451,7 +451,7 @@ device_removed_cb (CcWifiPanel *self, NMDevice *device)
     {
       NetDeviceWifi *net_device = g_ptr_array_index (self->devices, i);
 
-      if (net_device_get_nm_device (NET_DEVICE (net_device)) == device)
+      if (net_device_wifi_get_device (net_device) == device)
         {
           g_ptr_array_remove (self->devices, net_device);
           break;
@@ -548,7 +548,7 @@ on_stack_visible_child_changed_cb (GtkStack    *stack,
     {
       NetDeviceWifi *net_device = g_ptr_array_index (self->devices, i);
 
-      if (g_strcmp0 (nm_device_get_udi (net_device_get_nm_device (NET_DEVICE (net_device))), 
visible_device_id) == 0)
+      if (g_strcmp0 (nm_device_get_udi (net_device_wifi_get_device (net_device)), visible_device_id) == 0)
         {
           self->spinner_binding = g_object_bind_property (net_device,
                                                           "scanning",
diff --git a/panels/network/net-device-bluetooth.c b/panels/network/net-device-bluetooth.c
index 1888bd988..034f40bdd 100644
--- a/panels/network/net-device-bluetooth.c
+++ b/panels/network/net-device-bluetooth.c
@@ -43,6 +43,7 @@ struct _NetDeviceBluetooth
         GtkSeparator *separator;
 
         NMClient     *client;
+        NMDevice     *device;
         gboolean      updating_device;
 };
 
@@ -89,16 +90,13 @@ update_off_switch_from_device_state (GtkSwitch *sw,
 static void
 nm_device_bluetooth_refresh_ui (NetDeviceBluetooth *self)
 {
-        NMDevice *nm_device;
         NMDeviceState state;
 
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-
         /* set device kind */
         g_object_bind_property (self, "title", self->device_label, "label", 0);
 
         /* set up the device on/off switch */
-        state = nm_device_get_state (nm_device);
+        state = nm_device_get_state (self->device);
         gtk_widget_set_visible (GTK_WIDGET (self->device_off_switch),
                                 state != NM_DEVICE_STATE_UNAVAILABLE
                                 && state != NM_DEVICE_STATE_UNMANAGED);
@@ -127,7 +125,7 @@ device_off_toggled (NetDeviceBluetooth *self)
         if (self->updating_device)
                 return;
 
-        connection = net_device_get_find_connection (self->client, net_device_get_nm_device (NET_DEVICE 
(self)));
+        connection = net_device_get_find_connection (self->client, self->device);
         if (connection == NULL)
                 return;
 
@@ -135,7 +133,7 @@ device_off_toggled (NetDeviceBluetooth *self)
         if (active) {
                 nm_client_activate_connection_async (self->client,
                                                      connection,
-                                                     net_device_get_nm_device (NET_DEVICE (self)),
+                                                     self->device,
                                                      NULL, NULL, NULL, NULL);
         } else {
                 const gchar *uuid;
@@ -160,7 +158,7 @@ edit_connection (NetDeviceBluetooth *self)
         g_autoptr(GError) error = NULL;
         NMConnection *connection;
 
-        connection = net_device_get_find_connection (self->client, net_device_get_nm_device (NET_DEVICE 
(self)));
+        connection = net_device_get_find_connection (self->client, self->device);
         uuid = nm_connection_get_uuid (connection);
         cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
         g_debug ("Launching '%s'\n", cmdline);
@@ -175,6 +173,7 @@ net_device_bluetooth_finalize (GObject *object)
 
         g_clear_object (&self->builder);
         g_clear_object (&self->client);
+        g_clear_object (&self->device);
 
         G_OBJECT_CLASS (net_device_bluetooth_parent_class)->finalize (object);
 }
@@ -222,10 +221,9 @@ net_device_bluetooth_new (NMClient *client, NMDevice *device)
 {
         NetDeviceBluetooth *self;
 
-        self = g_object_new (NET_TYPE_DEVICE_BLUETOOTH,
-                             "nm-device", device,
-                             NULL);
+        self = g_object_new (NET_TYPE_DEVICE_BLUETOOTH, NULL);
         self->client = g_object_ref (client);
+        self->device = g_object_ref (device);
 
         g_signal_connect_object (device, "state-changed", G_CALLBACK (device_state_changed_cb), self, 
G_CONNECT_SWAPPED);
 
@@ -233,3 +231,10 @@ net_device_bluetooth_new (NMClient *client, NMDevice *device)
 
         return self;
 }
+
+NMDevice *
+net_device_bluetooth_get_device (NetDeviceBluetooth *self)
+{
+        g_return_val_if_fail (NET_IS_DEVICE_BLUETOOTH (self), NULL);
+        return self->device;
+}
diff --git a/panels/network/net-device-bluetooth.h b/panels/network/net-device-bluetooth.h
index 89eefe00e..a6c5d5910 100644
--- a/panels/network/net-device-bluetooth.h
+++ b/panels/network/net-device-bluetooth.h
@@ -34,7 +34,9 @@ G_DECLARE_FINAL_TYPE (NetDeviceBluetooth, net_device_bluetooth, NET, DEVICE_BLUE
 NetDeviceBluetooth *net_device_bluetooth_new                (NMClient           *client,
                                                              NMDevice           *device);
 
-void                net_device_bluetooth_set_show_separator (NetDeviceBluetooth *device_bluetooth,
+NMDevice           *net_device_bluetooth_get_device         (NetDeviceBluetooth *device);
+
+void                net_device_bluetooth_set_show_separator (NetDeviceBluetooth *device,
                                                              gboolean            show_separator);
 
 G_END_DECLS
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index e00983337..38a68af87 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -50,6 +50,7 @@ struct _NetDeviceEthernet
         GtkScrolledWindow *scrolled_window;
 
         NMClient          *client;
+        NMDevice          *device;
         GtkListBox        *list;
         gboolean           updating_device;
         GHashTable        *connections;
@@ -194,16 +195,13 @@ device_state_to_off_switch (NMDeviceState state)
 static void
 device_ethernet_refresh_ui (NetDeviceEthernet *self)
 {
-        NMDevice *nm_device;
         NMDeviceState state;
         g_autofree gchar *speed_text = NULL;
         g_autofree gchar *status = NULL;
 
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-
         gtk_label_set_label (self->device_label, net_object_get_title (NET_OBJECT (self)));
 
-        state = nm_device_get_state (nm_device);
+        state = nm_device_get_state (self->device);
         gtk_widget_set_sensitive (GTK_WIDGET (self->device_off_switch),
                                   state != NM_DEVICE_STATE_UNAVAILABLE
                                   && state != NM_DEVICE_STATE_UNMANAGED);
@@ -212,13 +210,13 @@ device_ethernet_refresh_ui (NetDeviceEthernet *self)
         self->updating_device = FALSE;
 
         if (state != NM_DEVICE_STATE_UNAVAILABLE) {
-                guint speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (nm_device));
+                guint speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (self->device));
                 if (speed > 0) {
                         /* Translators: network device speed */
                         speed_text = g_strdup_printf (_("%d Mb/s"), speed);
                 }
         }
-        status = panel_device_status_to_localized_string (nm_device, speed_text);
+        status = panel_device_status_to_localized_string (self->device, speed_text);
         hdy_action_row_set_title (self->details_row, status);
 
         populate_ui (self);
@@ -237,15 +235,13 @@ show_details (NetDeviceEthernet *self, GtkButton *button, const gchar *title)
         NMConnection *connection;
         GtkWidget *window;
         NetConnectionEditor *editor;
-        NMDevice *nmdev;
 
         window = gtk_widget_get_toplevel (GTK_WIDGET (self->box));
 
         row = g_object_get_data (G_OBJECT (button), "row");
         connection = NM_CONNECTION (g_object_get_data (G_OBJECT (row), "connection"));
 
-        nmdev = net_device_get_nm_device (NET_DEVICE (self));
-        editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, self->client);
+        editor = net_connection_editor_new (GTK_WINDOW (window), connection, self->device, NULL, 
self->client);
         if (title)
                 net_connection_editor_set_title (editor, title);
         g_signal_connect_swapped (editor, "done", G_CALLBACK (editor_done), self);
@@ -276,15 +272,13 @@ add_row (NetDeviceEthernet *self, NMConnection *connection)
         GtkWidget *widget;
         GtkWidget *box;
         GtkWidget *details;
-        NMDevice *nmdev;
         NMActiveConnection *aconn;
         gboolean active;
         GtkWidget *image;
 
         active = FALSE;
 
-        nmdev = net_device_get_nm_device (NET_DEVICE (self));
-        aconn = nm_device_get_active_connection (nmdev);
+        aconn = nm_device_get_active_connection (self->device);
         if (aconn) {
                 const gchar *uuid1, *uuid2;
                 uuid1 = nm_active_connection_get_uuid (aconn);
@@ -314,7 +308,7 @@ add_row (NetDeviceEthernet *self, NMConnection *connection)
 
                 gtk_box_pack_start (GTK_BOX (row), details, FALSE, TRUE, 0);
 
-                add_details (details, nmdev, connection);
+                add_details (details, self->device, connection);
         }
 
         /* filler */
@@ -368,7 +362,7 @@ populate_ui (NetDeviceEthernet *self)
         }
         g_list_free (children);
 
-        connections = net_device_get_valid_connections (self->client, net_device_get_nm_device (NET_DEVICE 
(self)));
+        connections = net_device_get_valid_connections (self->client, self->device);
         for (l = connections; l; l = l->next) {
                 NMConnection *connection = l->data;
                 if (!g_hash_table_contains (self->connections, connection)) {
@@ -421,7 +415,6 @@ add_profile (NetDeviceEthernet *self)
         g_autofree gchar *id = NULL;
         NetConnectionEditor *editor;
         GtkWidget *window;
-        NMDevice *nmdev;
         const GPtrArray *connections;
 
         connection = nm_simple_connection_new ();
@@ -444,8 +437,7 @@ add_profile (NetDeviceEthernet *self)
 
         window = gtk_widget_get_toplevel (GTK_WIDGET (self->box));
 
-        nmdev = net_device_get_nm_device (NET_DEVICE (self));
-        editor = net_connection_editor_new (GTK_WINDOW (window), connection, nmdev, NULL, self->client);
+        editor = net_connection_editor_new (GTK_WINDOW (window), connection, self->device, NULL, 
self->client);
         g_signal_connect_swapped (editor, "done", G_CALLBACK (editor_done), self);
         net_connection_editor_run (editor);
 }
@@ -453,24 +445,21 @@ add_profile (NetDeviceEthernet *self)
 static void
 device_off_toggled (NetDeviceEthernet *self)
 {
-        NMDevice *nm_device;
         NMConnection *connection;
 
         if (self->updating_device)
                 return;
 
-        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 (self->client, nm_device);
+                connection = net_device_get_find_connection (self->client, self->device);
                 if (connection != NULL) {
                         nm_client_activate_connection_async (self->client,
                                                              connection,
-                                                             nm_device,
+                                                             self->device,
                                                              NULL, NULL, NULL, NULL);
                 }
         } else {
-                nm_device_disconnect (nm_device, NULL, NULL);
+                nm_device_disconnect (self->device, NULL, NULL);
         }
 }
 
@@ -483,20 +472,17 @@ device_title_changed (NetDeviceEthernet *self)
 static void
 connection_activated (NetDeviceEthernet *self, GtkListBoxRow *row)
 {
-        NMDevice *nm_device;
         NMConnection *connection;
 
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-
-        if (!NM_IS_DEVICE_ETHERNET (nm_device) ||
-            !nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (nm_device)))
+        if (!NM_IS_DEVICE_ETHERNET (self->device) ||
+            !nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (self->device)))
                 return;
 
         connection = NM_CONNECTION (g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (row))), 
"connection"));
 
         nm_client_activate_connection_async (self->client,
                                              connection,
-                                             nm_device,
+                                             self->device,
                                              NULL, NULL, NULL, NULL);
 }
 
@@ -507,6 +493,7 @@ device_ethernet_finalize (GObject *object)
 
         g_clear_object (&self->builder);
         g_clear_object (&self->client);
+        g_clear_object (&self->device);
         g_hash_table_destroy (self->connections);
 
         G_OBJECT_CLASS (net_device_ethernet_parent_class)->finalize (object);
@@ -570,10 +557,9 @@ net_device_ethernet_new (NMClient *client, NMDevice *device)
 {
         NetDeviceEthernet *self;
 
-        self = g_object_new (NET_TYPE_DEVICE_ETHERNET,
-                             "nm-device", device,
-                             NULL);
+        self = g_object_new (NET_TYPE_DEVICE_ETHERNET, NULL);
         self->client = g_object_ref (client);
+        self->device = g_object_ref (device);
 
         g_signal_connect_object (client, NM_CLIENT_CONNECTION_ADDED,
                                  G_CALLBACK (client_connection_added_cb), self, G_CONNECT_SWAPPED);
@@ -587,3 +573,10 @@ net_device_ethernet_new (NMClient *client, NMDevice *device)
 
         return self;
 }
+
+NMDevice *
+net_device_ethernet_get_device (NetDeviceEthernet *self)
+{
+        g_return_val_if_fail (NET_IS_DEVICE_ETHERNET (self), NULL);
+        return self->device;
+}
diff --git a/panels/network/net-device-ethernet.h b/panels/network/net-device-ethernet.h
index 3bf152512..929756ed0 100644
--- a/panels/network/net-device-ethernet.h
+++ b/panels/network/net-device-ethernet.h
@@ -30,7 +30,9 @@ G_BEGIN_DECLS
 #define NET_TYPE_DEVICE_ETHERNET          (net_device_ethernet_get_type ())
 G_DECLARE_FINAL_TYPE (NetDeviceEthernet, net_device_ethernet, NET, DEVICE_ETHERNET, NetDevice)
 
-NetDeviceEthernet *net_device_ethernet_new (NMClient *client,
-                                            NMDevice *device);
+NetDeviceEthernet *net_device_ethernet_new        (NMClient *client,
+                                                   NMDevice *device);
+
+NMDevice          *net_device_ethernet_get_device (NetDeviceEthernet *device);
 
 G_END_DECLS
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index 6a5bbc785..8e412bb46 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;
+        NMDevice     *device;
         GDBusObject  *modem;
         GCancellable *cancellable;
 
@@ -120,7 +121,6 @@ mobile_connection_changed_cb (NetDeviceMobile *self)
         GtkTreeIter iter;
         GtkTreeModel *model;
         NMConnection *connection;
-        NMDevice *device;
         GtkWidget *toplevel;
 
         if (self->updating_device)
@@ -130,10 +130,6 @@ mobile_connection_changed_cb (NetDeviceMobile *self)
         if (!ret)
                 return;
 
-        device = net_device_get_nm_device (NET_DEVICE (self));
-        if (device == NULL)
-                return;
-
         /* get entry */
         model = gtk_combo_box_get_model (self->network_combo);
         gtk_tree_model_get (model, &iter,
@@ -141,9 +137,7 @@ mobile_connection_changed_cb (NetDeviceMobile *self)
                             -1);
         if (g_strcmp0 (object_path, NULL) == 0) {
                 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->box));
-                cc_network_panel_connect_to_3g_network (toplevel,
-                                                        self->client,
-                                                        device);
+                cc_network_panel_connect_to_3g_network (toplevel, self->client, self->device);
                 return;
         }
 
@@ -151,10 +145,10 @@ mobile_connection_changed_cb (NetDeviceMobile *self)
         g_debug ("try to switch to connection %s", object_path);
         connection = (NMConnection*) nm_client_get_connection_by_path (self->client, object_path);
         if (connection != NULL) {
-                nm_device_disconnect (device, NULL, NULL);
+                nm_device_disconnect (self->device, NULL, NULL);
                 nm_client_activate_connection_async (self->client,
                                                      connection,
-                                                     device, NULL, NULL,
+                                                     self->device, NULL, NULL,
                                                      connection_activate_cb,
                                                      self);
                 return;
@@ -165,16 +159,11 @@ static void
 mobilebb_enabled_toggled (NetDeviceMobile *self)
 {
         gboolean enabled = FALSE;
-        NMDevice *device;
-
-        device = net_device_get_nm_device (NET_DEVICE (self));
-        if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_MODEM)
-                return;
 
         if (nm_client_wwan_get_enabled (self->client)) {
                 NMDeviceState state;
 
-                state = nm_device_get_state (device);
+                state = nm_device_get_state (self->device);
                 if (state == NM_DEVICE_STATE_UNKNOWN ||
                     state == NM_DEVICE_STATE_UNMANAGED ||
                     state == NM_DEVICE_STATE_UNAVAILABLE ||
@@ -373,13 +362,10 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
 {
         gboolean is_connected;
         NMDeviceModemCapabilities caps;
-        NMDevice *nm_device;
         g_autofree gchar *status = NULL;
         NMIPConfig *ipv4_config = NULL, *ipv6_config = NULL;
         gboolean have_ipv4_address = FALSE, have_ipv6_address = FALSE;
 
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-
         /* set device kind */
         g_object_bind_property (self, "title", self->device_label, "label", 0);
 
@@ -388,14 +374,14 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
         mobilebb_enabled_toggled (self);
 
         /* set device state, with status */
-        status = panel_device_status_to_localized_string (nm_device, NULL);
+        status = panel_device_status_to_localized_string (self->device, NULL);
         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 (self->client, nm_device) != NULL;
+        is_connected = net_device_get_find_connection (self->client, self->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));
+        caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (self->device));
         if ((caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) ||
             (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) ||
             (caps & NM_DEVICE_MODEM_CAPABILITY_LTE)) {
@@ -405,11 +391,11 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
 
         /* add possible connections to device */
         device_add_device_connections (self,
-                                       nm_device,
+                                       self->device,
                                        self->mobile_connections_list_store,
                                        self->network_combo);
 
-        ipv4_config = nm_device_get_ip4_config (nm_device);
+        ipv4_config = nm_device_get_ip4_config (self->device);
         if (ipv4_config != NULL) {
                 GPtrArray *addresses;
                 const gchar *ipv4_text = NULL;
@@ -442,7 +428,7 @@ nm_device_mobile_refresh_ui (NetDeviceMobile *self)
                 gtk_widget_hide (GTK_WIDGET (self->route_label));
         }
 
-        ipv6_config = nm_device_get_ip6_config (nm_device);
+        ipv6_config = nm_device_get_ip6_config (self->device);
         if (ipv6_config != NULL) {
                 GPtrArray *addresses;
                 const gchar *ipv6_text = NULL;
@@ -488,7 +474,7 @@ device_off_toggled (NetDeviceMobile *self)
         if (self->updating_device)
                 return;
 
-        connection = net_device_get_find_connection (self->client, net_device_get_nm_device (NET_DEVICE 
(self)));
+        connection = net_device_get_find_connection (self->client, self->device);
         if (connection == NULL)
                 return;
 
@@ -496,7 +482,7 @@ device_off_toggled (NetDeviceMobile *self)
         if (active) {
                 nm_client_activate_connection_async (self->client,
                                                      connection,
-                                                     net_device_get_nm_device (NET_DEVICE (self)),
+                                                     self->device,
                                                      NULL, NULL, NULL, NULL);
         } else {
                 const gchar *uuid;
@@ -521,7 +507,7 @@ edit_connection (NetDeviceMobile *self)
         g_autoptr(GError) error = NULL;
         NMConnection *connection;
 
-        connection = net_device_get_find_connection (self->client, net_device_get_nm_device (NET_DEVICE 
(self)));
+        connection = net_device_get_find_connection (self->client, self->device);
         uuid = nm_connection_get_uuid (connection);
         cmdline = g_strdup_printf ("nm-connection-editor --edit %s", uuid);
         g_debug ("Launching '%s'\n", cmdline);
@@ -755,6 +741,7 @@ net_device_mobile_dispose (GObject *object)
 
         g_clear_object (&self->builder);
         g_clear_object (&self->client);
+        g_clear_object (&self->device);
         g_clear_object (&self->modem);
         g_clear_object (&self->cancellable);
         g_clear_object (&self->gsm_proxy);
@@ -845,10 +832,9 @@ net_device_mobile_new (NMClient *client, NMDevice *device, GDBusObject *modem)
         NetDeviceMobile *self;
         NMDeviceModemCapabilities caps;
 
-        self = g_object_new (NET_TYPE_DEVICE_MOBILE,
-                             "nm-device", device,
-                             NULL);
+        self = g_object_new (NET_TYPE_DEVICE_MOBILE, NULL);
         self->client = g_object_ref (client);
+        self->device = g_object_ref (device);
 
         g_signal_connect_object (device, "state-changed", G_CALLBACK (device_state_changed_cb), self, 
G_CONNECT_SWAPPED);
 
@@ -922,3 +908,10 @@ net_device_mobile_new (NMClient *client, NMDevice *device, GDBusObject *modem)
 
         return self;
 }
+
+NMDevice *
+net_device_mobile_get_device (NetDeviceMobile *self)
+{
+        g_return_val_if_fail (NET_IS_DEVICE_MOBILE (self), NULL);
+        return self->device;
+}
diff --git a/panels/network/net-device-mobile.h b/panels/network/net-device-mobile.h
index 94d6f9c2c..7873a4c67 100644
--- a/panels/network/net-device-mobile.h
+++ b/panels/network/net-device-mobile.h
@@ -31,8 +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 (NMClient    *client,
-                                        NMDevice    *device,
-                                        GDBusObject *modem);
+NetDeviceMobile *net_device_mobile_new          (NMClient    *client,
+                                                 NMDevice    *device,
+                                                 GDBusObject *modem);
+
+NMDevice          *net_device_mobile_get_device (NetDeviceMobile *device);
 
 G_END_DECLS
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 8f253259e..ab9f6e95a 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -79,6 +79,7 @@ struct _NetDeviceWifi
 
         CcPanel                 *panel;
         NMClient                *client;
+        NMDevice                *device;
         gboolean                 updating_device;
         gchar                   *selected_ssid_title;
         gchar                   *selected_connection_id;
@@ -128,11 +129,6 @@ static void
 wireless_enabled_toggled (NetDeviceWifi *self)
 {
         gboolean enabled;
-        NMDevice *device;
-
-        device = net_device_get_nm_device (NET_DEVICE (self));
-        if (nm_device_get_device_type (device) != NM_DEVICE_TYPE_WIFI)
-                return;
 
         enabled = nm_client_wireless_get_enabled (self->client);
 
@@ -168,13 +164,11 @@ static gboolean
 device_is_hotspot (NetDeviceWifi *self)
 {
         NMConnection *c;
-        NMDevice *device;
 
-        device = net_device_get_nm_device (NET_DEVICE (self));
-        if (nm_device_get_active_connection (device) == NULL)
+        if (nm_device_get_active_connection (self->device) == NULL)
                 return FALSE;
 
-        c = find_connection_for_device (self, device);
+        c = find_connection_for_device (self, self->device);
         if (c == NULL)
                 return FALSE;
 
@@ -285,15 +279,13 @@ nm_device_wifi_refresh_hotspot (NetDeviceWifi *self)
         g_autofree gchar *hotspot_secret = NULL;
         g_autofree gchar *hotspot_security = NULL;
         g_autofree gchar *hotspot_ssid = NULL;
-        NMDevice *nm_device;
 
         /* refresh hotspot ui */
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-        ssid = device_get_hotspot_ssid (self, nm_device);
+        ssid = device_get_hotspot_ssid (self, self->device);
         if (ssid)
                 hotspot_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size 
(ssid));
         device_get_hotspot_security_details (self,
-                                             nm_device,
+                                             self->device,
                                              &hotspot_secret,
                                              &hotspot_security);
 
@@ -331,11 +323,9 @@ static gboolean
 update_scanning (gpointer user_data)
 {
         NetDeviceWifi *self = user_data;
-        NMDevice *nm_device;
         gint64 last_scan;
 
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-        last_scan = nm_device_wifi_get_last_scan (NM_DEVICE_WIFI (nm_device));
+        last_scan = nm_device_wifi_get_last_scan (NM_DEVICE_WIFI (self->device));
 
         /* The last_scan property is updated after the device finished scanning,
          * so notify about it and stop monitoring for changes.
@@ -353,21 +343,18 @@ static gboolean
 request_scan (gpointer user_data)
 {
         NetDeviceWifi *self = user_data;
-        NMDevice *nm_device;
 
         g_debug ("Periodic Wi-Fi scan requested");
 
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-
         set_scanning (self, TRUE,
-                      nm_device_wifi_get_last_scan (NM_DEVICE_WIFI (nm_device)));
+                      nm_device_wifi_get_last_scan (NM_DEVICE_WIFI (self->device)));
 
         if (self->monitor_scanning_id == 0) {
                 self->monitor_scanning_id = g_timeout_add (1500, update_scanning,
                                                                   self);
         }
 
-        nm_device_wifi_request_scan_async (NM_DEVICE_WIFI (nm_device),
+        nm_device_wifi_request_scan_async (NM_DEVICE_WIFI (self->device),
                                            self->cancellable, NULL, NULL);
 
         return G_SOURCE_CONTINUE;
@@ -376,7 +363,6 @@ request_scan (gpointer user_data)
 static void
 nm_device_wifi_refresh_ui (NetDeviceWifi *self)
 {
-        NMDevice *nm_device;
         g_autofree gchar *status = NULL;
 
         if (device_is_hotspot (self)) {
@@ -393,12 +379,10 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *self)
                 request_scan (self);
         }
 
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-
         /* keep this in sync with the signal handler setup in cc_network_panel_init */
         wireless_enabled_toggled (self);
 
-        status = panel_device_status_to_localized_string (nm_device, NULL);
+        status = panel_device_status_to_localized_string (self->device, NULL);
         gtk_label_set_label (self->status_label, status);
 
         /* update list of APs */
@@ -503,7 +487,6 @@ wireless_try_to_connect (NetDeviceWifi *self,
                          const gchar *ap_object_path)
 {
         const gchar *ssid_target;
-        NMDevice *device;
 
         if (self->updating_device)
                 return;
@@ -511,16 +494,12 @@ wireless_try_to_connect (NetDeviceWifi *self,
         if (ap_object_path == NULL || ap_object_path[0] == 0)
                 return;
 
-        device = net_device_get_nm_device (NET_DEVICE (self));
-        if (device == NULL)
-                return;
-
         ssid_target = nm_utils_escape_ssid ((gpointer) g_bytes_get_data (ssid, NULL), g_bytes_get_size 
(ssid));
         g_debug ("try to connect to WIFI network %s [%s]",
                  ssid_target, ap_object_path);
 
         /* activate the connection */
-        if (!is_8021x (device, ap_object_path)) {
+        if (!is_8021x (self->device, ap_object_path)) {
                 g_autoptr(GPermission) permission = NULL;
                 gboolean allowed_to_share = FALSE;
                 g_autoptr(NMConnection) partial = NULL;
@@ -542,7 +521,7 @@ wireless_try_to_connect (NetDeviceWifi *self,
                 g_debug ("no existing connection found for %s, creating and activating one", ssid_target);
                 nm_client_add_and_activate_connection_async (self->client,
                                                              partial,
-                                                             device,
+                                                             self->device,
                                                              ap_object_path,
                                                              self->cancellable,
                                                              connection_add_activate_cb,
@@ -554,7 +533,7 @@ wireless_try_to_connect (NetDeviceWifi *self,
                 g_debug ("no existing connection found for %s, creating", ssid_target);
                 builder = g_variant_builder_new (G_VARIANT_TYPE ("av"));
                 g_variant_builder_add (builder, "v", g_variant_new_string ("connect-8021x-wifi"));
-                g_variant_builder_add (builder, "v", g_variant_new_string (nm_object_get_path (NM_OBJECT 
(device))));
+                g_variant_builder_add (builder, "v", g_variant_new_string (nm_object_get_path (NM_OBJECT 
(self->device))));
                 g_variant_builder_add (builder, "v", g_variant_new_string (ap_object_path));
                 parameters = g_variant_new ("av", builder);
 
@@ -684,7 +663,7 @@ net_device_wifi_get_hotspot_connection (NetDeviceWifi *self)
         GSList *connections, *l;
         NMConnection *c = NULL;
 
-        connections = net_device_get_valid_connections (self->client, net_device_get_nm_device (NET_DEVICE 
(self)));
+        connections = net_device_get_valid_connections (self->client, self->device);
         for (l = connections; l; l = l->next) {
                 NMConnection *tmp = l->data;
                 if (is_hotspot_connection (tmp)) {
@@ -704,7 +683,6 @@ overwrite_ssid_cb (GObject      *source_object,
 {
         g_autoptr(GError) error = NULL;
         NMRemoteConnection *connection;
-        NMDevice *device;
         NMConnection *c;
         NetDeviceWifi *self;
 
@@ -718,13 +696,12 @@ overwrite_ssid_cb (GObject      *source_object,
         }
 
         self = user_data;
-        device = net_device_get_nm_device (NET_DEVICE (self));
         c = net_device_wifi_get_hotspot_connection (self);
 
         g_debug ("activate existing hotspot connection\n");
         nm_client_activate_connection_async (self->client,
                                              c,
-                                             device,
+                                             self->device,
                                              NULL,
                                              self->cancellable,
                                              activate_cb,
@@ -734,7 +711,6 @@ overwrite_ssid_cb (GObject      *source_object,
 static void
 start_hotspot (NetDeviceWifi *self)
 {
-        NMDevice *device;
         g_autofree gchar *active_ssid = NULL;
         GtkWidget *window;
         NMConnection *c;
@@ -742,13 +718,11 @@ start_hotspot (NetDeviceWifi *self)
         g_autofree gchar *ssid = NULL;
         gint response;
 
-        device = net_device_get_nm_device (NET_DEVICE (self));
-
         window = gtk_widget_get_toplevel (GTK_WIDGET (self->notebook));
 
         if (!self->hotspot_dialog)
                 self->hotspot_dialog = cc_wifi_hotspot_dialog_new (GTK_WINDOW (window));
-        cc_wifi_hotspot_dialog_set_device (self->hotspot_dialog, NM_DEVICE_WIFI (device));
+        cc_wifi_hotspot_dialog_set_device (self->hotspot_dialog, NM_DEVICE_WIFI (self->device));
         hostname = get_hostname ();
         ssid =  pretty_hostname_to_ssid (hostname);
         cc_wifi_hotspot_dialog_set_hostname (self->hotspot_dialog, ssid);
@@ -771,7 +745,7 @@ start_hotspot (NetDeviceWifi *self)
                 else
                         nm_client_add_and_activate_connection_async (self->client,
                                                                      connection,
-                                                                     device,
+                                                                     self->device,
                                                                      NULL,
                                                                      self->cancellable,
                                                                      activate_new_cb,
@@ -786,18 +760,16 @@ stop_shared_connection (NetDeviceWifi *self)
 {
         const GPtrArray *connections;
         const GPtrArray *devices;
-        NMDevice *device;
         gint i;
         NMActiveConnection *c;
         gboolean found = FALSE;
 
-        device = net_device_get_nm_device (NET_DEVICE (self));
         connections = nm_client_get_active_connections (self->client);
         for (i = 0; connections && i < connections->len; i++) {
                 c = (NMActiveConnection *)connections->pdata[i];
 
                 devices = nm_active_connection_get_devices (c);
-                if (devices && devices->pdata[0] == device) {
+                if (devices && devices->pdata[0] == self->device) {
                         nm_client_deactivate_connection (self->client, c, NULL, NULL);
                         found = TRUE;
                         break;
@@ -869,6 +841,7 @@ net_device_wifi_finalize (GObject *object)
 
         g_clear_object (&self->builder);
         g_clear_object (&self->client);
+        g_clear_object (&self->device);
         g_clear_pointer (&self->selected_ssid_title, g_free);
         g_clear_pointer (&self->selected_connection_id, g_free);
         g_clear_pointer (&self->selected_ap_id, g_free);
@@ -1064,15 +1037,13 @@ show_details_for_row (NetDeviceWifi *self, CcWifiConnectionRow *row, CcWifiConne
         NMAccessPoint *ap;
         GtkWidget *window;
         NetConnectionEditor *editor;
-        NMDevice *device;
 
         window = gtk_widget_get_toplevel (GTK_WIDGET (row));
 
         connection = cc_wifi_connection_row_get_connection (row);
         ap = cc_wifi_connection_row_best_access_point (row);
 
-        device = net_device_get_nm_device (NET_DEVICE (self));
-        editor = net_connection_editor_new (GTK_WINDOW (window), connection, device, ap, self->client);
+        editor = net_connection_editor_new (GTK_WINDOW (window), connection, self->device, ap, self->client);
         net_connection_editor_run (editor);
 }
 
@@ -1124,7 +1095,6 @@ open_history (NetDeviceWifi *self)
         GtkWidget *swin;
         GtkWidget *content_area;
         GtkWidget *separator;
-        NMDevice *nm_device;
         GtkWidget *list;
         GList *list_rows;
 
@@ -1158,10 +1128,8 @@ open_history (NetDeviceWifi *self)
         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), GTK_SHADOW_NONE);
         gtk_container_add (GTK_CONTAINER (content_area), swin);
 
-        nm_device = net_device_get_nm_device (NET_DEVICE (self));
-
         list = GTK_WIDGET (cc_wifi_connection_list_new (self->client,
-                                                        NM_DEVICE_WIFI (nm_device),
+                                                        NM_DEVICE_WIFI (self->device),
                                                         FALSE, FALSE, TRUE));
         gtk_widget_show (list);
         gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
@@ -1222,7 +1190,6 @@ ap_activated (NetDeviceWifi *self, GtkListBoxRow *row)
         CcWifiConnectionRow *c_row;
         NMConnection *connection;
         NMAccessPoint *ap;
-        NMDevice *nm_device;
 
         /* The mockups want a row to connecto hidden networks; this could
          * be handeled here. */
@@ -1236,10 +1203,9 @@ ap_activated (NetDeviceWifi *self, GtkListBoxRow *row)
 
         if (ap != NULL) {
                 if (connection != NULL) {
-                        nm_device = net_device_get_nm_device (NET_DEVICE (self));
                         nm_client_activate_connection_async (self->client,
                                                              connection,
-                                                             nm_device, NULL, self->cancellable,
+                                                             self->device, NULL, self->cancellable,
                                                              connection_activate_cb, self);
                 } else {
                         GBytes *ssid;
@@ -1315,11 +1281,10 @@ net_device_wifi_new (CcPanel *panel, NMClient *client, NMDevice *device)
         NMDeviceWifiCapabilities caps;
         GtkWidget *list;
 
-        self = g_object_new (NET_TYPE_DEVICE_WIFI,
-                             "nm-device", device,
-                             NULL);
+        self = g_object_new (NET_TYPE_DEVICE_WIFI, NULL);
         self->panel = panel;
         self->client = g_object_ref (client);
+        self->device = g_object_ref (device);
 
         g_signal_connect_object (client, "notify::wireless-enabled",
                                  G_CALLBACK (wireless_enabled_toggled), self, G_CONNECT_SWAPPED);
@@ -1341,7 +1306,7 @@ net_device_wifi_new (CcPanel *panel, NMClient *client, NMDevice *device)
 
         /* only enable the button if the user can create a hotspot */
         perm = nm_client_get_permission_result (client, NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN);
-        caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device));
+        caps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (self->device));
         if (perm != NM_CLIENT_PERMISSION_RESULT_YES &&
             perm != NM_CLIENT_PERMISSION_RESULT_AUTH) {
                 gtk_widget_set_tooltip_text (GTK_WIDGET (self->start_hotspot_button), _("System policy 
prohibits use as a Hotspot"));
@@ -1359,14 +1324,23 @@ net_device_wifi_new (CcPanel *panel, NMClient *client, NMDevice *device)
         return self;
 }
 
+NMDevice *
+net_device_wifi_get_device (NetDeviceWifi *self)
+{
+        g_return_val_if_fail (NET_IS_DEVICE_WIFI (self), NULL);
+        return self->device;
+}
+
 GtkWidget *
 net_device_wifi_get_header_widget (NetDeviceWifi *self)
 {
+        g_return_val_if_fail (NET_IS_DEVICE_WIFI (self), NULL);
         return GTK_WIDGET (self->header_box);
 }
 
 GtkWidget *
 net_device_wifi_get_title_widget (NetDeviceWifi *self)
 {
+        g_return_val_if_fail (NET_IS_DEVICE_WIFI (self), NULL);
         return GTK_WIDGET (self->center_box);
 }
diff --git a/panels/network/net-device-wifi.h b/panels/network/net-device-wifi.h
index 582bab8a7..e74817dcf 100644
--- a/panels/network/net-device-wifi.h
+++ b/panels/network/net-device-wifi.h
@@ -34,9 +34,11 @@ NetDeviceWifi *net_device_wifi_new               (CcPanel       *panel,
                                                   NMClient      *client,
                                                   NMDevice      *device);
 
-GtkWidget     *net_device_wifi_get_header_widget (NetDeviceWifi *device_wifi);
+NMDevice      *net_device_wifi_get_device        (NetDeviceWifi *device);
 
-GtkWidget     *net_device_wifi_get_title_widget  (NetDeviceWifi *device_wifi);
+GtkWidget     *net_device_wifi_get_header_widget (NetDeviceWifi *device);
+
+GtkWidget     *net_device_wifi_get_title_widget  (NetDeviceWifi *device);
 
 G_END_DECLS
 
diff --git a/panels/network/net-device.c b/panels/network/net-device.c
index 12b0afa02..82edb951e 100644
--- a/panels/network/net-device.c
+++ b/panels/network/net-device.c
@@ -30,99 +30,17 @@
 
 #include "net-device.h"
 
-typedef struct
-{
-        NMDevice                        *nm_device;
-} NetDevicePrivate;
-
 enum {
         PROP_0,
         PROP_DEVICE,
         PROP_LAST
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (NetDevice, net_device, NET_TYPE_OBJECT)
-
-NMDevice *
-net_device_get_nm_device (NetDevice *self)
-{
-        NetDevicePrivate *priv;
-
-        g_return_val_if_fail (NET_IS_DEVICE (self), NULL);
-
-        priv = net_device_get_instance_private (self);
-        return priv->nm_device;
-}
-
-/**
- * net_device_get_property:
- **/
-static void
-net_device_get_property (GObject *object,
-                         guint prop_id,
-                         GValue *value,
-                         GParamSpec *pspec)
-{
-        NetDevice *net_device = NET_DEVICE (object);
-        NetDevicePrivate *priv = net_device_get_instance_private (net_device);
-
-        switch (prop_id) {
-        case PROP_DEVICE:
-                g_value_set_object (value, priv->nm_device);
-                break;
-        default:
-                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-                break;
-        }
-}
-
-/**
- * net_device_set_property:
- **/
-static void
-net_device_set_property (GObject *object,
-                         guint prop_id,
-                         const GValue *value,
-                         GParamSpec *pspec)
-{
-        NetDevice *net_device = NET_DEVICE (object);
-        NetDevicePrivate *priv = net_device_get_instance_private (net_device);
-
-        switch (prop_id) {
-        case PROP_DEVICE:
-                priv->nm_device = g_value_dup_object (value);
-                break;
-        default:
-                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-                break;
-        }
-}
-
-static void
-net_device_finalize (GObject *object)
-{
-        NetDevice *self = NET_DEVICE (object);
-        NetDevicePrivate *priv = net_device_get_instance_private (self);
-
-        g_clear_object (&priv->nm_device);
-
-        G_OBJECT_CLASS (net_device_parent_class)->finalize (object);
-}
+G_DEFINE_TYPE (NetDevice, net_device, NET_TYPE_OBJECT)
 
 static void
 net_device_class_init (NetDeviceClass *klass)
 {
-        GParamSpec *pspec;
-        GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-        object_class->finalize = net_device_finalize;
-        object_class->get_property = net_device_get_property;
-        object_class->set_property = net_device_set_property;
-
-        pspec = g_param_spec_object ("nm-device", NULL, NULL,
-                                     NM_TYPE_DEVICE,
-                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
-        g_object_class_install_property (object_class, PROP_DEVICE, pspec);
 }
 
 static void
diff --git a/panels/network/net-device.h b/panels/network/net-device.h
index 1953d8bae..1363e664b 100644
--- a/panels/network/net-device.h
+++ b/panels/network/net-device.h
@@ -34,6 +34,4 @@ struct _NetDeviceClass
         NetObjectClass               parent_class;
 };
 
-NMDevice     *net_device_get_nm_device         (NetDevice *device);
-
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]