[Xfce4-commits] <ristretto:ristretto-0.0> Implement preloading Fix bug with iter-clone operation - make sure it also gets the same position as the cloned iter

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


Updating branch refs/heads/ristretto-0.0
         to b9192a847107dfce64889adfd0a2dc5f97f31039 (commit)
       from d9be1e3096ae3b487f08d7a09e8d88fee8b9948f (commit)

commit b9192a847107dfce64889adfd0a2dc5f97f31039
Author: Stephan Arts <stephan at xfce.org>
Date:   Mon Jul 12 22:56:28 2010 +0200

    Implement preloading
    Fix bug with iter-clone operation - make sure it also gets the same position as the cloned iter

 src/image_list.c         |   30 +++++++++++++++++++++++++++++-
 src/main_window.c        |   16 ++++++++++++++++
 src/preferences_dialog.c |   41 +++++++++++++++++++----------------------
 src/settings.c           |   20 +++++++++-----------
 4 files changed, 73 insertions(+), 34 deletions(-)

diff --git a/src/image_list.c b/src/image_list.c
index 911d1cc..1a53d68 100644
--- a/src/image_list.c
+++ b/src/image_list.c
@@ -390,6 +390,10 @@ rstto_image_list_iter_new (RsttoImageList *nav, RsttoImage *image)
 
     iter = g_object_new(RSTTO_TYPE_IMAGE_LIST_ITER, NULL);
     iter->priv->image = image;
+    if (image)
+    {
+        g_object_ref (image);
+    }
     iter->priv->image_list = nav;
 
     return iter;
@@ -405,8 +409,13 @@ rstto_image_list_iter_find_image (RsttoImageListIter *iter, RsttoImage *image)
 
         if (iter->priv->image)
         {
+            g_object_unref (iter->priv->image);
             iter->priv->image = NULL;
         }
+        if (image)
+        {
+            g_object_ref (image);
+        }
         iter->priv->image = image;
 
         g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
@@ -429,7 +438,7 @@ rstto_image_list_iter_get_position (RsttoImageListIter *iter)
 RsttoImage *
 rstto_image_list_iter_get_image (RsttoImageListIter *iter)
 {
-    return RSTTO_IMAGE (iter->priv->image);
+    return iter->priv->image;
 }
 
 
@@ -440,10 +449,15 @@ rstto_image_list_iter_set_position (RsttoImageListIter *iter, gint pos)
 
     if (iter->priv->image)
     {
+        g_object_unref (iter->priv->image);
         iter->priv->image = NULL;
     }
 
     iter->priv->image = g_list_nth_data (iter->priv->image_list->priv->images, pos); 
+    if (iter->priv->image)
+    {
+        g_object_ref (iter->priv->image);
+    }
 
     g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
 }
@@ -459,6 +473,7 @@ rstto_image_list_iter_next (RsttoImageListIter *iter)
     if (iter->priv->image)
     {
         position = g_list_find (iter->priv->image_list->priv->images, iter->priv->image);
+        g_object_unref (iter->priv->image);
         iter->priv->image = NULL;
     }
 
@@ -482,6 +497,11 @@ rstto_image_list_iter_next (RsttoImageListIter *iter)
         g_object_unref (settings);
     }
 
+    if (iter->priv->image)
+    {
+        g_object_ref (iter->priv->image);
+    }
+
     g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
 }
 
@@ -497,6 +517,7 @@ rstto_image_list_iter_previous (RsttoImageListIter *iter)
     {
         position = g_list_find (iter->priv->image_list->priv->images, iter->priv->image);
         iter->priv->image = NULL;
+        g_object_unref (iter->priv->image);
     }
 
     position = g_list_previous (position);
@@ -519,6 +540,12 @@ rstto_image_list_iter_previous (RsttoImageListIter *iter)
         g_object_unref (settings);
     }
 
