#!/bin/sh
#
# SmbBox Notify - Notification icon for SmbBox (umount function). 
#
# Copyright (C) 2012 SliTaz GNU/Linux - GNU gpl v2
#
# Authors : Stanislas Leduc <shann@slitaz.org>
# version: 0.3

# I18n
. /usr/bin/gettext.sh
TEXTDOMAIN='smbbox-notify'
export TEXTDOMAIN

fifo=/tmp/$(basename $0).fifo
shares=$(mount | awk '/\\/ {print $0}' | wc -l)
text="$(gettext "Folder Shares mounted: ") <b>$shares</b>"
icon="/usr/share/pixmaps/netbox.png"

# Notification icon
listen() {
	# Manage the I/O redirection from SHell
	rm -f $fifo && mkfifo $fifo		
	# Attach a file descriptor
	exec 3<> $fifo	
	# Notification icon
		yad --notification --listen --image=$icon \
		--text="$text" <&3
	# Clean-up
	rm -f $fifo
}

# Notication menu (right click)
menu() {
	cat << EOT
menu:\
$(gettext "SmbBox")!smbbox!netbox|\
$(gettext "Close notification")!quit!gtk-close
EOT
}

case $1 in
	usage|help|*-h)
		gettext "Usage:"; echo " $(basename $0)" ;;
	*)
		# Sleep before displaying the notification icon and
		# sleep to let user read the tooltips.
		sleep 4
		listen &
		sleep 2
		menu > $fifo
		sleep 1
		# Mounted folder share
		tooltip=$(eval_gettext "$(gettext "SmbBox Notification ")\n Double clic for viewing and unmount share folders")
			echo "action:smbbox umount" > $fifo
			echo "tooltip:$tooltip" > $fifo
			echo "icon:netbox" > $fifo && exit 0
esac
exit 0
