[Goodies-commits] r5261 - ristretto/trunk/src

Stephan Arts stephan at xfce.org
Sun Aug 17 01:34:49 CEST 2008


Author: stephan
Date: 2008-08-16 23:34:49 +0000 (Sat, 16 Aug 2008)
New Revision: 5261

Modified:
   ristretto/trunk/src/main.c
   ristretto/trunk/src/main_window.c
   ristretto/trunk/src/navigator.c
Log:
- Applied a slightly modified patch from Philip Guo <pg AT cs DOT stanford DOT edu> -- improves preloading
- Fix compile-warning
- Improved history behaviour (push 'old' images to the top when they are visited again)



Modified: ristretto/trunk/src/main.c
===================================================================
--- ristretto/trunk/src/main.c	2008-08-16 22:00:52 UTC (rev 5260)
+++ ristretto/trunk/src/main.c	2008-08-16 23:34:49 UTC (rev 5261)
@@ -265,7 +265,7 @@
     gint slideshow_timeout = xfce_rc_read_int_entry(xfce_rc, "SlideShowTimeout", 5000);
     gboolean slideshow_hide_thumbnail = xfce_rc_read_bool_entry(xfce_rc, "SlideShowHideThumbnail", TRUE);
     gint max_cache = xfce_rc_read_int_entry(xfce_rc, "MaxImagesCacheSize", 64);
-    gboolean preload_during_slideshow = xfce_rc_read_bool_entry (xfce_rc, "PreloadDuringSlideShow", FALSE);
+    gboolean preload_imgs = xfce_rc_read_bool_entry (xfce_rc, "PreloadImgs", FALSE);
     gboolean override_bg_color = xfce_rc_read_bool_entry (xfce_rc, "OverrideBgColor", FALSE);
     gboolean scale_to_100 = xfce_rc_read_bool_entry (xfce_rc, "ScaleTo100", FALSE);
 
@@ -284,7 +284,7 @@
 
     RsttoNavigator *navigator = rstto_main_window_get_navigator(RSTTO_MAIN_WINDOW(window));
 
-    navigator->preload = preload_during_slideshow;
+    navigator->preload = preload_imgs;
 
     rstto_main_window_set_max_cache_size(RSTTO_MAIN_WINDOW(window), max_cache);
     rstto_main_window_set_slideshow_timeout(RSTTO_MAIN_WINDOW(window), (gdouble)slideshow_timeout);
@@ -346,7 +346,7 @@
 
     xfce_rc_write_bool_entry(xfce_rc, "ShowToolBar", rstto_main_window_get_show_toolbar(RSTTO_MAIN_WINDOW(window)));
     xfce_rc_write_bool_entry(xfce_rc, "ScaleTo100", rstto_main_window_get_scale_to_100(RSTTO_MAIN_WINDOW(window)));
-    xfce_rc_write_bool_entry(xfce_rc, "PreloadDuringSlideShow", navigator->preload);
+    xfce_rc_write_bool_entry(xfce_rc, "PreloadImgs", navigator->preload);
     xfce_rc_write_bool_entry(xfce_rc, "ShowThumbnailViewer", rstto_main_window_get_show_thumbnail_viewer(RSTTO_MAIN_WINDOW(window)));
     if (bg_color)
     {

Modified: ristretto/trunk/src/main_window.c
===================================================================
--- ristretto/trunk/src/main_window.c	2008-08-16 22:00:52 UTC (rev 5260)
+++ ristretto/trunk/src/main_window.c	2008-08-16 23:34:49 UTC (rev 5261)
@@ -934,7 +934,7 @@
             if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_YES)
             {
                 gtk_widget_hide(dialog);
-                GtkWidget *save_dialog = rstto_save_dialog_new (window, modified_files);
+                GtkWidget *save_dialog = rstto_save_dialog_new (GTK_WINDOW(window), modified_files);
                 gtk_dialog_run (GTK_DIALOG(save_dialog));
             }
         }
@@ -1434,17 +1434,17 @@
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), notebook,  TRUE, TRUE, 0);
 
 /** Add notebook pages */
