#!/bin/bash

URL=http://www.smnd.sk/tomi/files/message/

date=""
[ -f "date.txt" ] && date="?d=`cat date.txt`"

while true; do
	content=`GET ${URL}watch.php$date`
	if [ "${content%#}" == "$content" ]; then
		# it wasn't a timeout
		if [ "${content#*/}" == "$content" ]; then
			# something bad happened
			kdialog --warningcontinuecancel "Notification subsystem error. Continue?"
			if [ "$?" == "2" ]; then
				exit 1
			fi
		else
			# success; new message came
			date=${content#*/}
			echo $date > date.txt
			kdialog --yesno "Notification subsystem activated. Show content?"
			if [ "$?" == "0" ]; then
				mozilla-firefox ${URL}get.php
			else
				exit 0
			fi
		fi
	fi
done


