[Xfce4-commits] <thunar-volman:jannis/port-to-udev> Implement photo import from cameras detected as mass storage devices.
Jannis Pohlmann
noreply at xfce.org
Sun Jul 25 19:44:13 CEST 2010
Updating branch refs/heads/jannis/port-to-udev
to a75667cca11293e4f6582ac219f32b92cfbb9462 (commit)
from d7fb1ad549e9b090b03ccfde1df46771c4b7863c (commit)
commit a75667cca11293e4f6582ac219f32b92cfbb9462
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Tue Jul 20 13:55:54 2010 +0200
Implement photo import from cameras detected as mass storage devices.
thunar-volman/tvm-block-device.c | 77 +++++++++++++++++++++++++++++++++++--
1 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/thunar-volman/tvm-block-device.c b/thunar-volman/tvm-block-device.c
index 81cffb2..dfe570b 100644
--- a/thunar-volman/tvm-block-device.c
+++ b/thunar-volman/tvm-block-device.c
@@ -53,6 +53,9 @@ typedef gboolean (*TvmBlockDeviceHandler) (TvmContext *context,
static gboolean tvm_file_test (GMount *mount,
const gchar *filename,
GFileTest test);
+static gboolean tvm_block_device_autophoto (TvmContext *context,
+ GMount *mount,
+ GError **error);
static gboolean tvm_block_device_autorun (TvmContext *context,
GMount *mount,
GError **error);
@@ -66,8 +69,8 @@ static TvmBlockDeviceHandler block_device_handlers[] =
{
#if 0
tvm_block_device_autoipod,
- tvm_block_device_autophoto,
#endif
+ tvm_block_device_autophoto,
tvm_block_device_autorun,
tvm_block_device_autobrowse,
};
@@ -126,6 +129,61 @@ tvm_file_test (GMount *mount,
static gboolean
+tvm_block_device_autophoto (TvmContext *context,
+ GMount *mount,
+ GError **error)
+{
+ gboolean autophoto;
+ gboolean result = FALSE;
+ gchar *autophoto_command;
+ gint response;
+
+ g_return_val_if_fail (context != NULL, FALSE);
+ g_return_val_if_fail (G_IS_MOUNT (mount), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ /* check if autophoto support is enabled */
+ autophoto = xfconf_channel_get_bool (context->channel, "/autophoto/enabled", FALSE);
+ if (autophoto)
+ {
+ autophoto_command = xfconf_channel_get_string (context->channel,
+ "/autophoto/command", NULL);
+ if (autophoto_command != NULL && *autophoto_command != '\0')
+ {
+ /* check if we have any photos on the volume */
+ if (tvm_file_test (mount, "dcim", G_FILE_TEST_IS_DIR))
+ {
+ /* ask the user to import photos */
+ response = tvm_prompt (context, "camera-photo", _("Photo Import"),
+ _("A photo card has been detected"),
+ _("There are photos on the card. Would you like to "
+ "add these photos to your album?"),
+ _("Ig_nore"), GTK_RESPONSE_CANCEL,
+ _("Import _Photos"), TVM_RESPONSE_PHOTOS,
+ NULL);
+
+ if (response == TVM_RESPONSE_PHOTOS)
+ {
+ /* run the preferred photo application */
+ result = tvm_run_command (context, mount, autophoto_command, error);
+ }
+ else
+ {
+ /* pretend that we handled the device */
+ result = TRUE;
+ }
+ }
+ }
+
+ g_free (autophoto_command);
+ }
+
+ return result;
+}
+
+
+
+static gboolean
tvm_block_device_autorun (TvmContext *context,
GMount *mount,
GError **error)
@@ -221,12 +279,15 @@ tvm_block_device_autorun (TvmContext *context,
/* try to launch the autorun file */
result = g_spawn_async (mount_path, argv, NULL, 0, NULL, NULL, NULL,
- error);
+ &err);
/* free strings */
g_strfreev (argv);
g_free (mount_path);
+ if (err != NULL)
+ g_propagate_error (error, err);
+
return result;
}
}
@@ -266,7 +327,7 @@ tvm_block_device_autorun (TvmContext *context,
/* try to launch the autorun file */
result = g_spawn_async (mount_path, argv, NULL, 0, NULL, NULL, NULL,
- error);
+ &err);
/* free strings */
g_strfreev (argv);
@@ -275,6 +336,9 @@ tvm_block_device_autorun (TvmContext *context,
/* free path to wine */
g_free (wine);
+ if (err != NULL)
+ g_propagate_error (error, err);
+
return result;
}
}
@@ -340,7 +404,7 @@ tvm_block_device_autorun (TvmContext *context,
/* let Thunar open the file */
result = g_spawn_async (mount_path, argv, NULL, 0, NULL, NULL,
- NULL, error);
+ NULL, &err);
/* cleanup */
g_free (path_autoopen);
@@ -349,6 +413,9 @@ tvm_block_device_autorun (TvmContext *context,
/* free the mount point path */
g_free (mount_path);
+ if (err != NULL)
+ g_propagate_error (error, err);
+
return result;
}
}
@@ -415,7 +482,7 @@ tvm_block_device_mounted (TvmContext *context,
g_return_if_fail (error == NULL || *error == NULL);
/* try block device handlers (iPod, cameras etc.) until one succeeds */
- for (n = 0; !success && n < G_N_ELEMENTS (block_device_handlers); ++n)
+ for (n = 0; !success && err == NULL && n < G_N_ELEMENTS (block_device_handlers); ++n)
success = (block_device_handlers[n]) (context, mount, &err);
/* forward errors to the caller */
More information about the Xfce4-commits
mailing list