[Xfce4-commits] <ristretto:ristretto-0.0> Images can only be opened once

Stephan Arts noreply at xfce.org
Sun Oct 23 19:21:43 CEST 2011


Updating branch refs/heads/ristretto-0.0
         to 062b0f1f7443308430ec246387e3408a79a1e8d7 (commit)
       from 2366de5be112bf8a9883f40436ad6c0904bd9d34 (commit)

commit 062b0f1f7443308430ec246387e3408a79a1e8d7
Author: Stephan Arts <stephan at xfce.org>
Date:   Sat Sep 26 10:16:46 2009 +0200

    Images can only be opened once

 ChangeLog           |    6 +++++
 src/image_list.c    |   57 +++++++++++++++++++++++++++++++++++++-------------
 src/main_window.c   |   21 ++++++++++++++++++
 src/thumbnail_bar.c |    7 ++++++
 4 files changed, 76 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 176c2e1..8aea31a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-09-26  Stephan Arts <stephan at xfce.org>
 
+	* src/main_window.c,
+	  src/image_list.c,
+	  src/thumbnailbar.c: Images can only be opened once
+
+2009-09-26  Stephan Arts <stephan at xfce.org>
+
 	* src/wallpaper_manager.h,
 	  src/wallpaper_manager.c,
 	  src/main_window.c,
diff --git a/src/image_list.c b/src/image_list.c
index 08eaebf..ac16f77 100644
--- a/src/image_list.c
+++ b/src/image_list.c
@@ -5,7 +5,8 @@
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
- * *  This program is distributed in the hope that it will be useful,
+ *
+ *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU Library General Public License for more details.
@@ -47,6 +48,8 @@ static gint
 cb_rstto_image_list_image_name_compare_func (RsttoImage *a, RsttoImage *b);
 static gint
 cb_rstto_image_list_exif_date_compare_func (RsttoImage *a, RsttoImage *b);
+static gint
+cb_rstto_image_list_file_compare_func (RsttoImage *a, GFile *file);
 
 static GObjectClass *parent_class = NULL;
 static GObjectClass *iter_parent_class = NULL;
