[gnome-bluetooth] First pass at adding UUIDs support



commit 666efceb95afe76fd4353e29659c903cd8722628
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Apr 24 01:48:58 2009 +0100

    First pass at adding UUIDs support
    
    We don't process the UUIDs into short names yet.
    (Helps: #578485)
---
 common/bluetooth-client.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
 common/bluetooth-client.h |    1 +
 common/test-client.c      |   21 +++++++++++++++++++++
 3 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/common/bluetooth-client.c b/common/bluetooth-client.c
index aac06be..2f79213 100644
--- a/common/bluetooth-client.c
+++ b/common/bluetooth-client.c
@@ -417,6 +417,35 @@ device_list_nodes (DBusGProxy *device, BluetoothClient *client, gboolean connect
 	return table;
 }
 
+static char **
+device_list_uuids (GValue *value)
+{
+	GPtrArray *ret;
+	char **uuids;
+	guint i;
+
+	if (value == NULL)
+		return NULL;
+
+	uuids = g_value_get_boxed (value);
+	if (uuids == NULL)
+		return NULL;
+
+	ret = g_ptr_array_new ();
+
+	for (i = 0; uuids[i] != NULL; i++) {
+		char *uuid;
+
+		//FIXME convert to bluetooth short names
+		uuid = g_strdup (uuids[i]);
+		g_ptr_array_add (ret, uuid);
+	}
+
+	g_ptr_array_add (ret, NULL);
+
+	return (char **) g_ptr_array_free (ret, FALSE);
+}
+
 static void device_changed(DBusGProxy *device, const char *property,
 					GValue *value, gpointer user_data)
 {
@@ -461,10 +490,14 @@ static void device_changed(DBusGProxy *device, const char *property,
 				BLUETOOTH_COLUMN_CONNECTED, connected, -1);
 	} else if (g_str_equal (property, "UUIDs") == TRUE) {
 		GHashTable *services;
+		char **uuids;
 
 		services = device_list_nodes (device, client, TRUE);
+		uuids = device_list_uuids (value);
 		gtk_tree_store_set(priv->store, &iter,
-				   BLUETOOTH_COLUMN_SERVICES, services, -1);
+				   BLUETOOTH_COLUMN_SERVICES, services,
+				   BLUETOOTH_COLUMN_UUIDS, uuids, -1);
+		g_strfreev (uuids);
 	}
 }
 
@@ -476,6 +509,7 @@ static void add_device(DBusGProxy *adapter, GtkTreeIter *parent,
 	DBusGProxy *device;
 	GValue *value;
 	const gchar *address, *alias, *name, *icon;
+	char **uuids;
 	GHashTable *services;
 	gboolean paired, trusted, connected;
 	guint type;
@@ -519,6 +553,9 @@ static void add_device(DBusGProxy *adapter, GtkTreeIter *parent,
 
 		value = g_hash_table_lookup(hash, "Connected");
 		connected = value ? g_value_get_boolean(value) : FALSE;
+
+		value = g_hash_table_lookup(hash, "UUIDs");
+		uuids = device_list_uuids (value);
 	} else {
 		if (device)
 			g_object_unref (device);
@@ -542,6 +579,7 @@ static void add_device(DBusGProxy *adapter, GtkTreeIter *parent,
 					BLUETOOTH_COLUMN_TYPE, type,
 					BLUETOOTH_COLUMN_ICON, icon,
 					BLUETOOTH_COLUMN_RSSI, rssi,
+					BLUETOOTH_COLUMN_UUIDS, uuids,
 					-1);
 
 			if (device != NULL) {
@@ -577,6 +615,7 @@ static void add_device(DBusGProxy *adapter, GtkTreeIter *parent,
 				BLUETOOTH_COLUMN_TRUSTED, trusted,
 				BLUETOOTH_COLUMN_CONNECTED, connected,
 				BLUETOOTH_COLUMN_SERVICES, services,
+				BLUETOOTH_COLUMN_UUIDS, uuids,
 				-1);
 
 done:
@@ -587,6 +626,7 @@ done:
 				G_CALLBACK(device_changed), client, NULL);
 		g_object_unref(device);
 	}
+	g_strfreev (uuids);
 }
 
 static void device_found(DBusGProxy *adapter, const char *address,
@@ -927,7 +967,7 @@ static void bluetooth_client_init(BluetoothClient *client)
 					 G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INT,
 					 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
 					 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
-					 G_TYPE_HASH_TABLE);
+					 G_TYPE_HASH_TABLE, G_TYPE_STRV);
 
 	priv->dbus = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS,
 				DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
diff --git a/common/bluetooth-client.h b/common/bluetooth-client.h
index 48cd334..b39b62c 100644
--- a/common/bluetooth-client.h
+++ b/common/bluetooth-client.h
@@ -46,6 +46,7 @@ enum {
 	BLUETOOTH_COLUMN_DISCOVERING,
 	BLUETOOTH_COLUMN_POWERED,
 	BLUETOOTH_COLUMN_SERVICES,
+	BLUETOOTH_COLUMN_UUIDS,
 	_BLUETOOTH_NUM_COLUMNS
 };
 
diff --git a/common/test-client.c b/common/test-client.c
index f5c2b26..558fdf5 100644
--- a/common/test-client.c
+++ b/common/test-client.c
@@ -121,6 +121,23 @@ static void services_to_text(GtkTreeViewColumn *column, GtkCellRenderer *cell,
 	g_string_free (str, TRUE);
 }
 
+static void uuids_to_text(GtkTreeViewColumn *column, GtkCellRenderer *cell,
+			  GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
+{
+	char **uuids;
+	char *str;
+
+	gtk_tree_model_get(model, iter, BLUETOOTH_COLUMN_UUIDS, &uuids, -1);
+	if (uuids == NULL)
+		str = NULL;
+	else
+		str = g_strjoinv (", ", uuids);
+	g_free (uuids);
+
+	g_object_set(cell, "text", str, NULL);
+	g_free (str);
+}
+
 static void create_window(void)
 {
 	GtkWidget *window;
@@ -219,6 +236,10 @@ static void create_window(void)
 					"Services", gtk_cell_renderer_text_new(),
 						services_to_text, NULL, NULL);
 
+	gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(tree), -1,
+					"UUIDs", gtk_cell_renderer_text_new(),
+						uuids_to_text, NULL, NULL);
+
 	model = bluetooth_client_get_model(client);
 	sorted = gtk_tree_model_sort_new_with_model(model);
 	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sorted),



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