%
% anyremote configuration file for Exaile management (Server-mode)
% prerequisites: amixer/pactl utility
%

% STATUS stable
% XTEST no
% SOUND mixer
% ENV no
% DEF_PLAYER   
% ALL_IN_ONE
% MEDIACENTER audio 
% FBROWSER v.4i

GuiAppName=Exaile
GuiAppBinary=exaile
GuiAppRun=echo 'P=`ps -ef|grep exaile |grep -v grep|grep -v anyremote|grep -v nedit`; if [ "x$P" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=exaile.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Exaile is a music player aiming to be similar to KDE's Amarok, but for GTK+ and written in Python.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
	Macro(TEST_DBUS_SEND);\
    Include($(CfgDir)/Utils/aliases-server-fbrowser-v4i.cfg);\
	Macro(FBROWSER_IC_INIT);\
	Make(var,cover_size,by_value,);\
	Make(var,player_name,by_value,Exaile);\
	Make(var,exaile_cmd,by_value,dbus-send --type=method_call --dest=org.exaile.Exaile /org/exaile/Exaile);\
	Make(var,exaile_get,by_value,dbus-send --type=method_call --print-reply --dest=org.exaile.Exaile /org/exaile/Exaile);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,exaile_layout,by_value,5x1);
	
(Connect)=\
	Make(mode,exaile_$(exaile_layout));

(Exit)=\
	Macro(FBROWSER_IC_EXIT);

[Mode]=exaile_general

EXAILE_SETTITLE_GENERAL=\
	Make(var,exaile_artist,$(exaile_get) org.exaile.Exaile.GetTrackAttr string:artist|tail -1|grep string|cut -d '"' -f 2);\
        Make(var,exaile_album, $(exaile_get) org.exaile.Exaile.GetTrackAttr string:album |tail -1|grep string|cut -d '"' -f 2);\
	Make(var,exaile_title, $(exaile_get) org.exaile.Exaile.GetTrackAttr string:title |tail -1|grep string|cut -d '"' -f 2);\
	Set(title,$(exaile_artist)  - $(exaile_album));\
	Set(status,$(exaile_title));

Play CD=\
	Exec(exaile --play-cd);\
	Timer(EXAILE_SETTITLE,$(UpdateTimeout),0);

Files=\
	Timer(EXAILE_SETTITLE,cancel);\
	Make(mode,exaile_filebrowser);

EXAILE_SETPOS=\
	Exec($(exaile_cmd) org.exaile.Exaile.Seek double:$(exaile_pos));

EXAILE_GETPOS=\
	Make(var,exaile_curpos,$(exaile_get) org.exaile.Exaile.CurrentProgress|tail -1|grep string|cut -d '"' -f 2);

PLAY_ONLY=\
	Exec($(exaile_cmd) org.exaile.Exaile.Play);\
	Macro(EXAILE_SETTITLE);

PLAY=\
	Macro(PLAY_ONLY);\
	Timer(EXAILE_SETTITLE,5,0);
	
RWD=\
	Macro(EXAILE_GETPOS);\
	Make(var,exaile_pos,echo "$(exaile_curpos) * 3 - 3"|bc);\
	Macro(EXAILE_SETPOS);\
	Macro(EXAILE_SETTITLE);
	
FF=\
	Macro(EXAILE_GETPOS);\
	Make(var,exaile_pos,echo "$(exaile_curpos) * 3 + 8"|bc);\
	Macro(EXAILE_SETPOS);\
	Macro(EXAILE_SETTITLE);
	
PREV=\
	Exec($(exaile_cmd) org.exaile.Exaile.Prev);\
	Macro(EXAILE_SETTITLE);

STOP=\
	Timer(EXAILE_SETTITLE,cancel);\
	Exec($(exaile_cmd) org.exaile.Exaile.Stop);

NEXT=\
	Exec($(exaile_cmd) org.exaile.Exaile.Next);\
	Macro(EXAILE_SETTITLE);

PAUSE=\
	Exec($(exaile_cmd) org.exaile.Exaile.PlayPause);\
	Timer(EXAILE_SETTITLE,cancel);

