Re: VFS Questions
- From: Yaron Tausky <decaycell gmail com>
- To: Wouter Bolsterlee <uws+gnome xs4all nl>
- Cc: synce-devel lists sourceforge net, desktop-devel-list gnome org
- Subject: Re: VFS Questions
- Date: Sun, 07 Aug 2005 09:46:52 +0300
On Sun, 2005-08-07 at 00:28 +0200, Wouter Bolsterlee wrote:
> P�un, Aug 07, 2005 at 01:49:28AM +0300, Yaron Tausky skrev:
> > 2. HAL recognizes the device upon plugging/unplugging, is the a GNOME
> > mechanism that will allow me to run custom code when the device is
> > plugged in (in order to mount it, of course)? I assume it's around the
> > same code that's used for auto-mounting volumes or creating new drives
> > when they're plugged in. I'd appreciate some pointers here.
>
> Have a look at gnome-volume-manager, which manages the mounting and
> umounting of device upon HAL events.
Thanks, I did that and came up with a patch. However... since the VFS
isn't designed with tons extensibility in mind (well, that's an
overstatement, don't get mad :-), the patch should be applied to g-v-m
rather than SynCE, as it's the only way to do it other than creating a
new process and listening to HAL.
There are a few issues with this patch, and I don't really expect to see
it integrated as it's more like an experiment for me, so I'd be glad to
hear comments:
1. For the life of me, I couldn't find a decent way to determine whether
a device is a PDA or not. First I tried using the sysfs entry and see
which driver it uses, but that didn't quite work (I guess that's because
sysfs isn't a normal FS...). Eventually I took the usb_device.product
property and checked if it ends with "Pocket PC" -- because it matched
the device I have... Is there a way to alter the data HAL gives for a
certain device, like add a pda.type property, for example? And where has
the change to be made?
2. If, by some sheer force of luck, every wince device matches my little
test -- it's not going to work with Palms. I don't have one, so
obviously I can't work on that, but perhaps I can refine the
infrastructure for it?
3. I set the icon to "gnome-dev-pda", which doesn't exist. And since we
even have an iPod icon... :-)
Waiting for comments,
--
Yaron Tausky <decaycell gmail com>
diff -ur gnome-volume-manager-1.2.1.original/src/manager.c gnome-volume-manager-1.2.1.synce/src/manager.c
--- gnome-volume-manager-1.2.1.original/src/manager.c 2005-03-30 23:20:25.000000000 +0200
+++ gnome-volume-manager-1.2.1.synce/src/manager.c 2005-08-07 09:21:42.000000000 +0300
@@ -22,6 +22,11 @@
#include <dbus/dbus-glib.h>
#include <libhal.h>
#include <signal.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <libgnomevfs/gnome-vfs-volume.h>
+#include <libgnomevfs/gnome-vfs-volume-monitor.h>
#include "gvm.h"
@@ -58,6 +63,9 @@
/** List of UDI's of all volumes mounted during the lifetime of the program */
static GSList *all_mounted_volumes = NULL;
+/** UDI of a connected ipaq */
+static GString *ipaq_udi = NULL;
+
/*
* gvm_load_config - synchronize gconf => config structure
*/
@@ -386,6 +394,56 @@
}
/*
+ * gvm_check_ipaq - check if this device is a wince handheld.
+ * Returns TRUE if this was an ipaq, FALSE otherwise
+ */
+static gboolean
+gvm_check_ipaq (const char *udi)
+{
+ char *product = NULL;
+ int retval = FALSE;
+
+ product = hal_device_get_property_string (hal_ctx, udi, "usb_device.product");
+ if (product) {
+ if (g_str_has_suffix (product, "Pocket PC")) {
+ ipaq_udi = g_string_assign (ipaq_udi, udi);
+ retval = TRUE;
+ }
+ hal_free_string (product);
+ }
+ return retval;
+}
+
+/*
+ * gvm_find_ipaq - locates a mounted ipaq device. */
+static GnomeVFSVolume *
+gvm_find_ipaq (void)
+{
+ GnomeVFSVolumeMonitor *monitor;
+ GnomeVFSVolume *volume;
+ GList *volumes, *l;
+
+ monitor = gnome_vfs_get_volume_monitor ();
+ volumes = gnome_vfs_volume_monitor_get_mounted_volumes (monitor);
+ for (l = volumes; l != NULL; l = l->next) {
+ volume = l->data;
+ if (!strcmp(gnome_vfs_volume_get_display_name(volume), N_("Mobile Device"))) {
+ return volume;
+ }
+ }
+ return NULL;
+}
+
+/*
+ * gvm_unmount_empty_cb - used for unmounting gnome-vfs volumes, when no
+ * special actions are required. */
+static void
+gvm_unmount_empty_cb (gboolean succeeded, char *error, char *detailed_error, gpointer data)
+{
+ /* do nothing */
+}
+
+/*
* gvm_device_autorun - automatically execute stuff on the given UDI
*
* we currently autorun: autorun files, video DVD's, and digital photos
@@ -733,6 +791,11 @@
dbg ("New Device: %s\n", udi);
gvm_check_camera (udi);
+
+ /* add a desktop icon for wince devices */
+ if (gvm_check_ipaq (udi)) {
+ gnome_vfs_connect_to_server("synce://", N_("Mobile Device"), "gnome-dev-pda");
+ }
if (!hal_device_query_capability(hal_ctx, udi, "block"))
goto out;
@@ -793,6 +856,17 @@
hal_device_removed (LibHalContext *ctx __attribute__((__unused__)),
const char *udi)
{
+ GnomeVFSVolume *volume;
+
+ /* if the unmounted device was an ipaq, do necessary stuff to unmount */
+ if (!strcmp(ipaq_udi->str, udi)) {
+ volume = gvm_find_ipaq ();
+ if (volume) {
+ gnome_vfs_volume_unmount(volume, gvm_unmount_empty_cb, NULL);
+ }
+ g_string_assign (ipaq_udi, "");
+ }
+
dbg ("Device removed: %s\n", udi);
}
@@ -1039,6 +1113,8 @@
warn ("no device_file for udi=%s\n", udi);
}
}
+
+ g_string_free (ipaq_udi, TRUE);
}
@@ -1143,6 +1219,8 @@
g_io_add_watch (sigterm_iochn, G_IO_IN, sigterm_iochn_data, NULL);
signal (SIGTERM, handle_sigterm);
+ ipaq_udi = g_string_new ("");
+
mount_all (hal_ctx);
gtk_main ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]