#!/bin/bash -a
export APP_NAME="$(realpath "$0")"
export TEXTDOMAIN=puppy
export OUTPUT_CHARSET=UTF-8
. gettext.sh

#first run
[ ! -d $HOME/.wallmaker/tmp ] && mkdir -p $HOME/.wallmaker/tmp

export DESDIR="/usr/share/backgrounds"
export WORKDIR="$HOME/.wallmaker"

[ ! -f $WORKDIR/tmp/curformat ] && echo "svg" > $WORKDIR/tmp/curformat

function save ()
{
W="$(xwininfo -root | grep Width | cut -d ":" -f 2)"
H="$(xwininfo -root | grep Height | cut -d ":" -f 2)"
sed -i 's/width="'$(($W/4))'" height="'$(($H/4))'"/width="'$(($W))'" height="'$(($H))'"/g' $WORKDIR/tmp/copypic.svg
BC=$(echo "$STAMPSIZE*192"|bc)

if [ "$STAMP" = "true" ]; then
sed -i 's/transform="translate('$STAMPX','$STAMPY') scale('$STAMPSIZE')"/transform="translate('$(($STAMPX*4))','$(($STAMPY*4))') scale('$(echo "$STAMPSIZE*4"|bc)')"/g' $WORKDIR/tmp/copypic.svg
fi

if [ "$STAMPFILTERREFLECT" = "true" ]; then	
sed -i 's/transform="translate('$STAMPX','$(echo "$STAMPY+$BC"|bc)') scale('$STAMPSIZE' -'$STAMPSIZE')"/transform="translate('$(($STAMPX*4))','$(echo "$STAMPY+$BC*4+12"|bc)') scale('$(echo "$STAMPSIZE*4"|bc)' -'$(echo "$STAMPSIZE*4"|bc)')"/g' $WORKDIR/tmp/copypic.svg
fi

if [ "$TEXT" ]; then
sed -i 's/font-size=".*"/font-size="'$(($SIZE))'"/g' $WORKDIR/tmp/copypic.svg
sed -i 's/transform="rotate(.*) skewX/transform="rotate('$ROT' '$(($W*$XPOS/100))','$(($H*$YPOS/100))') skewX/g' $WORKDIR/tmp/copypic.svg
sed -i 's/stroke-width="1" x="'$XPOS'%" y="'$YPOS'%"/stroke-width="6" x="'$XPOS'%" y="'$YPOS'%"/g' $WORKDIR/tmp/copypic.svg
fi
if [ "$TEXTFILTERSHADOW" = "true" ]; then
sed -i 's/stdDeviation="3 3"/stdDeviation="6 6"/g' $WORKDIR/tmp/copypic.svg
sed -i 's/style="filter: url(#shadowtext)" x="'$XPOS'%" y="'$YPOS'%"/style="filter: url(#shadowtext)" x="'$(($XPOS+1))'%" y="'$(($YPOS+1))'%"/g' $WORKDIR/tmp/copypic.svg
sed -i 's/stroke-width="1" style="filter: url(#shadowtext)"/stroke-width="7" style="filter: url(#shadowtext)"/g' $WORKDIR/tmp/copypic.svg
fi

if [ "$TEXTFILTERREFLECT" = "true" ]; then
sed -i 's/stroke-width="1" style="filter: url(#reflect)"/stroke-width="6" style="filter: url(#reflect)"/g' $WORKDIR/tmp/copypic.svg
sed -i 's/stdDeviation="3 3"/stdDeviation="6 6"/g' $WORKDIR/tmp/copypic.svg
sed -i 's/translate(0, '$(($H*$YPOS/100/2+14))') scale(1, -1)"/translate(0, '$(($H*$YPOS/100*2+56))') scale(1, -1)"/g' $WORKDIR/tmp/copypic.svg
fi

if [ "$FORMAT" = "svg" ]; then
cp -f $WORKDIR/tmp/copypic.svg $DESDIR/wallpaper$$.svg
else
	if [ "$(which rsvg-convert)" ]; then
	rsvg-convert -f png -o $DESDIR/wallpaper$$.png $WORKDIR/tmp/copypic.svg
	else
	gxmessage -bg orange "Conversion to png failed"
	exit 0
	fi
fi
Xdialog --title "Wallmaker" --no-close --screen-center -no-buttons --infobox "Wallpaper is saved" 10 30
}

