#!/bin/bash
# mkwallpaper-gui (frontend for 01micko's mkwallpaper)
# Copyright 2015-2016 GPL3 http://www.gnu.org/licenses
# Roger Grider (radky)
# 151115: v1.0 - initial release
# 160423: v2.0 - adjust GUI; add hex2float function; support mkwallpaper >=0.7
# 160510: v2.1 - add option to set destination directory; add preview button; assure set_bg in executable PATH
# 160630: v2.2 - adjust for non-English locales (set LC_NUMERIC="C"; auto-adjust GUI width for long text strings)
# 160910: v2.3 - adjust GUI; support embedded png image (mkwallpaper >=0.8); support rsvg-convert, LXDE, XFCE

export TEXTDOMAIN=mkwallpaper_gui
export OUTPUT_CHARSET=UTF-8

[ ! "`which mkwallpaper 2>/dev/null`" ] && Xdialog --title "$(gettext 'Alert')" --beep --no-buttons --msgbox "\n  $(gettext 'The mkwallpaper executable is not installed!')  \n" 0 0 && exit 0

mkwPID=$(ps -ax | grep gtkdialog | grep 'p MKW$' | awk '{print $1}')
[ "$mkwPID" ] && Xdialog --title "$(gettext 'Alert')" --beep --no-buttons --msgbox "\n  $(gettext 'Mkwallpaper-gui is already active!')  \n" 0 0 && exit 0

export VERSION="2.3"
export WORKDIR="/usr/local/mkwallpaper-gui"
export PREFDIR="$WORKDIR/preferences"
export TMPDIR1="/tmp/mkw" TMPDIR2="/tmp/mkw2"
[ ! -d "$PREFDIR" ] && mkdir -p $PREFDIR
[ ! -d "$TMPDIR1" ] && mkdir -p $TMPDIR1
[ ! -d "$TMPDIR2" ] && mkdir -p $TMPDIR2

###############################################################################
#
# Define parameters for graphical interface
#
###############################################################################

#required for floating-point numbers in locales using a comma as decimal point
export LC_NUMERIC="C"

#define gtkdialog
if [ "`which gtkdialog4`" ]; then
 GTKDIALOG=gtkdialog4
elif [ "`which gtkdialog3`" ]; then
 GTKDIALOG=gtkdialog3
else
 GTKDIALOG=gtkdialog
fi
export GTKDIALOG

#current window manager
export CURRWM=`cat /etc/windowmanager`

#distro name
. /etc/DISTRO_SPECS

#screen resolution
if [ "`which xdpyinfo`" ]; then
 [ $(xdpyinfo | grep dimensions | awk '{print $2}' | grep x) != "" ] && SCREEN=$(xdpyinfo | grep dimensions | awk '{print $2}') || SCREEN="1024x768"
elif [ "`which xrandr`" ]; then
 [ $(xrandr | grep '*' | awk '{print $1}' | grep x) != "" ] && SCREEN=$(xrandr | grep '*' | awk '{print $1}') || SCREEN="1024x768"
else
 SCREEN="1024x768"
fi

#title-bar icon
ln -sf $WORKDIR/icons/mkwallpaper64.png /usr/share/icons/hicolor/48x48/apps && gtk-update-icon-cache -f -i /usr/share/icons/hicolor 2>/dev/null

#auto-adjust GUI width for long text strings in non-English locales
[ "${LANG%_*}" = "en" ] && WINDOW_WIDTH="650" || WINDOW_WIDTH="700"

#GUI font color
if [ "`grep 'Stardust_dark' $HOME/.gtkrc-2.0 2>/dev/null`" ]; then #gold text for Stardust themes
 COLOR=#D7B740
else #light-blue text for common dark themes, otherwise medium blue
 [ "`grep -Ei 'black|dark|dusk|night' $HOME/.gtkrc-2.0 2>/dev/null`" ] && COLOR=#84aad9 || COLOR=#3272C0
fi
export COLOR

#frame font
echo "style \"specialframe\"
{
  font_name=\"Sans bold 9\"
}
widget \"*.GtkFrame.GtkLabel\" style \"specialframe\"
class \"*.GtkFrame.GtkLabel\" style \"specialframe\"" > "$WORKDIR/gtkrc_special"

export GTK2_RC_FILES="$WORKDIR/gtkrc_special:${HOME}/.gtkrc-2.0"

#current image format
IMAGE_FORMAT=$(cat $PREFDIR/imageformat 2>/dev/null)
[ ! "$IMAGE_FORMAT" ] && echo "svg" > $PREFDIR/imageformat

#current background color
BGCOLOR=$(cat $PREFDIR/bgcolor 2>/dev/null)
[ ! "$BGCOLOR" ] && echo "#224879" > $PREFDIR/bgcolor

#current gradient settings
GRADIENT_ANGLE=$(cat $PREFDIR/gradientangle 2>/dev/null)
[ ! "$GRADIENT_ANGLE" ] && echo "10" > $PREFDIR/gradientangle

GRADIENT_OFFSET=$(cat $PREFDIR/gradientoffset 2>/dev/null)
[ ! "$GRADIENT_OFFSET" ] && echo "0.65" > $PREFDIR/gradientoffset

