%
% anyremote configuration file for amarok management. (Server-mode)
% v.3 - Improved cover art + library access
% Made by Carlos Sanchez (chukysoria@gmail.com)
% --- modified to run with amarok/kde4 (johann bauer, johann.bauer1@gmail.com )

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

GuiAppName=Amarok v3
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
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 supports cover art. This configuration file is for Amarok/KDE3

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(SETUP_DEFAULT_POWER_MANAGEMENT);\
	Macro(TEST_IMAGEMAGIC);\
	Make(var,kde4_app,by_value,amarok);\
	Macro(TEST_KDE4_APP);\
	Make(var,arDir,echo $(TmpDir)/);\
	Make(var,cvDir,by_value,$(arDir)amarok_covers/);

(Connect)=\
	Make(mode,amarok-v3);
	
InCall($$)=\
	Exec(qdbus org.kde.amarok /Player Mute);\
	Exec(dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Pause);\
	Macro(AMAROK_V2_STOP_TIMER);\
	Make(remote,off);
	
EndCall($$)=\
	Make(remote,on);\
	Exec(qdbus org.kde.amarok /Player Mute);\
	Exec(dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Play);\
	Macro(AMAROK_V2_START_TIMER);

AMAROK_V2_SETINFO=\
	ExecAndSet(title,T=`qdbus org.kde.amarok /Player GetMetadata|grep title:|cut -f 2 -d ":"`; A=`qdbus org.kde.amarok /Player GetMetadata|grep artist:|cut -f 2 -d ":"`;echo "$T" by"$A");\
	ExecAndSet(status,T=`qdbus org.kde.amarok /Player GetMetadata |grep "^time"|cut -f 2 -d ":" ` ; if [ "x$T" = "x" ]; then echo ""; else min=`expr $T / 60` ; sec=`expr $T % 60`; echo "$min:$sec"; fi);\
	ExecAndSet(cover,noname,I=`qdbus org.kde.amarok /Player GetMetadata |grep arturl|cut -f 2 -d " "|sed "s/%20/ /g"|cut -f 2 -d ":" ` ;F=`basename "$I"`; if [ "x$F" = "x" ]; then echo ""; else convert "$I" -resize $(cover_size)x$(cover_size) -append $(cvDir)$F; echo $(cvDir)$F; fi);

AMAROK_V2_START_TIMER=\
	Timer(AMAROK_V2_SETINFO,$(UpdateTimeout),0);

AMAROK_V2_STOP_TIMER=\
	Timer(AMAROK_V2_SETINFO,cancel);

[Mode]=amarok-v3

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

AM_V2_MENU=\
	Set(menu,replace,Shuffle,Repeat,Playlist,Run Player,Quit Player,Toggle Fullscreen,PowerMgmt,Help);\
	Macro(ALLIN1MENU);\
	Macro(VOL_SET);

(EnterMode)=\
	Macro(AM_V2_LAYOUT);\
	Macro(AM_V2_RUN_IF);\
	Exec(rm -rf $(cvDir);mkdir $(cvDir));\
	Make(var,cover_size,echo 128);\
	Get(cover_size);\
	Macro(AMAROK_V2_SETINFO);\
	Macro(VOL_GET);\
	Make(var,am_mute,by_value,$(am_volume));\
	Macro(AM_V2_MENU);\
	Macro(AMAROK_V2_START_TIMER);

Cancel=\
	Exec(rm -rf $(cvDir));
	
(Disconnect)=\
	Macro(AMAROK_V2_STOP_TIMER);

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

Playlist=\
	Macro(AMAROK_V2_STOP_TIMER);\
	Make(mode,amarok_playlist_v3);

Shuffle=\
	Make(var,shuffle_val,P=`qdbus org.kde.amarok /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Shuffle`; if [ "x$P" = "xtrue" ]; then echo 0; else echo 1; fi);\
        Exec(qdbus org.kde.amarok /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Shuffle $(shuffle_val));

Repeat=\
	Make(var,repeat_val,P=`qdbus org.kde.amarok /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.LoopStatus`; if [ "x$P" = "xNone" ]; then echo 1; else echo 0; fi);\
        Exec(qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.Repeat $(repeat_val));

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

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

% Android support
VOL-=Macro(Vol-);
VOL+=Macro(Vol+);
	
Toggle Fullscreen=\
	Set(fullscreen,toggle);\
	Set(cover,clear);\
	Get(cover_size);

CoverSize($$)=\
	Make(var,cover_size,by_value,$(Index));\
	Exec(echo $(arDir) > $(TmpDir)/cover_size);
	
Run Player=\
	Macro(AM_V2_RUN_IF);

Quit Player=\
	Exec( qdbus org.kde.amarok /MainApplication quit );\
	Macro(AMAROK_V2_STOP_TIMER);\
	Set(title,);\
	Set(status,);
	
Help=Set(text,replace,Help,Manage player by joystick or from menu);

VOL_SET=\
	ExecAndSet(volume, qdbus org.kde.amarok /Player VolumeGet);Macro(AMAROK_V2_SETINFO);

VOL_GET=\
	Make(var,am_volume,qdbus org.kde.amarok /Player VolumeGet);

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

% No more 7 buttons - Nokias Series40 has 160x120 screens 
1=Exec(qdbus org.kde.amarok /Player Prev);Macro(AMAROK_V2_SETINFO);
2=Macro(GETPOS);\
	Exec(qdbus org.kde.amarok /Player PositionSet `expr $(am_pos) - 10000`);
3=Exec(qdbus org.kde.amarok /Player Play);Macro(AMAROK_V2_START_TIMER);Macro(VOL_SET);
4=Exec(qdbus org.kde.amarok /Player Pause);
5=Macro(GETPOS);\
	Exec(qdbus org.kde.amarok /Player PositionSet `expr $(am_pos) + 10000`);
6=Exec(qdbus org.kde.amarok /Player Next);Macro(AMAROK_V2_SETINFO);
7=Exec(qdbus org.kde.amarok /Player Mute);

[ModeEnd]

[Mode]=amarok_playlist_v3

(EnterMode)=\
	Set(list,font,small);\
	Set(list,bg,54,73,135);\
	Set(list,fg,141,159,218);\
	ExecAndSet(list,replace,Playlist,$(CfgDir)/Utils/getPlayList.sh);\
	Set(menu,add,Play);
	
(ExitMode)=\
	Set(list,close);\
	Macro(AMAROK_V2_START_TIMER);

Back($$)=\
	Make(mode,amarok-v3);

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

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

[ModeEnd]

[End]