function edit ()
{
cp -f $WORKDIR/templates/$SVGNAME $WORKDIR/tmp/copypic.svg
W="$(xwininfo -root | grep Width | cut -d ":" -f 2)"
H="$(xwininfo -root | grep Height | cut -d ":" -f 2)"

if [ $BACKFILTERGLOW = "true" ]; then
sed -i 's/<\/defs>/<filter id="glow1" x="-30%" y="-30%" width="160%" height="160%"><feGaussianBlur stdDeviation="10 10" result="glow"\/><feMerge><feMergeNode in="glow"\/><feMergeNode in="glow"\/><feMergeNode in="glow"\/><\/feMerge><\/filter>\\\n<\/defs>/g' $WORKDIR/tmp/copypic.svg
sed -i 's/<rect/<rect filter="url(#glow1)"/g' $WORKDIR/tmp/copypic.svg
fi

if [ $BACKFILTERBLURRED = "true" ]; then
sed -i 's/<\/defs>/<filter id="sideways_blur"><feGaussianBlur stdDeviation="10 1"\/><\/filter>\\\n<\/defs>/g' $WORKDIR/tmp/copypic.svg
sed -i 's/<rect/<rect filter="url(#sideways_blur)"/g' $WORKDIR/tmp/copypic.svg
fi

if [ $BACKFILTERTONED = "true" ]; then
RECTLINE=$(cat $WORKDIR/tmp/copypic.svg | grep -n '<rect style' | cut -d ":" -f 1)
sed -i ''$(($RECTLINE+1))'i/<rect fill-opacity="0.3" fill="'$TONEDCOL'" width="100%" height="100%" x="0" y="0" rx="0" ry="0"\/> z"\/>' $WORKDIR/tmp/copypic.svg
fi

if [ $USEFILL = "false" ]; then
TEXTFILL="none"
FILL="none"
else
FILL="black"
fi

if [ $USECOL = "false" ]; then
TEXTCOL="none"
COL="none"
else
COL="black"
fi

if [ $USESTAMPFILL = "false" ]; then
STAMPFILL="none"
STAMPFILLEFFECT="none"
else
STAMPFILLEFFECT="black"
fi

if [ "$TEXT" ]; then
	
	if [ "$TEXTFILTERREFLECT" = "true" ]; then	
	sed -i 's/<\/defs>/<filter id="reflect" x="-25%" y="-25%" width="140%" height="140%"><feGaussianBlur stdDeviation="3 3" result="shadow"\/><feOffset dx="1" dy="1"\/><\/filter>\\\n<\/defs>/g' $WORKDIR/tmp/copypic.svg
	sed -i 's/<\/svg>/<text stroke-width="1" style="filter: url(#reflect)" x="'$XPOS'%" y="'$YPOS'%" text-anchor="start" transform="rotate('$ROT' '$(($W/4*$XPOS/100))','$(($H/4*$YPOS/100))') skewX('$XSKEW') skewY('$YSKEW') translate(0, '$(($H*$YPOS/100/2+14))') scale(1, -1)" fill="'$TEXTFILL'" stroke="'$TEXTCOL'" font-family="'"$FONT"'" font-style="'"$FONTSTYLE"'" font-weight="'"$FONTWEIGHT"'" font-size="'$(($SIZE/4))'">'"$TEXT"'<\/text>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	sed -i 's/<\/svg>/<text stroke-width="1" x="'$XPOS'%" y="'$YPOS'%" text-anchor="start" transform="rotate('$ROT' '$(($W/4*$XPOS/100))','$(($H/4*$YPOS/100))') skewX('$XSKEW') skewY('$YSKEW')" fill="'$TEXTFILL'" stroke="'$TEXTCOL'" font-family="'"$FONT"'" font-style="'"$FONTSTYLE"'" font-weight="'"$FONTWEIGHT"'" font-size="'$(($SIZE/4))'">'"$TEXT"'<\/text>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	fi
	if [ "$TEXTFILTERSHADOW" = "true" ]; then	
	sed -i 's/<\/defs>/<filter id="shadowtext" x="-5%" y="-5%" width="140%" height="140%"><feGaussianBlur stdDeviation="3 3" result="shadow"\/><feOffset dx="6" dy="6"\/><\/filter>\\\n<\/defs>/g' $WORKDIR/tmp/copypic.svg
	sed -i 's/<\/svg>/<text stroke-width="1" style="filter: url(#shadowtext)" x="'$XPOS'%" y="'$YPOS'%" text-anchor="start" transform="rotate('$ROT' '$(($W/4*$XPOS/100))','$(($H/4*$YPOS/100))') skewX('$XSKEW') skewY('$YSKEW')" fill="'$FILL'" stroke="'$COL'" font-family="'"$FONT"'" font-style="'"$FONTSTYLE"'" font-weight="'"$FONTWEIGHT"'" font-size="'$(($SIZE/4))'">'"$TEXT"'<\/text>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	sed -i 's/<\/svg>/<text stroke-width="1" x="'$XPOS'%" y="'$YPOS'%" text-anchor="start" transform="rotate('$ROT' '$(($W/4*$XPOS/100))','$(($H/4*$YPOS/100))') skewX('$XSKEW') skewY('$YSKEW')" fill="'$TEXTFILL'" stroke="'$TEXTCOL'" font-family="'"$FONT"'" font-style="'"$FONTSTYLE"'" font-weight="'"$FONTWEIGHT"'" font-size="'$(($SIZE/4))'">'"$TEXT"'<\/text>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	fi
	if [ "$TEXTFILTERNONE" = "true" ]; then
	sed -i 's/<\/svg>/<text stroke-width="1" x="'$XPOS'%" y="'$YPOS'%" text-anchor="start" transform="rotate('$ROT' '$(($W/4*$XPOS/100))','$(($H/4*$YPOS/100))') skewX('$XSKEW') skewY('$YSKEW')" fill="'$TEXTFILL'" stroke="'$TEXTCOL'" font-family="'"$FONT"'" font-style="'"$FONTSTYLE"'" font-weight="'"$FONTWEIGHT"'" font-size="'$(($SIZE/4))'">'"$TEXT"'<\/text>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	fi		
fi

if [ "$STAMP" = "true" ]; then

STAMPUSED=$(cat $WORKDIR/tmp/stamp)
if [ ! "$STAMPUSED" ]; then
STAMPUSED="puppy-head.svg"
fi

BC=$(echo "$STAMPSIZE*192"|bc)

cat $WORKDIR/stamps/"$STAMPUSED" | grep "<path" | sed 's/<path //g' | sed 's/ fill="none" stroke="#444" stroke-width="3"\/>//g' > $WORKDIR/tmp/pathline
PATHLINE=$(cat $WORKDIR/tmp/pathline)
	
	if [ "$STAMPFILTERREFLECT" = "true" ]; then	
	sed -i 's/<\/defs>/<filter id="reflect" x="-25%" y="-25%" width="140%" height="140%"><feGaussianBlur stdDeviation="2 2" result="shadow"\/><feOffset dx="1" dy="1"\/><\/filter>\\\n<\/defs>/g' $WORKDIR/tmp/copypic.svg
	sed -i 's/<\/svg>/<path  fill="'$STAMPFILL'"  stroke-width="3" stroke="'$STAMPCOL'" transform="translate('$STAMPX','$STAMPY') scale('$STAMPSIZE')" '"$PATHLINE"' \/>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	sed -i 's/<\/svg>/<path style="filter: url(#reflect)" fill="'$STAMPFILL'"  stroke-width="3" stroke="'$STAMPCOL'" transform="translate('$STAMPX','$(echo "$STAMPY+$BC"|bc)') scale('$STAMPSIZE' -'$STAMPSIZE')" '"$PATHLINE"' \/>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	fi
	
	if [ "$STAMPFILTERSHADOW" = "true" ]; then	
	sed -i 's/<\/defs>/<filter id="shadow" x="-5%" y="-5%" width="140%" height="140%"><feGaussianBlur stdDeviation="2 2" result="shadow"\/><feOffset dx="6" dy="6"\/><\/filter>\\\n<\/defs>/g' $WORKDIR/tmp/copypic.svg
	sed -i 's/<\/svg>/<path style="filter: url(#shadow)" fill="'$STAMPFILLEFFECT'"  stroke-width="3" stroke="black" transform="translate('$STAMPX','$STAMPY') scale('$STAMPSIZE')" '"$PATHLINE"' \/>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	sed -i 's/<\/svg>/<path  fill="'$STAMPFILL'"  stroke-width="3" stroke="'$STAMPCOL'" transform="translate('$STAMPX','$STAMPY') scale('$STAMPSIZE')" '"$PATHLINE"' \/>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	fi
	if [ "$STAMPFILTERNONE" = "true" ]; then
	sed -i 's/<\/svg>/<path  fill="'$STAMPFILL'"  stroke-width="3" stroke="'$STAMPCOL'" transform="translate('$STAMPX','$STAMPY') scale('$STAMPSIZE')" '"$PATHLINE"' \/>\\\n<\/svg>/g' $WORKDIR/tmp/copypic.svg
	fi	
fi

sed -i 's/width="100" height="100"/width="'$(($W/4))'" height="'$(($H/4))'"/g' $WORKDIR/tmp/copypic.svg
sed -i 's/orange/'$COL1'/g' $WORKDIR/tmp/copypic.svg
sed -i 's/blue/'$COL2'/g' $WORKDIR/tmp/copypic.svg
sed -i 's/red/'$COL3'/g' $WORKDIR/tmp/copypic.svg
}

