%
% anyremote configuration file for Banshee management (Server-mode)
% prerequisites: amixer/pactl utility
%

% STATUS stable
% XTEST no
% SOUND mixer
% ENV no
% TODO FF/RWD do not works
% DEF_PLAYER   
% ALL_IN_ONE 
% MEDIACENTER audio

GuiAppName=Banshee
GuiAppBinary=echo 'B=`which banshee 2> /dev/null`;if [ "x$B" = "x" ]; then echo banshee-1; else echo banshee; fi'|sh -s
GuiAppRun=echo 'P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`; if [ "x$P" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=media-player-banshee.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Music management and playback for Gnome

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(TEST_DBUS_SEND);\
	Macro(SETUP_DEFAULT_MIXER);\
	Make(var,banshee_exec,which banshee 2> /dev/null);\
	Make(var,banshee_exec,if [ "x$(banshee_exec)" = "x" ]; then which banshee-1; else echo $(banshee_exec); fi);\
	Make(var,player_name,by_value,Banshee);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,cover_size,by_value,);\
	Make(var,banshee_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get banshee_layout`;\
	     if [ "x$V" = "x" ]; then echo "5x1"; else echo $V; fi);

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

(Connect)=\
	Make(mode,banshee_$(banshee_layout));

[Mode]= banshee_general

% BANSHEE_SETTITLE must be defined in child modes

BANSHEE_DELTIMER=\
	Set(title, );\
	Set(status, );\
	Timer(BANSHEE_SETTITLE,cancel);
	
BANSHEE_SETTITLE_GENERAL=\
	Macro(BANSHEE_DO_SETTITLE_GENERAL,\
	      B=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`;\
	      if [ "x$B" != "x" ]; then echo 0; else echo 1; fi);

BANSHEE_DO_SETTITLE_GENERAL=\
	Make(var,banshee_title,$(banshee_exec) --query-title|cut -f 2 -d ":");\
	Make(var,banshee_album,$(banshee_exec) --query-album|cut -f 2 -d ":");\
	Make(var,banshee_artist,$(banshee_exec) --query-artist|cut -f 2 -d ":");\
	Set(title,$(banshee_album) - $(banshee_title));\
	Set(status,$(banshee_artist));
	
BANSHEE_CMD=\
	Exec(P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`;\
	     if [ "x$P" != "x" ]; then $(banshee_cmd); fi);

BANSHEE_POS=\
	Make(var,banshee_pos,banshee --query-position|cut -f 2 -d ' '|cut -f 1 -d ',');

% Volume control and 0-9,*,# assignments by Utils/aliases-server-player.cfg

PLAY=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --toggle-playing);\
	Macro(BANSHEE_CMD);\
	Macro(BANSHEE_SETTITLE);\
	Timer(BANSHEE_SETTITLE,$(UpdateTimeout),0);

RWD=\
	Macro(BANSHEE_POS);\
	Make(var,banshee_pos,echo "$(banshee_pos) - 10"|bc);\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --set-position=$(banshee_pos));\
	Macro(BANSHEE_CMD);

FF=\
	Macro(BANSHEE_POS);\
	Make(var,banshee_pos,echo "$(banshee_pos) + 10"|bc);\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --set-position=$(banshee_pos));\
	Macro(BANSHEE_CMD);
	
PREV=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --previous);\
	Macro(BANSHEE_CMD);\
	Macro(BANSHEE_SETTITLE);
	
STOP=\
	Macro(BANSHEE_DELTIMER);\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --pause);\
	Macro(BANSHEE_CMD);\
	Set(title,);\
	Set(status,);

NEXT=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --next);\
	Macro(BANSHEE_CMD);\
	Macro(BANSHEE_SETTITLE);
	
PAUSE=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --pause);\
	Macro(BANSHEE_CMD);\
	Macro(BANSHEE_DELTIMER);

Shuffle=\	
	Exec(dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.banshee /org/mpris/MediaPlayer2  org.mpris.MediaPlayer2.Player.Shuffle);

RUN_IF_NEED=\
	Exec(P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`;\
	     if [ "x$P" = "x" ]; then $(banshee_exec) > /dev/null & fi);\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh -switch banshee);
	
