#!/bin/sh
# JWMDesk Theme Manager: preferences

export TEXTDOMAIN=jwmdesk
export OUTPUT_CHARSET=UTF-8
. gettext.sh

APPDIR=/usr/local/jwmdesk

[ "`which gtkdialog4 2>/dev/null`" ] && GTKDIALOG=gtkdialog4 || GTKDIALOG=gtkdialog
if [ "`which gtk2dialog 2>/dev/null`" ]; then
	gtk2_dialog=$(cat $APPDIR/.jcc/gtk2-dialog 2>/dev/null)
	[ ! "$gtk2_dialog" ] && gtk2_dialog="true" && echo "$gtk2_dialog" > $APPDIR/.jcc/gtk2-dialog
	[ "$gtk2_dialog" = "true" ] && GTKDIALOG=gtk2dialog
fi

# define legacy background (wallpaper) option
wallpaper_option=$(cat $APPDIR/.jcc/wallpaper 2>/dev/null)
if [ ! "$wallpaper_option" ]; then
	if [ -f /usr/local/apps/Wallpaper/AppRun ]; then
		wallpaper_option="Nathan Wallpaper"
	else
		wallpaper_option="Qwallpaper"
	fi
fi
[ -f /usr/local/apps/Wallpaper/AppRun ] && WALLPAPER="<item>Nathan Wallpaper</item>" || WALLPAPER=""

# define background text color
bg_text_color=$(cat $APPDIR/.jcc/bg-text-color 2>/dev/null)
[ ! "$bg_text_color" ] && bg_text_color="#FFF (white)" && echo "$bg_text_color" > $APPDIR/.jcc/bg-text-color

ps="`busybox ps`"
echo "$ps" | grep -q -m1 "ROX-Filer -p" && ROX_PINBOARD="yes"

if [ "$ROX_PINBOARD" = "yes" ]; then
	BTC="
		<hseparator space-expand=\"false\" space-fill=\"false\"></hseparator>

		<vbox margin=\"5\" space-expand=\"true\" space-fill=\"true\">
		<hbox homogeneous=\"true\">
			<text use-markup=\"true\" homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\"><label>\"<b><span size='"'medium'"'>$(gettext 'Background Text Color')</span></b>\"</label></text>
		</hbox>
		<hbox homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\">
			<comboboxtext wrap-width=\"1\" space-expand=\"true\" space-fill=\"true\">
				<variable>bg_text_color</variable>
				<default>$bg_text_color</default>
				<item>#000 (black)</item>
				<item>#FFF (white)</item>
				<action>echo \$bg_text_color > $APPDIR/.jcc/bg-text-color</action>
			</comboboxtext>
		</hbox>
		</vbox>"
else
	BTC=""
fi

# define background gradient
bg_gradient_orientation=$(cat $APPDIR/.jcc/bg-gradient-orientation 2>/dev/null)
[ ! "$bg_gradient_orientation" ] && bg_gradient_orientation="radial" && echo "$bg_gradient_orientation" > $APPDIR/.jcc/bg-gradient-orientation

custom_gradient_colors=$(cat $APPDIR/.jcc/custom-colors 2>/dev/null)
[ ! "$custom_gradient_colors" ] && custom_gradient_colors="true" && echo "$custom_gradient_colors" > $APPDIR/.jcc/custom-colors
[ "$custom_gradient_colors" = "true" ] && ssc=true || ssc=false

bg_color1=$(cat $APPDIR/.jcc/bg-color1 2>/dev/null)
[ ! "$bg_color1" ] && bg_color1="#0D465F" && echo "$bg_color1" > $APPDIR/.jcc/bg-color1

bg_color2=$(cat $APPDIR/.jcc/bg-color2 2>/dev/null)
[ ! "$bg_color2" ] && bg_color2="#26A269" && echo "$bg_color2" > $APPDIR/.jcc/bg-color2

# define filemanager
for f in defaultfilemanager roxfiler rox pcmanfm Thunar; do [ "`which $f 2>/dev/null`" ] && { FILEMANAGER="$f"; break; } done
export FILEMANAGER