function editgui ()
{
if [ "$(ps | grep 'gtkdialog --program=editgui --center --space-fill=true')" ]; then
kill $(ps | grep "gtkdialog --program=editgui --center --space-fill=true" | awk '{print $1}')
fi	

export SVGNAME="$(cat $WORKDIR/tmp/chosen)"
COLBUT="$(echo "$SVGNAME" | cut -d "-" -f 2)"
	case "$COLBUT" in
	"1col.svg")
	export	BUT2="false"
	export	BUT3="false"
	export	TONED="false"
	;;
	"2col.svg")
	export	BUT2="true"
	export	BUT3="false"
	export	TONED="true"
	;;
	"3col.svg")
	export	BUT2="true"
	export	BUT3="true"
	export	TONED="true"
	;;
	esac

echo "`fc-list : family | sort -u`" > $WORKDIR/tmp/fontlist.txt
echo "$(cat $WORKDIR/tmp/fontlist.txt | awk '{print "<item>"$0"</item>"}')" > $WORKDIR/tmp/fontlist.txt
FONTS=$(cat $WORKDIR/tmp/fontlist.txt)

echo "$(cat $WORKDIR/tmp/curformat | awk '{print "<item>"$0"</item>"}')" > $WORKDIR/tmp/curformatitem
CURFORMAT=$(cat $WORKDIR/tmp/curformatitem)

