[gnome-bluetooth/wip/hadess/remove-gtk-tree: 9/18] lib: Remove GtkTreeModel usage when selecting new default adapter




commit 05500ee43fa1034de40e52c0ac895130afceae5c
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 1 15:43:39 2021 +0100

    lib: Remove GtkTreeModel usage when selecting new default adapter

 lib/bluetooth-client.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index 4a58fe64..d05d8452 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -791,6 +791,8 @@ adapter_removed (GDBusObjectManager   *manager,
                 BluetoothClient      *client)
 {
        GtkTreeIter iter, childiter;
+       g_autoptr(GDBusProxy) new_default_adapter = NULL;
+       GList *object_list, *l;
        gboolean was_default = FALSE;
        gboolean have_child;
 
@@ -824,16 +826,22 @@ adapter_removed (GDBusObjectManager   *manager,
        g_clear_object (&client->default_adapter);
        gtk_tree_store_remove (client->store, &iter);
 
-       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL(client->store),
-                                          &iter)) {
-               GDBusProxy *adapter;
-
-               gtk_tree_model_get (GTK_TREE_MODEL(client->store), &iter,
-                                  BLUETOOTH_COLUMN_PROXY, &adapter, -1);
+       new_default_adapter = NULL;
+       object_list = g_dbus_object_manager_get_objects (client->manager);
+       for (l = object_list; l != NULL; l = l->next) {
+               GDBusObject *object = l->data;
+               GDBusInterface *iface;
 
-               default_adapter_changed (manager, adapter, client);
+               iface = g_dbus_object_get_interface (object, BLUEZ_ADAPTER_INTERFACE);
+               if (iface) {
+                       new_default_adapter = G_DBUS_PROXY (g_object_ref (iface));
+                       break;
+               }
+       }
+       g_list_free_full (object_list, g_object_unref);
 
-               g_object_unref(adapter);
+       if (new_default_adapter) {
+               default_adapter_changed (manager, new_default_adapter, client);
        } else {
                g_object_notify (G_OBJECT (client), "default-adapter");
                g_object_notify (G_OBJECT (client), "default-adapter-powered");


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