#current label settings
FONT_NAME=$(cat $PREFDIR/fontname 2>/dev/null)
[ ! "$FONT_NAME" ] && echo "Sans" > $PREFDIR/fontname
FONT_NAME_ITEMS=$(echo -e "Sans\n`fc-list : family | cut -d',' -f1 | sort -u`" | awk '{print "<item>"$1" "$2" "$3" "$4"</item>"}' | sed -e 's/ //g;s/\\//g')

FONT_SIZE=$(cat $PREFDIR/fontsize 2>/dev/null)
[ ! "$FONT_SIZE" ] && echo "72" > $PREFDIR/fontsize

FONT_WEIGHT=$(cat $PREFDIR/fontweight 2>/dev/null)
[ ! "$FONT_WEIGHT" ] && echo "bold" > $PREFDIR/fontweight

FONT_STYLE=$(cat $PREFDIR/fontstyle 2>/dev/null)
[ ! "$FONT_STYLE" ] && echo "italic" > $PREFDIR/fontstyle

FONT_EMBOSS=$(cat $PREFDIR/fontemboss 2>/dev/null)
[ ! "$FONT_EMBOSS" ] && echo "no" > $PREFDIR/fontemboss

LABEL_GEOMETRY=$(cat $PREFDIR/labelgeometry 2>/dev/null)
[ ! "$LABEL_GEOMETRY" ] && echo "bottom R" > $PREFDIR/labelgeometry

LABEL_ALIGN=$(cat $PREFDIR/labelalign 2>/dev/null)
[ ! "$LABEL_ALIGN" ] && echo "center" > $PREFDIR/labelalign

#current graphic logo settings
GRAPHIC_LOGO=$(cat $PREFDIR/graphic-logo 2>/dev/null)

GRAPHIC_XPOS=$(cat $PREFDIR/graphic-xpos 2>/dev/null)
[ ! "$GRAPHIC_XPOS" ] && GRAPHIC_XPOS="0"

GRAPHIC_YPOS=$(cat $PREFDIR/graphic-ypos 2>/dev/null)
[ ! "$GRAPHIC_YPOS" ] && GRAPHIC_YPOS="0"

#current graphic format and file filters
if [ "$(which rsvg-convert 2>/dev/null)" ]; then
 FORMAT="$(gettext 'Wallpaper graphic (png or svg format)')"
 FS_FILTERS="*.png|*.svg"
else
 FORMAT="$(gettext 'Wallpaper graphic (png format)')"
 FS_FILTERS="*.png"
fi

#image viewer
for i in fotoxx geeqie gpicview gqview gwenview ristretto viewnior xnview; do [ "`which $i 2>/dev/null`" ] && { VIEWER="$i"; break; } done
export VIEWER

#file manager
for i in pcmanfm rox spacefm Thunar xfe; do [ "`which $i 2>/dev/null`" ] && { FILER="$i"; break; } done
export FILER

#wallpaper manager
if [ "$CURRWM" = "startlxde" -o "$CURRWM" = "openbox-lxde" -o "$CURRWM" = "lxsession" ]; then
 WALL_MGR="sleep 1 ; pcmanfm --desktop-pref" #sleep to open desktop-pref window on top
elif [ "$CURRWM" = "startxfce4" -o "$CURRWM" = "xfce4-session" -o "$CURRWM" = "xfwm4" ]; then
 WALL_MGR="xfdesktop-settings"
elif [ -f /usr/local/apps/Wallpaper2/AppRun ]; then
 WALL_MGR="/usr/local/apps/Wallpaper2/AppRun"
elif [ -f /usr/local/apps/Wallpaper/AppRun ]; then
 WALL_MGR="/usr/local/apps/Wallpaper/AppRun"
elif [ "`which qwallpaper 2>/dev/null`" ]; then
 WALL_MGR="qwallpaper"
elif [ "`which pwallpaper 2>/dev/null`" ]; then
 WALL_MGR="pwallpaper"
fi

WALLMANAGER=""
if [ "$WALL_MGR" ]; then
 WALLMANAGER="
     <button tooltip-text=\" $(gettext 'Open wallpaper manager') \">
      <label>\" $(gettext 'Walls')\"</label>
      <input file stock=\"gtk-jump-to\"></input>
      <action>$WALL_MGR &</action>
     </button>"
fi

#wallpaper directory
WALLDIR=$(cat $PREFDIR/walldir 2>/dev/null)
if [ ! "$WALLDIR" ]; then
 WALLDIR="/usr/share/backgrounds/"
 echo "$WALLDIR" > $PREFDIR/walldir
fi

###############################################################################
#
# Functions
#
###############################################################################

#convert hex color values to floats
hex2float()
{
red=$(echo ${BGCOLOR:1:2})                  #parse red, green, blue hex values
green=$(echo ${BGCOLOR:3:2})
blue=$(echo ${BGCOLOR:5:2})

red="$((16#$red))"                          #convert hex values to base16
green="$((16#$green))"
blue="$((16#$blue))"

red=$(echo "scale=3; $red / 255.0" | bc)    #convert base16 integers to floats
green=$(echo "scale=3; $green / 255.0" | bc)
blue=$(echo "scale=3; $blue / 255.0" | bc)

BACKGROUND_COLOR="$red $green $blue"
}
export -f hex2float

