%
% anyremote configuration file for mplayer management. (Server-mode)
% 
% Thanks Kristjan Ugrin for corrections.
%

% STATUS stable
% XTEST no
% ENV no
% SOUND app
% FBROWSER v.3i
% DEF_VIDEO_PLAYER   
% ALL_IN_ONE 
% MEDIACENTER video

GuiAppName=MPlayer
GuiAppBinary=mplayer
GuiAppRun=A=`ps -ef|grep mplayer|grep -v kmplayer|grep -v gmplayer|grep -v grep|grep -v edit|grep -v anyremote`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi
GuiAppIcon=mplayer.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=A movie player.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
        Include($(CfgDir)/Utils/aliases-server-fbrowser-v3i.cfg);\
	Macro(FBROWSER_IC_INIT);\
	Include($(CfgDir)/Utils/aliases-server-video-player.cfg);\
	Make(var,app_name,by_value,MPlayer);\
	Make(var,open_file,by_value,);\
	Make(var,do_app_init,by_value,1);\
	Make(var,mplayer_pure_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get mplayer_pure_layout`;\
	     if [ "x$V" = "x" ]; then echo "3x4"; else echo $V; fi);\
	Make(var,app_manage_mode,by_value,mplayer_$(mplayer_pure_layout));

(Exit)=\
	Macro(FBROWSER_IC_EXIT);\
	Exec($(CfgDir)/Utils/registry.sh $(TmpDir) set mplayer_pure_layout $(mplayer_pure_layout));

(Connect)=\
	Make(mode,mplayer_init);

[Mode]=mplayer_init : default_video_player_init

APP_IS_RUN=\
	Make(var,app_run,ID=`id -u`;A=`ps -fu $ID|grep "mplayer -input"|grep -v kmplayer|grep -v gmplayer|grep -v grep|grep -v edit|grep -v anyremote|grep "mplayer/fifo"`; if [ "x$A" = "x" ]; then echo 0; else echo 1; fi);

[ModeEnd]

[Mode]=mplayer_general

APP_SETUP=\
	Exec(if [ -d $HOME/.mplayer ]; then true; else mkdir $HOME/.mplayer; fi; if [ -p $HOME/.mplayer/fifo ]; then true; else mkfifo $HOME/.mplayer/fifo; fi)

APP_START_IF=\
	Set(title,$(open_file));\
	Make(var,app_run,ID=`id -u`;A=`ps -fu $ID|grep "mplayer -input"|grep -v kmplayer|grep -v gmplayer|grep -v grep|grep -v edit|grep -v anyremote|grep "mplayer/fifo"`; if [ "x$A" = "x" ]; then echo 0; else echo 1; fi);\
 	Exec(if [ "x$(app_run)" = "x0" ]; then cd "$(fbrowser_dir)";mplayer -input file=$HOME/.mplayer/fifo $(open_file) > /dev/null & fi);

% Application window should be present in output of "wmctrl -l"
APP_RAISE=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh -switch mplayer);

APP_QUIT=\
	Exec(P=`ps -ef|grep "mplayer -input"|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" != "x" ]; then echo quit > $HOME/.mplayer/fifo; fi);\
	Exec(pkill -u `id -u` mplayer);

APP_FULLSCREEN=\
	Exec(echo vo_fullscreen > $HOME/.mplayer/fifo);

PLAY=Exec(echo pause > $HOME/.mplayer/fifo);
RWD=Exec(echo "seek -10" > $HOME/.mplayer/fifo);
FF=Exec(echo "seek 10" > $HOME/.mplayer/fifo);
STOP=Exec(echo pause > $HOME/.mplayer/fifo);
PAUSE=Exec(echo pause > $HOME/.mplayer/fifo);

Layout 3x4=\
	Make(mode,mplayer_3x4);

Layout 5x1=\
	Make(mode,mplayer_5x1);

[ModeEnd]

[Mode]=mplayer_3x4 : mplayer_general,default_video_player

% (EnterMode) by Utils/aliases-server-video-player.cfg
	
% Override
1=Exec(echo "volume -10" > $HOME/.mplayer/fifo)
2=Exec(echo mute > $HOME/.mplayer/fifo)
3=Exec(echo "volume +10" > $HOME/.mplayer/fifo)

APP_POST_SETUP=\
	Make(var,mplayer_pure_layout,by_value,3x4);\
	Make(var,app_manage_mode,by_value,mplayer_pure_$(mplayer_pure_layout));


APP_MENU=\
	Set(menu,replace,Layout 5x1,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

[ModeEnd]

[Mode]=mplayer_5x1 : mplayer_general,default_video_player_5x1 

APP_POST_SETUP=\
	Make(var,mplayer_pure_layout,by_value,5x1);\
	Make(var,app_manage_mode,by_value,mplayer_pure_$(mplayer_pure_layout));

APP_MENU=\
	Set(menu,replace,Help,Mute,Quit,Files,Layout 3x4,IMDB,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

% Override
VOL-=\
	Exec(echo "volume -10" > $HOME/.mplayer/fifo);

Mute=\
	Exec(echo mute > $HOME/.mplayer/fifo);

VOL+=\
	Exec(echo "volume +10" > $HOME/.mplayer/fifo);

[ModeEnd]

[End]
