#!/bin/sh
#add or remove fvwmbuttons from the Fvwm95 desktop, Puppy Linux.

if [ ! "`cat /root/.fvwm95rc | grep "wmpower" | grep "Swallow" | grep '#FvwmButtons'`" = "" ];then
 CHECK004="false"
else
 CHECK004="true"
fi
if [ ! "`cat /root/.fvwm95rc | grep "page" | grep "Swallow" | grep '#FvwmButtons'`" = "" ];then
 CHECK005="false"
else
 CHECK005="true"
fi
if [ ! "`cat /root/.fvwm95rc | grep "wmsm" | grep "Swallow" | grep '#FvwmButtons'`" = "" ];then
 CHECK006="false"
else
 CHECK006="true"
fi
if [ ! "`cat /root/.fvwm95rc | grep "wmwifi" | grep "Swallow" | grep '#FvwmButtons'`" = "" ];then
 CHECKWIFI="false"
else
 CHECKWIFI="true"
fi
if [ ! "`cat /root/.fvwm95rc | grep "wmnd" | grep "Swallow" | grep '#FvwmButtons'`" = "" ];then
 CHECKND="false"
else
 CHECKND="true"
fi

export FvwmDockApps="
 <vbox>
   <text>
    <label>Swallowed applications, also referred to as dockapps, may be</label>
   </text>
   <text>
    <label>turned on or off on the Puppy desktop. However, a change will</label>
   </text>
   <text>
    <label>only take effect AFTER exiting and restarting X.</label>
   </text>
    <checkbox>
     <label>Display APM/ACPI (battery, temp, fan) dockapp</label>
     <default>$CHECK004</default>
    </checkbox>
    <checkbox>
     <label>Display window pager dockapp</label>
     <default>$CHECK005</default>
    </checkbox>
    <checkbox>
     <label>Display CPU/memory usage and uptime dockapp</label>
     <default>$CHECK006</default>
    </checkbox>
    <checkbox>
     <label>Display wireless signal strength NOT YET IMPLEMENTED</label>
     <default>$CHECKWIFI</default>
    </checkbox>
    <checkbox>
     <label>Display network interface traffic dockapp</label>
     <default>$CHECKND</default>
    </checkbox>
  <hbox>
   <button cancel></button>
   <button ok></button>
  </hbox>
 </vbox>
"



RETPARAMS="`gtkdialog --program=FvwmDockApps`"
if [ `echo "$RETPARAMS" | grep "EXIT" | grep "OK"` ];then
 #echo $RETPARAMS
 if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX004" | grep "false"`" = "" ];then
  cat /root/.fvwm95rc | sed -e 's/*FvwmButtons (Size 64 64, Swallow "wmpower/#FvwmButtons (Size 64 64, Swallow "wmpower/g' > /tmp/fvwm95rc2
 else
  cat /root/.fvwm95rc | sed -e 's/#FvwmButtons (Size 64 64, Swallow "wmpower/*FvwmButtons (Size 64 64, Swallow "wmpower/g' > /tmp/fvwm95rc2
 fi
 sync
 if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX005" | grep "false"`" = "" ];then
  cat /tmp/fvwm95rc2 | sed -e 's/*FvwmButtons (Size 64 64, Swallow(UseOld) "page/#FvwmButtons (Size 64 64, Swallow(UseOld) "page/g' > /root/.fvwm95rc
 else
  cat /tmp/fvwm95rc2 | sed -e 's/#FvwmButtons (Size 64 64, Swallow(UseOld) "page/*FvwmButtons (Size 64 64, Swallow(UseOld) "page/g' > /root/.fvwm95rc
 fi
 sync
 if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX006" | grep "false"`" = "" ];then
  cat /root/.fvwm95rc | sed -e 's/*FvwmButtons (Size 64 64, Swallow "wmsm/#FvwmButtons (Size 64 64, Swallow "wmsm/g' > /tmp/fvwm95rc2
 else
  cat /root/.fvwm95rc | sed -e 's/#FvwmButtons (Size 64 64, Swallow "wmsm/*FvwmButtons (Size 64 64, Swallow "wmsm/g' > /tmp/fvwm95rc2
 fi
 sync
 if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX007" | grep "false"`" = "" ];then
  cat /tmp/fvwm95rc2 | sed -e 's/*FvwmButtons (Size 64 64, Swallow "wmwifi/#FvwmButtons (Size 64 64, Swallow "wmwifi/g' > /root/.fvwm95rc
 else
  #NOT YET IMPLEMENTED
  #cat /tmp/fvwm95rc2 | sed -e 's/#FvwmButtons (Size 64 64, Swallow "wmwifi/*FvwmButtons (Size 64 64, Swallow "wmwifi/g' > /root/.fvwm95rc
  cp -f /tmp/fvwm95rc2 /root/.fvwm95rc #TEMPORARY
 fi
 sync
 if [ ! "`echo "$RETPARAMS" | grep "CHECKBOX008" | grep "false"`" = "" ];then
  cat /root/.fvwm95rc | sed -e 's/*FvwmButtons (Size 64 64, Swallow "wmnd/#FvwmButtons (Size 64 64, Swallow "wmnd/g' > /tmp/fvwm95rc2
 else
  cat /root/.fvwm95rc | sed -e 's/#FvwmButtons (Size 64 64, Swallow "wmnd/*FvwmButtons (Size 64 64, Swallow "wmnd/g' > /tmp/fvwm95rc2
 fi
 sync

 mv -f /tmp/fvwm95rc2 /root/.fvwm95rc
 sync
fi

unset FvwmDockApps