+    if (iter->priv->image)
+    {
+        g_object_ref (iter->priv->image);
+    }
+
+
     g_signal_emit (G_OBJECT (iter), rstto_image_list_iter_signals[RSTTO_IMAGE_LIST_ITER_SIGNAL_CHANGED], 0, NULL);
 }
 
@@ -526,6 +553,7 @@ RsttoImageListIter *
 rstto_image_list_iter_clone (RsttoImageListIter *iter)
 {
     RsttoImageListIter *new_iter = rstto_image_list_iter_new (iter->priv->image_list, iter->priv->image);
+    rstto_image_list_iter_set_position (new_iter, rstto_image_list_iter_get_position(iter));
 
     return new_iter;
 }
diff --git a/src/main_window.c b/src/main_window.c
index 2bace1e..d98dc56 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -1501,9 +1501,25 @@ cb_rstto_main_window_pause (GtkWidget *widget, RsttoMainWindow *window)
 static gboolean
 cb_rstto_main_window_play_slideshow (RsttoMainWindow *window)
 {
+    RsttoImageListIter *preload_iter = NULL;
+    GValue max_size = {0,};
+
     if (window->priv->playing)
     {
         rstto_image_list_iter_next (window->priv->iter);
+        if (rstto_settings_get_boolean_property(window->priv->settings_manager, "preload-images"))
+        {
+            g_value_init (&max_size, G_TYPE_UINT);
+            g_object_get_property (G_OBJECT(window->priv->settings_manager), "image-quality", &max_size);
+
+            preload_iter = rstto_image_list_iter_clone (window->priv->iter);   
+
+            rstto_image_list_iter_next (preload_iter);
+            rstto_image_load (rstto_image_list_iter_get_image (preload_iter), TRUE, g_value_get_uint (&max_size), TRUE, NULL);
+
+            g_value_reset(&max_size);
+            g_object_unref (preload_iter);
+        }
         rstto_main_window_image_list_iter_changed (window);
     }
     else
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 222399e..32f4345 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -45,7 +45,7 @@ cb_rstto_preferences_dialog_bgcolor_color_set (GtkColorButton *, gpointer);
 static void
 cb_rstto_preferences_dialog_cache_check_button_toggled (GtkToggleButton *, gpointer);
 static void
-cb_rstto_preferences_dialog_cache_preload_hscale_value_changed (GtkRange *range, 
+cb_rstto_preferences_dialog_cache_preload_check_button_toggled (GtkToggleButton *button, 
                                                                 gpointer user_data);
 static void
 cb_rstto_preferences_dialog_cache_spin_button_value_changed (GtkSpinButton *, gpointer);
@@ -143,8 +143,7 @@ struct _RsttoPreferencesDialogPriv
         GtkWidget *cache_check_button;
         GtkWidget *cache_alignment;
         GtkWidget *cache_spin_button;
-        GtkWidget *cache_preload_label;
-        GtkWidget *cache_preload_hscale;
+        GtkWidget *cache_preload_check_button;
     } cache_tab;
 };
 
