%
% anyremote configuration file for amarok/KDE4 management with cover support. (Server-mode)
% 
% Thanks to Jesus Vidal Panalus for this configuration file                                               
%                                                                                                         

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

GuiAppName=Amarok with Cover support
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 Amarok2 with cover support

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(SETUP_DEFAULT_POWER_MANAGEMENT);\
	Macro(TEST_QDBUS);\
	Macro(TEST_DBUS_SEND);\
	Macro(TEST_IMAGEMAGIC);\
	Make(var,kde4_app,by_value,amarok);\
	Macro(TEST_KDE4_APP);\
	Make(var,arDir,by_value,$HOME/.anyRemote/);\
	Make(var,cvDir,by_value,$(arDir)amarok_covers/);
	
(Connect)=\
	Make(mode,amarok-v2);

AMAROK_HELP=\
	Set(text,replace,Help, 1 Prev\n 2 Rewind\n 3 Play\n 4 Pause\n 5 Stop\n 6 Forward\n 7 Next\n 8 Vol-\n 9 Vol+\n 0 Mute\n ** Help\n # Quit\n *# Run/Quit);

AM_COVER=\
	Make(var,coverencode,qdbus org.kde.amarok /Player GetMetadata|grep arturl:|sed "s/arturl: file:\/\///");\
	Make(var,coverdecode, echo 'arg="$(coverencode)";i="0";while [ "$i" -lt ${#arg} ]; do c0=${arg:$i:1}; if [ "x$c0" = "x%" ]; then c1=${arg:$((i+1)):1}; c2=${arg:$((i+2)):1}; printf "\x$c1$c2"; i=$((i+3)); else echo -n "$c0"; i=$((i+1)); fi done'|bash -f -s);\
	Make(var,coverconverted, echo 'F=`basename "$(coverdecode)"`;convert \( "$(coverdecode)" -resize $(cover_size)x$(cover_size) \) -append $(cvDir)/$F;echo $(cvDir)/$F;' | bash -f -s);\
	Set(cover,$(coverconverted));
	
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));\
	Macro(AM_COVER);

#       Make(var,song_pos,qdbus org.kde.amarok /Player PositionGet);\
#	ExecAndSet(status,echo $(song_pos)|awk '{min=int($0/60000);sec=int(($0-min*60000)/1000);if (sec < 10) {sec="0"sec;}; printf("%s:%s",min,sec);}');\
#       ExecAndSet(status,echo `qdbus org.kde.amarok /Player GetMetadata|grep mtime|sed 's/mtime://'|tr -d ' '`|awk '{min=int($0/60000);sec=int(($0-min*60000)/1000);if (sec < 10) {sec="0"sec;}; printf("%s:%s",min,sec);}');\
 	
AMAROK_START_TIMER=\
	Macro(AMAROK_TITLE);\
	Timer(AMAROK_TITLE,5,0);

AMAROK_STOP_TIMER=\
	Timer(AMAROK_TITLE,cancel);

AM_LAYOUT=\
	Set(icons, Amarok2,1,prev,2,rewind,3,play,4,pause,5,stop,6,forward,7,next,8,none,9,none,*,none,0,none,#,none);\
	Set(layout,7x1,joystick_only,choose,3,volume,ticker,up,Vol+,down,Vol-);\
	Set(font,small);
	
AM_RUN=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh amarok);

GETVOL=\
	Make(var,am_volume,qdbus org.kde.amarok /Player VolumeGet);\
	
SETVOL=\
	Macro(GETVOL);\
	Set(volume,$(am_volume));

GETPOS=Make(var,am_pos,qdbus org.kde.amarok /Player PositionGet);

[Mode]=amarok-v2

(EnterMode)=\
	Macro(AM_LAYOUT);\
	Macro(AM_RUN);\
	Exec(rm -rf $(cvDir);mkdir $(cvDir));\
	Make(var,cover_size,by_value,128);\
	Get(cover_size);\
	Exec(convert $(CfgDir)/Utils/gradient.png -resize $(cover_size) $(cvDir)/gradient_small);\
	Macro(SETVOL);\
	Macro(GETPOS);\
	Set(status,);\
	Macro(AMAROK_START_TIMER);\
	Make(var,am_mute,by_value,0);\
	Macro(AMAROK_MENU);
	
AMAROK_MENU=\
	Set(menu,replace,Help,Playlist,Power Off,Suspend);\
	Macro(ALLIN1MENU);

Cancel=\
	Exec(qdbus org.kde.amarok / Quit);\
	Exec(rm -rf $(cvDir));\
	Exit;

(Disconnect)=\
	Macro(AMAROK_STOP_TIMER);

Back=Set(text,close);\
	Macro(AMAROK_MENU);

CoverSize($$)=Make(var,cover_size,by_value,$(Index));

Vol+=Exec(qdbus org.kde.amarok /Player VolumeUp 5);\
	Macro(SETVOL);
	
Vol-=Exec(qdbus org.kde.amarok /Player VolumeDown 5);\
	Macro(SETVOL);

% Android support
VOL-=Macro(Vol-);
VOL+=Macro(Vol+);
	
Help=Macro(AMAROK_HELP);

Playlist=\
	Macro(AMAROK_STOP_TIMER);\
	Make(mode,amarok_playlist_v2)

Power Off=\
	Macro(DEFAULT_PC_SWITCHOFF);

Suspend=\
	Macro(DEFAULT_PC_SUSPEND);

% It is possible to use
% qdbus org.kde.amarok /Player Next/Prev/...

1=Exec(amarok --previous);\
	Macro(AMAROK_START_TIMER);

2=Macro(GETPOS);\
	Exec(qdbus org.kde.amarok /Player PositionSet `expr $(am_pos) - 10000`);

3=Exec(amarok --play);\
	Macro(AMAROK_START_TIMER);\
	Set(status,);

4=Exec(amarok --pause);\
	Macro(AMAROK_STOP_TIMER);

5=Exec(amarok --stop);\
	Macro(AMAROK_STOP_TIMER);\
	Set(status,Stopped);

6=Macro(GETPOS);\
	Exec(qdbus org.kde.amarok /Player PositionSet `expr $(am_pos) + 10000`);

7=Exec(amarok --next);\
	Macro(AMAROK_START_TIMER);

8=Exec(qdbus org.kde.amarok /Player VolumeDown 5);\
	Macro(SETVOL);

9=Exec(qdbus org.kde.amarok /Player VolumeUp 5);\
	Macro(SETVOL);

0=Macro(GETVOL);\
	Set(volume,$(am_mute));\
	Exec(qdbus org.kde.amarok /Player VolumeSet $(am_mute));\
	Make(var,am_mute,if [ "$(am_mute)" = "0" ]; then echo $(am_volume); else echo 0; fi);

* *=Macro(AMAROK_HELP);

* #=Exec(P=`pgrep amarok`; if [ "x$P" = "x" ]; then amarok 2> /dev/null; else qdbus org.kde.amarok / Quit; fi);\
	Set(title,);\
	Set(status,);

#=Exec(qdbus org.kde.amarok / Quit);\
	Macro(AMAROK_STOP_TIMER);\
	Set(title,);\
	Set(status,);

[ModeEnd]

[Mode]=amarok_playlist_v2

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

Back($$)=Make(mode,amarok-v2);

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

[ModeEnd]

[End]
