%
% anyremote configuration file for Kaffeine management. (Server-mode)
% Kaffeine playlist should be already created
%
% Thanks to Gabriele Flammia for the patch.
%

% STATUS stable
% XTEST no
% SOUND app
% ENV no
% XTEST no
% FBROWSER v.3i
% ALL_IN_ONE 

GuiAppName=Kaffeine
GuiAppBinary=kaffeine
GuiAppRun=echo 'A=`pgrep kaffeine`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=kaffeine.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=KDE media player

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Include($(CfgDir)/Utils/aliases-server-fbrowser-v3i.cfg);\
	Make(var,kde-version,kaffeine -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d ".");
	
(Connect)=\
	Make(mode,kaffeine-kde$(kde-version));

[Mode]=kaffeine-kde

% Dummy mode

(EnterMode)=\
	Set(layout,default);\
	Set(icons,Kaffeine,1,none,2,none,3,none,4,none,5,no,6,none,7,none,8,none,9,none,*,none,0,none,#,none);\
	Set(title,It seems Kaffeine is not installed);\
	Set(menu,replace,);\
	Macro(ALLIN1MENU);
	
[ModeEnd]

[Mode]=kaffeine-kde4

(EnterMode)=\
	Macro(RUN_IF_NEED);\
	Set(layout,default);\
	Set(title,);\
	Set(status,);\
	Set(icons,Kaffeine,1,vol_down,2,mute,3,vol_up,4,rewind,5,play,6,forward,7,prev,8,pause,9,next,*,question,0,stop,#,no);\
	Macro(K_MENU);\
	Macro(ALLIN1MENU);
	
Cancel=Macro(QUIT);Exit

Back      =Set(text,close);Macro(K_MENU);Macro(ALLIN1MENU);
Back($$)  =Set(list,close);Macro(K_MENU);Macro(ALLIN1MENU);

UpdateMenu=Set(menu,replace,GoTo,Open,Go Home);
Browse files=Macro(QUIT);Set(title,);Macro(FBROWSER_IC_FILL_LIST);Macro(UpdateMenu);
Fullscreen=Exec(qdbus org.mpris.kaffeine /Player ToggleFullScreen);
QUIT=Exec(qdbus org.mpris.kaffeine /MainApplication quit)

K_MENU=Set(menu,replace,Browse files,Fullscreen,Power Off,Suspend);
MPRIS_POS=Make(var,mpris_pos,qdbus org.mpris.kaffeine /Player PositionGet 2> /dev/null);

Open($$)=Set(list,close);\
	ExecAndSet(title,$(Param));\
	Set(menu,clear);\
	Exec(P=`qdbus|grep kaffeine`; if [ "x$P" = "x" ]; then cd "`cat $HOME/.anyRemote/ar_storedir.tmp`";kaffeine "$(Param)"& fi);\
	Macro(K_MENU);\
	Macro(ALLIN1MENU);

GoTo($$)   =Macro(FBROWSER_IC_GO_TO);
Go Home($$)=Macro(FBROWSER_IC_GO_HOME);
Push($$)   =Macro(FBROWSER_IC_GO_TO);

1=Exec(qdbus org.mpris.kaffeine /Player DecreaseVolume);
2=Exec(qdbus org.mpris.kaffeine /Player ToggleMuted);
3=Exec(qdbus org.mpris.kaffeine /Player IncreaseVolume);

4=Macro(MPRIS_POS);\
        Make(var,mpris_pos,echo "$(mpris_pos)-10000"|bc);\
        Exec(qdbus org.mpris.kaffeine /Player PositionSet $(mpris_pos)  2> /dev/null);
5=Exec(qdbus org.mpris.kaffeine /Player Play);
6=Macro(MPRIS_POS);\
        Make(var,mpris_pos,echo "$(mpris_pos)+10000"|bc);\
        Exec(qdbus org.mpris.kaffeine /Player PositionSet $(mpris_pos)  2> /dev/null);

7=Exec(qdbus org.mpris.kaffeine /Player Prev);
8=Exec(qdbus org.mpris.kaffeine /Player Pause);
9=Exec(qdbus org.mpris.kaffeine /Player Next);

* *=Set(text,replace,Help,1 Vol-\n2 Mute\n3 Vol+\n4 Rew\n5 Play\n6 FF\n7 Prew\n8 Pause\n9 Next\n* * Help\n0 Stop\n* 0 Toggle Fullscreen\n# Exit\n)
0=Exec(qdbus org.mpris.kaffeine /Player Stop);
* 0=Macro(Fullscreen);
#=Macro(QUIT);

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

[ModeEnd]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% legacy support for KDE3, to be removed
%
%

[Mode]=kaffeine-kde3

KAFFEINE_SETTITLE=\
	ExecAndSet(title,basename "`dcop kaffeine KaffeineIface getFileName`")

(EnterMode)=\
	Exec(A=`dcop|grep kaffeine`; if [ "x$A" = "x" ]; then kaffeine;sleep 2;dcop kaffeine KaffeineIface setNumber 1;fi);\
	Set(layout,default);\
	Set(icons,Kaffeine,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(menu,replace,Playlist,Toggle Fullscreen,Close and exit);\
	Macro(ALLIN1MENU);

Cancel=\
	Exec(dcop kaffeine KaffeineIface quit);Exit

Back=\
	Set(text,close);\
	Set(menu,replace,Playlist,Toggle Fullscreen,Close and exit);\
	Macro(ALLIN1MENU)

1=Exec(dcop kaffeine KaffeineIface volDown)
2=Exec(dcop kaffeine KaffeineIface mute)
3=Exec(dcop kaffeine KaffeineIface volUp)

4=Exec(dcop kaffeine KaffeineIface posMinus)
5=Exec(dcop kaffeine KaffeineIface play);Set(status,Playing);Macro(KAFFEINE_SETTITLE);Timer(KAFFEINE_SETTITLE,10,0);
6=Exec(dcop kaffeine KaffeineIface posPlus)

7=ExecAndSet(title,dcop kaffeine KaffeineIface previous;basename "`dcop kaffeine KaffeineIface getFileName`")
8=Exec(dcop kaffeine KaffeineIface stop);Set(status,Stopped);Timer(KAFFEINE_SETTITLE,cancel);
9=ExecAndSet(title,dcop kaffeine KaffeineIface next;basename "`dcop kaffeine KaffeineIface getFileName`")


* 1=Exec(dcop kaffeine XinePartIface zoomOut);
* 3=Exec(dcop kaffeine XinePartIface zoomIn);

* *=Set(text,replace,Help,1 Vol-  2 Mute  3 Vol+\n4 Rew   5 Play  6 FF\n7 Prew  8 Stop  9 Next\n* Help  0 Pause # Exit\n* 1 - Zoom In\n* 3 - Zoom Out\n* # - Run/Quit)
* #=Exec(P=`dcop|grep kaffeine`; if [ "x$P" = "x" ]; then kaffeine;sleep 2;dcop kaffeine KaffeineIface setNumber 1; else dcop kaffeine KaffeineIface quit; fi)
0=Exec(dcop kaffeine KaffeineIface pause);Make(mode,kaffeine_pause);
#=Exec(dcop kaffeine KaffeineIface quit)

Playlist=Make(mode,kaffeine_playlist)
Toggle Fullscreen=Exec(dcop kaffeine KaffeineIface fullscreen);
Close and exit=Macro(Cancel);

[ModeEnd]

[Mode]=kaffeine_pause

Back=\
	Set(text,close);\
	Set(menu,replace,Playlist,Toggle Fullscreen);\
	Macro(ALLIN1MENU)

(EnterMode)=\
	Set(status,Paused);Timer(KAFFEINE_SETTITLE,cancel);

0=Exec(dcop kaffeine KaffeineIface pause);Set(status,Playing);Make(mode,kaffeine);Macro(KAFFEINE_SETTITLE);Timer(KAFFEINE_SETTITLE,10,0);
5=Exec(dcop kaffeine KaffeineIface play;dcop kaffeine KaffeineIface fullscreen);\
	Make(mode,kaffeine);\
	Set(status,Playing);\
	ExecAndSet(title,basename "`dcop kaffeine KaffeineIface getFileName`")

* *=Set(text,replace,Help,1 Vol-  2 Mute  3 Vol+\n4 Rew   5 Play  6 FF\n7 Prew  8 Stop  9 Next\n* Help  0 Pause # Exit\n* # - Run/Quit)

[ModeEnd]

[Mode]=kaffeine_playlist

(EnterMode)=\
	Timer(KAFFEINE_SETTITLE,cancel);\
	Set(list,font,medium);\
	ExecAndSet(list,replace,Playlist,grep url $HOME/.kde/share/apps/kaffeine/playlists/`grep Playlists $HOME/.kde/share/config/kaffeinerc|head -1|sed 's/Playlists=//'`.kaffeine|sed 's/<entry.*url=\"\(.*\)\" album\(.\)*$/\1/'|xargs -i basename {}|sed 's/$/,/');\
	Set(menu,add,Choose);

(ExitMode)=\
	Set(list,close);\
	Set(status,Playing);\
	Set(menu,replace,Playlist,Toggle Fullscreen,Close and exit);\
	ExecAndSet(title,basename `dcop kaffeine KaffeineIface getFileName`);\
	Macro(KAFFEINE_SETTITLE);\
	Timer(KAFFEINE_SETTITLE,10,0);

Back($$)=Make(mode,kaffeine);
Choose($$)=Exec(dcop kaffeine KaffeineIface setNumber `expr $(Index)`);
Push($$)=Macro(Choose($$));

[ModeEnd]

[End]