# GUI
export PREFERENCES="
<window title=\"$(gettext 'Preferences')\" icon-name=\"jwm_themes\" resizable=\"false\" window-position=\"2\">
	<vbox space-expand=\"true\" space-fill=\"true\">
		<vbox margin=\"5\" space-expand=\"true\" space-fill=\"true\">
		<hbox homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\">
			<text use-markup=\"true\" homogeneous=\"true\"><label>\"<b><span size='"'medium'"'>$(gettext 'Wallpaper Selector')</span></b>\"</label></text>
		</hbox>
		<hbox homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\">
			<comboboxtext wrap-width=\"1\" space-expand=\"true\" space-fill=\"true\">
				<variable>wallpaper</variable>
				<default>$wallpaper_option</default>
				${WALLPAPER}
				<item>Qwallpaper</item>
				<action>echo \$wallpaper > $APPDIR/.jcc/wallpaper</action>
			</comboboxtext>
		</hbox>
		</vbox>

		$BTC

		<hseparator space-expand=\"false\" space-fill=\"false\"></hseparator>

		<vbox margin=\"5\" space-expand=\"true\" space-fill=\"true\">
		<hbox homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\">
			<text use-markup=\"true\" homogeneous=\"true\"><label>\"<b><span size='"'medium'"'>$(gettext 'Background Gradient Properties')</span></b>\"</label></text>
		</hbox>
		<hbox space-expand=\"true\" space-fill=\"true\">
			<vbox space-expand=\"true\" space-fill=\"true\">
				<hbox homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\">
					<text homogeneous=\"true\"><label>\"$(gettext 'Orientation')\"</label></text>
				</hbox>
				<hbox homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\">
					<comboboxtext wrap-width=\"1\" space-expand=\"true\" space-fill=\"true\" tooltip-text=\" Direction of gradient vector \">
						<variable>bg_gradient_orientation</variable>
						<default>$bg_gradient_orientation</default>
						<item>horizontal</item>
						<item>oblique</item>
						<item>vertical</item>
						<item>radial</item>
						<action>echo \$bg_gradient_orientation > $APPDIR/.jcc/bg-gradient-orientation</action>
					</comboboxtext>
				</hbox>
				<hbox homogeneous=\"true\" space-expand=\"false\" space-fill=\"false\">
					<checkbox tooltip-text=\" $(gettext 'Enable custom colors for the background gradient') 
 $(gettext 'or uncheck for a gradient with JWM theme colors.') \">
						<label>$(gettext 'Custom colors')</label>
						<variable>custom_gradient_colors</variable>
						<input file>$APPDIR/.jcc/custom-colors</input>
						<action>if true echo true > $APPDIR/.jcc/custom-colors</action>
						<action>if true enable:bg_color1</action>
						<action>if true enable:bg_color2</action>
						<action>if false echo false > $APPDIR/.jcc/custom-colors</action>
						<action>if false disable:bg_color1</action>
						<action>if false disable:bg_color2</action>
					</checkbox>
				</hbox>
				<hbox homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\">
				<vbox space-expand=\"true\" space-fill=\"true\">
					<colorbutton sensitive=\"$ssc\" height-request=\"35\" width-request=\"120\" space-expand=\"true\" space-fill=\"true\" title=\"Gradient color-1\" tooltip-text=\" First color of gradient \">
						<input file>$APPDIR/.jcc/bg-color1</input>
						<variable>bg_color1</variable>
						<action>echo \$bg_color1 > $APPDIR/.jcc/bg-color1</action>
					</colorbutton>
				</vbox>
				<vbox space-expand=\"true\" space-fill=\"true\">
					<colorbutton sensitive=\"$ssc\" height-request=\"35\" width-request=\"120\" space-expand=\"true\" space-fill=\"true\" title=\"Gradient color-2\" tooltip-text=\" Second color of gradient \">
						<input file>$APPDIR/.jcc/bg-color2</input>
						<variable>bg_color2</variable>
						<action>echo \$bg_color2 > $APPDIR/.jcc/bg-color2</action>
					</colorbutton>
				</vbox>
				</hbox>
			</vbox>
		</hbox>
		</vbox>
		<hseparator space-expand=\"false\" space-fill=\"false\"></hseparator>
		<hbox homogeneous=\"true\" space-expand=\"true\" space-fill=\"true\">
			<button space-expand=\"true\" space-fill=\"true\">
				<label>$(gettext 'Files')</label>
				<input file>$APPDIR/icons/manage.svg</input><height>20</height><width>20</width>
				<action>$FILEMANAGER /usr/share/backgrounds &</action>
			</button>
			<button space-expand=\"true\" space-fill=\"true\">
				<label>\"$(gettext 'Quit')\"</label>
				<input file>$APPDIR/icons/quit.svg</input><height>20</height><width>20</width>
				<action type=\"exit\">quit_now</action>
			</button>
		</hbox>
	</vbox>
</window>"

$GTKDIALOG -p PREFERENCES
unset PREFERENCES

exit 0

###END###
