#!/bin/sh
# This file is sourced not run.
# Filmstrip source plugin default configuration file.
# Do not edit this file; copy it to your home folder and edit the new file:
#  cp -n /usr/share/doc/findnrun/examples/filmstrip/taprc $HOME/.filmstriprc


# . Review next section 'Basic settings' and adapt for your system.
#   All defaults have sensible values for most systems, but do check
#   that `FIND_PATH` points to existing picture folder locations, and
#   that `TYPING_RATE` is well-suited to your hardware (try the default
#   value first). You can come back to review other settings later.

# ------ Basic settings ------ {{{1
# Image search paths (separate multiple with ':').
FIND_PATH="${HOME}/Pictures:${HOME}/Downloads:/usr/share/backgrounds"
# Include these image types only (fullpath regular expression matcher).
FIND_TYPE='\.\(jpg\|png\)$'
# Search also sub-folders of $FIND_PATH elements.
FIND_IN_SUBFOLDERS=false
# Command-line options for find command.
FIND_OPTS='-L' # follow symlinks
# Command-line options for find command expression.
FIND_EXPR_OPTS=
# Sort search results.
FIND_SORTED='true'
# How many pictures to show and paginate.
VIEWER_FRAMES=4
# Should image frame show vertical/horizontal scrollbars?
SHOW_SCROLLBARS='false'
# Image horizontal width. The image will fit entirely within.
# The image never scales whether the main window is resized or not.
PICTURE_WIDTH=180
# Image vertical viewport on plugin start up.
# It can be increased by resizing the main window vertically.
PICTURE_HEIGHT=120
# Caption width: 10+$PICTURE_WIDTH gives best look.
CAPTION_WIDTH=190
# Caption height: the first value is used when $CUSTOM_CAPTION is null or
# undefined; the second value is used otherwise.
CAPTION_HEIGHT=40:60
# Cap findnrun search result list at these many lines (hide remaining results).
LIST_LINES=60
# Typing rate (seconds): Increase this value if displayed thumbnails do
# not match the top lines of the search result list.
# Increase by 1/10 steps until thumbnail updates match the list. Test by
# typing several character at your typical typing speed. As you increase
# TYPING_RATE, the lag you see between the final typed character and the
# final thumbnail update also increases. So, set the smallest value that
# balances viewer accuracy for your typical typing speed with acceptable
# thumbnail update lag.
TYPING_RATE=0.6

# ------ Advanced settings ------ {{{1
# Cache the image list after the first tap invocation.
CACHE_LIST=true

# Optional thumbnail click command.
# Set empty for default command, ROX-Filer, which presumably opens the
# image file with the default image viewer.
# Examples of custom click commands.
#CUSTOM_CLICK=rox
#CUSTOM_CLICK=defaultimageviewer
#CUSTOM_CLICK=mtpaint
#CUSTOM_CLICK=/path/to/my-image-viewer-script.sh

# Optional custom caption creation function.
# Set empty to display default caption, which consists of the image file name.
# Otherwise set to the name of a function that generates the custom caption.
# For example, predefined function exif_caption_abstract is defined
# further down in this file. It extracts EXIF metadata to generate a
# caption.
#CUSTOM_CAPTION=exif_caption_abstract

# For gtkdialog styles
# Puppy and Fatdog use GTK2 (default), Slacko uses GTK3 (uncomment).
GTK_STYLES="--styles=${0%/*}/gtkrc-2.0"
#GTK_STYLES="--styles=${0%/*}/gtk3.css"
#
# GTK2 gtkdialog supports rc style file priority (uncomment).
#GTK2_RC_FILES="~/.gtkrc-2.0:${0%/*}/gtkrc-2.0"
#export GTK2_RC_FILES

# Predefined custom caption functions. No change below. {{{1
# A custom caption function must output a list of records and nothing
# else.  Record format:
#  <record> ::=  <image full pathname>'|'<caption text>
# Characters '/', '|', newline (\n) and carriage return (\r) aren't
# allowed in <caption text>.  Do not output empty lines.
#
# The custom caption function is invoked when the search result cache is
# being built if $CACHE_LIST is 'true', and on each character typed into
# the search input field otherwise. The invocation command is:
#
#     ${CUSTOM_CAPTION} <file pathname>
# where <file pathname> is an input file that lists the pathnames of all
# found image files, one pathname per line. Do not overwrite or delete
# the contents of <file pathname>.

exif_caption_abstract () # $1-image-list-filepath [$2-ExifTool-tag] {{{2
# Function exif_caption_abstract extracts ExifTool tag values from
# image files to generate their captions. The ExifTool command must be
# pre-installed.
# $1 is an input file that lists the pathnames of all image files, one
# pathname per line.
# $2 is optional. Its purpose is explained next.
# A caption is formed by concatenating the values of the following tags:
# $2 (default name Caption-Abstract), Source, ImageSize, FileSize, FileName.
# Thus $2 links to the opening text of a caption.
#
# To call function exif_caption_abstract with a custom value for $2:
# 1. Name and define a custom tag in your ~/.ExifTool_config file
# 2. Define a custom caption function in this file as:
#
#      exif_caption_foo () exif_caption_abstract 'MyExifToolTag'
#
#    where 'MyExifToolTag' is the custom tag that you defined in step 1
# 3. Finally set CUSTOM_CAPTION=exif_caption_foo in this file.
#
{
  local infile tagname tagexpr mod do_not_change_this custom_exiftool_expr
  infile=$1
  tagname=${2:-Caption-Abstract}
  if [ -n "${tagname}" ] && which exiftool >/dev/null 2>&1; then
    # Mandatory replacements: {{{
    # \r might come from Windows => delete it
    # \n might be embedded in the caption text => to ' '
    # / isn't allowed in captions => to Unicode U+2215
    # | isn't allowed in output records => to Unicode U+2215 [sic]
    # U+2215 is the division slash character. It looks like the forward
    # slash character.
    # NOTE: generate-records.awk undoes the U+2215 replacement, so in
    # the end forward-slashed will be forward-slashes, which could be
    # imporant if the caption text includes a URL and is copy-pasted.
    # Generating division slash character:
    # in  ash: printf "\xe2\x88\x95"
    # in bash: printf "\u2215" and also the ash way
    #}}}
    mod='s/\n/ /g;s/\r//g;s/[|\/]/'$(printf '\xe2\x88\x95')'/g'

    do_not_change_this="\$Directory/\$FileName|" # Really, don't!
    # But this you can change.
    custom_exiftool_expr="\${${tagname};${mod}} \${Source;${mod}} \$ImageSize \$FileSize \${FileName;${mod}}"

    tagexpr="${do_not_change_this}${custom_exiftool_expr}"
    # -m makes exiftool ignore errors extracting ${tagname}.
    exiftool -m -q -p "${tagexpr}" -@ "${infile}"
  fi
}

