%
% anyremote configuration file for Juk/KDE4 management (Server-mode)
%
% Thanks to Calve (calvinh34 at gmail.com) for enhancing this configuration file
%

% STATUS stable
% XTEST no
% SOUND app
% ENV no
% IPC DBUS
% DEF_PLAYER
% ALL_IN_ONE 
% TODO Volume control by Juk is a bit buggy: no min/max values check inside Juk

GuiAppName=Juk/KDE4
GuiAppBinary=juk
GuiAppVersion=echo 'V=`juk -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 juk`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=juk.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=JuK is a free software audio player for KDE, part of the kdemultimedia package. JuK supports collections of MP3, Ogg Vorbis, and FLAC audio files. This configuration file is for Juk/KDE4.

[Protocol]=Server

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

(Connect)=\
	Make(mode,juk);
	
[Mode]=juk : default_player

% (EnterMode) by Utils/aliases-server-player.cfg

(ExitMode)=\
	Timer(JUK_SETTITLE,cancel);

JUK_SETTITLE=\
	ExecAndSet(title,qdbus org.kde.juk /Player playingString|sed 's/<i>//;s/<\/i>//')

JUK_VOLUME=\
	ExecAndSet(status,echo `qdbus org.kde.juk /Player volume`|awk '{min=int($0*100);print min;}');
	
APP_MENU=\
	Set(menu,replace,Search,Random,Power Off,Suspend);\
	Macro(ALLIN1MENU);
	
% Power Off, Suspend by Utils/aliases-server-player.cfg

Search=\
	Make(mode,juk_search);

Random=\
	Exec(P=`qdbus org.kde.juk /Player org.kde.juk.player.randomPlayMode`;if [ "x$P" = "xRandom" ]; then qdbus org.kde.juk /Player org.kde.juk.player.setRandomPlayMode NoRandom; else qdbus org.kde.juk /Player org.kde.juk.player.setRandomPlayMode Random;fi);

% Custom volume control
1=Exec(dbus-send --type=method_call --dest=org.kde.juk /Player org.kde.juk.player.volumeDown);Macro(JUK_VOLUME);
2=Exec(dbus-send --type=method_call --dest=org.kde.juk /Player org.kde.juk.player.mute);
3=Exec(dbus-send --type=method_call --dest=org.kde.juk /Player org.kde.juk.player.volumeUp);Macro(JUK_VOLUME);

% 0,4-9,*,# assignments by Utils/aliases-server-player.cfg
PLAY =Exec(qdbus org.kde.juk /Player org.kde.juk.player.playPause);Macro(JUK_SETTITLE);Timer(JUK_SETTITLE,5,0)
RWD  =Exec(qdbus org.kde.juk /Player org.kde.juk.player.seekBack);
FF   =Exec(qdbus org.kde.juk /Player org.kde.juk.player.seekForward);
PREV =Exec(qdbus org.kde.juk /Player org.kde.juk.player.back);Macro(JUK_SETTITLE);
STOP =Exec(qdbus org.kde.juk /Player org.kde.juk.player.stop);Timer(JUK_SETTITLE,cancel)
NEXT =Exec(qdbus org.kde.juk /Player org.kde.juk.player.forward);Macro(JUK_SETTITLE);
PAUSE=Exec(qdbus org.kde.juk /Player org.kde.juk.player.pause);

RUN_IF_NEED=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh juk);
	
RUN_OR_QUIT=\
	Exec(P=`pgrep juk`; if [ "x$P" = "x" ]; then juk; else dbus-send --type=method_call --dest=org.kde.juk /MainApplication org.kde.KApplication.quit; fi);

QUIT=\
	Exec(dbus-send --type=method_call --dest=org.kde.juk /MainApplication org.kde.KApplication.quit);\
	Timer(JUK_SETTITLE,cancel);

% Found no way to choose track
%Playlist=\
%	Make(var,juk_playlist,qdbus org.kde.juk /Collection org.kde.juk.collection.playingPlaylist);\
%  	ExecAndSet(list,replace,Playlist,qdbus org.kde.juk /Collection org.kde.juk.collection.playlistTracks $(juk_playlist)|sed "s/'//"|xargs -i basename {}|sed "s/$/,/");\
%  	ExecAndSet(list,select,expr 1 + `......`);\
%	Set(menu,replace,Choose);
%	
%Push($$)=\
%	Macro(Choose($$))
%	
%Choose($$)=\
%	Exec(.... `expr $(Index) - 1`);

[ModeEnd]

[Mode]=juk_search

(EnterMode)=\
	Make(var,searchval,qdbus org.kde.juk /Search org.kde.juk.search.searchText);\
	ExecAndSet(editfield,echo "Search...,Search,$(searchval)");

(ExitMode)=\
	Macro(JUK_SETTITLE);\
	Timer(JUK_SETTITLE,0,5);

Ok($$)=\
	Set(text,close);\
	Exec(qdbus org.kde.juk /Search org.kde.juk.search.setSearchText "$(Param)" );\
	Set(vibrate);\
	Make(mode,juk);
	
Back($$)=Make(mode,juk);

Back=Make(mode,juk);

[ModeEnd]

[End]
