#!/bin/bash
#################################################################
#this GUI is designed for a script what was posted from longtom #
#rotator_tray based on YAD										#
#on: March 01, 2011	as rotator, in PCLinuxOS-Forums.			#
#Designed for PCLinuxOS-LXDE.									#
#Date: March 23, 2015											#
#Licence: GPLv2													#
#Author: D.Meiß-Wilhelm (Leiche) 								#
#Don't remove this header										#
#################################################################
Encoding=UTF-8
# i18n - Internationalization -------------------------------------------
export TEXTDOMAIN=rotator_gui
export TEXTDOMAINDIR="/usr/share/locale"
# create config directory for user --------------------------------------
if [ ! -d $HOME/.config/lxrotator ]; then
	mkdir $HOME/.config/lxrotator
	echo 0 > $HOME/.config/lxrotator/pid
	echo "config directory ready"
fi
#  variables for simple handling ----------------------------------------
TITLE=LXRotatorGUI
VERSION=01.1
CONF=$HOME/.config/lxrotator
dirname="$(dirname "$(readlink -e "$0")")"
if [ ! -f $CONF/lxrotator ]; then
cp $dirname/lxrotator $CONF
fi
RESTART=$dirname/rotator_gui
AUTOSTARTER=$dirname/starter
CHANGER=$CONF/lxrotator
ICON=/usr/share/icons/lxrotator.png
# /end variables --------------------------------------------------------
# systray checking, if activated so display in systray ------------------
if [ $(grep -c systray=1 $CHANGER) -gt 0  > /dev/null 2>&1 ];then
	echo $"Systray always enabled"
	# instance checking only one instance should be display in systray --
	if [ $(pgrep -f "yad --title=lxrotator") -gt 1  > /dev/null 2>&1 ];then
		#kill `cat $CONF/pid`
		echo $"systray menu always running"
		exit 2
	fi	
 # systray menu ---------------------------------------------------------
# create pipe -----------------------------------------------------------
PIPE="$CONF/.pipe.tmp"
rm $PIPE
mkfifo $PIPE
exec 3<> $PIPE
# create yad ------------------------------------------------------------
yad --title=lxrotator --notification --listen <&3 & 
pgrep -n yad > $CONF/pid 
cat $CONF/pid 
# define entries --------------------------------------------------------
echo $"menu:\
PAUSE!pkill lxrotator|\
PLAY!$CHANGER|\
SETTING!$RESTART|\
EXIT!kill `cat $CONF/pid`|" >&3
# Icon ------------------------------------------------------------------ 
echo "icon:$ICON" >&3
# Name the menu ---------------------------------------------------------
echo $"tooltip:LXRotator" >&3
fi
