#!/bin/sh
########################
# Graphic note v1.0
########################

path=/mnt/us/extensions/gestures/notes
which=`cat $path/which`

info(){
    eips 2 5 "Home button      -  exit"
    eips 2 7 "Pinch   + up     -  show gestures"
    eips 2 9 "Long tap         -  save current note"
    eips 2 11 "Pinch   + down   -  show note (go to last save)"
    eips 2 14 "Stretch or pinch -  clear"
    eips 2 16 "Pinch   + left   -  next note"
    eips 2 18 "Stretch + left   -  5 forward"
    eips 2 20 "Pinch   + right  -  previous note"
    eips 2 22 "Stretch + right  -  5 backward"
    eips 2 24 "Stretch + up     -  go to last"
    eips 2 27 "Stretch + down   -  edit backgr (only portrait)"
    eips 2 29 "Pinch + down + up -  quick review all notes"
    eips 2 33 "When you saving last note,"
	eips 2 34 "another one will be added."
}

rest(){
#	kill -9 `cat /tmp/xtest.pid`
#	dd if=/dev/fb0 bs=608 count=800 2>/dev/null | gzip > /tmp/fbtmp
#	gzip -dc $path/fb0white > /dev/fb0
#	eips ''
#	gzip -dc /tmp/fbtmp > /dev/fb0
#	eips ''
	killall xtestlab126
	xtestlab126 -d &>/dev/null &
	usleep 100000
#	echo $! > /tmp/xtest.pid
}

case $1 in

	"info")
		rest
		info ;;

	"tap")
		dd if=/dev/fb0 bs=608 count=800 2>/dev/null | gzip > $path/$which ;;

	"prev")
		rest
		if [ $which -gt $2 ]; then which=$(($which-$2))
		else which=0
		fi
		gzip -dc $path/$which > /dev/fb0
		eips ''	;;

	"next")
		hm=`ls $path | wc -w`
		hm=$(($hm-2))
		rest
		if [ $(($which+$2)) -lt $hm ]; then
			which=$(($which+$2))
			gzip -dc $path/$which > /dev/fb0
			eips ''
		else 
			which=$(($hm+0))
			gzip -dc $path/fb0white > /dev/fb0
			eips ''
			eips 3 5 "This is the last note. For edit."
		fi	;;

	"show")
		rest
		gzip -dc $path/$which > /dev/fb0
		eips '' ;;

	"background")
#		kill -9 `cat /tmp/xtest.pid`
		killall xtestlab126 -d &
		sleep 1
		dd if=/dev/fb0 bs=608 count=800 2>/dev/null | gzip > /tmp/fb0
		xtestlab126 -d &>/dev/null &
		echo $! > /tmp/xtest.pid
		gzip -dc /tmp/fb0 > /dev/fb0
		eips '' ;;

	"clear")
		rest ;;

	"start")
		/usr/bin/lipc-get-prop -s com.lab126.winmgr orientation > /tmp/xtest.orient
		/usr/bin/lipc-set-prop -s com.lab126.winmgr orientationLock U
		/usr/bin/lipc-set-prop -i com.lab126.audio Volume 5
	    xtestlab126 -d &>/dev/null &
#		echo $! > /tmp/xtest.pid
		if [ "$which" -lt "0" ]; then which=0 ; fi
		gzip -dc $path/$which > /dev/fb0
		eips ''
#		info
#		sleep 2
#		info
    	;;

	"review")
		hm=`ls $path | wc -w`
		hm=$(($hm-2))
		i=0
		while [ $i -lt $hm ];
		do 
			gzip -dc $path/$i > /dev/fb0
			eips ''
			i=$(($i+1))
			usleep 900000
		done
		sleep 1
		rest
		gzip -dc $path/$which > /dev/fb0
		eips ''
		;;

esac

echo $which > $path/which
eips 44 38 " $which"

