#!/bin/bash
#default user interface.
#120203 rodin.s: internationalized.
#120224 handle translated help.htm
#120504 some files moved into /tmp/petget
#120515 calls to /tmp/petget/filterpkgs.results.postfilter.sh replace by /usr/local/petget/postfilterpkgs.sh.
#120527 first column of tree now an icon.
#120529 app icons in tree. variable FLG_APPICONS created in pkg_chooser.sh
#120811 category field now supports sub-category |category;subcategory|, use as icon in ppm main window.
#121113 "Calculate" is old name, top-level menu category is now "Business".
#130330 GUI filter. see also filterpkgs.sh, pkg_chooser.sh, ui_Ziggy.
#130331 more GUI filter options.

export TEXTDOMAIN=petget___ui_Classic
export OUTPUT_CHARSET=UTF-8

# Remove any 'auto' flags
rm -f /tmp/{install,remove}{,_pets}_quietly

APPICONXMLINSERT=' icon-column="1"' #120811 each line is format: abiword0-1.2.3|subcategory|description of abiword|stuff

if [ 0 -eq 1 ];then #w020 disable this choice.
 #filter pkgs by first letter, for more speed. must start with ab...
 echo "ab" > /tmp/petget_pkg_first_char
 FIRSTCHARS="
<radiobutton><label>a,b</label><action>echo ab > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>c,d</label><action>echo cd > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>e,f</label><action>echo ef > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>g,h</label><action>echo gh > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>i,j</label><action>echo ij > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>k,l</label><action>echo kl > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>m,n</label><action>echo mn > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>o,p</label><action>echo op > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>q,r</label><action>echo qr > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>s,t</label><action>echo st > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>u,v</label><action>echo uv > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>w,x</label><action>echo wx > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>y,z</label><action>echo yz > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>0-9</label><action>echo 0123456789 > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
<radiobutton><label>ALL</label><action>echo ALL > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
"
 xFIRSTCHARS="<hbox>
${FIRSTCHARS}
</hbox>"
else
 #do not dispay the alphabetic radiobuttons...
 echo "ALL" > /tmp/petget_pkg_first_char
 FIRSTCHARS=""
 xFIRSTCHARS=""
fi

touch /var/local/petget/bb_category
if [ "`cat /var/local/petget/bb_category`" = "true" ]; then
  BBCATEGORY="<radiobutton><label>$(gettext 'BuildingBlock')</label><action>/usr/local/petget/filterpkgs.sh BuildingBlock</action><action>refresh:TREE1</action></radiobutton>"
else
  BBCATEGORY=""
fi

#120224 handle translated help.htm
LANG1="${LANG%_*}" #ex: de
HELPFILE="/usr/local/petget/help.htm"
[ -f /usr/local/petget/help-${LANG1}.htm ] && HELPFILE="/usr/local/petget/help-${LANG1}.htm"

DEFGUIFILTER="$(cat /var/local/petget/gui_filter)" #130330 see pkg_chooser.sh, and below.

ALLCATEGORY=''
if [ "$DISTRO_BINARY_COMPAT" = "puppy" ];then #v424 reintroduce the 'ALL' category.
 ALLCATEGORY="<radiobutton><label>$(gettext 'ALL')</label><action>/usr/local/petget/filterpkgs.sh ALL</action><action>refresh:TREE1</action></radiobutton>"
fi
#100513 also for 't2' (quirky) builds...
if [ "$DISTRO_BINARY_COMPAT" = "t2" ];then #reintroduce the 'ALL' category.
 ALLCATEGORY="<radiobutton><label>$(gettext 'ALL')</label><action>/usr/local/petget/filterpkgs.sh ALL</action><action>refresh:TREE1</action></radiobutton>"
fi

#120515 ditto for gentoo build...
if [ "$DISTRO_BINARY_COMPAT" = "gentoo" ];then #reintroduce the 'ALL' category.
 ALLCATEGORY="<radiobutton><label>$(gettext 'ALL')</label><action>/usr/local/petget/filterpkgs.sh ALL</action><action>refresh:TREE1</action></radiobutton>"
