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

% STATUS stable
% XTEST no
% SOUND mixer
% ENV no
% DEF_PLAYER   
% ALL_IN_ONE
% MEDIACENTER audio
% TODO It looks like listen does not process next/previous D-BUS commands properly

GuiAppName=Listen
GuiAppBinary=listen
GuiAppRun=P=`pgrep listen`; if [ "x$P" = "x" ]; then echo NOK; else echo OK; fi
GuiAppIcon=listen.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Listen is an audio player written in Python

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
	Macro(TEST_DBUS_SEND);\
	Make(var,player_name,by_value,Listen);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,cover_size,by_value,);\
	Make(var,listen_cmd,by_value,dbus-send --type=method_call --dest=org.gnome.Listen /org/gnome/listen);\
	Make(var,listen_retcmd,by_value,dbus-send --type=method_call --print-reply --dest=org.gnome.Listen /org/gnome/listen);\
	Make(var,listen_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get listen_layout`;\
	     if [ "x$V" = "x" ]; then echo "3x4"; else echo $V; fi);

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

(Connect)=\
	Make(mode,listen_$(listen_layout));

[Mode]=listen_general

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

PLAY=\
	Exec($(listen_cmd) org.gnome.Listen.play_pause);\
	Macro(LISTEN_SETTITLE);\
	Timer(LISTEN_SETTITLE,$(UpdateTimeout),0);

RWD=\
	Exec($(listen_cmd) org.gnome.Listen.rewind);
	
FF=\
	Exec($(listen_cmd) org.gnome.Listen.forward);
	
PREV=\
	Exec($(listen_cmd) org.gnome.Listen.previous);\
	Macro(LISTEN_SETTITLE);

STOP=\
	Timer(LISTEN_SETTITLE,cancel);\
	Exec($(listen_cmd) org.gnome.Listen.play_pause);

NEXT=\
	Exec($(listen_cmd) org.gnome.Listen.next);\
	Macro(LISTEN_SETTITLE);

PAUSE=\
	Exec($(listen_cmd) org.gnome.Listen.play_pause);\
	Timer(LISTEN_SETTITLE,cancel)

RUN_IF_NEED=\
	Exec(P=`pgrep listen`; if [ "x$P" = "x" ]; then listen > /dev/null & fi);

RUN_OR_QUIT=\
	Exec(P=`pgrep listen`; \
	     if [ "x$P" = "x" ]; then \
	         listen > /dev/null & \
	     else \
	         $(listen_cmd) org.gnome.Listen.quit; \
	     fi);

APP_QUIT=\
	Timer(LISTEN_SETTITLE,cancel);\
	Exec($(listen_cmd) org.gnome.Listen.quit);

% LISTEN_DO_SETTITLE must be defined in child modes
LISTEN_SETTITLE=\
	Macro(LISTEN_DO_SETTITLE,P=`pgrep listen`; if [ "x$P" = "x" ]; then echo 1; else echo 0; fi); 

LISTEN_TITLE_GENERAL=\
	Make(var,listen_album,$(listen_retcmd) org.gnome.Listen.get_album|tail -1|grep string|cut -d '"' -f 2);\
	Make(var,listen_song,$(listen_retcmd) org.gnome.Listen.get_title|tail -1|grep string|cut -d '"' -f 2);\
	ExecAndSet(title,echo "$(listen_album) - $(listen_song)");\
	ExecAndSet(status,$(listen_retcmd) org.gnome.Listen.get_artist|tail -1|grep string|cut -d '"' -f 2);

APP_PLAY_STATUS=\
	Make(var,listen_status,$(listen_retcmd) org.gnome.Listen.playing|tail -1|grep boolean|tr -s ' '|cut -f3 -d ' ');\
	Make(var,app_status,if [ "x$(listen_status)" = "xtrue" ]; then echo playing; else echo paused; fi);

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

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

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

[Mode]=listen_3x4 : listen_general, default_player

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

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

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

LISTEN_DO_SETTITLE=\
	Macro(LISTEN_TITLE_GENERAL);

[ModeEnd]

[Mode]=listen_cover

LISTEN_DO_SETTITLE=\
	Macro(LISTEN_TITLE_GENERAL);\
	Macro(APP_COVER, if [ "x$(cover_size)" = "x" ]; then echo 1; else echo 0; fi);

APP_COVER=\
	Make(var,media_file, $(listen_retcmd) org.gnome.Listen.get_cover_path|tail -1|grep string|cut -d '"' -f 2);\
	Macro(DEFAULT_METADATA_COVER);

[ModeEnd]

[Mode]=listen_7x1 : listen_general, default_player_7x1, listen_cover

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

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

[ModeEnd]

[Mode]=listen_5x1 : listen_general, default_player_5x1, listen_cover

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

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

APP_TITLE=\
	Macro(LISTEN_SETTITLE);

PLAY=\
	Exec($(listen_cmd) org.gnome.Listen.play_pause);

[ModeEnd]

[End]
