[gnome-bluetooth] Change the "Search" button to a label with a spinner



commit b65b0f39a39f0f9572afc24adf23326a5122ad22
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Jun 15 15:40:10 2009 +0100

    Change the "Search" button to a label with a spinner
    
    Allows us to really show that something is happening, and just
    restart the search when another one finishes (Closes: #579076)

 lib/Makefile.am            |    4 +
 lib/bling-color.c          |   86 +++++++++++++
 lib/bling-color.h          |   35 +++++
 lib/bling-spinner.c        |  300 ++++++++++++++++++++++++++++++++++++++++++++
 lib/bling-spinner.h        |   58 +++++++++
 lib/bluetooth-chooser.c    |  118 +++++++++++------
 lib/bluetooth-chooser.h    |    1 +
 lib/test-deviceselection.c |    6 +-
 8 files changed, 564 insertions(+), 44 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1f82ed3..df10cb4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -10,6 +10,8 @@ libcommon_la_SOURCES =						\
 		obex-agent.h obex-agent.c			\
 		bluetooth-plugin-manager.c			\
 		bluetooth-plugin-manager.h			\
+		bling-color.c bling-color.h			\
+		bling-spinner.c bling-spinner.h			\
 		bluetooth-enums.h
 libcommon_la_LIBADD = $(COMMON_LIBS)
 libcommon_la_LDFLAGS = -no-undefined $(AM_LDFLAGS)
@@ -20,6 +22,8 @@ libgnome_bluetooth_la_SOURCES =				\
 	marshal.h marshal.c				\
 	gnome-bluetooth-enum-types.h			\
 	gnome-bluetooth-enum-types.c			\
+	bling-color.c bling-color.h			\
+	bling-spinner.c bling-spinner.h			\
 	bluetooth-chooser.c bluetooth-chooser.h		\
 	bluetooth-chooser-button.c bluetooth-chooser-button.h
 
diff --git a/lib/bling-color.c b/lib/bling-color.c
new file mode 100644
index 0000000..fd7f503
--- /dev/null
+++ b/lib/bling-color.c
@@ -0,0 +1,86 @@
+/*
+ * @file libbling/bling-window.c A RGBA color type, for use with libbling.
+ *
+ * @Copyright (C) 2007 John Stowers, Neil Jagdish Patel.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA  02111-1307, USA.
+ */
+ 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <string.h>
+#include <bling-color.h>
+
+
+static int 
+getdec(char hexchar)
+{
+   if ((hexchar >= '0') && (hexchar <= '9')) return hexchar - '0';
+   if ((hexchar >= 'A') && (hexchar <= 'F')) return hexchar - 'A' + 10;
+   if ((hexchar >= 'a') && (hexchar <= 'f')) return hexchar - 'a' + 10;
+
+   return -1; // Wrong character
+
+}
+
+static void
+hex2float(const char* HexColor, float* FloatColor)
+{
+   const char* HexColorPtr = HexColor;
+
+   int i = 0;
+   for (i = 0; i < 4; i++)
+   {
+     int IntColor = (getdec(HexColorPtr[0]) * 16) +
+                     getdec(HexColorPtr[1]);
+
+     FloatColor[i] = (float) IntColor / 255.0;
+     HexColorPtr += 2;
+   }
+
+}
+
+void 
+bling_color_parse_string (BlingColor *color, const gchar *str)
+{
+	gfloat colors[4];
+	size_t len;
+	
+	len = strlen (str);
+	if (len != 8) {
+		/* Always return a valid color */
+		color->red = 0.0;
+		color->green = 0.0;
+		color->blue = 0.0;
+		color->alpha = 1.0;
+	} else {
+		hex2float (str, colors);
+		color->red = colors[0];
+		color->green = colors[1];
+		color->blue = colors[2];
+		color->alpha = colors[3];
+	}
+}
+
+
+
+
+
+
+
diff --git a/lib/bling-color.h b/lib/bling-color.h
new file mode 100644
index 0000000..b12ae71
--- /dev/null
+++ b/lib/bling-color.h
@@ -0,0 +1,35 @@
+/* @Copyright (C) 2007 John Stowers, Neil Jagdish Patel.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA  02111-1307, USA.
+ */
+
+
+#ifndef _BLING_COLOR_H_
+#define _BLING_COLOR_H_
+
+typedef struct {
+	gfloat red;
+	gfloat green;
+	gfloat blue;
+	gfloat alpha;
+	
+} BlingColor;
+
+
+void bling_color_parse_string (BlingColor *color, const gchar *str);
+
+
+#endif /* _BLING_COLOR_H_ */
diff --git a/lib/bling-spinner.c b/lib/bling-spinner.c
new file mode 100644
index 0000000..ecd5901
--- /dev/null
+++ b/lib/bling-spinner.c
@@ -0,0 +1,300 @@
+/*
+ * @file libbling/bling-spinner.c A apple-esque spinner widger
+ *
+ * @Copyright (C) 2007 John Stowers, Neil Jagdish Patel.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA  02111-1307, USA.
+ * 
+ * Code adapted from egg-spinner 
+ * by Christian Hergert <christian hergert gmail com>
+ */
+ 
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <math.h>
+
+#include "bling-spinner.h"
+#include "bling-color.h"
+
+#define BLING_SPINNER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), BLING_TYPE_SPINNER, BlingSpinnerPrivate))
+
+G_DEFINE_TYPE (BlingSpinner, bling_spinner, GTK_TYPE_DRAWING_AREA);
+
+enum
+{
+	PROP_0,
+	PROP_COLOR,
+	PROP_NUM_LINES
+};
+
+/* STRUCTS & ENUMS */
+struct _BlingSpinnerPrivate
+{
+	/* state */
+	gboolean have_alpha;
+	guint current;
+	guint timeout;
+
+	/* appearance */
+	BlingColor color;
+	guint lines;
+};
+
+/* FORWARDS */
+static void bling_spinner_class_init(BlingSpinnerClass *klass);
+static void bling_spinner_init(BlingSpinner *spinner);
+static void bling_spinner_finalize(GObject *obj);
+static void bling_spinner_set_property(GObject *gobject, guint prop_id, const GValue *value, GParamSpec *pspec);
+static gboolean bling_spinner_expose(GtkWidget *widget, GdkEventExpose *event);
+static void bling_spinner_screen_changed (GtkWidget* widget, GdkScreen* old_screen);
+
+static GtkDrawingAreaClass *parent_class;
+
+/* DRAWING FUNCTIONS */
+static void
+draw (GtkWidget *widget, cairo_t *cr)
+{
+	double x, y;
+	double radius;
+	double half;
+	int i;
+	int width, height;
+
+	BlingSpinnerPrivate *priv;
+
+	priv = BLING_SPINNER_GET_PRIVATE (widget);
+	
+	cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+	
+	width = widget->allocation.width;
+	height = widget->allocation.height;
+
+	if ( (width < 12) || (height <12) )
+		gtk_widget_set_size_request(widget, 12, 12);
+	
+	//x = widget->allocation.x + widget->allocation.width / 2;
+	//y = widget->allocation.y + widget->allocation.height / 2;
+	x = widget->allocation.width / 2;
+	y = widget->allocation.height / 2;
+	radius = MIN (widget->allocation.width  / 2,
+	              widget->allocation.height / 2);
+	half = priv->lines / 2;
+
+	/*FIXME: render in B&W for non transparency */
+
+	for (i = 0; i < priv->lines; i++) {
+		int inset = 0.7 * radius;
+		/* transparency is a function of time and intial value */
+		double t = (double) ((i + priv->lines - priv->current)
+		           % priv->lines) / priv->lines;
+
+		cairo_save (cr);
+
+		cairo_set_source_rgba (cr, 0, 0, 0, t);
+		//cairo_set_line_width (cr, 2 * cairo_get_line_width (cr));
+		cairo_set_line_width (cr, 2.0);
+		cairo_move_to (cr,
+		               x + (radius - inset) * cos (i * M_PI / half),
+					   y + (radius - inset) * sin (i * M_PI / half));
+		cairo_line_to (cr,
+		               x + radius * cos (i * M_PI / half),
+					   y + radius * sin (i * M_PI / half));
+		cairo_stroke (cr);
+
+		cairo_restore (cr);
+	}
+}
+
+
+/*  GOBJECT INIT CODE */
+static void
+bling_spinner_class_init(BlingSpinnerClass *klass)
+{
+	GObjectClass *gobject_class;
+	GtkWidgetClass *widget_class;
+
+	parent_class = g_type_class_peek_parent(klass);
+
+	gobject_class = G_OBJECT_CLASS(klass);
+	g_type_class_add_private (gobject_class, sizeof (BlingSpinnerPrivate));
+	gobject_class->set_property = bling_spinner_set_property;
+	
+	widget_class = GTK_WIDGET_CLASS(klass);
+	widget_class->expose_event = bling_spinner_expose;
+	widget_class->screen_changed = bling_spinner_screen_changed;
+
+	g_object_class_install_property(gobject_class, PROP_COLOR,
+		g_param_spec_string("color", "Color",
+							"Main color",
+							"454545C8",
+							G_PARAM_CONSTRUCT | G_PARAM_WRITABLE));
+
+	g_object_class_install_property(gobject_class, PROP_NUM_LINES,
+		g_param_spec_uint("lines", "Num Lines",
+							"The number of lines to animate",
+							0,20,12,
+							G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+
+}
+
+static void
+bling_spinner_init (BlingSpinner *spinner)
+{
+	BlingSpinnerPrivate *priv;
+	
+	priv = BLING_SPINNER_GET_PRIVATE (spinner);
+	priv->current = 0;
+	priv->timeout = 0;
+}
+
+static gboolean
+bling_spinner_expose (GtkWidget *widget, GdkEventExpose *event)
+{
+	cairo_t *cr;
+
+	/* get cairo context */
+	cr = gdk_cairo_create (widget->window);
+
+	/* set a clip region for the expose event */
+	cairo_rectangle (cr,
+	                 event->area.x, event->area.y,
+					 event->area.width, event->area.height);
+	cairo_clip (cr);
+
+	/* draw clip region */
+	draw (widget, cr);
+
+	/* free memory */
+	cairo_destroy (cr);
+
+	return FALSE;
+}
+
+static void 
+bling_spinner_screen_changed (GtkWidget* widget, GdkScreen* old_screen)
+{                       
+	BlingSpinner *spinner;
+	BlingSpinnerPrivate *priv;
+	GdkScreen* new_screen;
+	GdkColormap* colormap;
+	
+	spinner = BLING_SPINNER(widget);
+	priv = BLING_SPINNER_GET_PRIVATE (spinner);
+
+	new_screen = gtk_widget_get_screen (widget);
+	colormap = gdk_screen_get_rgba_colormap (new_screen);
+      
+	if (!colormap) {
+		colormap = gdk_screen_get_rgb_colormap (new_screen);
+		priv->have_alpha = FALSE;
+	} else
+		priv->have_alpha = TRUE;
+	
+	gtk_widget_set_colormap (widget, colormap);
+}
+
+gboolean
+bling_spinner_timeout (gpointer data)
+{
+	BlingSpinner *spinner;
+	BlingSpinnerPrivate *priv;
+
+	spinner = BLING_SPINNER (data);
+	priv = BLING_SPINNER_GET_PRIVATE (spinner);
+
+	if (priv->current + 1 >= priv->lines) {
+		priv->current = 0;
+	} else {
+		priv->current++;
+	}
+
+	gtk_widget_queue_draw (GTK_WIDGET (data));
+
+	return TRUE;
+}
+
+static void
+bling_spinner_set_property(GObject *gobject, guint prop_id,
+					const GValue *value, GParamSpec *pspec)
+{
+	BlingSpinner *spinner;
+	BlingSpinnerPrivate *priv;
+	
+	spinner = BLING_SPINNER(gobject);
+	priv = BLING_SPINNER_GET_PRIVATE (spinner);
+
+	switch (prop_id)
+	{
+		case PROP_COLOR:
+			bling_color_parse_string (&priv->color, g_value_get_string(value));
+			break;
+		case PROP_NUM_LINES:
+			priv->lines = g_value_get_uint(value);
+			break;
+		default:
+			G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
+			break;
+	}
+}
+
+/**
+ * bling_spinner_new
+ *
+ * Returns a default spinner. Not yet started.
+ *
+ * Returns: a new #BlingSpinner
+ */
+GtkWidget *
+bling_spinner_new (void)
+{
+	return g_object_new (BLING_TYPE_SPINNER, NULL);
+}
+
+/**
+ * bling_spinner_start
+ *
+ * Starts the animation
+ */
+void
+bling_spinner_start (BlingSpinner *spinner)
+{
+	BlingSpinnerPrivate *priv;
+
+	priv = BLING_SPINNER_GET_PRIVATE (spinner);
+	if (priv->timeout != 0)
+		return;
+	priv->timeout = g_timeout_add (80, bling_spinner_timeout, spinner);
+}
+
+/**
+ * bling_spinner_stop
+ *
+ * Stops the animation
+ */void
+bling_spinner_stop (BlingSpinner *spinner)
+{
+	BlingSpinnerPrivate *priv;
+
+	priv = BLING_SPINNER_GET_PRIVATE (spinner);
+	if (priv->timeout == 0)
+		return;
+	g_source_remove (priv->timeout);
+	priv->timeout = 0;
+}
+
diff --git a/lib/bling-spinner.h b/lib/bling-spinner.h
new file mode 100644
index 0000000..8bc153c
--- /dev/null
+++ b/lib/bling-spinner.h
@@ -0,0 +1,58 @@
+/* @Copyright (C) 2007 John Stowers, Neil Jagdish Patel.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA  02111-1307, USA.
+ */
+
+
+#ifndef _BLING_SPINNER_H_
+#define _BLING_SPINNER_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define BLING_TYPE_SPINNER           (bling_spinner_get_type ())
+#define BLING_SPINNER(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), BLING_TYPE_SPINNER, BlingSpinner))
+#define BLING_SPINNER_CLASS(obj)     (G_TYPE_CHECK_CLASS_CAST ((obj), BLING_SPINNER,  BlingSpinnerClass))
+#define BLING_IS_SPINNER(obj)        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BLING_TYPE_SPINNER))
+#define BLING_IS_SPINNER_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE ((obj), BLING_TYPE_SPINNER))
+#define BLING_SPINNER_GET_CLASS      (G_TYPE_INSTANCE_GET_CLASS ((obj), BLING_TYPE_SPINNER, BlingSpinnerClass))
+
+typedef struct _BlingSpinner      BlingSpinner;
+typedef struct _BlingSpinnerClass BlingSpinnerClass;
+typedef struct _BlingSpinnerPrivate  BlingSpinnerPrivate;
+
+struct _BlingSpinner
+{
+	GtkDrawingArea parent;
+};
+
+struct _BlingSpinnerClass
+{
+	GtkDrawingAreaClass parent_class;
+	BlingSpinnerPrivate *priv;
+};
+
+GType bling_spinner_get_type (void);
+
+GtkWidget * bling_spinner_new (void);
+
+void bling_spinner_start (BlingSpinner *spinner);
+void bling_spinner_stop  (BlingSpinner *spinner);
+
+G_END_DECLS
+
+#endif
diff --git a/lib/bluetooth-chooser.c b/lib/bluetooth-chooser.c
index 21c7662..6d66dbd 100644
--- a/lib/bluetooth-chooser.c
+++ b/lib/bluetooth-chooser.c
@@ -33,6 +33,7 @@
 #include "bluetooth-client.h"
 #include "bluetooth-chooser.h"
 #include "gnome-bluetooth-enum-types.h"
+#include "bling-spinner.h"
 
 enum {
 	SELECTED_DEVICE_CHANGED,
@@ -58,7 +59,7 @@ struct _BluetoothChooserPrivate {
 	GtkCellRenderer *bonded_cell;
 	GtkCellRenderer *connected_cell;
 	GtkWidget *treeview;
-	GtkWidget *search_button;
+	GtkWidget *search_hbox, *search_label, *spinner;
 	GtkWidget *device_type_label, *device_type;
 	GtkWidget *device_category_label, *device_category;
 	GtkWidget *filters_vbox;
@@ -71,7 +72,7 @@ struct _BluetoothChooserPrivate {
 
 	guint show_paired : 1;
 	guint show_connected : 1;
-	guint show_search : 1;
+	guint show_searching : 1;
 	guint show_device_type : 1;
 	guint show_device_category : 1;
 	guint disco_rq : 1;
@@ -162,6 +163,27 @@ alias_to_label (GtkTreeViewColumn *column, GtkCellRenderer *cell,
 	g_free (alias);
 }
 
+static void
+set_search_label (BluetoothChooser *self, gboolean state)
+{
+	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
+
+	if (priv->show_searching == FALSE) {
+		/* Just making sure */
+		bling_spinner_stop (BLING_SPINNER (priv->spinner));
+		return;
+	}
+	if (state == FALSE) {
+		bling_spinner_stop (BLING_SPINNER (priv->spinner));
+		gtk_widget_hide (priv->spinner);
+		gtk_label_set_text (GTK_LABEL (priv->search_label), _("No adapters available"));
+	} else {
+		gtk_widget_show (priv->spinner);
+		bling_spinner_start (BLING_SPINNER (priv->spinner));
+		gtk_label_set_text (GTK_LABEL (priv->search_label), _("Searching for devices..."));
+	}
+}
+
 /**
  * bluetooth_chooser_start_discovery:
  * @self: a #BluetoothChooser widget
@@ -170,19 +192,35 @@ alias_to_label (GtkTreeViewColumn *column, GtkCellRenderer *cell,
  * only work if the Search button is visible, as otherwise the user has no
  * visual feedback that the process is on-going.
  *
- * See also: #BluetoothChooser:show-search
+ * See also: #BluetoothChooser:show-searching
  */
 void
 bluetooth_chooser_start_discovery (BluetoothChooser *self)
 {
 	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
 
-	g_return_if_fail (priv->show_search);
+	g_return_if_fail (priv->show_searching);
 
 	if (bluetooth_client_start_discovery (priv->client) != FALSE)
-		gtk_widget_set_sensitive (GTK_WIDGET(priv->search_button), FALSE);
-	else
-		priv->disco_rq = TRUE;
+		set_search_label (self, TRUE);
+	priv->disco_rq = TRUE;
+}
+
+/**
+ * bluetooth_chooser_stop_discovery:
+ * @self: a #BluetoothChooser widget
+ *
+ * Stops a discovery started with #bluetooth_chooser_start_discovery.
+ */
+void
+bluetooth_chooser_stop_discovery (BluetoothChooser *self)
+{
+	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
+
+	g_return_if_fail (priv->show_searching);
+
+	priv->disco_rq = FALSE;
+	bluetooth_client_stop_discovery (priv->client);
 }
 
 static char *
@@ -363,14 +401,6 @@ device_model_row_changed (GtkTreeModel *model,
 }
 
 static void
-search_button_clicked (GtkButton *button, gpointer user_data)
-{
-	BluetoothChooser *self = BLUETOOTH_CHOOSER(user_data);
-
-	bluetooth_chooser_start_discovery (self);
-}
-
-static void
 select_browse_device_callback (GtkTreeSelection *selection, gpointer user_data)
 {
 	BluetoothChooser *self = user_data;
@@ -560,8 +590,13 @@ adapter_model_row_changed (GtkTreeModel *model,
 
 	if (is_default == FALSE)
 		return;
-	gtk_widget_set_sensitive (GTK_WIDGET(priv->search_button), !discovering && powered);
+	if (powered != FALSE && discovering == FALSE && priv->disco_rq != FALSE) {
+		bluetooth_chooser_start_discovery (self);
+		set_search_label (self, TRUE);
+		return;
+	}
 	gtk_widget_set_sensitive (GTK_WIDGET (priv->treeview), powered);
+	set_search_label (self, discovering);
 }
 
 static void default_adapter_changed (GObject    *gobject,
@@ -576,7 +611,7 @@ static void default_adapter_changed (GObject    *gobject,
 
 	if (adapter == NULL) {
 		gtk_widget_set_sensitive (GTK_WIDGET (priv->treeview), FALSE);
-		gtk_widget_set_sensitive (GTK_WIDGET(priv->search_button), FALSE);
+		set_search_label (self, FALSE);
 		gtk_tree_view_set_model (GTK_TREE_VIEW(priv->treeview), NULL);
 	}
 
@@ -600,14 +635,11 @@ static void default_adapter_changed (GObject    *gobject,
 				  G_CALLBACK (device_model_row_changed), self);
 		g_object_unref (priv->filter);
 		gtk_widget_set_sensitive (GTK_WIDGET (priv->treeview), TRUE);
-		gtk_widget_set_sensitive (GTK_WIDGET(priv->search_button), TRUE);
 
 		/* Start a disovery if it was requested before we
 		 * had an adapter available */
-		if (priv->disco_rq != FALSE) {
+		if (priv->disco_rq != FALSE)
 			bluetooth_chooser_start_discovery (self);
-			priv->disco_rq = FALSE;
-		}
 	}
 }
 
@@ -697,7 +729,7 @@ create_treeview (BluetoothChooser *self)
 		g_object_unref (priv->filter);
 	} else {
 		gtk_widget_set_sensitive (GTK_WIDGET (tree), FALSE);
-		gtk_widget_set_sensitive (GTK_WIDGET (priv->search_button), FALSE);
+		set_search_label (self, FALSE);
 	}
 
 	gtk_container_add (GTK_CONTAINER(scrolled), tree);
@@ -724,7 +756,7 @@ bluetooth_chooser_init(BluetoothChooser *self)
 	gtk_widget_push_composite_child ();
 
 	priv->show_paired = FALSE;
-	priv->show_search = FALSE;
+	priv->show_searching = FALSE;
 
 	priv->client = bluetooth_client_new ();
 
@@ -762,15 +794,19 @@ bluetooth_chooser_init(BluetoothChooser *self)
 	g_signal_connect (priv->adapter_model, "row-changed",
 			  G_CALLBACK (adapter_model_row_changed), self);
 
-	/* The search button */
-	priv->search_button = gtk_button_new_with_mnemonic (_("S_earch"));
-	gtk_widget_set_no_show_all (priv->search_button, TRUE);
-	gtk_box_pack_end (GTK_BOX (hbox), priv->search_button, FALSE, TRUE, 0);
-	g_signal_connect (G_OBJECT(priv->search_button), "clicked",
-			  G_CALLBACK(search_button_clicked), self);
-	gtk_widget_set_tooltip_text (priv->search_button, _("Search for Bluetooth devices"));
-	if (priv->show_search)
-		gtk_widget_show (priv->search_button);
+	/* The searching label */
+	priv->search_hbox = gtk_hbox_new (FALSE, 2);
+	gtk_widget_set_no_show_all (priv->search_hbox, TRUE);
+	priv->spinner = bling_spinner_new ();
+	gtk_container_add (GTK_CONTAINER (priv->search_hbox), priv->spinner);
+	gtk_widget_show (priv->spinner);
+	priv->search_label = gtk_label_new (_("Searching for devices..."));
+	gtk_container_add (GTK_CONTAINER (priv->search_hbox), priv->search_label);
+	gtk_widget_show (priv->search_label);
+
+	gtk_box_pack_end (GTK_BOX (hbox), priv->search_hbox, FALSE, TRUE, 0);
+	if (priv->show_searching)
+		gtk_widget_show (priv->search_hbox);
 	//FIXME check whether the default adapter is discovering right now
 
 	/* The treeview */
@@ -934,7 +970,7 @@ enum {
 	PROP_DEVICE_SELECTED,
 	PROP_SHOW_PAIRING,
 	PROP_SHOW_CONNECTED,
-	PROP_SHOW_SEARCH,
+	PROP_SHOW_SEARCHING,
 	PROP_SHOW_DEVICE_TYPE,
 	PROP_SHOW_DEVICE_CATEGORY,
 	PROP_DEVICE_TYPE_FILTER,
@@ -961,9 +997,9 @@ bluetooth_chooser_set_property (GObject *object, guint prop_id,
 		if (priv->connected_cell != NULL)
 			g_object_set (G_OBJECT (priv->connected_cell), "visible", priv->show_connected, NULL);
 		break;
-	case PROP_SHOW_SEARCH:
-		priv->show_search = g_value_get_boolean (value);
-		g_object_set (G_OBJECT (priv->search_button), "visible", priv->show_search, NULL);
+	case PROP_SHOW_SEARCHING:
+		priv->show_searching = g_value_get_boolean (value);
+		g_object_set (G_OBJECT (priv->search_hbox), "visible", priv->show_searching, NULL);
 		break;
 	case PROP_SHOW_DEVICE_TYPE:
 		priv->show_device_type = g_value_get_boolean (value);
@@ -1014,8 +1050,8 @@ bluetooth_chooser_get_property (GObject *object, guint prop_id,
 	case PROP_SHOW_CONNECTED:
 		g_value_set_boolean (value, priv->show_connected);
 		break;
-	case PROP_SHOW_SEARCH:
-		g_value_set_boolean (value, priv->show_search);
+	case PROP_SHOW_SEARCHING:
+		g_value_set_boolean (value, priv->show_searching);
 		break;
 	case PROP_SHOW_DEVICE_TYPE:
 		g_value_set_boolean (value, priv->show_device_type);
@@ -1101,13 +1137,13 @@ bluetooth_chooser_class_init (BluetoothChooserClass *klass)
 					 PROP_SHOW_CONNECTED, g_param_spec_boolean ("show-connected",
 										    NULL, NULL, FALSE, G_PARAM_READWRITE));
 	/**
-	 * BluetoothChooser:show-search:
+	 * BluetoothChooser:show-searchinging:
 	 *
-	 * Whether to show the Search button, this is necessary if you want to programmatically
+	 * Whether to show the Searching label , this is necessary if you want to programmatically
 	 * start a discovery, using bluetooth_chooser_start_discovery()
 	 **/
 	g_object_class_install_property (G_OBJECT_CLASS(klass),
-					 PROP_SHOW_SEARCH, g_param_spec_boolean ("show-search",
+					 PROP_SHOW_SEARCHING, g_param_spec_boolean ("show-searching",
 										 NULL, NULL, FALSE, G_PARAM_READWRITE));
 	/**
 	 * BluetoothChooser:show-device-type:
diff --git a/lib/bluetooth-chooser.h b/lib/bluetooth-chooser.h
index df11447..e9efff0 100644
--- a/lib/bluetooth-chooser.h
+++ b/lib/bluetooth-chooser.h
@@ -71,6 +71,7 @@ BluetoothType bluetooth_chooser_get_selected_device_type (BluetoothChooser *self
 gboolean bluetooth_chooser_get_selected_device_is_connected (BluetoothChooser *self);
 
 void bluetooth_chooser_start_discovery (BluetoothChooser *self);
+void bluetooth_chooser_stop_discovery (BluetoothChooser *self);
 
 G_END_DECLS
 
diff --git a/lib/test-deviceselection.c b/lib/test-deviceselection.c
index fd67ebb..c1159a7 100644
--- a/lib/test-deviceselection.c
+++ b/lib/test-deviceselection.c
@@ -101,7 +101,7 @@ static void
 chooser_created (BluetoothChooserButton *button, BluetoothChooser *chooser, gpointer data)
 {
 	g_object_set(chooser,
-		     "show-search", FALSE,
+		     "show-searching", FALSE,
 		     "show-pairing", FALSE,
 		     "show-device-type", FALSE,
 		     "device-type-filter", BLUETOOTH_TYPE_PHONE,
@@ -196,7 +196,7 @@ create_wizard_dialogue (void)
 	gtk_container_set_border_width(GTK_CONTAINER(selector), 5);
 	gtk_widget_show(selector);
 	g_object_set(selector,
-		     "show-search", TRUE,
+		     "show-searching", TRUE,
 		     "show-device-type", TRUE,
 		     "show-device-category", FALSE,
 		     "device-category-filter", BLUETOOTH_CATEGORY_NOT_PAIRED_OR_TRUSTED,
@@ -230,7 +230,7 @@ create_props_dialogue (void)
 	gtk_container_set_border_width(GTK_CONTAINER(selector), 5);
 	gtk_widget_show(selector);
 	g_object_set(selector,
-		     "show-search", FALSE,
+		     "show-searching", FALSE,
 		     "show-device-type", FALSE,
 		     "show-device-category", FALSE,
 		     "show-pairing", TRUE,



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