[Utopia] [patch] add support for digital cameras
- From: David Zeuthen <david fubar dk>
- To: rml ximian com
- Cc: utopia-list gnome org
- Subject: [Utopia] [patch] add support for digital cameras
- Date: Thu, 26 Aug 2004 03:55:15 +0200
Hey Robert,
Here's a patch to g-v-m that a) adds support for passing the HAL UDI to
the invoked program using %h; and b) do camera/photo stuff when a hal
device object got the capability camera. We also bail out if the program
line in g-v-m requires a parameter that is not available which is kind
of reasonable I think
Specifically, with the new hal callout I just added that
reads /etc/hotplug/usb.usermap all gphoto2 supported cameras get this
capability in hal. Coupled with this patch and a simple wrapper like
this using 'gvm-gthumb-wrapper %h' in g-v-m for cameras/photos
#!/bin/sh
MOUNT_POINT=`hal-get-property --udi $1 --key block.device`
if test "$MOUNT_POINT" == ""; then
gthumb --import-photos
else
gthumb $MOUNT_POINT
fi
then g-v-m does the right thing for both card readers, USB Mass Storage
based cameras and gphoto2 supported cameras. Please apply.
Thanks,
David
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-volume-manager/ChangeLog,v
retrieving revision 1.90
diff -u -p -r1.90 ChangeLog
--- ChangeLog 25 Aug 2004 08:37:57 -0000 1.90
+++ ChangeLog 26 Aug 2004 01:45:55 -0000
@@ -1,3 +1,18 @@
+2004-08-26 David Zeuthen <david fubar dk>
+
+ * src/manager.c:
+ (gvm_run_command): Accept UDI; bail out if required parameter in
+ command is NULL
+ (gvm_check_dvd): Accept and pass UDI
+ (gvm_check_photos): Pass UDI
+ (gvm_check_camera): New function; check if UDI got capability camera
+ (gvm_device_autorun): Pass UDI
+ (gvm_run_cdplayer): Accept and pass UDI
+ (gvm_ask_mixed): Accept and pass UDI
+ (gvm_run_cdburner): Accept and pass UDI
+ (gvm_cdrom_policy): Pass UDI
+ (hal_device_added): Also do gvm_check_camera
+
2004-08-25 Maxim Dziumanenko <mvd mylinux com ua>
* configure.in: Add "uk" (Ukrainian) to ALL_LINGUAS.
Index: src/manager.c
===================================================================
RCS file: /cvs/gnome/gnome-volume-manager/src/manager.c,v
retrieving revision 1.29
diff -u -p -r1.29 manager.c
--- src/manager.c 17 Aug 2004 15:29:18 -0000 1.29
+++ src/manager.c 26 Aug 2004 01:45:56 -0000
@@ -38,7 +38,7 @@
# define N_(String) (String)
#endif
-//#define GVM_DEBUG
+/*#define GVM_DEBUG*/
#ifdef GVM_DEBUG
# define dbg(fmt,arg...) fprintf(stderr, "%s/%d: " fmt,__FILE__,__LINE__,##arg)
#else
@@ -144,11 +144,13 @@ gvm_init_config (void)
}
/*
- * gvm_run_command - run the given command, replacing %d with the device node
- * and %m with the given path
+ * gvm_run_command - run the given command, replacing %d with the device node,
+ * %h with the HAL UDI and %m with the given path. Bails out if the command
+ * requires a given %d,%h or %m and this is NULL.
*/
static void
-gvm_run_command (const char *device, const char *command, const char *path)
+gvm_run_command (const char *device, const char *command,
+ const char *path, const char *udi)
{
char *argv[4];
gchar *new_command;
@@ -156,23 +158,37 @@ gvm_run_command (const char *device, con
GString *exec = g_string_new (NULL);
char *p, *q;
- /* perform s/%d/device/ and s/%m/path/ */
+ /* perform s/%d/device/, s/%m/path/ and s/%h/udi/ */
new_command = g_strdup (command);
q = new_command;
p = new_command;
while ((p = strchr (p, '%')) != NULL) {
if (*(p + 1) == 'd') {
+ if (device == NULL)
+ goto error;
*p = '\0';
g_string_append (exec, q);
g_string_append (exec, device);
q = p + 2;
p = p + 2;
} else if (*(p + 1) == 'm') {
+ if (path == NULL)
+ goto error;
*p = '\0';
g_string_append (exec, q);
g_string_append (exec, path);
q = p + 2;
p = p + 2;
+ } else if (*(p + 1) == 'h') {
+ if (udi == NULL)
+ goto error;
+ *p = '\0';
+ g_string_append (exec, q);
+ g_string_append (exec, "\"");
+ g_string_append (exec, udi);
+ g_string_append (exec, "\"");
+ q = p + 2;
+ p = p + 2;
}
}
g_string_append (exec, q);
@@ -189,6 +205,13 @@ gvm_run_command (const char *device, con
g_string_free (exec, TRUE);
g_free (new_command);
+ return;
+
+error:
+ warn ("command '%s' required unavailable parameter; "
+ "%%d='%s' %%m='%s' %%h='%s'\n", command, device, path, udi);
+ g_string_free (exec, TRUE);
+ g_free (new_command);
}
/*
@@ -228,7 +251,7 @@ gvm_ask_autorun (const char *path)
* Returns TRUE if this was a Video DVD and FALSE otherwise.
*/
static gboolean
-gvm_check_dvd (const char *device, const char *mount_point)
+gvm_check_dvd (const char *device, const char *mount_point, const char *udi)
{
char *path;
gboolean retval;
@@ -247,7 +270,7 @@ gvm_check_dvd (const char *device, const
if (retval && config.autoplay_dvd)
gvm_run_command (device, config.autoplay_dvd_command,
- mount_point);
+ mount_point, udi);
return retval;
}
@@ -299,7 +322,7 @@ gvm_check_photos (const char *udi, const
if (action == IMPORT)
gvm_run_command (device, config.autophoto_command,
- dcim_path);
+ dcim_path, udi);
}
out:
@@ -307,6 +330,48 @@ out:
return retval;
}
+
+/*
+ * gvm_check_camera - check if this device is a digital camera. If it is, then
+ * ask the user if he wants to import the photos.
+ *
+ * Returns TRUE if this was a camera, FALSE otherwise
+ *
+ */
+static gboolean
+gvm_check_camera (const char *udi)
+{
+ enum { IMPORT } action = -1;
+ GtkWidget *askme;
+ int retval = FALSE;
+
+ /* see if it's a camera */
+ if (!hal_device_query_capability(hal_ctx, udi, "camera"))
+ goto out;
+
+ retval = TRUE;
+ dbg ("Camera detected: %s\n", udi);
+
+ if (config.autophoto) {
+ askme = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ _(ASK_PHOTOS_MSG));
+ gtk_dialog_add_buttons (GTK_DIALOG (askme),
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL, _("_Import"),
+ IMPORT, NULL);
+ action = gtk_dialog_run (GTK_DIALOG (askme));
+ gtk_widget_destroy (askme);
+
+ if (action == IMPORT)
+ gvm_run_command (NULL, config.autophoto_command,
+ NULL, udi);
+ }
+
+out:
+ return retval;
+}
+
/*
* gvm_device_autorun - automatically execute stuff on the given UDI
*
@@ -331,7 +396,7 @@ gvm_device_autorun (const char *udi)
goto out;
}
- if (gvm_check_dvd (device, mount_point))
+ if (gvm_check_dvd (device, mount_point, udi))
goto out;
if (gvm_check_photos (udi, device, mount_point))
@@ -376,7 +441,7 @@ gvm_device_autorun (const char *udi)
}
if ((config.autobrowse == TRUE) && (autorun_succeeded == FALSE)) {
- gvm_run_command (device, NAUTILUS_COMMAND, mount_point);
+ gvm_run_command (device, NAUTILUS_COMMAND, mount_point, udi);
}
out:
@@ -445,11 +510,11 @@ gvm_device_unmount (char *device)
* the given device node
*/
static void
-gvm_run_cdplayer (const char *device, const char *mount_point)
+gvm_run_cdplayer (const char *device, const char *mount_point, const char *udi)
{
if (config.autoplay_cda)
gvm_run_command (device, config.autoplay_cda_command,
- mount_point);
+ mount_point, udi);
}
#define ASK_MIXED_MSG "This CD has both audio tracks and data files.\n" \
@@ -497,7 +562,7 @@ gvm_ask_mixed (const char *udi)
gvm_device_mount (device);
break;
case PLAY:
- gvm_run_cdplayer (device, device);
+ gvm_run_cdplayer (device, device, udi);
break;
default:
break;
@@ -513,10 +578,10 @@ out:
* given device node, if so configured
*/
static void
-gvm_run_cdburner (const char *device, const char *mount)
+gvm_run_cdburner (const char *device, const char *mount, const char *udi)
{
if (config.autoburn_cdr)
- gvm_run_command (device, config.autoburn_cdr_command, mount);
+ gvm_run_command (device, config.autoburn_cdr_command, mount, udi);
}
/*
@@ -565,7 +630,7 @@ gvm_cdrom_policy (const char *udi)
}
if (has_audio && (!has_data)) {
- gvm_run_cdplayer (device, device);
+ gvm_run_cdplayer (device, device, udi);
} else if (has_audio && has_data) {
gvm_ask_mixed (udi);
} else if (has_data) {
@@ -573,7 +638,7 @@ gvm_cdrom_policy (const char *udi)
gvm_device_mount (device);
} else if (is_blank) {
if (gvm_device_is_writer (drive_udi))
- gvm_run_cdburner (device, device);
+ gvm_run_cdburner (device, device, udi);
}
/** @todo enforce policy for all the new disc types now supported */
@@ -630,6 +695,8 @@ hal_device_added (LibHalContext *ctx __a
dbg ("New Device: %s\n", udi);
+ gvm_check_camera (udi);
+
if (!hal_device_query_capability(hal_ctx, udi, "block"))
goto out;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]