[gnome-control-center] network: Remove NetObject id property



commit c74d26bf3a90b7e5dd732a6532394b06f8c10fca
Author: Robert Ancell <robert ancell canonical com>
Date:   Wed Oct 23 12:45:07 2019 +1300

    network: Remove NetObject id property
    
    This is better handled by comparing objects.

 panels/network/cc-network-panel.c     | 73 ++++++++++++++---------------------
 panels/network/cc-wifi-panel.c        | 13 +++----
 panels/network/net-device-bluetooth.c |  4 +-
 panels/network/net-device-bluetooth.h |  3 +-
 panels/network/net-device-ethernet.c  |  4 +-
 panels/network/net-device-ethernet.h  |  3 +-
 panels/network/net-device-mobile.c    |  4 +-
 panels/network/net-device-mobile.h    |  3 +-
 panels/network/net-device-wifi.c      |  4 +-
 panels/network/net-device-wifi.h      |  3 +-
 panels/network/net-object.c           | 41 --------------------
 panels/network/net-object.h           |  3 --
 panels/network/net-proxy.c            |  4 +-
 panels/network/net-vpn.c              | 44 ++++++++++++---------
 panels/network/net-vpn.h              | 12 +++---
 15 files changed, 76 insertions(+), 142 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 48ad02d03..b7a22ee7f 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -90,7 +90,6 @@ enum {
         PROP_PARAMETERS
 };
 
-static NetObject *find_net_object_by_id (CcNetworkPanel *self, const gchar *id);
 static void handle_argv (CcNetworkPanel *self);
 
 CC_PANEL_REGISTER (CcNetworkPanel, cc_network_panel)
@@ -378,10 +377,7 @@ handle_argv (CcNetworkPanel *self)
                         done = handle_argv_for_device (self, device);
                         g_object_unref (device);
                 } else if (NET_IS_VPN (object_tmp)) {
-                        g_autoptr(NMConnection) connection = NULL;
-
-                        g_object_get (object_tmp, "connection", &connection, NULL);
-                        done = handle_argv_for_connection (self, connection);
+                        done = handle_argv_for_connection (self, net_vpn_get_connection (NET_VPN 
(object_tmp)));
                 }
 
                 if (done)
@@ -446,20 +442,23 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
 {
         NMDeviceType type;
         NetDevice *net_device;
-        const char *udi;
+        guint i;
 
         if (!nm_device_get_managed (device))
                 return;
 
-        /* do we have an existing object with this id? */
-        udi = nm_device_get_udi (device);
-        if (find_net_object_by_id (self, udi) != NULL)
-                return;
+        /* does already exist */
+        for (i = 0; i < self->devices->len; i++) {
+                NetObject *o = g_ptr_array_index (self->devices, i);
+
+                if (NET_IS_DEVICE (o) && net_device_get_nm_device (NET_DEVICE (o)) == device)
+                        return;
+        }
 
         type = nm_device_get_device_type (device);
 
         g_debug ("device %s type %i path %s",
-                 udi, type, nm_object_get_path (NM_OBJECT (device)));
+                 nm_device_get_udi (device), type, nm_object_get_path (NM_OBJECT (device)));
 
         /* map the NMDeviceType to the GType, or ignore */
         switch (type) {
@@ -467,22 +466,19 @@ panel_add_device (CcNetworkPanel *self, NMDevice *device)
         case NM_DEVICE_TYPE_INFINIBAND:
                 net_device = NET_DEVICE (net_device_ethernet_new (self->cancellable,
                                                                   self->client,
-                                                                  device,
-                                                                  nm_device_get_udi (device)));
+                                                                  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->cancellable,
                                                                 self->client,
-                                                                device,
-                                                                nm_device_get_udi (device)));
+                                                                device));
                 add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_wired));
                 break;
         case NM_DEVICE_TYPE_BT:
                 net_device = NET_DEVICE (net_device_bluetooth_new (self->cancellable,
                                                                    self->client,
-                                                                   device,
-                                                                   nm_device_get_udi (device)));
+                                                                   device));
                 add_object (self, NET_OBJECT (net_device), GTK_CONTAINER (self->box_bluetooth));
                 break;
 
