diff --git a/src/gui/lua/lua_misc.cpp b/src/gui/lua/lua_misc.cpp index fca56c1c2..baad8915e 100644 --- a/src/gui/lua/lua_misc.cpp +++ b/src/gui/lua/lua_misc.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include +#include #include #include #include @@ -33,6 +36,8 @@ #include "luainstance.h" #include "lua_misc.h" +extern CVolume* g_volume; + CLuaInstMisc* CLuaInstMisc::getInstance() { static CLuaInstMisc* LuaInstMisc = NULL; @@ -54,6 +59,11 @@ void CLuaInstMisc::LuaMiscRegister(lua_State *L) { "strFind", CLuaInstMisc::strFind }, { "strSub", CLuaInstMisc::strSub }, { "enableInfoClock", CLuaInstMisc::enableInfoClock }, + { "enableMuteIcon", CLuaInstMisc::enableMuteIcon }, + { "setVolume", CLuaInstMisc::setVolume }, + { "getVolume", CLuaInstMisc::getVolume }, + { "AudioMute", CLuaInstMisc::AudioMute }, + { "isMuted", CLuaInstMisc::isMuted }, { "runScript", CLuaInstMisc::runScriptExt }, { "GetRevision", CLuaInstMisc::GetRevision }, { "checkVersion", CLuaInstMisc::checkVersion }, @@ -144,6 +154,56 @@ int CLuaInstMisc::enableInfoClock(lua_State *L) return 0; } +int CLuaInstMisc::enableMuteIcon(lua_State *L) +{ + bool enable = true; + int numargs = lua_gettop(L); + if (numargs > 1) + enable = _luaL_checkbool(L, 2); + CAudioMute::getInstance()->enableMuteIcon(enable); + return 0; +} + +int CLuaInstMisc::setVolume(lua_State *L) +{ + lua_Integer vol = luaL_checkint(L, 2); + if (vol < 0) vol = 0; + if (vol > 100) vol = 100; + g_settings.current_volume = vol; + g_volume->setvol(vol); + return 0; +} + +int CLuaInstMisc::getVolume(lua_State *L) +{ + lua_pushinteger(L, g_settings.current_volume); + return 1; +} + +int CLuaInstMisc::AudioMute(lua_State *L) +{ + int numargs = lua_gettop(L); + if (numargs < 2) { + printf("CLuaInstMisc::%s: not enough arguments (%d, expected 1 (or 2))\n", __func__, numargs); + return 0; + } + + bool newValue = false; + bool isEvent = false; + newValue = _luaL_checkbool(L, 2); + if (numargs > 2) + isEvent = _luaL_checkbool(L, 3); + + CAudioMute::getInstance()->AudioMute(newValue, isEvent); + return 0; +} + +int CLuaInstMisc::isMuted(lua_State *L) +{ + lua_pushboolean(L, CNeutrinoApp::getInstance()->isMuted()); + return 1; +} + int CLuaInstMisc::runScriptExt(lua_State *L) { int numargs = lua_gettop(L); diff --git a/src/gui/lua/lua_misc.h b/src/gui/lua/lua_misc.h index 551c40443..0d4969be7 100644 --- a/src/gui/lua/lua_misc.h +++ b/src/gui/lua/lua_misc.h @@ -54,6 +54,11 @@ class CLuaInstMisc static int strFind(lua_State *L); static int strSub(lua_State *L); static int enableInfoClock(lua_State *L); + static int enableMuteIcon(lua_State *L); + static int setVolume(lua_State *L); + static int getVolume(lua_State *L); + static int AudioMute(lua_State *L); + static int isMuted(lua_State *L); static int runScriptExt(lua_State *L); static int GetRevision(lua_State *L); static int checkVersion(lua_State *L); diff --git a/src/gui/lua/luainstance.h b/src/gui/lua/luainstance.h index 425a2fdbe..2f8be126f 100644 --- a/src/gui/lua/luainstance.h +++ b/src/gui/lua/luainstance.h @@ -31,7 +31,7 @@ extern "C" { #include "luainstance_helpers.h" #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 34 +#define LUA_API_VERSION_MINOR 35 void LuaInstRegisterFunctions(lua_State *L, bool fromThreads=false);