@@ -181,26 +184,36 @@ rstto_image_list_new (void)
 gboolean
 rstto_image_list_add_file (RsttoImageList *image_list, GFile *file, GError **error)
 {
-    RsttoImage *image = rstto_image_new (file);
-    if (image)
-    {
-        image_list->priv->images = g_list_insert_sorted (image_list->priv->images, image, rstto_image_list_get_compare_func (image_list));
-        image_list->priv->n_images++;
+    RsttoImage *image = NULL;
+
+    GList *image_iter = g_list_find_custom (image_list->priv->images, file, (GCompareFunc)cb_rstto_image_list_file_compare_func);
 
-        g_signal_emit (G_OBJECT (image_list), rstto_image_list_signals[RSTTO_IMAGE_LIST_SIGNAL_NEW_IMAGE], 0, image, NULL);
-        if (image_list->priv->n_images == 1)
+    if (!image_iter)
+    {
+        image = rstto_image_new (file);
+        if (image)
         {
-            /** TODO: update all iterators */
-            GSList *iter = image_list->priv->iterators;
-            while (iter)
+            image_list->priv->images = g_list_insert_sorted (image_list->priv->images, image, rstto_image_list_get_compare_func (image_list));
+            image_list->priv->n_images++;
+
+            g_signal_emit (G_OBJECT (image_list), rstto_image_list_signals[RSTTO_IMAGE_LIST_SIGNAL_NEW_IMAGE], 0, image, NULL);
+            if (image_list->priv->n_images == 1)
             {
-                g_signal_emit (G_OBJECT (iter->data), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
-                iter = g_slist_next (iter);
+                /** TODO: update all iterators */
+                GSList *iter = image_list->priv->iterators;
+                while (iter)
+                {
+                    g_signal_emit (G_OBJECT (iter->data), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
+                    iter = g_slist_next (iter);
+                }
             }
+            return TRUE;
         }
-        return TRUE;
+        return FALSE;
     }
-    return FALSE;
+    g_signal_emit (G_OBJECT (image_list), rstto_image_list_signals[RSTTO_IMAGE_LIST_SIGNAL_NEW_IMAGE], 0, image_iter->data, NULL);
+
+    return TRUE;
 }
 
 gint
@@ -570,3 +583,17 @@ cb_rstto_image_list_exif_date_compare_func (RsttoImage *a, RsttoImage *b)
     g_object_unref (file_info_b);
     return result;
 }
+
+static gint
+cb_rstto_image_list_file_compare_func (RsttoImage *a, GFile *file)
+{
+    gchar *a_base = g_file_get_uri (rstto_image_get_file (a));  
+    gchar *b_base = g_file_get_uri (file);  
+    gint result = 0;
+
+    result = g_strcasecmp (a_base, b_base);
+
+    g_free (a_base);
+    g_free (b_base);
+    return result;
+}
diff --git a/src/main_window.c b/src/main_window.c
index a1615e5..e286b95 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -64,6 +64,7 @@ struct _RsttoMainWindowPriv
 
     guint show_fs_toolbar_timeout_id;
     gint window_save_geometry_timer_id;
+    gint open_image_timer_id;
     
     gboolean fs_toolbar_sticky;
 
@@ -138,6 +139,8 @@ rstto_main_window_get_property (GObject    *object,
 
 static gboolean
 rstto_window_save_geometry_timer (gpointer user_data);
+static gboolean
+rstto_window_open_image_timer(gpointer user_data);
 static void
 rstto_main_window_image_list_iter_changed (RsttoMainWindow *window);
 
@@ -1075,6 +1078,14 @@ rstto_window_save_geometry_timer (gpointer user_data)
     return FALSE;
 }
 
+static gboolean
+rstto_window_open_image_timer (gpointer user_data)
+{
+    RsttoMainWindow *window = RSTTO_MAIN_WINDOW (user_data);
+    window->priv->open_image_timer_id = 0;
+    return FALSE;
+}
+
 static void
 rstto_main_window_set_navigationbar_position (RsttoMainWindow *window, guint orientation)
 {
@@ -1601,6 +1612,16 @@ cb_rstto_main_window_image_list_new_image (RsttoImageList *image_list, RsttoImag
 {
     if (rstto_image_list_iter_get_position (window->priv->iter) == -1)
         rstto_image_list_iter_set_position (window->priv->iter, 0);
+    if (window->priv->open_image_timer_id > 0)
+    {
+        g_source_remove (window->priv->open_image_timer_id);
+    }
+    else
+    {
+        rstto_image_list_iter_find_image (window->priv->iter, image);
+    }
+    window->priv->open_image_timer_id = g_timeout_add (
+            1000, rstto_window_open_image_timer, window);
     rstto_main_window_image_list_iter_changed (window);
 }
 
diff --git a/src/thumbnail_bar.c b/src/thumbnail_bar.c
index fe1d22b..8711604 100644
--- a/src/thumbnail_bar.c
+++ b/src/thumbnail_bar.c
@@ -777,9 +777,16 @@ cb_rstto_thumbnail_bar_image_list_new_image (RsttoImageList *image_list, RsttoIm
 {
     RsttoThumbnailBar *bar = RSTTO_THUMBNAIL_BAR (user_data);
     GtkWidget *thumb;
+    GList *iter;
 
     g_return_if_fail (rstto_image_list_iter_find_image (bar->priv->internal_iter, image));
 
+    for (iter = bar->priv->thumbs; iter != NULL; iter = g_list_next (iter))
+    {
+        if (image == rstto_thumbnail_get_image (iter->data))
+            return;
+    }
+
     thumb = rstto_thumbnail_new (image);
 
     gtk_container_add (GTK_CONTAINER (bar), thumb);


More information about the Xfce4-commits mailing list