[Xfce4-commits] <ristretto:master> Connect the image-list and icon-bar to the thumbnailer.

Stephan Arts noreply at xfce.org
Mon Feb 20 21:52:01 CET 2012


Updating branch refs/heads/master
         to 43ab55e66d9e2a3809b8a6f30850a3f9604a3690 (commit)
       from 95b5c150d23487be6de89cac15f41d3590106429 (commit)

commit 43ab55e66d9e2a3809b8a6f30850a3f9604a3690
Author: Stephan Arts <stephan at xfce.org>
Date:   Mon Feb 20 21:49:50 2012 +0100

    Connect the image-list and icon-bar to the thumbnailer.

 src/icon_bar.c    |   14 +++++++++++++-
 src/image_list.c  |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/thumbnailer.c |   51 +++++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 97 insertions(+), 11 deletions(-)

diff --git a/src/icon_bar.c b/src/icon_bar.c
index e53a7f3..bc9d298 100644
--- a/src/icon_bar.c
+++ b/src/icon_bar.c
@@ -33,6 +33,7 @@
 
 #include "util.h"
 #include "file.h"
+#include "thumbnailer.h"
 #include "settings.h"
 #include "marshal.h"
 #include "icon_bar.h"
@@ -327,6 +328,7 @@ struct _RsttoIconBarPrivate
     GtkAdjustment  *vadjustment;
 
     RsttoSettings  *settings;
+    RsttoThumbnailer *thumbnailer;
 
     RsttoThumbnailSize thumbnail_size;
 
@@ -550,6 +552,7 @@ rstto_icon_bar_init (RsttoIconBar *icon_bar)
     icon_bar->priv->show_text = TRUE;
     icon_bar->priv->auto_center = TRUE;
     icon_bar->priv->settings = rstto_settings_new ();
+    icon_bar->priv->thumbnailer = rstto_thumbnailer_new();
 
     icon_bar->priv->thumbnail_size = rstto_settings_get_uint_property (
             icon_bar->priv->settings,
@@ -573,7 +576,6 @@ rstto_icon_bar_init (RsttoIconBar *icon_bar)
             "notify::thumbnail-size",
             G_CALLBACK (cb_rstto_thumbnail_size_changed),
             icon_bar);
-
 }
 
 
@@ -597,6 +599,7 @@ rstto_icon_bar_finalize (GObject *object)
 
     g_object_unref (G_OBJECT (icon_bar->priv->layout));
     g_object_unref (G_OBJECT (icon_bar->priv->settings));
+    g_object_unref (G_OBJECT (icon_bar->priv->thumbnailer));
 
     (*G_OBJECT_CLASS (rstto_icon_bar_parent_class)->finalize) (object);
 }
@@ -913,6 +916,8 @@ rstto_icon_bar_expose (
     GdkRectangle    area;
     RsttoIconBar     *icon_bar = RSTTO_ICON_BAR (widget);
     GList          *lp;
+    RsttoFile      *file;
+    GtkTreeIter     iter;
 
     if (expose->window != icon_bar->priv->bin_window)
         return FALSE;
@@ -936,7 +941,14 @@ rstto_icon_bar_expose (
         area.height = icon_bar->priv->item_height;
 
         if (gdk_region_rect_in (expose->region, &area) != GDK_OVERLAP_RECTANGLE_OUT)
+        {
+            iter = item->iter;
+            gtk_tree_model_get (icon_bar->priv->model, &iter,
+                    icon_bar->priv->file_column, &file,
+                    -1);
+            rstto_thumbnailer_queue_file (icon_bar->priv->thumbnailer, file);
             rstto_icon_bar_paint_item (icon_bar, item, &expose->area);
+        }
     }
 
     return TRUE;
diff --git a/src/image_list.c b/src/image_list.c
index e29db5e..021fef3 100644
--- a/src/image_list.c
+++ b/src/image_list.c
@@ -32,6 +32,7 @@
 #include "util.h"
 #include "file.h"
 #include "image_list.h"
+#include "thumbnailer.h"
 #include "settings.h"
 
 static void
@@ -68,6 +69,12 @@ cb_rstto_wrap_images_changed (
         gpointer user_data);
 
 static void
+cb_rstto_thumbnailer_ready(
+        RsttoThumbnailer *thumbnailer,
+        RsttoFile *file,
+        gpointer user_data);
+
+static void
 rstto_image_list_monitor_dir (
         RsttoImageList *image_list,
         GFile *dir );
@@ -206,6 +213,7 @@ struct _RsttoImageListPriv
     gint           stamp;
     GFileMonitor  *monitor;
     RsttoSettings *settings;
+    RsttoThumbnailer *thumbnailer;
     GtkFileFilter *filter;
 
     GList        *images;
@@ -300,6 +308,7 @@ rstto_image_list_init(RsttoImageList *image_list)
     image_list->priv = g_new0 (RsttoImageListPriv, 1);
     image_list->priv->stamp = g_random_int();
     image_list->priv->settings = rstto_settings_new ();
+    image_list->priv->thumbnailer = rstto_thumbnailer_new();
     image_list->priv->filter = gtk_file_filter_new ();
     g_object_ref_sink (image_list->priv->filter);
     gtk_file_filter_add_pixbuf_formats (image_list->priv->filter);
@@ -316,6 +325,12 @@ rstto_image_list_init(RsttoImageList *image_list)
             G_CALLBACK (cb_rstto_wrap_images_changed),
             image_list);
 
+    g_signal_connect (
+            G_OBJECT(image_list->priv->thumbnailer),
+            "ready",
+            G_CALLBACK (cb_rstto_thumbnailer_ready),
+            image_list);
+
 }
 
 static void