-    behaviour_main_vbox = gtk_vbox_new(FALSE, 0);
-    behaviour_main_lbl = gtk_label_new(_("Behaviour"));
-    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), behaviour_main_vbox, behaviour_main_lbl);
+    display_main_vbox = gtk_vbox_new(FALSE, 0);
+    display_main_lbl = gtk_label_new(_("Display"));
+    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), display_main_vbox, display_main_lbl);
 
     slideshow_main_vbox = gtk_vbox_new(FALSE, 0);
     slideshow_main_lbl = gtk_label_new(_("Slideshow"));
     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), slideshow_main_vbox, slideshow_main_lbl);
 
-    display_main_vbox = gtk_vbox_new(FALSE, 0);
-    display_main_lbl = gtk_label_new(_("Display"));
-    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), display_main_vbox, display_main_lbl);
+    behaviour_main_vbox = gtk_vbox_new(FALSE, 0);
+    behaviour_main_lbl = gtk_label_new(_("Behaviour"));
+    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), behaviour_main_vbox, behaviour_main_lbl);
 
 /** Add content for behaviour page */
     resize_to_content_vbox = gtk_vbox_new(FALSE, 0);
@@ -1491,67 +1491,55 @@
     cache_label = gtk_label_new(_("Cache size:"));
     cache_mb_label = gtk_label_new(_("MB"));
 
+    GtkWidget *preload_check = gtk_check_button_new_with_mnemonic(_("_Preload images (GUI more responsive but more CPU-intensive)"));
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(preload_check), window->priv->navigator->preload);
+
     gtk_box_pack_start(GTK_BOX(cache_hbox), cache_label, FALSE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(cache_hbox), cache_spin_button, FALSE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(cache_hbox), cache_mb_label, FALSE, FALSE, 0);
     gtk_box_pack_start(GTK_BOX(cache_vbox), cache_hbox, FALSE, FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(cache_vbox), preload_check, FALSE, FALSE, 0);
 
-
     gtk_container_set_border_width (GTK_CONTAINER (bg_color_frame), 8);
     gtk_container_set_border_width (GTK_CONTAINER (cache_frame), 8);
 
     gtk_box_pack_start(GTK_BOX(display_main_vbox), bg_color_frame, FALSE, TRUE, 0);
     gtk_box_pack_start(GTK_BOX(display_main_vbox), cache_frame, FALSE, TRUE, 0);
 
+
 /** Add content for slideshow page */
     GtkWidget *slideshow_vbox = gtk_vbox_new(FALSE, 0);
     GtkWidget *slideshow_frame = xfce_create_framebox_with_content (_("Timeout"), slideshow_vbox);
 
-    GtkWidget *preload_vbox = gtk_vbox_new(FALSE, 0);
-    GtkWidget *preload_frame = xfce_create_framebox_with_content (_("Preload"), preload_vbox);
-
     GtkWidget *thumbnails_vbox = gtk_vbox_new(FALSE, 0);
     GtkWidget *thumbnails_frame = xfce_create_framebox_with_content (_("Thumbnails"), thumbnails_vbox);
 
     gtk_container_set_border_width (GTK_CONTAINER (slideshow_frame), 8);
     gtk_container_set_border_width (GTK_CONTAINER (thumbnails_frame), 8);
-    gtk_container_set_border_width (GTK_CONTAINER (preload_frame), 8);
 
     GtkWidget *slideshow_lbl = gtk_label_new(_("The time period an individual image is displayed during a slideshow\n(in seconds)"));
     GtkWidget *slideshow_hscale = gtk_hscale_new_with_range(1, 60, 1);
 
-
-    GtkWidget *preload_lbl = gtk_label_new(_("Preload images during slideshow\n(uses more memory)"));
-    GtkWidget *preload_check = gtk_check_button_new_with_mnemonic(_("_Preload images"));
-
     GtkWidget *thumbnails_lbl = gtk_label_new(_("Hide the thumbnails bar during slideshow"));
     GtkWidget *thumbnails_check = gtk_check_button_new_with_mnemonic(_("_Hide thumbnails"));
 
     gtk_misc_set_alignment(GTK_MISC(slideshow_lbl), 0, 0.5);
