%
% anyremote configuration file for  Rhythmbox. (AT-mode)
%

% STATUS stable
% XTEST no
% SOUND app
% ENV no
% DEF_PLAYER   

% 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`; if [ "x$A" == "x" ]; then echo NOK; else echo OK; fi'|bash -f -s
GuiAppIcon=rhythmbox.png
GuiAppType=Application
GuiAppProtocols=AT
GuiAppDesc=Rhythmbox - The music management application for GNOME

[Protocol]=AT

(Init)=\
	Include($(CfgDir)/Utils/aliases-at.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
	Make(var,TwoWayComm,by_value,false);\
	Macro(CHECK_RFCOMM_DEVICE);

(Connect)=Make(mode,rhythmbox);

[Mode]=rhythmbox : default_player_at
		
RUN_IF_NEED=Exec(ID=`id -u`;P=`ps -fu $ID|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=`ps -fu $ID|grep rhythmbox|grep -v grep|grep -v anyremote|grep -v edit`; 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=Exec(dbus-send --type=method_call --dest=org.gnome.Rhythmbox /org/gnome/Rhythmbox/Shell org.gnome.Rhythmbox.Shell.quit);

PLAY=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause);
PREV=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous);
NEXT=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next);
STOP=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop);
PAUSE=Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause);

% override
* *=Macro(DEFAULT_HELP_NO_FF_RWD);

% https://bugs.launchpad.net/ubuntu/+source/rhythmbox/+bug/875064 rhythmbox-client is missing
%(InCall) =Exec(rhythmbox-client --no-start --play-pause;kdialog --msgbox "$(CallId)");Make(remote,off);
%(EndCall)=Make(remote,on);Exec(rhythmbox-client --no-start  --play-pause)
%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');ts=player.getElapsed();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');ts=player.getElapsed();player.setVolumeRelative(.10)")
%1=Exec(rhythmbox-client --no-start --volume-down)
%2=Exec(echo 'M=`rhythmbox-client --no-start --print-volume|grep muted|wc -l`;if [ "x$M" == "x0" ]; then rhythmbox-client --no-start --mute; else rhythmbox-client --no-start --unmute; fi'|bash -f -s);
%3=Exec(rhythmbox-client --no-start --volume-up)
%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)")
%5=Exec(rhythmbox-client --no-start --play-pause);
%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)")
%7=Exec(rhythmbox-client --no-start --previous);
%8=Exec(rhythmbox-client --no-start --play-pause)
%9=Exec(rhythmbox-client --no-start --next);
%* #=Exec(P=`ps -ef|grep rhythmbox|grep -v grep|grep -v anyremote`; if [ "x$P" = "x" ]; then rhythmbox & else rhythmbox-client --no-start --quit; fi)
%0=Exec(rhythmbox-client --no-start --play-pause)
%#=Exec(rhythmbox-client --no-start --quit)

[ModeEnd]

[End]
