#!/bin/bash

export TEXTDOMAIN=jwmdesk
export OUTPUT_CHARSET=UTF-8
APPDIR="/usr/local/jwmdesk"
ICONDIR="$APPDIR/icons"

[ "`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
export GTKDIALOG

[ ! -f /usr/share/icons/hicolor/48x48/apps/theme_switcher.svg ] && \
ln -sf $ICONDIR/theme_switcher.svg /usr/share/icons/hicolor/48x48/apps && gtk-update-icon-cache -f -i /usr/share/icons/hicolor 2>/dev/null

if [ "`grep 'ptheme' /usr/sbin/icon_switcher 2>/dev/null`" ]; then
 cat /usr/sbin/icon_switcher | sed 's%which ptheme%which pthemexx 2>\/dev\/null%' > /tmp/icon_switcher
 chmod 755 /tmp/icon_switcher
 ICONSWITCHER_EXE="/tmp/icon_switcher"
else
 ICONSWITCHER_EXE="icon_switcher"
fi

if [ "`grep 'ptheme' /usr/sbin/pcur 2>/dev/null`" ]; then
 cat /usr/sbin/pcur | sed 's%which ptheme%which pthemexx 2>\/dev\/null%' > /tmp/pcur
 [ ! "`grep 'xml_button-icon internet\.svg' /tmp/pcur`" ] && sed -i 's/xml_button-icon internet/xml_button-icon internet.svg/' /tmp/pcur
 chmod 755 /tmp/pcur
 CURSOR_EXE="/tmp/pcur"
else
 CURSOR_EXE="pcur"
fi

export LEGACY_THEMING='
<window title="'$(gettext 'Puppy Desktop')'" icon-name="theme_switcher" resizable="true">
<vbox width-request="600" space-expand="true" space-fill="true">

  <text use-markup="true" homogeneous="true" space-expand="false" space-fill="true"><label>"'"<b><span size='"'x-large'"'>$(gettext 'Legacy Theme Tools')</span></b>"'"</label></text>
      
  <vbox space-expand="true" space-fill="true">
      <hseparator space-expand="false" space-fill="false"></hseparator>
      <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
        <button image-position="2">
          <label>'$(gettext 'Background')'</label>
          <input file>'$ICONDIR'/wallpaper.svg</input><height>64</height><width>64</width>
          <action>/usr/local/apps/Wallpaper/AppRun &</action>
        </button>
        <button image-position="2">
          <label>'$(gettext 'GTK Theme')'</label>
          <input file>'$ICONDIR'/gtk_themes.svg</input><height>64</height><width>64</width>
          <action>'$APPDIR'/ptheme_gtk &</action>
        </button>
        <button image-position="2">
          <label>'$(gettext 'JWM Theme')'</label>
          <input file>'$ICONDIR'/jwm_themes.svg</input><height>64</height><width>64</width>
          <action>'$APPDIR'/theme_switcher &</action>
        </button>
        <button image-position="2">
          <label>'$(gettext 'Title Bar')'</label>
          <input file>'$ICONDIR'/close.svg</input><height>64</height><width>64</width>
          <action>'$APPDIR'/window_buttons &</action>
        </button>
      </hbox>

      <hbox spacing="10" homogeneous="true" space-expand="true" space-fill="true">
        <button image-position="2">
          <label>'$(gettext 'Icon Theme')'</label>
          <input file>'$ICONDIR'/desktop_icons.svg</input><height>64</height><width>64</width>
          <action>'$ICONSWITCHER_EXE' &</action>
        </button>
        <button image-position="2">
          <label>'$(gettext 'Icon Layout')'</label>
          <input file>'$ICONDIR'/desktop.svg</input><height>64</height><width>64</width>
          <action>/usr/local/desksetup/desksetup.sh &</action>
        </button>
        <button image-position="2">
          <label>'$(gettext 'Mouse Cursor')'</label>
          <input file>'$ICONDIR'/mouse_cursor.svg</input><height>64</height><width>64</width>
          <action>'$CURSOR_EXE' &</action>
        </button>
        <button image-position="2">
          <label>'$(gettext 'Screen Font')'</label>
          <input file>'$ICONDIR'/font.svg</input><height>64</height><width>64</width>
          <action>fontmanager &</action>
        </button>
      </hbox>
  </vbox>
</vbox>
<action signal="key-press-event" condition="command_is_true([ $KEY_SYM = Escape ] && echo true )">exit:EXIT</action>
</window>'

$GTKDIALOG -p LEGACY_THEMING --geometry +50+50
unset LEGACY_THEMING