-    gtk_misc_set_alignment(GTK_MISC(preload_lbl), 0, 0.5);
     gtk_misc_set_alignment(GTK_MISC(thumbnails_lbl), 0, 0.5);
 
     gtk_misc_set_padding(GTK_MISC(slideshow_lbl), 2, 2);
-    gtk_misc_set_padding(GTK_MISC(preload_lbl), 2, 2);
     gtk_misc_set_padding(GTK_MISC(thumbnails_lbl), 2, 2);
     
     gtk_range_set_value(GTK_RANGE(slideshow_hscale), window->priv->settings.slideshow_timeout / 1000);
 
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(preload_check), window->priv->navigator->preload);
-
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(thumbnails_check), window->priv->settings.slideshow_hide_thumbnail);
 
     gtk_box_pack_start(GTK_BOX(slideshow_vbox), slideshow_lbl, TRUE, TRUE, 0);
     gtk_box_pack_start(GTK_BOX(slideshow_vbox), slideshow_hscale, FALSE, TRUE, 0);
 
-    gtk_box_pack_start(GTK_BOX(preload_vbox), preload_lbl, TRUE, TRUE, 0);
-    gtk_box_pack_start(GTK_BOX(preload_vbox), preload_check, FALSE, TRUE, 0);
-
     gtk_box_pack_start(GTK_BOX(thumbnails_vbox), thumbnails_lbl, TRUE, TRUE, 0);
     gtk_box_pack_start(GTK_BOX(thumbnails_vbox), thumbnails_check, FALSE, TRUE, 0);
 
     gtk_box_pack_start(GTK_BOX(slideshow_main_vbox), slideshow_frame, FALSE, TRUE, 0);
-    gtk_box_pack_start(GTK_BOX(slideshow_main_vbox), preload_frame, FALSE, TRUE, 0);
     gtk_box_pack_start(GTK_BOX(slideshow_main_vbox), thumbnails_frame, FALSE, TRUE, 0);
 
     gtk_widget_show_all(notebook);

Modified: ristretto/trunk/src/navigator.c
===================================================================
--- ristretto/trunk/src/navigator.c	2008-08-16 22:00:52 UTC (rev 5260)
+++ ristretto/trunk/src/navigator.c	2008-08-16 23:34:49 UTC (rev 5261)
@@ -264,47 +264,22 @@
     return g_strcasecmp(a->info->display_name, b->info->display_name);
 }
 
-void
-rstto_navigator_guard_history(RsttoNavigator *navigator, RsttoNavigatorEntry *entry)
+
+static void
+rstto_navigator_add_entry_to_history(RsttoNavigator *navigator, RsttoNavigatorEntry *entry)
 {
-    /* check if the image is still loading, if so... don't cache the image */
-    if(entry->io_channel)
-    {
-        g_source_remove(entry->io_source_id);
-        g_io_channel_unref(entry->io_channel);
-        entry->io_channel = NULL;
-        entry->io_source_id = 0;
-        if(entry->loader)
-        {
-            g_signal_handlers_disconnect_by_func(entry->loader , cb_rstto_navigator_entry_area_prepared, entry);
-            gdk_pixbuf_loader_close(entry->loader, NULL);
-        }
 
-        if (entry->timeout_id)
-        {
-            g_source_remove(entry->timeout_id);
-            entry->timeout_id = 0;
-        }
+    /* rstto_debug_print_src_pixbufs(navigator); */
 
-        if(entry->animation)
-        {
-            g_object_unref(entry->animation);
-            entry->animation = NULL;
-        }
-
-        if(entry->src_pixbuf)
-        {
-            gdk_pixbuf_unref(entry->src_pixbuf);
-            entry->src_pixbuf = NULL;
-        }
-    }
-
-    /* add image to the cache-history */
-    if (g_list_index(navigator->history, entry) == -1)
+    /* Check if the image is already available in the image-cache */
+    if (g_list_index(navigator->history, entry) != -1)
     {
-        navigator->history = g_list_prepend(navigator->history, entry);
+        /* Remove the image from the history, we are going to re-add it at the front of the list later */
+        navigator->history = g_list_remove(navigator->history, entry);
     }
+    navigator->history = g_list_prepend(navigator->history, entry);
 
+    /* manage history by kicking excess elements out */
     GList *iter = NULL;
     guint64 size = 0;
 
@@ -346,7 +321,118 @@
     }
 }
 
