#!/bin/bash
#PupControl 3.6.1
#Functions (radky)

export TEXTDOMAIN=pupcontrol
export OUTPUT_CHARSET=UTF-8

WORKDIR="/usr/local/PupControl"
. /etc/DISTRO_SPECS

#define current window manager
CURRWM=`cat /etc/windowmanager`

case "$1" in

-calculator) if [ "`which galculator`" ]; then galculator & elif [ "`which gcalctool `" ]; then gcalctool & elif [ "`which calcoo `" ]; then calcoo & elif [ "`which cgtkcalc `" ]; then cgtkcalc & elif [ "`which xcalc`" ]; then xcalc & else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'Calculator not available.') " 0 0 & fi ;;

-cpufrequency) if [ "`which wcpufreq`" ]; then wcpufreq & elif [ -f /usr/local/cpu-freq/cpu_freq ]; then /usr/local/cpu-freq/cpu_freq -start & elif [ "`which acpi-control`" ]; then acpi-control & else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'CPU Frequency Scaling is not available.') " 0 0 & fi ;;

-firewall) if [ "`which firewall_ng`" ]; then firewall_ng & elif [ "`which Firewall_Genie`" ]; then Firewall_Genie & else rxvt -e firewallinstallshell & fi ;;

-gparted) if [ "`which gparted_shell`" ]; then gparted_shell & elif [ "`which gparted`" ]; then gparted & else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'Gparted is not available.') " 0 0 & fi ;;

-gtkhash) if [ "`which ghasher`" ]; then ghasher & elif [ "`which gtkhash`" ]; then gtkhash & elif [ "`which pupchecksum.sh`" ]; then pupchecksum.sh & elif [ "`which pupmd5sum.sh`" ]; then pupmd5sum.sh & else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'Hash utility not available.') " 0 0 & fi ;;

-hwclock)
	if [ "`which set_hwclock_type`" ] && [ ! -h /usr/sbin/set_hwclock_type ]; then set_hwclock_type &
	elif [ "`which quickcountry`" ]; then quickcountry &
	elif [ "`which countrywizard`" ]; then countrywizard &
	else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'The hardware clock option is \n not available in this distro.') " 0 0 &
	fi
	;;

-inxi)
	gtkdialog-splash -margin 8 -timeout 4 -fontsize large -bg goldenrod -text " $(gettext 'Processing...') " &
	inxi -Fxz -c 0 | perl -pe 's/[^[:ascii:]]//g' | sed -e 's/[©®–]//g' | Xdialog --fixed-font --title "Inxi System Information" --no-cancel --textbox "-" 32 110 &
#	urxvt -title "Inxi System Information" -hold -geometry 130x24 -e bash -c "inxi -Fxz -c 24" & #optional terminal ouput, based on inxi-term script by TaZoC. Note: use -c 17 text color if light urxvt background.
	;;

-logout)
	gtkdialog-splash -margin 8 -timeout 2 -fontsize large -bg goldenrod -text " Logging out to command prompt... "
	wmexit &
	;;

-menu_update) #update the Puppy XDG menu
	 sleep 1; gtkdialog-splash -timeout 2 -fontsize large -bg goldenrod -text " $(gettext 'Updating the menu...') " &
	 fixmenus 2>/dev/null
	;;

-mount) if [ "`which pmount`" ]; then pmount & elif [ "`which ymount`" ]; then ymount & else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'Pmount and Ymount are not available.') " 0 0 &  fi ;;

-poweroff)
	gtkdialog-splash -margin 8 -timeout 2 -fontsize large -bg goldenrod -text " $(gettext 'Please wait, closing session...') "
	wmpoweroff &
	;;

-preferences_nochange)
	gtkdialog-splash -margin 8 -timeout 1 -fontsize large -bg goldenrod -text "$(gettext 'No changes')" &
	sleep 0.7
	cp -f $WORKDIR/pupcontrol2.rc $WORKDIR/pupcontrol.rc && sleep 0.3 && $WORKDIR/PupControl &
	;;

-preferences_save)
	gtkdialog-splash -margin 8 -timeout 1 -fontsize large -bg goldenrod -text "$(gettext 'Saving preferences')" &
	sleep 1
	$WORKDIR/setdefaults &
	;;

-printmanager)
	if [ "`which gtklp`" ]; then gtklpq & sleep 1 && gtklp &
	elif [ "`which cupsd`" ]; then defaulthtmlviewer http://localhost:631/printers &
	else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'PupControl does not detect a printer manager.') " 0 0 & 
	fi
	;;

-printsetup)
	cups_shell &
	;;

-pupscan) if [ "`which pupscan`" ]; then pupscan & else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'PupScan is not available.') " 0 0 &  fi ;;

-prxvt)
	[ -f /usr/bin/urxvt ] && [ ! -f /usr/local/bin/Prxvt ] && echo "PupControl placeholder for non-path applications." > /usr/local/bin/Prxvt && chmod 755 /usr/local/bin/Prxvt
	[ -f /usr/local/bin/Prxvt ] && [ ! -f /usr/bin/urxvt ] && rm -f /usr/local/bin/Prxvt
	;;

-reboot)
	gtkdialog-splash -margin 8 -timeout 2 -fontsize large -bg goldenrod -text " $(gettext 'Please wait, rebooting...') "
	wmreboot &
	;;

-updatetime) if [ -f /usr/sbin/qsync ]; then /usr/sbin/qsync & elif [ -f /usr/local/psync/psync ]; then /usr/local/psync/psync & elif [ -f /usr/sbin/psync ]; then /usr/sbin/psync & else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'Psync is not available.') " 0 0 & fi ;;

-wallpaper)
	$WORKDIR/defaultapps/wallpaper &
	;;

-webcam) if [ "`which guvcview`" ]; then guvcview & elif [ "`which luvcview`" ]; then luvcview & elif [ "`which ucview`" ]; then ucview & fi ;;

-xorgwizard)
	if [ "`which xorgwizard`" ]; then xorgwizard &
	else Xdialog --title Alert --beep --under-mouse --msgbox " $(gettext 'xorgwizard not available!') " 0 0 &
	fi
	;;

esac
