[gnome-bluetooth] Move _dump_device() to BluetoothClient



commit d272168bb80df349f79e14ee5d8c78b85762ab4c
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Sep 17 17:34:56 2009 +0100

    Move _dump_device() to BluetoothClient
    
    and use it in the test-client when a device is selected
    
    https://bugzilla.gnome.org/show_bug.cgi?id=595486

 lib/bluetooth-client-private.h |    4 ++
 lib/bluetooth-client.c         |   94 ++++++++++++++++++++++++++++++++++++++++
 lib/test-client.c              |    8 +++-
 properties/main.c              |   92 +-------------------------------------
 4 files changed, 107 insertions(+), 91 deletions(-)
---
diff --git a/lib/bluetooth-client-private.h b/lib/bluetooth-client-private.h
index b773820..7f0112b 100644
--- a/lib/bluetooth-client-private.h
+++ b/lib/bluetooth-client-private.h
@@ -63,6 +63,10 @@ gboolean bluetooth_client_disconnect_service (BluetoothClient *client,
 					      BluetoothClientConnectFunc func,
 					      gpointer data);
 
+void bluetooth_client_dump_device (GtkTreeModel *model,
+				   GtkTreeIter *iter,
+				   gboolean recurse);
+
 G_END_DECLS
 
 #endif /* __BLUETOOTH_CLIENT_PRIVATE_H */
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index d310517..2cf0469 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -1733,3 +1733,97 @@ gboolean bluetooth_client_disconnect_service (BluetoothClient *client,
 	return TRUE;
 }
 