RUN_OR_QUIT=\
	Macro(BANSHEE_DELTIMER);\
	Exec(P=`ps -ef|grep banshee|grep -v grep|grep -v anyremote|grep -v edit`;\
	     if [ "x$P" = "x" ]; then $(banshee_exec) > /dev/null & else killall -r "banshee.*"; fi);
	
APP_QUIT=\
	Macro(BANSHEE_DELTIMER);\
	Exec(killall -r "banshee.*");

APP_PLAY_STATUS=\
	Make(var,banshee_status,banshee --query-current-state|grep playing|wc -l);\
	Make(var,app_status,if [ "x$(banshee_status)" = "x0" ]; then echo paused; else echo playing; fi);

Layout 3x4=\
	Make(mode,banshee_3x4);

Layout 7x1=\
	Make(mode,banshee_7x1);

Layout 5x1=\
	Make(mode,banshee_5x1);

[ModeEnd]

[Mode]= banshee_3x4: banshee_general,default_player

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

BANSHEE_SETTITLE=\
	Macro(BANSHEE_SETTITLE_GENERAL);

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

APP_POST_SETUP=\
	Make(var,banshee_layout,by_value,3x4);

% PowerMgmt by Utils/aliases-server.cfg
	
	
[ModeEnd]

[Mode]= banshee_cover

BANSHEE_SETTITLE=\
	Macro(BANSHEE_SETTITLE_GENERAL);\
	Macro(APP_COVER);

% too simple
%	Make(var,media_file,banshee --query-uri|sed "s/^uri: file:\/\///;s/'/'\\\''/g;s/\//\'\/\'/g;s/$/\'/g;s/^'\//\//");\
%

APP_COVER=\
	Make(var,coverencode,banshee --query-uri|sed "s/^uri: file:\/\///");\
	Make(var,coverdecode,echo 'arg="$(coverencode)";i="0";\
	                    while [ "$i" -lt ${#arg} ]; do c0=${arg:$i:1}; \
			        if [ "x$c0" = "x%" ]; then c1=${arg:$((i+1)):1}; c2=${arg:$((i+2)):1}; printf "\x$c1$c2"; i=$((i+3)); \
				else echo -n "$c0"; i=$((i+1)); fi \
			    done'|bash -s);\
	Make(var,media_file,echo $(coverdecode)|sed "s/'/'\\\''/g;s/\//\'\/\'/g;s/$/\'/g;s/^'\//\//")\;\
	Macro(DEFAULT_COVER);

[ModeEnd]

[Mode]= banshee_7x1: banshee_general,default_player_7x1,banshee_cover

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

APP_MENU=\
	Set(menu,replace,Mute,Shuffle,Next Cover,Previous Cover,Update Cover,Layout 3x4,Layout 5x1,Help,Run/Quit,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

APP_POST_SETUP=\
	Make(var,banshee_layout,by_value,7x1);

% PowerMgmt by Utils/aliases-server.cfg
		
[ModeEnd]

[Mode]= banshee_5x1: banshee_general,default_player_5x1,banshee_cover

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

PLAY=\
	Make(var,banshee_cmd,by_value,$(banshee_exec) --toggle-playing);\
	Macro(BANSHEE_CMD);

APP_MENU=\
	Set(menu,replace,Mute,Shuffle,Next Cover,Previous Cover,Update Cover,Layout 3x4,Layout 7x1,Help,Run/Quit,PowerMgmt);\
	Macro(ALLIN1MENU);\
	Macro(MEDIACENTER_MENU);

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

APP_TITLE=\
	Macro(BANSHEE_SETTITLE);

% PowerMgmt by Utils/aliases-server.cfg
		
[ModeEnd]

%gdbus introspect --session --dest org.mpris.MediaPlayer2.banshee --object-path /org/mpris/MediaPlayer2
%qdbus org.mpris.MediaPlayer2.banshee /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Shuffle
%dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.banshee /org/mpris/MediaPlayer2  org.mpris.MediaPlayer2.Player.Next	
%qdbus org.mpris.MediaPlayer2.banshee /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata
%gdbus call --session --dest org.mpris.MediaPlayer2.banshee --object-path /org/mpris/MediaPlayer2 --method org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata
%dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.banshee --print-reply /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata

[End]
