#!/bin/bash
licq_fifo="$HOME/.licq/licq_fifo"
licq_pid="$HOME/.licq/licq.pid"
gajim_stat_file="$HOME/.gajim/xlock.status"

#function gajimstatus {
#	for acc in  `gajim-remote list_accounts`
#	do
#		curstat="`gajim-remote get_status "$acc"`"
#		echo $acc: $curstat
#		if [ "$curstat" != "offline" ]
#		then
#			echo change status to "$1"
#			gajim-remote change_status "$1" "" "$acc"
#		fi
#	done
#}

# gajim: store status and set away
function gajim_store_and_set {
	cat /dev/null > "$gajim_stat_file"
	for acc in  `gajim-remote list_accounts`
	do
		curstat="`gajim-remote get_status "$acc"`"
		if [ "$curstat" != "offline" ]
		then
			echo $acc
			echo $curstat
			gajim-remote change_status "$1" "$2" "$acc"
		fi
	done >> "$gajim_stat_file"
}

function gajim_restore {
	# gajim: restore status
	while read acc
	do
		read stat
		gajim-remote change_status "$stat" "" "$acc"
	done < "$gajim_stat_file"
}

case "$1" in
	"start")
		[ -p $licq_fifo ] && [ -f $licq_pid ] && \
			echo "status away" > $licq_fifo &
		#gajim-remote change_status away &
		gajim_store_and_set away "Nejsem tu :P" &
		sudo /usr/local/sbin/sysrq-off
		;;
	
	"stop")
		[ -p $licq_fifo ] && [ -f $licq_pid ] \
			echo "status online" > $licq_fifo &
		#gajim-remote change_status online &
		gajim_restore &
		sudo /usr/local/sbin/sysrq-on
		;;
	*)
		echo "Usage: $0 {start|stop}"
		;;
esac

