Fix #516: Shortcut/Feature: Select random image
authorColin Clark <colin.clark@cclark.uk>
Sat, 5 Jan 2019 16:22:05 +0000 (16:22 +0000)
committerColin Clark <colin.clark@cclark.uk>
Sat, 5 Jan 2019 16:22:05 +0000 (16:22 +0000)
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
plugins/Makefile.am
plugins/random-image/Makefile.am [new file with mode: 0644]
plugins/random-image/geeqie-random-image [new file with mode: 0755]
plugins/random-image/random-image.desktop.in [new file with mode: 0644]
po/POTFILES.in

index 3cc2a8a..7e20158 100644 (file)
@@ -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
 ])
 
index 957df07..abfaef8 100644 (file)
@@ -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 (file)
index 0000000..423ae9b
--- /dev/null
@@ -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 (executable)
index 0000000..66e3c72
--- /dev/null
@@ -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 (file)
index 0000000..a9c733a
--- /dev/null
@@ -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
index 54f9211..87caba2 100644 (file)
@@ -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