@@ -179,7 +178,7 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
 {
     guint uint_image_quality;
     guint uint_cache_size;
-    guint uint_preload_images;
+    gboolean bool_preload_images;
     gboolean bool_enable_cache;
     gboolean bool_bgcolor_override;
     gchar *scrollwheel_primary_action;
@@ -212,7 +211,7 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
                   "image-quality", &uint_image_quality,
                   "cache-size", &uint_cache_size,
                   "show-preview", &bool_show_preview,
-                  "preload-images", &uint_preload_images,
+                  "preload-images", &bool_preload_images,
                   "enable-cache", &bool_enable_cache,
                   "bgcolor-override", &bool_bgcolor_override,
                   "bgcolor", &bgcolor,
@@ -471,11 +470,7 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
     gtk_alignment_set_padding (GTK_ALIGNMENT (dialog->priv->cache_tab.cache_alignment), 0, 0, 20, 0);
     dialog->priv->cache_tab.cache_spin_button = gtk_spin_button_new(GTK_ADJUSTMENT(cache_adjustment), 1.0, 0);
 
-    dialog->priv->cache_tab.cache_preload_label = gtk_label_new (_("Preload images"));
-    gtk_misc_set_alignment(GTK_MISC(dialog->priv->cache_tab.cache_preload_label), 0, 0.5);
-    gtk_misc_set_padding(GTK_MISC(dialog->priv->cache_tab.cache_preload_label), 2, 2);
-    dialog->priv->cache_tab.cache_preload_hscale = gtk_hscale_new_with_range(0, 50, 1);
-    gtk_scale_set_value_pos (GTK_SCALE (dialog->priv->cache_tab.cache_preload_hscale), GTK_POS_LEFT);
+    dialog->priv->cache_tab.cache_preload_check_button = gtk_check_button_new_with_label (_("Enable preloading"));
 
     gtk_box_pack_start (GTK_BOX (dialog->priv->cache_tab.cache_hbox), 
                                  dialog->priv->cache_tab.cache_size_label, FALSE, FALSE, 0);
@@ -494,9 +489,7 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
     gtk_box_pack_start (GTK_BOX (dialog->priv->cache_tab.cache_sub_vbox), 
                                  dialog->priv->cache_tab.cache_hbox, FALSE, FALSE, 0);
     gtk_box_pack_start (GTK_BOX (dialog->priv->cache_tab.cache_sub_vbox), 
-                                 dialog->priv->cache_tab.cache_preload_label, FALSE, FALSE, 0);
-    gtk_box_pack_start (GTK_BOX (dialog->priv->cache_tab.cache_sub_vbox), 
-                                 dialog->priv->cache_tab.cache_preload_hscale, FALSE, FALSE, 0);
+                                 dialog->priv->cache_tab.cache_preload_check_button, FALSE, FALSE, 0);
     
     /* set current value */
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->cache_tab.cache_check_button),
@@ -504,9 +497,6 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
     gtk_widget_set_sensitive (GTK_WIDGET (dialog->priv->cache_tab.cache_sub_vbox),
                               bool_enable_cache);
 
