changeset 2879:c8147f1d5fc3

Fix #516: Shortcut/Feature: Select random image https://github.com/BestImageViewer/geeqie/issues/516 Implemented as a plugin. The random image is selected from all files in all collections plus all images in the current folder.
author Colin Clark <colin.clark@cclark.uk>
date Sat, 05 Jan 2019 16:22:05 +0000
parents 8b1c451c8ff2
children 288ea5f33bf7
files configure.ac plugins/Makefile.am plugins/random-image/Makefile.am plugins/random-image/geeqie-random-image plugins/random-image/random-image.desktop.in po/POTFILES.in
diffstat 6 files changed, 84 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Fri Jan 04 13:44:58 2019 +0000
+++ b/configure.ac	Sat Jan 05 16:22:05 2019 +0000
@@ -623,6 +623,7 @@
     plugins/tethered-photography/Makefile
     plugins/camera-import/Makefile
     plugins/image-crop/Makefile
+    plugins/random-image/Makefile
     geeqie.spec
 ])
 
--- a/plugins/Makefile.am	Fri Jan 04 13:44:58 2019 +0000
+++ b/plugins/Makefile.am	Sat Jan 05 16:22:05 2019 +0000
@@ -1,5 +1,5 @@
 
-SUBDIRS = rotate symlink ufraw import geocode-parameters export-jpeg tethered-photography camera-import image-crop
+SUBDIRS = rotate symlink ufraw import geocode-parameters export-jpeg tethered-photography camera-import image-crop random-image
 qq_desktoptemplatedir = $(appdir)
 qq_desktoptemplate_in_files = template.desktop.in
 qq_desktoptemplate_DATA = $(qq_desktoptemplate_in_files:.desktop.in=.desktop)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/random-image/Makefile.am	Sat Jan 05 16:22:05 2019 +0000
@@ -0,0 +1,9 @@
+dist_gq_bin_SCRIPTS = geeqie-random-image
+
+gq_desktopdir = $(appdir)/applications
+gq_desktop_in_files = random-image.desktop.in
+gq_desktop_DATA = $(gq_desktop_in_files:.desktop.in=.desktop)
+@INTLTOOL_DESKTOP_RULE@
+
+EXTRA_DIST = $(gq_desktop_in_files)
+CLEANFILES = $(gq_desktop_DATA)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/random-image/geeqie-random-image	Sat Jan 05 16:22:05 2019 +0000
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# Select and display a random image from a list of all images
+# in Collections and the currently displayed folder
+
+# get list of images in all collections
+collection_list=$(geeqie --remote --get-collection-list)
+OLDIFS=$IFS
+while IFS= read -r line
+do
+	collection=$(geeqie --remote --get-collection:"$line")
+	list="$list""$collection"$'\n'
+done <<< "$collection_list"
+IFS=$OLDIFS
+
+# get list of images in current folder
+file_list=$(geeqie --remote --get-filelist:)
+OLDIFS=$IFS
+while IFS= read -r line
+do
+	class_whitespace="${line##*Class:}"
+	class="${class_whitespace#"${class_whitespace%%[![:space:]]*}"}"
+
+	if [ "$class" == "Image" ]
+	then
+		list="$list""${line%%Class*}"$'\n'
+	fi
+
+	if [ "$class" == "RAW Image" ]
+	then
+		list="$list""${line%%Class*}"$'\n'
+	fi
+done <<< "$file_list"
+IFS=$OLDIFS
+
+# remove blank lines
+files_no_blanks=$(echo "$list" | sed -e 's/^[[:blank:]]*$//')
+# remove leading trailing whitespace
+files_no_spaces=$(echo "$files_no_blanks" | sed 's/^[ \t]*//;s/[ \t]*$//')
+
+# remove duplicate lines and select random line
+display_image="$(echo "$files_no_spaces" | sort --uniq | shuf -n 1)"
+
+# get image currently displayed
+current_image_collection=$(geeqie --remote --tell)
+# remove collection name, if it is there
+current_image_spaces="${current_image_collection%%Collection:*}"
+# remove leading trailing whitespace
+curent_image=$(echo "$current_image_spaces" | sed 's/^[ \t]*//;s/[ \t]*$//')
+
+# if the selected random image is currently displayed, try again
+if [ "$current_image" == "$display_image" ]
+then
+	display_image="$(echo "$files_no_spaces" | sort --uniq | shuf -n 1)"
+fi
+
+geeqie --remote file:"$display_image"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/random-image/random-image.desktop.in	Sat Jan 05 16:22:05 2019 +0000
@@ -0,0 +1,15 @@
+[Desktop Entry]
+Version=1.0
+Type=Application
+_Name=Random image
+
+Exec=geeqie-random-image
+
+# Desktop files that are usable only in Geeqie should be marked like this:
+Categories=X-Geeqie;
+OnlyShowIn=X-Geeqie;
+
+# It can be made verbose
+#X-Geeqie-Verbose=true
+
+Icon=geeqie
--- a/po/POTFILES.in	Fri Jan 04 13:44:58 2019 +0000
+++ b/po/POTFILES.in	Sat Jan 05 16:22:05 2019 +0000
@@ -5,6 +5,7 @@
 plugins/tethered-photography/tethered-photography.desktop.in
 plugins/camera-import/camera-import.desktop.in
 plugins/image-crop/image-crop.desktop.in
+plugins/random_image/random_image.desktop.in
 plugins/rotate/rotate.desktop.in
 plugins/symlink/symlink.desktop.in
 plugins/template.desktop.in