@@ -363,6 +378,12 @@ rstto_image_list_dispose(GObject *object)
             image_list->priv->settings = NULL;
         }
 
+        if (image_list->priv->thumbnailer)
+        {
+            g_object_unref (image_list->priv->thumbnailer);
+            image_list->priv->thumbnailer = NULL;
+        }
+
         if (image_list->priv->filter)
         {
             g_object_unref (image_list->priv->filter);
@@ -1426,3 +1447,25 @@ image_list_model_get_value (
             break;
     }
 }
+
+static void
+cb_rstto_thumbnailer_ready(
+        RsttoThumbnailer *thumbnailer,
+        RsttoFile *file,
+        gpointer user_data)
+{
+    RsttoImageList *image_list = RSTTO_IMAGE_LIST (user_data);
+    GtkTreePath *path_ = NULL;
+    GtkTreeIter iter;
+    gint index_;
+
+    index_ = g_list_index (image_list->priv->images, file);
+    if (index_ > 0)
+    {
+        path_ = gtk_tree_path_new();
+        gtk_tree_path_append_index(path_,index_);
+        gtk_tree_model_get_iter (GTK_TREE_MODEL (image_list), &iter, path_);
+
+        gtk_tree_model_row_changed (GTK_TREE_MODEL(image_list), path_, &iter);
+    }
+}
diff --git a/src/thumbnailer.c b/src/thumbnailer.c
index a3d2c85..01f69d7 100644
--- a/src/thumbnailer.c
+++ b/src/thumbnailer.c
@@ -79,6 +79,14 @@ static RsttoThumbnailer *thumbnailer_object;
 
 enum
 {
+    RSTTO_THUMBNAILER_SIGNAL_READY = 0,
+    RSTTO_THUMBNAILER_SIGNAL_COUNT
+};
+
+static gint rstto_thumbnailer_signals[RSTTO_THUMBNAILER_SIGNAL_COUNT];
+
+enum
+{
     PROP_0,
 };
 
@@ -119,6 +127,8 @@ struct _RsttoThumbnailerPriv
     RsttoSettings     *settings;
 
     GSList            *queue;
+
+    GSList            *in_process_queue;
     gint               handle;
 
     gboolean           show_missing_thumbnailer_error;
@@ -198,6 +208,18 @@ rstto_thumbnailer_class_init (GObjectClass *object_class)
     object_class->set_property = rstto_thumbnailer_set_property;
     object_class->get_property = rstto_thumbnailer_get_property;
 
+
+    rstto_thumbnailer_signals[RSTTO_THUMBNAILER_SIGNAL_READY] = g_signal_new("ready",
+            G_TYPE_FROM_CLASS(thumbnailer_class),
+            G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+            0,
+            NULL,
+            NULL,
+            g_cclosure_marshal_VOID__OBJECT,
+            G_TYPE_NONE,
+            1,
+            G_TYPE_OBJECT,
+            NULL);
 }
 
 /**
@@ -381,14 +403,17 @@ rstto_thumbnailer_queue_request_timer (
 
     g_return_val_if_fail ( RSTTO_IS_THUMBNAILER (thumbnailer), FALSE);
 
+    thumbnailer->priv->in_process_queue = thumbnailer->priv->queue;
+    thumbnailer->priv->queue = NULL;
+
     uris = g_new0 (
             const gchar *,
-            g_slist_length(thumbnailer->priv->queue) + 1);
+            g_slist_length(thumbnailer->priv->in_process_queue) + 1);
     mimetypes = g_new0 (
             const gchar *,
-            g_slist_length (thumbnailer->priv->queue) + 1);
+            g_slist_length (thumbnailer->priv->in_process_queue) + 1);
 
-    iter = thumbnailer->priv->queue;
+    iter = thumbnailer->priv->in_process_queue;
     while (iter)
     {
         if (iter->data)
@@ -477,9 +502,9 @@ cb_rstto_thumbnailer_request_finished (
 
     g_return_if_fail ( RSTTO_IS_THUMBNAILER (thumbnailer) );
 
-    g_slist_foreach (thumbnailer->priv->queue, (GFunc)g_object_unref, NULL);
-    g_slist_free (thumbnailer->priv->queue);
-    thumbnailer->priv->queue = NULL;
+    g_slist_foreach (thumbnailer->priv->in_process_queue, (GFunc)g_object_unref, NULL);
+    g_slist_free (thumbnailer->priv->in_process_queue);
+    thumbnailer->priv->in_process_queue = NULL;
 }
 
 static void
@@ -491,7 +516,7 @@ cb_rstto_thumbnailer_thumbnail_ready (
 {
     RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (data);
     RsttoFile *file;
-    GSList *iter = thumbnailer->priv->queue;
+    GSList *iter = thumbnailer->priv->in_process_queue;
     gint x = 0;
     const gchar *f_uri;
 
@@ -508,12 +533,18 @@ cb_rstto_thumbnailer_thumbnail_ready (
         f_uri = rstto_file_get_uri (file);
         if (strcmp (uri[x], f_uri) == 0)
         {
-            thumbnailer->priv->queue = g_slist_remove (
-                    thumbnailer->priv->queue,
+            g_signal_emit (
+                    G_OBJECT (thumbnailer),
+                    rstto_thumbnailer_signals[RSTTO_THUMBNAILER_SIGNAL_READY],
+                    0,
+                    file,
+                    NULL);
+            thumbnailer->priv->in_process_queue = g_slist_remove (
+                    thumbnailer->priv->in_process_queue,
                     file);
             g_object_unref (file);
 
-            iter = thumbnailer->priv->queue;
+            iter = thumbnailer->priv->in_process_queue;
             x++;
         }
         else


More information about the Xfce4-commits mailing list