Bug fix: Collection preview
authorColin Clark <colin.clark@cclark.uk>
Thu, 19 Jul 2018 09:56:46 +0000 (10:56 +0100)
committerColin Clark <colin.clark@cclark.uk>
Thu, 19 Jul 2018 09:56:46 +0000 (10:56 +0100)
Creating thumbnails takes too long; use only thumbnails in the cache.
Option in Preferences/General to define the maximum number of thumbnails
in the montage.

src/image_load_collection.c
src/options.c
src/options.h
src/preferences.c
src/rcfile.c

index d8bd281..15a8e08 100644 (file)
@@ -22,7 +22,9 @@
 #include "image-load.h"
 #include "image_load_collection.h"
 
+#include "cache.h"
 #include "misc.h"
+#include "ui_fileops.h"
 
 typedef struct _ImageLoaderCOLLECTION ImageLoaderCOLLECTION;
 struct _ImageLoaderCOLLECTION {
@@ -42,7 +44,6 @@ static gboolean image_loader_collection_load(gpointer loader, const guchar *buf,
        ImageLoader *il = ld->data;
 
        #define LINE_LENGTH 1000
-       #define MAX_LINES 23
 
        gboolean ret = FALSE;
        gchar *randname;
@@ -51,28 +52,41 @@ static gboolean image_loader_collection_load(gpointer loader, const guchar *buf,
        gint line_count = 0;
        GString *file_names = g_string_new(NULL);
        gchar line[LINE_LENGTH];
+       gchar **split_line = NULL;
+       gchar *cache_found;
+       gchar *pathl;
 
        if (runcmd("which montage >/dev/null 2>&1") == 0)
                {
-               fp = fopen(il->fd->path, "r");
+               pathl = path_from_utf8(il->fd->path);
+               fp = fopen(pathl, "r");
+               g_free(pathl);
                if (fp)
                        {
-                       while(fgets(line, LINE_LENGTH, fp) && line_count < MAX_LINES)
+                       while(fgets(line, LINE_LENGTH, fp) && line_count < options->thumbnails.collection_preview)
                                {
-                               /* get rid of ending \n from fgets */
-                               line[strlen(line) - 1] = '\0';
                                if (line[0] && line[0] != '#')
                                        {
-                                       file_names = g_string_append(file_names, line);
-                                       file_names = g_string_append(file_names, " ");
+                                       split_line = g_strsplit(line, "\"", 4);
+                                       cache_found = cache_find_location(CACHE_TYPE_THUMB, split_line[1]);
+                                       if (cache_found)
+                                               {
+                                               file_names = g_string_append(file_names, g_strconcat("\"", cache_found,"\" ", NULL));
+                                               line_count++;
+                                               }
+                                       g_free(cache_found);
                                        }
-                               line_count++;
+                                       if (split_line)
+                                               {
+                                               g_strfreev(split_line);
+                                               }
+                                       split_line = NULL;
                                }
                        fclose(fp);
 
                        if (file_names->len > 0)
                                {
-                               randname = g_strdup("geeqie_collection_XXXXXX.png");
+                               randname = g_strdup("/tmp/geeqie_collection_XXXXXX.png");
                                g_mkstemp(randname);
 
                                cmd_line = g_strdup_printf("montage %s -geometry %dx%d+1+1 %s >/dev/null 2>&1", file_names->str, options->thumbnails.max_width, options->thumbnails.max_height, randname);
index d7c02fc..e7d1f0d 100644 (file)
@@ -171,6 +171,7 @@ ConfOptions *init_options(ConfOptions *options)
        options->thumbnails.use_exif = FALSE;
        options->thumbnails.use_ft_metadata = TRUE;
 //     options->thumbnails.use_ft_metadata_small = TRUE;
+       options->thumbnails.collection_preview = 20;
 
        options->tree_descend_subdirs = FALSE;
        options->view_dir_list_single_click_enter = TRUE;
index 4bc52dd..abaf8b2 100644 (file)
@@ -140,6 +140,7 @@ struct _ConfOptions
                guint quality;
                gboolean use_exif;
                gboolean use_ft_metadata;
+               gint collection_preview;
 //             gboolean use_ft_metadata_small;
        } thumbnails;
 
index febe1d7..52d7abe 100644 (file)
@@ -287,6 +287,7 @@ static void config_window_apply(void)
        options->thumbnails.enable_caching = c_options->thumbnails.enable_caching;
        options->thumbnails.cache_into_dirs = c_options->thumbnails.cache_into_dirs;
        options->thumbnails.use_exif = c_options->thumbnails.use_exif;
+       options->thumbnails.collection_preview = c_options->thumbnails.collection_preview;
        options->thumbnails.use_ft_metadata = c_options->thumbnails.use_ft_metadata;
 //     options->thumbnails.use_ft_metadata_small = c_options->thumbnails.use_ft_metadata_small;
        options->thumbnails.spec_standard = c_options->thumbnails.spec_standard;
@@ -1749,6 +1750,11 @@ static void config_tab_general(GtkWidget *notebook)
        pref_checkbox_new_int(group, _("Use EXIF thumbnails when available (EXIF thumbnails may be outdated)"),
                              options->thumbnails.use_exif, &c_options->thumbnails.use_exif);
 
+       spin = pref_spin_new_int(group, _("Collection preview:"), NULL,
+                                1, 999, 1,
+                                options->thumbnails.collection_preview, &c_options->thumbnails.collection_preview);
+       gtk_widget_set_tooltip_text(spin, _("The maximum number of thumbnails shown in a Collection preview montage"));
+
 #ifdef HAVE_FFMPEGTHUMBNAILER_METADATA
        pref_checkbox_new_int(group, _("Use embedded metadata in video files as thumbnails when available"),
                              options->thumbnails.use_ft_metadata, &c_options->thumbnails.use_ft_metadata);
index 2f6a28c..4aea053 100644 (file)
@@ -398,6 +398,7 @@ static void write_global_attributes(GString *outstr, gint indent)
        WRITE_NL(); WRITE_UINT(*options, thumbnails.quality);
        WRITE_NL(); WRITE_BOOL(*options, thumbnails.use_exif);
        WRITE_NL(); WRITE_BOOL(*options, thumbnails.use_ft_metadata);
+       WRITE_NL(); WRITE_INT(*options, thumbnails.collection_preview);
 //     WRITE_NL(); WRITE_BOOL(*options, thumbnails.use_ft_metadata_small);
 
        /* File sorting Options */
@@ -725,6 +726,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_BOOL(*options, thumbnails.spec_standard)) continue;
                if (READ_UINT_CLAMP(*options, thumbnails.quality, GDK_INTERP_NEAREST, GDK_INTERP_HYPER)) continue;
                if (READ_BOOL(*options, thumbnails.use_exif)) continue;
+               if (READ_INT(*options, thumbnails.collection_preview)) continue;
                if (READ_BOOL(*options, thumbnails.use_ft_metadata)) continue;
 //             if (READ_BOOL(*options, thumbnails.use_ft_metadata_small)) continue;