[gnome-bluetooth/wip/hadess/cleanups: 2/9] lib: Simplify device search helpers
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-bluetooth/wip/hadess/cleanups: 2/9] lib: Simplify device search helpers
- Date: Wed, 17 Feb 2021 16:32:18 +0000 (UTC)
commit e2771decb1f76216ff8f35328cdd344d29b906f3
Author: Bastien Nocera <hadess hadess net>
Date: Thu Feb 11 12:03:00 2021 +0100
lib: Simplify device search helpers
Using g_auto*
lib/bluetooth-client.c | 30 ++++++++++++------------------
1 file changed, 12 insertions(+), 18 deletions(-)
---
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index f34b48fd..b0c03427 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -132,22 +132,20 @@ static gboolean iter_search(GtkTreeStore *store,
return found;
}
-static gboolean compare_path(GtkTreeStore *store,
- GtkTreeIter *iter, gpointer user_data)
+static gboolean
+compare_path (GtkTreeStore *store,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
const gchar *path = user_data;
- GDBusProxy *object;
- gboolean found = FALSE;
-
- gtk_tree_model_get(GTK_TREE_MODEL(store), iter,
- BLUETOOTH_COLUMN_PROXY, &object, -1);
+ g_autoptr(GDBusProxy) object = NULL;
- if (object != NULL) {
- found = g_str_equal(path, g_dbus_proxy_get_object_path(object));
- g_object_unref(object);
- }
+ gtk_tree_model_get (GTK_TREE_MODEL(store), iter,
+ BLUETOOTH_COLUMN_PROXY, &object,
+ -1);
- return found;
+ return (object != NULL &&
+ g_str_equal (path, g_dbus_proxy_get_object_path (object)));
}
static gboolean
@@ -156,15 +154,11 @@ compare_address (GtkTreeStore *store,
gpointer user_data)
{
const char *address = user_data;
- char *tmp_address;
- gboolean found = FALSE;
+ g_autofree char *tmp_address = NULL;
gtk_tree_model_get (GTK_TREE_MODEL(store), iter,
BLUETOOTH_COLUMN_ADDRESS, &tmp_address, -1);
- found = g_str_equal (address, tmp_address);
- g_free (tmp_address);
-
- return found;
+ return (g_strcmp0 (address, tmp_address) == 0);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]