W="$(xwininfo -root | grep Width | cut -d ":" -f 2)"
H="$(xwininfo -root | grep Height | cut -d ":" -f 2)"

for STAMPFILE in `find $HOME/.wallmaker/stamps -mindepth 1 -maxdepth 1 -type f`
do
STAMPNAME=$(basename $STAMPFILE)

 STAMPSET=''$STAMPSET'
  <vbox>
   <button width-request="100" height-request="100" tooltip-text="'$STAMPNAME'">
   <input file>'$STAMPFILE'</input>
   <action>echo "'$STAMPNAME'" > $WORKDIR/tmp/stamp</action>
   <action>edit</action>
   <action>refresh: PIC</action>
   </button>
  </vbox>'
done

cp -f $WORKDIR/templates/$SVGNAME $WORKDIR/tmp/copypic.svg
sed -i 's/width="100" height="100"/width="'$(($W/4))'" height="'$(($H/4))'"/g' $WORKDIR/tmp/copypic.svg
export editgui='<window title="Wallpaper Editor" allow-grow="false">

<vbox>


<hbox>
<hbox  space-fill="true"  space-expand="true"><text><label>" "</label></text></hbox>
<pixmap>
<input file>'$WORKDIR'/tmp/copypic.svg</input>
<variable>PIC</variable>
</pixmap>
<vbox>
<text sensitive="false"><label>Text Rotate</label><variable>ROTTEXT</variable></text>
<vscale range-min="0" range-max="360" height-request="'$(($(($H/4))-20))'" sensitive="false">
<default>0</default>
<item>"0 | 1 | <span> 0° </span>"</item>
<item>"180 | 1 | <span> 180° </span>"</item>
<item>"360 | 1 | <span> 360° </span>"</item>
<variable>ROT</variable>
<action>edit</action>
<action>refresh: PIC</action>
</vscale>
</vbox>
<hbox  space-fill="true"  space-expand="true"><text><label>" "</label></text></hbox>
</hbox>

