[Xfce4-commits] <ristretto:ristretto-0.0> Add a wrap-images option and prevent the iterators from jumping to the start or end of the image-list when an image is removed

Stephan Arts noreply at xfce.org
Sun Oct 23 19:22:41 CEST 2011


Updating branch refs/heads/ristretto-0.0
         to 735d8fd9583ca1d123c9d0d3e273b51720f2f5ff (commit)
       from 90f3cc5e0b5941e613defb37160c40d23d952eca (commit)

commit 735d8fd9583ca1d123c9d0d3e273b51720f2f5ff
Author: Stephan Arts <stephan at xfce.org>
Date:   Sat Oct 24 04:41:55 2009 +0200

    Add a wrap-images option and prevent the iterators from jumping to the start or end of the image-list when an image is removed

 ChangeLog        |    7 +++++++
 src/image_list.c |   39 ++++++++++++++++++++++++++++++++++++---
 src/image_list.h |    3 +++
 3 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c0e2a5b..c98fe84 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,13 @@
 
 	* src/image_cache.c: Make image-cache cache one less image to prevent it
 	  from exceeding the maximum-size.
+	* src/image_list.c: Move the iterators around before removing the image
+	  from the image-list, this prevents the iterators from jumping to the
+	  start or end of the list.
+	* src/image_list.c
+	  src/image_list.h,
+	  src/settings.c: Add a wrap-images setting
+
 
 2009-10-16  Stephan Arts <stephan at xfce.org>
 
diff --git a/src/image_list.c b/src/image_list.c
index ac16f77..34c8d65 100644
--- a/src/image_list.c
+++ b/src/image_list.c
@@ -27,6 +27,7 @@
 
 #include "image.h"
 #include "image_list.h"
+#include "settings.h"
 
 static void 
 rstto_image_list_init(RsttoImageList *);
@@ -82,6 +83,8 @@ struct _RsttoImageListPriv
 
     GSList *iterators;
     GCompareFunc cb_rstto_image_list_compare_func;
+
+    gboolean wrap_images;
 };
 
 static gint rstto_image_list_signals[RSTTO_IMAGE_LIST_SIGNAL_COUNT];
@@ -116,8 +119,13 @@ rstto_image_list_get_type (void)
 static void
 rstto_image_list_init(RsttoImageList *image_list)
 {
+    RsttoSettings *settings = rstto_settings_new();
+
     image_list->priv = g_new0 (RsttoImageListPriv, 1);
     image_list->priv->cb_rstto_image_list_compare_func = (GCompareFunc)cb_rstto_image_list_image_name_compare_func;
+
+    image_list->priv->wrap_images = rstto_settings_get_boolean_property (settings, "wrap-images");
+    g_object_unref (settings);
 }
 
 static void
@@ -253,7 +261,6 @@ rstto_image_list_remove_image (RsttoImageList *image_list, RsttoImage *image)
 
     if (g_list_find (image_list->priv->images, image))
     {
-        image_list->priv->images = g_list_remove (image_list->priv->images, image);
 
         iter = image_list->priv->iterators;
         while (iter)
@@ -264,6 +271,18 @@ rstto_image_list_remove_image (RsttoImageList *image_list, RsttoImage *image)
             }
             iter = g_slist_next (iter);
         }
+
+        image_list->priv->images = g_list_remove (image_list->priv->images, image);
+        iter = image_list->priv->iterators;
+        while (iter)
+        {
+            if (rstto_image_list_iter_get_image (iter->data) == image)
+            {
+                rstto_image_list_iter_previous (iter->data);
+            }
+            iter = g_slist_next (iter);
+        }
+
         g_signal_emit (G_OBJECT (image_list), rstto_image_list_signals[RSTTO_IMAGE_LIST_SIGNAL_REMOVE_IMAGE], 0, image, NULL);
         g_object_unref (image);
     }
@@ -453,7 +472,11 @@ rstto_image_list_iter_next (RsttoImageListIter *iter)
         iter->priv->image = position->data; 
     else
     {
-        position = g_list_first (iter->priv->image_list->priv->images);
+        if (rstto_image_list_get_wrap_images (iter->priv->image_list))
+            position = g_list_first (iter->priv->image_list->priv->images);
+        else
+            position = g_list_last (iter->priv->image_list->priv->images);
+
         if (position)
             iter->priv->image = position->data; 
         else
@@ -481,7 +504,11 @@ rstto_image_list_iter_previous (RsttoImageListIter *iter)
         iter->priv->image = position->data; 
     else
     {
-        position = g_list_last (iter->priv->image_list->priv->images);
+        if (rstto_image_list_get_wrap_images (iter->priv->image_list))
+            position = g_list_last (iter->priv->image_list->priv->images);
+        else
+            position = g_list_first (iter->priv->image_list->priv->images);
+
         if (position)
             iter->priv->image = position->data; 
         else
@@ -597,3 +624,9 @@ cb_rstto_image_list_file_compare_func (RsttoImage *a, GFile *file)
     g_free (b_base);
     return result;
 }
+
+gboolean
+rstto_image_list_get_wrap_images (RsttoImageList *image_list)
+{
+    return image_list->priv->wrap_images;
+}
diff --git a/src/image_list.h b/src/image_list.h
index 901831b..f1c8145 100644
--- a/src/image_list.h
+++ b/src/image_list.h
@@ -98,6 +98,9 @@ RsttoImageList *rstto_image_list_new ();
 gint     rstto_image_list_get_n_images (RsttoImageList *image_list);
 gboolean rstto_image_list_add_file (RsttoImageList *image_list, GFile *file, GError **);
 
+gboolean
+rstto_image_list_get_wrap_images (RsttoImageList *image_list);
+
 
 GCompareFunc rstto_image_list_get_compare_func (RsttoImageList *image_list);
 void         rstto_image_list_set_compare_func (RsttoImageList *image_list, GCompareFunc func);


More information about the Xfce4-commits mailing list