gvfs r2126 - in trunk: . daemon monitor/gphoto2
- From: hadess svn gnome org
- To: svn-commits-list gnome org
- Subject: gvfs r2126 - in trunk: . daemon monitor/gphoto2
- Date: Tue, 9 Dec 2008 10:43:05 +0000 (UTC)
Author: hadess
Date: Tue Dec 9 10:43:05 2008
New Revision: 2126
URL: http://svn.gnome.org/viewvc/gvfs?rev=2126&view=rev
Log:
2008-12-09 Bastien Nocera <hadess hadess net>
* monitor/gphoto2/Makefile.am:
* monitor/gphoto2/ggphoto2volumemonitor.c (get_stores_for_camera),
(update_cameras): For each camera discovered, create shadow mounts
for each one of the top-level storage heads, makes each of the
device's stores appear separately
* daemon/gvfsbackendgphoto2.c (monitors_emit_internal),
(release_device), (split_filename), (file_get_info), (do_mount),
(do_open_for_read_real), (do_query_info), (try_query_info),
(do_enumerate), (try_enumerate), (do_make_directory),
(do_set_display_name), (do_delete), (do_create_internal),
(do_replace), (do_append_to), (do_move), (do_create_dir_monitor),
(do_create_file_monitor): Remove all the hacks to handle
a single storage head differently from multiple storage heads,
this makes photo directories detection and the likes work
for multiple storage-heads
(Closes: #520123)
Modified:
trunk/ChangeLog
trunk/daemon/gvfsbackendgphoto2.c
trunk/monitor/gphoto2/Makefile.am
trunk/monitor/gphoto2/ggphoto2volumemonitor.c
Modified: trunk/daemon/gvfsbackendgphoto2.c
==============================================================================
--- trunk/daemon/gvfsbackendgphoto2.c (original)
+++ trunk/daemon/gvfsbackendgphoto2.c Tue Dec 9 10:43:05 2008
@@ -148,13 +148,6 @@
* use replace() directly instead of fooling around with ~-style
* backup files
*
- * - support for multiple storage heads
- * - need a device that supports this
- * - should be different mounts so need to infect GHalVolumeMonitor with libgphoto2
- * - probably not a huge priority to add
- * - might help properly resolve the hack we're doing in ensure_ignore_prefix()
- * - http://bugzilla.gnome.org/show_bug.cgi?id=520123
- *
* - adding a payload cache don't make much sense as libgphoto2 has a LRU cache already
* - (see comment in the do_close_write() function)
*
@@ -179,9 +172,6 @@
GPContext *context;
Camera *camera;
- /* see comment in ensure_ignore_prefix() */
- char *ignore_prefix;
-
/* list of open files */
int num_open_files_for_reading;
@@ -236,7 +226,7 @@
/* ------------------------------------------------------------------------------------------------- */
typedef struct {
- /* this is the path of the dir/file including ignore_prefix */
+ /* this is the path of the dir/file */
char *path;
GVfsMonitor *vfs_monitor;
} MonitorProxy;
@@ -358,8 +348,6 @@
GList *l;
char *filepath;
- g_return_if_fail (g_str_has_prefix (dir, gphoto2_backend->ignore_prefix));
-
DEBUG ("monitors_emit_internal() %s for '%s' '%s'", event_name, dir, name);
for (l = gphoto2_backend->dir_monitor_proxies; l != NULL; l = l->next)
@@ -368,7 +356,7 @@
if (strcmp (proxy->path, dir) == 0)
{
char *path;
- path = g_build_filename (dir + strlen (gphoto2_backend->ignore_prefix), name, NULL);
+ path = g_build_filename (dir, name, NULL);
g_vfs_monitor_emit_event (proxy->vfs_monitor, event, path, NULL);
DEBUG (" emitted %s for '%s' on dir monitor for '%s'", event_name, path, dir);
g_free (path);
@@ -381,9 +369,8 @@
MonitorProxy *proxy = l->data;
if (strcmp (proxy->path, filepath) == 0)
{
- const char *path = filepath + strlen (gphoto2_backend->ignore_prefix);
- g_vfs_monitor_emit_event (proxy->vfs_monitor, event, path, NULL);
- DEBUG (" emitted %s for '%s' on file monitor", event_name, path);
+ g_vfs_monitor_emit_event (proxy->vfs_monitor, event, filepath, NULL);
+ DEBUG (" emitted %s for '%s' on file monitor", event_name, filepath);
}
}
g_free (filepath);
@@ -568,9 +555,6 @@
g_free (gphoto2_backend->hal_icon_name);
gphoto2_backend->hal_icon_name = NULL;
- g_free (gphoto2_backend->ignore_prefix);
- gphoto2_backend->ignore_prefix = NULL;
-
if (gphoto2_backend->info_cache != NULL)
{
g_hash_table_unref (gphoto2_backend->info_cache);
@@ -919,15 +903,15 @@
/* ------------------------------------------------------------------------------------------------- */
static void
-split_filename_with_ignore_prefix (GVfsBackendGphoto2 *gphoto2_backend, const char *filename, char **dir, char **name)
+split_filename (GVfsBackendGphoto2 *gphoto2_backend, const char *filename, char **dir, char **name)
{
char *s;
s = g_path_get_dirname (filename);
if (s[0] == '/')
- *dir = g_strconcat (gphoto2_backend->ignore_prefix, s + 1, NULL);
+ *dir = g_strconcat ("/", s + 1, NULL);
else
- *dir = g_strconcat (gphoto2_backend->ignore_prefix, s, NULL);
+ *dir = g_strconcat ("/", s, NULL);
g_free (s);
if (strcmp (filename, "/") == 0)
@@ -939,28 +923,11 @@
if (s[strlen(s)] == '/')
s[strlen(s)] = '\0';
- /*DEBUG ("split_filename_with_ignore_prefix: '%s' -> '%s' '%s'", filename, *dir, *name);*/
+ /*DEBUG ("split_filename: '%s' -> '%s' '%s'", filename, *dir, *name);*/
}
/* ------------------------------------------------------------------------------------------------- */
-static char *
-add_ignore_prefix (GVfsBackendGphoto2 *gphoto2_backend, const char *filename)
-{
- char *result;
-
- if (filename[0] == '/')
- result = g_strconcat (gphoto2_backend->ignore_prefix, filename + 1, NULL);
- else
- result = g_strconcat (gphoto2_backend->ignore_prefix, filename, NULL);
-
- /*DEBUG ("add_ignore_prefix: '%s' -> '%s'", filename, result);*/
- return result;
-}
-
-/* ------------------------------------------------------------------------------------------------- */
-
-/* the passed 'dir' variable must contain ignore_prefix */
static gboolean
file_get_info (GVfsBackendGphoto2 *gphoto2_backend,
const char *dir,
@@ -984,7 +951,7 @@
full_path = g_build_filename (dir, name, NULL);
DEBUG ("file_get_info() try_cache_only=%d dir='%s', name='%s'\n"
" full_path='%s'",
- try_cache_only, dir, name, full_path, gphoto2_backend->ignore_prefix);
+ try_cache_only, dir, name, full_path);
/* first look up cache */
@@ -1011,7 +978,7 @@
g_file_info_unset_attribute_mask (info);
/* handle root directory */
- if (strcmp (full_path, gphoto2_backend->ignore_prefix) == 0 || strcmp (full_path, "/") == 0)
+ if (strcmp (full_path, "/") == 0)
{
char *display_name;
display_name = compute_display_name (gphoto2_backend);
@@ -1143,7 +1110,7 @@
GMountSpec *mount_spec;
mount_spec = g_vfs_backend_get_mount_spec (G_VFS_BACKEND (gphoto2_backend));
- icon_id = g_strdup_printf ("preview:%s/%s", dir + strlen (gphoto2_backend->ignore_prefix), name);
+ icon_id = g_strdup_printf ("preview:%s/%s", dir, name);
icon = g_vfs_icon_new (mount_spec,
icon_id);
g_file_info_set_attribute_object (info,
@@ -1301,89 +1268,6 @@
/* ------------------------------------------------------------------------------------------------- */
-/* The PTP gphoto2 backend puts an annoying virtual store_00010001
- * directory in the root (in fact 00010001 can be any hexedecimal
- * digit).
- *
- * We want to skip that as the x-content detection expects to find the
- * DCIM/ folder. As such, this function tries to detect the presence
- * of such a folder in the root and, if found, sets a variable that is
- * prepended to any path passed to libgphoto2. This is cached for as
- * long as we got a connection to libgphoto2. If this operation fails
- * then the passed job will be cancelled and this function will return
- * FALSE.
- *
- * This function needs to be called from do_mount().
- */
-static gboolean
-ensure_ignore_prefix (GVfsBackendGphoto2 *gphoto2_backend, GVfsJob *job)
-{
- int rc;
- char *prefix;
- GError *error;
- CameraList *list;
-
- /* already set */
- if (gphoto2_backend->ignore_prefix != NULL)
- return TRUE;
-
- /* check folders in / - if there is exactly one folder of the form "store_" followed by eight
- * hexadecimal digits.. then use that as ignore_prefix.. otherwise don't use anything
- */
-
- gp_list_new (&list);
- rc = gp_camera_folder_list_folders (gphoto2_backend->camera,
- "/",
- list,
- gphoto2_backend->context);
- if (rc != 0)
- {
- error = get_error_from_gphoto2 (_("Failed to get folder list"), rc);
- g_vfs_job_failed_from_error (job, error);
- g_error_free (error);
- return FALSE;
- }
-
- prefix = NULL;
-
- if (gp_list_count (list) == 1)
- {
- char *name;
- const char *s;
- unsigned int n;
-
- gp_list_get_name (list, 0, &s);
-
- name = g_ascii_strdown (s, -1);
- if (g_str_has_prefix (name, "store_") && strlen (name) == 14)
- {
- for (n = 6; n < 14; n++)
- {
- if (!g_ascii_isxdigit (name[n]))
- {
- break;
- }
- }
- if (n == 14)
- {
- prefix = g_strconcat ("/", name, "/", NULL);
- }
- }
-
- g_free (name);
- }
- gp_list_free (list);
-
- if (prefix == NULL)
- gphoto2_backend->ignore_prefix = g_strdup ("/");
- else
- gphoto2_backend->ignore_prefix = prefix;
-
- return TRUE;
-}
-
-/* ------------------------------------------------------------------------------------------------- */
-
static void
do_mount (GVfsBackend *backend,
GVfsJobMount *job,
@@ -1559,12 +1443,6 @@
return;
}
- if (!ensure_ignore_prefix (gphoto2_backend, G_VFS_JOB (job)))
- {
- release_device (gphoto2_backend);
- return;
- }
-
/* Translator: %s represents the device, e.g. usb:001,042 */
fuse_name = g_strdup_printf (_("gphoto2 mount on %s"), gphoto2_backend->gphoto2_port);
icon_name = compute_icon_name (gphoto2_backend);
@@ -1711,7 +1589,7 @@
ensure_not_dirty (gphoto2_backend);
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
if (is_directory (gphoto2_backend, dir, name))
{
@@ -1941,7 +1819,7 @@
DEBUG ("query_info (%s)", filename);
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
error = NULL;
if (!file_get_info (gphoto2_backend, dir, name, info, &error, FALSE))
@@ -1977,7 +1855,7 @@
ret = FALSE;
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
if (!file_get_info (gphoto2_backend, dir, name, info, NULL, TRUE))
{
@@ -2011,7 +1889,6 @@
CameraList *list;
int n;
int rc;
- char *filename;
gboolean using_cached_dir_list;
gboolean using_cached_file_list;
char *as_dir;
@@ -2021,10 +1898,9 @@
using_cached_dir_list = FALSE;
using_cached_file_list = FALSE;
- filename = add_ignore_prefix (gphoto2_backend, given_filename);
DEBUG ("enumerate (%s)", given_filename);
- split_filename_with_ignore_prefix (gphoto2_backend, given_filename, &as_dir, &as_name);
+ split_filename (gphoto2_backend, given_filename, &as_dir, &as_name);
if (!is_directory (gphoto2_backend, as_dir, as_name))
{
if (is_regular (gphoto2_backend, as_dir, as_name))
@@ -2048,18 +1924,18 @@
/* first, list the folders */
g_mutex_lock (gphoto2_backend->lock);
- list = g_hash_table_lookup (gphoto2_backend->dir_name_cache, filename);
+ list = g_hash_table_lookup (gphoto2_backend->dir_name_cache, given_filename);
if (list == NULL)
{
g_mutex_unlock (gphoto2_backend->lock);
ensure_not_dirty (gphoto2_backend);
- DEBUG (" Generating dir list for dir '%s'", filename);
+ DEBUG (" Generating dir list for dir '%s'", given_filename);
gp_list_new (&list);
rc = gp_camera_folder_list_folders (gphoto2_backend->camera,
- filename,
+ given_filename,
list,
gphoto2_backend->context);
if (rc != 0)
@@ -2067,13 +1943,12 @@
error = get_error_from_gphoto2 (_("Failed to get folder list"), rc);
g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
g_error_free (error);
- g_free (filename);
return;
}
}
else
{
- DEBUG (" Using cached dir list for dir '%s'", filename);
+ DEBUG (" Using cached dir list for dir '%s'", given_filename);
using_cached_dir_list = TRUE;
gp_list_ref (list);
g_mutex_unlock (gphoto2_backend->lock);
@@ -2086,7 +1961,7 @@
DEBUG (" enum folder '%s'", name);
info = g_file_info_new ();
error = NULL;
- if (!file_get_info (gphoto2_backend, filename, name, info, &error, FALSE))
+ if (!file_get_info (gphoto2_backend, given_filename, name, info, &error, FALSE))
{
g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
g_error_free (error);
@@ -2101,7 +1976,7 @@
{
#ifndef DEBUG_NO_CACHING
g_mutex_lock (gphoto2_backend->lock);
- g_hash_table_insert (gphoto2_backend->dir_name_cache, g_strdup (filename), list);
+ g_hash_table_insert (gphoto2_backend->dir_name_cache, g_strdup (given_filename), list);
g_mutex_unlock (gphoto2_backend->lock);
#endif
}
@@ -2115,17 +1990,17 @@
/* then list the files in each folder */
g_mutex_lock (gphoto2_backend->lock);
- list = g_hash_table_lookup (gphoto2_backend->file_name_cache, filename);
+ list = g_hash_table_lookup (gphoto2_backend->file_name_cache, given_filename);
if (list == NULL)
{
g_mutex_unlock (gphoto2_backend->lock);
ensure_not_dirty (gphoto2_backend);
- DEBUG (" Generating file list for dir '%s'", filename);
+ DEBUG (" Generating file list for dir '%s'", given_filename);
gp_list_new (&list);
rc = gp_camera_folder_list_files (gphoto2_backend->camera,
- filename,
+ given_filename,
list,
gphoto2_backend->context);
if (rc != 0)
@@ -2133,13 +2008,12 @@
error = get_error_from_gphoto2 (_("Failed to get file list"), rc);
g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
g_error_free (error);
- g_free (filename);
return;
}
}
else
{
- DEBUG (" Using cached file list for dir '%s'", filename);
+ DEBUG (" Using cached file list for dir '%s'", given_filename);
using_cached_file_list = TRUE;
gp_list_ref (list);
g_mutex_unlock (gphoto2_backend->lock);
@@ -2153,7 +2027,7 @@
info = g_file_info_new ();
error = NULL;
- if (!file_get_info (gphoto2_backend, filename, name, info, &error, FALSE))
+ if (!file_get_info (gphoto2_backend, given_filename, name, info, &error, FALSE))
{
g_vfs_job_failed_from_error (G_VFS_JOB (job), error);
g_error_free (error);
@@ -2168,7 +2042,7 @@
{
#ifndef DEBUG_NO_CACHING
g_mutex_lock (gphoto2_backend->lock);
- g_hash_table_insert (gphoto2_backend->file_name_cache, g_strdup (filename), list);
+ g_hash_table_insert (gphoto2_backend->file_name_cache, g_strdup (given_filename), list);
g_mutex_unlock (gphoto2_backend->lock);
#endif
}
@@ -2186,8 +2060,6 @@
g_list_foreach (l, (GFunc) g_object_unref, NULL);
g_list_free (l);
g_vfs_job_enumerate_done (job);
-
- g_free (filename);
}
/* ------------------------------------------------------------------------------------------------- */
@@ -2205,17 +2077,15 @@
GError *error;
CameraList *list;
int n;
- char *filename;
const char *name;
l = NULL;
- filename = add_ignore_prefix (gphoto2_backend, given_filename);
DEBUG ("try_enumerate (%s)", given_filename);
/* first, list the folders */
g_mutex_lock (gphoto2_backend->lock);
- list = g_hash_table_lookup (gphoto2_backend->dir_name_cache, filename);
+ list = g_hash_table_lookup (gphoto2_backend->dir_name_cache, given_filename);
if (list == NULL)
{
g_mutex_unlock (gphoto2_backend->lock);
@@ -2228,7 +2098,7 @@
gp_list_get_name (list, n, &name);
DEBUG (" try_enum folder '%s'", name);
info = g_file_info_new ();
- if (!file_get_info (gphoto2_backend, filename, name, info, &error, TRUE))
+ if (!file_get_info (gphoto2_backend, given_filename, name, info, &error, TRUE))
{
g_mutex_lock (gphoto2_backend->lock);
gp_list_unref (list);
@@ -2243,7 +2113,7 @@
/* then list the files in each folder */
g_mutex_lock (gphoto2_backend->lock);
- list = g_hash_table_lookup (gphoto2_backend->file_name_cache, filename);
+ list = g_hash_table_lookup (gphoto2_backend->file_name_cache, given_filename);
if (list == NULL)
{
g_mutex_unlock (gphoto2_backend->lock);
@@ -2257,7 +2127,7 @@
DEBUG (" try_enum file '%s'", name);
info = g_file_info_new ();
- if (!file_get_info (gphoto2_backend, filename, name, info, &error, TRUE))
+ if (!file_get_info (gphoto2_backend, given_filename, name, info, &error, TRUE))
{
g_mutex_lock (gphoto2_backend->lock);
gp_list_unref (list);
@@ -2278,7 +2148,6 @@
g_list_free (l);
g_vfs_job_enumerate_done (job);
- g_free (filename);
DEBUG (" YAY got info from cache for try_enumerate (%s)", given_filename);
return TRUE;
@@ -2286,7 +2155,6 @@
g_list_foreach (l, (GFunc) g_object_unref, NULL);
g_list_free (l);
- g_free (filename);
DEBUG (" BUU no info from cache for try_enumerate (%s)", given_filename);
return FALSE;
}
@@ -2414,7 +2282,7 @@
goto out;
}
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
rc = gp_camera_folder_make_dir (gphoto2_backend->camera,
dir,
@@ -2623,7 +2491,7 @@
goto out;
}
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
/* refuse is desired name is already taken */
if (is_directory (gphoto2_backend, dir, display_name) ||
@@ -2678,7 +2546,7 @@
monitors_emit_deleted (gphoto2_backend, dir, name);
monitors_emit_created (gphoto2_backend, dir, display_name);
- new_name = g_build_filename (dir + strlen (gphoto2_backend->ignore_prefix), display_name, NULL);
+ new_name = g_build_filename (dir, display_name, NULL);
g_vfs_job_set_display_name_set_new_path (job, new_name);
g_vfs_job_succeeded (G_VFS_JOB (job));
@@ -2720,12 +2588,11 @@
goto out;
}
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
if (is_directory (gphoto2_backend, dir, name))
{
- dir_name = add_ignore_prefix (gphoto2_backend, filename);
- if (!is_directory_empty (gphoto2_backend, dir_name))
+ if (!is_directory_empty (gphoto2_backend, filename))
{
g_vfs_job_failed (G_VFS_JOB (job), G_IO_ERROR,
G_IO_ERROR_NOT_EMPTY,
@@ -2813,7 +2680,7 @@
goto out;
}
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
if (is_directory (gphoto2_backend, dir, name))
{
@@ -2971,7 +2838,7 @@
dir = NULL;
name = NULL;
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
/* write a new file
* - will delete the existing one when done in do_close_write()
@@ -2998,7 +2865,7 @@
dir = NULL;
name = NULL;
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
/* write a new file
* - will read existing data in do_create_internal
@@ -3218,8 +3085,8 @@
ensure_not_dirty (gphoto2_backend);
- split_filename_with_ignore_prefix (gphoto2_backend, source, &src_dir, &src_name);
- split_filename_with_ignore_prefix (gphoto2_backend, destination, &dst_dir, &dst_name);
+ split_filename (gphoto2_backend, source, &src_dir, &src_name);
+ split_filename (gphoto2_backend, destination, &dst_dir, &dst_name);
/* this is an limited implementation that can only move files / folders in the same directory */
if (strcmp (src_dir, dst_dir) != 0)
@@ -3353,10 +3220,10 @@
DEBUG ("create_dir_monitor (%s)", filename);
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
proxy = g_new0 (MonitorProxy, 1);
- proxy->path = add_ignore_prefix (gphoto2_backend, filename);
+ proxy->path = g_strdup (filename);
proxy->vfs_monitor = g_vfs_monitor_new (backend);
gphoto2_backend->dir_monitor_proxies = g_list_prepend (gphoto2_backend->dir_monitor_proxies, proxy);
@@ -3403,10 +3270,10 @@
DEBUG ("create_file_monitor (%s)", filename);
- split_filename_with_ignore_prefix (gphoto2_backend, filename, &dir, &name);
+ split_filename (gphoto2_backend, filename, &dir, &name);
proxy = g_new0 (MonitorProxy, 1);
- proxy->path = add_ignore_prefix (gphoto2_backend, filename);
+ proxy->path = g_strdup (filename);
proxy->vfs_monitor = g_vfs_monitor_new (backend);
gphoto2_backend->file_monitor_proxies = g_list_prepend (gphoto2_backend->file_monitor_proxies, proxy);
Modified: trunk/monitor/gphoto2/Makefile.am
==============================================================================
--- trunk/monitor/gphoto2/Makefile.am (original)
+++ trunk/monitor/gphoto2/Makefile.am Tue Dec 9 10:43:05 2008
@@ -29,6 +29,7 @@
-I$(top_srcdir)/monitor/proxy \
$(GLIB_CFLAGS) \
$(HAL_CFLAGS) \
+ $(GPHOTO2_CFLAGS) \
-DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" \
-DGVFS_LOCALEDIR=\""$(localedir)"\" \
-DG_DISABLE_DEPRECATED \
@@ -40,6 +41,7 @@
gvfs_gphoto2_volume_monitor_LDADD = \
$(GLIB_LIBS) \
$(HAL_LIBS) \
+ $(GPHOTO2_LIBS) \
$(top_builddir)/common/libgvfscommon.la \
$(top_builddir)/monitor/proxy/libgvfsproxyvolumemonitordaemon-noin.la \
$(NULL)
Modified: trunk/monitor/gphoto2/ggphoto2volumemonitor.c
==============================================================================
--- trunk/monitor/gphoto2/ggphoto2volumemonitor.c (original)
+++ trunk/monitor/gphoto2/ggphoto2volumemonitor.c Tue Dec 9 10:43:05 2008
@@ -29,6 +29,7 @@
#include <glib.h>
#include <glib/gi18n-lib.h>
+#include <gphoto2.h>
#include <gio/gio.h>
#include "ggphoto2volumemonitor.h"
@@ -448,6 +449,67 @@
}
}
+static GList *
+get_stores_for_camera (int bus_num, int device_num)
+{
+ GList *l;
+ CameraStorageInformation *storage_info;
+ GPContext *context;
+ GPPortInfo info;
+ GPPortInfoList *il;
+ int num_storage_info, n;
+ Camera *camera;
+ char *port;
+ guint i;
+
+ il = NULL;
+ camera = NULL;
+ context = NULL;
+ l = NULL;
+ port = g_strdup_printf ("usb:%d,%d", bus_num, device_num);
+
+ /* Connect to the camera */
+ context = gp_context_new ();
+ if (gp_camera_new (&camera) != 0)
+ goto out;
+ if (gp_port_info_list_new (&il) != 0)
+ goto out;
+ if (gp_port_info_list_load (il) != 0)
+ goto out;
+ n = gp_port_info_list_lookup_path (il, port);
+ if (n == GP_ERROR_UNKNOWN_PORT)
+ goto out;
+ if (gp_port_info_list_get_info (il, n, &info) != 0)
+ goto out;
+ if (gp_camera_set_port_info (camera, info) != 0)
+ goto out;
+ gp_port_info_list_free (il);
+ il = NULL;
+ if (gp_camera_init (camera, context) != 0)
+ goto out;
+
+ /* Get information about the storage heads */
+ if (gp_camera_get_storageinfo (camera, &storage_info, &num_storage_info, context) != 0)
+ goto out;
+
+ /* Append the data to the list */
+ for (i = 0; i < num_storage_info; i++)
+ l = g_list_prepend (l, g_strdup (storage_info[i].basedir));
+
+out:
+ /* Clean up */
+ if (il != NULL)
+ gp_port_info_list_free (il);
+ if (context != NULL)
+ gp_context_unref (context);
+ if (camera != NULL)
+ gp_camera_unref (camera);
+
+ g_free (port);
+
+ return l;
+}
+
static void
update_cameras (GGPhoto2VolumeMonitor *monitor,
GList **added_volumes,
@@ -513,11 +575,11 @@
for (l = added; l != NULL; l = l->next)
{
HalDevice *d = l->data;
- char *uri;
GFile *foreign_mount_root;
int usb_bus_num;
int usb_device_num;
gboolean found;
+ GList *store_heads, *l;
/* Look for the device in the added volumes, so as
* not to add devices that are both audio players, and cameras */
@@ -537,24 +599,34 @@
usb_bus_num = hal_device_get_property_int (d, "usb.bus_number");
usb_device_num = hal_device_get_property_int (d, "usb.linux.device_number");
- uri = g_strdup_printf ("gphoto2://[usb:%03d,%03d]", usb_bus_num, usb_device_num);
- /*g_warning ("uri is '%s'", uri);*/
- foreign_mount_root = g_file_new_for_uri (uri);
- g_free (uri);
+ store_heads = get_stores_for_camera (usb_bus_num, usb_device_num);
+ for (l = store_heads ; l != NULL; l = l->next)
+ {
+ char *store_path = (char *) l->data;
+ char *uri;
- udi = hal_device_get_udi (d);
- /*g_warning ("camera adding %s", udi);*/
+ uri = g_strdup_printf ("gphoto2://[usb:%03d,%03d]/%s", usb_bus_num, usb_device_num,
+ store_path[0] == '/' ? store_path + 1 : store_path);
+
+ foreign_mount_root = g_file_new_for_uri (uri);
+ g_free (uri);
+
+ udi = hal_device_get_udi (d);
+ volume = g_gphoto2_volume_new (G_VOLUME_MONITOR (monitor),
+ d,
+ monitor->pool,
+ foreign_mount_root);
+ g_object_unref (foreign_mount_root);
+ if (volume != NULL)
+ {
+ monitor->camera_volumes = g_list_prepend (monitor->camera_volumes, volume);
+ *added_volumes = g_list_prepend (*added_volumes, g_object_ref (volume));
+ }
+
+ g_free (l->data);
- volume = g_gphoto2_volume_new (G_VOLUME_MONITOR (monitor),
- d,
- monitor->pool,
- foreign_mount_root);
- g_object_unref (foreign_mount_root);
- if (volume != NULL)
- {
- monitor->camera_volumes = g_list_prepend (monitor->camera_volumes, volume);
- *added_volumes = g_list_prepend (*added_volumes, g_object_ref (volume));
}
+ g_list_free (store_heads);
}
g_list_free (added);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]