[gnome-bluetooth/wip/hadess/lib-changes: 23/24] lib: Port update_properties() to GListModel
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/wip/hadess/lib-changes: 23/24] lib: Port update_properties() to GListModel
- Date: Fri, 26 Nov 2021 15:29:56 +0000 (UTC)
commit f93cdd677664684d0bc3d988aacc38c6ca617ed0
Author: Bastien Nocera <hadess hadess net>
Date: Fri Nov 26 13:11:27 2021 +0100
lib: Port update_properties() to GListModel
lib/bluetooth-settings-widget.c | 69 ++++++++++++-----------------------------
1 file changed, 20 insertions(+), 49 deletions(-)
---
diff --git a/lib/bluetooth-settings-widget.c b/lib/bluetooth-settings-widget.c
index b7242233..f203383b 100644
--- a/lib/bluetooth-settings-widget.c
+++ b/lib/bluetooth-settings-widget.c
@@ -27,6 +27,7 @@
#include <math.h>
#include "bluetooth-client.h"
+#include "bluetooth-device.h"
#include "bluetooth-client-private.h"
#include "bluetooth-client-glue.h"
#include "bluetooth-agent.h"
@@ -1103,12 +1104,8 @@ static void
update_properties (BluetoothSettingsWidget *self,
GDBusProxy *proxy)
{
+ g_autoptr(BluetoothDevice) device = NULL;
GtkSwitch *button;
- g_autoptr (GtkTreeModel) model = NULL;
- GtkTreeIter iter, child_iter;
- gboolean is_default = FALSE;
- gboolean found_adapter = FALSE;
- gboolean ret;
BluetoothType type;
gboolean connected, paired;
g_auto(GStrv) uuids = NULL;
@@ -1116,56 +1113,30 @@ update_properties (BluetoothSettingsWidget *self,
g_autofree char *icon = NULL;
guint i;
- model = bluetooth_client_get_model (self->client);
- g_assert (model);
+ g_autoptr(GListStore) model = NULL;
- ret = gtk_tree_model_get_iter_first (model, &iter);
- while (ret) {
- gtk_tree_model_get (model, &iter,
- BLUETOOTH_COLUMN_DEFAULT, &is_default,
- -1);
+ model = bluetooth_client_get_devices (self->client);
+ g_assert (model);
- if (is_default) {
- found_adapter = TRUE;
- break;
- }
- ret = gtk_tree_model_iter_next (model, &iter);
- }
- if (!found_adapter) {
- g_warning ("Could not find default adapter");
+ device = find_device_in_model (model, proxy);
+ if (!device) {
+ g_debug ("Device '%s' doesn't exist on the default adapter?!",
+ g_dbus_proxy_get_object_path (proxy));
return;
}
- ret = gtk_tree_model_iter_children (model, &child_iter, &iter);
- while (ret) {
- g_autoptr(GDBusProxy) p = NULL;
-
- gtk_tree_model_get (model, &child_iter,
- BLUETOOTH_COLUMN_PROXY, &p,
- -1);
-
- if (g_strcmp0 (g_dbus_proxy_get_object_path (proxy),
- g_dbus_proxy_get_object_path (p)) == 0) {
- break;
- }
-
- ret = gtk_tree_model_iter_next (model, &child_iter);
- }
-
- /* This means we've found the device */
- g_assert (ret);
-
- gtk_tree_model_get (model, &child_iter,
- BLUETOOTH_COLUMN_ADDRESS, &bdaddr,
- BLUETOOTH_COLUMN_ALIAS, &alias,
- BLUETOOTH_COLUMN_ICON, &icon,
- BLUETOOTH_COLUMN_PAIRED, &paired,
- BLUETOOTH_COLUMN_CONNECTED, &connected,
- BLUETOOTH_COLUMN_UUIDS, &uuids,
- BLUETOOTH_COLUMN_TYPE, &type,
- -1);
if (self->debug)
- bluetooth_client_dump_device (model, &child_iter);
+ bluetooth_device_dump (device);
+
+ g_object_get (device,
+ "address", &bdaddr,
+ "alias", &alias,
+ "icon", &icon,
+ "paired", &paired,
+ "connected", &connected,
+ "uuids", &uuids,
+ "type", &type,
+ NULL);
g_free (self->selected_object_path);
self->selected_object_path = g_strdup (g_dbus_proxy_get_object_path (proxy));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]