%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Key aliases for Server mode
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[Protocol]=Server

% Cancel buttons on different phones
-11=Macro(Cancel)
-8=Macro(Cancel)
69=Macro(Cancel)

Cancel=\
    Macro(QUIT);\
    Make(exit);

% SETUP_PACTL will be executed only if SETUP_AMIXER not executed
SETUP_DEFAULT_MIXER=\
        Make(var,audio_setup,P=`pacmd dump 2> /dev/null | grep set-sink-volume|wc -l`; if [ "x$P" = "x0" ]; then echo SETUP_AMIXER; else echo SETUP_PACTL; fi);\
	Macro($(audio_setup));
	
SETUP_AMIXER=\
	Make(var,default_mixer_up,by_value,amixer sset Master,0 5%+ -q);\
	Make(var,default_mixer_down,by_value,amixer sset Master,0 5%- -q);\
	Make(var,default_mixer_mute,by_value,amixer sset Master,0 toggle -q);\
	Make(var,default_mixer_get,by_value,amixer sget Master,0|grep '\['|head -1|cut -f 2 -d "["|cut -f 1 -d "]"|sed "s/%//");\
	Make(var,default_mixer_set,by_value,amixer -q sset Master,0 );

SETUP_PACTL=\
	Make(var,default_sink,LANG=C;pactl stat|grep "Default Sink"|cut -f 2 -d ":"|tr -d ' ');\
	Make(var,default_mixer_down,by_value,$(CfgDir)/Utils/pulse-audio-ctl.sh down $(default_sink));\
	Make(var,default_mixer_up,by_value,$(CfgDir)/Utils/pulse-audio-ctl.sh up $(default_sink));\
	Make(var,default_mixer_mute,by_value,$(CfgDir)/Utils/pulse-audio-ctl.sh mute $(default_sink));\
	Make(var,default_mixer_get,by_value,$(CfgDir)/Utils/pulse-audio-ctl.sh get $(default_sink));\
	Make(var,default_mixer_set,by_value,$(CfgDir)/Utils/pulse-audio-ctl.sh set $(default_sink) );

DEFAULT_VOLUME_UP=\
    Exec($(default_mixer_up));

DEFAULT_VOLUME_DOWN=\
    Exec($(default_mixer_down));

DEFAULT_TOGGLE_MUTE=\
    Exec($(default_mixer_mute));

% default_mixer_value in range 1-100
DEFAULT_VOLUME_GET=\
    Make(var,default_mixer_value,$(default_mixer_get));

DEFAULT_VOLUME_SET=\
    Exec($(default_mixer_set) $(default_mixer_value));

% Aliases for AverMedia IR remote
KEY_TEXT=Macro(*)
KEY_POWER=Macro(#)

% Android support
SEARCH=Macro(FIRE);

TEST_DBUS_SEND=\
	Exec(P=`which dbus-send|grep dbus-send|grep -v no|wc -l|tr -d " "`; \
	     if [ "x$P" != "x1" ]; then \
	         $(CfgDir)/Utils/message.sh "ERROR: dbus-send not found"; \
	     fi);

TEST_QDBUS=\
	Exec(P=`which qdbus|grep qdbus|grep -v no|wc -l|tr -d " "`; \
	     if [ "x$P" != "x1" ]; then \
	         $(CfgDir)/Utils/message.sh "ERROR: qdbus not found"; \
	     fi);

TEST_IMAGEMAGIC=\
	Exec(P=`which convert 2> /dev/null|grep convert|grep -v no|wc -l|tr -d " "`; \
	     if [ "x$P" = "x0" ]; then \
	         $(CfgDir)/Utils/message.sh "ERROR: ImageMagic is not installed"; \
	     fi);

% set $(kde4_app) before use
TEST_KDE4_APP=\
	Exec(V=`$(kde4_app) -v|grep KDE|tr -d " "|cut -f 2 -d ":"|cut -f 1 -d "."`; \
	     if [ "x$V" = "x3" ]; then \
	         $(CfgDir)/Utils/message.sh "ERROR: this configuration file is for KDE4"; \
	     fi);

%
% Power management (switch off/suspend) stuff
%
PowerMgmt=\
    Make(var,return_mode,by_value,$(Mode));\
    Make(mode,power_manager);

TEST_POWER_MANAGEMENT=\
	Exec(P=`which pmi|grep pmi|grep -v no|wc -l|tr -d " "`; \
	     if [ "x$P" != "x1" ]; then \
	         $(CfgDir)/Utils/message.sh "ERROR: pmi (power management interface) utility is not found"; \
	     fi);

% pmi action suspend -- Absent on non-Ubuntu distros
SETUP_DEFAULT_POWER_MANAGEMENT=\
	Make(var,default_switch_off,by_value,echo poweroff);\
	Make(var,default_suspend,by_value,echo dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend);

% Use sleep 3 to get some time to receive disconnect response from client
DEFAULT_PC_SWITCHOFF=\
    Set(disconnect);\
	Exec(sleep 3;$(default_switch_off));

DEFAULT_PC_SUSPEND=\
    Set(disconnect);\
	Exec(sleep 3;$(default_suspend));

%
% rely on $(return_mode) variable
%
[Mode]=power_manager

(EnterMode)=\
	Set(list,replace,PowerMgmt,Power Off, Suspend);\
    Set(menu,replace,Choose);

(ExitMode)=\
    Set(list,close);

Back($$)=\
    Make(mode,$(return_mode));
	
Push($$)=\
	Macro(Choose($$));

Choose($$)=\
    Macro($(Param));

Power Off=\
	Macro(DEFAULT_PC_SWITCHOFF);\
    Make(mode,$(return_mode));

Suspend=\
	Macro(DEFAULT_PC_SUSPEND);\
    Make(mode,$(return_mode));

[ModeEnd]
	
[End]