<notebook labels="Background|Text|Stamp">

<frame Background Configuration>
<hbox homogeneous="true">
<colorbutton>
<default>orange</default>
<variable>COL1</variable>
<action>edit</action>
<action>refresh: PIC</action>
</colorbutton>
<colorbutton visible="'$BUT2'">
<default>blue</default>
<variable>COL2</variable>
<action>edit</action>
<action>refresh: PIC</action>
</colorbutton>
<colorbutton visible="'$BUT3'">
<default>red</default>
<variable>COL3</variable>
<action>edit</action>
<action>refresh: PIC</action>
</colorbutton>
</hbox>
<frame Filter Effects>
<hbox>
<vbox>
<radiobutton>
<default>true</default>
<label>None</label>
<variable>BACKFILTERNONE</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<radiobutton>
<default>false</default>
<label>Glow</label>
<variable>BACKFILTERGLOW</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<radiobutton>
<default>false</default>
<label>Blurred</label>
<variable>BACKFILTERBLURRED</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<radiobutton sensitive="'$TONED'">
<default>false</default>
<label>Toned ------ color:</label>
<variable>BACKFILTERTONED</variable>
<action>if true enable:TONEDCOL</action>
<action>if false disable:TONEDCOL</action>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
</vbox>
<vbox>
<vbox  space-fill="true"  space-expand="true"><text><label>" "</label></text></vbox>
<colorbutton sensitive="false">
<default>yellow</default>
<variable>TONEDCOL</variable>
<action>edit</action>
<action>refresh: PIC</action>
</colorbutton>
</vbox>
<hbox  space-fill="true"  space-expand="true"><text><label>" "</label></text></hbox>
</hbox>
</frame>
<frame Puppy Linux>
<text><label>Trio Tjandradjaja</label><variable>ROTTEXT</variable></text>
<text use-markup="true"><label>"<b>GPL 2016</b>"</label><variable>ROTTEXT</variable></text>
</frame>
</frame>