#convert gui selections to mkwallpaper format
gui2mkw()
{
IMAGE_NAME=$(echo "$IMAGE_NAME" | sed 's/ //g')
X=$(echo "$IMAGE_SIZE" | cut -f1 -d'x')
Y=$(echo "$IMAGE_SIZE" | cut -f2 -d'x')
if [ "$FONT_WEIGHT" = "normal" ] && [ "$FONT_STYLE" = "normal" ]; then
 FONT_ATTRIBUTE="n"
elif [ "$FONT_WEIGHT" = "bold" ] && [ "$FONT_STYLE" = "normal" ]; then
 FONT_ATTRIBUTE="b"
elif [ "$FONT_WEIGHT" = "normal" ] && [ "$FONT_STYLE" = "italic" ]; then
 FONT_ATTRIBUTE="i"
else
 FONT_ATTRIBUTE="o"
fi
if [ "$LABEL_GEOMETRY" = "top L" ]; then
 LABEL_GEOMETRY="tl"
elif [ "$LABEL_GEOMETRY" = "bottom L" ]; then
 LABEL_GEOMETRY="bl"
elif [ "$LABEL_GEOMETRY" = "top R" ]; then
 LABEL_GEOMETRY="tr"
else
 LABEL_GEOMETRY="br"
fi
if [ "$LABEL_ALIGN" = "left" ]; then
 LABEL_ALIGN="0"
elif [ "$LABEL_ALIGN" = "right" ]; then
 LABEL_ALIGN="2"
else
 LABEL_ALIGN="1"
fi
[ ! "$GRAPHIC_XPOS" ] && GRAPHIC_XPOS="0"
[ ! "$GRAPHIC_YPOS" ] && GRAPHIC_YPOS="0"
GRAPHIC=""
if [ "$GRAPHIC_LOGO" ]; then
 FILENAME="${GRAPHIC_LOGO##*/}" #with extension
 FILENAMEnx="${FILENAME%.*}" #no extension
 EXTENSION="${FILENAME##*.}"
 if [ "$EXTENSION" = "png" -o "$EXTENSION" = "PNG" ]; then
  [ ! "`file -b -L $GRAPHIC_LOGO | grep PNG 2>/dev/null`" ] && Xdialog --title "$(gettext 'Alert')" --beep --no-buttons --msgbox "\n $FILENAME \n\n  $(gettext 'Not identified as png image!')  \n" 0 0 && exit 0
  GRAPHIC="-e $GRAPHIC_LOGO $GRAPHIC_XPOS $GRAPHIC_YPOS"
 elif [ "$EXTENSION" = "svg" -o "$EXTENSION" = "SVG" ]; then
  [ ! "`file -b -L $GRAPHIC_LOGO | grep SVG 2>/dev/null`" ] && Xdialog --title "$(gettext 'Alert')" --beep --no-buttons --msgbox "\n $FILENAME \n\n  $(gettext 'Not identified as svg image!')  \n" 0 0 && exit 0
  if [ "$(which rsvg-convert)" ]; then
   rsvg-convert -f png -o $TMPDIR2/$FILENAMEnx.png $GRAPHIC_LOGO
   GRAPHIC_LOGO="$TMPDIR2/$FILENAMEnx.png"
   GRAPHIC="-e $GRAPHIC_LOGO $GRAPHIC_XPOS $GRAPHIC_YPOS"
  fi
 fi
fi
}
export -f gui2mkw

#open wallpaper directory
open_walldir()
{
WALLDIR=$(cat $PREFDIR/walldir 2>/dev/null)
$FILER $WALLDIR &
}
export -f open_walldir

#preview single background image
preview_wallpaper()
{
[ ! "$IMAGE_NAME" ] && Xdialog --title "$(gettext 'Alert')" --beep --no-buttons --msgbox "\n $(gettext 'Please enter an image filename!') \n" 0 0 && exit 0
gui2mkw
hex2float
mkwallpaper -n "$IMAGE_NAME" -l "$IMAGE_LABEL" -f "$FONT_NAME" -s "$FONT_SIZE" -b "$FONT_ATTRIBUTE" -k "$FONT_EMBOSS" -p "$IMAGE_FORMAT" -x "$X" -y "$Y" -z "$BACKGROUND_COLOR" -o "$GRADIENT_OFFSET" -a "$GRADIENT_ANGLE" -j "$LABEL_GEOMETRY" -i "$LABEL_ALIGN" "$GRAPHIC" -d "$TMPDIR1"
killall $VIEWER 2>/dev/null
$VIEWER $TMPDIR1/$IMAGE_NAME.$IMAGE_FORMAT
}
export -f preview_wallpaper

