diff options
author | Philip Langdale <philipl@overt.org> | 2012-09-01 16:51:42 -0700 |
---|---|---|
committer | Philip Langdale <philipl@overt.org> | 2013-01-11 20:30:29 -0800 |
commit | 50a35ca5e3a2207cd552a9fb932c16b57ca8c56e (patch) | |
tree | 920dfd2d7f536a37bc820e98ddabb46dcc402d49 /daemon | |
parent | 7c9e64ac4874fa291be53a3d3d93aa3e476c5e5b (diff) | |
download | gvfs-50a35ca5e3a2207cd552a9fb932c16b57ca8c56e.tar.gz |
MTP: Event handling.
This change adds an event listener to receive libmtp events. The
primary use for this is detecting when stores appear after a phone
is unlocked. That way you can plug it in, then unlock it, and then
you'll see the stores appear automatically.
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/gvfsbackendmtp.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c index a593199e..10e70bcf 100644 --- a/daemon/gvfsbackendmtp.c +++ b/daemon/gvfsbackendmtp.c @@ -253,6 +253,34 @@ try_mount (GVfsBackend *backend, return FALSE; } +#if HAVE_LIBMTP_READ_EVENT +static gpointer +check_event(gpointer user_data) +{ + GVfsBackendMtp *backend = user_data; + + LIBMTP_event_t event; + int ret = 0; + while (ret == 0) { + uint32_t param1; + char *path; + ret = LIBMTP_Read_Event(backend->device, &event, ¶m1); + switch (event) { + case LIBMTP_EVENT_STORE_ADDED: + path = g_strdup_printf ("/%u", param1); + g_mutex_lock (&backend->mutex); + g_hash_table_foreach (backend->monitors, emit_create_event, path); + g_mutex_unlock (&backend->mutex); + g_free (path); + break; + default: + break; + } + } + return NULL; +} +#endif + static void do_mount (GVfsBackend *backend, GVfsJobMount *job, @@ -319,6 +347,10 @@ do_mount (GVfsBackend *backend, g_mount_spec_unref (mtp_mount_spec); g_vfs_job_succeeded (G_VFS_JOB (job)); + +#if HAVE_LIBMTP_READ_EVENT + g_thread_new("events", check_event, backend); +#endif } } |