%
% anyremote configuration file for amarok/KDE4 management. (Server-mode)
% 

% STATUS stable
% XTEST no
% SOUND app
% ENV no
% DEF_PLAYER   
% ALL_IN_ONE 

GuiAppName=Amarok
GuiAppBinary=amarok
GuiAppVersion=echo 'V=`amarok -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d "."`; if [ "x$V" = "x4" ]; then echo OK; else echo NOK; fi'|sh -s
GuiAppRun=echo 'A=`pgrep amarok`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=amarok.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Amarok is the music player for Linux and Unix with an intuitive interface. Amarok makes playing the music you love easier than ever before - and looks good doing it. This configuration file is for Amarok/KDE4

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(TEST_QDBUS);\
	Macro(TEST_DBUS_SEND);\
	Make(var,kde4_app,by_value,amarok);\
	Macro(TEST_KDE4_APP);\
	Make(var,player_name,by_value,Amarok);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);

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

(Disconnect)=\
	Timer(AMAROK_TITLE,cancel);

AMAROK_TITLE=\
	Make(var,art,qdbus org.kde.amarok /Player GetMetadata|grep artist:|sed 's/artist://');\
	Make(var,tit,qdbus org.kde.amarok /Player GetMetadata|grep title:|sed 's/title://');\
	Set(title,$(art) - $(tit));

AMAROK_TIMER=\
	Macro(AMAROK_TITLE);\
	Timer(AMAROK_TITLE,5,0);

[Mode]=amarok
	
(EnterMode)=\
	Make(var,am_dbus,if [ "x$(Dbus)" = "xyes" ]; then echo amarok_dbus; else echo amarok_nodbus; fi);\
	Make(mode,$(am_dbus));

[ModeEnd]

%
% Will be used if compiled with dbus support
%
[Mode]=amarok_dbus : default_player

% (EnterMode) by Utils/aliases-server-player.cfg
	
APP_POST_SETUP=\
	Dbus(connect,am2,org.kde.amarok,/Player,org.freedesktop.MediaPlayer);\
	Dbus(connect,am2b,org.kde.amarok,/,org.freedesktop.MediaPlayer);\
	Macro(AMAROK_TITLE);\
	Macro(GETVOL);\
	Macro(GETPOS);\
	Make(var,am_mute,by_value,$(am_volume));

GETVOL=Dbus(get,am2,VolumeGet,int,am_volume);
GETPOS=Dbus(get,am2,PositionGet,int,am_pos);

APP_MENU=\
	Set(menu,replace,Playlist,Power Off,Suspend);\
	Macro(ALLIN1MENU);

% Power Off, Suspend by Utils/aliases-server-player.cfg

Playlist=\
	Timer(AMAROK_TITLE,cancel);\
	Make(mode,amarok_playlist);
	
% Custom volume control
1=Macro(GETVOL);\
	Make(var,am_volume,expr $(am_volume) - 5);\
	Dbus(set,am2,VolumeSet,int,$(am_volume));

2=Make(var,am_mute,if [ "x$(am_mute)" = "x-1" ]; then qdbus org.kde.amarok /Player VolumeGet; dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.VolumeSet int32:0; else dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.VolumeSet int32:$(am_volume); echo "-1"; fi)

3=Macro(GETVOL);\
	Make(var,am_volume,expr $(am_volume) + 5);\
	Dbus(set,am2,VolumeSet,int,$(am_volume));

PLAY=\
	Dbus(set,am2,Play);Macro(AMAROK_TIMER);
	
RWD=\
	Macro(GETPOS);\
	Make(var,am_pos,expr $(am_pos) - 10000);\
	Dbus(set,am2,PositionSet,int,$(am_pos));
	
FF=\
	Macro(GETPOS);\
	Make(var,am_pos,expr $(am_pos) + 10000);\
	Dbus(set,am2,PositionSet,int,$(am_pos));
	
PREV=\
	Dbus(set,am2,Prev);
	Macro(AMAROK_TITLE);

STOP=\
	Dbus(set,am2,Stop);\
	Set(title,);\
	Set(status,);\
	Timer(AMAROK_TITLE,cancel);

NEXT=\
	Dbus(set,am2,Next);\
	Macro(AMAROK_TITLE);

