%
% anyremote configuration file for rhythmbox. (Server-mode)
%

% STATUS stable
% XTEST no
% SOUND mixer
% ENV no
% DEF_PLAYER
% ALL_IN_ONE 
% MEDIACENTER audio

GuiAppName=Rhythmbox
GuiAppBinary=rhythmbox
GuiAppRun= A=`ps -ef|grep rhythmbox|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi
GuiAppIcon=rhythmbox.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Rhythmbox - The music management application for GNOME

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
	Macro(TEST_DBUS_SEND);\
	Make(var,player_name,by_value,Rhythmbox);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,cover_size,by_value,);\
	Make(var,rhythmbox_exec,by_value,\
	     dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2);\
	Make(var,rhythmbox_get,by_value,\
	     dbus-send --print-reply --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player);\
	Make(var,rhythmbox_set,by_value,\
	      dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Set string:org.mpris.MediaPlayer2.Player);\
	Make(var,rhythmbox_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get rhythmbox_layout`;\
	     if [ "x$V" = "x" ]; then echo "5x1"; else echo $V; fi);

(Exit)=\
	Exec($(CfgDir)/Utils/registry.sh $(TmpDir) set rhythmbox_layout $(rhythmbox_layout));

(Connect)=\
	Make(mode,rhythmbox_$(rhythmbox_layout));

[Mode]=rhythmbox_general

APP_QUIT=\
	Timer(RHYTHMBOX_TITLE,cancel);\
	Exec($(rhythmbox_exec) org.mpris.MediaPlayer2.Quit);

RUN_IF_NEED=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh rhythmbox);
	
RUN_OR_QUIT=\
	Macro(RHYTHMBOX_TIMER_CANCEL);\
	Make(var,whoami,id -u);\
	Exec(P=`pgrep -u $(whoami) rhythmbox`; \
	     if [ "x$P" = "x" ]; then rhythmbox & \
	     else $(rhythmbox_exec) org.mpris.MediaPlayer2.Quit; fi)

PREV=\
	Exec($(rhythmbox_exec) org.mpris.MediaPlayer2.Player.Previous);\
	Macro(RHYTHMBOX_TITLE);

PLAY_ONLY=\
	Exec($(rhythmbox_exec) org.mpris.MediaPlayer2.Player.PlayPause);

PLAY=\
	Macro(PLAY_ONLY);\
	Macro(RHYTHMBOX_TIMER_START);
	
NEXT=\
	Exec($(rhythmbox_exec) org.mpris.MediaPlayer2.Player.Next);\
	Macro(RHYTHMBOX_TITLE);

RWD=\
	Exec($(rhythmbox_exec) org.mpris.MediaPlayer2.Player.Seek int64:-5000000);

FF=\
	Exec($(rhythmbox_exec) org.mpris.MediaPlayer2.Player.Seek int64:5000000);
	
PAUSE=\
	Exec($(rhythmbox_exec) org.mpris.MediaPlayer2.Player.Pause);

STOP=\
	Macro(RHYTHMBOX_TIMER_CANCEL);\
	Exec($(rhythmbox_exec) org.mpris.MediaPlayer2.Player.Stop);

RHYTHMBOX_CHECK_TIMER=\
	Make(var,rhythmbox_status,\
	     $(rhythmbox_get) string:PlaybackStatus|tail -1|grep string|cut -d '"' -f 2);\
	Make(var,timer_action,if [ "x$(rhythmbox_status)" = "xPlaying" ]; \
	                      then echo RHYTHMBOX_TIMER_START; else echo RHYTHMBOX_TIMER_CANCEL; fi);\
	Macro($(timer_action));

RHYTHMBOX_TIMER_START=\
	Macro(RHYTHMBOX_TITLE);\
	Timer(RHYTHMBOX_TITLE,$(UpdateTimeout),0);

RHYTHMBOX_TIMER_CANCEL=\
	Timer(RHYTHMBOX_TITLE,cancel);\
	Set(title,);\
	Set(status,);

APP_PLAY_STATUS=\
	Make(var,rhythmbox_status,\
	     $(rhythmbox_get) string:PlaybackStatus|tail -1|grep string|cut -d '"' -f 2);\
	Make(var,app_status,if [ "x$(rhythmbox_status)" = "xPlaying" ]; then echo playing; else echo paused; fi);

Repeat=\
	Exec(P=`$(rhythmbox_get) string:LoopStatus|tail -1|grep string|cut -d '"' -f 2`; \
		if [ "x$P" = "xNone" ]; \
		then \
		    $(rhythmbox_set) string:LoopStatus variant:string:Playlist & \
		else \
		    $(rhythmbox_set) string:LoopStatus variant:string:None & \
		fi);

RHYTHMBOX_TITLE_GENERAL=\
	Make(var,alb,$(rhythmbox_get) string:Metadata|awk '/.*xesam.album".*/{getline;print}'|grep string|cut -f 2 -d '"');\
	Make(var,tit,$(rhythmbox_get) string:Metadata|awk '/.*xesam.title.*/{getline;print}'|grep string|cut -f 2 -d '"');\
	Make(var,art,$(rhythmbox_get) string:Metadata|awk '/.*xesam.albumArtist.*/{getline;getline;print}'|grep string|cut -f 2 -d '"');\
	Set(title,$(alb) - $(tit));\
	Set(status,$(art));

Layout 3x4=\
	Make(mode,rhythmbox_3x4);
	
Layout 7x1=\
	Make(mode,rhythmbox_7x1);

Layout 5x1=\
	Make(mode,rhythmbox_5x1);
	
[ModeEnd]

[Mode]=rhythmbox_3x4 : rhythmbox_general, default_player

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

APP_POST_SETUP=\
	Make(var,rhythmbox_layout,by_value,3x4);\
	Macro(RHYTHMBOX_CHECK_TIMER);

APP_MENU=\
	Set(menu,replace,Repeat,Layout 5x1,Layout 7x1,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

RHYTHMBOX_TITLE=\
	Macro(RHYTHMBOX_TITLE_GENERAL);

[ModeEnd]

[Mode]=rhythmbox_cover

RHYTHMBOX_TITLE=\
	Macro(RHYTHMBOX_TITLE_GENERAL);\
	Macro(APP_COVER);
 
APP_COVER=\
	Make(var,media_file,\
	     $(rhythmbox_get) string:Metadata|awk '/.*mpris.artUrl.*/{getline;print}'|cut -f 2 -d '"'|cut -f 2 -d ':'|sed 's/"$//;s/^\/\/\//\//');\
	Macro(DEFAULT_METADATA_COVER);

[ModeEnd]

[Mode]=rhythmbox_7x1 : rhythmbox_general, rhythmbox_cover, default_player_7x1

APP_MENU=\
	Set(menu,replace,Repeat,Mute,Layout 3x4,Layout 5x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,rhythmbox_layout,by_value,7x1);\
	Macro(RHYTHMBOX_CHECK_TIMER);

[ModeEnd]

[Mode]=rhythmbox_5x1 : rhythmbox_general, rhythmbox_cover, default_player_5x1

APP_MENU=\
	Set(menu,replace,Repeat,Mute,Layout 3x4,Layout 7x1,Help,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,rhythmbox_layout,by_value,5x1);

APP_TITLE=\
	Macro(RHYTHMBOX_TITLE);

PLAY=\
	Macro(PLAY_ONLY);

[ModeEnd]

[End]