+
 void
+rstto_navigator_guard_history(RsttoNavigator *navigator, RsttoNavigatorEntry *entry)
+{
+    /* check if the image is still loading, if so... don't cache the image */
+    if(entry->io_channel)
+    {
+        g_source_remove(entry->io_source_id);
+        g_io_channel_unref(entry->io_channel);
+        entry->io_channel = NULL;
+        entry->io_source_id = 0;
+        if(entry->loader)
+        {
+            g_signal_handlers_disconnect_by_func(entry->loader , cb_rstto_navigator_entry_area_prepared, entry);
+            gdk_pixbuf_loader_close(entry->loader, NULL);
+        }
+
+        if (entry->timeout_id)
+        {
+            g_source_remove(entry->timeout_id);
+            entry->timeout_id = 0;
+        }
+
+        if(entry->animation)
+        {
+            g_object_unref(entry->animation);
+            entry->animation = NULL;
+        }
+
+        if(entry->src_pixbuf)
+        {
+            gdk_pixbuf_unref(entry->src_pixbuf);
+            entry->src_pixbuf = NULL;
+        }
+    }
+
+    rstto_navigator_add_entry_to_history(navigator, entry);
+}
+
+/* for debugging:
+ * iterate through navigator->file_list and print out all
+ * pixbuf entries to see whether they've been loaded or not
+ */
+void
+rstto_debug_print_src_pixbufs (RsttoNavigator *navigator)
+{
+    GList *e = navigator->file_list;
+    int i = 1;
+    printf("src_pixbufs loaded for these image indices: ");
+    while (e != NULL)
+    {
+        RsttoNavigatorEntry *re = e->data;
+        if (re->src_pixbuf != NULL)
+        {
+            printf("%d ", i);
+        }
+        e = g_list_next(e);
+        i++;
+    }
+    printf("\n");
+}
+
+
+/* preloading for improved responsiveness
+ * (at the expense of increased memory usage) 
+ */
+static gboolean
+rstto_navigator_preload_next_img (RsttoNavigator *navigator)
+{
+    GList *next = g_list_next(navigator->file_iter);
+    /* wraparound case */
+    if (next == NULL)
+    {
+        next = navigator->file_list;
+    }
+    if (next != NULL)
+    {
+        RsttoNavigatorEntry *next_entry = next->data;
+        rstto_navigator_entry_load_image(next_entry, FALSE);
+
+        /* add image to the cache-history */
+        rstto_navigator_add_entry_to_history(navigator, next_entry);
+    }
+
+    /* for use with g_timeout_add() */
+    return FALSE;
+}
+
+static gboolean
+rstto_navigator_preload_prev_img (RsttoNavigator *navigator)
+{
+    GList *prev = g_list_previous(navigator->file_iter);
+    /* wraparound case */
+    if (prev == NULL)
+    {
+        prev = g_list_last(navigator->file_list);
+    }
+    if (prev != NULL)
+    {
+        RsttoNavigatorEntry *prev_entry = prev->data;
+        rstto_navigator_entry_load_image(prev_entry, FALSE);
+
+        /* add image to the cache-history */
+        rstto_navigator_add_entry_to_history(navigator, prev_entry);
+    }
+    
+    /* for use with g_timeout_add() */
+    return FALSE;
+}
+
+
+void
 rstto_navigator_jump_first (RsttoNavigator *navigator)
 {
     if(navigator->file_iter)
@@ -358,6 +444,13 @@
     if(navigator->file_iter)
     {
         g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED], 0, 0, navigator->file_iter->data, NULL);
+
+        if (navigator->preload)
+        {
+            /* preload in both directions */
+            g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_next_img, navigator);
+            g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_prev_img, navigator);
+        }
     }
 }
 
@@ -381,6 +474,12 @@
                       g_list_position(navigator->file_list, navigator->file_iter),
                       navigator->file_iter->data,
                       NULL);
