[gnome-control-center] network/net-device-ethernet: Re-work how we keep track of connections



commit c8986f602af6557d373be6247d32b45f6a439115
Author: Rui Matos <tiagomatos gmail com>
Date:   Mon May 25 16:43:28 2015 +0200

    network/net-device-ethernet: Re-work how we keep track of connections
    
    When we're finalizing, the remote settings instance might already be
    gone and thus we can't list connections. In particular this happens at
    panel finalization resulting in the following warning:
    
    libnm-glib-CRITICAL **: nm_remote_settings_list_connections: assertion
    'NM_IS_REMOTE_SETTINGS (settings)' failed
    
    because cc_network_panel_dispose() unrefs the remote settings object
    before all the NetDevice instances are finalized.
    
    Since we only need to list connections on finalize to disconnect a
    signal we can instead use g_signal_connect_object() and keep the
    connections that we're keeping track of in a hash table instead of
    g_object_set_data().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=749850

 panels/network/net-device-ethernet.c |   23 ++++++++---------------
 panels/network/net-device-ethernet.h |    2 ++
 2 files changed, 10 insertions(+), 15 deletions(-)
---
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index 695ecfb..06bc218 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -369,6 +369,7 @@ static void
 connection_removed (NMRemoteConnection *connection,
                     NetDeviceEthernet  *device)
 {
+        g_hash_table_remove (device->connections, connection);
         device_ethernet_refresh_ui (device);
 }
 
@@ -395,10 +396,10 @@ populate_ui (NetDeviceEthernet *device)
         connections = net_device_get_valid_connections (NET_DEVICE (device));
         for (l = connections; l; l = l->next) {
                 NMConnection *connection = l->data;
-                if (!g_object_get_data (G_OBJECT (connection), "removed_signal_handler")) {
-                        g_signal_connect (connection, "removed",
-                                          G_CALLBACK (connection_removed), device);
-                        g_object_set_data (G_OBJECT (connection), "removed_signal_handler", GINT_TO_POINTER 
(TRUE));
+                if (!g_hash_table_contains (device->connections, connection)) {
+                        g_hash_table_add (device->connections, connection);
+                        g_signal_connect_object (connection, "removed",
+                                                 G_CALLBACK (connection_removed), device, 0);
                 }
         }
         n_connections = g_slist_length (connections);
@@ -585,19 +586,9 @@ static void
 device_ethernet_finalize (GObject *object)
 {
         NetDeviceEthernet *device = NET_DEVICE_ETHERNET (object);
-        GSList *connections, *l;
 
         g_object_unref (device->builder);
-
-        connections = net_device_get_valid_connections (NET_DEVICE (device));
-        for (l = connections; l; l = l->next) {
-                NMConnection *connection = l->data;
-                if (g_object_get_data (G_OBJECT (connection), "removed_signal_handler")) {
-                        g_signal_handlers_disconnect_by_func (connection, connection_removed, device);
-                        g_object_set_data (G_OBJECT (connection), "removed_signal_handler", NULL);
-                }
-        }
-        g_slist_free (connections);
+        g_hash_table_destroy (device->connections);
 
         G_OBJECT_CLASS (net_device_ethernet_parent_class)->finalize (object);
 }
@@ -637,4 +628,6 @@ net_device_ethernet_init (NetDeviceEthernet *device)
                 g_error_free (error);
                 return;
         }
+
+        device->connections = g_hash_table_new (NULL, NULL);
 }
diff --git a/panels/network/net-device-ethernet.h b/panels/network/net-device-ethernet.h
index 84d0e43..0d92fd1 100644
--- a/panels/network/net-device-ethernet.h
+++ b/panels/network/net-device-ethernet.h
@@ -51,6 +51,8 @@ struct _NetDeviceEthernet
         GtkWidget *details_button;
         GtkWidget *add_profile_button;
         gboolean   updating_device;
+
+        GHashTable *connections;
 };
 
 struct _NetDeviceEthernetClass


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