@@ -537,10 +533,16 @@ static void
 panel_remove_device (CcNetworkPanel *self, NMDevice *device)
 {
         NetObject *object;
+        guint i;
 
-        /* remove device from array */
-        object = find_net_object_by_id (self, nm_device_get_udi (device));
+        for (i = 0; i < self->devices->len; i++) {
+                NetObject *o = g_ptr_array_index (self->devices, i);
 
+                if (NET_IS_DEVICE (o) && net_device_get_nm_device (NET_DEVICE (o)) == device) {
+                        object = o;
+                        break;
+                }
+        }
         if (object == NULL)
                 return;
 
@@ -652,39 +654,22 @@ out:
         handle_argv (self);
 }
 
-static NetObject *
-find_net_object_by_id (CcNetworkPanel *self, const gchar *id)
-{
-        NetObject *object_tmp;
-        NetObject *object = NULL;
-        guint i;
-
-        for (i = 0; i < self->devices->len; i++) {
-                object_tmp = g_ptr_array_index (self->devices, i);
-
-                if (g_strcmp0 (net_object_get_id (object_tmp), id) == 0) {
-                        object = object_tmp;
-                        break;
-                }
-        }
-
-        return object;
-}
-
 static void
 panel_add_vpn_device (CcNetworkPanel *self, NMConnection *connection)
 {
         NetVpn *net_vpn;
-        const gchar *id;
+        guint i;
 
         /* does already exist */
-        id = nm_connection_get_path (connection);
-        if (find_net_object_by_id (self, id) != NULL)
-                return;
+        for (i = 0; i < self->devices->len; i++) {
+                NetObject *o = g_ptr_array_index (self->devices, i);
+
+                if (NET_IS_VPN (o) && net_vpn_get_connection (NET_VPN (o)) == connection)
+                        return;
+        }
 
         /* add as a VPN object */
-        net_vpn = net_vpn_new (id,
-                               connection,
+        net_vpn = net_vpn_new (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 2ef0ab440..2ea4a79f4 100644
--- a/panels/network/cc-wifi-panel.c
+++ b/panels/network/cc-wifi-panel.c
@@ -160,13 +160,12 @@ add_wifi_device (CcWifiPanel *self,
   net_device = net_device_wifi_new (CC_PANEL (self),
                                     self->cancellable,
                                     self->client,
-                                    device,
-                                    nm_device_get_udi (device));
+                                    device);
 
   /* And add to the header widgets */
   header_widget = net_device_wifi_get_header_widget (net_device);
 
-  gtk_stack_add_named (self->header_stack, header_widget, net_object_get_id (NET_OBJECT (net_device)));
+  gtk_stack_add_named (self->header_stack, header_widget, nm_device_get_udi (device));
 
   /* Setup custom title properties */
   g_ptr_array_add (self->devices, net_device);
@@ -176,7 +175,7 @@ add_wifi_device (CcWifiPanel *self,
   /* Needs to be added after the device is added to the self->devices array */
   widget = net_object_get_widget (NET_OBJECT (net_device), self->sizegroup);
   gtk_stack_add_titled (self->stack, widget,
-                        net_object_get_id (NET_OBJECT (net_device)),
+                        nm_device_get_udi (device),
                         nm_device_get_description (device));
 }
 
@@ -356,7 +355,7 @@ handle_argv_for_device (CcWifiPanel *self,
         }
       else if (self->arg_operation == OPERATION_SHOW_DEVICE)
         {
-          gtk_stack_set_visible_child_name (self->stack, net_object_get_id (net_object));
+          gtk_stack_set_visible_child_name (self->stack, nm_device_get_udi (device));
           ret = TRUE;
         }
     }
@@ -454,7 +453,7 @@ device_removed_cb (CcWifiPanel *self, NMDevice *device)
     {
       NetObject *object = g_ptr_array_index (self->devices, i);
 
-      if (g_strcmp0 (net_object_get_id (object), id) == 0)
+      if (net_device_get_nm_device (NET_DEVICE (object)) == device)
         {
           g_ptr_array_remove (self->devices, object);
           break;
@@ -551,7 +550,7 @@ on_stack_visible_child_changed_cb (GtkStack    *stack,
     {
       NetObject *object = g_ptr_array_index (self->devices, i);
 
-      if (g_strcmp0 (net_object_get_id (object), visible_device_id) == 0)
+      if (g_strcmp0 (nm_device_get_udi (net_device_get_nm_device (NET_DEVICE (object))), visible_device_id) 
== 0)
         {
           self->spinner_binding = g_object_bind_property (object,
                                                           "scanning",
diff --git a/panels/network/net-device-bluetooth.c b/panels/network/net-device-bluetooth.c
index 1543009d5..f2de0295e 100644
--- a/panels/network/net-device-bluetooth.c
+++ b/panels/network/net-device-bluetooth.c
@@ -235,13 +235,11 @@ net_device_bluetooth_init (NetDeviceBluetooth *self)
 NetDeviceBluetooth *
 net_device_bluetooth_new (GCancellable *cancellable,
                           NMClient     *client,
-                          NMDevice     *device,
-                          const gchar  *id)
+                          NMDevice     *device)
 {
         return g_object_new (NET_TYPE_DEVICE_BLUETOOTH,
                              "cancellable", cancellable,
                              "client", client,
                              "nm-device", device,
-                             "id", id,
                              NULL);
 }
diff --git a/panels/network/net-device-bluetooth.h b/panels/network/net-device-bluetooth.h
index 9da291c10..f42aeef14 100644
--- a/panels/network/net-device-bluetooth.h
+++ b/panels/network/net-device-bluetooth.h
@@ -33,8 +33,7 @@ G_DECLARE_FINAL_TYPE (NetDeviceBluetooth, net_device_bluetooth, NET, DEVICE_BLUE
 
 NetDeviceBluetooth *net_device_bluetooth_new                (GCancellable       *cancellable,
                                                              NMClient           *client,
-                                                             NMDevice           *device,
-                                                             const gchar        *id);
+                                                             NMDevice           *device);
 
 void                net_device_bluetooth_set_show_separator (NetDeviceBluetooth *device_bluetooth,
                                                              gboolean            show_separator);
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index a4cb76519..b2865708f 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -594,13 +594,11 @@ net_device_ethernet_init (NetDeviceEthernet *self)
 NetDeviceEthernet *
 net_device_ethernet_new (GCancellable *cancellable,
                          NMClient     *client,
-                         NMDevice     *device,
-                         const gchar  *id)
+                         NMDevice     *device)
 {
         return g_object_new (NET_TYPE_DEVICE_ETHERNET,
                              "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 ba865e224..d74648dcd 100644
--- a/panels/network/net-device-ethernet.h
+++ b/panels/network/net-device-ethernet.h
@@ -32,7 +32,6 @@ G_DECLARE_FINAL_TYPE (NetDeviceEthernet, net_device_ethernet, NET, DEVICE_ETHERN
 
 NetDeviceEthernet *net_device_ethernet_new (GCancellable *cancellable,
                                             NMClient     *client,
-                                            NMDevice     *device,
-                                            const gchar  *id);
+                                            NMDevice     *device);
 
 G_END_DECLS
diff --git a/panels/network/net-device-mobile.c b/panels/network/net-device-mobile.c
index 3a5242352..066987483 100644
--- a/panels/network/net-device-mobile.c
+++ b/panels/network/net-device-mobile.c
@@ -981,13 +981,11 @@ net_device_mobile_init (NetDeviceMobile *self)
 NetDeviceMobile *
 net_device_mobile_new (GCancellable *cancellable,
                        NMClient     *client,
-                       NMDevice     *device,
-                       const gchar  *id)
+                       NMDevice     *device)
 {
         return g_object_new (NET_TYPE_DEVICE_MOBILE,
                              "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 664b17550..220806547 100644
--- a/panels/network/net-device-mobile.h
+++ b/panels/network/net-device-mobile.h
@@ -33,7 +33,6 @@ G_DECLARE_FINAL_TYPE (NetDeviceMobile, net_device_mobile, NET, DEVICE_MOBILE, Ne
 
 NetDeviceMobile *net_device_mobile_new (GCancellable *cancellable,
                                         NMClient     *client,
-                                        NMDevice     *device,
-                                        const gchar  *id);
+                                        NMDevice     *device);
 
 G_END_DECLS
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index aafcdc2e3..ed8a7f6a6 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -104,14 +104,12 @@ NetDeviceWifi *
 net_device_wifi_new (CcPanel      *panel,
                      GCancellable *cancellable,
                      NMClient     *client,
-                     NMDevice     *device,
-                     const gchar  *id)
+                     NMDevice     *device)
 {
         NetDeviceWifi *self = g_object_new (NET_TYPE_DEVICE_WIFI,
                                             "cancellable", cancellable,
                                             "client", client,
                                             "nm-device", device,
-                                            "id", id,
                                             NULL);
         self->panel = panel;
         return self;
diff --git a/panels/network/net-device-wifi.h b/panels/network/net-device-wifi.h
index ada9a40ec..0b4b29977 100644
--- a/panels/network/net-device-wifi.h
+++ b/panels/network/net-device-wifi.h
@@ -33,8 +33,7 @@ G_DECLARE_FINAL_TYPE (NetDeviceWifi, net_device_wifi, NET, DEVICE_WIFI, NetDevic
 NetDeviceWifi *net_device_wifi_new               (CcPanel       *panel,
                                                   GCancellable  *cancellable,
                                                   NMClient      *client,
-                                                  NMDevice      *device,
-                                                  const gchar   *id);
+                                                  NMDevice      *device);
 
 GtkWidget     *net_device_wifi_get_header_widget (NetDeviceWifi *device_wifi);
 
diff --git a/panels/network/net-object.c b/panels/network/net-object.c
index 3170ccb9d..45ad38df6 100644
--- a/panels/network/net-object.c
+++ b/panels/network/net-object.c
@@ -28,7 +28,6 @@
 
 typedef struct
 {
-        gchar                           *id;
         gchar                           *title;
         GCancellable                    *cancellable;
         NMClient                        *client;
@@ -36,7 +35,6 @@ typedef struct
 
 enum {
         PROP_0,
-        PROP_ID,
         PROP_TITLE,
         PROP_CLIENT,
         PROP_CANCELLABLE,
@@ -55,43 +53,17 @@ G_DEFINE_TYPE_WITH_PRIVATE (NetObject, net_object, G_TYPE_OBJECT)
 void
 net_object_emit_changed (NetObject *self)
 {
-        NetObjectPrivate *priv = net_object_get_instance_private (self);
-
         g_return_if_fail (NET_IS_OBJECT (self));
-        g_debug ("NetObject: %s emit 'changed'", priv->id);
         g_signal_emit (self, signals[SIGNAL_CHANGED], 0);
 }
 
 void
 net_object_emit_removed (NetObject *self)
 {
-        NetObjectPrivate *priv = net_object_get_instance_private (self);
-
         g_return_if_fail (NET_IS_OBJECT (self));
-        g_debug ("NetObject: %s emit 'removed'", priv->id);
         g_signal_emit (self, signals[SIGNAL_REMOVED], 0);
 }
 
-const gchar *
-net_object_get_id (NetObject *self)
-{
-        NetObjectPrivate *priv = net_object_get_instance_private (self);
-
-        g_return_val_if_fail (NET_IS_OBJECT (self), NULL);
-        return priv->id;
-}
-
-void
-net_object_set_id (NetObject *self, const gchar *id)
-{
-        NetObjectPrivate *priv = net_object_get_instance_private (self);
-
-        g_return_if_fail (NET_IS_OBJECT (self));
-        g_clear_pointer (&priv->id, g_free);
-        priv->id = g_strdup (id);
-        g_object_notify (G_OBJECT (self), "id");
-}
-
 const gchar *
 net_object_get_title (NetObject *self)
 {
@@ -160,9 +132,6 @@ net_object_get_property (GObject *object,
         NetObjectPrivate *priv = net_object_get_instance_private (self);
 
         switch (prop_id) {
-        case PROP_ID:
-                g_value_set_string (value, priv->id);
-                break;
         case PROP_TITLE:
                 g_value_set_string (value, priv->title);
                 break;
@@ -191,10 +160,6 @@ net_object_set_property (GObject *object,
         NetObjectPrivate *priv = net_object_get_instance_private (self);
 
         switch (prop_id) {
-        case PROP_ID:
-                g_free (priv->id);
-                priv->id = g_strdup (g_value_get_string (value));
-                break;
         case PROP_TITLE:
                 g_free (priv->title);
                 priv->title = g_strdup (g_value_get_string (value));
@@ -220,7 +185,6 @@ net_object_finalize (GObject *object)
         NetObject *self = NET_OBJECT (object);
         NetObjectPrivate *priv = net_object_get_instance_private (self);
 
-        g_clear_pointer (&priv->id, g_free);
         g_clear_pointer (&priv->title, g_free);
         g_clear_object (&priv->cancellable);
 
@@ -239,11 +203,6 @@ net_object_class_init (NetObjectClass *klass)
         object_class->get_property = net_object_get_property;
         object_class->set_property = net_object_set_property;
 
-        pspec = g_param_spec_string ("id", NULL, NULL,
-                                     NULL,
-                                     G_PARAM_READWRITE);
-        g_object_class_install_property (object_class, PROP_ID, pspec);
-
         pspec = g_param_spec_string ("title", NULL, NULL,
                                      NULL,
                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
diff --git a/panels/network/net-object.h b/panels/network/net-object.h
index bd5f2ebdc..63c3d3085 100644
--- a/panels/network/net-object.h
+++ b/panels/network/net-object.h
@@ -43,9 +43,6 @@ struct _NetObjectClass
         void                     (*refresh)             (NetObject       *object);
 };
 
-const gchar     *net_object_get_id                      (NetObject      *object);
-void             net_object_set_id                      (NetObject      *object,
-                                                         const gchar    *id);
 const gchar     *net_object_get_title                   (NetObject      *object);
 void             net_object_set_title                   (NetObject      *object,
                                                          const gchar    *title);
diff --git a/panels/network/net-proxy.c b/panels/network/net-proxy.c
index 6f1b7db5b..29f326627 100644
--- a/panels/network/net-proxy.c
+++ b/panels/network/net-proxy.c
@@ -406,7 +406,5 @@ net_proxy_init (NetProxy *self)
 NetProxy *
 net_proxy_new (void)
 {
-        return g_object_new (NET_TYPE_PROXY,
-                             "id", "proxy",
-                             NULL);
+        return g_object_new (NET_TYPE_PROXY, NULL);
 }
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index 5897027ca..75a42fa5d 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -60,25 +60,6 @@ G_DEFINE_TYPE (NetVpn, net_vpn, NET_TYPE_OBJECT)
 
 static void nm_device_refresh_vpn_ui (NetVpn *self);
 
-NetVpn *
-net_vpn_new (const gchar  *id,
-             NMConnection *connection,
-             NMClient     *client)
-{
-        return g_object_new (NET_TYPE_VPN,
-                             "id", id,
-                             "connection", connection,
-                             "client", client,
-                             NULL);
-}
-
-void
-net_vpn_set_show_separator (NetVpn   *self,
-                            gboolean  show_separator)
-{
-        gtk_widget_set_visible (GTK_WIDGET (self->separator), show_separator);
-}
-
 static void
 connection_changed_cb (NetVpn *self)
 {
@@ -406,3 +387,28 @@ net_vpn_init (NetVpn *self)
         g_signal_connect_swapped (self->options_button, "clicked",
                                   G_CALLBACK (edit_connection), self);
 }
+
+NetVpn *
+net_vpn_new (NMConnection *connection,
+             NMClient     *client)
+{
+        return g_object_new (NET_TYPE_VPN,
+                             "connection", connection,
+                             "client", client,
+                             NULL);
+}
+
+NMConnection *
+net_vpn_get_connection (NetVpn *self)
+{
+        g_return_val_if_fail (NET_IS_VPN (self), NULL);
+        return self->connection;
+}
+
+void
+net_vpn_set_show_separator (NetVpn   *self,
+                            gboolean  show_separator)
+{
+        g_return_if_fail (NET_IS_VPN (self));
+        gtk_widget_set_visible (GTK_WIDGET (self->separator), show_separator);
+}
diff --git a/panels/network/net-vpn.h b/panels/network/net-vpn.h
index cb17eb3c8..5ebdbe48d 100644
--- a/panels/network/net-vpn.h
+++ b/panels/network/net-vpn.h
@@ -31,11 +31,13 @@ G_BEGIN_DECLS
 #define NET_TYPE_VPN (net_vpn_get_type ())
 G_DECLARE_FINAL_TYPE (NetVpn, net_vpn, NET, VPN, NetObject)
 
-NetVpn *net_vpn_new                (const gchar  *id,
-                                    NMConnection *connection,
-                                    NMClient     *client);
+NetVpn       *net_vpn_new                (NMConnection *connection,
+                                          NMClient     *client);
 
-void    net_vpn_set_show_separator (NetVpn       *self,
-                                    gboolean      show_separator);
+NMConnection *net_vpn_get_connection     (NetVpn       *vpn);
+
+
+void          net_vpn_set_show_separator (NetVpn       *vpn,
+                                          gboolean      show_separator);
 
 G_END_DECLS


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