[Xfce4-commits] <thunar:master> Add lazy checks to thumbnailer.

Nick Schermer noreply at xfce.org
Tue Oct 30 22:06:09 CET 2012


Updating branch refs/heads/master
         to 1ac786f81c2c843468d4a64f3572f6327d7fedb7 (commit)
       from 0d5b53acae487b33641c1590ab57221941c97f08 (commit)

commit 1ac786f81c2c843468d4a64f3572f6327d7fedb7
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Oct 30 20:27:41 2012 +0100

    Add lazy checks to thumbnailer.
    
    Idea is simple, don't try to load thumbnails for files
    that have already been tried when scrolling a view. This
    saves a lot of requests.

 thunar/thunar-standard-view.c |   30 ++++++++++++++++++++++++------
 thunar/thunar-thumbnailer.c   |   18 +++++++++++-------
 thunar/thunar-thumbnailer.h   |    1 +
 3 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index 5734691..4e487df 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -274,7 +274,8 @@ static void                 thunar_standard_view_finished_thumbnailing      (Thu
 static void                 thunar_standard_view_cancel_thumbnailing        (ThunarStandardView       *standard_view);
 static void                 thunar_standard_view_schedule_thumbnail_timeout (ThunarStandardView       *standard_view);
 static void                 thunar_standard_view_schedule_thumbnail_idle    (ThunarStandardView       *standard_view);
-static gboolean             thunar_standard_view_request_thumbnails         (ThunarStandardView       *standard_view);
+static gboolean             thunar_standard_view_request_thumbnails         (gpointer                  data);
+static gboolean             thunar_standard_view_request_thumbnails_lazy    (gpointer                  data);
 static void                 thunar_standard_view_show_thumbnails_toggled    (ThunarStandardView       *standard_view,
                                                                              GParamSpec               *pspec,
                                                                              ThunarIconFactory        *icon_factory);
@@ -3721,8 +3722,7 @@ thunar_standard_view_schedule_thumbnail_timeout (ThunarStandardView *standard_vi
 
   /* schedule the timeout handler */
   standard_view->priv->thumbnail_source_id =
-    g_timeout_add (175, (GSourceFunc) thunar_standard_view_request_thumbnails,
-                   standard_view);
+    g_timeout_add (175, thunar_standard_view_request_thumbnails_lazy, standard_view);
 }
 
 
@@ -3747,13 +3747,14 @@ thunar_standard_view_schedule_thumbnail_idle (ThunarStandardView *standard_view)
 
   /* schedule the timeout or idle handler */
   standard_view->priv->thumbnail_source_id =
-    g_idle_add ((GSourceFunc) thunar_standard_view_request_thumbnails, standard_view);
+    g_idle_add (thunar_standard_view_request_thumbnails, standard_view);
 }
 
 
 
 static gboolean
-thunar_standard_view_request_thumbnails (ThunarStandardView *standard_view)
+thunar_standard_view_request_thumbnails_real (ThunarStandardView *standard_view,
+                                              gboolean            lazy_request)
 {
   GtkTreePath *start_path;
   GtkTreePath *end_path;
@@ -3811,7 +3812,8 @@ thunar_standard_view_request_thumbnails (ThunarStandardView *standard_view)
         }
 
       /* queue a thumbnail request */
-      thunar_thumbnailer_queue_files (standard_view->priv->thumbnailer, visible_files,
+      thunar_thumbnailer_queue_files (standard_view->priv->thumbnailer,
+                                      lazy_request, visible_files,
                                       &standard_view->priv->thumbnail_request);
 
       /* release the file list */
@@ -3830,6 +3832,22 @@ thunar_standard_view_request_thumbnails (ThunarStandardView *standard_view)
 
 
 
+static gboolean
+thunar_standard_view_request_thumbnails (gpointer data)
+{
+  return thunar_standard_view_request_thumbnails_real (data, FALSE);
+}
+
+
+
+static gboolean
+thunar_standard_view_request_thumbnails_lazy (gpointer data)
+{
+  return thunar_standard_view_request_thumbnails_real (data, TRUE);
+}
+
+
+
 static void
 thunar_standard_view_show_thumbnails_toggled (ThunarStandardView *standard_view,
                                               GParamSpec         *pspec,
diff --git a/thunar/thunar-thumbnailer.c b/thunar/thunar-thumbnailer.c
index f73ae65..81f0f1a 100644
--- a/thunar/thunar-thumbnailer.c
+++ b/thunar/thunar-thumbnailer.c
@@ -829,13 +829,14 @@ thunar_thumbnailer_queue_file (ThunarThumbnailer *thumbnailer,
   files.prev = NULL;
 
   /* queue a thumbnail request for the file */
-  return thunar_thumbnailer_queue_files (thumbnailer, &files, request);
+  return thunar_thumbnailer_queue_files (thumbnailer, FALSE, &files, request);
 }
 
 
 
 gboolean
 thunar_thumbnailer_queue_files (ThunarThumbnailer *thumbnailer,
+                                gboolean           lazy_checks,
                                 GList             *files,
                                 guint             *request)
 {
@@ -875,13 +876,16 @@ thunar_thumbnailer_queue_files (ThunarThumbnailer *thumbnailer,
       /* get the current thumb state */
       thumb_state = thunar_file_get_thumb_state (lp->data);
 
-      /* if previously this failed, don't both to check. this saves a
-       * lot of check when resizing a window */
-      if (thumb_state == THUNAR_FILE_THUMB_STATE_NONE)
-        continue;
+      if (lazy_checks)
+        {
+          /* in lazy mode, don't both for files that have already
+           * been loaded or are not supported */
+          if (thumb_state == THUNAR_FILE_THUMB_STATE_NONE
+              || thumb_state == THUNAR_FILE_THUMB_STATE_READY)
+            continue;
+        }
 
-      /* if the state is unknown of there previously was a thumb, add
-       * to the supported list */
+      /* check if the file is supported, assume it is when the state was ready previously */
       if (thumb_state == THUNAR_FILE_THUMB_STATE_READY
           || thunar_thumbnailer_file_is_supported (thumbnailer, lp->data))
         {
diff --git a/thunar/thunar-thumbnailer.h b/thunar/thunar-thumbnailer.h
index d46f94e..daed609 100644
--- a/thunar/thunar-thumbnailer.h
+++ b/thunar/thunar-thumbnailer.h
@@ -43,6 +43,7 @@ gboolean           thunar_thumbnailer_queue_file      (ThunarThumbnailer
                                                        ThunarFile               *file,
                                                        guint                    *request);
 gboolean           thunar_thumbnailer_queue_files     (ThunarThumbnailer        *thumbnailer,
+                                                       gboolean                  lazy_checks,
                                                        GList                    *files,
                                                        guint                    *request);
 void               thunar_thumbnailer_dequeue         (ThunarThumbnailer        *thumbnailer,


More information about the Xfce4-commits mailing list