<frame Text  Configuration>
<hbox>
<entry>
<action signal="changed">edit</action>
<action signal="changed">refresh: PIC</action>
<action signal="changed">enable: ROT</action>
<action signal="changed">enable: ROTTEXT</action>
<variable>TEXT</variable>
</entry>
<text><label>Size</label></text>
<spinbutton range-min="40" range-max="900" range-step="4" editable="false">
<default>100</default>
<action signal="changed">edit</action>
<action>refresh: PIC</action>
<variable>SIZE</variable>
</spinbutton>
</hbox>
<hbox homogeneous="true">
<checkbox>
<default>true</default>
<label>Line</label>
<variable>USECOL</variable>
<action>if true enable:TEXTCOL</action>
<action>if false disable:TEXTCOL</action>
<action>edit</action>
<action>refresh: PIC</action>
</checkbox>
<colorbutton>
<default>red</default>
<variable>TEXTCOL</variable>
<action>edit</action>
<action>refresh: PIC</action>
</colorbutton>
<checkbox>
<default>true</default>
<label>Fill</label>
<variable>USEFILL</variable>
<action>if true enable:TEXTFILL</action>
<action>if false disable:TEXTFILL</action>
<action>edit</action>
<action>refresh: PIC</action>
</checkbox>
<colorbutton>
<default>green</default>
<variable>TEXTFILL</variable>
<action>edit</action>
<action>refresh: PIC</action>
</colorbutton>
</hbox>
<hbox homogeneous="true">
<text><label>Pos X</label></text>
<spinbutton editable="false">
<default>50</default>
<action signal="changed">edit</action>
<action signal="changed">refresh: PIC</action>
<variable>XPOS</variable>
</spinbutton>
<text><label>Pos Y</label></text>
<spinbutton editable="false">
<default>50</default>
<action signal="changed">edit</action>
<action signal="changed">refresh: PIC</action>
<variable>YPOS</variable>
</spinbutton>
</hbox>
<hbox homogeneous="true">
<text><label>Skew X</label></text>
<spinbutton range-min="-100" range-max="100" editable="false">
<default>0</default>
<action signal="changed">edit</action>
<action>refresh: PIC</action>
<variable>XSKEW</variable>
</spinbutton>
<text><label>Skew Y</label></text>
<spinbutton range-min="-100" range-max="100" editable="false">
<default>0</default>
<action signal="changed">edit</action>
<action>refresh: PIC</action>
<variable>YSKEW</variable>
</spinbutton>
</hbox>
<frame Font configuration>
<comboboxtext>
<variable>FONT</variable>
'$FONTS'
<action signal="changed">edit</action>
<action>refresh: PIC</action>
</comboboxtext>
<hbox homogeneous="true">
<text><label>Style</label></text>
<comboboxtext>
<variable>FONTSTYLE</variable>
<item>normal</item>
<item>italic</item>
<item>oblique</item>
<action signal="changed">edit</action>
<action>refresh: PIC</action>
</comboboxtext>
<text><label>Weight</label></text>
<comboboxtext>
<variable>FONTWEIGHT</variable>
<item>normal</item>
<item>bold</item>
<item>bolder</item>
<item>lighter</item>
<action signal="changed">edit</action>
<action>refresh: PIC</action>
</comboboxtext>
</hbox>
</frame>
<frame Filter Effects>
<hbox>
<radiobutton>
<default>true</default>
<label>None</label>
<variable>TEXTFILTERNONE</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<radiobutton>
<default>false</default>
<label>Shadow</label>
<variable>TEXTFILTERSHADOW</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<radiobutton>
<default>false</default>
<label>Reflection</label>
<variable>TEXTFILTERREFLECT</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<hbox  space-fill="true"  space-expand="true"><text><label>" "</label></text></hbox>
</hbox>
</frame>
</frame>

<frame Stamp Configuration>
<hbox scrollable="true">
'$STAMPSET'
</hbox>
<hbox>
<checkbox>
<default>false</default>
<label>Use stamp</label>
<variable>STAMP</variable>
<action>if true enable:STAMPCOL</action>
<action>if true enable:STAMPX</action>
<action>if true enable:STAMPY</action>
<action>if true enable:STAMPSIZE</action>
<action>if true enable:STAMPFILTERSHADOW</action>
<action>if true enable:STAMPFILTERNONE</action>
<action>if true enable:STAMPFILTERREFLECT</action>
<action>if true enable:USESTAMPFILL</action>
<action>if false disable:STAMPCOL</action>
<action>if false disable:STAMPX</action>
<action>if false disable:STAMPY</action>
<action>if false disable:STAMPSIZE</action>
<action>if false disable:STAMPFILTERNONE</action>
<action>if false disable:STAMPFILTERSHADOW</action>
<action>if false disable:STAMPFILTERREFLECT</action>
<action>if false disable:USESTAMPFILL</action>
<action>edit</action>
<action>refresh: PIC</action>
</checkbox>
<hbox  space-fill="true"  space-expand="true"><text><label>" "</label></text></hbox>
</hbox>
<hbox homogeneous="true">
<text><label>Color</label></text>
<colorbutton sensitive="false">
<default>grey</default>
<variable>STAMPCOL</variable>
<action>edit</action>
<action>refresh: PIC</action>
</colorbutton>
<checkbox sensitive="false">
<default>false</default>
<label>Fill</label>
<variable>USESTAMPFILL</variable>
<action>if true enable:STAMPFILL</action>
<action>if false disable:STAMPFILL</action>
<action>edit</action>
<action>refresh: PIC</action>
</checkbox>
<colorbutton sensitive="false">
<default>white</default>
<variable>STAMPFILL</variable>
<action>edit</action>
<action>refresh: PIC</action>
</colorbutton>
</hbox>
<hbox homogeneous="true">
<text><label>Pos X</label></text>
<spinbutton range-min="0" range-max="999" sensitive="false" editable="false">
<default>0</default>
<action signal="changed">edit</action>
<action>refresh: PIC</action>
<variable>STAMPX</variable>
</spinbutton>
<text><label>Pos Y</label></text>
<spinbutton range-min="0" range-max="999" sensitive="false" editable="false">
<default>0</default>
<action signal="changed">edit</action>
<action>refresh: PIC</action>
<variable>STAMPY</variable>
</spinbutton>
<text><label>Size</label></text>
<spinbutton range-min="0.5" range-max="2" range-step="0.5" editable="false" sensitive="false">
<default>0.5</default>
<action signal="changed">edit</action>
<action>refresh: PIC</action>
<variable>STAMPSIZE</variable>
</spinbutton>
</hbox>
<frame Filter Effects>
<hbox>
<radiobutton sensitive="false">
<default>true</default>
<label>None</label>
<variable>STAMPFILTERNONE</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<radiobutton sensitive="false">
<default>false</default>
<label>Shadow</label>
<variable>STAMPFILTERSHADOW</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<radiobutton sensitive="false">
<default>false</default>
<label>Reflection</label>
<variable>STAMPFILTERREFLECT</variable>
<action>edit</action>
<action>refresh: PIC</action>
</radiobutton>
<hbox  space-fill="true"  space-expand="true"><text><label>" "</label></text></hbox>
</hbox>
</frame>
</frame>

