diff --git a/data/locale/deutsch.locale b/data/locale/deutsch.locale index c4555b354..658fa2500 100644 --- a/data/locale/deutsch.locale +++ b/data/locale/deutsch.locale @@ -611,6 +611,8 @@ flashupdate.getupdatefile lade Update flashupdate.getupdatefileerror Kann Aktualisierung nicht laden! flashupdate.globalprogress Gesamtstatus: flashupdate.head Aktualisierung +flashupdate.install_image Heruntergeladenes Image installieren? +flashupdate.install_package Heruntergeladenes Paket installieren? flashupdate.md5check Imageprüfung flashupdate.md5sumerror Das Image ist fehlerhaft flashupdate.menu_apply_kernel Kernel flashen diff --git a/data/locale/english.locale b/data/locale/english.locale index 875b688a1..01f7d4048 100644 --- a/data/locale/english.locale +++ b/data/locale/english.locale @@ -612,6 +612,8 @@ flashupdate.getupdatefile getting update flashupdate.getupdatefileerror Can't get update! flashupdate.globalprogress Global Progress: flashupdate.head Software Update +flashupdate.install_image Flash downloaded image? +flashupdate.install_package Install downloadad pack? flashupdate.md5check checking image flashupdate.md5sumerror image has errors flashupdate.menu_apply_kernel Flashing kernel diff --git a/src/gui/lua/Makefile.am b/src/gui/lua/Makefile.am index a04fca60e..d3c7aa4cc 100644 --- a/src/gui/lua/Makefile.am +++ b/src/gui/lua/Makefile.am @@ -37,6 +37,9 @@ libneutrino_gui_lua_a_SOURCES = \ lua_menue.cpp \ lua_messagebox.cpp \ lua_misc.cpp \ + lua_threads.cpp \ + lua_threads_copy.cpp \ + lua_threads_functions.cpp \ lua_video.cpp # the continuous changes of LUA_API_VERSION_* in luainstance.h diff --git a/src/gui/lua/lua_cc_picture.cpp b/src/gui/lua/lua_cc_picture.cpp index 21ebed5e3..d58062c7b 100644 --- a/src/gui/lua/lua_cc_picture.cpp +++ b/src/gui/lua/lua_cc_picture.cpp @@ -129,8 +129,8 @@ int CLuaInstCCPicture::CCPictureNew(lua_State *L) int CLuaInstCCPicture::CCPicturePaint(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCPicture *m = CCPictureCheck(L, 1); - if (!m) return 0; + CLuaCCPicture *D = CCPictureCheck(L, 1); + if (!D) return 0; bool do_save_bg = true; if (!tableLookup(L, "do_save_bg", do_save_bg)) { @@ -139,15 +139,15 @@ int CLuaInstCCPicture::CCPicturePaint(lua_State *L) paramBoolDeprecated(L, tmp.c_str()); do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes"); } - m->cp->paint(do_save_bg); + D->cp->paint(do_save_bg); return 0; } int CLuaInstCCPicture::CCPictureHide(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCPicture *m = CCPictureCheck(L, 1); - if (!m) return 0; + CLuaCCPicture *D = CCPictureCheck(L, 1); + if (!D) return 0; bool no_restore = false; if (!tableLookup(L, "no_restore", no_restore)) { @@ -156,48 +156,47 @@ int CLuaInstCCPicture::CCPictureHide(lua_State *L) paramBoolDeprecated(L, tmp.c_str()); no_restore = (tmp == "true" || tmp == "1" || tmp == "yes"); } - if (m->parent) { - m->cp->setPicture(""); - m->cp->paint(); + if (D->parent) { + D->cp->setPicture(""); + D->cp->paint(); } else - m->cp->hide(no_restore); + D->cp->hide(no_restore); return 0; } int CLuaInstCCPicture::CCPictureSetPicture(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCPicture *m = CCPictureCheck(L, 1); - if (!m) return 0; + CLuaCCPicture *D = CCPictureCheck(L, 1); + if (!D) return 0; std::string image_name = ""; tableLookup(L, "image", image_name); - m->cp->setPicture(image_name); + D->cp->setPicture(image_name); return 0; } int CLuaInstCCPicture::CCPictureSetCenterPos(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCPicture *m = CCPictureCheck(L, 1); - if (!m) return 0; + CLuaCCPicture *D = CCPictureCheck(L, 1); + if (!D) return 0; lua_Integer tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y; tableLookup(L, "along_mode", tmp_along_mode); if (tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y) along_mode=tmp_along_mode; - m->cp->setCenterPos(along_mode); + D->cp->setCenterPos(along_mode); return 0; } int CLuaInstCCPicture::CCPictureDelete(lua_State *L) { LUA_DEBUG("CLuaInstCCPicture::%s %d\n", __func__, lua_gettop(L)); - CLuaCCPicture *m = CCPictureCheck(L, 1); - if (!m) return 0; - - delete m; + CLuaCCPicture *D = CCPictureCheck(L, 1); + if (!D) return 0; + delete D; return 0; } diff --git a/src/gui/lua/lua_cc_signalbox.cpp b/src/gui/lua/lua_cc_signalbox.cpp index 084e702cc..6f9253f13 100644 --- a/src/gui/lua/lua_cc_signalbox.cpp +++ b/src/gui/lua/lua_cc_signalbox.cpp @@ -92,8 +92,8 @@ int CLuaInstCCSignalbox::CCSignalBoxNew(lua_State *L) int CLuaInstCCSignalbox::CCSignalBoxPaint(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCSignalBox *m = CCSignalBoxCheck(L, 1); - if (!m) return 0; + CLuaCCSignalBox *D = CCSignalBoxCheck(L, 1); + if (!D) return 0; bool do_save_bg = true; if (!tableLookup(L, "do_save_bg", do_save_bg)) { @@ -102,31 +102,29 @@ int CLuaInstCCSignalbox::CCSignalBoxPaint(lua_State *L) paramBoolDeprecated(L, tmp.c_str()); do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes"); } - m->s->paint(do_save_bg); + D->s->paint(do_save_bg); return 0; } int CLuaInstCCSignalbox::CCSignalBoxSetCenterPos(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCSignalBox *m = CCSignalBoxCheck(L, 1); - if (!m) return 0; + CLuaCCSignalBox *D = CCSignalBoxCheck(L, 1); + if (!D) return 0; lua_Integer tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y; tableLookup(L, "along_mode", tmp_along_mode); if (tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y) along_mode=tmp_along_mode; - m->s->setCenterPos(along_mode); + D->s->setCenterPos(along_mode); return 0; } int CLuaInstCCSignalbox::CCSignalBoxDelete(lua_State *L) { - CLuaCCSignalBox *m = CCSignalBoxCheck(L, 1); - if (!m) - return 0; - - delete m; + CLuaCCSignalBox *D = CCSignalBoxCheck(L, 1); + if (!D) return 0; + delete D; return 0; } diff --git a/src/gui/lua/lua_cc_text.cpp b/src/gui/lua/lua_cc_text.cpp index 5f87e409e..57b907e60 100644 --- a/src/gui/lua/lua_cc_text.cpp +++ b/src/gui/lua/lua_cc_text.cpp @@ -154,8 +154,8 @@ int CLuaInstCCText::CCTextNew(lua_State *L) int CLuaInstCCText::CCTextPaint(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCText *m = CCTextCheck(L, 1); - if (!m) return 0; + CLuaCCText *D = CCTextCheck(L, 1); + if (!D) return 0; bool do_save_bg = true; if (!tableLookup(L, "do_save_bg", do_save_bg)) { @@ -164,15 +164,15 @@ int CLuaInstCCText::CCTextPaint(lua_State *L) paramBoolDeprecated(L, tmp.c_str()); do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes"); } - m->ct->paint(do_save_bg); + D->ct->paint(do_save_bg); return 0; } int CLuaInstCCText::CCTextHide(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCText *m = CCTextCheck(L, 1); - if (!m) return 0; + CLuaCCText *D = CCTextCheck(L, 1); + if (!D) return 0; bool no_restore = false; if (!tableLookup(L, "no_restore", no_restore)) { @@ -181,36 +181,36 @@ int CLuaInstCCText::CCTextHide(lua_State *L) paramBoolDeprecated(L, tmp.c_str()); no_restore = (tmp == "true" || tmp == "1" || tmp == "yes"); } - if (m->parent) { - m->ct->setText("", m->mode, g_Font[m->font_text]); - m->ct->paint(); + if (D->parent) { + D->ct->setText("", D->mode, g_Font[D->font_text]); + D->ct->paint(); } else - m->ct->hide(no_restore); + D->ct->hide(no_restore); return 0; } int CLuaInstCCText::CCTextSetText(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCText *m = CCTextCheck(L, 1); - if (!m) return 0; + CLuaCCText *D = CCTextCheck(L, 1); + if (!D) return 0; std::string text = ""; - lua_Integer mode = m->mode; - lua_Integer font_text = m->font_text; + lua_Integer mode = D->mode; + lua_Integer font_text = D->font_text; tableLookup(L, "text", text); tableLookup(L, "mode", mode); tableLookup(L, "font_text", font_text); - m->ct->setText(text, mode, g_Font[font_text]); + D->ct->setText(text, mode, g_Font[font_text]); return 0; } int CLuaInstCCText::CCTextScroll(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCText *m = CCTextCheck(L, 1); - if (!m) return 0; + CLuaCCText *D = CCTextCheck(L, 1); + if (!D) return 0; std::string tmp = "true"; tableLookup(L, "dir", tmp); @@ -219,7 +219,7 @@ int CLuaInstCCText::CCTextScroll(lua_State *L) tableLookup(L, "pages", pages); //get the textbox instance from lua object and use CTexBbox scroll methods - CTextBox* ctb = m->ct->getCTextBoxObject(); + CTextBox* ctb = D->ct->getCTextBoxObject(); if (ctb) { if (pages == -1) pages = ctb->getPages(); @@ -236,23 +236,23 @@ int CLuaInstCCText::CCTextScroll(lua_State *L) int CLuaInstCCText::CCTextSetCenterPos(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCText *m = CCTextCheck(L, 1); - if (!m) return 0; + CLuaCCText *D = CCTextCheck(L, 1); + if (!D) return 0; lua_Integer tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y; tableLookup(L, "along_mode", tmp_along_mode); if (tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y) along_mode=tmp_along_mode; - m->ct->setCenterPos(along_mode); + D->ct->setCenterPos(along_mode); return 0; } int CLuaInstCCText::CCTextEnableUTF8(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCText *m = CCTextCheck(L, 1); - if (!m) return 0; + CLuaCCText *D = CCTextCheck(L, 1); + if (!D) return 0; bool utf8_encoded = true; if (!tableLookup(L, "utf8_encoded", utf8_encoded)) { @@ -261,17 +261,15 @@ int CLuaInstCCText::CCTextEnableUTF8(lua_State *L) paramBoolDeprecated(L, tmp.c_str()); utf8_encoded = (tmp == "true" || tmp == "1" || tmp == "yes"); } - m->ct->enableUTF8(utf8_encoded); + D->ct->enableUTF8(utf8_encoded); return 0; } int CLuaInstCCText::CCTextDelete(lua_State *L) { LUA_DEBUG("CLuaInstCCText::%s %d\n", __func__, lua_gettop(L)); - CLuaCCText *m = CCTextCheck(L, 1); - if (!m) - return 0; - - delete m; + CLuaCCText *D = CCTextCheck(L, 1); + if (!D) return 0; + delete D; return 0; } diff --git a/src/gui/lua/lua_cc_window.cpp b/src/gui/lua/lua_cc_window.cpp index 399abd7f7..fd08b0802 100644 --- a/src/gui/lua/lua_cc_window.cpp +++ b/src/gui/lua/lua_cc_window.cpp @@ -177,8 +177,8 @@ CLuaCCWindow *CLuaInstCCWindow::CCWindowCheck(lua_State *L, int n) int CLuaInstCCWindow::CCWindowPaint(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) return 0; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; bool do_save_bg = true; if (!tableLookup(L, "do_save_bg", do_save_bg)) { @@ -187,15 +187,15 @@ int CLuaInstCCWindow::CCWindowPaint(lua_State *L) paramBoolDeprecated(L, tmp.c_str()); do_save_bg = (tmp == "true" || tmp == "1" || tmp == "yes"); } - m->w->paint(do_save_bg); + D->w->paint(do_save_bg); return 0; } int CLuaInstCCWindow::CCWindowHide(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) return 0; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; bool no_restore = false; if (!tableLookup(L, "no_restore", no_restore)) { @@ -204,41 +204,41 @@ int CLuaInstCCWindow::CCWindowHide(lua_State *L) paramBoolDeprecated(L, tmp.c_str()); no_restore = (tmp == "true" || tmp == "1" || tmp == "yes"); } - m->w->hide(no_restore); + D->w->hide(no_restore); return 0; } int CLuaInstCCWindow::CCWindowSetCaption(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) return 0; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; std::string name = ""; tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name); - m->w->setWindowCaption(name); + D->w->setWindowCaption(name); return 0; } int CLuaInstCCWindow::CCWindowSetWindowColor(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) return 0; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; lua_Unsigned color; if (tableLookup(L, "color_frame" , color)) { checkMagicMask(color); - m->w->setColorFrame(color); + D->w->setColorFrame(color); } if (tableLookup(L, "color_body" , color)) { checkMagicMask(color); - m->w->setColorBody(color); + D->w->setColorBody(color); } if (tableLookup(L, "color_shadow" , color)) { checkMagicMask(color); - m->w->setColorShadow(color); + D->w->setColorShadow(color); } return 0; @@ -246,12 +246,12 @@ int CLuaInstCCWindow::CCWindowSetWindowColor(lua_State *L) int CLuaInstCCWindow::CCWindowPaintHeader(lua_State *L) { - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) return 0; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; - CComponentsHeader* header = m->w->getHeaderObject(); + CComponentsHeader* header = D->w->getHeaderObject(); if (header) - m->w->showHeader(); + D->w->showHeader(); header->paint(); return 0; @@ -273,11 +273,10 @@ int CLuaInstCCWindow::CCWindowGetFooterHeight_dep(lua_State *L) int CLuaInstCCWindow::CCWindowGetHeaderHeight(lua_State *L) { - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) - return 0; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; - CComponentsHeader* header = m->w->getHeaderObject(); + CComponentsHeader* header = D->w->getHeaderObject(); int hh = 0; if (header) hh = header->getHeight(); @@ -287,11 +286,10 @@ int CLuaInstCCWindow::CCWindowGetHeaderHeight(lua_State *L) int CLuaInstCCWindow::CCWindowGetFooterHeight(lua_State *L) { - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) - return 0; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; - CComponentsFooter* footer = m->w->getFooterObject(); + CComponentsFooter* footer = D->w->getFooterObject(); int fh = 0; if (footer) fh = footer->getHeight(); @@ -302,25 +300,23 @@ int CLuaInstCCWindow::CCWindowGetFooterHeight(lua_State *L) int CLuaInstCCWindow::CCWindowSetCenterPos(lua_State *L) { lua_assert(lua_istable(L,1)); - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) return 0; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; lua_Integer tmp_along_mode, along_mode = CC_ALONG_X | CC_ALONG_Y; tableLookup(L, "along_mode", tmp_along_mode); if (tmp_along_mode & CC_ALONG_X || tmp_along_mode & CC_ALONG_Y) along_mode=tmp_along_mode; - m->w->setCenterPos(along_mode); + D->w->setCenterPos(along_mode); return 0; } int CLuaInstCCWindow::CCWindowDelete(lua_State *L) { LUA_DEBUG("CLuaInstCCWindow::%s %d\n", __func__, lua_gettop(L)); - CLuaCCWindow *m = CCWindowCheck(L, 1); - if (!m) - return 0; - - delete m; + CLuaCCWindow *D = CCWindowCheck(L, 1); + if (!D) return 0; + delete D; return 0; } diff --git a/src/gui/lua/lua_configfile.cpp b/src/gui/lua/lua_configfile.cpp index 010b9131a..e39938530 100644 --- a/src/gui/lua/lua_configfile.cpp +++ b/src/gui/lua/lua_configfile.cpp @@ -89,39 +89,39 @@ int CLuaInstConfigFile::LuaConfigFileNew(lua_State *L) int CLuaInstConfigFile::LuaConfigFileLoadConfig(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; const char *fname = luaL_checkstring(L, 2); - bool ret = c->c->loadConfig(fname); + bool ret = D->c->loadConfig(fname); lua_pushboolean(L, ret); return 1; } int CLuaInstConfigFile::LuaConfigFileSaveConfig(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; const char *fname = luaL_checkstring(L, 2); - bool ret = c->c->saveConfig(fname); + bool ret = D->c->saveConfig(fname); lua_pushboolean(L, ret); return 1; } int CLuaInstConfigFile::LuaConfigFileClear(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; - c->c->clear(); + D->c->clear(); return 0; } int CLuaInstConfigFile::LuaConfigFileGetString(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; int numargs = lua_gettop(L); std::string ret; @@ -129,26 +129,26 @@ int CLuaInstConfigFile::LuaConfigFileGetString(lua_State *L) const char *defaultVal = ""; if (numargs > 2) defaultVal = luaL_checkstring(L, 3); - ret = c->c->getString(key, defaultVal); + ret = D->c->getString(key, defaultVal); lua_pushstring(L, ret.c_str()); return 1; } int CLuaInstConfigFile::LuaConfigFileSetString(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; const char *key = luaL_checkstring(L, 2); const char *val = luaL_checkstring(L, 3); - c->c->setString(key, val); + D->c->setString(key, val); return 0; } int CLuaInstConfigFile::LuaConfigFileGetInt32(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; int numargs = lua_gettop(L); int ret; @@ -156,26 +156,26 @@ int CLuaInstConfigFile::LuaConfigFileGetInt32(lua_State *L) int defaultVal = 0; if (numargs > 2) defaultVal = luaL_checkint(L, 3); - ret = c->c->getInt32(key, defaultVal); + ret = D->c->getInt32(key, defaultVal); lua_pushinteger(L, ret); return 1; } int CLuaInstConfigFile::LuaConfigFileSetInt32(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; const char *key = luaL_checkstring(L, 2); int val = luaL_checkint(L, 3); - c->c->setInt32(key, val); + D->c->setInt32(key, val); return 0; } int CLuaInstConfigFile::LuaConfigFileGetBool(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; int numargs = lua_gettop(L); bool ret; @@ -183,37 +183,37 @@ int CLuaInstConfigFile::LuaConfigFileGetBool(lua_State *L) bool defaultVal = false; if (numargs > 2) defaultVal = _luaL_checkbool(L, 3); - ret = c->c->getBool(key, defaultVal); + ret = D->c->getBool(key, defaultVal); lua_pushboolean(L, ret); return 1; } int CLuaInstConfigFile::LuaConfigFileSetBool(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; const char *key = luaL_checkstring(L, 2); bool val = _luaL_checkbool(L, 3); - c->c->setBool(key, val); + D->c->setBool(key, val); return 0; } int CLuaInstConfigFile::LuaConfigFileDeleteKey(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; const char *s1 = luaL_checkstring(L, 2); std::string key(s1); - c->c->deleteKey(key); + D->c->deleteKey(key); return 0; } int CLuaInstConfigFile::LuaConfigFileDelete(lua_State *L) { - CLuaConfigFile *c = LuaConfigFileCheck(L, 1); - if (!c) return 0; - delete c; + CLuaConfigFile *D = LuaConfigFileCheck(L, 1); + if (!D) return 0; + delete D; return 0; } diff --git a/src/gui/lua/lua_curl.cpp b/src/gui/lua/lua_curl.cpp index 69d25ea17..c6a3f77a7 100644 --- a/src/gui/lua/lua_curl.cpp +++ b/src/gui/lua/lua_curl.cpp @@ -99,7 +99,7 @@ int CLuaInstCurl::CurlProgressFunc(void *p, curl_off_t dltotal, curl_off_t dlnow curl_easy_getinfo(_pgd->curl, CURLINFO_RESPONSE_CODE, &responseCode); uint32_t MUL = 0x7FFF; - uint32_t dlFragment = (dlnow * MUL) / dltotal; + uint32_t dlFragment = (uint32_t)((dlnow * MUL) / dltotal); if (responseCode != 200) { dlFragment = 0; dlSpeed = 0; @@ -173,6 +173,8 @@ Example: #define CURL_MSG_ERROR "[curl:download \33[1;31mERROR!\33[0m]" lua_assert(lua_istable(L,1)); + CLuaCurl *D = CurlCheckData(L, 1); + if (!D) return 0; char errMsg[1024]; CURL *curl_handle = curl_easy_init(); @@ -348,7 +350,7 @@ Example: return 2; } - if (silent == false) + if (verbose == true) printf("%s\n \n", msg.c_str()); lua_pushinteger(L, LUA_CURL_OK); @@ -359,6 +361,7 @@ Example: int CLuaInstCurl::CurlDelete(lua_State *L) { CLuaCurl *D = CurlCheckData(L, 1); + if (!D) return 0; delete D; return 0; } diff --git a/src/gui/lua/lua_hintbox.cpp b/src/gui/lua/lua_hintbox.cpp index 6b9c23d7f..900637777 100644 --- a/src/gui/lua/lua_hintbox.cpp +++ b/src/gui/lua/lua_hintbox.cpp @@ -100,36 +100,36 @@ int CLuaInstHintbox::HintboxNew(lua_State *L) int CLuaInstHintbox::HintboxDelete(lua_State *L) { - CLuaHintbox *m = HintboxCheck(L, 1); - delete m; + CLuaHintbox *D = HintboxCheck(L, 1); + if (!D) return 0; + delete D; return 0; } int CLuaInstHintbox::HintboxPaint(lua_State *L) { - CLuaHintbox *m = HintboxCheck(L, 1); - if (!m) - return 0; - m->b->paint(); + CLuaHintbox *D = HintboxCheck(L, 1); + if (!D) return 0; + D->b->paint(); return 0; } int CLuaInstHintbox::HintboxHide(lua_State *L) { - CLuaHintbox *m = HintboxCheck(L, 1); - m->b->hide(); + CLuaHintbox *D = HintboxCheck(L, 1); + if (!D) return 0; + D->b->hide(); return 0; } int CLuaInstHintbox::HintboxExec(lua_State *L) { - CLuaHintbox *m = HintboxCheck(L, 1); - if (!m) - return 0; + CLuaHintbox *D = HintboxCheck(L, 1); + if (!D) return 0; int timeout = -1; if (lua_isnumber(L, -1)) timeout = (int) lua_tonumber(L, -1); - m->b->paint(); + D->b->paint(); // copied from gui/widget/hintbox.cpp neutrino_msg_t msg; @@ -149,11 +149,11 @@ int CLuaInstHintbox::HintboxExec(lua_State *L) res = messages_return::cancel_info; else if (msg == CRCInput::RC_home) res = messages_return::cancel_all; - else if ((m->b->has_scrollbar()) && ((msg == CRCInput::RC_up) || (msg == CRCInput::RC_down))) { + else if ((D->b->has_scrollbar()) && ((msg == CRCInput::RC_up) || (msg == CRCInput::RC_down))) { if (msg == CRCInput::RC_up) - m->b->scroll_up(); + D->b->scroll_up(); else - m->b->scroll_down(); + D->b->scroll_down(); } else if ((msg == CRCInput::RC_sat) || (msg == CRCInput::RC_favorites)) { } else if (msg == CRCInput::RC_mode) { res = messages_return::handled; @@ -171,6 +171,6 @@ int CLuaInstHintbox::HintboxExec(lua_State *L) } } } - m->b->hide(); + D->b->hide(); return 0; } diff --git a/src/gui/lua/lua_menue.cpp b/src/gui/lua/lua_menue.cpp index 85be4460b..fcd421e09 100644 --- a/src/gui/lua/lua_menue.cpp +++ b/src/gui/lua/lua_menue.cpp @@ -292,9 +292,8 @@ int CLuaInstMenu::MenuNew(lua_State *L) int CLuaInstMenu::MenuAddKey(lua_State *L) { - CLuaMenu *m = MenuCheck(L, 1); - if (!m) - return 0; + CLuaMenu *D = MenuCheck(L, 1); + if (!D) return 0; lua_assert(lua_istable(L, 2)); std::string action; tableLookup(L, "action", action); @@ -302,16 +301,16 @@ int CLuaInstMenu::MenuAddKey(lua_State *L) lua_Unsigned directkey = CRCInput::RC_nokey; tableLookup(L, "directkey", directkey); if ((!action.empty()) && (directkey != CRCInput::RC_nokey)) { CLuaMenuForwarder *forwarder = new CLuaMenuForwarder(L, action, id); - m->m->addKey(directkey, forwarder, action); - m->targets.push_back(forwarder); + D->m->addKey(directkey, forwarder, action); + D->targets.push_back(forwarder); } return 0; } int CLuaInstMenu::MenuAddItem(lua_State *L) { - CLuaMenu *m = MenuCheck(L, 1); - if (!m) { + CLuaMenu *D = MenuCheck(L, 1); + if (!D) { lua_pushnil(L); return 1; } @@ -319,25 +318,25 @@ int CLuaInstMenu::MenuAddItem(lua_State *L) CMenuItem *mi = NULL; CLuaMenuItem i; - m->items.push_back(i); - CLuaMenuItem *b = &m->items.back(); + D->items.push_back(i); + CLuaMenuItem *b = &D->items.back(); tableLookup(L, "name", b->name); std::string type; tableLookup(L, "type", type); if (type == "back") { - m->m->addItem(GenericMenuBack); + D->m->addItem(GenericMenuBack); } else if (type == "next") { - m->m->addItem(GenericMenuNext); + D->m->addItem(GenericMenuNext); } else if (type == "cancel") { - m->m->addItem(GenericMenuCancel); + D->m->addItem(GenericMenuCancel); } else if (type == "separator") { - m->m->addItem(GenericMenuSeparator); + D->m->addItem(GenericMenuSeparator); } else if ((type == "separatorline") || (type == "subhead")) { if (!b->name.empty()) { int flag = (type == "separatorline") ? CMenuSeparator::LINE : CMenuSeparator::SUB_HEAD; - m->m->addItem(new CMenuSeparator(CMenuSeparator::STRING | flag, b->name.c_str(), NONEXISTANT_LOCALE)); + D->m->addItem(new CMenuSeparator(CMenuSeparator::STRING | flag, b->name.c_str(), NONEXISTANT_LOCALE)); } else - m->m->addItem(GenericMenuSeparatorLine); + D->m->addItem(GenericMenuSeparatorLine); } else { std::string right_icon_str; tableLookup(L, "right_icon", right_icon_str); std::string action; tableLookup(L, "action", action); @@ -350,17 +349,17 @@ int CLuaInstMenu::MenuAddItem(lua_State *L) char *right_icon = NULL; if (!right_icon_str.empty()) { right_icon = strdup(right_icon_str.c_str()); - m->tofree.push_back(right_icon); + D->tofree.push_back(right_icon); } char *hint_icon = NULL; if (!hint_icon_str.empty()) { hint_icon = strdup(hint_icon_str.c_str()); - m->tofree.push_back(hint_icon); + D->tofree.push_back(hint_icon); } char *icon = NULL; if (!icon_str.empty()) { icon = strdup(icon_str.c_str()); - m->tofree.push_back(icon); + D->tofree.push_back(icon); } lua_Unsigned directkey = CRCInput::RC_nokey; tableLookup(L, "directkey", directkey); @@ -384,7 +383,7 @@ int CLuaInstMenu::MenuAddItem(lua_State *L) mi = new CMenuForwarder(b->name, enabled, b->str_val, forwarder, NULL/*ActionKey*/, directkey, icon, right_icon); if (!hint.empty() || hint_icon) mi->setHint(hint_icon, hint); - m->targets.push_back(forwarder); + D->targets.push_back(forwarder); } else if (type == "chooser") { int options_count = 0; lua_pushstring(L, "options"); @@ -396,13 +395,13 @@ int CLuaInstMenu::MenuAddItem(lua_State *L) } lua_pop(L, 1); if (options_count == 0) { - m->m->addItem(new CMenuSeparator(CMenuSeparator::STRING | CMenuSeparator::LINE, "ERROR! (options_count)", NONEXISTANT_LOCALE)); + D->m->addItem(new CMenuSeparator(CMenuSeparator::STRING | CMenuSeparator::LINE, "ERROR! (options_count)", NONEXISTANT_LOCALE)); lua_pushnil(L); return 1; } CMenuOptionChooser::keyval_ext *kext = (CMenuOptionChooser::keyval_ext *)calloc(options_count, sizeof(CMenuOptionChooser::keyval_ext)); - m->tofree.push_back(kext); + D->tofree.push_back(kext); lua_pushstring(L, "options"); lua_gettable(L, -2); b->int_val = 0; @@ -415,38 +414,38 @@ int CLuaInstMenu::MenuAddItem(lua_State *L) kext[j].key = atoi(key); kext[j].value = NONEXISTANT_LOCALE; kext[j].valname = strdup(val); - m->tofree.push_back((void *)kext[j].valname); + D->tofree.push_back((void *)kext[j].valname); if (!strcmp(value.c_str(), kext[j].valname)) b->int_val = kext[j].key; j++; } } lua_pop(L, 1); - mi = new CMenuOptionChooser(b->name.c_str(), &b->int_val, kext, options_count, enabled, m->observ, directkey, icon, pulldown); + mi = new CMenuOptionChooser(b->name.c_str(), &b->int_val, kext, options_count, enabled, D->observ, directkey, icon, pulldown); } else if (type == "numeric") { b->int_val = range_from; sscanf(value.c_str(), "%d", &b->int_val); - mi = new CMenuOptionNumberChooser(b->name, &b->int_val, enabled, range_from, range_to, m->observ, 0, 0, NONEXISTANT_LOCALE, pulldown); + mi = new CMenuOptionNumberChooser(b->name, &b->int_val, enabled, range_from, range_to, D->observ, 0, 0, NONEXISTANT_LOCALE, pulldown); } else if (type == "string") { b->str_val = value; - mi = new CMenuOptionStringChooser(b->name.c_str(), &b->str_val, enabled, m->observ, directkey, icon, pulldown); + mi = new CMenuOptionStringChooser(b->name.c_str(), &b->str_val, enabled, D->observ, directkey, icon, pulldown); } else if (type == "stringinput") { b->str_val = value; std::string valid_chars = "abcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?-. "; tableLookup(L, "valid_chars", valid_chars); lua_Integer sms = 0; tableLookup(L, "sms", sms); lua_Integer size = 30; tableLookup(L, "size", size); - CLuaMenuStringinput *stringinput = new CLuaMenuStringinput(L, action, id, b->name.c_str(), &b->str_val, size, valid_chars, m->observ, icon, sms); + CLuaMenuStringinput *stringinput = new CLuaMenuStringinput(L, action, id, b->name.c_str(), &b->str_val, size, valid_chars, D->observ, icon, sms); mi = new CMenuForwarder(b->name, enabled, b->str_val, stringinput, NULL/*ActionKey*/, directkey, icon, right_icon); - m->targets.push_back(stringinput); + D->targets.push_back(stringinput); } else if (type == "keyboardinput") { b->str_val = value; lua_Integer size = 0; tableLookup(L, "size", size); std::string help = ""; tableLookup(L, "help", help); std::string help2 = ""; tableLookup(L, "help2", help2); - CLuaMenuKeyboardinput *keyboardinput = new CLuaMenuKeyboardinput(L, action, id, b->name.c_str(), &b->str_val, size, m->observ, icon, help, help2); + CLuaMenuKeyboardinput *keyboardinput = new CLuaMenuKeyboardinput(L, action, id, b->name.c_str(), &b->str_val, size, D->observ, icon, help, help2); mi = new CMenuForwarder(b->name, enabled, b->str_val, keyboardinput, NULL/*ActionKey*/, directkey, icon, right_icon); - m->targets.push_back(keyboardinput); + D->targets.push_back(keyboardinput); } else if (type == "filebrowser") { b->str_val = value; lua_Integer dirMode = 0; tableLookup(L, "dir_mode", dirMode); @@ -462,19 +461,19 @@ int CLuaInstMenu::MenuAddItem(lua_State *L) lua_pop(L, 1); mi = new CMenuForwarder(b->name, enabled, b->str_val, filebrowser, NULL/*ActionKey*/, directkey, icon, right_icon); - m->targets.push_back(filebrowser); + D->targets.push_back(filebrowser); } if (mi) { mi->setLua(L, action, id); if (!hint.empty() || hint_icon) mi->setHint(hint_icon, hint); - m->m->addItem(mi); + D->m->addItem(mi); } } if (mi) { - lua_Integer id = m->itemmap.size() + 1; - m->itemmap.insert(itemmap_pair_t(id, mi)); + lua_Integer id = D->itemmap.size() + 1; + D->itemmap.insert(itemmap_pair_t(id, mi)); lua_pushinteger(L, id); } else lua_pushnil(L); @@ -484,35 +483,32 @@ int CLuaInstMenu::MenuAddItem(lua_State *L) int CLuaInstMenu::MenuExec(lua_State *L) { - CLuaMenu *m = MenuCheck(L, 1); - if (!m) - return 0; - m->m->exec(NULL, ""); - m->m->hide(); + CLuaMenu *D = MenuCheck(L, 1); + if (!D) return 0; + D->m->exec(NULL, ""); + D->m->hide(); return 0; } int CLuaInstMenu::MenuHide(lua_State *L) { - CLuaMenu *m = MenuCheck(L, 1); - if (!m) - return 0; - m->m->hide(); + CLuaMenu *D = MenuCheck(L, 1); + if (!D) return 0; + D->m->hide(); return 0; } int CLuaInstMenu::MenuSetActive(lua_State *L) { - CLuaMenu *m = MenuCheck(L, 1); - if (!m) - return 0; lua_assert(lua_istable(L, 2)); + CLuaMenu *D = MenuCheck(L, 1); + if (!D) return 0; lua_Integer id; tableLookup(L, "item", id); bool activ; tableLookup(L, "activ", activ); CMenuItem* item = NULL; - for (itemmap_iterator_t it = m->itemmap.begin(); it != m->itemmap.end(); ++it) { + for (itemmap_iterator_t it = D->itemmap.begin(); it != D->itemmap.end(); ++it) { if (it->first == id) { item = it->second; break; @@ -525,16 +521,15 @@ int CLuaInstMenu::MenuSetActive(lua_State *L) int CLuaInstMenu::MenuSetName(lua_State *L) { - CLuaMenu *m = MenuCheck(L, 1); - if (!m) - return 0; lua_assert(lua_istable(L, 2)); + CLuaMenu *D = MenuCheck(L, 1); + if (!D) return 0; lua_Integer id; tableLookup(L, "item", id); std::string name; tableLookup(L, "name", name); CMenuItem* item = NULL; - for (itemmap_iterator_t it = m->itemmap.begin(); it != m->itemmap.end(); ++it) { + for (itemmap_iterator_t it = D->itemmap.begin(); it != D->itemmap.end(); ++it) { if (it->first == id) { item = it->second; break; @@ -547,19 +542,18 @@ int CLuaInstMenu::MenuSetName(lua_State *L) int CLuaInstMenu::MenuDelete(lua_State *L) { - CLuaMenu *m = MenuCheck(L, 1); - if (!m) - return 0; + CLuaMenu *D = MenuCheck(L, 1); + if (!D) return 0; - while (!m->targets.empty()) { - delete m->targets.back(); - m->targets.pop_back(); + while (!D->targets.empty()) { + delete D->targets.back(); + D->targets.pop_back(); } - while (!m->tofree.empty()) { - free(m->tofree.back()); - m->tofree.pop_back(); + while (!D->tofree.empty()) { + free(D->tofree.back()); + D->tofree.pop_back(); } - delete m; + delete D; return 0; } diff --git a/src/gui/lua/lua_misc.cpp b/src/gui/lua/lua_misc.cpp index eb26b19c9..2c173fe0f 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 @@ -36,6 +39,8 @@ /* autogenerated from luainstance.h */ #include "lua_api_version.h" +extern CVolume* g_volume; + CLuaInstMisc* CLuaInstMisc::getInstance() { static CLuaInstMisc* LuaInstMisc = NULL; @@ -57,6 +62,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 }, @@ -83,6 +93,14 @@ int CLuaInstMisc::MiscNew(lua_State *L) int CLuaInstMisc::strFind(lua_State *L) { + /* workaround for deprecated functions */ + CLuaMisc *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = MiscCheckData(L, 1); + if (!D) return 0; + } + /* CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; */ int numargs = lua_gettop(L); if (numargs < 3) { printf("CLuaInstMisc::%s: not enough arguments (%d, expected 2 (or 3 or 4))\n", __func__, numargs); @@ -115,6 +133,14 @@ int CLuaInstMisc::strFind(lua_State *L) int CLuaInstMisc::strSub(lua_State *L) { + /* workaround for deprecated functions */ + CLuaMisc *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = MiscCheckData(L, 1); + if (!D) return 0; + } + /* CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; */ int numargs = lua_gettop(L); if (numargs < 3) { printf("CLuaInstMisc::%s: not enough arguments (%d, expected 2 (or 3))\n", __func__, numargs); @@ -139,6 +165,14 @@ int CLuaInstMisc::strSub(lua_State *L) int CLuaInstMisc::enableInfoClock(lua_State *L) { + /* workaround for deprecated functions */ + CLuaMisc *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = MiscCheckData(L, 1); + if (!D) return 0; + } + /* CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; */ bool enable = true; int numargs = lua_gettop(L); if (numargs > 1) @@ -147,8 +181,76 @@ int CLuaInstMisc::enableInfoClock(lua_State *L) return 0; } +int CLuaInstMisc::enableMuteIcon(lua_State *L) +{ + CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; + 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) +{ + CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; + 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) +{ + CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; + lua_pushinteger(L, g_settings.current_volume); + return 1; +} + +int CLuaInstMisc::AudioMute(lua_State *L) +{ + CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; + 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) +{ + CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; + lua_pushboolean(L, CNeutrinoApp::getInstance()->isMuted()); + return 1; +} + int CLuaInstMisc::runScriptExt(lua_State *L) { + /* workaround for deprecated functions */ + CLuaMisc *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = MiscCheckData(L, 1); + if (!D) return 0; + } + /* CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; */ int numargs = lua_gettop(L); const char *script = luaL_checkstring(L, 2); std::vector args; @@ -167,6 +269,14 @@ int CLuaInstMisc::runScriptExt(lua_State *L) int CLuaInstMisc::GetRevision(lua_State *L) { + /* workaround for deprecated functions */ + CLuaMisc *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = MiscCheckData(L, 1); + if (!D) return 0; + } + /* CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; */ unsigned int rev = 0; std::string hw = ""; #if HAVE_COOL_HARDWARE @@ -180,6 +290,14 @@ int CLuaInstMisc::GetRevision(lua_State *L) int CLuaInstMisc::checkVersion(lua_State *L) { + /* workaround for deprecated functions */ + CLuaMisc *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = MiscCheckData(L, 1); + if (!D) return 0; + } + /* CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; */ int numargs = lua_gettop(L); if (numargs < 3) { printf("CLuaInstMisc::%s: not enough arguments (%d, expected 2)\n", __func__, numargs); @@ -204,6 +322,8 @@ int CLuaInstMisc::checkVersion(lua_State *L) int CLuaInstMisc::postMsg(lua_State *L) { + CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; lua_Integer msg = 0; neutrino_msg_t post_msg = 0; msg = luaL_checkint(L, 2); @@ -221,6 +341,7 @@ int CLuaInstMisc::postMsg(lua_State *L) int CLuaInstMisc::MiscDelete(lua_State *L) { CLuaMisc *D = MiscCheckData(L, 1); + if (!D) return 0; delete D; return 0; } 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/lua_threads.cpp b/src/gui/lua/lua_threads.cpp new file mode 100644 index 000000000..8885f7ea2 --- /dev/null +++ b/src/gui/lua/lua_threads.cpp @@ -0,0 +1,389 @@ +/****************************************************************************** +* Copyright (c) 2011 by Robert G. Jakabosky +* Copyright (c) 2015 M. Liebmann (micha-bbg) +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "lua_threads.h" + +int __strerror_r(int err, char* buf, size_t len) +{ + memset(buf, '\0', len); + snprintf(buf, len-1, "%s", strerror(err)); + return 0; +} + +CLLThread* CLLThread::getInstance() +{ + static CLLThread* llthreadInst = NULL; + + if (!llthreadInst) + llthreadInst = new CLLThread(); + return llthreadInst; +} + +void CLLThread::llthread_log(lua_State *L, const char *hdr, const char *msg) +{ + int top = lua_gettop(L); + lua_rawgetp(L, LUA_REGISTRYINDEX, LLTHREAD_LOGGER_HOLDER); + if (lua_isnil(L, -1)) { + lua_pop(L, 1); + fputs(hdr, stderr); + fputs(msg, stderr); + fputc('\n', stderr); + fflush(stderr); + return; + } + lua_pushstring(L, hdr); + lua_pushstring(L, msg); + lua_concat(L, 2); + lua_pcall(L, 1, 0, 0); + lua_settop(L, top); +} + +int CLLThread::fail(lua_State *L, const char *msg) +{ + lua_pushnil(L); + lua_pushstring(L, msg); + return 2; +} + +int CLLThread::traceback (lua_State *L) +{ + const char *msg = lua_tostring(L, 1); + if (msg) + luaL_traceback(L, L, msg, 1); + else if (!lua_isnoneornil(L, 1)) { /* is there an error object? */ + if (!luaL_callmeta(L, 1, "__tostring")) /* try its 'tostring' metamethod */ + lua_pushliteral(L, "(no error message)"); + } + return 1; +} + +void CLLThread::open_thread_libs(lua_State *L) +{ + /* Not yet tested calling thread from thread out */ + /* LuaThreadsRegister(L); */ + + /* luainstance.cpp */ + LuaInstRegisterFunctions(L, true); +} + +llthread_child_t *CLLThread::llthread_child_new() +{ + llthread_child_t *_this = ALLOC_STRUCT(llthread_child_t); + if (!_this) return NULL; + + memset(_this, 0, sizeof(llthread_child_t)); + + /* create new lua_State for the thread. */ + /* open standard libraries. */ + _this->L = luaL_newstate(); + open_thread_libs(_this->L); + + return _this; +} + +llthread_t *CLLThread::llthread_new() +{ + llthread_t *_this = ALLOC_STRUCT(llthread_t); + if (!_this) return NULL; + + _this->flags = FLAG_NONE; + _this->child = llthread_child_new(); + if (!_this->child) { + FREE_STRUCT(_this); + return NULL; + } + return _this; +} + +int CLLThread::llthread_push_args(lua_State *L, llthread_child_t *child, int idx, int top) +{ + return llthread_copy_values(L, child->L, idx, top, 1 /* is_arg */); +} + +int CLLThread::llthread_push_results(lua_State *L, llthread_child_t *child, int idx, int top) +{ + return llthread_copy_values(child->L, L, idx, top, 0 /* is_arg */); +} + +void CLLThread::llthread_validate(llthread_t *_this) +{ + /* describe valid state of llthread_t object + * from after create and before destroy + */ + if (!IS(_this, STARTED)) { + assert(!IS(_this, DETACHED)); + assert(!IS(_this, JOINED)); + assert(!IS(_this, JOINABLE)); + return; + } + + if (IS(_this, DETACHED)) { + if (!IS(_this, JOINABLE)) assert(_this->child == NULL); + else assert(_this->child != NULL); + } +} + +llthread_t *CLLThread::llthread_create(lua_State *L, const char *code, size_t code_len) +{ + llthread_t *_this = llthread_new(); + llthread_child_t *child = _this->child; + + /* load Lua code into child state. */ + int rc = luaL_loadbuffer(child->L, code, code_len, code); + if (rc != 0) { + /* copy error message to parent state. */ + size_t len; const char *str = lua_tolstring(child->L, -1, &len); + if (str != NULL) { + lua_pushlstring(L, str, len); + } else { + /* non-string error message. */ + lua_pushfstring(L, "luaL_loadbuffer() failed to load Lua code: rc=%d", rc); + } + /* llthread_destroy(_this); */ + lua_error(L); + return NULL; + } + + /* copy extra args from main state to child state. */ + /* Push all args after the Lua code. */ + llthread_push_args(L, child, 3, lua_gettop(L)); + + llthread_validate(_this); + + return _this; +} + +llthread_t *CLLThread::l_llthread_at (lua_State *L, int i) +{ + llthread_t **_this = (llthread_t **) luaL_checkudata(L, i, LLTHREAD_TAG); + return *_this; +} + +void CLLThread::llthread_child_destroy(llthread_child_t *_this) +{ + lua_close(_this->L); + FREE_STRUCT(_this); +} + +void CLLThread::llthread_cleanup_child(llthread_t *_this) +{ + if (_this->child) { + llthread_child_destroy(_this->child); + _this->child = NULL; + } +} + +int CLLThread::llthread_detach(llthread_t *_this) +{ + int rc = 0; + + assert(IS(_this, STARTED)); + assert(_this->child != NULL); + + _this->child = NULL; + + /*we can not detach joined thread*/ + if (IS(_this, JOINED)) + return 0; + + rc = pthread_detach(_this->thread); + return rc; +} + +void* CLLThread::llthread_child_thread_run(void *arg) +{ + llthread_child_t *_this = (llthread_child_t *)arg; + lua_State *L = _this->L; + int nargs = lua_gettop(L) - 1; + + /* push traceback function as first value on stack. */ + lua_pushcfunction(_this->L, traceback); + lua_insert(L, 1); + + _this->status = lua_pcall(L, nargs, LUA_MULTRET, 1); + + /* alwasy print errors here, helps with debugging bad code. */ + if (_this->status != 0) { + llthread_log(L, "Error from thread: ", lua_tostring(L, -1)); + } + + if (IS(_this, DETACHED) || !IS(_this, JOINABLE)) { + /* thread is detached, so it must clean-up the child state. */ + llthread_child_destroy(_this); + _this = NULL; + } + + return _this; +} + +int CLLThread::llthread_start(llthread_t *_this, int start_detached, int joinable) +{ + llthread_child_t *child = _this->child; + int rc = 0; + + llthread_validate(_this); + + if (joinable) SET(child, JOINABLE); + if (start_detached) SET(child, DETACHED); + + rc = pthread_create(&(_this->thread), NULL, llthread_child_thread_run, child); + + if (rc == 0) { + SET(_this, STARTED); + if (joinable) SET(_this, JOINABLE); + if (start_detached) SET(_this, DETACHED); + if ((start_detached)&&(!joinable)) { + rc = llthread_detach(_this); + } + } + + llthread_validate(_this); + + return rc; +} + +int CLLThread::llthread_cancel(llthread_t *_this) +{ + llthread_validate(_this); + + if (IS(_this, JOINED)) { + return JOIN_OK; + } else { + int rc = pthread_cancel(_this->thread); + if (rc == 0) { + return JOIN_ETIMEDOUT; + } + + if (rc != ESRCH) { + /*@fixme what else it can be ?*/ + return rc; + } + + return JOIN_OK; + } +} + +int CLLThread::llthread_join(llthread_t *_this, join_timeout_t timeout) +{ + llthread_validate(_this); + + if (IS(_this, JOINED)) { + return JOIN_OK; + } else { + int rc; + if (timeout == 0) { + rc = pthread_kill(_this->thread, 0); + if (rc == 0) { /* still alive */ + return JOIN_ETIMEDOUT; + } + + if (rc != ESRCH) { + /*@fixme what else it can be ?*/ + return rc; + } + + /*thread dead so we call join to free pthread_t struct */ + } + + /* @todo use pthread_tryjoin_np/pthread_timedjoin_np to support timeout */ + + /* then join the thread. */ + rc = pthread_join(_this->thread, NULL); + if ((rc == 0) || (rc == ESRCH)) { + SET(_this, JOINED); + rc = JOIN_OK; + } + + llthread_validate(_this); + + return rc; + } +} + +void CLLThread::llthread_destroy(llthread_t *_this) +{ + do { + /* thread not started */ + if (!IS(_this, STARTED)) { + llthread_cleanup_child(_this); + break; + } + + /* DETACHED */ + if (IS(_this, DETACHED)) { + if (IS(_this, JOINABLE)) { + llthread_detach(_this); + } + break; + } + + /* ATTACHED */ + if (!IS(_this, JOINED)) { + llthread_join(_this, INFINITE_JOIN_TIMEOUT); + if (!IS(_this, JOINED)) { + /* @todo use current lua state to logging */ + /* + * char buf[ERROR_LEN]; + * strerror_r(errno, buf, ERROR_LEN); + * llthread_log(L, "Error can not join thread on gc: ", buf); + */ + } + } + if (IS(_this, JOINABLE)) { + llthread_cleanup_child(_this); + } + + } while (0); + + FREE_STRUCT(_this); +} + +int CLLThread::llthread_alive(llthread_t *_this) +{ + llthread_validate(_this); + + if (IS(_this, JOINED)) { + return JOIN_OK; + } else { + int rc = pthread_kill(_this->thread, 0); + if (rc == 0) { /* still alive */ + return JOIN_ETIMEDOUT; + } + + if (rc != ESRCH) { + /*@fixme what else it can be ?*/ + return rc; + } + return JOIN_OK; + } +} diff --git a/src/gui/lua/lua_threads.h b/src/gui/lua/lua_threads.h new file mode 100644 index 000000000..324e43ccd --- /dev/null +++ b/src/gui/lua/lua_threads.h @@ -0,0 +1,153 @@ +/****************************************************************************** +* Copyright (c) 2011 by Robert G. Jakabosky +* Copyright (c) 2015 M. Liebmann (micha-bbg) +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ + +#ifndef _LLTHREAD_H_ +#define _LLTHREAD_H_ + +extern "C" +{ +#include +#include +#include +} +#include + +/* wrap strerror_r(). */ +#ifndef strerror_r +#define strerror_r __strerror_r +#endif + +#define OS_THREAD_RETURN void * +#define INFINITE_JOIN_TIMEOUT -1 +#define JOIN_OK 0 +#define JOIN_ETIMEDOUT ETIMEDOUT +typedef int join_timeout_t; +typedef pthread_t os_thread_t; + +#define ERROR_LEN 1024 + +#define flags_t unsigned char + +#define FLAG_NONE (flags_t)0 +#define FLAG_STARTED (flags_t)1<<0 +#define FLAG_DETACHED (flags_t)1<<1 +#define FLAG_JOINED (flags_t)1<<2 +#define FLAG_JOINABLE (flags_t)1<<3 + +/*At least one flag*/ +#define FLAG_IS_SET(O, F) (O->flags & (flags_t)(F)) +#define FLAG_SET(O, F) O->flags |= (flags_t)(F) +#define FLAG_UNSET(O, F) O->flags &= ~((flags_t)(F)) +#define IS(O, F) FLAG_IS_SET(O, FLAG_##F) +#define SET(O, F) FLAG_SET(O, FLAG_##F) + +#define ALLOC_STRUCT(S) (S*)calloc(1, sizeof(S)) +#define FREE_STRUCT(O) free(O) + +#define LLTHREAD_NAME "threads" +#define LLTHREAD_TAG LLTHREAD_NAME +#define LLTHREAD_LOGGER_HOLDER LLTHREAD_NAME " logger holder" + +typedef struct llthread_child_t { + lua_State* L; + int status; + flags_t flags; +} llthread_child_t; + +typedef struct llthread_t { + llthread_child_t* child; + os_thread_t thread; + flags_t flags; +} llthread_t; + +typedef struct { + lua_State* from_L; + lua_State* to_L; + int has_cache; + int cache_idx; + int is_arg; +} llthread_copy_state; + +#if LUA_VERSION_NUM >= 503 /* Lua 5.3 */ + +#ifndef luaL_optint +# define luaL_optint luaL_optinteger +#endif + +#ifndef luaL_checkint +# define luaL_checkint luaL_checkinteger +#endif + +#endif /* Lua 5.3 */ + +int __strerror_r(int err, char* buf, size_t len); + +class CLLThread +{ + public: + CLLThread() {}; +// ~CLLThread() {}; + static CLLThread* getInstance(); + static void LuaThreadsRegister(lua_State *L); + + private: + static void llthread_log(lua_State *L, const char *hdr, const char *msg); + static int fail(lua_State *L, const char *msg); + static int traceback (lua_State *L); + static void open_thread_libs(lua_State *L); + static llthread_child_t *llthread_child_new(); + static llthread_t *llthread_new(); + static int llthread_push_args(lua_State *L, llthread_child_t *child, int idx, int top); + static int llthread_push_results(lua_State *L, llthread_child_t *child, int idx, int top); + static void llthread_validate(llthread_t *_this); + static llthread_t *llthread_create(lua_State *L, const char *code, size_t code_len); + static llthread_t *l_llthread_at (lua_State *L, int i); + static void llthread_child_destroy(llthread_child_t *_this); + static void llthread_cleanup_child(llthread_t *_this); + static int llthread_detach(llthread_t *_this); + static void* llthread_child_thread_run(void *arg); + static int llthread_start(llthread_t *_this, int start_detached, int joinable); + static int llthread_cancel(llthread_t *_this); + static int llthread_join(llthread_t *_this, join_timeout_t timeout); + static void llthread_destroy(llthread_t *_this); + static int llthread_alive(llthread_t *_this); + + /* copy.cpp */ + static int llthread_copy_table_from_cache(llthread_copy_state *state, int idx); + static int llthread_copy_value(llthread_copy_state *state, int depth, int idx); + static int llthread_copy_values(lua_State *from_L, lua_State *to_L, int idx, int top, int is_arg); + + /* lua_functions.cpp */ + static int l_llthread_new(lua_State *L); + static int l_llthread_start(lua_State *L); + static int l_llthread_cancel(lua_State *L); + static int l_llthread_join(lua_State *L); + static int l_llthread_alive(lua_State *L); + static int l_llthread_set_logger(lua_State *L); + static int l_llthread_started(lua_State *L); + static int l_llthread_detached(lua_State *L); + static int l_llthread_joinable(lua_State *L); + static int l_llthread_delete(lua_State *L); +}; + +#endif // _LLTHREAD_H_ diff --git a/src/gui/lua/lua_threads_copy.cpp b/src/gui/lua/lua_threads_copy.cpp new file mode 100644 index 000000000..a7d140018 --- /dev/null +++ b/src/gui/lua/lua_threads_copy.cpp @@ -0,0 +1,167 @@ +/****************************************************************************** +* Copyright (c) 2011 by Robert G. Jakabosky +* Copyright (c) 2015 M. Liebmann (micha-bbg) +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ + +#include "lua_threads.h" + +/* maximum recursive depth of table copies. */ +#define MAX_COPY_DEPTH 30 + +int CLLThread::llthread_copy_table_from_cache(llthread_copy_state *state, int idx) +{ + void *ptr; + + /* convert table to pointer for lookup in cache. */ + ptr = (void *)lua_topointer(state->from_L, idx); + if (ptr == NULL) return 0; /* can't convert to pointer. */ + + /* check if we need to create the cache. */ + if (!state->has_cache) { + lua_newtable(state->to_L); + lua_replace(state->to_L, state->cache_idx); + state->has_cache = 1; + } + + lua_pushlightuserdata(state->to_L, ptr); + lua_rawget(state->to_L, state->cache_idx); + if (lua_isnil(state->to_L, -1)) { + /* not in cache. */ + lua_pop(state->to_L, 1); + /* create new table and add to cache. */ + lua_newtable(state->to_L); + lua_pushlightuserdata(state->to_L, ptr); + lua_pushvalue(state->to_L, -2); + lua_rawset(state->to_L, state->cache_idx); + return 0; + } + /* found table in cache. */ + return 1; +} + +int CLLThread::llthread_copy_value(llthread_copy_state *state, int depth, int idx) +{ + const char *str; + size_t str_len; + + /* Maximum recursive depth */ + if (++depth > MAX_COPY_DEPTH) { + return luaL_error(state->from_L, "Hit maximum copy depth (%d > %d).", depth, MAX_COPY_DEPTH); + } + + /* only support string/number/boolean/nil/table/lightuserdata. */ + switch (lua_type(state->from_L, idx)) { + case LUA_TNIL: + lua_pushnil(state->to_L); + break; + case LUA_TNUMBER: + lua_pushnumber(state->to_L, lua_tonumber(state->from_L, idx)); + break; + case LUA_TBOOLEAN: + lua_pushboolean(state->to_L, lua_toboolean(state->from_L, idx)); + break; + case LUA_TSTRING: + str = lua_tolstring(state->from_L, idx, &(str_len)); + lua_pushlstring(state->to_L, str, str_len); + break; + case LUA_TLIGHTUSERDATA: + lua_pushlightuserdata(state->to_L, lua_touserdata(state->from_L, idx)); + break; + case LUA_TTABLE: + /* make sure there is room on the new state for 3 values (table,key,value) */ + if (!lua_checkstack(state->to_L, 3)) { + return luaL_error(state->from_L, "To stack overflow!"); + } + /* make room on from stack for key/value pairs. */ + luaL_checkstack(state->from_L, 2, "From stack overflow!"); + + /* check cache for table. */ + if (llthread_copy_table_from_cache(state, idx)) { + /* found in cache don't need to copy table. */ + break; + } + lua_pushnil(state->from_L); + while (lua_next(state->from_L, idx) != 0) { + /* key is at (top - 1), value at (top), but we need to normalize these + * to positive indices */ + int kv_pos = lua_gettop(state->from_L); + /* copy key */ + llthread_copy_value(state, depth, kv_pos - 1); + /* copy value */ + llthread_copy_value(state, depth, kv_pos); + /* Copied key and value are now at -2 and -1 in state->to_L. */ + lua_settable(state->to_L, -3); + /* Pop value for next iteration */ + lua_pop(state->from_L, 1); + } + break; + case LUA_TFUNCTION: + if (lua_iscfunction(state->from_L, idx)) { + lua_CFunction fn = lua_tocfunction(state->from_L, idx); + lua_pushcfunction(state->to_L, fn); + break; + } + case LUA_TUSERDATA: + case LUA_TTHREAD: + default: + if (state->is_arg) { + return luaL_argerror(state->from_L, idx, "function/userdata/thread types un-supported."); + } else { + /* convert un-supported types to an error string. */ + lua_pushfstring(state->to_L, "Un-supported value: %s: %p", + lua_typename(state->from_L, lua_type(state->from_L, idx)), lua_topointer(state->from_L, idx)); + } + } + + return 1; +} + +int CLLThread::llthread_copy_values(lua_State *from_L, lua_State *to_L, int idx, int top, int is_arg) +{ + llthread_copy_state state; + int nvalues = 0; + int n; + + nvalues = (top - idx) + 1; + /* make sure there is room on the new state for the values. */ + if (!lua_checkstack(to_L, nvalues + 1)) { + return luaL_error(from_L, "To stack overflow!"); + } + + /* setup copy state. */ + state.from_L = from_L; + state.to_L = to_L; + state.is_arg = is_arg; + state.has_cache = 0; /* don't create cache table unless it is needed. */ + lua_pushnil(to_L); + state.cache_idx = lua_gettop(to_L); + + nvalues = 0; + for (n = idx; n <= top; n++) { + llthread_copy_value(&state, 0, n); + ++nvalues; + } + + /* remove cache table. */ + lua_remove(to_L, state.cache_idx); + + return nvalues; +} diff --git a/src/gui/lua/lua_threads_functions.cpp b/src/gui/lua/lua_threads_functions.cpp new file mode 100644 index 000000000..3d8f210cc --- /dev/null +++ b/src/gui/lua/lua_threads_functions.cpp @@ -0,0 +1,271 @@ +/****************************************************************************** +* Copyright (c) 2011 by Robert G. Jakabosky +* Copyright (c) 2015 M. Liebmann (micha-bbg) +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include "lua_threads.h" + +void CLLThread::LuaThreadsRegister(lua_State *L) +{ + luaL_Reg meth[] = { + { "new", CLLThread::l_llthread_new }, + { "start", CLLThread::l_llthread_start }, + { "cancel", CLLThread::l_llthread_cancel }, + { "join", CLLThread::l_llthread_join }, +#if 0 + /* Fix me */ + { "set_logger", CLLThread::l_llthread_set_logger }, +#endif + { "started", CLLThread::l_llthread_started }, + { "detached", CLLThread::l_llthread_detached }, + { "joinable", CLLThread::l_llthread_joinable }, + { "__gc", CLLThread::l_llthread_delete }, + { NULL, NULL } + }; + + luaL_newmetatable(L, LLTHREAD_TAG); + luaL_setfuncs(L, meth, 0); + lua_pushvalue(L, -1); + lua_setfield(L, -1, "__index"); + lua_setglobal(L, LLTHREAD_TAG); +} + +int CLLThread::l_llthread_new(lua_State *L) +{ + size_t lua_code_len; const char *lua_code = luaL_checklstring(L, 1, &lua_code_len); + + llthread_t **_this = (llthread_t **) lua_newuserdata(L, sizeof(llthread_t *)); + luaL_getmetatable(L, LLTHREAD_TAG); + lua_setmetatable(L, -2); + lua_insert(L, 2); /*move self prior args*/ + *_this = llthread_create(L, lua_code, lua_code_len); + + lua_settop(L, 2); + return 1; +} + +int CLLThread::l_llthread_start(lua_State *L) +{ + llthread_t *_this = l_llthread_at(L, 1); + if (!_this) return 0; + int start_detached = lua_toboolean(L, 2); + int joinable, rc; + + if (!lua_isnone(L, 3)) + joinable = lua_toboolean(L, 3); + else + joinable = start_detached ? 0 : 1; + + if (IS(_this, STARTED)) { + return fail(L, "Thread already started."); + } + + rc = llthread_start(_this, start_detached, joinable); + if (rc != 0) { + char buf[ERROR_LEN]; + strerror_r(errno, buf, ERROR_LEN); + return fail(L, buf); + } + + lua_settop(L, 1); // return _this + return 1; +} + +int CLLThread::l_llthread_cancel(lua_State *L) +{ + llthread_t *_this = l_llthread_at(L, 1); + if (!_this) return 0; + /* llthread_child_t *child = _this->child; */ + int rc; + + if (!IS(_this, STARTED )) { + return fail(L, "Can't cancel a thread that hasn't be started."); + } + if ( IS(_this, DETACHED)) { + return fail(L, "Can't cancel a thread that has been detached."); + } + if ( IS(_this, JOINED )) { + return fail(L, "Can't cancel a thread that has already been joined."); + } + + /* cancel the thread. */ + rc = llthread_cancel(_this); + + if ( rc == JOIN_ETIMEDOUT ) { + lua_pushboolean(L, 1); + return 1; + } + + if (rc == JOIN_OK) { + lua_pushboolean(L, 0); + return 1; + } + + char buf[ERROR_LEN]; + strerror_r(errno, buf, ERROR_LEN); + /* llthread_cleanup_child(_this); */ + return fail(L, buf); +} + +int CLLThread::l_llthread_join(lua_State *L) +{ + llthread_t *_this = l_llthread_at(L, 1); + if (!_this) return 0; + llthread_child_t *child = _this->child; + int rc; + + if (!IS(_this, STARTED )) { + return fail(L, "Can't join a thread that hasn't be started."); + } + if ( IS(_this, DETACHED) && !IS(_this, JOINABLE)) { + return fail(L, "Can't join a thread that has been detached."); + } + if ( IS(_this, JOINED )) { + return fail(L, "Can't join a thread that has already been joined."); + } + + /* join the thread. */ + rc = llthread_join(_this, luaL_optint(L, 2, INFINITE_JOIN_TIMEOUT)); + + if (child && IS(_this, JOINED)) { + int top; + + if (IS(_this, DETACHED) || !IS(_this, JOINABLE)) { + /*child lua state has been destroyed by child thread*/ + /*@todo return thread exit code*/ + lua_pushboolean(L, 1); + lua_pushnumber(L, 0); + return 2; + } + + /* copy values from child lua state */ + if (child->status != 0) { + const char *err_msg = lua_tostring(child->L, -1); + lua_pushboolean(L, 0); + lua_pushfstring(L, "Error from child thread: %s", err_msg); + top = 2; + } else { + lua_pushboolean(L, 1); + top = lua_gettop(child->L); + /* return results to parent thread. */ + llthread_push_results(L, child, 2, top); + } + +// llthread_cleanup_child(_this); + return top; + } + + if ( rc == JOIN_ETIMEDOUT ) { + return fail(L, "timeout"); + } + + char buf[ERROR_LEN]; + strerror_r(errno, buf, ERROR_LEN); + /* llthread_cleanup_child(_this); */ + return fail(L, buf); +} + +int CLLThread::l_llthread_alive(lua_State *L) +{ + llthread_t *_this = l_llthread_at(L, 1); + if (!_this) return 0; + /* llthread_child_t *child = _this->child; */ + int rc; + + if (!IS(_this, STARTED )) { + return fail(L, "Can't join a thread that hasn't be started."); + } + if ( IS(_this, DETACHED) && !IS(_this, JOINABLE)) { + return fail(L, "Can't join a thread that has been detached."); + } + if ( IS(_this, JOINED )) { + return fail(L, "Can't join a thread that has already been joined."); + } + + /* join the thread. */ + rc = llthread_alive(_this); + + if ( rc == JOIN_ETIMEDOUT ) { + lua_pushboolean(L, 1); + return 1; + } + + if (rc == JOIN_OK) { + lua_pushboolean(L, 0); + return 1; + } + + char buf[ERROR_LEN]; + strerror_r(errno, buf, ERROR_LEN); + /* llthread_cleanup_child(_this); */ + return fail(L, buf); +} + +int CLLThread::l_llthread_set_logger(lua_State *L) +{ + lua_settop(L, 1); + luaL_argcheck(L, lua_isfunction(L, 1), 1, "function expected"); + lua_rawsetp(L, LUA_REGISTRYINDEX, LLTHREAD_LOGGER_HOLDER); + return 0; +} + +int CLLThread::l_llthread_started(lua_State *L) +{ + llthread_t *_this = l_llthread_at(L, 1); + if (!_this) return 0; + lua_pushboolean(L, IS(_this, STARTED)?1:0); + return 1; +} + +int CLLThread::l_llthread_detached(lua_State *L) +{ + llthread_t *_this = l_llthread_at(L, 1); + if (!_this) return 0; + lua_pushboolean(L, IS(_this, DETACHED)?1:0); + return 1; +} + +int CLLThread::l_llthread_joinable(lua_State *L) +{ + llthread_t *_this = l_llthread_at(L, 1); + if (!_this) return 0; + lua_pushboolean(L, IS(_this, JOINABLE)?1:0); + return 1; +} + +int CLLThread::l_llthread_delete(lua_State *L) +{ + llthread_t **pthis = (llthread_t **)luaL_checkudata(L, 1, LLTHREAD_TAG); + luaL_argcheck (L, pthis != NULL, 1, "thread expected"); + if (*pthis == NULL) return 0; + llthread_destroy(*pthis); + *pthis = NULL; + + return 0; +} diff --git a/src/gui/lua/lua_video.cpp b/src/gui/lua/lua_video.cpp index 5dc90e6b4..5dc3e26cf 100644 --- a/src/gui/lua/lua_video.cpp +++ b/src/gui/lua/lua_video.cpp @@ -85,6 +85,14 @@ int CLuaInstVideo::VideoNew(lua_State *L) int CLuaInstVideo::setBlank(lua_State *L) { + /* workaround for deprecated functions */ + CLuaVideo *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = VideoCheckData(L, 1); + if (!D) return 0; + } + /* CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; */ bool enable = true; int numargs = lua_gettop(L); if (numargs > 1) @@ -95,19 +103,43 @@ int CLuaInstVideo::setBlank(lua_State *L) int CLuaInstVideo::ShowPicture(lua_State *L) { + /* workaround for deprecated functions */ + CLuaVideo *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = VideoCheckData(L, 1); + if (!D) return 0; + } + /* CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; */ const char *fname = luaL_checkstring(L, 2); CFrameBuffer::getInstance()->showFrame(fname); return 0; } -int CLuaInstVideo::StopPicture(lua_State */*L*/) +int CLuaInstVideo::StopPicture(lua_State *L) { + /* workaround for deprecated functions */ + CLuaVideo *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = VideoCheckData(L, 1); + if (!D) return 0; + } + /* CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; */ CFrameBuffer::getInstance()->stopFrame(); return 0; } int CLuaInstVideo::PlayFile(lua_State *L) { + /* workaround for deprecated functions */ + CLuaVideo *D = NULL; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = VideoCheckData(L, 1); + if (!D) return 0; + } + /* CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; */ LUA_DEBUG("CLuaInstVideo::%s %d\n", __func__, lua_gettop(L)); int numargs = lua_gettop(L); @@ -117,10 +149,8 @@ int CLuaInstVideo::PlayFile(lua_State *L) } bool sp = false; - if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { - CLuaVideo *D = VideoCheckData(L, 1); + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) sp = D->singlePlay; - } if ((sp == false) && (CMoviePlayerGui::getInstance().getBlockedFromPlugin() == false)) CMoviePlayerGui::getInstance().setBlockedFromPlugin(true); @@ -149,6 +179,14 @@ int CLuaInstVideo::PlayFile(lua_State *L) int CLuaInstVideo::zapitStopPlayBack(lua_State *L) { + /* workaround for deprecated functions */ + CLuaVideo *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = VideoCheckData(L, 1); + if (!D) return 0; + } + /* CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; */ bool stop = true; int numargs = lua_gettop(L); if (numargs > 1) @@ -162,8 +200,16 @@ int CLuaInstVideo::zapitStopPlayBack(lua_State *L) return 0; } -int CLuaInstVideo::channelRezap(lua_State */*L*/) +int CLuaInstVideo::channelRezap(lua_State *L) { + /* workaround for deprecated functions */ + CLuaVideo *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = VideoCheckData(L, 1); + if (!D) return 0; + } + /* CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; */ CNeutrinoApp::getInstance()->channelRezap(); if (CNeutrinoApp::getInstance()->getMode() == CNeutrinoApp::mode_radio) CFrameBuffer::getInstance()->showFrame("radiomode.jpg"); @@ -172,6 +218,14 @@ int CLuaInstVideo::channelRezap(lua_State */*L*/) int CLuaInstVideo::createChannelIDfromUrl(lua_State *L) { + /* workaround for deprecated functions */ + CLuaVideo *D; + if (luaL_testudata(L, 1, LUA_CLASSNAME) == NULL) { + D = VideoCheckData(L, 1); + if (!D) return 0; + } + /* CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; */ int numargs = lua_gettop(L); if (numargs < 2) { printf("CLuaInstVideo::%s: no arguments\n", __func__); @@ -195,18 +249,21 @@ int CLuaInstVideo::createChannelIDfromUrl(lua_State *L) int CLuaInstVideo::getNeutrinoMode(lua_State *L) { + CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; lua_pushinteger(L, (lua_Integer)CNeutrinoApp::getInstance()->getMode()); return 1; } int CLuaInstVideo::setSinglePlay(lua_State *L) { + CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; bool mode = true; int numargs = lua_gettop(L); if (numargs > 1) mode = _luaL_checkbool(L, 2); - CLuaVideo *D = VideoCheckData(L, 1); D->singlePlay = mode; return 0; } @@ -214,6 +271,7 @@ int CLuaInstVideo::setSinglePlay(lua_State *L) int CLuaInstVideo::VideoDelete(lua_State *L) { CLuaVideo *D = VideoCheckData(L, 1); + if (!D) return 0; delete D; return 0; } diff --git a/src/gui/lua/lua_video.h b/src/gui/lua/lua_video.h index f4ae6a216..6668f3a5b 100644 --- a/src/gui/lua/lua_video.h +++ b/src/gui/lua/lua_video.h @@ -35,6 +35,7 @@ class CLuaInstVideo ~CLuaInstVideo() {}; static CLuaInstVideo* getInstance(); static void LuaVideoRegister(lua_State *L); + static int channelRezap(lua_State *L); /* deprecated functions */ static int setBlank_old(lua_State *L); @@ -53,7 +54,6 @@ class CLuaInstVideo static int StopPicture(lua_State *L); static int PlayFile(lua_State *L); static int zapitStopPlayBack(lua_State *L); - static int channelRezap(lua_State *L); static int createChannelIDfromUrl(lua_State *L); static int getNeutrinoMode(lua_State *L); static int setSinglePlay(lua_State *L); diff --git a/src/gui/lua/luainstance.cpp b/src/gui/lua/luainstance.cpp index f70fe2d07..177cca979 100644 --- a/src/gui/lua/luainstance.cpp +++ b/src/gui/lua/luainstance.cpp @@ -46,12 +46,14 @@ #include "lua_menue.h" #include "lua_messagebox.h" #include "lua_misc.h" +#include "lua_threads.h" #include "lua_video.h" /* autogenerated from luainstance.h */ #include "lua_api_version.h" extern CPictureViewer * g_PicViewer; +extern cVideo * videoDecoder; static void set_lua_variables(lua_State *L) { @@ -405,7 +407,7 @@ CLuaInstance::CLuaInstance() lua = luaL_newstate(); /* register standard + custom functions. */ - registerFunctions(); + LuaInstRegisterFunctions(lua); } CLuaInstance::~CLuaInstance() @@ -470,7 +472,8 @@ void CLuaInstance::runScript(const char *fileName, std::vector *arg if (CMoviePlayerGui::getInstance().getBlockedFromPlugin()) { CMoviePlayerGui::getInstance().setBlockedFromPlugin(false); CMoviePlayerGui::getInstance().restoreNeutrino(); - } + } else if (videoDecoder->getBlank()) + CLuaInstVideo::getInstance()->channelRezap(lua); } } @@ -511,50 +514,6 @@ void CLuaInstance::abortScript() lua_sethook(lua, &abortHook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); } -const luaL_Reg CLuaInstance::methods[] = -{ - { "GetInput", CLuaInstance::GetInput }, - { "Blit", CLuaInstance::Blit }, - { "GetLanguage", CLuaInstance::GetLanguage }, - { "PaintBox", CLuaInstance::PaintBox }, - { "paintHLine", CLuaInstance::paintHLineRel }, - { "paintVLine", CLuaInstance::paintVLineRel }, - { "RenderString", CLuaInstance::RenderString }, - { "getRenderWidth", CLuaInstance::getRenderWidth }, - { "FontHeight", CLuaInstance::FontHeight }, - { "getDynFont", CLuaInstance::getDynFont }, - { "PaintIcon", CLuaInstance::PaintIcon }, - { "DisplayImage", CLuaInstance::DisplayImage }, - { "GetSize", CLuaInstance::GetSize }, - { "saveScreen", CLuaInstance::saveScreen }, - { "restoreScreen", CLuaInstance::restoreScreen }, - { "deleteSavedScreen", CLuaInstance::deleteSavedScreen }, - - /* - lua_misc.cpp - Deprecated, for the future separate class for misc functions - */ - { "strFind", CLuaInstMisc::getInstance()->strFind_old }, - { "strSub", CLuaInstMisc::getInstance()->strSub_old }, - { "enableInfoClock", CLuaInstMisc::getInstance()->enableInfoClock_old }, - { "runScript", CLuaInstMisc::getInstance()->runScriptExt_old }, - { "GetRevision", CLuaInstMisc::getInstance()->GetRevision_old }, - { "checkVersion", CLuaInstMisc::getInstance()->checkVersion_old }, - - /* - lua_video.cpp - Deprecated, for the future separate class for video - */ - { "setBlank", CLuaInstVideo::getInstance()->setBlank_old }, - { "ShowPicture", CLuaInstVideo::getInstance()->ShowPicture_old }, - { "StopPicture", CLuaInstVideo::getInstance()->StopPicture_old }, - { "PlayFile", CLuaInstVideo::getInstance()->PlayFile_old }, - { "zapitStopPlayBack", CLuaInstVideo::getInstance()->zapitStopPlayBack_old }, - { "channelRezap", CLuaInstVideo::getInstance()->channelRezap_old }, - { "createChannelIDfromUrl", CLuaInstVideo::getInstance()->createChannelIDfromUrl_old }, - { NULL, NULL } -}; - #ifdef STATIC_LUAPOSIX /* hack: we link against luaposix, which is included in our * custom built lualib */ @@ -562,47 +521,101 @@ extern "C" { LUAMOD_API int (luaopen_posix_c) (lua_State *L); } #endif /* load basic functions and register our own C callbacks */ -void CLuaInstance::registerFunctions() +void LuaInstRegisterFunctions(lua_State *L, bool fromThreads/*=false*/) { - luaL_openlibs(lua); - luaopen_table(lua); - luaopen_io(lua); - luaopen_string(lua); - luaopen_math(lua); - lua_newtable(lua); - int methodtable = lua_gettop(lua); - luaL_newmetatable(lua, className); - int metatable = lua_gettop(lua); - lua_pushliteral(lua, "__metatable"); - lua_pushvalue(lua, methodtable); - lua_settable(lua, metatable); +// ------------------------------------------ + const luaL_Reg methods[] = + { + { "GetInput", CLuaInstance::GetInput }, + { "Blit", CLuaInstance::Blit }, + { "GetLanguage", CLuaInstance::GetLanguage }, + { "PaintBox", CLuaInstance::PaintBox }, + { "paintHLine", CLuaInstance::paintHLineRel }, + { "paintVLine", CLuaInstance::paintVLineRel }, + { "RenderString", CLuaInstance::RenderString }, + { "getRenderWidth", CLuaInstance::getRenderWidth }, + { "FontHeight", CLuaInstance::FontHeight }, + { "getDynFont", CLuaInstance::getDynFont }, + { "PaintIcon", CLuaInstance::PaintIcon }, + { "DisplayImage", CLuaInstance::DisplayImage }, + { "GetSize", CLuaInstance::GetSize }, + { "saveScreen", CLuaInstance::saveScreen }, + { "restoreScreen", CLuaInstance::restoreScreen }, + { "deleteSavedScreen", CLuaInstance::deleteSavedScreen }, - lua_pushliteral(lua, "__index"); - lua_pushvalue(lua, methodtable); - lua_settable(lua, metatable); + /* + lua_misc.cpp + Deprecated, for the future using separate class for misc functions + */ + { "strFind", CLuaInstMisc::getInstance()->strFind_old }, + { "strSub", CLuaInstMisc::getInstance()->strSub_old }, + { "enableInfoClock", CLuaInstMisc::getInstance()->enableInfoClock_old }, + { "runScript", CLuaInstMisc::getInstance()->runScriptExt_old }, + { "GetRevision", CLuaInstMisc::getInstance()->GetRevision_old }, + { "checkVersion", CLuaInstMisc::getInstance()->checkVersion_old }, - lua_pushliteral(lua, "__gc"); - lua_pushcfunction(lua, GCWindow); - lua_settable(lua, metatable); + /* + lua_video.cpp + Deprecated, for the future using separate class for video + */ + { "setBlank", CLuaInstVideo::getInstance()->setBlank_old }, + { "ShowPicture", CLuaInstVideo::getInstance()->ShowPicture_old }, + { "StopPicture", CLuaInstVideo::getInstance()->StopPicture_old }, + { "PlayFile", CLuaInstVideo::getInstance()->PlayFile_old }, + { "zapitStopPlayBack", CLuaInstVideo::getInstance()->zapitStopPlayBack_old }, + { "channelRezap", CLuaInstVideo::getInstance()->channelRezap_old }, + { "createChannelIDfromUrl", CLuaInstVideo::getInstance()->createChannelIDfromUrl_old }, + { NULL, NULL } + }; +// ------------------------------------------ + int top; + if (fromThreads) + top = lua_gettop(L); - lua_pop(lua, 1); + luaL_openlibs(L); + luaopen_table(L); + luaopen_io(L); + luaopen_string(L); + luaopen_math(L); + lua_newtable(L); + int methodtable = lua_gettop(L); + luaL_newmetatable(L, LUA_CLASSNAME); + int metatable = lua_gettop(L); + lua_pushliteral(L, "__metatable"); + lua_pushvalue(L, methodtable); + lua_settable(L, metatable); - luaL_setfuncs(lua, methods, 0); - lua_pop(lua, 1); + lua_pushliteral(L, "__index"); + lua_pushvalue(L, methodtable); + lua_settable(L, metatable); - lua_register(lua, className, NewWindow); + lua_pushliteral(L, "__gc"); + lua_pushcfunction(L, CLuaInstance::GCWindow); + lua_settable(L, metatable); - CLuaInstCCPicture::getInstance()->CCPictureRegister(lua); - CLuaInstCCSignalbox::getInstance()->CCSignalBoxRegister(lua); - CLuaInstCCText::getInstance()->CCTextRegister(lua); - CLuaInstCCWindow::getInstance()->CCWindowRegister(lua); - CLuaInstConfigFile::getInstance()->LuaConfigFileRegister(lua); - CLuaInstCurl::getInstance()->LuaCurlRegister(lua); - CLuaInstHintbox::getInstance()->HintboxRegister(lua); - CLuaInstMenu::getInstance()->MenuRegister(lua); - CLuaInstMessagebox::getInstance()->MessageboxRegister(lua); - CLuaInstMisc::getInstance()->LuaMiscRegister(lua); - CLuaInstVideo::getInstance()->LuaVideoRegister(lua); + lua_pop(L, 1); + + luaL_setfuncs(L, methods, 0); + lua_pop(L, 1); + + lua_register(L, LUA_CLASSNAME, CLuaInstance::NewWindow); + + if (fromThreads) + lua_settop(L, top); +// ------------------------------------------ + CLuaInstCCPicture::getInstance()->CCPictureRegister(L); + CLuaInstCCSignalbox::getInstance()->CCSignalBoxRegister(L); + CLuaInstCCText::getInstance()->CCTextRegister(L); + CLuaInstCCWindow::getInstance()->CCWindowRegister(L); + CLuaInstConfigFile::getInstance()->LuaConfigFileRegister(L); + CLuaInstCurl::getInstance()->LuaCurlRegister(L); + CLuaInstHintbox::getInstance()->HintboxRegister(L); + CLuaInstMenu::getInstance()->MenuRegister(L); + CLuaInstMessagebox::getInstance()->MessageboxRegister(L); + CLuaInstMisc::getInstance()->LuaMiscRegister(L); + CLuaInstVideo::getInstance()->LuaVideoRegister(L); + if (!fromThreads) + CLLThread::getInstance()->LuaThreadsRegister(L); } CLuaData *CLuaInstance::CheckData(lua_State *L, int narg) @@ -656,13 +669,15 @@ int CLuaInstance::GCWindow(lua_State *L) CNeutrinoFonts::getInstance()->deleteDynFontExtAll(); /* restoreNeutrino at plugin closing, when blocked from plugin */ - LUA_DEBUG(">>>>[%s:%d] (restoreNeutrino()) BlockedFromPlugin: %d, Playing: %d\n", __func__, __LINE__, - CMoviePlayerGui::getInstance().getBlockedFromPlugin, CMoviePlayerGui::getInstance().Playing()); - if (CMoviePlayerGui::getInstance().getBlockedFromPlugin() && - CMoviePlayerGui::getInstance().Playing()) { + bool block = CMoviePlayerGui::getInstance().getBlockedFromPlugin(); + bool play = CMoviePlayerGui::getInstance().Playing(); + LUA_DEBUG(">>>>[%s:%d] (restoreNeutrino()) BlockedFromPlugin: %d, Playing: %d\n", __func__, __LINE__, block, play); + if (block && play) { CMoviePlayerGui::getInstance().setBlockedFromPlugin(false); CMoviePlayerGui::getInstance().restoreNeutrino(); } + else if (videoDecoder->getBlank()) + CLuaInstVideo::getInstance()->channelRezap(L); delete w->fbwin; w->rcinput = NULL; @@ -677,8 +692,7 @@ int CLuaInstance::GetInput(lua_State *L) neutrino_msg_t msg; neutrino_msg_data_t data; CLuaData *W = CheckData(L, 1); - if (!W) - return 0; + if (!W) return 0; if (numargs > 1) timeout = luaL_checkint(L, 2); W->rcinput->getMsg_ms(&msg, &data, timeout); @@ -732,8 +746,7 @@ int CLuaInstance::PaintBox(lua_State *L) lua_Unsigned c; CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; x = luaL_checkint(L, 2); y = luaL_checkint(L, 3); w = luaL_checkint(L, 4); @@ -765,8 +778,7 @@ int CLuaInstance::paintHLineRel(lua_State *L) lua_Unsigned c; CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; x = luaL_checkint(L, 2); dx = luaL_checkint(L, 3); y = luaL_checkint(L, 4); @@ -789,8 +801,7 @@ int CLuaInstance::paintVLineRel(lua_State *L) lua_Unsigned c; CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; x = luaL_checkint(L, 2); y = luaL_checkint(L, 3); dy = luaL_checkint(L, 4); @@ -822,8 +833,7 @@ int CLuaInstance::RenderString(lua_State *L) center = 0; CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; int step = 0; bool isDynFont = false; @@ -888,8 +898,7 @@ int CLuaInstance::getRenderWidth(lua_State *L) LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); CLuaData *W = CheckData(L, 1); - if (!W) - return 0; + if (!W) return 0; int step = 0; bool isDynFont = false; @@ -932,8 +941,7 @@ int CLuaInstance::FontHeight(lua_State *L) LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); CLuaData *W = CheckData(L, 1); - if (!W) - return 0; + if (!W) return 0; int step = 0; bool isDynFont = false; @@ -972,8 +980,7 @@ int CLuaInstance::getDynFont(lua_State *L) { int numargs = lua_gettop(L); CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; if (numargs < 3) { printf("CLuaInstance::%s: not enough arguments (%d, expected 2)\n", __func__, numargs); @@ -1030,8 +1037,7 @@ int CLuaInstance::PaintIcon(lua_State *L) const char *fname; CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; fname = luaL_checkstring(L, 2); x = luaL_checkint(L, 3); y = luaL_checkint(L, 4); @@ -1043,6 +1049,8 @@ int CLuaInstance::PaintIcon(lua_State *L) int CLuaInstance::DisplayImage(lua_State *L) { + CLuaData *W = CheckData(L, 1); + if (!W) return 0; LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); int x, y, w, h; const char *fname; @@ -1061,6 +1069,8 @@ int CLuaInstance::DisplayImage(lua_State *L) int CLuaInstance::GetSize(lua_State *L) { + CLuaData *W = CheckData(L, 1); + if (!W) return 0; LUA_DEBUG("CLuaInstance::%s %d\n", __func__, lua_gettop(L)); int w = 0, h = 0; const char *fname; @@ -1079,8 +1089,7 @@ int CLuaInstance::saveScreen(lua_State *L) int x, y, w, h; fb_pixel_t* buf; CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; x = luaL_checkint(L, 2); y = luaL_checkint(L, 3); w = luaL_checkint(L, 4); @@ -1100,8 +1109,7 @@ int CLuaInstance::restoreScreen(lua_State *L) fb_pixel_t* buf = NULL; bool del; CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; x = luaL_checkint(L, 2); y = luaL_checkint(L, 3); w = luaL_checkint(L, 4); @@ -1126,8 +1134,7 @@ int CLuaInstance::deleteSavedScreen(lua_State *L) { int id; CLuaData *W = CheckData(L, 1); - if (!W || !W->fbwin) - return 0; + if (!W || !W->fbwin) return 0; id = luaL_checkint(L, 2); for (screenmap_iterator_t it = W->screenmap.begin(); it != W->screenmap.end(); ++it) { diff --git a/src/gui/lua/luainstance.h b/src/gui/lua/luainstance.h index 75ff2094a..7f0510e05 100644 --- a/src/gui/lua/luainstance.h +++ b/src/gui/lua/luainstance.h @@ -26,21 +26,22 @@ extern "C" { #include } #include +#include #include #include "luainstance_helpers.h" #if 0 #define LUA_API_VERSION_MAJOR 1 -#define LUA_API_VERSION_MINOR 33 +#define LUA_API_VERSION_MINOR 35 #endif +void LuaInstRegisterFunctions(lua_State *L, bool fromThreads=false); + /* inspired by Steve Kemp http://www.steve.org.uk/ */ class CLuaInstance { static const char className[]; - static const luaL_Reg methods[]; - static const luaL_Reg menu_methods[]; static CLuaData *CheckData(lua_State *L, int narg); public: CLuaInstance(); @@ -60,10 +61,6 @@ public: // The last parameter to NULL is imperative. void runScript(const char *fileName, const char *arg0, ...); -private: - lua_State* lua; - void registerFunctions(); - static int NewWindow(lua_State *L); static int GCWindow(lua_State *L); static int GetInput(lua_State *L); @@ -82,6 +79,10 @@ private: static int saveScreen(lua_State *L); static int restoreScreen(lua_State *L); static int deleteSavedScreen(lua_State *L); + +private: + lua_State* lua; + }; #endif /* _LUAINSTANCE_H */ diff --git a/src/gui/moviebrowser.cpp b/src/gui/moviebrowser.cpp index 763b4b664..3dc85ccc7 100644 --- a/src/gui/moviebrowser.cpp +++ b/src/gui/moviebrowser.cpp @@ -3956,11 +3956,11 @@ int CDirMenu::exec(CMenuTarget* parent, const std::string & actionKey) { int returnval = menu_return::RETURN_REPAINT; + if (parent) + parent->hide(); + if (actionKey.empty()) { - if (parent) - parent->hide(); - changed = false; return show(); } diff --git a/src/gui/personalize.cpp b/src/gui/personalize.cpp index 617fa1351..7dcc700f4 100644 --- a/src/gui/personalize.cpp +++ b/src/gui/personalize.cpp @@ -60,6 +60,10 @@ const bool item_mode = optional, default true, if you don't want to see this item in personalize menue, then set it to false CMenuItem *observer_Item = optional, default NULL, if you want to observe this item with another item (observer), then use this prameter. Effect: this observed item will be deactivated, if observer is set to 'visible' or 'pin-protected' + menu_item_disable_cond_t& disable_condition = optional, default DCOND_MODE_NONE + Effect: on used condition eg. DCOND_MODE_TS, this item is disabled in mode_ts + Also usable are combined conditions: eg: DCOND_MODE_TV | DCOND_MODE_TS, this item is disabled in mode_tv and mode_ts + More possible conditions are defined in menue.h. Icon handling: If you define an icon in the item object, this will be shown in the personalized menu but not the personilazitions menue itself, otherwise a shortcut will be create @@ -155,7 +159,7 @@ #include #include #include - +#include #include #include #include @@ -628,7 +632,7 @@ int CPersonalizeGui::ShowMenuOptions(const int& widget) //found observer item and if found, then define 'this' as observer for current option chooser and run changeNotify bool is_observer = isObserver(v_item[i].widget, v_item[i].menuItem) ? true : false; CChangeObserver* observer = is_observer ? this : NULL; - CMenuOptionChooser * opt = new CMenuOptionChooser(name, p_mode, PERSONALIZE_MODE_OPTIONS, PERSONALIZE_MODE_MAX, v_item[i].menuItem->active, observer); + CMenuOptionChooser * opt = new CMenuOptionChooser(name, p_mode, PERSONALIZE_MODE_OPTIONS, PERSONALIZE_MODE_MAX, v_item[i].menuItem->current_active, observer); if (is_observer) changeNotify(name, (void*)p_mode); @@ -832,20 +836,20 @@ void CPersonalizeGui::addIntroItems(CMenuWidget *widget) //overloaded version from 'addItem', first parameter is an id from widget collection 'v_widget' -void CPersonalizeGui::addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item) +void CPersonalizeGui::addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item, const menu_item_disable_cond_t& disable_condition) { - addItem(v_widget[widget_id], menu_Item, personalize_mode, defaultselected, item_mode, observer_Item); + addItem(v_widget[widget_id], menu_Item, personalize_mode, defaultselected, item_mode, observer_Item, disable_condition); } //adds a personalized menu item object to menu with personalizing parameters -void CPersonalizeGui::addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item) +void CPersonalizeGui::addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode, const bool defaultselected, const int& item_mode, CMenuItem *observer_Item, const menu_item_disable_cond_t& disable_condition) { if (observer_Item != NULL) addObservedItem(widget, observer_Item, menu_Item); - CMenuForwarder *fw = static_cast (menu_Item); + CMenuForwarder *fw = static_cast (menu_Item); - menu_item_t item = {widget, menu_Item, defaultselected, fw->getTextLocale(), (int*)personalize_mode, item_mode, observer_Item}; + menu_item_t item = {widget, menu_Item, defaultselected, fw->getTextLocale(), (int*)personalize_mode, item_mode, observer_Item, disable_condition}; if (item_mode == PERSONALIZE_SHOW_AS_ACCESS_OPTION) { @@ -873,10 +877,10 @@ void CPersonalizeGui::addSeparator(const int& widget_id, const neutrino_locale_t void CPersonalizeGui::addSeparator(CMenuWidget &widget, const neutrino_locale_t locale_text, const int& item_mode) { if (locale_text == NONEXISTANT_LOCALE) { - menu_item_t to_add_sep = {&widget, GenericMenuSeparatorLine, false, locale_text, NULL, item_mode, NULL}; + menu_item_t to_add_sep = {&widget, GenericMenuSeparatorLine, false, locale_text, NULL, item_mode, NULL, DCOND_MODE_NONE }; v_item.push_back(to_add_sep); } else { - menu_item_t to_add_sep = {&widget, new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, locale_text), false, locale_text, NULL, item_mode, NULL}; + menu_item_t to_add_sep = {&widget, new CMenuSeparator(CMenuSeparator::LINE | CMenuSeparator::STRING, locale_text), false, locale_text, NULL, item_mode, NULL, DCOND_MODE_NONE }; v_item.push_back(to_add_sep); } } @@ -911,7 +915,7 @@ void CPersonalizeGui::addPersonalizedItems() //get current mode of personlize itself int in_pinmode = hasPinItems() ? PERSONALIZE_PROTECT_MODE_PIN_PROTECTED : PERSONALIZE_PROTECT_MODE_NOT_PROTECTED; - for (uint i = 0; i < v_item.size(); i++) + for (uint i = 0; i < v_item.size(); i++) { int i_mode = v_item[i].item_mode; @@ -941,6 +945,7 @@ void CPersonalizeGui::addPersonalizedItems() neutrino_msg_t d_key = fw->directKey; bool add_shortcut = false; + //get shortcut if (fw->active && (d_key == CRCInput::RC_nokey || CRCInput::isNumeric(d_key))) //if RC_nokey or RC_key is digi and item is active, allow to generate a shortcut, { @@ -967,6 +972,14 @@ void CPersonalizeGui::addPersonalizedItems() use_pin, fw->active, NULL, fw->getTarget(), fw->getActionKey(), d_key, NULL, lock_icon); v_item[i].menuItem->hintIcon = fw->hintIcon; v_item[i].menuItem->hint = fw->hint; + + //assign slot for items, causes disable/enable by condition eg: receiver mode + if (v_item[i].condition != DCOND_MODE_NONE ){ + sigc::slot0 sl = sigc::bind<0>(sigc::mem_fun1(v_item[i].menuItem, &CMenuForwarder::disableByCondition), v_item[i].condition); + v_item[i].menuItem->OnPaintItem.connect(sl); + v_item[i].default_selected = false; + } + //add item if it's set to visible or pin protected and allow to add an forwarder as next if (p_mode != PERSONALIZE_MODE_NOTVISIBLE || i_mode == PERSONALIZE_SHOW_AS_ACCESS_OPTION) { diff --git a/src/gui/personalize.h b/src/gui/personalize.h index fb84f80b5..0ffcb24f9 100644 --- a/src/gui/personalize.h +++ b/src/gui/personalize.h @@ -111,6 +111,7 @@ typedef struct menu_item_t int* personalize_mode; int item_mode; CMenuItem *observer_Item; + int condition; }menu_item_struct_t; typedef struct observ_menu_item_t @@ -242,8 +243,8 @@ class CPersonalizeGui : public CMenuTarget, public CChangeObserver, public CPINP int getItemsCount(CMenuWidget *widget); int getItemsCount(const int& widget_id); void setShortcut(const int& short_cut = 1) {shortcut = short_cut;}; - void addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode = NULL, const bool defaultselected = false, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION, CMenuItem *observer_Item = NULL); - void addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode = NULL, const bool defaultselected = false, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION, CMenuItem *observer_Item = NULL); + void addItem(CMenuWidget *widget, CMenuItem *menu_Item, const int *personalize_mode = NULL, const bool defaultselected = false, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION, CMenuItem *observer_Item = NULL, const menu_item_disable_cond_t& disable_condition = DCOND_MODE_NONE ); + void addItem(const int& widget_id, CMenuItem *menu_Item, const int *personalize_mode = NULL, const bool defaultselected = false, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION, CMenuItem *observer_Item = NULL, const menu_item_disable_cond_t& disable_condition = DCOND_MODE_NONE ); void addIntroItems(CMenuWidget *widget); void addIntroItems(const int& widget_id); void addSeparator(CMenuWidget &menu, const neutrino_locale_t locale_text = NONEXISTANT_LOCALE, const int& item_mode = PERSONALIZE_SHOW_AS_ITEM_OPTION); diff --git a/src/gui/update.cpp b/src/gui/update.cpp index 260111e2b..de5415bf7 100644 --- a/src/gui/update.cpp +++ b/src/gui/update.cpp @@ -517,7 +517,7 @@ int CFlashUpdate::exec(CMenuTarget* parent, const std::string &actionKey) return menu_return::RETURN_REPAINT; } if(softupdate_mode==1) { //internet-update - if ( ShowMsg(LOCALE_MESSAGEBOX_INFO, (fileType < '3') ? "Flash downloaded image ?" : "Install downloaded pack ?", CMessageBox::mbrYes, CMessageBox::mbYes | CMessageBox::mbNo, NEUTRINO_ICON_UPDATE) != CMessageBox::mbrYes) // UTF-8 + if ( ShowMsg(LOCALE_MESSAGEBOX_INFO, (fileType < '3') ? LOCALE_FLASHUPDATE_INSTALL_IMAGE : LOCALE_FLASHUPDATE_INSTALL_PACKAGE, CMessageBox::mbrYes, CMessageBox::mbYes | CMessageBox::mbNo, NEUTRINO_ICON_UPDATE) != CMessageBox::mbrYes) // UTF-8 { hide(); return menu_return::RETURN_REPAINT; diff --git a/src/gui/widget/menue.cpp b/src/gui/widget/menue.cpp index ffd366c77..6e5c3e5b8 100644 --- a/src/gui/widget/menue.cpp +++ b/src/gui/widget/menue.cpp @@ -59,7 +59,7 @@ CMenuForwarder * const GenericMenuNext = &CGenericMenuNext; CMenuItem::CMenuItem(bool Active, neutrino_msg_t DirectKey, const char * const IconName, const char * const IconName_Info_right, bool IsStatic) { - active = Active; + active = current_active = Active; directKey = DirectKey; isStatic = IsStatic; @@ -89,6 +89,7 @@ CMenuItem::CMenuItem(bool Active, neutrino_msg_t DirectKey, const char * const I selected_iconName = NULL; height = 0; actObserv = NULL; + parent_widget = NULL; } void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX) @@ -104,7 +105,7 @@ void CMenuItem::init(const int X, const int Y, const int DX, const int OFFX) void CMenuItem::setActive(const bool Active) { - active = Active; + active = current_active = Active; /* used gets set by the addItem() function. This is for disabling machine-specific options by just not calling the addItem() function. Without this, the changeNotifiers would become machine-dependent. */ @@ -112,6 +113,48 @@ void CMenuItem::setActive(const bool Active) paint(); } +bool CMenuItem::initModeCondition(const int& stb_mode) +{ + if (CNeutrinoApp::getInstance()->getMode() == stb_mode){ + active = false; + marked = false; + if (parent_widget) + if (!isSelectable()) + parent_widget->initSelectable(); + return true; + } + printf("\033[33m[CMenuItem] [%s - %d] missmatching stb mode condition %d\033[0m\n", __func__, __LINE__, stb_mode); + return false; +} + +void CMenuItem::disableByCondition(const menu_item_disable_cond_t& condition) +{ + int stb_mode = CNeutrinoApp::getInstance()->getMode(); + + if (condition & DCOND_MODE_TS){ + if (stb_mode == CNeutrinoApp::mode_ts) + if (initModeCondition(stb_mode)) + return; + } + if (condition & DCOND_MODE_RADIO){ + if (stb_mode == CNeutrinoApp::mode_radio) + if (initModeCondition(stb_mode)) + return; + } + if (condition & DCOND_MODE_TV){ + if (stb_mode == CNeutrinoApp::mode_tv) + if (initModeCondition(stb_mode)) + return; + } + + active = current_active; + + if (parent_widget){ + if (!isSelectable()) + parent_widget->initSelectable(); + } +} + void CMenuItem::setMarked(const bool Marked) { marked = Marked; @@ -297,6 +340,9 @@ void CMenuItem::paintItemButton(const bool select_mode, int item_height, const c //get data of number icon and paint if (icon_name && *icon_name) { + if (!active) + icon_name = NEUTRINO_ICON_BUTTON_DUMMY_SMALL; + frameBuffer->getIconSize(icon_name, &icon_w, &icon_h); if (/*active &&*/ icon_w>0 && icon_h>0 && icon_space_x >= icon_w) @@ -605,6 +651,7 @@ void CMenuWidget::addItem(CMenuItem* menuItem, const bool defaultselected) menuItem->isUsed(); items.push_back(menuItem); + menuItem->setParentWidget(this); } void CMenuWidget::resetWidget(bool delete_items) @@ -668,12 +715,7 @@ int CMenuWidget::exec(CMenuTarget* parent, const std::string &) neutrino_msg_data_t data; bool bAllowRepeatLR = false; CVFD::MODES oldLcdMode = CVFD::getInstance()->getMode(); - - int pos = 0; - if (selected > 0 && selected < (int)items.size()) - pos = selected; - else - selected = -1; + exit_pressed = false; frameBuffer->Lock(); @@ -693,21 +735,22 @@ int CMenuWidget::exec(CMenuTarget* parent, const std::string &) } } } - /* make sure we start with a selectable item... */ - while (pos < (int)items.size()) { - if (items[pos]->isSelectable()) - break; - pos++; - } + checkHints(); if(savescreen) { calcSize(); saveScreen(); } + + /* make sure we start with a selectable item... */ + initSelectable(); + paint(); frameBuffer->blit(); + int pos = selected; + int retval = menu_return::RETURN_REPAINT; uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]); @@ -1131,6 +1174,22 @@ void CMenuWidget::calcSize() setMenuPos(full_width); } +void CMenuWidget::initSelectable() +{ + int pos = 0; + if (selected > 0 && selected < (int)items.size()) + pos = selected; + else + selected = -1; + + while (pos < (int)items.size()) { + if (items[pos]->isSelectable()) + break; + pos++; + } + selected = pos; +} + void CMenuWidget::paint() { calcSize(); @@ -1217,16 +1276,16 @@ void CMenuWidget::paintItems() * different height and this might leave artifacts otherwise after changing pages */ frameBuffer->paintBoxRel(x,item_start_y, width,item_height, COL_MENUCONTENT_PLUS_0); } + int ypos=item_start_y; for (int count = 0; count < (int)items.size(); count++) { CMenuItem* item = items[count]; - + item->OnPaintItem(); if ((count >= page_start[current_page]) && (count < page_start[current_page + 1])) { item->init(x, ypos, width, iconOffset); - if (item->isSelectable() && selected == -1) selected = count; @@ -2123,7 +2182,8 @@ std::string CMenuForwarder::getOption(void) int CMenuForwarder::paint(bool selected) { - std::string option_name = getOption(); + std::string option_name = getOption(); + fb_pixel_t bgcol = 0; if (jumpTarget) bgcol = jumpTarget->getColor(); @@ -2136,7 +2196,7 @@ int CMenuForwarder::paint(bool selected) //caption paintItemCaption(selected, option_name.c_str(), bgcol); - + return y+ height; } diff --git a/src/gui/widget/menue.h b/src/gui/widget/menue.h index 3fb863451..1d55bfbab 100644 --- a/src/gui/widget/menue.h +++ b/src/gui/widget/menue.h @@ -56,7 +56,8 @@ extern "C" { #define NO_WIDGET_ID -1 typedef int mn_widget_id_t; - +typedef int menu_item_disable_cond_t; +class CMenuWidget; struct menu_return { enum @@ -69,6 +70,15 @@ struct menu_return }; }; +enum +{ + DCOND_MODE_NONE = 1, + + DCOND_MODE_TV = 2, + DCOND_MODE_RADIO = 4, + DCOND_MODE_TS = 8 +}/*menu_item_disable_cond_t*/; + class CChangeObserver { public: @@ -104,15 +114,16 @@ class CMenuTarget virtual fb_pixel_t getColor(void) { return 0; } }; -class CMenuItem +class CMenuItem : public CComponentsSignals { private: void setIconName(); + CMenuWidget* parent_widget; protected: int x, y, dx, offx, name_start_x, icon_frame_w; bool used; fb_pixel_t item_color, item_bgcolor; - + bool initModeCondition(const int& stb_mode); void initItemColors(const bool select_mode); lua_State *luaState; std::string luaAction; @@ -124,7 +135,7 @@ class CMenuItem CActivateObserver * actObserv; public: int height; - bool active; + bool active, current_active; bool marked; bool inert; bool isStatic; @@ -157,7 +168,7 @@ class CMenuItem } virtual int getYPosition(void) const { return y; } - virtual bool isSelectable(void) const { return active; } + virtual bool isSelectable(void) const { return (active && current_active); } virtual int exec(CMenuTarget* /*parent*/) { @@ -166,9 +177,9 @@ class CMenuItem virtual void setActive(const bool Active); virtual void setMarked(const bool Marked); virtual void setInert(const bool Inert); - + virtual void paintItemButton(const bool select_mode, int item_height, const char * const icon_Name = NEUTRINO_ICON_BUTTON_RIGHT); - + virtual void prepareItem(const bool select_mode, const int &item_height); virtual void setItemButton(const char * const icon_Name, const bool is_select_button = false); @@ -180,17 +191,20 @@ class CMenuItem virtual int isMenueOptionChooser(void) const{return 0;} void setHint(const char * const icon, const neutrino_locale_t text) { hintIcon = (icon && *icon) ? icon : NULL; hint = text; } void setHint(const char * const icon, const std::string text) { hintIcon = (icon && *icon) ? icon : NULL; hintText = text; } + void setLua(lua_State *_luaState, std::string &_luaAction, std::string &_luaId) { luaState = _luaState; luaAction = _luaAction; luaId = _luaId; }; virtual const char *getName(); virtual void setName(const std::string& text); virtual void setName(const neutrino_locale_t text); - + sigc::signal OnPaintItem; virtual const char *getDescription(); virtual void setDescription(const std::string& text); virtual void setDescription(const neutrino_locale_t text); virtual int getDescriptionHeight(void); void setActivateObserver(CActivateObserver * Observ) { actObserv = Observ; } void activateNotify(void); + virtual void disableByCondition(const menu_item_disable_cond_t& condition); + void setParentWidget(CMenuWidget* parent){parent_widget = parent;} }; class CMenuSeparator : public CMenuItem @@ -355,7 +369,7 @@ struct CMenuOptionChooserCompareItem: public std::binary_function setHint(NEUTRINO_ICON_HINT_MB, LOCALE_MENU_HINT_MB); - personalize.addItem(MENU_MAIN, mb, &g_settings.personalize[SNeutrinoSettings::P_MPLAYER_MBROWSER]); + personalize.addItem(MENU_MAIN, mb, &g_settings.personalize[SNeutrinoSettings::P_MPLAYER_MBROWSER], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, NULL, DCOND_MODE_TS); } #if 0 CMenuForwarder *cl = new CMenuForwarder(LOCALE_MAINMENU_CHANNELS, true, NULL, this, "channels", CRCInput::RC_green); @@ -168,17 +168,17 @@ void CNeutrinoApp::InitMenuMain() //tv <-> radio toggle CMenuForwarder *tvradio_switch = new CMenuForwarder(LOCALE_MAINMENU_TVRADIO_SWITCH, true, NULL, this, "tv_radio_switch", CRCInput::RC_red); tvradio_switch->setHint(NEUTRINO_ICON_HINT_TVRADIO_SWITCH, LOCALE_MENU_HINT_TVRADIO_SWITCH); - personalize.addItem(MENU_MAIN, tvradio_switch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_TV_RADIO_MODE]); + personalize.addItem(MENU_MAIN, tvradio_switch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_TV_RADIO_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, NULL, DCOND_MODE_TS); //tv-mode CMenuForwarder *tvswitch = new CMenuForwarder(LOCALE_MAINMENU_TVMODE, true, NULL, this, "tv", CRCInput::RC_red); tvswitch->setHint(NEUTRINO_ICON_HINT_TVMODE, LOCALE_MENU_HINT_TVMODE); - personalize.addItem(MENU_MAIN, tvswitch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_TV_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, tvradio_switch); //observed + personalize.addItem(MENU_MAIN, tvswitch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_TV_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, tvradio_switch, DCOND_MODE_TV | DCOND_MODE_TS); //observed //radio-mode CMenuForwarder *radioswitch = new CMenuForwarder(LOCALE_MAINMENU_RADIOMODE, true, NULL, this, "radio", CRCInput::RC_green); radioswitch->setHint(NEUTRINO_ICON_HINT_RADIOMODE, LOCALE_MENU_HINT_RADIOMODE); - personalize.addItem(MENU_MAIN, radioswitch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_RADIO_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, tvradio_switch); //observed + personalize.addItem(MENU_MAIN, radioswitch, &g_settings.personalize[SNeutrinoSettings::P_MAIN_RADIO_MODE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, tvradio_switch, DCOND_MODE_RADIO | DCOND_MODE_TS); //observed } //timer @@ -489,7 +489,7 @@ void CNeutrinoApp::InitMenuService() // channel scan mf = new CMenuForwarder(LOCALE_SERVICEMENU_SCANTS , true, NULL, CScanSetup::getInstance(), "", CRCInput::RC_green); mf->setHint(NEUTRINO_ICON_HINT_SERVICE_SCAN, LOCALE_MENU_HINT_SERVICE_SCAN); - personalize.addItem(MENU_SERVICE, mf, &g_settings.personalize[SNeutrinoSettings::P_MSER_SCANTS]); + personalize.addItem(MENU_SERVICE, mf, &g_settings.personalize[SNeutrinoSettings::P_MSER_SCANTS], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, NULL, DCOND_MODE_TS); if (!g_settings.easymenu) { //reload channels @@ -564,5 +564,5 @@ void CNeutrinoApp::InitMenuService() mf = new CMenuForwarder(LOCALE_SERVICEMENU_UPDATE, true, NULL, new CSoftwareUpdate()); mf->setHint(NEUTRINO_ICON_HINT_SW_UPDATE, LOCALE_MENU_HINT_SW_UPDATE); - personalize.addItem(MENU_SERVICE, mf, &g_settings.personalize[SNeutrinoSettings::P_MSER_SOFTUPDATE]); + personalize.addItem(MENU_SERVICE, mf, &g_settings.personalize[SNeutrinoSettings::P_MSER_SOFTUPDATE], false, CPersonalizeGui::PERSONALIZE_SHOW_AS_ITEM_OPTION, NULL, DCOND_MODE_TS); } diff --git a/src/system/locals.h b/src/system/locals.h index ed0b4642a..2b7c5cfc8 100644 --- a/src/system/locals.h +++ b/src/system/locals.h @@ -639,6 +639,8 @@ typedef enum LOCALE_FLASHUPDATE_GETUPDATEFILEERROR, LOCALE_FLASHUPDATE_GLOBALPROGRESS, LOCALE_FLASHUPDATE_HEAD, + LOCALE_FLASHUPDATE_INSTALL_IMAGE, + LOCALE_FLASHUPDATE_INSTALL_PACKAGE, LOCALE_FLASHUPDATE_MD5CHECK, LOCALE_FLASHUPDATE_MD5SUMERROR, LOCALE_FLASHUPDATE_MENU_APPLY_KERNEL, diff --git a/src/system/locals_intern.h b/src/system/locals_intern.h index 3bd5b0347..407159852 100644 --- a/src/system/locals_intern.h +++ b/src/system/locals_intern.h @@ -639,6 +639,8 @@ const char * locale_real_names[] = "flashupdate.getupdatefileerror", "flashupdate.globalprogress", "flashupdate.head", + "flashupdate.install_image", + "flashupdate.install_package", "flashupdate.md5check", "flashupdate.md5sumerror", "flashupdate.menu_apply_kernel",