[Xfce4-commits] <thunar:master> Regenerate thumbnails on file changes (bug #8473).

Nick Schermer noreply at xfce.org
Mon Sep 24 19:54:04 CEST 2012


Updating branch refs/heads/master
         to 803adcaa403278913e306a29b05fe40814dfa6c5 (commit)
       from 1e23b9a0675d4eaa2b75e7e7dadab293b456f7ac (commit)

commit 803adcaa403278913e306a29b05fe40814dfa6c5
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Sep 24 19:51:28 2012 +0200

    Regenerate thumbnails on file changes (bug #8473).
    
    Watch file changes in the model and if this occurs, poke the
    thumbnailer to regenerate the thumbnail.
    
    Also reduce the file-change emission a bit for cacse we don't
    respond to (thumbnailing wise).

 thunar/thunar-file.c          |    6 ++-
 thunar/thunar-standard-view.c |   65 +++++++++++++++++++++++++++++++++++++++++
 thunar/thunar-thumbnailer.c   |   30 +++++++++++++++++++
 3 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index c238d67..eb4406e 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -2831,8 +2831,10 @@ thunar_file_set_thumb_state (ThunarFile          *file,
   file->flags = (file->flags & ~THUNAR_FILE_THUMB_STATE_MASK) | (state);
 
   /* notify others of this change, so that all components can update
-   * their file information */
-  thunar_file_monitor_file_changed (file);
+   * their file information. loading is only a state for the thumbnailer,
+   * so don't emit changes for that */
+  if (state != THUNAR_FILE_THUMB_STATE_LOADING)
+    thunar_file_monitor_file_changed (file);
 }
 
 
diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c
index c60d508..2450dfe 100644
--- a/thunar/thunar-standard-view.c
+++ b/thunar/thunar-standard-view.c
@@ -252,6 +252,10 @@ static void                 thunar_standard_view_drag_end                   (Gtk
 static void                 thunar_standard_view_row_deleted                (ThunarListModel          *model,
                                                                              GtkTreePath              *path,
                                                                              ThunarStandardView       *standard_view);
+static void                 thunar_standard_view_row_changed                (ThunarListModel          *model,
+                                                                             GtkTreePath              *path,
+                                                                             GtkTreeIter              *iter,
+                                                                             ThunarStandardView       *standard_view);
 static void                 thunar_standard_view_restore_selection          (ThunarListModel          *model,
                                                                              GtkTreePath              *path,
                                                                              ThunarStandardView       *standard_view);
@@ -265,6 +269,9 @@ static gboolean             thunar_standard_view_drag_scroll_timer          (gpo
 static void                 thunar_standard_view_drag_scroll_timer_destroy  (gpointer                  user_data);
 static gboolean             thunar_standard_view_drag_timer                 (gpointer                  user_data);
 static void                 thunar_standard_view_drag_timer_destroy         (gpointer                  user_data);
+static void                 thunar_standard_view_finished_thumbnailing      (ThunarThumbnailer        *thumbnailer,
+                                                                             guint                     request,
+                                                                             ThunarStandardView       *standard_view);
 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);
@@ -349,6 +356,9 @@ struct _ThunarStandardViewPrivate
   guint                   thumbnail_source_id;
   gboolean                thumbnailing_scheduled;
 
+  /* file insert signal */
+  gulong                  row_changed_id;
+
   /* Tree path for restoring the selection after selecting and
    * deleting an item */
   GtkTreePath            *selection_before_delete;
@@ -557,6 +567,7 @@ thunar_standard_view_init (ThunarStandardView *standard_view)
 
   /* create a thumbnailer */
   standard_view->priv->thumbnailer = thunar_thumbnailer_new ();
+  g_signal_connect (G_OBJECT (standard_view->priv->thumbnailer), "request-finished", G_CALLBACK (thunar_standard_view_finished_thumbnailing), standard_view);
   standard_view->priv->thumbnailing_scheduled = FALSE;
 
   /* initialize the scrolled window */
@@ -602,6 +613,7 @@ thunar_standard_view_init (ThunarStandardView *standard_view)
   /* setup the list model */
   standard_view->model = thunar_list_model_new ();
   g_signal_connect (G_OBJECT (standard_view->model), "row-deleted", G_CALLBACK (thunar_standard_view_row_deleted), standard_view);
+  standard_view->priv->row_changed_id = g_signal_connect (G_OBJECT (standard_view->model), "row-changed", G_CALLBACK (thunar_standard_view_row_changed), standard_view);
   g_signal_connect_after (G_OBJECT (standard_view->model), "row-deleted", G_CALLBACK (thunar_standard_view_restore_selection), standard_view);
   g_signal_connect (G_OBJECT (standard_view->model), "error", G_CALLBACK (thunar_standard_view_error), standard_view);
   exo_binding_new (G_OBJECT (standard_view->preferences), "misc-case-sensitive", G_OBJECT (standard_view->model), "case-sensitive");
@@ -1273,6 +1285,12 @@ thunar_standard_view_set_loading (ThunarStandardView *standard_view,
   /* apply the new state */
   standard_view->loading = loading;
 
+  /* block or unblock the insert signal to avoid queuing thumbnail reloads */
+  if (loading)
+    g_signal_handler_block (standard_view->model, standard_view->priv->row_changed_id);
+  else
+    g_signal_handler_unblock (standard_view->model, standard_view->priv->row_changed_id);
+
   /* check if we're done loading and have a scheduled scroll_to_file */
   if (G_UNLIKELY (!loading && standard_view->priv->scroll_to_file != NULL))
     {
@@ -3190,6 +3208,40 @@ thunar_standard_view_row_deleted (ThunarListModel    *model,
 
 
 static void
+thunar_standard_view_row_changed (ThunarListModel    *model,
+                                  GtkTreePath        *path,
+                                  GtkTreeIter        *iter,
+                                  ThunarStandardView *standard_view)
+{
+  ThunarFile *file;
+  gboolean    show_thumbnails;
+
+  _thunar_return_if_fail (THUNAR_IS_LIST_MODEL (model));
+  _thunar_return_if_fail (path != NULL);
+  _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
+  _thunar_return_if_fail (standard_view->model == model);
+
+  if (standard_view->priv->thumbnail_request != 0)
+    return;
+
+  g_object_get (standard_view->icon_factory, "show-thumbnails", &show_thumbnails, NULL);
+  if (!show_thumbnails)
+    return;
+
+  /* queue a thumbnail request */
+  file = thunar_list_model_get_file (standard_view->model, iter);
+  if (thunar_file_get_thumb_state (file) == THUNAR_FILE_THUMB_STATE_UNKNOWN)
+    {
+      thunar_standard_view_cancel_thumbnailing (standard_view);
+      thunar_thumbnailer_queue_file (standard_view->priv->thumbnailer, file,
+                                     &standard_view->priv->thumbnail_request);
+    }
+  g_object_unref (G_OBJECT (file));
+}
+
+
+
+static void
 thunar_standard_view_restore_selection (ThunarListModel    *model,
                                         GtkTreePath        *path,
                                         ThunarStandardView *standard_view)
@@ -3385,6 +3437,19 @@ thunar_standard_view_drag_timer_destroy (gpointer user_data)
 
 
 static void
+thunar_standard_view_finished_thumbnailing (ThunarThumbnailer  *thumbnailer,
+                                            guint               request,
+                                            ThunarStandardView *standard_view)
+{
+  _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
+
+  if (standard_view->priv->thumbnail_request == request)
+    standard_view->priv->thumbnail_request = 0;
+}
+
+
+
+static void
 thunar_standard_view_cancel_thumbnailing (ThunarStandardView *standard_view)
 {
   _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view));
diff --git a/thunar/thunar-thumbnailer.c b/thunar/thunar-thumbnailer.c
index 6248d9b..1b7cde9 100644
--- a/thunar/thunar-thumbnailer.c
+++ b/thunar/thunar-thumbnailer.c
@@ -89,6 +89,13 @@ typedef struct _ThunarThumbnailerJob  ThunarThumbnailerJob;
 typedef struct _ThunarThumbnailerIdle ThunarThumbnailerIdle;
 #endif
 
+/* Signal identifiers */
+enum
+{
+  REQUEST_FINISHED,
+  LAST_SIGNAL,
+};
+
 
 
 static void                   thunar_thumbnailer_finalize               (GObject                    *object);
@@ -183,6 +190,10 @@ struct _ThunarThumbnailerIdle
 
 
 
+static guint thumbnailer_signals[LAST_SIGNAL];
+
+
+
 G_DEFINE_TYPE (ThunarThumbnailer, thunar_thumbnailer, G_TYPE_OBJECT);
 
 
@@ -194,6 +205,22 @@ thunar_thumbnailer_class_init (ThunarThumbnailerClass *klass)
 
   gobject_class = G_OBJECT_CLASS (klass);
   gobject_class->finalize = thunar_thumbnailer_finalize;
+
+  /**
+   * ThunarThumbnailer:request-finished:
+   * @thumbnailer : a #ThunarThumbnailer.
+   * @request     : id of the request that is finished.
+   *
+   * Emitted by @thumbnailer, when a request is finished
+   * by the thumbnail generator
+   **/
+  thumbnailer_signals[REQUEST_FINISHED] =
+    g_signal_new (I_("request-finished"),
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL,
+                  g_cclosure_marshal_VOID__UINT,
+                  G_TYPE_NONE, 1, G_TYPE_UINT);
 }
 
 
@@ -470,6 +497,9 @@ thunar_thumbnailer_thumbnailer_finished (DBusGProxy        *proxy,
           /* this job is finished, forget about the handle */
           job->handle = 0;
 
+          /* tell everybody we're done here */
+          g_signal_emit (G_OBJECT (thumbnailer), thumbnailer_signals[REQUEST_FINISHED], 0, job->request);
+
           /* remove job from the list */
           g_mutex_lock (thumbnailer->lock);
           thumbnailer->jobs = g_slist_delete_link (thumbnailer->jobs, lp);


More information about the Xfce4-commits mailing list