[Xfce4-commits] <ristretto:ristretto-0.0> Revert "Implement state-machine in image class"

Stephan Arts noreply at xfce.org
Sun Oct 23 19:13:32 CEST 2011


Updating branch refs/heads/ristretto-0.0
         to 66cae1e72422b4912d5cc852c4989a9225322ea3 (commit)
       from 99f0917fc1d220dd6a2ef61a5f5f53fe2e839065 (commit)

commit 66cae1e72422b4912d5cc852c4989a9225322ea3
Author: Stephan Arts <stephan at thor.(none)>
Date:   Fri May 15 18:33:06 2009 +0200

    Revert "Implement state-machine in image class"
    
    This reverts commit 96ee95c3848f91e9693d4519e1c7d52f35ab4340.

 src/image.c          |  109 ++++++++-----------------------------------------
 src/image.h          |   12 -----
 src/picture_viewer.c |   36 +++++------------
 3 files changed, 28 insertions(+), 129 deletions(-)

diff --git a/src/image.c b/src/image.c
index 38333eb..c454cf8 100644
--- a/src/image.c
+++ b/src/image.c
@@ -38,12 +38,11 @@
 
 enum
 {
-    RSTTO_IMAGE_SIGNAL_STATE_CHANGED = 0,
-    RSTTO_IMAGE_SIGNAL_UPDATED,
+    RSTTO_IMAGE_SIGNAL_UPDATED= 0,
+    RSTTO_IMAGE_SIGNAL_PREPARED,
     RSTTO_IMAGE_SIGNAL_COUNT    
 };
 
-
 static void
 rstto_image_init (GObject *);
 static void
@@ -62,9 +61,6 @@ static gboolean
 cb_rstto_image_update(RsttoImage *image);
 
 static void
-rstto_image_set_state (RsttoImage *image, RsttoImageState state);
-
-static void
 cb_rstto_image_read_file_ready (GObject *source_object, GAsyncResult *result, gpointer user_data);
 static void
 cb_rstto_image_read_input_stream_ready (GObject *source_object, GAsyncResult *result, gpointer user_data);
@@ -101,8 +97,6 @@ rstto_image_get_type ()
 
 struct _RsttoImagePriv
 {
-    /* Generic data */
-    RsttoImageState state;
     /* File data */
     /*************/
     GFile *file;
@@ -111,18 +105,15 @@ struct _RsttoImagePriv
     /* File I/O data */
     /*****************/
     guchar *buffer;
-    GdkPixbufLoader *loader;
-    gboolean load_cancelled;
 
     /* Image data */
     /**************/
+    GdkPixbufLoader *loader;
     ExifData *exif_data;
     GdkPixbuf *thumbnail;
     GdkPixbuf *pixbuf;
     gint       width;
     gint       height;
-    gint       pixbuf_width;
-    gint       pixbuf_height;
     guint      max_size;
 
     GdkPixbufAnimation  *animation;
@@ -165,7 +156,7 @@ rstto_image_class_init (GObjectClass *object_class)
             0,
             NULL);
 
