#!/bin/bash
#pRun 1.7.2
#Preferences (radky)

export TEXTDOMAIN=prun
export OUTPUT_CHARSET=UTF-8

export VERSION="1.7.2"

#functions
func_prunhelp (){
export PRUN_HELP="
<window default-width=\"425\" title=\"pRun\" icon-name=\"prun48\" window-position=\"3\" resizable=\"false\">
    <vbox margin=\"10\" width-request=\"425\">
        <pixmap><input file>$WORKDIR/icons/prun48.png</input><height>48</height><width>48</width></pixmap>
        <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>pRun</span> $VERSION</b>\"</label></text>
        <text use-markup=\"true\"><label>\"<b>$(gettext 'GTK-based Run Dialog')</b>\"</label></text>
        <text><label>\"Roger D. Grider (C) 2013-2025 GPL3\"</label></text>
        <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>
        <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>
        <hbox space-expand=\"false\" space-fill=\"true\" homogeneous=\"true\">
            <button>
                <label>\"$(gettext 'Help')\"</label>
                <action>defaultbrowser $WORKDIR/Help.html &</action>
            </button>
            <button tooltip-text=\" http://www.gnu.org/licenses \">
                <label>\"$(gettext 'License')\"</label>
                <action>defaulthtmlviewer http:\/\/www.gnu.org\/licenses\/ &</action>
            </button>
        </hbox>
    </vbox>
</window>"
$GTKDIALOG -p PRUN_HELP
unset PRUN_HELP
}
export -f func_prunhelp

#define current window manager
CURRWM=$(cat /etc/windowmanager)

#define TERMINAL for terminal combobox
TERMINAL=$(cat $WORKDIR/preferences/terminal_emulator 2>/dev/null)
if [ ! "$TERMINAL" ]; then
   TERMINAL="rxvt"
   echo "rxvt" > $WORKDIR/preferences/terminal_emulator
fi

TERMINAL_ARRAY=("rxvt" "urxvt" "mrxvt" "aterm" "xterm" "konsole" "roxterm" "sakura" "Terminal" "terminal" "termit" "lxterminal")
TERMINAL_ITEMS="<item>$TERMINAL</item>"
for i in "${TERMINAL_ARRAY[@]}"
do
   if [ "$i" != "$TERMINAL" ]; then
      if [  "`which $i`" != "" ]; then
         TERMINAL_ITEMS=`echo "$TERMINAL_ITEMS<item>$i</item>"`
      fi
   fi
done

#define hotkey compatibility
if [ "$CURRWM" = "startxfce4" -o "$CURRWM" = "xfce4-session" -o "$CURRWM" = "xfwm4" -o "$CURRWM" = "startkde" -o "`pidof enlightenment`" ]; then
 HOTKEY=""
else
 HOTKEY="
     <button height-request=\"35\" width-request=\"110\" tooltip-text=\" $(gettext 'Set Ctrl+Alt+R hotkey') \">
      <label>$(gettext 'Key')</label>
      <input file>$WORKDIR/icons/keyboard20.png</input>
      <action>. $WORKDIR/hkey_func -prun_hotkey &</action>
     </button>"
fi

#auto-adjust header text color for light or dark GTK themes
if [ "`grep -a 'Stardust_dark' $HOME/.gtkrc-2.0 2>/dev/null`" ]; then #gold text for unique Stardust dark-grey-orange themes
   COLOR=#D7B740
else #light-blue text for common dark themes, otherwise medium blue
   [ "`grep -aEi 'black|dark|dusk|night|nox' $HOME/.gtkrc-2.0 2>/dev/null | grep -av xfdark`" ] && COLOR=#84aad9 || COLOR=#3272C0
fi
export COLOR

