%
% anyremote configuration file for amarok management. (Server-mode)
% 
% Thanks to Gabriele Flammia for the patch.
%

% STATUS stable
% TODO comma in song title
% XTEST no
% SOUND app
% ENV no
% FBROWSER v.3i

GuiAppName=Amarok/KDE3
GuiAppBinary=amarok
GuiAppVersion=echo 'V=`amarok -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d "."`; if [ "x$V" == "x3" ]; then echo OK; else echo NOK; fi'|bash -f -s
GuiAppRun=echo 'A=`dcop 2> /dev/null|grep amarok`; if [ "x$A" == "x" ]; then echo NOK; else echo OK; fi'|bash -f -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/KDE3

[Protocol]=Server

(Init)=Include($(CfgDir)/Utils/aliases-server.cfg);\
	Exec(echo 'V=`amarok -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d "."`;if [ "x$V" == "x4" ]; then $(CfgDir)/Utils/message.sh "ERROR: this configuration file is for KDE3"; fi'|bash -f -s);

(Connect)=Set(parameter,debug,on);\
	Make(mode,amarok);

AMAROK_HELP =Set(text,replace,Help, 1 Vol-\n 2 Mute\n 3 Vol+\n 4 Rew\n 5 Play\n 6 FF\n 7 Prew\n 8 Stop\n 9 Next\n ** Help\n 0 Pause\n # Quit\n *# Run/Quit);
AMAROK_TITLE=ExecAndSet(title,dcop amarok player nowPlaying|sed 's/%20/ /g');
AMAROK_TIMER=Macro(AMAROK_TITLE);\
	Timer(AMAROK_TITLE,5,0);

[Mode]=amarok

(EnterMode)=Exec(echo 'A=`dcop 2> /dev/null|grep amarok`; if [ "x$A" == "x" ]; then amarok 2> /dev/null; fi'|bash -f -s);\
	Macro(AMAROK_TITLE);\
	Make(var,am_volume,dcop amarok player getVolume);\
	Set(layout,default);\
	Set(icons,Amarok,1,vol_down,2,mute,3,vol_up,4,rewind,5,play,6,forward,7,prev,8,stop,9,next,*,question,0,pause,#,no);\
	Set(status,);\
	Set(font,small);\
	Set(menu,replace,Playlist,Search,File Browser);\
	Macro(ALLIN1MENU);

Cancel=Exec(dcop amarok MainApplication-Interface quit);
(Disconnect)=Timer(AMAROK_TITLE,cancel);

Back=Set(text,close);Set(menu,replace,Playlist,File Browser);Macro(ALLIN1MENU);

Playlist=Timer(AMAROK_TITLE,cancel);Make(mode,amarok_playlist)
Search=Timer(AMAROK_TITLE,cancel);Make(mode,amarok_search)
File Browser=Timer(AMAROK_TITLE,cancel);Make(mode,amarok_file_browser)

1=Exec(dcop amarok player volumeDown) 
%2=Exec(dcop amarok player mute) -- only mutes with amarok 1.4.8
2=Make(var,am_volume,echo 'if [ "x$(am_volume)" == "x-1" ]; then dcop amarok player getVolume;dcop amarok player setVolume 0; else dcop amarok player setVolume $(am_volume); echo "-1"; fi;'|bash -f -s)
3=Exec(dcop amarok player volumeUp) 

4=Exec(dcop amarok player seekRelative -10) 
5=Exec(dcop amarok player play);Macro(AMAROK_TIMER);
6=Exec(dcop amarok player seekRelative 10) 

7=Exec(dcop amarok player prev);Macro(AMAROK_TITLE);
8=Exec(dcop amarok player stop);Set(title,Stopped);Timer(AMAROK_TITLE,cancel);
9=Exec(dcop amarok player next);Macro(AMAROK_TITLE);

* *=Macro(AMAROK_HELP);
* #=Exec(echo 'P=`dcop 2> /dev/null|grep amarok`; if [ "x$P" == "x" ]; then amarok 2> /dev/null; else dcop amarok MainApplication-Interface quit; fi'|bash -f -s);\
	Set(title,);\
	Set(status,);
0=Exec(dcop amarok player pause);Timer(AMAROK_TITLE,cancel);Set(title,Paused);Set(status,);
#=Exec(dcop amarok MainApplication-Interface quit);Timer(AMAROK_TITLE,cancel);Set(title,);Set(status,);

[ModeEnd]

[Mode]=amarok_playlist

(EnterMode)=Set(list,font,medium);\
	ExecAndSet(list,replace,Playlist,dcop amarok playlist saveCurrentPlaylist;grep '<item'  $HOME/.kde/share/apps/amarok/current.xml|sed 's/<item url=\"file:\/\/\(.*\)\" \(.\)*$/\1/'|xargs -i basename {}|sed 's/uniqueid=.*//g;s/%20/ /g;s/,/\r/g;s/$/,/');\
	Set(menu,add,Choose);
(ExitMode)=Set(list,close);Set(status,Playing);Macro(AMAROK_TITLE);Macro(AMAROK_TIMER);

Back($$)=Make(mode,amarok);
Choose($$)=Exec(dcop amarok playlist playByIndex `expr $(Index) - 1`);

[ModeEnd]

[Mode]=amarok_search

(EnterMode)=Set(editfield,Search,Pattern, )
(ExitMode)=Set(list,close);Set(status,Playing);Macro(AMAROK_TITLE);Macro(AMAROK_TIMER);

Back($$)=Exec(rm -f $HOME/.anyRemote/amarok.numbered_playlist);Make(mode,amarok);
Ok($$)=Exec(dcop amarok playlist saveCurrentPlaylist;grep '<item' $HOME/.kde/share/apps/amarok/current.xml|sed 's/<item url=\"file:\/\/\(.*\)\" \(.\)*$/\1/'|xargs -i basename {}|sed 's/uniqueid=.*//g;s/%20/ /g;s/,/\r/g'|nl > $HOME/.anyRemote/amarok.numbered_playlist;cat $HOME/.anyRemote/amarok.numbered_playlist|grep $(Param) > $HOME/.anyRemote/amarok.filtered_playlist);\
	Set(list,font,medium);\
	ExecAndSet(list,replace,Filtered,sleep 1;cat $HOME/.anyRemote/amarok.filtered_playlist|cut -f 2|sed 's/$/,/');\
	Set(menu,add,Choose_);

Choose_($$)=Make(var,real_index,cat $HOME/.anyRemote/amarok.filtered_playlist|head -$(Index)|tail -1|cut -f 1|tr -d ' ');\
	Exec(dcop amarok playlist playByIndex `expr $(real_index) - 1`);

[ModeEnd]

[Mode]=amarok_file_browser

(EnterMode)=Set(list,font,small);Macro(FillList);Macro(UPDATEMENU);
(ExitMode)=Set(list,close);Macro(AMAROK_TIMER);

UPDATEMENU=Set(menu,replace,GoTo,Add to playlist,Clear playlist,Go Home);

% FBROWSER v.3i 
FillList=Set(iconlist,replace,Files,folder:..);\
	Macro(FillDir);\
        Macro(FillFile);
FillDir =ExecAndSet(iconlist,add,SAME,cd "`cat $HOME/.anyRemote/ar_storedir.tmp`";ls -F --quoting-style=shell|sed 's/\*//;s/,/\r/g;s/@//;s/$/,/'|grep '/'| xargs -d '\n' -i echo "folder:" {});
FillFile=ExecAndSet(iconlist,add,SAME,cd "`cat $HOME/.anyRemote/ar_storedir.tmp`";ls -F --quoting-style=shell|sed 's/\*//;s/,/\r/g;s/@//;s/$/,/'|grep -v '/'| xargs -d '\n' -i echo "file:"{});
GoTo($$)=Make(var,goto,by_value,$(Param));\
	ExecAndSet(iconlist,replace,Files,cd "`cat $HOME/.anyRemote/ar_storedir.tmp`";echo "if [ -d $(goto) ]; then cd $(goto);fi;pwd>$HOME/.anyRemote/ar_storedir.tmp;"|bash -f -s;echo "folder:..");\
	Macro(FillDir);\
        Macro(FillFile);
Go Home($$)=ExecAndSet(iconlist,replace,Files,cd;pwd>$HOME/.anyRemote/ar_storedir.tmp;echo "folder:..");\
	Macro(FillDir);\
        Macro(FillFile);
% FBROWSER v.3i 

Add to playlist($$)=Exec(dcop amarok playlist addMedia "`cat $HOME/.anyRemote/ar_storedir.tmp`/$(Param)");
Clear playlist($$)=Exec(dcop amarok playlist clearPlaylist);
Back($$)=Make(mode,amarok);

[ModeEnd]

[End]
