>>From a20df6227a9533e895b2ded9e77c7c93fe1d7ae3 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@snoogens.fab.redhat.com>
Date: Sat, 23 Jun 2007 03:24:05 +0100
Subject: [PATCH] Add "Browse device..." menu entry
* Add a "Browse device..." menu entry
* Make menu entry unsensitive if obexftp isn't available in nautilus,
  or there's no active bluetooth device
* Move checking for an unknown formfactor to the HAL conversation function,
  not the actual setup
---
 applet/Makefile.am |    2 +-
 applet/main.c      |   71 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/applet/Makefile.am b/applet/Makefile.am
index 8eb0346..db34902 100644
--- a/applet/Makefile.am
+++ b/applet/Makefile.am
@@ -9,7 +9,7 @@ bluetooth_applet_LDADD = $(top_builddir)/compat/libcompat.a \
 nodist_bluetooth_applet_SOURCES = $(top_builddir)/common/passkey-agent-glue.h \
 					$(top_builddir)/common/auth-agent-glue.h
 
-AM_CFLAGS = @DBUS_CFLAGS@ @HAL_CFLAGS@ @GTK_CFLAGS@ @GCONF_CFLAGS@ @NOTIFY_CFLAGS@
+AM_CFLAGS = @DBUS_CFLAGS@ @HAL_CFLAGS@ @GTK_CFLAGS@ @GCONF_CFLAGS@ @NOTIFY_CFLAGS@ -DSYSCONFDIR=\"$(sysconfdir)\"
 
 INCLUDES = -I$(top_builddir)/common -I$(top_srcdir)/compat
 
diff --git a/applet/main.c b/applet/main.c
index 8131308..15e11e6 100644
--- a/applet/main.c
+++ b/applet/main.c
@@ -1230,8 +1230,15 @@ static char *get_form_factor(void)
 	libhal_ctx_shutdown(ctx, NULL);
 	libhal_ctx_free(ctx);
 
+	if (strcmp(formfactor, "laptop") && strcmp(formfactor, "desktop")) {
+		/* We don't know anything else */
+		g_free(formfactor);
+		formfactor = g_strdup("uncategorized");
+	}
+
 	return formfactor;
 }
+
 static void adapter_setup(gpointer data, gpointer user_data)
 {
 	struct adapter_data *adapter = data;
@@ -1241,11 +1248,6 @@ static void adapter_setup(gpointer data, gpointer user_data)
 	if (formfactor == NULL)
 		return;
 
-	if (strcmp(formfactor, "laptop") && strcmp(formfactor, "desktop")) {
-		/* We don't know anything else */
-		formfactor = g_strdup("uncategorized");
-	}
-
 	object = dbus_g_proxy_new_for_name(conn, "org.bluez",
 					adapter->path, "org.bluez.Adapter");
 	if (!object)
@@ -1398,6 +1400,49 @@ static void name_owner_changed(DBusGProxy *object, const char *name,
 	}
 }
 
+static gboolean obexftp_available(void)
+{
+	char *path;
+	gboolean retval = FALSE;
+
+	/* Look for nautilus in the PATH */
+	path = g_find_program_in_path("nautilus");
+	if (path == NULL)
+		return FALSE;
+	g_free(path);
+
+	/* Look for obex-module.conf in the system-wide dir
+	 * FIXME: should use modulesdir from gnome-vfs
+	 * http://bugzilla.gnome.org/show_bug.cgi?id=447202 */
+	path = g_build_filename(SYSCONFDIR, "gnome-vfs-2.0/modules", "obex-module.conf", NULL);
+	retval = g_file_test(path, G_FILE_TEST_IS_REGULAR);
+	g_free(path);
+	if (retval != FALSE)
+		return TRUE;
+
+	/* Look in the home dir */
+	if (g_get_home_dir() != NULL) {
+		path = g_build_filename(g_get_home_dir(), ".gnome2", "vfs",
+					 "modules", "obex-module.conf", NULL);
+		retval = g_file_test(path, G_FILE_TEST_IS_REGULAR);
+		g_free(path);
+		if (retval != FALSE)
+			return TRUE;
+	}
+
+	/* Look in the envvar defined dir */
+	if (g_getenv("GNOME_VFS_MODULE_CONFIG_PATH") != NULL) {
+		path = g_build_filename(g_getenv("GNOME_VFS_MODULE_CONFIG_PATH"),
+					"obex-module.conf", NULL);
+		retval = g_file_test(path, G_FILE_TEST_IS_REGULAR);
+		g_free(path);
+		if (retval != FALSE)
+			return TRUE;
+	}
+
+	return FALSE;
+}
+
 static int setup_dbus(void)
 {
 	DBusGProxy *object;
@@ -1494,6 +1539,10 @@ static void wizard_callback(GObject *widget, gpointer user_data)
 }
 #endif
 
+static void browse_device_callback(GObject *widget, gpointer user_data)
+{
+}
+
 static void activate_callback(GObject *widget, gpointer user_data)
 {
 	close_notification();
@@ -1523,6 +1572,18 @@ static void popup_callback(GObject *widget, guint button,
 	gtk_widget_show(item);
 	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
+	item = gtk_separator_menu_item_new();
+	gtk_widget_show(item);
+	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+
+	item = gtk_image_menu_item_new_with_label(_("Browse Device..."));
+	g_signal_connect(item, "activate",
+			 G_CALLBACK(browse_device_callback), NULL);
+	gtk_widget_show(item);
+	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+
+	gtk_widget_set_sensitive (item, obexftp_available() && attached_adapters() > 0);
+
 #if 0
 	item = gtk_separator_menu_item_new();
 	gtk_widget_show(item);
-- 
1.5.2.2

