[gnome-bluetooth/wip/hadess/remove-gtk-tree: 5/18] lib: Add helper to find a BluetoothDevice for a D-Bus object path




commit bae3c5f730ac6c5361ae68199e2e3c371d50b9d3
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 1 15:12:05 2021 +0100

    lib: Add helper to find a BluetoothDevice for a D-Bus object path
    
    This should get some use, as a number of APIs use object paths as a
    short-hand for Bluetooth devices as represented in bluetoothd.

 lib/bluetooth-client.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
---
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index cc608f36..dabc9009 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -198,6 +198,24 @@ get_iter_from_address (GtkTreeStore *store,
        return iter_search (store, iter, &parent_iter, compare_address, (gpointer) address);
 }
 
+static BluetoothDevice *
+get_device_for_path (BluetoothClient *client,
+                    const char      *path)
+{
+       guint n_items, i;
+
+       n_items = g_list_model_get_n_items (G_LIST_MODEL (client->list_store));
+       for (i = 0; i < n_items; i++) {
+               g_autoptr(BluetoothDevice) d = NULL;
+
+               d = g_list_model_get_item (G_LIST_MODEL (client->list_store), i);
+               if (g_str_equal (path, bluetooth_device_get_object_path (d))) {
+                       return g_steal_pointer (&d);
+               }
+       }
+       return NULL;
+}
+
 static char **
 device_list_uuids (const gchar * const *uuids)
 {


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