#!/bin/sh
#created BK apr 2009 for Puppy 4.00, GPL

. /usr/bin/localization 


PUPPYVERSION=`cat /etc/puppyversion`
[ $PUPPYVERSION -eq 398 ] && PUPPYVERSION=400 #temp fixup.
[ $PUPPYVERSION -eq 399 ] && PUPPYVERSION=400 #temp fixup.
PUPVERDIGIT1="`echo -n "$PUPPYVERSION" | cut -b 1`"

FILTER_CATEG="All"
FILTER_VERSION="$PUPVERDIGIT1"
#note, cannot initialise radio buttons in gtkdialog...
echo "All" > /tmp/petget_filtercategory
echo "$PUPVERDIGIT1" > /tmp/petget_filterversion

#finds all installed pkgs and formats ready for display...
/usr/local/petget/findinstalledpkgs.sh #writes to /tmp/installedpkgs.results

#finds pkgs in repository based on filter category and version and formats ready for display...
/usr/local/petget/filterpkgs.sh $FILTER_CATEG #writes to /tmp/filterpkgs.results

echo '#!/bin/sh
echo $1 > /tmp/petget_filterversion
' > /tmp/filterversion.sh
chmod 777 /tmp/filterversion.sh


export MAIN_DIALOG="<window title=\"$(eval_gettext "PETget package manager")\" icon-name=\"gtk-about\">

<vbox>
 <hbox>
  <text><label>$(eval_gettext "Choose PET package repository:")</label></text>
  <radiobutton><label>$(eval_gettext "Official Puppy4")</label><action>/tmp/filterversion.sh 4</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  <radiobutton><label>$(eval_gettext "Official Puppy3")</label><action>/tmp/filterversion.sh 3</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  <radiobutton><label>$(eval_gettext "Official Puppy2")</label><action>/tmp/filterversion.sh 2</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
 </hbox>
 <hbox>
  <vbox>
   <radiobutton><label>$(eval_gettext "All")</label><action>/usr/local/petget/filterpkgs.sh All</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Desktop")</label><action>/usr/local/petget/filterpkgs.sh Desktop</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "System")</label><action>/usr/local/petget/filterpkgs.sh System</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Setup")</label><action>/usr/local/petget/filterpkgs.sh Setup</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Utility")</label><action>/usr/local/petget/filterpkgs.sh Utility</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Filesystem")</label><action>/usr/local/petget/filterpkgs.sh Filesystem</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Graphic")</label><action>/usr/local/petget/filterpkgs.sh Graphic</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Document")</label><action>/usr/local/petget/filterpkgs.sh Document</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Calculate")</label><action>/usr/local/petget/filterpkgs.sh Calculate</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Personal")</label><action>/usr/local/petget/filterpkgs.sh Personal</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Network")</label><action>/usr/local/petget/filterpkgs.sh Network</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Internet")</label><action>/usr/local/petget/filterpkgs.sh Internet</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Multimedia")</label><action>/usr/local/petget/filterpkgs.sh Multimedia</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "Fun")</label><action>/usr/local/petget/filterpkgs.sh Fun</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(eval_gettext "BuildingBlock")</label><action>/usr/local/petget/filterpkgs.sh BuildingBlock</action><action>refresh:TREE1</action></radiobutton>
  </vbox>
  <vbox>
  <tree icon=\"pet48x\">
    <label>$(eval_gettext "Package|Description|Category,dependencies,size")</label>
    <height>280</height><width>668</width>
    <variable>TREE1</variable>
    <input>cat /tmp/filterpkgs.results</input>
    <action signal=\"button-release-event\">/usr/local/petget/installpreview.sh</action>
    <action signal=\"button-release-event\">/usr/local/petget/findinstalledpkgs.sh</action>
    <action signal=\"button-release-event\">refresh:TREE2</action>
  </tree>
  </vbox>
 </hbox>
<hbox>
 <vbox>
  <text><label>\" \"</label></text>
  <text use-markup=\"true\"  width-chars=\"26\"><label>$(eval_gettext "\"<b>Welcome! To install or uninstall simply click on a package</b>\"")</label></text>
  <text><label>\" \"</label></text>
  <button cancel></button>
 </vbox>
 <text><label>\" \"</label></text>
 <frame $(eval_gettext "Installed packages")>
  <tree icon=\"pet48x\">
    <label>$(eval_gettext "Package|Description")</label>
    <height>100</height><width>480</width>
    <variable>TREE2</variable>
    <input>cat /tmp/installedpkgs.results</input>
    <action signal=\"button-release-event\">/usr/local/petget/removepreview.sh</action>
    <action signal=\"button-release-event\">/usr/local/petget/findinstalledpkgs.sh</action>
    <action signal=\"button-release-event\">refresh:TREE2</action>
  </tree>
 </frame>
</hbox>
</vbox>
</window>
"

#
#  <button><label>Quit</label><action type=\"exit\">QUIT</action></button>

RETPARAMS="`gtkdialog3 --program=MAIN_DIALOG`"

#echo "$RETPARAMS"
exit

eval "$RETPARAMS"

###END###