#make single background image
make_wallpaper()
{
[ ! "$IMAGE_NAME" ] && Xdialog --title "$(gettext 'Alert')" --beep --no-buttons --msgbox "\n $(gettext 'Please enter an image filename!') \n" 0 0 && exit 0
gui2mkw
hex2float
mkwallpaper -n "$IMAGE_NAME" -l "$IMAGE_LABEL" -f "$FONT_NAME" -s "$FONT_SIZE" -b "$FONT_ATTRIBUTE" -k "$FONT_EMBOSS" -p "$IMAGE_FORMAT" -x "$X" -y "$Y" -z "$BACKGROUND_COLOR" -o "$GRADIENT_OFFSET" -a "$GRADIENT_ANGLE" -j "$LABEL_GEOMETRY" -i "$LABEL_ALIGN" "$GRAPHIC" -d "$WALLDIR"
switch_wallpaper
[ -f /usr/share/backgrounds_original/ORIGINAL-"$IMAGE_NAME.$IMAGE_FORMAT" ] && rm -f /usr/share/backgrounds_original/ORIGINAL-"$IMAGE_NAME.$IMAGE_FORMAT"
}
export -f make_wallpaper

#make 10 random background images
make_randomwallpaper()
{
[ ! "$IMAGE_NAME" ] && Xdialog --title "$(gettext 'Alert')" --beep --no-buttons --msgbox "\n $(gettext 'Please enter a base image filename!') \n" 0 0 && exit 0
gui2mkw
x=1
while [ $x -le 10 ]; do #make images 1-10 with random offset, angle and color
   off="0.${RANDOM}"
   ang=($[ 1 + $[ RANDOM % 20 ]])
   r="0.${RANDOM}"
   g="0.${RANDOM}"
   b="0.${RANDOM}"
   echo -n "$r $g $b : "
   mkwallpaper -n "${IMAGE_NAME}-wall${x}" -l "$IMAGE_LABEL" -f "$FONT_NAME" -s "$FONT_SIZE" -b "$FONT_ATTRIBUTE" -k "$FONT_EMBOSS" -p "$IMAGE_FORMAT" -x "$X" -y "$Y" -z "$r $g $b" -o "$off" -a "$ang" -j "$LABEL_GEOMETRY" -i "$LABEL_ALIGN" "$GRAPHIC" -d "$WALLDIR"
   unset off ang r g b
   x=$(($x + 1))
done
if [ -d /usr/share/backgrounds_original ]; then
 for x in {1..10}; do rm -f /usr/share/backgrounds_original/ORIGINAL-"${IMAGE_NAME}-wall${x}.$IMAGE_FORMAT" 2>/dev/null; done
fi
Xdialog --title "$(gettext 'Save')" --no-buttons --infobox "\n     $(gettext "10 wallpapers saved to")     \n\n     $WALLDIR     \n" 0 0 3000
}
export -f make_randomwallpaper

#switch wallpaper
switch_wallpaper()
{
if [ "$CURRWM" = "startlxde" -o "$CURRWM" = "openbox-lxde" -o "$CURRWM" = "lxsession" ]; then
 pcmanfm --set-wallpaper=$WALLDIR$IMAGE_NAME.$IMAGE_FORMAT
else
 if [ "`which busybox`" ]; then
  ROXRUNNING=`busybox ps|grep "/usr/local/apps/ROX-Filer/ROX-Filer -p /root/Choices/ROX-Filer/PuppyPin"|grep -v "grep"`
 else
  ROXRUNNING=`ps -aux|grep "/usr/local/apps/ROX-Filer/ROX-Filer -p /root/Choices/ROX-Filer/PuppyPin"|grep -v "grep"`
 fi
 [ ! "$ROXRUNNING" ] && ROXRUNNING=`ps -aux|grep "/usr/share/ROX-Filer/ROX-Filer -p /root/.config/rox.sourceforge.net/ROX-Filer/PuppyPin"|grep -v "grep"` #Fatdog
 if [ "$ROXRUNNING" ]; then
  [ -f /usr/local/apps/Wallpaper/set_bg ] && [ ! "`which set_bg 2>/dev/null`" ] && ln -sf /usr/local/apps/Wallpaper/set_bg /usr/bin
  WALLDIR_ESC=$(echo "$WALLDIR" | sed -e 's%\/%\\/%g')
  echo -n "Stretch" > $HOME/.config/wallpaper/backgroundmode
  echo -n "$WALLDIR$IMAGE_NAME.$IMAGE_FORMAT" > $HOME/.config/wallpaper/bg_img
  [ ! "`which set_bg`" ] && sed -i -e "s/^.*<backdrop style=.*$/  <backdrop style=\"Stretched\">$WALLDIR_ESC$IMAGE_NAME.$IMAGE_FORMAT<\/backdrop>/" $HOME/Choices/ROX-Filer/PuppyPin
  [ "`which set_bg`" ] && set_bg $WALLDIR$IMAGE_NAME.$IMAGE_FORMAT || rox --pinboard=/root/Choices/ROX-Filer/PuppyPin
 fi
fi
PWIDGETS_PID=$(ps | grep -w conky | grep -vw grep | grep -w pwidgets)
CONKY_PID=$(ps | grep -w conky | grep -Ewv 'conky\.conf|grep|pwidgets')
if [ "$PWIDGETS_PID" ]; then
 for I in `ps -eo pid,command | grep -Ew "conky|xonclock|http://rss.accuweather.com" | awk '{print $1}'`; do kill -9 $I; done
 $HOME/.pwidgets/pwidgets-exec &
fi
if [ "$CONKY_PID" ]; then
 for I in `ps -eo pid,command | grep -w conky | grep -vw 'conky\.conf' | awk '{print $1}'`; do kill -9 $I; done
 if [ -f $HOME/Startup/conkystart ]; then
  $HOME/Startup/conkystart &
  [ -f $HOME/Startup/conkyipstart ] && $HOME/Startup/conkyipstart &
 else
  conky &
 fi
fi
}
export -f switch_wallpaper

