[gnome-bluetooth] Fix BluetoothFilterWidget property binding and document the widget



commit 2abd2c463973915d8d381c64e88659f9aabf67fd
Author: Joshua Lock <josh linux intel com>
Date:   Mon Sep 28 13:00:07 2009 +0100

    Fix BluetoothFilterWidget property binding and document the widget
    
    The property binding needs to be two way so that the properties are
    propogated regardless of whether they are set on the chooser or the filter.
    Add an extra mode to test-deviceselection, the "filter" option, which
    creates the wizard with two filters so that their synchronicity can be
    tested.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=596590

 lib/Makefile.am               |    2 +-
 lib/bluetooth-filter-widget.c |   50 ++++++++++++++++++++++++++++++------
 lib/gnome-bluetooth.symbols   |    1 +
 lib/test-deviceselection.c    |   55 ++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 97 insertions(+), 11 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 56839f8..7516b2c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -112,7 +112,7 @@ test_client_LDADD = libcommon.la $(GTK_LIBS) $(DBUS_LIBS)
 
 test_agent_LDADD = libcommon.la $(DBUS_LIBS)
 
-test_deviceselection_LDADD = libgnome-bluetooth.la
+test_deviceselection_LDADD = libcommon.la libgnome-bluetooth.la
 
 test_plugins_LDADD = libcommon.la
 
diff --git a/lib/bluetooth-filter-widget.c b/lib/bluetooth-filter-widget.c
index 88084e2..d58ee7a 100644
--- a/lib/bluetooth-filter-widget.c
+++ b/lib/bluetooth-filter-widget.c
@@ -53,7 +53,7 @@ struct _BluetoothFilterWidgetPrivate {
 	char *device_service_filter;
 
 	/* See bluetooth_filter_widget_bind_chooser () */
-	gpointer bindings[4];
+	gpointer bindings[8];
 
 	guint show_device_type : 1;
 	guint show_device_category : 1;
@@ -160,6 +160,14 @@ filter_type_changed_cb (GtkComboBox *widget, gpointer data)
 	g_object_notify (G_OBJECT(self), "device-type-filter");
 }
 
+/**
+ * bluetooth_filter_widget_set_title:
+ * @self: a #BluetoothFilterWidget.
+ * @title: Title for the #BluetoothFilterWidget.
+ *
+ * Used to set a different title for the #BluetoothFilterWidget than the default.
+ *
+ **/
 void
 bluetooth_filter_widget_set_title (BluetoothFilterWidget *self, gchar *title)
 {
@@ -173,25 +181,41 @@ static void
 bluetooth_filter_widget_bind_chooser_single (BluetoothFilterWidget *self,
 					     BluetoothChooser *chooser,
 					     const char *property,
-					     guint i)
+					     guint *i)
 {
 	BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(self);
 
-	/* Remember the bindings so we can unbind them later on */
-	priv->bindings[i] = seahorse_bind_property (property, (gpointer) chooser,
+	/* NOTE: We are binding the chooser as the source so that all of it's
+	 * properties are pushed to the filter.
+	 * Remember the bindings so we can unbind them later on */
+	priv->bindings[*i] = seahorse_bind_property (property, (gpointer) chooser,
 						    property, (gpointer) self);
+	priv->bindings[(*i)++] = seahorse_bind_property (property, (gpointer) self,
+		 				      property, (gpointer) chooser);
+	(*i)++;
 }
 
+/**
+ * bluetooth_filter_widget_bind_filter:
+ * @self: a #BluetoothFilterWidget.
+ * @chooser: The #BluetoothChooser widget to bind the filter to.
+ *
+ * Binds a #BluetoothFilterWidget to a #BluetoothChooser such that changing the
+ * #BluetoothFilterWidget results in filters being applied on the #BluetoothChooser.
+ * Any properties set on a bound #BluetoothChooser will also be set on the
+ * #BluetoothFilterWidget.
+ *
+ **/
 void
 bluetooth_filter_widget_bind_filter (BluetoothFilterWidget *self, BluetoothChooser *chooser)
 {
 	guint i;
 
 	i = 0;
-	bluetooth_filter_widget_bind_chooser_single (self, chooser, "device-type-filter", i);
-	bluetooth_filter_widget_bind_chooser_single (self, chooser, "device-category-filter", i++);
-	bluetooth_filter_widget_bind_chooser_single (self, chooser, "show-device-type", i++);
-	bluetooth_filter_widget_bind_chooser_single (self, chooser, "show-device-category", i++);
+	bluetooth_filter_widget_bind_chooser_single (self, chooser, "device-type-filter", &i);
+	bluetooth_filter_widget_bind_chooser_single (self, chooser, "device-category-filter", &i);
+	bluetooth_filter_widget_bind_chooser_single (self, chooser, "show-device-type", &i);
+	bluetooth_filter_widget_bind_chooser_single (self, chooser, "show-device-category", &i);
 }
 
 static void
@@ -335,7 +359,7 @@ bluetooth_filter_widget_dispose (GObject *object)
 		g_object_unref (priv->chooser);
 		priv->chooser = NULL;
 	}