#Preferences dlg...
export PR_PREFERENCES="
<window title=\"$(gettext 'PR-Preferences')\" icon-name=\"prun48\" resizable=\"false\" window-position=\"1\">
 <vbox>
  <text use-markup=\"true\"><label>\"<b><span size='"'x-large'"'>p</span><span size='"'x-large'"' color='"$COLOR"'>Run</span> $VERSION</b>\"</label></text>

   <vbox width-request=\"400\">
   <vbox>

   <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>
   <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>

   <hbox homogeneous=\"true\">
   <vbox>
    <text><label>$(gettext 'GUI Height')</label></text>
   <hbox>
     <spinbutton sensitive=\"$HS\" width-request=\"120\" range-min=\"24\" range-max=\"300\" range-step=\"1\" range-value=\"120\" has-focus=\"true\" tooltip-text=\" $(gettext 'Height of applications window') \">
      <variable>TREE_HEIGHT</variable>
      <input>cat $WORKDIR/preferences/tree_height</input>
      <action>echo \$TREE_HEIGHT > $WORKDIR/preferences/tree_height</action>
     </spinbutton>
   </hbox>
   </vbox>
   <vbox>
    <text><label>$(gettext 'GUI Width')</label></text>
   <hbox>
     <spinbutton width-request=\"120\" range-min=\"300\" range-max=\"800\" range-step=\"1\" range-value=\"420\" tooltip-text=\" $(gettext 'Width of applications window') \">
      <variable>TREE_WIDTH</variable>
      <input>cat $WORKDIR/preferences/tree_width</input>
      <action>echo \$TREE_WIDTH > $WORKDIR/preferences/tree_width</action>
     </spinbutton>
   </hbox>
   </vbox>
   </hbox>

   <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>

   <hbox homogeneous=\"true\">
     <checkbox tooltip-text=\" $(gettext 'Minimal height of applications window') \">
      <label>$(gettext 'Mini-GUI')  </label>
      <variable>MINI_GUI</variable>
      <input>cat $WORKDIR/preferences/mini_gui</input>
      <action>if true echo true > $WORKDIR/preferences/mini_gui</action>
      <action>if true disable:TREE_HEIGHT</action>
      <action>if false echo false > $WORKDIR/preferences/mini_gui</action>
      <action>if false enable:TREE_HEIGHT</action>
      <action>refresh:TREE_HEIGHT</action>
     </checkbox>
   </hbox>

   <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>
   <hseparator space-expand=\"false\" space-fill=\"false\"></hseparator>
   <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>

   <hbox homogeneous=\"true\">
     <checkbox tooltip-text=\" $(gettext 'Automatically close pRun after 
 launching selected application.') \">
      <label>$(gettext 'Auto-close')  </label>
      <variable>CLOSE_PRUN</variable>
      <input>cat $WORKDIR/preferences/close_prun</input>
      <action>if true echo true > $WORKDIR/preferences/close_prun</action>
      <action>if false echo false > $WORKDIR/preferences/close_prun</action>
     </checkbox>
     <checkbox tooltip-text=\" $(gettext 'Enable double-click launching of applications. 
 Caveat: Many utilities have no user interface.') \">
      <label>$(gettext 'Double-click')</label>
      <variable>DOUBLE_CLICK</variable>
      <input>cat $WORKDIR/preferences/double_click</input>
      <action>if true echo true > $WORKDIR/preferences/double_click</action>
      <action>if false echo false > $WORKDIR/preferences/double_click</action>
     </checkbox>
   </hbox>

   <hseparator space-expand=\"false\" space-fill=\"false\"></hseparator>
   <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>

   <hbox homogeneous=\"true\">
   <hbox>
   <vbox>
   <hbox>
    <text><label>$(gettext 'Terminal')</label></text>
     <comboboxentry wrap-width=\"1\" width-request=\"120\" tooltip-text=\" $(gettext 'Default terminal emulator') \">
      <variable>TERMINAL</variable>
      <default>$TERMINAL</default>
      $TERMINAL_ITEMS
      <action>echo \$TERMINAL > $WORKDIR/preferences/terminal_emulator</action>
     </comboboxentry>
   </hbox>
   </vbox>
   <vbox homogeneous=\"true\">
     <checkbox tooltip-text=\" $(gettext 'Close the default terminal window after 
 closing a launched terminal application. 
 Uncheck the box to hold terminal open.') \">
      <label>$(gettext 'Close')</label>
      <variable>CLOSE_TERMINAL</variable>
      <input>cat $WORKDIR/preferences/close_terminal</input>
      <action>if true echo true > $WORKDIR/preferences/close_terminal</action>
      <action>if false echo false > $WORKDIR/preferences/close_terminal</action>
     </checkbox>
   </vbox>
   </hbox>
   </hbox>
   <pixmap><input file>$WORKDIR/icons/blank1.png</input></pixmap>
   <hseparator space-expand=\"false\" space-fill=\"false\"></hseparator>
   </vbox>
  </vbox>

   <hbox space-expand=\"false\" space-fill=\"true\" homogeneous=\"true\">
     $HOTKEY
     <button height-request=\"35\" width-request=\"110\">
      <label>$(gettext 'Help')</label>
      <input file>$WORKDIR/icons/help20.png</input>
      <action>func_prunhelp &</action>
     </button>
     <button height-request=\"35\" width-request=\"110\" tooltip-text=\" $(gettext 'Return to pRun') \">
      <label>$(gettext 'OK')</label>
      <input file stock=\"gtk-ok\"></input>
      <action>. $WORKDIR/prun &</action>
      <action type=\"exit\">quit_now</action>
     </button>
   </hbox>
 </vbox>
</window>"

$GTKDIALOG -p PR_PREFERENCES --styles=$TMPDIR/gtkrc.css
unset PR_PREFERENCES

exit 0