%	Exec(P=`ps -ef|grep exaile|grep -v grep|grep -v anyremote|grep -v nedit`; if [ "x$P" = "x" ]; then exaile 2> /dev/null & fi);
RUN_IF_NEED=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh exaile);

RUN_OR_QUIT=\
	Timer(EXAILE_SETTITLE,cancel);\
	Exec(P=`ps -ef|grep exaile|grep -v grep|grep -v anyremote|grep -v nedit`; if [ "x$P" = "x" ]; then exaile 2> /dev/null & else pkill -f "python (.)*exaile"; fi);

APP_QUIT=\
	Timer(EXAILE_SETTITLE,cancel);Exec(pkill -f 'python (.)*exaile');

APP_PLAY_STATUS=\
	Make(var,exaile_status,$(exaile_get) org.exaile.Exaile.GetState|tail -1|grep string|cut -d '"' -f 2);\
	Make(var,app_status,if [ "x$(exaile_status)" = "xplaying" ]; then echo playing; else echo paused; fi);

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

Layout 5x1=\
	Make(mode,exaile_5x1);
	
[ModeEnd]

[Mode]=exaile_3x4 : exaile_general, default_player

EXAILE_SETTITLE=\
	Macro(EXAILE_SETTITLE_GENERAL);

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

APP_POST_SETUP=\
	Make(var,exaile_layout,by_value,3x4);

[ModeEnd]

[Mode]=exaile_cover

EXAILE_SETTITLE=\
	Macro(EXAILE_SETTITLE_GENERAL);\
	Macro(APP_COVER, if [ "x$(cover_size)" = "x" ]; then echo 1; else echo 0; fi);

APP_COVER=\
	Make(var,media_file,$(exaile_get) org.exaile.Exaile.GetTrackAttr string:__basedir|tail -1|grep string|cut -d '"' -f 2);\
	Macro(DEFAULT_COVER);

[ModeEnd]

[Mode]=exaile_5x1 : exaile_general, default_player_5x1, exaile_cover

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

APP_POST_SETUP=\
	Make(var,exaile_layout,by_value,3x4);

APP_TITLE=\
	Macro(EXAILE_SETTITLE);

PLAY=\
	Macro(PLAY_ONLY);
	
[ModeEnd]

[Mode]=exaile_nobutton

% bug-prone :)
1=Make(mode,exaile_$(exaile_layout));	
2=Make(mode,exaile_$(exaile_layout));	
3=Make(mode,exaile_$(exaile_layout));	
4=Make(mode,exaile_$(exaile_layout));	
5=Make(mode,exaile_$(exaile_layout));	
6=Make(mode,exaile_$(exaile_layout));	
7=Make(mode,exaile_$(exaile_layout));	
8=Make(mode,exaile_$(exaile_layout));	
9=Make(mode,exaile_$(exaile_layout));	
*=Make(mode,exaile_$(exaile_layout));	
0=Make(mode,exaile_$(exaile_layout));	
#=Make(mode,exaile_$(exaile_layout));	

[ModeEnd]

% rely on $(exaile_layout) variable
[Mode]=exaile_filebrowser : exaile_nobutton

(EnterMode)=\
	Macro(FBROWSER_IC_FILL_LIST);\
	Macro(UpdateMenu);

UpdateMenu=\
	Set(menu,replace,GoTo,Add,Go Home);

GoTo($$)=\
	Macro(FBROWSER_IC_GO_TO);
	
Go Home($$)=\
	Macro(FBROWSER_IC_GO_HOME);
	
%Push($$) use from aliases-server-fbrowser-v4i.cfg

Add($$)=\
	Exec($(exaile_cmd) org.exaile.Exaile.Enqueue array:string:"$(fbrowser_dir)"/$(Param));

Back($$)=\
	Set(list,close);\
	Make(mode,exaile_$(exaile_layout));

[ModeEnd]

[End]

%qdbus org.exaile.Exaile /org/exaile/Exaile org.exaile.Exaile.GetTrackAttr __loc

