[gnome-bluetooth] lib: Remove start/stop discovering



commit affaf37d34e1dc484c2403e9fc03c5e65ed96906
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Oct 12 19:20:47 2011 +0100

    lib: Remove start/stop discovering
    
    And use a default-adapter-discovering property instead.

 lib/bluetooth-chooser.c        |   10 ++--
 lib/bluetooth-client-private.h |    3 -
 lib/bluetooth-client.c         |   99 +++++++++++++++++++--------------------
 lib/test-client.c              |    2 +-
 4 files changed, 54 insertions(+), 60 deletions(-)
---
diff --git a/lib/bluetooth-chooser.c b/lib/bluetooth-chooser.c
index f999c43..f9ee5f4 100644
--- a/lib/bluetooth-chooser.c
+++ b/lib/bluetooth-chooser.c
@@ -194,8 +194,8 @@ bluetooth_chooser_start_discovery (BluetoothChooser *self)
 
 	g_return_if_fail (priv->show_searching);
 
-	if (bluetooth_client_start_discovery (priv->client) != FALSE)
-		set_search_label (self, TRUE);
+	g_object_set (G_OBJECT (priv->client), "default-adapter-discovering", TRUE, NULL);
+	set_search_label (self, TRUE);
 	priv->disco_rq = TRUE;
 }
 
@@ -213,7 +213,7 @@ bluetooth_chooser_stop_discovery (BluetoothChooser *self)
 	g_return_if_fail (priv->show_searching);
 
 	priv->disco_rq = FALSE;
-	bluetooth_client_stop_discovery (priv->client);
+	g_object_set (G_OBJECT (priv->client), "default-adapter-discovering", FALSE, NULL);
 }
 
 static char *
@@ -640,7 +640,7 @@ adapter_model_row_changed (GtkTreeModel *model,
 	if (is_default == FALSE)
 		return;
 	if (powered != FALSE && discovering == FALSE && priv->disco_rq != FALSE) {
-		bluetooth_chooser_start_discovery (self);
+		g_object_set (G_OBJECT (priv->client), "default-adapter-discovering", TRUE, NULL);
 		set_search_label (self, TRUE);
 		return;
 	}
@@ -915,7 +915,7 @@ bluetooth_chooser_finalize (GObject *object)
 		g_signal_handler_disconnect (G_OBJECT(priv->client), priv->default_adapter_changed_id);
 		priv->default_adapter_changed_id = 0;
 
-		bluetooth_client_stop_discovery (priv->client);
+		g_object_set (G_OBJECT (priv->client), "default-adapter-discovering", FALSE, NULL);
 		g_object_unref (priv->client);
 		priv->client = NULL;
 	}
diff --git a/lib/bluetooth-client-private.h b/lib/bluetooth-client-private.h
index 0bfd86e..8dd9592 100644
--- a/lib/bluetooth-client-private.h
+++ b/lib/bluetooth-client-private.h
@@ -30,9 +30,6 @@
 
 G_BEGIN_DECLS
 
-gboolean bluetooth_client_start_discovery(BluetoothClient *client);
-gboolean bluetooth_client_stop_discovery(BluetoothClient *client);
-
 typedef void (*BluetoothClientCreateDeviceFunc) (BluetoothClient *client,
 						 const char *path,
 						 const GError *error,
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c
index 4b8d4a6..d92b92f 100644
--- a/lib/bluetooth-client.c
+++ b/lib/bluetooth-client.c
@@ -87,7 +87,8 @@ enum {
 	PROP_DEFAULT_ADAPTER,
 	PROP_DEFAULT_ADAPTER_POWERED,
 	PROP_DEFAULT_ADAPTER_DISCOVERABLE,
-	PROP_DEFAULT_ADAPTER_NAME
+	PROP_DEFAULT_ADAPTER_NAME,
+	PROP_DEFAULT_ADAPTER_DISCOVERING
 };
 
 G_DEFINE_TYPE(BluetoothClient, bluetooth_client, G_TYPE_OBJECT)
@@ -1170,6 +1171,43 @@ bail:
 }
 
 static void
