changeset 2800:0ecd4885dc09

Bug fix: Collection preview 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.
author Colin Clark <colin.clark@cclark.uk>
date Thu, 19 Jul 2018 10:56:46 +0100
parents ea4163f0c769
children 3e9ca298bb1d
files src/image_load_collection.c src/options.c src/options.h src/preferences.c src/rcfile.c
diffstat 5 files changed, 33 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/image_load_collection.c	Wed Jul 18 11:09:22 2018 +0100
+++ b/src/image_load_collection.c	Thu Jul 19 10:56:46 2018 +0100
@@ -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 @@
 	ImageLoader *il = ld->data;
 
 	#define LINE_LENGTH 1000
-	#define MAX_LINES 23
 
 	gboolean ret = FALSE;
 	gchar *randname;
@@ -51,28 +52,41 @@
 	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);
--- a/src/options.c	Wed Jul 18 11:09:22 2018 +0100
+++ b/src/options.c	Thu Jul 19 10:56:46 2018 +0100
@@ -171,6 +171,7 @@
 	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;
--- a/src/options.h	Wed Jul 18 11:09:22 2018 +0100
+++ b/src/options.h	Thu Jul 19 10:56:46 2018 +0100
@@ -140,6 +140,7 @@
 		guint quality;
 		gboolean use_exif;
 		gboolean use_ft_metadata;
+		gint collection_preview;
 // 		gboolean use_ft_metadata_small;
 	} thumbnails;
 
--- a/src/preferences.c	Wed Jul 18 11:09:22 2018 +0100
+++ b/src/preferences.c	Thu Jul 19 10:56:46 2018 +0100
@@ -287,6 +287,7 @@
 	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 @@
 	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);
--- a/src/rcfile.c	Wed Jul 18 11:09:22 2018 +0100
+++ b/src/rcfile.c	Thu Jul 19 10:56:46 2018 +0100
@@ -398,6 +398,7 @@
 	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 @@
 		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;