#!/bin/dash
#150503 step: see https://github.com/step-/nathans-wallpaper/

usage()
{
# TODO i18n localization
  cat << EOF
Usage:
  ${0##*/} [FILE [FILE...]] | [OPTION]
OPTIONs:
  -about                    display version dialog and exit
  -clear                    clear desktop background
  -h|-help                  output this text and exit
  -play[=MODE]              play FILEs located in the slideshow directory
  -play-dir=FOLDER-PATH     play the image FILEs found in and under FOLDER-PATH
  -play-list=PLAYLIST-FILE  play the FILE paths listed in PLAYLIST-FILE
  -prefs                    display application preferences dialog
  -stop                     stop the slideshow

A single FILE sets the background and exits.  Multiple FILEs play a slideshow
in the background.  Specifying no FILE nor OPTION displays the application GUI.
Supported FILE formats: JPEG, PNG, GIF, TIFF, BMP.

The slideshow directory can be set with -prefs.  Each slide plays using the
currently saved wallpaper mode: Centre, Tile, Scale, Stretch, Distort.  Set
mode with -prefs or the Preferences dialog or by writing the mode value in
\$HOME/.config/wallpaper/backgroundmode.  Bypass using the saved mode with
-play=MODE or by prefixing FILE with MODE and a colon, i.e.,
  /usr/bin/wallpaper Stretch:/path/to/wallpaper.jpg

PLAYLIST-FILE lists one filepath per line as: [MODE':']/path/to/image.ext.
Set slideshow delay and shuffle mode with -prefs or in
\$HOME/.config/wallpaper/preferences.

ENVIRONMENT:
  \$DEBUG: Enable debug trace to stderr; set verbosity (integer) 1-3.
  \$SCALE_FILTER: Scaling method for Stretch MODE; one of: point, box, triangle,
    quadratic, cubic, catrom, mitchell, gauss, gauss sinc, bessel, hanning,
    hamming, blackman, kaiser, normal, hermite(default), lanczos, pixel-mixing.
EOF
}

case $1 in
  -clear) DEBUG=${DEBUG:-} \
    exec "${0%/*}/../local/apps/Wallpaper/set_bg" -clear;;
  -h|-help|--help) usage; exit;;
  -prefs) DEBUG=${DEBUG:-} \
    exec "${0%/*}/../local/apps/Wallpaper/functions" -preferences;;
esac

DEBUG=${DEBUG:-} \
SCALE_FILTER=${SCALE_FILTER:-hermite} \
exec "${0%/*}/../local/apps/Wallpaper/AppRun" "$@"
