[gnome-user-share] Hide the share bar when Bluetooth is disabled



commit afd610280975688f2b9ed9a53897efdeaaf055db
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Apr 14 17:32:56 2010 +0100

    Hide the share bar when Bluetooth is disabled
    
    So we don't tell the user they can share via Bluetooth when
    they don't have a Bluetooth adapter.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=613584

 configure.in          |    2 +-
 src/share-extension.c |   32 +++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/configure.in b/configure.in
index 68dc226..dc7c192 100644
--- a/configure.in
+++ b/configure.in
@@ -134,7 +134,7 @@ AC_ARG_WITH(nautilusdir,
 	    [ac_with_nautilusdir=""])
 
 PKG_CHECK_MODULES(EXTENSION,
-		   libnautilus-extension >= 2.91.7)
+		   libnautilus-extension >= 2.91.7 gnome-bluetooth-1.0)
 if test "${ac_with_nautilusdir}" = ""; then
 	ac_with_nautilusdir=`pkg-config --variable=extensiondir libnautilus-extension`
 fi
diff --git a/src/share-extension.c b/src/share-extension.c
index db50017..a361c68 100644
--- a/src/share-extension.c
+++ b/src/share-extension.c
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
+#include <bluetooth-client.h>
 #include <libnautilus-extension/nautilus-menu-provider.h>
 #include <libnautilus-extension/nautilus-location-widget-provider.h>
 
@@ -100,6 +101,27 @@ bar_response_cb (NautilusShareBar *bar,
         }
 }
 
+static void
+downloads_bar_set_from_bluetooth_status (GtkWidget *bar)
+{
+	BluetoothClient *client;
+	gboolean bt_powered;
+
+	client = g_object_get_data (G_OBJECT (bar), "bluetooth-client");
+	g_object_get (G_OBJECT (client),
+		      "default-adapter-powered", &bt_powered,
+		      NULL);
+	gtk_widget_set_visible (bar, bt_powered);
+}
+
+static void
+default_adapter_powered_cb (GObject    *gobject,
+			    GParamSpec *pspec,
+			    GtkWidget  *bar)
+{
+	downloads_bar_set_from_bluetooth_status (bar);
+}
+
 static GtkWidget *
 nautilus_user_share_get_location_widget (NautilusLocationWidgetProvider *iface,
                                          const char                     *uri,
@@ -143,14 +165,22 @@ nautilus_user_share_get_location_widget (NautilusLocationWidgetProvider *iface,
 	} else if (is_dir[0] != FALSE) {
 		bar = nautilus_share_bar_new (_("May be shared over the network or Bluetooth"));
 	} else {
+		BluetoothClient *client;
+
 		bar = nautilus_share_bar_new (_("May be used to receive files over Bluetooth"));
+		gtk_widget_set_no_show_all (bar, TRUE);
+		client = bluetooth_client_new ();
+		g_object_set_data_full (G_OBJECT (bar), "bluetooth-client", client, g_object_unref);
+		g_signal_connect (G_OBJECT (client), "notify::default-adapter-powered",
+				  G_CALLBACK (default_adapter_powered_cb), bar);
+		downloads_bar_set_from_bluetooth_status (bar);
 	}
 
 	g_signal_connect (bar, "response",
 			  G_CALLBACK (bar_response_cb),
 			  window);
 
-	gtk_widget_show (bar);
+	gtk_widget_show_all (bar);
 
 	g_object_unref (file);
 



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