</notebook>

<hbox>
		<button>
		<input file stock="gtk-save"></input>
		<label>Save</label>
		<action>save &</action>
		<action signal="button-release-event">echo "$FORMAT" > $WORKDIR/tmp/curformat</action>
		</button>
		<text><label>as</label></text>
		<comboboxtext>
		<variable>FORMAT</variable>
		'$CURFORMAT'
		<item>png</item>
		<item>svg</item>
		</comboboxtext>
		<button>
		<input file stock="gtk-quit"></input>
		<label>Quit</label>
		</button>
</hbox>
</vbox>
</window>'

gtkdialog --program=editgui --center --space-fill=true

unset editgui
}

if [ "$(which wallpaper)" ]; then
SETTER="wallpaper"
SETTERBUT="true"
else
	if [ "$(which xfdesktop-settings)" ]; then
	SETTER="xfdesktop-settings"
	SETTERBUT="true"
	fi
	
	if [ "$(which qwallpaper)" ]; then
	SETTER="qwallpaper"
	SETTERBUT="true"
	else
	SETTERBUT="false"
	fi
fi

for SVG in `find $HOME/.wallmaker/templates -mindepth 1 -maxdepth 1 -type f`
do

SVGNAME=$(basename $SVG)

 SVGSET="$SVGSET
    <vbox>
   <button width-request=\"100\" height-request=\"105\" tooltip-text=\"$SVGNAME\">
   <input file>$SVG</input>
   <action>echo $SVGNAME > $WORKDIR/tmp/chosen</action>
   <action signal=\"button-release-event\">editgui &</action>
   </button>
 </vbox>"
done
 
 export MAIN="
   <window title=\"$(gettext 'Wallpaper Maker 1.8.9.3')\" icon-name=\"gtk-convert\" allow-grow=\"false\"  height-request=\"230\" width-request=\"350\">
     <vbox>
		<text><label>$(gettext 'Templates')</label></text>
      <text><label>$(gettext 'Click to edit')</label></text>
      <hbox scrollable=\"true\">
        $SVGSET
      </hbox>
	   <hbox>
	   <button tooltip-text=\"Go to directory\">
		<input file stock=\"gtk-directory\"></input>
		<label>Backgrounds</label>
		<action>rox /usr/share/backgrounds &</action>
		</button>
	   <button visible=\"$SETTERBUT\" tooltip-text=\"$SETTER\">
		<input file stock=\"gtk-preferences\"></input>
		<label>Setter</label>
		<action>$SETTER &</action>
		</button>
        <button tooltip-text=\"Exit this application\"><input file stock=\"gtk-quit\"></input><label>Quit</label></button>
      </hbox>
     </vbox>
      </window>"
gtkdialog -p MAIN

unset MAIN