+
+        if (navigator->preload)
+        {
+            /* preload forwards */
+            g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_next_img, navigator);
+        }
     }
     else
     {
@@ -414,6 +513,12 @@
                       g_list_position(navigator->file_list, navigator->file_iter),
                       navigator->file_iter->data,
                       NULL);
+
+        if (navigator->preload)
+        {
+            /* preload backwards */
+            g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_prev_img, navigator);
+        }
     }
 }
 
@@ -435,6 +540,13 @@
                       g_list_position(navigator->file_list, navigator->file_iter),
                       navigator->file_iter->data,
                       NULL);
+
+        if (navigator->preload)
+        {
+            /* preload in both directions */
+            g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_next_img, navigator);
+            g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_prev_img, navigator);
+        }
     }
 }
 
@@ -449,17 +561,8 @@
             navigator->id = g_timeout_add(navigator->timeout, (GSourceFunc)cb_rstto_navigator_running, navigator);
             if (navigator->preload)
             {
-                GList *next = g_list_next(navigator->file_iter);
-                if (next == NULL)
-                {
-                    next = navigator->file_list;
-                }
-                if (next != NULL)
-                {
-                    RsttoNavigatorEntry *next_entry = next->data;
-                    
-                    rstto_navigator_entry_load_image(next_entry, FALSE);
-                }
+                /* preload forwards */
+                rstto_navigator_preload_next_img(navigator);
             }
         }
     }
@@ -554,9 +657,13 @@
             if(!navigator->file_iter)
                 navigator->file_iter = g_list_first(navigator->file_list);
 
-            /* Ehm... an item can exist several times inside the history? */
+            /* An item should not be able to exist several times inside the
+             * history, g_list_remove should suffice here
+             */
             if (navigator->history)
-                navigator->history = g_list_remove_all(navigator->history, entry);
+            {
+                navigator->history = g_list_remove (navigator->history, entry);
+            }
 
             if (navigator->busy == FALSE)
             {
@@ -622,7 +729,6 @@
     }
     g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_ITER_CHANGED], 0, -1, NULL, NULL);
     g_signal_emit(G_OBJECT(navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_REORDERED], 0, NULL);
-    
 }
 
 void
@@ -656,21 +762,14 @@
 
         if (navigator->preload)
         {
-            GList *next = g_list_next(navigator->file_iter);
-            if (next == NULL)
-            {
-                next = navigator->file_list;
-            }
-            if (next != NULL)
-            {
-                RsttoNavigatorEntry *next_entry = next->data;
-                
-                rstto_navigator_entry_load_image(next_entry, FALSE);
-            }
+            /* preload forwards */
+            rstto_navigator_preload_next_img(navigator);
         }
     }
     else
+    {
         navigator->id = 0;
+    }
     return navigator->running;
 }
 
@@ -791,9 +890,13 @@
 rstto_navigator_entry_get_flip (RsttoNavigatorEntry *entry, gboolean horizontal)
 {
     if (horizontal)
+    {
         return entry->h_flipped;
+    }
     else
+    {
         return entry->v_flipped;
+    }
 }
 
 static void
@@ -945,10 +1048,14 @@
     }
     /* Max scale 1600% */
     if (scale > 16)
+    {
         scale = 16;
+    }
     /* Min scale 5% */
     if (scale < 0.05)
+    {
         scale = 0.05;
+    }
     entry->scale = scale;
 }
 
@@ -1056,6 +1163,7 @@
         g_signal_connect(entry->loader, "closed", G_CALLBACK(cb_rstto_navigator_entry_closed), entry);
 
         path = thunar_vfs_path_dup_string(entry->info->path);
+
         entry->io_channel = g_io_channel_new_file(path, "r", NULL);
 
         g_io_channel_set_encoding(entry->io_channel, NULL, NULL);
@@ -1366,6 +1474,14 @@
                       navigator->file_iter->data,
                       NULL);
         }
+
+        if (navigator->preload)
+        {
+            /* preload in both directions */
+            g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_next_img, navigator);
+            g_timeout_add(500, (GSourceFunc)rstto_navigator_preload_prev_img, navigator);
+
+        }
     }
 
 }




More information about the Goodies-commits mailing list