%
% anyremote configuration file for tomahawk (http://www.tomahawk-player.org/) (Server-mode)
%

% STATUS non-stable
% XTEST no
% SOUND mixer
% ENV no
% DEF_PLAYER
% ALL_IN_ONE
% TODO https://bugs.tomahawk-player.org/browse/TWK-1161
%      Initial playlist creation
%      Shuffle do not works with playing queue

GuiAppName=Tomahawk
GuiAppBinary=tomahawk
GuiAppVersion=
GuiAppRun=echo 'A=`pgrep tomahawk`; if [ "x$A" = "x" ]; then echo NOK; else echo OK; fi'|sh -s
GuiAppIcon=tomahawk.png
GuiAppType=Application
GuiAppProtocols=Server
GuiAppDesc=Tomahawk is a music player that fundamentally changes the way music is consumed and shared. It decouples the name of the song from the source it was shared from - and fulfills the request using all of your available sources.

[Protocol]=Server

(Init)=\
	Include($(CfgDir)/Utils/aliases-server.cfg);\
	Macro(SETUP_DEFAULT_MIXER);\
	Macro(TEST_QDBUS);\
	Make(var,player_name,by_value,Tomahawk);\
	Include($(CfgDir)/Utils/aliases-server-player.cfg);\
	Make(var,cover_size,by_value,);\
	Make(var,tomahahk_dbus,if [ "x$(Dbus)" = "xyes" ]; then echo DBUS; else echo NODBUS; fi);\
	Make(var,tomahahk_layout,\
	     V=`$(CfgDir)/Utils/registry.sh $(TmpDir) get tomahahk_layout`;\
	     if [ "x$V" = "x" ]; then echo "5x1"; else echo $V; fi);

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

(Connect)=\
	Make(mode,tomahahk_$(tomahahk_layout));

(Disconnect)=\
	Timer(TOMAHAWK_TITLE,cancel);

[Mode]=tomahahk_general

TOMAHAWK_TITLE_GENERAL=\
	Make(var,alb,qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata|grep xesam:album:|sed 's/xesam:album: //');\
	Make(var,art,qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata|grep xesam:artist:|sed 's/xesam:artist: //');\
	Make(var,tit,qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata|grep xesam:title:|sed 's/xesam:title: //');\
	Set(title,$(alb) - $(tit));\
	Set(status,$(art));

TOMAHAWK_SET_VOL=\
	Make(var,dummy,sleep 1;echo 0);\
	Macro(DEFAULT_VOLUME_GET);\
	Set(volume,$(default_mixer_value));

% TOMAHAWK_TITLE should be defined in child modes

TOMAHAWK_TIMER=\
	Macro(TOMAHAWK_TITLE);\
	Timer(TOMAHAWK_TITLE,$(UpdateTimeout),0);
	
TOMAHAWK_TIMER_CANCEL=\
	Timer(TOMAHAWK_TITLE,cancel);\
	Set(title,);\
	Set(status,);

TOMAHAWK_CHECK_TIMER=\
	Make(var,tomahawk_status,qdbus org.mpris.MediaPlayer2.tomahawk  /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus);\
	Make(var,timer_action,if [ "x$(tomahawk_status)" = "xPlaying" ]; \
	                      then echo TOMAHAWK_TIMER; else echo TOMAHAWK_TIMER_CANCEL; fi);\
	Macro($(timer_action));

RUN_IF_NEED=\
	Exec($(CfgDir)/Utils/run-or-switch-to.sh tomahawk);

RUN_OR_QUIT=\
	Exec(ID=`id -u`;P=`pgrep -u $ID tomahawk`; \
	     if [ "x$P" = "x" ]; then \
	         tomahawk 2> /dev/null&; \
             else \
	         qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Quit; \
	     fi);\
	Set(title,);\
	Set(status,);

PLAY_ONLY=\
	Exec(qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause);

PLAY=\
	Macro(PLAY_ONLY);\
	Macro(TOMAHAWK_TIMER);

RWD=\
	Exec(qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek -5000000);

FF=\
	Exec(qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Seek 5000000);

PREV=\
	Exec(qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous);\
	Macro(TOMAHAWK_TITLE);

NEXT=\
	Exec(qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next);\
	Macro(TOMAHAWK_TITLE);

STOP=\
	Macro(TOMAHAWK_TIMER_CANCEL);\
	Exec(qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop);

PAUSE=\
	Exec(qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Pause);

APP_QUIT=\
	Macro(TOMAHAWK_TIMER_CANCEL);\
	Exec(qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Quit);

APP_PLAY_STATUS=\
	Make(var,tomahawk_status,qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2  org.mpris.MediaPlayer2.Player.PlaybackStatus);\
	Make(var,app_status,if [ "x$(tomahawk_status)" = "xPlaying" ]; then echo playing; else echo paused; fi);

Shuffle=\
	Exec(P=`qdbus org.mpris.MediaPlayer2.tomahawk  /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Shuffle`; \
		if [ "x$P" = "xtrue" ]; \
		then \
		    qdbus org.mpris.MediaPlayer2.tomahawk  /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Shuffle false & \
		else \
		    qdbus org.mpris.MediaPlayer2.tomahawk  /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Shuffle true & \
		fi);

% Repeat does not works https://bugs.tomahawk-player.org/browse/TWK-1161

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

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

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

[ModeEnd]

[Mode]=tomahahk_3x4 : tomahahk_general, default_player

% (EnterMode) by Utils/aliases-server-player.cfg
% PowerMgmt by Utils/aliases-server.cfg
APP_MENU=\
	Set(menu,replace,Shuffle,Layout 5x1,Layout 7x1,PowerMgmt);\
	Macro(ALLIN1MENU);

APP_POST_SETUP=\
	Make(var,tomahahk_layout,by_value,3x4);\
	Macro(TOMAHAWK_CHECK_TIMER);

TOMAHAWK_TITLE=\
	Macro(TOMAHAWK_TITLE_GENERAL);

[ModeEnd]

[Mode]=tomahahk_cover

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

APP_COVER=\
	Make(var,tomahawk_cover_file,qdbus org.mpris.MediaPlayer2.tomahawk /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Metadata|\
			grep mpris:artUrl:|sed "s/mpris:artUrl: file:\/\///"|\
			sed "s/.*\/\/\//\//;s/'/'\\\''/g;s/\//\'\/\'/g;s/$/\'/g;s/^'\//\//;s/%20/ /g");\
	Make(var,coverfile,echo "$(tomahawk_cover_file)"|md5sum|cut -f 1 -d ' ');\
	Make(var,dummy,\
	     if  [ "x$(tomahawk_cover_file)" != "x" ]; then \
	         convert -resize $(cover_size)x$(cover_size) -depth -background transparent \
		         $(tomahawk_cover_file) $(TmpDir)/album_covers/$(coverfile)-$(cover_size).png;\
		 echo "$(TmpDir)/album_covers/$(coverfile)-$(cover_size).png";\
	     fi);\
	Set(cover,noname,$(TmpDir)/album_covers/$(coverfile)-$(cover_size).png);

[ModeEnd]

[Mode]=tomahahk_7x1 : tomahahk_general, tomahahk_cover, default_player_7x1

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

APP_POST_SETUP=\
	Make(var,tomahahk_layout,by_value,7x1);
	
[ModeEnd]

[Mode]=tomahahk_5x1 : tomahahk_general, tomahahk_cover, default_player_5x1

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

APP_POST_SETUP=\
	Make(var,tomahahk_layout,by_value,5x1);
	
APP_TITLE=\
	Macro(TOMAHAWK_TITLE);

PLAY=\
	Macro(PLAY_ONLY);

[ModeEnd]

[End]
