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_OBJECT_CLASS (net_device_ethernet_parent_class)->finalize (object);
}
static void
populate_ui (NetDeviceEthernet *device)
{
        GList *children, *c;
        GSList *connections, *l;
        NMConnection *connection;
        gint n_connections;

        children = gtk_container_get_children (GTK_CONTAINER (device->list));
        for (c = children; c; c = c->next) {
                gtk_container_remove (GTK_CONTAINER (device->list), c->data);
        }
        g_list_free (children);

        children = gtk_container_get_children (GTK_CONTAINER (device->details));
        for (c = children; c; c = c->next) {
                gtk_container_remove (GTK_CONTAINER (device->details), c->data);
        }
        g_list_free (children);

        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));
                }
        }
        n_connections = g_slist_length (connections);

        if (n_connections > 4) {
                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (device->scrolled_window),
                                                GTK_POLICY_NEVER,
                                                GTK_POLICY_AUTOMATIC);
                gtk_widget_set_vexpand (device->scrolled_window, TRUE);
        } else {
                gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (device->scrolled_window),
                                                GTK_POLICY_NEVER,
                                                GTK_POLICY_NEVER);
                gtk_widget_set_vexpand (device->scrolled_window, FALSE);
        }

        if (n_connections > 1) {
                gtk_widget_hide (device->details);
                gtk_widget_hide (device->details_button);
                for (l = connections; l; l = l->next) {
                        NMConnection *connection = l->data;
                        add_row (device, connection);
                }
                gtk_widget_show (device->scrolled_window);
        } else if (n_connections == 1) {
                connection = connections->data;
                gtk_widget_hide (device->scrolled_window);
                add_details (device->details, net_device_get_nm_device (NET_DEVICE (device)), connection);
                gtk_widget_show_all (device->details);
                gtk_widget_show (device->details_button);
                g_object_set_data (G_OBJECT (device->details_button), "row", device->details_button);
                g_object_set_data (G_OBJECT (device->details_button), "connection", connection);

        } else {
                gtk_widget_hide (device->scrolled_window);
                gtk_widget_hide (device->details);
                gtk_widget_hide (device->details_button);
        }

        g_slist_free (connections);
}