###############################################################################
#
# Help dialog
#
###############################################################################

mkwver=$(mkwallpaper -h | head -n1 | cut -d'-' -f2) || mkwver=""
export mkwver
mkwgui_help()
{
export MKW_GUI_HELP="
<window title=\"Mkwallpaper-gui\" icon-name=\"mkwallpaper64\" window-position=\"2\">
 <notebook labels=\"$(gettext 'About')|$(gettext 'License')\">
  <frame>
   <pixmap><input file>$WORKDIR/icons/mkwallpaper64.png</input><height>48</height><width>48</width></pixmap>
   <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>Mkwallpaper-</span><span size='"'x-large'"' color='"$COLOR"'>GUI</span> $VERSION</b>\"</label></text>
   <text use-markup=\"true\"><label>\"<b>$(gettext 'Make Desktop Wallpaper')</b>\"</label></text>
   <text><label>\"$(gettext 'Copyright (C) 2015-2016')\"</label></text>
   <text><label>\"Mkwallpaper "$mkwver" $(gettext 'by Michael Amadio')\"</label></text>
   <text><label>\"$(gettext 'Mkwallpaper-gui by Roger D. Grider')\"</label></text>
   <text height-request=\"10\"><label>\"\"</label></text>
   <hbox homogeneous=\"true\">
    <button width-request=\"170\" tooltip-text=\" $(gettext 'Go online to Mkwallpaper-gui forum') \">
     <label>\"$(gettext 'Online Forum')\"</label>
     <action>defaulthtmlviewer http://www.murga-linux.com/puppy/viewtopic.php?p=873722#873722 &</action>
    </button>
   </hbox>
  </frame>
  <frame>
   <text use-markup=\"true\"><label>\"$(gettext '<b>Mkwallpaper-gui</b> is free software which you can redistribute and/or modify under the terms of the <b>GNU General Public License</b> as published by the Free Software Foundation; either GPLv3 or later version.')

$(gettext 'This program is distributed in the hope that it will be useful, but') <b><span color='"'red'"'>$(gettext 'WITHOUT ANY WARRANTY')</span></b>. $(gettext 'See the GNU General Public License homepage below for additional information.')\"</label></text>
   <text height-request=\"20\"><label>\"\"</label></text>
   <hbox homogeneous=\"true\">
    <button>
     <label>\"   http://www.gnu.org/licenses/   \"</label>
     <action>defaulthtmlviewer http:\/\/www.gnu.org\/licenses\/ &</action>
    </button>
   </hbox>
  </frame>
 </notebook>
</window>"
$GTKDIALOG -p MKW_GUI_HELP
unset MKW_GUI_HELP
}
export -f mkwgui_help

###############################################################################
#
# Main dialog
#
###############################################################################