+_bluetooth_client_set_default_adapter_discovering (BluetoothClient *client,
+						   gboolean         discover)
+{
+	GDBusProxy *adapter;
+
+	adapter = _bluetooth_client_get_default_adapter (client);
+	if (adapter == NULL)
+		return;
+
+	if (discover)
+		adapter_call_start_discovery_sync (ADAPTER (adapter), NULL, NULL);
+	else
+		adapter_call_stop_discovery_sync (ADAPTER (adapter), NULL, NULL);
+
+	g_object_unref(adapter);
+}
+
+static gboolean
+_bluetooth_client_get_default_adapter_discovering (BluetoothClient *self)
+{
+	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE (self);
+	GtkTreePath *path;
+	GtkTreeIter iter;
+	gboolean ret;
+
+	if (priv->default_adapter == NULL)
+		return FALSE;
+
+	path = gtk_tree_row_reference_get_path (priv->default_adapter);
+	gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->store), &iter, path);
+	gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, BLUETOOTH_COLUMN_DISCOVERING, &ret, -1);
+	gtk_tree_path_free (path);
+
+	return ret;
+}
+
+static void
 bluetooth_client_get_property (GObject        *object,
 			       guint           property_id,
 			       GValue         *value,
@@ -1190,6 +1228,9 @@ bluetooth_client_get_property (GObject        *object,
 	case PROP_DEFAULT_ADAPTER_DISCOVERABLE:
 		g_value_set_boolean (value, _bluetooth_client_get_discoverable (self));
 		break;
+	case PROP_DEFAULT_ADAPTER_DISCOVERING:
+		g_value_set_boolean (value, _bluetooth_client_get_default_adapter_discovering (self));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
 		break;
@@ -1208,6 +1249,9 @@ bluetooth_client_set_property (GObject        *object,
 	case PROP_DEFAULT_ADAPTER_DISCOVERABLE:
 	        _bluetooth_client_set_discoverable (self, g_value_get_boolean (value), 0);
 		break;
+	case PROP_DEFAULT_ADAPTER_DISCOVERING:
+		_bluetooth_client_set_default_adapter_discovering (self, g_value_get_boolean (value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
 		break;
@@ -1257,6 +1301,9 @@ static void bluetooth_client_class_init(BluetoothClientClass *klass)
 	g_object_class_install_property (object_class, PROP_DEFAULT_ADAPTER_NAME,
 					 g_param_spec_string ("default-adapter-name", NULL, NULL,
 							      NULL, G_PARAM_READABLE));
+	g_object_class_install_property (object_class, PROP_DEFAULT_ADAPTER_DISCOVERING,
+					 g_param_spec_boolean ("default-adapter-discovering", NULL, NULL,
+							       FALSE, G_PARAM_READWRITE));
 
 	if (error != NULL) {
 		g_printerr("Connecting to system bus failed: %s\n",
@@ -1418,56 +1465,6 @@ GtkTreeModel *bluetooth_client_get_device_model (BluetoothClient *client)
 	return model;
 }
 
-/**
- * bluetooth_client_start_discovery:
- * @client: a #BluetoothClient object
- *
- * Start a discovery on the default adapter.
- *
- * Return value: Whether a discovery was successfully started on the default adapter.
- **/
-gboolean bluetooth_client_start_discovery(BluetoothClient *client)
-{
-	GDBusProxy *adapter;
-
-	g_return_val_if_fail (BLUETOOTH_IS_CLIENT (client), FALSE);
-
-	adapter = _bluetooth_client_get_default_adapter (client);
-	if (adapter == NULL)
-		return FALSE;
-
-	adapter_call_start_discovery_sync (ADAPTER (adapter), NULL, NULL);
-
-	g_object_unref(adapter);
-
-	return TRUE;
-}
-
-/**
- * bluetooth_client_stop_discovery:
- * @client: a #BluetoothClient object
- *
- * Stop a discovery started on the default adapter.
- *
- * Return value: Whether a discovery was successfully stopped on the default adapter.
- **/
-gboolean bluetooth_client_stop_discovery(BluetoothClient *client)
-{
-	GDBusProxy *adapter;
-
-	g_return_val_if_fail (BLUETOOTH_IS_CLIENT (client), FALSE);
-
-	adapter = _bluetooth_client_get_default_adapter (client);
-	if (adapter == NULL)
-		return FALSE;
-
-	adapter_call_stop_discovery_sync (ADAPTER (adapter), NULL, NULL);
-
-	g_object_unref(adapter);
-
-	return TRUE;
-}
-
 typedef struct {
 	BluetoothClientCreateDeviceFunc func;
 	gpointer data;
diff --git a/lib/test-client.c b/lib/test-client.c
index 45a663b..90ff5fd 100644
--- a/lib/test-client.c
+++ b/lib/test-client.c
@@ -45,7 +45,7 @@ static void delete_callback(GtkWidget *window, GdkEvent *event,
 
 static void scan_callback(GtkWidget *button, gpointer user_data)
 {
-	bluetooth_client_start_discovery(client);
+	g_object_set (G_OBJECT (client), "default-adapter-discovering", TRUE, NULL);
 }
 
 static void select_callback(GtkTreeSelection *selection, gpointer user_data)



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