-    rstto_image_signals[RSTTO_IMAGE_SIGNAL_STATE_CHANGED] = g_signal_new("state-changed",
+    rstto_image_signals[RSTTO_IMAGE_SIGNAL_PREPARED] = g_signal_new("prepared",
             G_TYPE_FROM_CLASS (image_class),
             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
             0,
@@ -186,7 +177,6 @@ rstto_image_class_init (GObjectClass *object_class)
 static void
 rstto_image_dispose (GObject *object)
 {
-    g_debug ("%s", __FUNCTION__);
     RsttoImage *image = RSTTO_IMAGE (object);
 
     if(image->priv->thumbnail)
@@ -201,16 +191,12 @@ rstto_image_dispose (GObject *object)
         image->priv->animation_timeout_id = 0;
     }
 
-/*
     if (image->priv->loader)
     {
-        g_signal_handlers_disconnect_by_func (image->priv->loader , cb_rstto_image_size_prepared, image);
         g_signal_handlers_disconnect_by_func (image->priv->loader , cb_rstto_image_area_prepared, image);
-        g_signal_handlers_disconnect_by_func (image->priv->loader , cb_rstto_image_closed, image);
         gdk_pixbuf_loader_close (image->priv->loader, NULL);
         image->priv->loader = NULL;
     }
-*/
 
     if (image->priv->animation)
     {
@@ -249,7 +235,6 @@ rstto_image_dispose (GObject *object)
 RsttoImage *
 rstto_image_new (GFile *file)
 {
-    g_debug ("%s", __FUNCTION__);
     g_object_ref (file);
 
     RsttoImage *image = g_object_new (RSTTO_TYPE_IMAGE, NULL);
@@ -311,7 +296,6 @@ rstto_image_new (GFile *file)
 static void
 cb_rstto_image_read_file_ready (GObject *source_object, GAsyncResult *result, gpointer user_data)
 {
-    g_debug ("%s", __FUNCTION__);
     GFile *file = G_FILE (source_object);
     RsttoImage *image = RSTTO_IMAGE (user_data);
 
@@ -330,7 +314,6 @@ cb_rstto_image_read_file_ready (GObject *source_object, GAsyncResult *result, gp
 static void
 cb_rstto_image_read_input_stream_ready (GObject *source_object, GAsyncResult *result, gpointer user_data)
 {
-    g_debug ("%s", __FUNCTION__);
     RsttoImage *image = RSTTO_IMAGE (user_data);
     gssize read_bytes = g_input_stream_read_finish (G_INPUT_STREAM (source_object), result, NULL);
     GError *error = NULL;
@@ -339,7 +322,7 @@ cb_rstto_image_read_input_stream_ready (GObject *source_object, GAsyncResult *re
         return;
 
 
-    if (read_bytes > 0 && (image->priv->load_cancelled == FALSE))
+    if (read_bytes > 0)
     {
         if(gdk_pixbuf_loader_write (image->priv->loader, (const guchar *)image->priv->buffer, read_bytes, &error) == FALSE)
         {
@@ -358,6 +341,7 @@ cb_rstto_image_read_input_stream_ready (GObject *source_object, GAsyncResult *re
         }
     }
     else
+    if (read_bytes == 0)
     {
         if (read_bytes == 0)
         {
@@ -396,7 +380,6 @@ cb_rstto_image_read_input_stream_ready (GObject *source_object, GAsyncResult *re
 gboolean
 rstto_image_load (RsttoImage *image, gboolean empty_cache, guint max_size, gboolean preload, GError **error)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_val_if_fail (image != NULL, FALSE);
 
     RsttoImageCache *cache = rstto_image_cache_new ();
@@ -429,10 +412,12 @@ rstto_image_load (RsttoImage *image, gboolean empty_cache, guint max_size, gbool
         /*g_signal_connect(image->priv->loader, "area-updated", G_CALLBACK(cb_rstto_image_area_updated), image);*/
         g_signal_connect(image->priv->loader, "closed", G_CALLBACK(cb_rstto_image_closed), image);
 
-        rstto_image_set_state (image, RSTTO_IMAGE_STATE_LOADING);
 	    g_file_read_async (image->priv->file, 0, NULL, (GAsyncReadyCallback)cb_rstto_image_read_file_ready, image);
     }
-
+    else
+    {
+        g_signal_emit(G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_UPDATED], 0, image, NULL);
+    }
     rstto_image_cache_push_image (cache, image, preload);
     return TRUE;
 }
@@ -447,11 +432,13 @@ rstto_image_load (RsttoImage *image, gboolean empty_cache, guint max_size, gbool
 void
 rstto_image_unload (RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_if_fail (image != NULL);
 
     if (image->priv->loader)
-        image->priv->load_cancelled = TRUE;
+    {
+        gdk_pixbuf_loader_close (image->priv->loader, NULL);
+        image->priv->loader = NULL;
+    }
 
     if (image->priv->pixbuf)
     {
@@ -490,7 +477,6 @@ rstto_image_unload (RsttoImage *image)
         image->priv->transformations = NULL;
     }
 
-    rstto_image_set_state (image, RSTTO_IMAGE_STATE_DEFAULT);
 }
 
 
@@ -503,7 +489,6 @@ rstto_image_unload (RsttoImage *image)
 GFile *
 rstto_image_get_file (RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_val_if_fail (image != NULL, NULL);
     g_return_val_if_fail (image->priv != NULL, NULL);
     g_return_val_if_fail (image->priv->file != NULL, NULL);
@@ -520,7 +505,6 @@ rstto_image_get_file (RsttoImage *image)
 gint
 rstto_image_get_width (RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_val_if_fail (image != NULL, 0);
     g_return_val_if_fail (image->priv != NULL, 0);
 
@@ -536,7 +520,6 @@ rstto_image_get_width (RsttoImage *image)
 gint
 rstto_image_get_height (RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_val_if_fail (image != NULL, 0);
     g_return_val_if_fail (image->priv != NULL, 0);
 
@@ -553,7 +536,6 @@ rstto_image_get_height (RsttoImage *image)
 GdkPixbuf *
 rstto_image_get_thumbnail (RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_val_if_fail (image != NULL, NULL);
     g_return_val_if_fail (image->priv != NULL, NULL);
 
@@ -590,7 +572,6 @@ rstto_image_get_thumbnail (RsttoImage *image)
 GdkPixbuf *
 rstto_image_get_pixbuf (RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_val_if_fail (image != NULL, NULL);
     g_return_val_if_fail (image->priv != NULL, NULL);
 
@@ -607,7 +588,6 @@ rstto_image_get_pixbuf (RsttoImage *image)
 void
 rstto_image_set_pixbuf (RsttoImage *image, GdkPixbuf *pixbuf)
 {
-    g_debug ("%s", __FUNCTION__);
     if (image->priv->pixbuf)
         g_object_unref (image->priv->pixbuf);
 
@@ -625,7 +605,6 @@ rstto_image_set_pixbuf (RsttoImage *image, GdkPixbuf *pixbuf)
 gboolean
 rstto_image_push_transformation (RsttoImage *image, GObject *object, GError **error)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_val_if_fail (RSTTO_IS_IMAGE_TRANSFORMATION (object), FALSE);
     RsttoImageTransformation *transformation = RSTTO_IMAGE_TRANSFORMATION (object);
 
@@ -651,7 +630,6 @@ rstto_image_push_transformation (RsttoImage *image, GObject *object, GError **er
 gboolean
 rstto_image_pop_transformation (RsttoImage *image, GError **error)
 {
-    g_debug ("%s", __FUNCTION__);
     if (image->priv->transformations)
     {
         RsttoImageTransformation *transformation = image->priv->transformations->data;
@@ -684,13 +662,8 @@ rstto_image_pop_transformation (RsttoImage *image, GError **error)
 static void
 cb_rstto_image_size_prepared (GdkPixbufLoader *loader, gint width, gint height, RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     image->priv->width = width;
     image->priv->height = height;
-    image->priv->pixbuf_width = width;
-    image->priv->pixbuf_height = height;
-
-    rstto_image_set_state (image, RSTTO_IMAGE_STATE_PREVIEW_READY);
 
     if (image->priv->max_size > 0)
     {
@@ -699,7 +672,7 @@ cb_rstto_image_size_prepared (GdkPixbufLoader *loader, gint width, gint height,
     	    gdk_pixbuf_loader_set_size (loader, width*ratio, height*ratio);
     }
 
-    //g_signal_emit(G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_PREPARED], 0, image, NULL);
+    g_signal_emit(G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_PREPARED], 0, image, NULL);
 }
 
 /**
@@ -711,11 +684,9 @@ cb_rstto_image_size_prepared (GdkPixbufLoader *loader, gint width, gint height,
 static void
 cb_rstto_image_area_prepared (GdkPixbufLoader *loader, RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
 
     image->priv->animation = gdk_pixbuf_loader_get_animation (loader);
     image->priv->iter = gdk_pixbuf_animation_get_iter (image->priv->animation, NULL);
-
     if (image->priv->pixbuf)
     {
         g_object_unref(image->priv->pixbuf);
@@ -753,7 +724,6 @@ cb_rstto_image_area_prepared (GdkPixbufLoader *loader, RsttoImage *image)
 static void
 cb_rstto_image_closed (GdkPixbufLoader *loader, RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     g_return_if_fail (image != NULL);
     g_return_if_fail (RSTTO_IS_IMAGE (image));
     g_return_if_fail (loader == image->priv->loader);
@@ -764,29 +734,6 @@ cb_rstto_image_closed (GdkPixbufLoader *loader, RsttoImage *image)
     g_object_unref (image->priv->loader);
     image->priv->loader = NULL;
 
-    if (image->priv->load_cancelled)
-    {
-        if (image->priv->pixbuf)
-        {
-            g_object_unref (image->priv->pixbuf);
-            image->priv->pixbuf = NULL;
-        }
-
-        if (image->priv->animation)
-        {
-            g_object_unref (image->priv->animation);
-            image->priv->animation = NULL;
-        }
-
-        if (image->priv->iter)
-        {
-            g_object_unref (image->priv->iter);
-            image->priv->iter = NULL;
-        }
-        rstto_image_set_state (image, RSTTO_IMAGE_STATE_DEFAULT);
-        return;
-    }
-
    
     if (image->priv->pixbuf != NULL)
     {
@@ -801,7 +748,9 @@ cb_rstto_image_closed (GdkPixbufLoader *loader, RsttoImage *image)
 
             transform_iter = g_list_previous (transform_iter);
         }
-        rstto_image_set_state (image, RSTTO_IMAGE_STATE_READY);
+
+
+        g_signal_emit(G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_UPDATED], 0, image, NULL);
     }
 }
 
@@ -814,7 +763,6 @@ cb_rstto_image_closed (GdkPixbufLoader *loader, RsttoImage *image)
 static gboolean
 cb_rstto_image_update(RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     RsttoImageTransformation *transformation = NULL;
 
     if (image->priv->iter)
@@ -865,7 +813,6 @@ cb_rstto_image_update(RsttoImage *image)
 guint
 rstto_image_get_size (RsttoImage *image)
 {
-    g_debug ("%s", __FUNCTION__);
     GdkPixbuf *pixbuf = rstto_image_get_pixbuf (image);
     if (pixbuf)
     {
@@ -876,23 +823,3 @@ rstto_image_get_size (RsttoImage *image)
     }
     return 0;
 }
-
-RsttoImageState
-rstto_image_get_state (RsttoImage *image)
-{
-    return image->priv->state;
-}
-
-/**
- * rstto_image_set_state:
- * @image:
- * @state:
- *
- * TODO: verify state-changes
- */
-static void
-rstto_image_set_state (RsttoImage *image, RsttoImageState state)
-{
-    image->priv->state = state;
-    g_signal_emit (G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_STATE_CHANGED], 0, image, NULL);
-}
diff --git a/src/image.h b/src/image.h
index 8a89360..05b0846 100644
--- a/src/image.h
+++ b/src/image.h
@@ -31,15 +31,6 @@ typedef enum
   RSTTO_IMAGE_ORIENT_270,
 } RsttoImageOrientation;
 
-typedef enum
-{
-    RSTTO_IMAGE_STATE_DEFAULT = 0,
-    RSTTO_IMAGE_STATE_LOADING,
-    RSTTO_IMAGE_STATE_PREVIEW_READY,
-    RSTTO_IMAGE_STATE_READY,
-    RSTTO_IMAGE_STATE_COUNT
-} RsttoImageState;
-
 #define RSTTO_TYPE_IMAGE rstto_image_get_type()
 
 #define RSTTO_IMAGE(obj)( \
@@ -99,9 +90,6 @@ rstto_image_pop_transformation (RsttoImage *image, GError **error);
 void rstto_image_set_pixbuf (RsttoImage *image, GdkPixbuf *pixbuf);
 guint rstto_image_get_size (RsttoImage *image);
 
-RsttoImageState
-rstto_image_get_state (RsttoImage *image);
-
 G_END_DECLS
 
 #endif /* __RISTRETTO_IMAGE_H__ */
diff --git a/src/picture_viewer.c b/src/picture_viewer.c
index 15f34fb..59b6f30 100644
--- a/src/picture_viewer.c
+++ b/src/picture_viewer.c
@@ -130,7 +130,7 @@ cb_rstto_picture_viewer_value_changed(GtkAdjustment *, RsttoPictureViewer *);
 static void
 cb_rstto_picture_viewer_image_updated (RsttoImage *image, RsttoPictureViewer *viewer);
 static void
-cb_rstto_picture_viewer_image_state_changed (RsttoImage *image, RsttoPictureViewer *viewer);
+cb_rstto_picture_viewer_image_prepared (RsttoImage *image, RsttoPictureViewer *viewer);
 
 static gboolean 
 cb_rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer);
@@ -954,7 +954,6 @@ rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer, gboolean refres
 static gboolean 
 cb_rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer)
 {
-    g_debug ("%s", __FUNCTION__);
     GdkPixbuf *p_src_pixbuf = NULL;
     GdkPixbuf *p_tmp_pixbuf = NULL;
     gdouble *p_scale = NULL;
@@ -1015,7 +1014,7 @@ cb_rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer)
                     thumb_scale = (thumb_width / image_width);
                 }
                 else
-                    return FALSE;
+                    return;
                 break;
             default:
                 break;
@@ -1284,7 +1283,7 @@ rstto_picture_viewer_set_image (RsttoPictureViewer *viewer, RsttoImage *image)
     if (viewer->priv->image)
     {
         g_signal_handlers_disconnect_by_func (viewer->priv->image, cb_rstto_picture_viewer_image_updated, viewer);
-        g_signal_handlers_disconnect_by_func (viewer->priv->image, cb_rstto_picture_viewer_image_state_changed, viewer);
+        g_signal_handlers_disconnect_by_func (viewer->priv->image, cb_rstto_picture_viewer_image_prepared, viewer);
         g_object_unref (viewer->priv->image);
     }
 
@@ -1294,7 +1293,7 @@ rstto_picture_viewer_set_image (RsttoPictureViewer *viewer, RsttoImage *image)
     {
         g_object_ref (viewer->priv->image);
         g_signal_connect (G_OBJECT (viewer->priv->image), "updated", G_CALLBACK (cb_rstto_picture_viewer_image_updated), viewer);
-        g_signal_connect (G_OBJECT (viewer->priv->image), "state-changed", G_CALLBACK (cb_rstto_picture_viewer_image_state_changed), viewer);
+        g_signal_connect (G_OBJECT (viewer->priv->image), "prepared", G_CALLBACK (cb_rstto_picture_viewer_image_prepared), viewer);
 
         scale = g_object_get_data (G_OBJECT (viewer->priv->image), "viewer-scale");
         fit_to_screen = g_object_get_data (G_OBJECT (viewer->priv->image), "viewer-fit-to-screen");
@@ -1311,14 +1310,7 @@ rstto_picture_viewer_set_image (RsttoPictureViewer *viewer, RsttoImage *image)
             g_object_set_data (G_OBJECT (viewer->priv->image), "viewer-fit-to-screen", fit_to_screen);
         }
 
-        if (rstto_image_get_state (viewer->priv->image) == RSTTO_IMAGE_STATE_DEFAULT)
-        {
-            rstto_image_load (viewer->priv->image, FALSE, g_value_get_uint (&max_size), FALSE, NULL);
-        }
-        else
-        {
-            rstto_picture_viewer_queued_repaint (viewer, TRUE);
-        }
+        rstto_image_load (viewer->priv->image, FALSE, g_value_get_uint (&max_size), FALSE, NULL);
     }
     else
     {
@@ -1341,25 +1333,17 @@ cb_rstto_picture_viewer_image_updated (RsttoImage *image, RsttoPictureViewer *vi
 }
 
 /**
- * cb_rstto_picture_viewer_image_state_changed:
+ * cb_rstto_picture_viewer_image_prepared:
  * @image:
  * @viewer:
  *
  */
 static void
-cb_rstto_picture_viewer_image_state_changed (RsttoImage *image, RsttoPictureViewer *viewer)
+cb_rstto_picture_viewer_image_prepared (RsttoImage *image, RsttoPictureViewer *viewer)
 {
-    switch (rstto_image_get_state (image))
-    {
-        case RSTTO_IMAGE_STATE_PREVIEW_READY:
-            rstto_picture_viewer_set_state (viewer, RSTTO_PICTURE_VIEWER_STATE_PREVIEW);
-            rstto_picture_viewer_queued_repaint (viewer, TRUE);
-            break;
-        case RSTTO_IMAGE_STATE_READY:
-            rstto_picture_viewer_set_state (viewer, RSTTO_PICTURE_VIEWER_STATE_NORMAL);
-            rstto_picture_viewer_queued_repaint (viewer, TRUE);
-            break;
-    }
+    rstto_picture_viewer_set_state (viewer, RSTTO_PICTURE_VIEWER_STATE_PREVIEW);
+
+    rstto_picture_viewer_queued_repaint (viewer, TRUE);
 }
 
 /**


More information about the Xfce4-commits mailing list