export MKW="
<window title=\"Mkwallpaper-gui\" icon-name=\"mkwallpaper64\" width-request=\"$WINDOW_WIDTH\" resizable=\"true\" window-position=\"1\">
  <vbox space-expand=\"false\" space-fill=\"true\">
   <text use-markup=\"true\"><label>\"<b><span size='"x-large"'>Mk</span><span size='"x-large"' color='"$COLOR"'>wallpaper</span> </b>\"</label></text>
   <vbox space-expand=\"true\" space-fill=\"true\" border-width=\"4\">
    <hbox space-expand=\"true\" space-fill=\"true\">
    <vbox>
     <frame $(gettext 'Background')>
     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Folder')</label></text>
     <hbox>
       <entry editable=\"false\" height-request=\"30\" width-request=\"245\" tooltip-text=\" $(gettext 'Wallpaper destination folder') \" fs-action=\"directory\" fs-folder=\""$WALLDIR"\" fs-title=\"$(gettext 'Wallpaper destination folder')\">
        <input>cat $PREFDIR/walldir</input>
        <variable>WALLDIR</variable>
       </entry>
       <button relief=\"1\" height-request=\"30\" width-request=\"30\" tooltip-text=\" $(gettext 'Folder selector') \">
        <input file>$WORKDIR/icons/open.png</input><height>16</height><width>16</width>
        <action>fileselect:WALLDIR</action>
        <action>echo \$WALLDIR\/ | sed -e 's%\/\/$%\/%g' > $PREFDIR/walldir</action>
        <action type=\"refresh\">WALLDIR</action>
       </button>
     </hbox>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Filename')</label></text>
       <entry height-request=\"30\" width-request=\"205\" tooltip-text=\" $(gettext 'Filename of wallpaper image') \">
        <variable>IMAGE_NAME</variable>
        <default>"$DISTRO_FILE_PREFIX"</default>
       </entry>
     </vbox>
     <vbox>
      <text><label>$(gettext 'Type')</label></text>
       <comboboxtext wrap-width=\"1\" height-request=\"30\" width-request=\"70\" tooltip-text=\" $(gettext 'Image format (Default: svg)') \">
        <variable>IMAGE_FORMAT</variable>
        <default>`cat $PREFDIR/imageformat`</default>
        <item>png</item>
        <item>svg</item>
       </comboboxtext>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Color')</label></text>
     <hbox>
       <entry editable=\"false\" height-request=\"30\" width-request=\"225\" tooltip-text=\" $(gettext 'Click the color selector button') \">
        <input>cat $PREFDIR/bgcolor</input>
        <variable>BGCOLOR</variable>
       </entry>
       <colorbutton height-request=\"30\" width-request=\"50\" title=\"$(gettext 'Background Color')\" tooltip-text=\" $(gettext 'Color selector') \">
        <input file>$PREFDIR/bgcolor</input>
        <variable>COLORBUTTON</variable>
        <action>echo \$COLORBUTTON > $PREFDIR/bgcolor</action>
        <action>refresh:BGCOLOR</action>
       </colorbutton>
     </hbox>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Size')</label></text>
       <comboboxtext wrap-width=\"5\" height-request=\"30\" width-request=\"280\" tooltip-text=\" $(gettext 'Select an image size to fit screen resolution') \">
        <variable>IMAGE_SIZE</variable>
        <default>"$SCREEN"</default>
        <item>640x400</item>
        <item>640x480</item>
        <item>800x480</item>
        <item>800x600</item>
        <item>854x480</item>
        <item>1024x600</item>
        <item>1024x768</item>
        <item>1152x864</item>
        <item>1200x1024</item>
        <item>1280x720</item>
        <item>1280x768</item>
        <item>1280x800</item>
        <item>1280x854</item>
        <item>1280x960</item>
        <item>1280x1024</item>
        <item>1360x768</item>
        <item>1366x768</item>
        <item>1400x1050</item>
        <item>1440x900</item>
        <item>1440x960</item>
        <item>1440x1050</item>
        <item>1440x1080</item>
        <item>1536x864</item>
        <item>1600x768</item>
        <item>1600x900</item>
        <item>1600x1200</item>
        <item>1680x1050</item>
        <item>1920x1080</item>
        <item>1920x1200</item>
        <item>1920x1280</item>
        <item>2048x1152</item>
        <item>2048x1536</item>
        <item>2160x1440</item>
        <item>2560x1440</item>
        <item>2560x1600</item>
        <item>2560x2048</item>
        <item>3000x2000</item>
        <item>3200x1800</item>
        <item>3200x2048</item>
        <item>3200x2400</item>
        <item>3360x1050</item>
        <item>3840x2160</item>
        <item>4096x2304</item>
        <item>4096x3072</item>
        <item>5120x2160</item>
        <item>5120x2880</item>
        <item>5120x3200</item>
        <item>5120x4096</item>
        <item>6400x4096</item>
        <item>6400x4800</item>
        <item>7680x4320</item>
        <item>7680x4800</item>
        <item>7800x4800</item>
        <item>8192x4608</item>
        <item>8192x8192</item>
       </comboboxtext>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Gradient Angle')</label></text>
       <spinbutton editable=\"false\" height-request=\"30\" width-request=\"280\" range-min=\"0\" range-max=\"20\" range-step=\"1\" range-value=\"10\" tooltip-text=\" $(gettext 'Angle of linear gradient (Default: 10)') \">
        <input file>$PREFDIR/gradientangle</input>
        <variable>GRADIENT_ANGLE</variable>
       </spinbutton>
     </vbox>
     </hbox>
     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Gradient Offset')</label></text>
       <spinbutton editable=\"false\" height-request=\"30\" width-request=\"280\" range-min=\"0.00\" range-max=\"1.00\" range-step=\"0.01\" range-value=\"0.65\" tooltip-text=\" $(gettext 'Location of gradient offset/stop (Default: 0.65)') \">
        <input file>$PREFDIR/gradientoffset</input>
        <variable>GRADIENT_OFFSET</variable>
       </spinbutton>
     </vbox>
     </hbox>
     </frame>
     </vbox>

     <vbox>
     <frame $(gettext 'Foreground')>
     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Label')</label></text>
       <entry height-request=\"30\" width-request=\"280\" tooltip-text=\" $(gettext 'Text of label (0-36 characters)') \">
        <variable>IMAGE_LABEL</variable>
        <default>"$DISTRO_NAME"</default>
       </entry>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Font')</label></text>
       <comboboxtext wrap-width=\"1\" height-request=\"30\" width-request=\"205\" tooltip-text=\" $(gettext 'Font of label (Default: Sans)') \">
        <variable>FONT_NAME</variable>
        <default>`cat $PREFDIR/fontname`</default>
        $FONT_NAME_ITEMS
       </comboboxtext>
     </vbox>
     <vbox>
      <text><label>$(gettext 'Size')</label></text>
       <spinbutton editable=\"false\" height-request=\"30\" width-request=\"70\" range-min=\"16\" range-max=\"200\" range-step=\"1\" range-value=\"72\" tooltip-text=\" $(gettext 'Size of label font (Default: 72px)') \">
        <input file>$PREFDIR/fontsize</input>
        <variable>FONT_SIZE</variable>
       </spinbutton>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Weight')</label></text>
       <comboboxtext wrap-width=\"1\" height-request=\"30\" width-request=\"90\" tooltip-text=\" $(gettext 'Normal or bold type') \">
        <variable>FONT_WEIGHT</variable>
        <default>`cat $PREFDIR/fontweight`</default>
        <item>normal</item>
        <item>bold</item>
       </comboboxtext>
     </vbox>
     <vbox>
      <text><label>$(gettext 'Style')</label></text>
       <comboboxtext wrap-width=\"1\" height-request=\"30\" width-request=\"90\" tooltip-text=\" $(gettext 'Normal or italic type') \">
        <variable>FONT_STYLE</variable>
        <default>`cat $PREFDIR/fontstyle`</default>
        <item>normal</item>
        <item>italic</item>
       </comboboxtext>
     </vbox>
     <vbox>
      <text><label>$(gettext 'Emboss')</label></text>
       <comboboxtext wrap-width=\"1\" height-request=\"30\" width-request=\"90\" tooltip-text=\" $(gettext 'Emboss label with highlights and shadows') \">
        <variable>FONT_EMBOSS</variable>
        <default>`cat $PREFDIR/fontemboss`</default>
        <item>no</item>
        <item>yes</item>
       </comboboxtext>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Geometry')</label></text>
       <comboboxtext wrap-width=\"1\" height-request=\"30\" width-request=\"138\" tooltip-text=\" $(gettext 'Geometric position of label (Default: bottom R)') \">
        <variable>LABEL_GEOMETRY</variable>
        <default>`cat $PREFDIR/labelgeometry`</default>
        <item>top L</item>
        <item>top R</item>
        <item>bottom L</item>
        <item>bottom R</item>
       </comboboxtext>
     </vbox>
     <vbox>
      <text><label>$(gettext 'Alignment')</label></text>
       <comboboxtext wrap-width=\"1\" height-request=\"30\" width-request=\"137\" tooltip-text=\" $(gettext 'Horizontal alignment of label (Default: center)') \">
        <variable>LABEL_ALIGN</variable>
        <default>`cat $PREFDIR/labelalign`</default>
        <item>left</item>
        <item>center</item>
        <item>right</item>
       </comboboxtext>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'Graphic Logo')</label></text>
     <hbox>
       <entry editable=\"false\" space-expand=\"true\" space-fill=\"true\" height-request=\"30\" width-request=\"245\" tooltip-text=\" $FORMAT \" fs-action=\"newfile\" fs-folder=\"/usr/share/pixmaps/\" fs-filters=\"$FS_FILTERS\" fs-title=\"$(gettext 'Wallpaper graphic')\" secondary-icon-stock=\"gtk-clear\" secondary-icon-tooltip-text=\" $(gettext 'Clear graphic') \">
        <input>cat $PREFDIR/graphic-logo</input>
        <variable>GRAPHIC_LOGO</variable>
        <action signal=\"secondary-icon-release\">echo "" > $PREFDIR/graphic-logo</action>
        <action signal=\"secondary-icon-release\">echo "0" > $PREFDIR/graphic-xpos</action>
        <action signal=\"secondary-icon-release\">echo "0" > $PREFDIR/graphic-ypos</action>
        <action signal=\"secondary-icon-release\">refresh:GRAPHIC_LOGO</action>
        <action signal=\"secondary-icon-release\">refresh:GRAPHIC_XPOS</action>
        <action signal=\"secondary-icon-release\">refresh:GRAPHIC_YPOS</action>
       </entry>
       <button relief=\"1\" space-expand=\"false\" space-fill=\"false\" height-request=\"30\" width-request=\"30\" tooltip-text=\" $(gettext 'Graphic selector') \">
        <input file>$WORKDIR/icons/open.png</input><height>16</height><width>16</width>
        <action>fileselect:GRAPHIC_LOGO</action>
        <action>echo "\$GRAPHIC_LOGO" > $PREFDIR/graphic-logo</action>
       </button>
     </hbox>
     </vbox>
     </hbox>

     <hbox space-expand=\"true\" space-fill=\"true\">
     <vbox>
      <text><label>$(gettext 'X-position')</label></text>
       <spinbutton editable=\"true\" height-request=\"30\" width-request=\"138\" range-min=\"0\" range-max=\"8000\" range-step=\"1\" range-value=\"0\" tooltip-text=\" $(gettext 'Graphic position on X-axis') \">
        <input file>$PREFDIR/graphic-xpos</input>
        <variable>GRAPHIC_XPOS</variable>
        <action>echo \$GRAPHIC_XPOS > $PREFDIR/graphic-xpos</action>
       </spinbutton>
     </vbox>
     <vbox>
      <text><label>$(gettext 'Y-position')</label></text>
       <spinbutton editable=\"true\" height-request=\"30\" width-request=\"137\" range-min=\"0\" range-max=\"8000\" range-step=\"1\" range-value=\"0\" tooltip-text=\" $(gettext 'Graphic position on Y-axis') \">
        <input file>$PREFDIR/graphic-ypos</input>
        <variable>GRAPHIC_YPOS</variable>
        <action>echo \$GRAPHIC_YPOS > $PREFDIR/graphic-ypos</action>
       </spinbutton>
     </vbox>
     </hbox>
     </frame>
    </vbox>
    </hbox>
   </vbox>

    <hbox homogeneous=\"true\" space-expand=\"false\" space-fill=\"true\">
     <button>
      <label>\" $(gettext 'Help')\"</label>
      <input file stock=\"gtk-help\"></input>
      <action>mkwgui_help &</action>
     </button>
     <button tooltip-text=\" $(gettext 'Open folder of wallpaper images') \">
      <label>\" $(gettext 'Files')\"</label>
      <input file>$WORKDIR/icons/directory.png</input><height>17</height><width>17</width>
      <action>open_walldir &</action>
     </button>
     $WALLMANAGER
    </hbox>

    <hbox homogeneous=\"true\" space-expand=\"false\" space-fill=\"true\">
     <button tooltip-text=\" $(gettext 'Preview wallpaper in default image viewer') \">
      <label>\" $(gettext 'Preview')\"</label>
      <input file stock=\"gtk-find\"></input>
      <action>echo \$IMAGE_FORMAT > $PREFDIR/imageformat</action>
      <action>echo \$FONT_NAME > $PREFDIR/fontname</action>
      <action>echo \$FONT_SIZE > $PREFDIR/fontsize</action>
      <action>echo \$FONT_WEIGHT > $PREFDIR/fontweight</action>
      <action>echo \$FONT_STYLE > $PREFDIR/fontstyle</action>
      <action>echo \$FONT_EMBOSS > $PREFDIR/fontemboss</action>
      <action>echo \$LABEL_GEOMETRY > $PREFDIR/labelgeometry</action>
      <action>echo \$LABEL_ALIGN > $PREFDIR/labelalign</action>
      <action>echo \$GRADIENT_ANGLE > $PREFDIR/gradientangle</action>
      <action>echo \$GRADIENT_OFFSET > $PREFDIR/gradientoffset</action>
      <action>preview_wallpaper &</action>
     </button>
     <button tooltip-text=\" $(gettext 'Make wallpaper') \">
      <label>\" $(gettext 'Apply')\"</label>
      <input file stock=\"gtk-apply\"></input>
      <action>echo \$IMAGE_FORMAT > $PREFDIR/imageformat</action>
      <action>echo \$FONT_NAME > $PREFDIR/fontname</action>
      <action>echo \$FONT_SIZE > $PREFDIR/fontsize</action>
      <action>echo \$FONT_WEIGHT > $PREFDIR/fontweight</action>
      <action>echo \$FONT_STYLE > $PREFDIR/fontstyle</action>
      <action>echo \$FONT_EMBOSS > $PREFDIR/fontemboss</action>
      <action>echo \$LABEL_GEOMETRY > $PREFDIR/labelgeometry</action>
      <action>echo \$LABEL_ALIGN > $PREFDIR/labelalign</action>
      <action>echo \$GRADIENT_ANGLE > $PREFDIR/gradientangle</action>
      <action>echo \$GRADIENT_OFFSET > $PREFDIR/gradientoffset</action>
      <action>make_wallpaper &</action>
     </button>
     <button tooltip-text=\" $(gettext 'Create ten (10) new wallpapers 
 of random colors and gradients. 
 Color, angle, offset are random. 
 The other settings above apply.') \">
      <label>\" $(gettext 'Batch')\"</label>
      <input file stock=\"gtk-media-forward\"></input>
      <action>echo \$IMAGE_FORMAT > $PREFDIR/imageformat</action>
      <action>echo \$FONT_NAME > $PREFDIR/fontname</action>
      <action>echo \$FONT_SIZE > $PREFDIR/fontsize</action>
      <action>echo \$FONT_WEIGHT > $PREFDIR/fontweight</action>
      <action>echo \$FONT_STYLE > $PREFDIR/fontstyle</action>
      <action>echo \$FONT_EMBOSS > $PREFDIR/fontemboss</action>
      <action>echo \$LABEL_GEOMETRY > $PREFDIR/labelgeometry</action>
      <action>echo \$LABEL_ALIGN > $PREFDIR/labelalign</action>
      <action>make_randomwallpaper &</action>
     </button>
     <button>
      <label>\" $(gettext 'Quit')\"</label>
      <input file stock=\"gtk-quit\"></input>
      <action type=\"exit\">quit_now</action>
     </button>
    </hbox>
  </vbox>
</window>"

$GTKDIALOG -p MKW

rm -r $TMPDIR1 $TMPDIR2

unset MKW

exit 0
