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

% STATUS stable
% XTEST no
% SOUND mixer
% ENV no
% ALL_IN_ONE 

% https://bugs.launchpad.net/ubuntu/+source/rhythmbox/+bug/875064 rhythmbox-client is missing

GuiAppName=Rhythmbox
GuiAppBinary=rhythmbox
GuiAppRun=echo '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'|bash -f -s
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);

(Connect)=Make(mode,rhythmbox);

%RHYTHMBOX_SETTITLE=ExecAndSet(title,rhythmbox-client --print-playing --no-start);
RHYTHMBOX_SETTITLE=ExecAndSet(title,qdbus org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata|grep title|cut -f 3 -d ':');

[Mode]=rhythmbox

(EnterMode)=Exec(echo 'P=`ps -ef|grep rhythmbox|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" == "x" ]; then rhythmbox & fi' |bash -f -s);\
	Set(layout,default);\
	Set(icons,Rhythmbox,1,vol_down,2,mute,3,vol_up,4,rewind,5,play,6,forward,7,prev,8,stop,9,next,*,question,0,pause,#,no);\
	Macro(APP_MENU);

%	Set(font,small);\
%	Macro(DBUS_TEST_RHB,if [ "x$(Dbus)" = "xyes" ]; then echo 0; else echo 1; fi);
%DBUS_TEST_RHB=Make(mode,rhythmbox_dbus);

APP_MENU=\
	Set(menu,replace,);\
	Macro(ALLIN1MENU)

RHYTHMBOX_QUIT=\
	Timer(RHYTHMBOX_SETTITLE,cancel);\
	Exec(dbus-send --type=method_call --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Shell org.gnome.Rhythmbox.Shell.quit);

RHYTHMBOX_RUN_OR_QUIT=\
	Make(var,whoami,id -u);Exec(P=`pgrep -u $(whoami) rhythmbox`; if [ "x$P" = "x" ]; then rhythmbox & else dbus-send --type=method_call --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Shell org.gnome.Rhythmbox.Shell.quit; fi)
	
Cancel=Macro(RHYTHMBOX_QUIT);Exit

Back=Set(text,close);Macro(APP_MENU)

% https://bugs.launchpad.net/ubuntu/+source/rhythmbox/+bug/875064 rhythmbox-client is missing
%1=Exec(python -c "import dbus;import sys;import os;session_bus = dbus.SessionBus();pp = session_bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player');player = dbus.Interface(pp, 'org.gnome.Rhythmbox.Player');player.setVolumeRelative(-.10)")
%3=Exec(python -c "import dbus;import sys;import os;session_bus = dbus.SessionBus();pp = session_bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player');player = dbus.Interface(pp, 'org.gnome.Rhythmbox.Player');player.setVolumeRelative(.10)")
%1=Exec(rhythmbox-client --volume-down --no-start)
%2=Exec(echo 'M=`LANG=C;rhythmbox-client --print-volume --no-start|grep "muted"|wc -l`;if [ "x$M" == "x0" ]; then rhythmbox-client --mute --no-start; else rhythmbox-client --unmute --no-start; fi'|bash -f -s);
%3=Exec(rhythmbox-client --volume-up --no-start)
%4=Exec(python -c "import dbus;import sys;import os;session_bus = dbus.SessionBus();pp = session_bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player');player = dbus.Interface(pp, 'org.gnome.Rhythmbox.Player');ts=player.getElapsed()-10;player.setElapsed(ts)")
%6=Exec(python -c "import dbus;import sys;import os;session_bus = dbus.SessionBus();pp = session_bus.get_object('org.gnome.Rhythmbox', '/org/gnome/Rhythmbox/Player');player = dbus.Interface(pp, 'org.gnome.Rhythmbox.Player');ts=player.getElapsed()+10;player.setElapsed(ts)")

1=Macro(DEFAULT_VOLUME_DOWN)
2=Macro(DEFAULT_TOGGLE_MUTE)
3=Macro(DEFAULT_VOLUME_UP)

4=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous);\
	Macro(RHYTHMBOX_SETTITLE);

5=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause);\
	Macro(RHYTHMBOX_SETTITLE);\
	Timer(RHYTHMBOX_SETTITLE,5,0);
	
6=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next);\
	Macro(RHYTHMBOX_SETTITLE);

7=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous);\
	Macro(RHYTHMBOX_SETTITLE);
8=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause);
9=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next);\
	Macro(RHYTHMBOX_SETTITLE);

* *=Set(text,replace,Help,1 Vol-\n2 Mute\n3 Vol+\n4 Prev\n5 Play\n6 Next\n7 Prew\n8 Stop\n9 Next\n** Help\n0 Pause\n # Quit\n* # - Run/Quit)
* #=Macro(RHYTHMBOX_RUN_OR_QUIT);
0=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop);
#=Macro(RHYTHMBOX_QUIT);

[ModeEnd]

[Mode]=rhythmbox_dbus : default_player

% (EnterMode) by Utils/aliases-server-player.cfg
	
APP_POST_SETUP=\
	Dbus(connect,rb,org.gnome.Rhythmbox,/org/gnome/Rhythmbox/Player,org.gnome.Rhythmbox.Player);\
	Dbus(connect,rb2,org.gnome.Rhythmbox,/org/gnome/Rhythmbox/Shell,org.gnome.Rhythmbox.Shell);\
	Dbus(signal,rb,playingUriChanged,string,RHYTHMBOX_SETTITLE);

% use defaults
%1=Dbus(set,rb,setVolumeRelative,double,-0.1)
%2=Exec(echo 'M=`LANG=C;rhythmbox-client --print-volume --no-start|grep "muted"|wc -l`;if [ "x$M" == "x0" ]; then rhythmbox-client --mute --no-start; else rhythmbox-client --unmute --no-start; fi'|bash -f -s);
%3=Dbus(set,rb,setVolumeRelative,double,0.1)

PLAY=Dbus(set,rb,playPause,bool,true);\
	Macro(RHYTHMBOX_SETTITLE);
RWD=Dbus(get,rb,getElapsed,uint,elapsed);\
	Make(var,elapsed,echo "$(elapsed)-10"|bc);\
	Dbus(set,rb,setElapsed,uint,$(elapsed));
FF=Dbus(get,rb,getElapsed,uint,elapsed);\
	Make(var,elapsed,echo "$(elapsed)+10"|bc);\
	Dbus(set,rb,setElapsed,uint,$(elapsed));
PREV=Dbus(set,rb,previous);\
	Macro(RHYTHMBOX_SETTITLE);
NEXT=Dbus(set,rb,next);\
	Macro(RHYTHMBOX_SETTITLE);
PAUSE=Dbus(set,rb,playPause,bool,true);
STOP=Dbus(set,rb,playPause,bool,true);

RUN_IF_NEED=\
	Exec(P=`ps -ef|grep rhythmbox|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" == "x" ]; then rhythmbox & fi);

RUN_OR_QUIT=\
	Exec(ID=`id -u`;P=`pgrep -u $ID rhythmbox`; if [ "x$P" = "x" ]; then rhythmbox & else dbus-send --type=method_call --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Shell org.gnome.Rhythmbox.Shell.quit; fi)

QUIT=Dbus(set,rb2,quit);

[ModeEnd]

[End]
