#!/bin/sh

# Determine the path to this application.
CURDIR="`pwd`"
APPDIR=`dirname "$0"`
cd "${APPDIR}"
APPDIR="`pwd`"
cd "${CURDIR}"
	
if [ "$1" = "-clear" ];then
 cat $HOME/Choices/ROX-Filer/PuppyPin | grep -v '<backdrop' > /tmp/tmp
 mv -f /tmp/tmp $HOME/Choices/ROX-Filer/PuppyPin
 rox -p=$HOME/Choices/ROX-Filer/PuppyPin
 echo "[none]" > $HOME/.config/wallpaper/bg_img
 exit
fi

MODE="`cat $HOME/.config/wallpaper/backgroundmode`"
[ "$MODE" = "" ] && MODE="Scale"
[ "$MODE" = "Centred" ] && MODE="Centre"
[ "$MODE" = "Scaled" ] && MODE="Scale"

#w482 BK now have script that truncates an image vertically so that it has the right dimensions
#for a widescreen...
if [ -x /usr/sbin/background_reshape ];then #legacy compatibility
 if [ "$MODE" = "Stretch" ];then
  /usr/sbin/background_reshape ${1}
  feh --bg-scale $1
 fi
fi

rox --RPC << EOF
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
 <env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
  <SetBackdrop>
   <Filename>$1</Filename>
   <Style>$MODE</Style>
  </SetBackdrop>
 </env:Body>
</env:Envelope>

EOF
