[Xfce4-commits] <thunar:jannis/thumbnailer-improvements> Add thunar_thumbnail_cache_copy_file().

Jannis Pohlmann noreply at xfce.org
Mon Feb 7 21:52:01 CET 2011


Updating branch refs/heads/jannis/thumbnailer-improvements
         to bdfbba792be55b094647fe06c739c5ac151b134f (commit)
       from 133d32f0fcc2c37f5c581d647ae5fd02014244f3 (commit)

commit bdfbba792be55b094647fe06c739c5ac151b134f
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Mon Feb 7 21:49:22 2011 +0100

    Add thunar_thumbnail_cache_copy_file().
    
    This one also uses a queue and a timeout of 250ms to group Copy() D-Bus
    method calls.

 thunar/thunar-thumbnail-cache.c |  149 +++++++++++++++++++++++++++++++++++++++
 thunar/thunar-thumbnail-cache.h |    3 +
 2 files changed, 152 insertions(+), 0 deletions(-)

diff --git a/thunar/thunar-thumbnail-cache.c b/thunar/thunar-thumbnail-cache.c
index 22d9eaf..fe62dc3 100644
--- a/thunar/thunar-thumbnail-cache.c
+++ b/thunar/thunar-thumbnail-cache.c
@@ -58,6 +58,10 @@ struct _ThunarThumbnailCache
   GList      *move_target_queue;
   guint       move_queue_idle_id;
 
+  GList      *copy_source_queue;
+  GList      *copy_target_queue;
+  guint       copy_queue_idle_id;
+
   GList      *delete_queue;
   guint       delete_queue_idle_id;
 
@@ -130,6 +134,14 @@ thunar_thumbnail_cache_finalize (GObject *object)
   g_list_free (cache->move_source_queue);
   g_list_free (cache->move_target_queue);
 
+  /* drop the copy queue idle and all queued files */
+  if (cache->copy_queue_idle_id > 0)
+    g_source_remove (cache->copy_queue_idle_id);
+  g_list_foreach (cache->copy_source_queue, (GFunc) g_object_unref, NULL);
+  g_list_foreach (cache->copy_target_queue, (GFunc) g_object_unref, NULL);
+  g_list_free (cache->copy_source_queue);
+  g_list_free (cache->copy_target_queue);
+
   /* drop the delete queue idle and all queued files */
   if (cache->delete_queue_idle_id > 0)
     g_source_remove (cache->delete_queue_idle_id);