-    gtk_range_set_value ( GTK_RANGE(dialog->priv->cache_tab.cache_preload_hscale),
-                                  uint_preload_images);
-
     if (uint_cache_size < RSTTO_MIN_CACHE_SIZE)
     {
         gtk_adjustment_set_value (GTK_ADJUSTMENT (cache_adjustment), RSTTO_DEFAULT_CACHE_SIZE);
@@ -519,8 +509,8 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
     /* connect signals */
     g_signal_connect (G_OBJECT (dialog->priv->cache_tab.cache_check_button), 
                       "toggled", (GCallback)cb_rstto_preferences_dialog_cache_check_button_toggled, dialog);
-    g_signal_connect (G_OBJECT (dialog->priv->cache_tab.cache_preload_hscale), 
-                      "value-changed", (GCallback)cb_rstto_preferences_dialog_cache_preload_hscale_value_changed, dialog);
+    g_signal_connect (G_OBJECT (dialog->priv->cache_tab.cache_check_button), 
+                      "toggled", (GCallback)cb_rstto_preferences_dialog_cache_preload_check_button_toggled, dialog);
     g_signal_connect (G_OBJECT (dialog->priv->cache_tab.cache_spin_button), 
                       "value-changed", (GCallback)cb_rstto_preferences_dialog_cache_spin_button_value_changed, dialog);
 
@@ -613,17 +603,24 @@ cb_rstto_preferences_dialog_cache_check_button_toggled (GtkToggleButton *button,
 }
 
 static void
-cb_rstto_preferences_dialog_cache_preload_hscale_value_changed (GtkRange *range, 
+cb_rstto_preferences_dialog_cache_preload_check_button_toggled (GtkToggleButton *button, 
                                                                 gpointer user_data)
 {
     RsttoPreferencesDialog *dialog = RSTTO_PREFERENCES_DIALOG (user_data);
 
     GValue value = {0, };
-    g_value_init (&value, G_TYPE_UINT);
-
-    g_value_set_uint (&value, gtk_range_get_value (range));
+    g_value_init (&value, G_TYPE_BOOLEAN);
+    if (gtk_toggle_button_get_active (button))
+    {
+        g_value_set_boolean (&value, TRUE);
+    }
+    else
+    {
+        g_value_set_boolean (&value, FALSE);
+    }
 
     g_object_set_property (G_OBJECT (dialog->priv->settings), "preload-images", &value);
+
     g_value_unset (&value);
 }
 
diff --git a/src/settings.c b/src/settings.c
index 3a3d359..a602b97 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -115,7 +115,7 @@ struct _RsttoSettingsPriv
     gboolean  hide_thumbnailbar_fullscreen;
     gboolean  open_entire_folder;
     gchar    *navigationbar_position;
-    guint     preload_images;
+    gboolean  preload_images;
     gboolean  enable_cache;
     guint     cache_size;
     guint     image_quality;
@@ -183,7 +183,7 @@ rstto_settings_init (GObject *object)
     xfconf_g_property_bind (settings->priv->channel, "/window/bgcolor-override", G_TYPE_BOOLEAN, settings, "bgcolor-override");
 
     xfconf_g_property_bind_gdkcolor (settings->priv->channel, "/window/bgcolor-fullscreen", settings, "bgcolor-fullscreen");
-    xfconf_g_property_bind (settings->priv->channel, "/image/preload", G_TYPE_UINT, settings, "preload-images");
+    xfconf_g_property_bind (settings->priv->channel, "/image/preload", G_TYPE_BOOLEAN, settings, "preload-images");
     xfconf_g_property_bind (settings->priv->channel, "/image/cache", G_TYPE_BOOLEAN, settings, "enable-cache");
     xfconf_g_property_bind (settings->priv->channel, "/image/cache-size", G_TYPE_UINT, settings, "cache-size");
     xfconf_g_property_bind (settings->priv->channel, "/image/quality", G_TYPE_UINT, settings, "image-quality");
@@ -292,13 +292,11 @@ rstto_settings_class_init (GObjectClass *object_class)
                                      PROP_SHOW_PREVIEW,
                                      pspec);
 
-    pspec = g_param_spec_uint ("preload-images",
-                               "",
-                               "",
-                               0,
-                               50,
-                               0,
-                               G_PARAM_READWRITE);
+    pspec = g_param_spec_boolean ("preload-images",
+                                  "",
+                                  "",
+                                  TRUE,
+                                  G_PARAM_READWRITE);
     g_object_class_install_property (object_class,
                                      PROP_PRELOAD_IMAGES,
                                      pspec);
@@ -526,7 +524,7 @@ rstto_settings_set_property    (GObject      *object,
             settings->priv->show_preview = g_value_get_boolean (value);
             break;
         case PROP_PRELOAD_IMAGES:
-            settings->priv->preload_images = g_value_get_uint (value);
+            settings->priv->preload_images = g_value_get_boolean (value);
             break;
         case PROP_ENABLE_CACHE:
             settings->priv->enable_cache = g_value_get_boolean (value);
@@ -620,7 +618,7 @@ rstto_settings_get_property    (GObject    *object,
             g_value_set_boolean (value, settings->priv->show_preview);
             break;
         case PROP_PRELOAD_IMAGES:
-            g_value_set_uint (value, settings->priv->preload_images);
+            g_value_set_boolean (value, settings->priv->preload_images);
             break;
         case PROP_ENABLE_CACHE:
             g_value_set_boolean (value, settings->priv->enable_cache);


More information about the Xfce4-commits mailing list