From 567e349fa3405332e7402a04df9a9d26e852c186 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sat, 5 Jan 2019 16:22:05 +0000 Subject: [PATCH] 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. --- configure.ac | 1 + plugins/Makefile.am | 2 +- plugins/random-image/Makefile.am | 9 ++++ plugins/random-image/geeqie-random-image | 57 ++++++++++++++++++++ plugins/random-image/random-image.desktop.in | 15 ++++++ po/POTFILES.in | 1 + 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 plugins/random-image/Makefile.am create mode 100755 plugins/random-image/geeqie-random-image create mode 100644 plugins/random-image/random-image.desktop.in diff --git a/configure.ac b/configure.ac index 3cc2a8a4..7e201582 100644 --- a/configure.ac +++ b/configure.ac @@ -623,6 +623,7 @@ AC_CONFIG_FILES([ plugins/tethered-photography/Makefile plugins/camera-import/Makefile plugins/image-crop/Makefile + plugins/random-image/Makefile geeqie.spec ]) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 957df07d..abfaef8d 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -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) diff --git a/plugins/random-image/Makefile.am b/plugins/random-image/Makefile.am new file mode 100644 index 00000000..423ae9b7 --- /dev/null +++ b/plugins/random-image/Makefile.am @@ -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) diff --git a/plugins/random-image/geeqie-random-image b/plugins/random-image/geeqie-random-image new file mode 100755 index 00000000..66e3c72b --- /dev/null +++ b/plugins/random-image/geeqie-random-image @@ -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" diff --git a/plugins/random-image/random-image.desktop.in b/plugins/random-image/random-image.desktop.in new file mode 100644 index 00000000..a9c733ab --- /dev/null +++ b/plugins/random-image/random-image.desktop.in @@ -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 diff --git a/po/POTFILES.in b/po/POTFILES.in index 54f92112..87caba27 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,6 +5,7 @@ plugins/export-jpeg/export-jpeg.desktop.in 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 -- 2.20.1