+#define BOOL_STR(x) (x ? "True" : "False")
+
+static void
+services_foreach (const char *service, gpointer _value, GString *str)
+{
+	gboolean value = GPOINTER_TO_INT (_value);
+	g_string_append_printf (str, "%s (%s) ", service, value ? "connected" : "not connected");
+}
+
+void
+bluetooth_client_dump_device (GtkTreeModel *model,
+			      GtkTreeIter *iter,
+			      gboolean recurse)
+{
+	DBusGProxy *proxy;
+	char *address, *alias, *name, *icon, **uuids;
+	gboolean is_default, paired, trusted, connected, discovering, powered, is_adapter;
+	GHashTable *services;
+	GtkTreeIter parent;
+	guint type;
+
+	gtk_tree_model_get (model, iter,
+			    BLUETOOTH_COLUMN_ADDRESS, &address,
+			    BLUETOOTH_COLUMN_ALIAS, &alias,
+			    BLUETOOTH_COLUMN_NAME, &name,
+			    BLUETOOTH_COLUMN_TYPE, &type,
+			    BLUETOOTH_COLUMN_ICON, &icon,
+			    BLUETOOTH_COLUMN_DEFAULT, &is_default,
+			    BLUETOOTH_COLUMN_PAIRED, &paired,
+			    BLUETOOTH_COLUMN_TRUSTED, &trusted,
+			    BLUETOOTH_COLUMN_CONNECTED, &connected,
+			    BLUETOOTH_COLUMN_DISCOVERING, &discovering,
+			    BLUETOOTH_COLUMN_POWERED, &powered,
+			    BLUETOOTH_COLUMN_SERVICES, &services,
+			    BLUETOOTH_COLUMN_UUIDS, &uuids,
+			    BLUETOOTH_COLUMN_PROXY, &proxy,
+			    -1);
+	is_adapter = !gtk_tree_model_iter_parent (model, &parent, iter);
+
+	if (is_adapter != FALSE) {
+		/* Adapter */
+		g_print ("Adapter: %s (%s)\n", name, address);
+		if (is_default)
+			g_print ("\tDefault adapter\n");
+		if (discovering)
+			g_print ("\tDiscovery in progress\n");
+		g_print ("\t%s\n", powered ? "Is powered" : "Is not powered");
+	} else {
+		/* Device */
+		g_print ("Device: %s (%s)\n", alias, address);
+		g_print ("\tD-Bus Path: %s\n", proxy ? dbus_g_proxy_get_path (proxy) : "(none)");
+		g_print ("\tType: %s Icon: %s\n", bluetooth_type_to_string (type), icon);
+		g_print ("\tPaired: %s Trusted: %s Connected: %s\n", BOOL_STR(paired), BOOL_STR(trusted), BOOL_STR(connected));
+		if (services != NULL) {
+			GString *str;
+
+			str = g_string_new (NULL);
+			g_hash_table_foreach (services, (GHFunc) services_foreach, str);
+			g_print ("\tServices: %s\n", str->str);
+			g_string_free (str, TRUE);
+		}
+		if (uuids != NULL) {
+			guint i;
+			g_print ("\tUUIDs: ");
+			for (i = 0; uuids[i] != NULL; i++)
+				g_print ("%s ", uuids[i]);
+			g_print ("\n");
+		}
+	}
+	g_print ("\n");
+
+	g_free (alias);
+	g_free (address);
+	g_free (icon);
+	g_object_unref (proxy);
+	if (services != NULL)
+		g_hash_table_unref (services);
+	g_strfreev (uuids);
+
+	if (recurse == FALSE)
+		return;
+
+	if (is_adapter != FALSE) {
+		GtkTreeIter child;
+
+		if (gtk_tree_model_iter_children (model, &child, iter) == FALSE)
+			return;
+		bluetooth_client_dump_device (model, &child, FALSE);
+		while (gtk_tree_model_iter_next (model, &child))
+			bluetooth_client_dump_device (model, &child, FALSE);
+	}
+
+}
+
diff --git a/lib/test-client.c b/lib/test-client.c
index 56d5ebc..81abafc 100644
--- a/lib/test-client.c
+++ b/lib/test-client.c
@@ -53,9 +53,13 @@ static void select_callback(GtkTreeSelection *selection, gpointer user_data)
 {
 	GtkTreeModel *model;
 	GtkTreeIter iter;
-	gboolean selected;
 
-	selected = gtk_tree_selection_get_selected(selection, &model, &iter);
+	if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE) {
+		g_print ("No devices selected");
+		return;
+	}
+
+	bluetooth_client_dump_device (model, &iter, FALSE);
 }
 
 static void row_inserted(GtkTreeModel *model, GtkTreePath *path,
diff --git a/properties/main.c b/properties/main.c
index 577e6c3..4bf511e 100644
--- a/properties/main.c
+++ b/properties/main.c
@@ -34,6 +34,7 @@
 
 #include "bluetooth-plugin-manager.h"
 #include "bluetooth-client.h"
+#include "bluetooth-client-private.h"
 #include "gconf-bridge.h"
 #include "general.h"
 #include "adapter.h"
@@ -220,93 +221,6 @@ message_received_cb (UniqueApp         *app,
 }
 
 static void
-services_foreach (const char *service, gpointer _value, GString *str)
-{
-	gboolean value = GPOINTER_TO_INT (_value);
-	g_string_append_printf (str, "%s (%s) ", service, value ? "connected" : "not connected");
-}
-
-#define BOOL_STR(x) (x ? "True" : "False")
-
-static void
-dump_device (GtkTreeModel *model, GtkTreeIter *iter, gboolean is_adapter)
-{
-	DBusGProxy *proxy;
-	char *address, *alias, *icon, **uuids, *name;
-	gboolean is_default, paired, trusted, connected, discovering, powered;
-	GHashTable *services;
-	guint type;
-
-	gtk_tree_model_get (model, iter,
-			    BLUETOOTH_COLUMN_ADDRESS, &address,
-			    BLUETOOTH_COLUMN_ALIAS, &alias,
-			    BLUETOOTH_COLUMN_NAME, &name,
-			    BLUETOOTH_COLUMN_TYPE, &type,
-			    BLUETOOTH_COLUMN_ICON, &icon,
-			    BLUETOOTH_COLUMN_DEFAULT, &is_default,
-			    BLUETOOTH_COLUMN_PAIRED, &paired,
-			    BLUETOOTH_COLUMN_TRUSTED, &trusted,
-			    BLUETOOTH_COLUMN_CONNECTED, &connected,
-			    BLUETOOTH_COLUMN_DISCOVERING, &discovering,
-			    BLUETOOTH_COLUMN_POWERED, &powered,
-			    BLUETOOTH_COLUMN_SERVICES, &services,
-			    BLUETOOTH_COLUMN_UUIDS, &uuids,
-			    BLUETOOTH_COLUMN_PROXY, &proxy,
-			    -1);
-
-	if (is_adapter != FALSE) {
-		/* Adapter */
-		g_print ("Adapter: %s (%s)\n", name, address);
-		if (is_default)
-			g_print ("\tDefault adapter\n");
-		if (discovering)
-			g_print ("\tDiscovery in progress\n");
-		g_print ("\t%s\n", powered ? "Is discovering" : "Not discovering");
-	} else {
-		/* Device */
-		g_print ("Device: %s (%s)\n", alias, address);
-		g_print ("\tD-Bus Path: %s\n", proxy ? dbus_g_proxy_get_path (proxy) : "(none)");
-		g_print ("\tType: %s Icon: %s\n", bluetooth_type_to_string (type), icon);
-		g_print ("\tPaired: %s Trusted: %s Connected: %s\n", BOOL_STR(paired), BOOL_STR(trusted), BOOL_STR(connected));
-		if (services != NULL) {
-			GString *str;
-
-			str = g_string_new (NULL);
-			g_hash_table_foreach (services, (GHFunc) services_foreach, str);
-			g_print ("\tServices: %s\n", str->str);
-			g_string_free (str, TRUE);
-		}
-		if (uuids != NULL) {
-			guint i;
-			g_print ("\tUUIDs: ");
-			for (i = 0; uuids[i] != NULL; i++)
-				g_print ("%s ", uuids[i]);
-			g_print ("\n");
-		}
-	}
-	g_print ("\n");
-
-	g_free (name);
-	g_free (alias);
-	g_free (address);
-	g_free (icon);
-	g_object_unref (proxy);
-	if (services != NULL)
-		g_hash_table_unref (services);
-	g_strfreev (uuids);
-
-	if (is_adapter != FALSE) {
-		GtkTreeIter child;
-
-		if (gtk_tree_model_iter_children (model, &child, iter) == FALSE)
-			return;
-		dump_device (model, &child, FALSE);
-		while (gtk_tree_model_iter_next (model, &child))
-			dump_device (model, &child, FALSE);
-	}
-}
-
-static void
 dump_devices (void)
 {
 	BluetoothClient *client;
@@ -321,9 +235,9 @@ dump_devices (void)
 		g_print ("Is bluetoothd running, and a Bluetooth adapter enabled?\n");
 		return;
 	}
-	dump_device (model, &iter, TRUE);
+	bluetooth_client_dump_device (model, &iter, TRUE);
 	while (gtk_tree_model_iter_next (model, &iter))
-		dump_device (model, &iter, TRUE);
+		bluetooth_client_dump_device (model, &iter, TRUE);
 }
 
 static gboolean option_dump = FALSE;



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