-	for (i = 0; i < 4; i++) {
+	for (i = 0; i < 8; i++) {
 		if (priv->bindings[i] != NULL) {
 			seahorse_bind_disconnect (priv->bindings[i]);
 			priv->bindings[i] = NULL;
@@ -459,6 +483,14 @@ bluetooth_filter_widget_class_init (BluetoothFilterWidgetClass *klass)
  * @chooser: The #BluetoothChooser to filter
  *
  * Return value: A #BluetoothFilterWidget widget
+ * 
+ * Creates a new #BluetoothFilterWidget which can be bound to a #BluetoothChooser to
+ * control filtering of that #BluetoothChooser.
+ * Usually used in conjunction with a #BluetoothChooser which has the "has-internal-filter"
+ * property set to FALSE.
+ * 
+ * Note: Must call bluetooth_filter_widget_bind_filter () to bind the #BluetoothFilterWidget
+ * to a #BluetoothChooser.
  **/
 GtkWidget *
 bluetooth_filter_widget_new (void)
diff --git a/lib/gnome-bluetooth.symbols b/lib/gnome-bluetooth.symbols
index 433eb9d..6f4fdbb 100644
--- a/lib/gnome-bluetooth.symbols
+++ b/lib/gnome-bluetooth.symbols
@@ -31,5 +31,6 @@ bluetooth_type_get_type
 bluetooth_filter_widget_new
 bluetooth_filter_widget_set_title
 bluetooth_filter_widget_get_type
+bluetooth_filter_widget_bind_filter
 bluetooth_chooser_combo_get_type
 bluetooth_chooser_combo_new
diff --git a/lib/test-deviceselection.c b/lib/test-deviceselection.c
index 1f56b11..9a5504c 100644
--- a/lib/test-deviceselection.c
+++ b/lib/test-deviceselection.c
@@ -32,6 +32,7 @@
 #include "bluetooth-chooser-button.h"
 #include "bluetooth-chooser-combo.h"
 #include "bluetooth-client.h"
+#include "bluetooth-filter-widget.h"
 
 static void dump_selected_device(BluetoothChooser *sel)
 {
@@ -303,6 +304,56 @@ create_combo_dialogue (const char *bdaddr)
 	return dialog;
 }
 
+static GtkWidget *
+create_filter_dialogue (void)
+{
+	GtkWidget *dialog, *selector, *filter, *vbox, *hbox;
+
+	dialog = create_dialogue ("Add a Device");
+
+	hbox = gtk_hbox_new (FALSE, 6);
+	gtk_widget_show (hbox);
+
+	selector = g_object_new (BLUETOOTH_TYPE_CHOOSER,
+				 "title", "Select new device to setup",
+				 NULL);
+	gtk_container_set_border_width(GTK_CONTAINER(selector), 5);
+	gtk_widget_show(selector);
+	g_object_set(selector,
+		     "show-searching", TRUE,
+		     "device-category-filter", BLUETOOTH_CATEGORY_NOT_PAIRED_OR_TRUSTED,
+		     NULL);
+	gtk_box_pack_start (GTK_BOX (hbox), selector, FALSE, FALSE, 6);
+
+	vbox = gtk_vbox_new (FALSE, 0);
+	gtk_widget_show (vbox);
+	gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
+	filter = bluetooth_filter_widget_new ();
+	g_object_set (filter,
+		      "show-device-type", TRUE,
+		      "show-device-category", FALSE,
+		      NULL);
+	gtk_widget_show (filter);
+	bluetooth_filter_widget_bind_filter (BLUETOOTH_FILTER_WIDGET (filter), BLUETOOTH_CHOOSER (selector));
+	gtk_box_pack_start (GTK_BOX (vbox), filter, FALSE, FALSE, 6);
+
+	g_signal_connect(selector, "selected-device-changed",
+			 G_CALLBACK(select_device_changed), dialog);
+	g_signal_connect(selector, "notify::device-selected",
+			 G_CALLBACK(device_selected_cb), dialog);
+	g_signal_connect(selector, "notify::device-type-filter",
+			 G_CALLBACK(device_type_filter_selected_cb), dialog);
+	g_signal_connect(selector, "notify::device-category-filter",
+			 G_CALLBACK(device_category_filter_selected_cb), dialog);
+	gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG(dialog))), hbox);
+	bluetooth_chooser_start_discovery (BLUETOOTH_CHOOSER (selector));
+
+	g_signal_connect (G_OBJECT (dialog), "response",
+			  G_CALLBACK (response_cb), selector);
+
+	return dialog;
+}
+
 int main(int argc, char **argv)
 {
 	GtkWidget *dialog;
@@ -328,8 +379,10 @@ int main(int argc, char **argv)
 			dialog = create_combo_dialogue (argv[2]);
 		else
 			dialog = create_combo_dialogue (NULL);
+	} else if (g_str_equal (selection, "filter")) {
+		dialog = create_filter_dialogue ();
 	} else {
-		g_warning ("Unknown dialogue type, try either \"phone\", \"props\", \"combo\"  or \"wizard\"");
+		g_warning ("Unknown dialogue type, try either \"phone\", \"props\", \"combo\", \"filter\"  or \"wizard\"");
 		return 1;
 	}
 



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