summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRok Mandeljc <rok.mandeljc@gmail.com>2014-07-28 20:45:03 +0200
committerPhilip Langdale <philipl@overt.org>2014-07-29 19:54:00 -0700
commit6eb6853bfca43d714f48ca5edd676feaec357326 (patch)
treea4b440866d23cf0fdc58c68dc6463abef401c0ab
parentbe000ea91e90186bb6f1031348e33d5b9025251a (diff)
downloadgvfs-6eb6853bfca43d714f48ca5edd676feaec357326.tar.gz
mtp: added support for OBJECT_ADDED event
This patch adds support for OBJECT_ADDED event, which is emitted when a file or a folder is created on the device. When such an event is received, its path is determined by first looking up the parent ID and appending object's name to it; the path and IDs are added to cache, and create event is emitted, causing clients (for example Nautilus) to display the new file/folder without having to refresh the display of parent folder. Signed-off-by: Rok Mandeljc <rok.mandeljc@gmail.com>
-rw-r--r--daemon/gvfsbackendmtp.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index ee503503..9148dd4d 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -709,6 +709,58 @@ check_event (gpointer user_data)
} else {
return NULL;
}
+ case LIBMTP_EVENT_OBJECT_ADDED:
+ backend = g_weak_ref_get (event_ref);
+ if (backend && !g_atomic_int_get (&backend->unmount_started)) {
+ g_mutex_lock (&backend->mutex);
+
+ LIBMTP_file_t *object = LIBMTP_Get_Filemetadata(backend->device, param1);
+ if (object) {
+ /* Obtain parent's path by searching cache by object's parent
+ ID; if the latter is zero, the object is located in storage's
+ root, otherwise, it is located in one of subfolders */
+ const char *parent_path = NULL;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_hash_table_iter_init (&iter, backend->file_cache);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ const char *path = key;
+ const CacheEntry *entry = value;
+
+ if (object->parent_id != 0) {
+ if (object->parent_id == entry->id && object->storage_id == entry->storage) {
+ parent_path = path;
+ break;
+ }
+ } else {
+ if (entry->id == -1 && object->storage_id == entry->storage) {
+ parent_path = path;
+ break;
+ }
+ }
+ }
+
+ if (parent_path) {
+ /* Create path, add cache entry and emit create event(s) */
+ char *path = g_build_filename (parent_path, object->filename, NULL);
+
+ add_cache_entry (G_VFS_BACKEND_MTP (backend),
+ path,
+ object->storage_id,
+ object->item_id);
+ g_hash_table_foreach (backend->monitors, emit_create_event, path);
+ }
+
+ LIBMTP_destroy_file_t (object);
+ }
+
+ g_mutex_unlock (&backend->mutex);
+ g_object_unref (backend);
+ break;
+ } else {
+ return NULL;
+ }
#endif
default:
break;