@@ -185,6 +197,34 @@ thunar_thumbnail_cache_move_async (ThunarThumbnailCache *cache,
 
 
 static void
+thunar_thumbnail_cache_copy_async_reply (DBusGProxy *proxy,
+                                         GError     *error,
+                                         gpointer    user_data)
+{
+  _thunar_return_if_fail (DBUS_IS_G_PROXY (proxy));
+}
+
+
+
+static void
+thunar_thumbnail_cache_copy_async (ThunarThumbnailCache *cache,
+                                   const gchar         **source_uris,
+                                   const gchar         **target_uris)
+{
+  _thunar_return_if_fail (THUNAR_IS_THUMBNAIL_CACHE (cache));
+  _thunar_return_if_fail (source_uris != NULL);
+  _thunar_return_if_fail (target_uris != NULL);
+
+  /* request a thumbnail cache update asynchronously */
+  thunar_thumbnail_cache_proxy_copy_async (cache->cache_proxy,
+                                           source_uris, target_uris,
+                                           thunar_thumbnail_cache_copy_async_reply,
+                                           NULL);
+}
+
+
+
+static void
 thunar_thumbnail_cache_delete_async_reply (DBusGProxy *proxy,
                                            GError     *error,
                                            gpointer    user_data)
@@ -277,6 +317,73 @@ thunar_thumbnail_cache_process_move_queue (ThunarThumbnailCache *cache)
 
 
 static gboolean
+thunar_thumbnail_cache_process_copy_queue (ThunarThumbnailCache *cache)
+{
+  GList  *sp;
+  GList  *tp;
+  gchar **source_uris;
+  gchar **target_uris;
+  guint   n_uris;
+  guint   n;
+
+  _thunar_return_val_if_fail (THUNAR_IS_THUMBNAIL_CACHE (cache), FALSE);
+
+  /* acquire a cache lock */
+  g_mutex_lock (cache->lock);
+  
+  /* compute how many URIs there are */
+  n_uris = g_list_length (cache->copy_source_queue);
+
+  /* allocate a string array for the URIs */
+  source_uris = g_new0 (gchar *, n_uris + 1);
+  target_uris = g_new0 (gchar *, n_uris + 1);
+
+  /* fill URI array with file URIs from the copy queue */
+  for (n = 0,
+       sp = g_list_last (cache->copy_source_queue), 
+       tp = g_list_last (cache->copy_target_queue);
+       sp != NULL && tp != NULL; 
+       sp = sp->prev, tp = tp->prev, ++n)
+    {
+      source_uris[n] = g_file_get_uri (sp->data);
+      target_uris[n] = g_file_get_uri (tp->data);
+
+      /* release the file objects */
+      g_object_unref (sp->data);
+      g_object_unref (tp->data);
+    }
+
+  /* NULL-terminate the URI arrays */
+  source_uris[n] = NULL;
+  target_uris[n] = NULL;
+
+  /* asynchronously copy the thumbnails */
+  thunar_thumbnail_cache_copy_async (cache, 
+                                     (const gchar **)source_uris,
+                                     (const gchar **)target_uris);
+
+  /* free the URI arrays */
+  g_free (source_uris);
+  g_free (target_uris);
+
+  /* release the copy queue lists */
+  g_list_free (cache->copy_source_queue);
+  g_list_free (cache->copy_target_queue);
+  cache->copy_source_queue = NULL;
+  cache->copy_target_queue = NULL;
+
+  /* reset the copy queue idle ID */
+  cache->copy_queue_idle_id = 0;
+
+  /* release the cache lock */
+  g_mutex_unlock (cache->lock);
+
+  return FALSE;
+}
+
+
+
+static gboolean
 thunar_thumbnail_cache_process_delete_queue (ThunarThumbnailCache *cache)
 {
   GList  *lp;
@@ -380,6 +487,48 @@ thunar_thumbnail_cache_move_file (ThunarThumbnailCache *cache,
 
 
 void
+thunar_thumbnail_cache_copy_file (ThunarThumbnailCache *cache,
+                                  GFile                *source_file,
+                                  GFile                *target_file)
+{
+  _thunar_return_if_fail (THUNAR_IS_THUMBNAIL_CACHE (cache));
+  _thunar_return_if_fail (G_IS_FILE (source_file));
+  _thunar_return_if_fail (G_IS_FILE (target_file));
+
+#ifdef HAVE_DBUS
+  /* acquire a cache lock */
+  g_mutex_lock (cache->lock);
+
+  /* check if we have a valid proxy for the cache service */
+  if (cache->cache_proxy != NULL)
+    {
+      /* cancel any pending timeout to process the copy queue */
+      if (cache->copy_queue_idle_id > 0)
+        {
+          g_source_remove (cache->copy_queue_idle_id);
+          cache->copy_queue_idle_id = 0;
+        }
+
+      /* add the files to the copy queues */
+      cache->copy_source_queue = g_list_prepend (cache->copy_source_queue, 
+                                                 g_object_ref (source_file));
+      cache->copy_target_queue = g_list_prepend (cache->copy_target_queue,
+                                                 g_object_ref (target_file));
+
+      /* process the copy queue in a 250ms timeout */
+      cache->copy_queue_idle_id =
+        g_timeout_add (250, (GSourceFunc) thunar_thumbnail_cache_process_copy_queue,
+                       cache);
+    }
+
+  /* release the cache lock */
+  g_mutex_unlock (cache->lock);
+#endif
+}
+
+
+
+void
 thunar_thumbnail_cache_delete_file (ThunarThumbnailCache *cache,
                                     GFile                *file)
 {
diff --git a/thunar/thunar-thumbnail-cache.h b/thunar/thunar-thumbnail-cache.h
index adc023c..79d8654 100644
--- a/thunar/thunar-thumbnail-cache.h
+++ b/thunar/thunar-thumbnail-cache.h
@@ -43,6 +43,9 @@ ThunarThumbnailCache *thunar_thumbnail_cache_new         (void) G_GNUC_MALLOC G_
 void                  thunar_thumbnail_cache_move_file   (ThunarThumbnailCache *cache,
                                                           GFile                *source_file,
                                                           GFile                *target_file);
+void                  thunar_thumbnail_cache_copy_file   (ThunarThumbnailCache *cache,
+                                                          GFile                *source_file,
+                                                          GFile                *target_file);
 void                  thunar_thumbnail_cache_delete_file (ThunarThumbnailCache *cache,
                                                           GFile                *file);
 



More information about the Xfce4-commits mailing list