PAUSE=\
	Dbus(set,am2, Pause);\
	Set(title,);
	Set(status,);

RUN_IF_NEED=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh amarok);

RUN_OR_QUIT=\
	Exec(P=`pgrep amarok`; if [ "x$P" = "x" ]; then amarok 2> /dev/null; else dbus-send --type=method_call --dest=org.kde.amarok / org.freedesktop.MediaPlayer.Quit; fi);\
	Set(title,);\
	Set(status,);

QUIT=\
	Exec(dbus-send --type=method_call --dest=org.kde.amarok / org.freedesktop.MediaPlayer.Quit);\
	Timer(AMAROK_TITLE,cancel);\
	Set(title,);\
	Set(status,);

[ModeEnd]

%
% Will be used if compiled without dbus support
%
[Mode]=amarok_nodbus : default_player

% (EnterMode) by Utils/aliases-server-player.cfg
	
APP_POST_SETUP=\
	Macro(GETVOL);\
	Make(var,am_mute,by_value,$(am_volume));
	
GETVOL=\
	Make(var,am_volume,qdbus org.kde.amarok /Player VolumeGet);
	
GETPOS=\
	Make(var,am_pos,qdbus org.kde.amarok /Player PositionGet);

APP_MENU=\
	Set(menu,replace,Playlist,Power Off,Suspend);Macro(ALLIN1MENU);

% Power Off, Suspend by Utils/aliases-server-player.cfg

Playlist=\
	Timer(AMAROK_TITLE,cancel);\
	Make(mode,amarok_playlist);

% Custom volume control
1=Macro(GETVOL);\
	Exec(dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.VolumeSet int32:`expr $(am_volume) - 5`);
2=Make(var,am_mute,if [ "x$(am_mute)" = "x-1" ]; then qdbus org.kde.amarok /Player VolumeGet; dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.VolumeSet int32:0; else dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.VolumeSet int32:$(am_volume); echo "-1"; fi);
3=Macro(GETVOL);\
	Exec(dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.VolumeSet int32:`expr $(am_volume) + 5`);

% Possible DBUS commands
% dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Play
% dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Stop
% dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Next
% dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Prev
% dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Pause

PLAY=\
	Exec(amarok --play);Macro(AMAROK_TIMER);
	
RWD=\
	Macro(GETPOS);\
	Exec(dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.PositionSet int32:`expr $(am_pos) - 10000`);

FF=\
	Macro(GETPOS);\
	Exec(dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.PositionSet int32:`expr $(am_pos) + 10000`);

PREV=\
	Exec(amarok --previous);\
	Macro(AMAROK_TITLE);

STOP=\
	Exec(amarok --stop);\
	Set(title,);\
	Set(status,);\
	Timer(AMAROK_TITLE,cancel);

NEXT=\
	Exec(amarok --next);\
	Macro(AMAROK_TITLE);

PAUSE=\
	Exec(amarok --pause);\
	Set(title,);\
	Set(status,);

RUN_IF_NEED=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh amarok);
	
RUN_OR_QUIT=\
	Exec(P=`pgrep amarok`; if [ "x$P" = "x" ]; then amarok 2> /dev/null; else dbus-send --type=method_call --dest=org.kde.amarok / org.freedesktop.MediaPlayer.Quit; fi);\
	Set(title,);\
	Set(status,);

QUIT=\
	Exec(dbus-send --type=method_call --dest=org.kde.amarok / org.freedesktop.MediaPlayer.Quit);\
	Timer(AMAROK_TITLE,cancel);\
	Set(title,);\
	Set(status,);

[ModeEnd]

[Mode]=amarok_playlist

(EnterMode)=\
	Set(list,font,small);\
	ExecAndSet(list,replace,Playlist,$(CfgDir)/Utils/getPlayList.sh);\
	Set(menu,add,Play);
	
(ExitMode)=\
	Set(list,close);

Back($$)=\
	Make(mode,$(am_dbus));

Play($$)=\
	Exec(qdbus org.kde.amarok /TrackList org.freedesktop.MediaPlayer.PlayTrack `expr $(Index) - 1`);

Push($$)=\
	Macro(Play($$));

[ModeEnd]

[End]