fi

DB_ORDERED="$REPOS_RADIO" #120831

#130330 $GUIONLYSTR $ANYTYPESTR are exported from pkg_chooser.sh. 130331 also $GUIEXCSTR $NONGUISTR
export PPM_GUI="<window title=\"$(gettext 'Puppy Package Manager')\" icon-name=\"gtk-about\" width-request=\"780\" hight-request=\"560\">

<vbox>
 <hbox scrollable=\"true\" shadow-type=\"0\">
  <text><label>$(gettext 'Repo:')</label></text>
  ${DB_ORDERED}
  <height>48</height>
 </hbox>
 ${xFIRSTCHARS}
 <hbox>
  <vbox>
   <radiobutton><label>$(gettext 'Desktop')</label><action>/usr/local/petget/filterpkgs.sh Desktop</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'System')</label><action>/usr/local/petget/filterpkgs.sh System</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Setup')</label><action>/usr/local/petget/filterpkgs.sh Setup</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Utility')</label><action>/usr/local/petget/filterpkgs.sh Utility</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Filesystem')</label><action>/usr/local/petget/filterpkgs.sh Filesystem</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Graphic')</label><action>/usr/local/petget/filterpkgs.sh Graphic</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Document')</label><action>/usr/local/petget/filterpkgs.sh Document</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Business')</label><action>/usr/local/petget/filterpkgs.sh Business</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Personal')</label><action>/usr/local/petget/filterpkgs.sh Personal</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Network')</label><action>/usr/local/petget/filterpkgs.sh Network</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Internet')</label><action>/usr/local/petget/filterpkgs.sh Internet</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Multimedia')</label><action>/usr/local/petget/filterpkgs.sh Multimedia</action><action>refresh:TREE1</action></radiobutton>
   <radiobutton><label>$(gettext 'Fun')</label><action>/usr/local/petget/filterpkgs.sh Fun</action><action>refresh:TREE1</action></radiobutton>
   ${ALLCATEGORY}
  </vbox>
  <vbox>
  <tree column-resizeable=\"false|false\">
    <label>$(gettext 'Package|Description')</label>
    <height>280</height><width>668</width>
    <variable>TREE1</variable>
    <input${APPICONXMLINSERT}>cat /tmp/petget/filterpkgs.results.post</input>
    <action>/usr/local/petget/installpreview.sh</action>
    <action>/usr/local/petget/finduserinstalledpkgs.sh</action>
    <action>/usr/local/petget/filterpkgs.sh</action>
    <action>refresh:TREE1</action>
    <action>refresh:TREE2</action>
    <action signal=\"button-release-event\">/usr/local/petget/installpreview.sh</action>
    <action signal=\"button-release-event\">/usr/local/petget/finduserinstalledpkgs.sh</action>
    <action signal=\"button-release-event\">/usr/local/petget/filterpkgs.sh</action>
    <action signal=\"button-release-event\">refresh:TREE1</action>
    <action signal=\"button-release-event\">refresh:TREE2</action>
  </tree>
  </vbox>
 </hbox>
