summaryrefslogtreecommitdiff
path: root/sendto
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2021-11-30 14:55:00 +0100
committerBastien Nocera <hadess@hadess.net>2021-11-30 14:55:00 +0100
commita0aafb0d7be283ff4854e9c4daf7c16ea533767f (patch)
tree83347e8f6bd39ba31b11b8e56f0cea856ec747cc /sendto
parenta87ca4445b98d0c192de09f767c9c9f15c749d76 (diff)
downloadgnome-bluetooth-a0aafb0d7be283ff4854e9c4daf7c16ea533767f.tar.gz
sendto: Port to GListStore BluetoothClient API
Diffstat (limited to 'sendto')
-rw-r--r--sendto/main.c57
1 files changed, 22 insertions, 35 deletions
diff --git a/sendto/main.c b/sendto/main.c
index b862f0fa..a9e43e97 100644
--- a/sendto/main.c
+++ b/sendto/main.c
@@ -34,6 +34,7 @@
#include <gtk/gtk.h>
#include <bluetooth-client.h>
+#include <bluetooth-device.h>
#define OBEX_SERVICE "org.bluez.obex"
#define OBEX_PATH "/org/bluez/obex"
@@ -517,45 +518,31 @@ static void create_window(void)
gtk_window_present(GTK_WINDOW(dialog));
}
-static gchar *get_device_name(const gchar *address)
+static char *
+get_device_name (const char *address)
{
- BluetoothClient *client;
- GtkTreeModel *model;
- GtkTreeIter iter;
- gboolean cont;
- char *found_name;
-
- found_name = NULL;
- client = bluetooth_client_new ();
- model = bluetooth_client_get_model (client);
- if (model == NULL) {
- g_object_unref (client);
- return NULL;
- }
-
- cont = gtk_tree_model_get_iter_first(model, &iter);
- while (cont != FALSE) {
- char *bdaddr, *name;
-
- gtk_tree_model_get(model, &iter,
- BLUETOOTH_COLUMN_ADDRESS, &bdaddr,
- BLUETOOTH_COLUMN_ALIAS, &name,
- -1);
- if (g_strcmp0 (bdaddr, address) == 0) {
- g_free (bdaddr);
- found_name = name;
- break;
- }
- g_free (bdaddr);
- g_free (name);
+ g_autoptr(BluetoothClient) client = NULL;
+ g_autoptr(GListStore) model = NULL;
+ guint n_devices, i;
+
+ model = bluetooth_client_get_devices (client);
+ n_devices = g_list_model_get_n_items (G_LIST_MODEL (model));
+ for (i = 0; i < n_devices; i++) {
+ g_autoptr(BluetoothDevice) device = NULL;
+ g_autofree char *name = NULL;
+ g_autofree char *_address = NULL;
+
+ g_object_get (device,
+ "name", &name,
+ "address", &_address,
+ NULL);
+ if (g_strcmp0 (address, _address) != 0)
+ continue;
- cont = gtk_tree_model_iter_next(model, &iter);
+ return g_steal_pointer (&name);
}
- g_object_unref (model);
- g_object_unref (client);
-
- return found_name;
+ return NULL;
}
static void