<hbox>
 <vbox>
  
  <hbox>
   <text><label>$(gettext 'Show:')</label></text>
   <checkbox><default>${DEF_CHK_EXE}</default><label>EXE</label><variable>CHK_EXE</variable><action>/usr/local/petget/postfilterpkgs.sh EXE \$CHK_EXE</action><action>refresh:TREE1</action></checkbox>
   <checkbox><default>${DEF_CHK_DEV}</default><label>DEV</label><variable>CHK_DEV</variable><action>/usr/local/petget/postfilterpkgs.sh DEV \$CHK_DEV</action><action>refresh:TREE1</action></checkbox>
   <checkbox><default>${DEF_CHK_DOC}</default><label>DOC</label><variable>CHK_DOC</variable><action>/usr/local/petget/postfilterpkgs.sh DOC \$CHK_DOC</action><action>refresh:TREE1</action></checkbox>
   <checkbox><default>${DEF_CHK_NLS}</default><label>NLS</label><variable>CHK_NLS</variable><action>/usr/local/petget/postfilterpkgs.sh NLS \$CHK_NLS</action><action>refresh:TREE1</action></checkbox>
  </hbox>
  
  <hbox>
   <comboboxtext width-request=\"140\">
    <variable>FILTERCOMBOBOX</variable>
    <default>$DEFGUIFILTER</default>
    <item>$ANYTYPESTR</item>
    <item>$GUIONLYSTR</item>
    <item>GTK+2 $GUIONLYSTR</item>
    <item>GTK+3 $GUIONLYSTR</item>
    <item>Qt4 $GUIONLYSTR</item>
    <item>Qt4 $GUIEXCSTR KDE</item>
    <item>Qt5 $GUIONLYSTR</item>
    <item>Qt5 $GUIEXCSTR KDE</item>
    <item>$NONGUISTR</item>
    <action>echo -n \"\$FILTERCOMBOBOX\" > /var/local/petget/gui_filter</action>
    <action>/usr/local/petget/filterpkgs.sh</action>
    <action>refresh:TREE1</action>
   </comboboxtext>
   <text><label>\" \"</label></text>
   
   <text><label>$(gettext 'Help:')</label></text>
   <button><input file>/usr/local/lib/X11/mini-icons/mini-question.xpm</input><action>defaulthtmlviewer file://${HELPFILE} & </action></button>
  </hbox>
  
  <hbox>
   <text><label>$(gettext 'Find:')</label></text>
   <entry activates-default=\"true\">
    <variable>ENTRY1</variable>
   </entry>
   <button can-default=\"true\" has-default=\"true\" use-stock=\"true\">
    <label>$(gettext 'Go')</label>
    <action>/usr/local/petget/findnames.sh</action>
    <action>refresh:TREE1</action>
    <action>/usr/local/petget/show_installed_version_diffs.sh & </action>
   </button>
  </hbox>
  <button>
   <input file icon=\"gtk-preferences\"></input>
   <label>$(gettext 'Configure package manager')</label>
   <action>/usr/local/petget/configure.sh</action>
   <action>/usr/local/petget/filterpkgs.sh</action>
   <action>refresh:TREE1</action>
  </button>
  <button type=\"exit\">
   <input file icon=\"mini-exit\"></input>
   <label>$(gettext 'Exit package manager')</label>
  </button>
 </vbox>
 <text><label>\" \"</label></text>
 <frame $(gettext 'Installed packages')>
  <tree column-resizeable=\"false|false\">
    <label>$(gettext 'Package|Description')</label>
    <height>100</height><width>480</width>
    <variable>TREE2</variable>
    <input${APPICONXMLINSERT}>cat /tmp/petget/installedpkgs.results.post</input>
    <action>/usr/local/petget/removepreview.sh</action>
    <action>/usr/local/petget/finduserinstalledpkgs.sh</action>
    <action>/usr/local/petget/filterpkgs.sh</action>
    <action>refresh:TREE2</action>
    <action>refresh:TREE1</action>
    <action signal=\"button-release-event\">/usr/local/petget/removepreview.sh</action>
    <action signal=\"button-release-event\">/usr/local/petget/finduserinstalledpkgs.sh</action>
    <action signal=\"button-release-event\">/usr/local/petget/filterpkgs.sh</action>
    <action signal=\"button-release-event\">refresh:TREE2</action>
    <action signal=\"button-release-event\">refresh:TREE1</action>
  </tree>
 </frame>
</hbox>
</vbox>
<action signal=\"show\">kill -9 $SPID</action>
</window>
"

export TEXTDOMAIN=petget___pkg_chooser.sh

RETPARAMS="`gtkdialog -p PPM_GUI`"

# Run indexgen after we exit the GUI
/usr/sbin/indexgen.sh
