mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-29 16:31:05 +02:00
CLuaInstance: Move msg box functions in separate classes / files
- hintbox
- messagebox
- No api changes, code only
Origin commit data
------------------
Branch: ni/coolstream
Commit: b904febf6a
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2015-12-12 (Sat, 12 Dec 2015)
------------------
This commit was generated by Migit
This commit is contained in:
@@ -36,5 +36,7 @@ libneutrino_gui_lua_a_SOURCES = \
|
||||
lua_cc_text.cpp \
|
||||
lua_cc_window.cpp \
|
||||
lua_configfile.cpp \
|
||||
lua_hintbox.cpp \
|
||||
lua_menue.cpp \
|
||||
lua_messagebox.cpp \
|
||||
lua_video.cpp
|
||||
|
176
src/gui/lua/lua_hintbox.cpp
Normal file
176
src/gui/lua/lua_hintbox.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* lua hintbox
|
||||
*
|
||||
* (C) 2014 by martii
|
||||
* (C) 2014-2015 M. Liebmann (micha-bbg)
|
||||
* (C) 2014 Sven Hoefer (svenhoefer)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <global.h>
|
||||
#include <system/debug.h>
|
||||
#include <gui/widget/hintbox.h>
|
||||
#include <neutrino.h>
|
||||
|
||||
#include "luainstance.h"
|
||||
#include "lua_hintbox.h"
|
||||
|
||||
CLuaInstHintbox* CLuaInstHintbox::getInstance()
|
||||
{
|
||||
static CLuaInstHintbox* LuaInstHintbox = NULL;
|
||||
|
||||
if(!LuaInstHintbox)
|
||||
LuaInstHintbox = new CLuaInstHintbox();
|
||||
return LuaInstHintbox;
|
||||
}
|
||||
|
||||
void CLuaInstHintbox::HintboxRegister(lua_State *L)
|
||||
{
|
||||
luaL_Reg meth[] = {
|
||||
{ "new", CLuaInstHintbox::HintboxNew },
|
||||
{ "exec", CLuaInstHintbox::HintboxExec },
|
||||
{ "paint", CLuaInstHintbox::HintboxPaint },
|
||||
{ "hide", CLuaInstHintbox::HintboxHide },
|
||||
{ "__gc", CLuaInstHintbox::HintboxDelete },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
luaL_newmetatable(L, "hintbox");
|
||||
luaL_setfuncs(L, meth, 0);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -1, "__index");
|
||||
lua_setglobal(L, "hintbox");
|
||||
}
|
||||
|
||||
CLuaHintbox *CLuaInstHintbox::HintboxCheck(lua_State *L, int n)
|
||||
{
|
||||
return *(CLuaHintbox **) luaL_checkudata(L, n, "hintbox");
|
||||
}
|
||||
|
||||
CLuaHintbox::CLuaHintbox()
|
||||
{
|
||||
caption = NULL;
|
||||
b = NULL;
|
||||
}
|
||||
|
||||
CLuaHintbox::~CLuaHintbox()
|
||||
{
|
||||
if (caption)
|
||||
free(caption);
|
||||
delete b;
|
||||
}
|
||||
|
||||
int CLuaInstHintbox::HintboxNew(lua_State *L)
|
||||
{
|
||||
lua_assert(lua_istable(L,1));
|
||||
|
||||
std::string name, text, icon = std::string(NEUTRINO_ICON_INFO);
|
||||
tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);
|
||||
tableLookup(L, "text", text);
|
||||
tableLookup(L, "icon", icon);
|
||||
lua_Integer width = 450;
|
||||
tableLookup(L, "width", width);
|
||||
|
||||
CLuaHintbox **udata = (CLuaHintbox **) lua_newuserdata(L, sizeof(CLuaHintbox *));
|
||||
*udata = new CLuaHintbox();
|
||||
(*udata)->caption = strdup(name.c_str());
|
||||
(*udata)->b = new CHintBox((*udata)->caption, text.c_str(), width, icon.c_str());
|
||||
luaL_getmetatable(L, "hintbox");
|
||||
lua_setmetatable(L, -2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CLuaInstHintbox::HintboxDelete(lua_State *L)
|
||||
{
|
||||
CLuaHintbox *m = HintboxCheck(L, 1);
|
||||
delete m;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstHintbox::HintboxPaint(lua_State *L)
|
||||
{
|
||||
CLuaHintbox *m = HintboxCheck(L, 1);
|
||||
if (!m)
|
||||
return 0;
|
||||
m->b->paint();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstHintbox::HintboxHide(lua_State *L)
|
||||
{
|
||||
CLuaHintbox *m = HintboxCheck(L, 1);
|
||||
m->b->hide();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstHintbox::HintboxExec(lua_State *L)
|
||||
{
|
||||
CLuaHintbox *m = HintboxCheck(L, 1);
|
||||
if (!m)
|
||||
return 0;
|
||||
int timeout = -1;
|
||||
if (lua_isnumber(L, -1))
|
||||
timeout = (int) lua_tonumber(L, -1);
|
||||
m->b->paint();
|
||||
|
||||
// copied from gui/widget/hintbox.cpp
|
||||
neutrino_msg_t msg;
|
||||
neutrino_msg_data_t data;
|
||||
if ( timeout == -1 )
|
||||
timeout = 5; /// default timeout 5 sec
|
||||
//timeout = g_settings.timing[SNeutrinoSettings::TIMING_INFOBAR];
|
||||
|
||||
uint64_t timeoutEnd = CRCInput::calcTimeoutEnd( timeout );
|
||||
|
||||
int res = messages_return::none;
|
||||
|
||||
while ( ! ( res & ( messages_return::cancel_info | messages_return::cancel_all ) ) ) {
|
||||
g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );
|
||||
|
||||
if ((msg == CRCInput::RC_timeout) || (msg == CRCInput::RC_ok))
|
||||
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))) {
|
||||
if (msg == CRCInput::RC_up)
|
||||
m->b->scroll_up();
|
||||
else
|
||||
m->b->scroll_down();
|
||||
} else if ((msg == CRCInput::RC_sat) || (msg == CRCInput::RC_favorites)) {
|
||||
} else if (msg == CRCInput::RC_mode) {
|
||||
res = messages_return::handled;
|
||||
break;
|
||||
} else if ((msg == CRCInput::RC_next) || (msg == CRCInput::RC_prev)) {
|
||||
res = messages_return::cancel_all;
|
||||
g_RCInput->postMsg(msg, data);
|
||||
} else {
|
||||
res = CNeutrinoApp::getInstance()->handleMsg(msg, data);
|
||||
if (res & messages_return::unhandled) {
|
||||
|
||||
// leave here and handle above...
|
||||
g_RCInput->postMsg(msg, data);
|
||||
res = messages_return::cancel_all;
|
||||
}
|
||||
}
|
||||
}
|
||||
m->b->hide();
|
||||
return 0;
|
||||
}
|
51
src/gui/lua/lua_hintbox.h
Normal file
51
src/gui/lua/lua_hintbox.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* lua hintbox
|
||||
*
|
||||
* (C) 2014 by martii
|
||||
* (C) 2014-2015 M. Liebmann (micha-bbg)
|
||||
* (C) 2014 Sven Hoefer (svenhoefer)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _LUAHINTBOX_H
|
||||
#define _LUAHINTBOX_H
|
||||
|
||||
class CLuaHintbox
|
||||
{
|
||||
public:
|
||||
CHintBox *b;
|
||||
char *caption;
|
||||
CLuaHintbox();
|
||||
~CLuaHintbox();
|
||||
};
|
||||
|
||||
class CLuaInstHintbox
|
||||
{
|
||||
public:
|
||||
CLuaInstHintbox() {};
|
||||
~CLuaInstHintbox() {};
|
||||
static CLuaInstHintbox* getInstance();
|
||||
static void HintboxRegister(lua_State *L);
|
||||
|
||||
private:
|
||||
static CLuaHintbox *HintboxCheck(lua_State *L, int n);
|
||||
static int HintboxNew(lua_State *L);
|
||||
static int HintboxDelete(lua_State *L);
|
||||
static int HintboxExec(lua_State *L);
|
||||
static int HintboxPaint(lua_State *L);
|
||||
static int HintboxHide(lua_State *L);
|
||||
};
|
||||
|
||||
#endif //_LUAHINTBOX_H
|
142
src/gui/lua/lua_messagebox.cpp
Normal file
142
src/gui/lua/lua_messagebox.cpp
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* lua messagebox
|
||||
*
|
||||
* (C) 2014 by martii
|
||||
* (C) 2014-2015 M. Liebmann (micha-bbg)
|
||||
* (C) 2014 Sven Hoefer (svenhoefer)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <global.h>
|
||||
#include <system/debug.h>
|
||||
#include <gui/widget/messagebox.h>
|
||||
#include <neutrino.h>
|
||||
|
||||
#include "luainstance.h"
|
||||
#include "lua_messagebox.h"
|
||||
|
||||
CLuaInstMessagebox* CLuaInstMessagebox::getInstance()
|
||||
{
|
||||
static CLuaInstMessagebox* LuaInstMessagebox = NULL;
|
||||
|
||||
if(!LuaInstMessagebox)
|
||||
LuaInstMessagebox = new CLuaInstMessagebox();
|
||||
return LuaInstMessagebox;
|
||||
}
|
||||
|
||||
void CLuaInstMessagebox::MessageboxRegister(lua_State *L)
|
||||
{
|
||||
luaL_Reg meth[] = {
|
||||
{ "exec", CLuaInstMessagebox::MessageboxExec },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
luaL_newmetatable(L, "messagebox");
|
||||
luaL_setfuncs(L, meth, 0);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -1, "__index");
|
||||
lua_setglobal(L, "messagebox");
|
||||
}
|
||||
|
||||
// messagebox.exec{caption="Title", text="text", icon="settings", width=500,timeout=-1,return_default_on_timeout=0,
|
||||
// default = "yes", buttons = { "yes", "no", "cancel", "all", "back", "ok" }, align="center1|center2|left|right" }
|
||||
int CLuaInstMessagebox::MessageboxExec(lua_State *L)
|
||||
{
|
||||
lua_assert(lua_istable(L,1));
|
||||
|
||||
std::string name, text, icon = std::string(NEUTRINO_ICON_INFO);
|
||||
tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);
|
||||
tableLookup(L, "text", text);
|
||||
tableLookup(L, "icon", icon);
|
||||
lua_Integer timeout = -1, width = 450, return_default_on_timeout = 0, show_buttons = 0, default_button = 0;
|
||||
tableLookup(L, "timeout", timeout);
|
||||
tableLookup(L, "width", width);
|
||||
tableLookup(L, "return_default_on_timeout", return_default_on_timeout);
|
||||
|
||||
std::string tmp;
|
||||
if (tableLookup(L, "align", tmp)) {
|
||||
lua_pushvalue(L, -2);
|
||||
const char *val = lua_tostring(L, -2);
|
||||
table_key mb[] = {
|
||||
{ "center1", CMessageBox::mbBtnAlignCenter1 },
|
||||
{ "center2", CMessageBox::mbBtnAlignCenter2 },
|
||||
{ "left", CMessageBox::mbBtnAlignLeft },
|
||||
{ "right", CMessageBox::mbBtnAlignRight },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
for (int i = 0; mb[i].name; i++)
|
||||
if (!strcmp(mb[i].name, val)) {
|
||||
show_buttons |= mb[i].code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lua_pushstring(L, "buttons");
|
||||
lua_gettable(L, -2);
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
|
||||
lua_pushvalue(L, -2);
|
||||
const char *val = lua_tostring(L, -2);
|
||||
table_key mb[] = {
|
||||
{ "yes", CMessageBox::mbYes },
|
||||
{ "no", CMessageBox::mbNo },
|
||||
{ "cancel", CMessageBox::mbCancel },
|
||||
{ "all", CMessageBox::mbAll },
|
||||
{ "back", CMessageBox::mbBack },
|
||||
{ "ok", CMessageBox::mbOk },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
for (int i = 0; mb[i].name; i++)
|
||||
if (!strcmp(mb[i].name, val)) {
|
||||
show_buttons |= mb[i].code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
table_key mbr[] = {
|
||||
{ "yes", CMessageBox::mbrYes },
|
||||
{ "no", CMessageBox::mbrNo },
|
||||
{ "cancel", CMessageBox::mbrCancel },
|
||||
{ "back", CMessageBox::mbrBack },
|
||||
{ "ok", CMessageBox::mbrOk },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
if (tableLookup(L, "default", tmp)) {
|
||||
lua_pushvalue(L, -2);
|
||||
const char *val = lua_tostring(L, -2);
|
||||
for (int i = 0; mbr[i].name; i++)
|
||||
if (!strcmp(mbr[i].name, val)) {
|
||||
default_button = mbr[i].code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int res = ShowMsg(name, text, (CMessageBox::result_) default_button, (CMessageBox::buttons_) show_buttons, icon.empty() ? NULL : icon.c_str(), width, timeout, return_default_on_timeout);
|
||||
|
||||
tmp = "cancel";
|
||||
for (int i = 0; mbr[i].name; i++)
|
||||
if (res == mbr[i].code) {
|
||||
tmp = mbr[i].name;
|
||||
break;
|
||||
}
|
||||
lua_pushstring(L, tmp.c_str());
|
||||
|
||||
return 1;
|
||||
}
|
46
src/gui/lua/lua_messagebox.h
Normal file
46
src/gui/lua/lua_messagebox.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* lua messagebox
|
||||
*
|
||||
* (C) 2014 by martii
|
||||
* (C) 2014-2015 M. Liebmann (micha-bbg)
|
||||
* (C) 2014 Sven Hoefer (svenhoefer)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _LUAMESSAGEBOX_H
|
||||
#define _LUAMESSAGEBOX_H
|
||||
|
||||
class CLuaMessagebox
|
||||
{
|
||||
public:
|
||||
CMessageBox *b;
|
||||
CLuaMessagebox();
|
||||
~CLuaMessagebox();
|
||||
};
|
||||
|
||||
class CLuaInstMessagebox
|
||||
{
|
||||
public:
|
||||
CLuaInstMessagebox() {};
|
||||
~CLuaInstMessagebox() {};
|
||||
static CLuaInstMessagebox* getInstance();
|
||||
static void MessageboxRegister(lua_State *L);
|
||||
|
||||
private:
|
||||
// static CLuaMessagebox *MessageboxCheck(lua_State *L, int n);
|
||||
static int MessageboxExec(lua_State *L);
|
||||
};
|
||||
|
||||
#endif //_LUAMESSAGEBOX_H
|
@@ -29,6 +29,7 @@
|
||||
#include <system/settings.h>
|
||||
#include <system/set_threadname.h>
|
||||
#include <gui/widget/msgbox.h>
|
||||
#include <gui/widget/messagebox.h>
|
||||
#include <gui/movieplayer.h>
|
||||
#include <gui/infoclock.h>
|
||||
#include <driver/neutrinofonts.h>
|
||||
@@ -42,7 +43,9 @@
|
||||
#include "lua_cc_text.h"
|
||||
#include "lua_cc_window.h"
|
||||
#include "lua_configfile.h"
|
||||
#include "lua_hintbox.h"
|
||||
#include "lua_menue.h"
|
||||
#include "lua_messagebox.h"
|
||||
#include "lua_video.h"
|
||||
|
||||
static void set_lua_variables(lua_State *L)
|
||||
@@ -542,14 +545,14 @@ void CLuaInstance::registerFunctions()
|
||||
|
||||
lua_register(lua, className, NewWindow);
|
||||
|
||||
HintboxRegister(lua);
|
||||
MessageboxRegister(lua);
|
||||
CLuaInstCCPicture::getInstance()->CCPictureRegister(lua);
|
||||
CLuaInstCCSignalbox::getInstance()->CCSignalBoxRegister(lua);
|
||||
CLuaInstCCText::getInstance()->CCTextRegister(lua);
|
||||
CLuaInstCCWindow::getInstance()->CCWindowRegister(lua);
|
||||
CLuaInstConfigFile::getInstance()->LuaConfigFileRegister(lua);
|
||||
CLuaInstHintbox::getInstance()->HintboxRegister(lua);
|
||||
CLuaInstMenu::getInstance()->MenuRegister(lua);
|
||||
CLuaInstMessagebox::getInstance()->MessageboxRegister(lua);
|
||||
}
|
||||
|
||||
CLuaData *CLuaInstance::CheckData(lua_State *L, int narg)
|
||||
@@ -1144,249 +1147,6 @@ int CLuaInstance::runScriptExt(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CLuaInstance::HintboxRegister(lua_State *L)
|
||||
{
|
||||
luaL_Reg meth[] = {
|
||||
{ "new", CLuaInstance::HintboxNew },
|
||||
{ "exec", CLuaInstance::HintboxExec },
|
||||
{ "paint", CLuaInstance::HintboxPaint },
|
||||
{ "hide", CLuaInstance::HintboxHide },
|
||||
{ "__gc", CLuaInstance::HintboxDelete },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
luaL_newmetatable(L, "hintbox");
|
||||
luaL_setfuncs(L, meth, 0);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -1, "__index");
|
||||
lua_setglobal(L, "hintbox");
|
||||
}
|
||||
|
||||
CLuaHintbox *CLuaInstance::HintboxCheck(lua_State *L, int n)
|
||||
{
|
||||
return *(CLuaHintbox **) luaL_checkudata(L, n, "hintbox");
|
||||
}
|
||||
|
||||
CLuaHintbox::CLuaHintbox()
|
||||
{
|
||||
caption = NULL;
|
||||
b = NULL;
|
||||
}
|
||||
|
||||
CLuaHintbox::~CLuaHintbox()
|
||||
{
|
||||
if (caption)
|
||||
free(caption);
|
||||
delete b;
|
||||
}
|
||||
|
||||
int CLuaInstance::HintboxNew(lua_State *L)
|
||||
{
|
||||
lua_assert(lua_istable(L,1));
|
||||
|
||||
std::string name, text, icon = std::string(NEUTRINO_ICON_INFO);
|
||||
tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);
|
||||
tableLookup(L, "text", text);
|
||||
tableLookup(L, "icon", icon);
|
||||
lua_Integer width = 450;
|
||||
tableLookup(L, "width", width);
|
||||
|
||||
CLuaHintbox **udata = (CLuaHintbox **) lua_newuserdata(L, sizeof(CLuaHintbox *));
|
||||
*udata = new CLuaHintbox();
|
||||
(*udata)->caption = strdup(name.c_str());
|
||||
(*udata)->b = new CHintBox((*udata)->caption, text.c_str(), width, icon.c_str());
|
||||
luaL_getmetatable(L, "hintbox");
|
||||
lua_setmetatable(L, -2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int CLuaInstance::HintboxDelete(lua_State *L)
|
||||
{
|
||||
CLuaHintbox *m = HintboxCheck(L, 1);
|
||||
delete m;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstance::HintboxPaint(lua_State *L)
|
||||
{
|
||||
CLuaHintbox *m = HintboxCheck(L, 1);
|
||||
if (!m)
|
||||
return 0;
|
||||
m->b->paint();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstance::HintboxHide(lua_State *L)
|
||||
{
|
||||
CLuaHintbox *m = HintboxCheck(L, 1);
|
||||
m->b->hide();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CLuaInstance::HintboxExec(lua_State *L)
|
||||
{
|
||||
CLuaHintbox *m = HintboxCheck(L, 1);
|
||||
if (!m)
|
||||
return 0;
|
||||
int timeout = -1;
|
||||
if (lua_isnumber(L, -1))
|
||||
timeout = (int) lua_tonumber(L, -1);
|
||||
m->b->paint();
|
||||
|
||||
// copied from gui/widget/hintbox.cpp
|
||||
|
||||
neutrino_msg_t msg;
|
||||
neutrino_msg_data_t data;
|
||||
if ( timeout == -1 )
|
||||
timeout = 5; /// default timeout 5 sec
|
||||
//timeout = g_settings.timing[SNeutrinoSettings::TIMING_INFOBAR];
|
||||
|
||||
uint64_t timeoutEnd = CRCInput::calcTimeoutEnd( timeout );
|
||||
|
||||
int res = messages_return::none;
|
||||
|
||||
while ( ! ( res & ( messages_return::cancel_info | messages_return::cancel_all ) ) )
|
||||
{
|
||||
g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );
|
||||
|
||||
if ((msg == CRCInput::RC_timeout) || (msg == CRCInput::RC_ok))
|
||||
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)))
|
||||
{
|
||||
if (msg == CRCInput::RC_up)
|
||||
m->b->scroll_up();
|
||||
else
|
||||
m->b->scroll_down();
|
||||
}
|
||||
else if((msg == CRCInput::RC_sat) || (msg == CRCInput::RC_favorites)) {
|
||||
}
|
||||
else if(msg == CRCInput::RC_mode) {
|
||||
res = messages_return::handled;
|
||||
break;
|
||||
}
|
||||
else if((msg == CRCInput::RC_next) || (msg == CRCInput::RC_prev)) {
|
||||
res = messages_return::cancel_all;
|
||||
g_RCInput->postMsg(msg, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = CNeutrinoApp::getInstance()->handleMsg(msg, data);
|
||||
if (res & messages_return::unhandled)
|
||||
{
|
||||
|
||||
// leave here and handle above...
|
||||
g_RCInput->postMsg(msg, data);
|
||||
res = messages_return::cancel_all;
|
||||
}
|
||||
}
|
||||
}
|
||||
m->b->hide();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CLuaInstance::MessageboxRegister(lua_State *L)
|
||||
{
|
||||
luaL_Reg meth[] = {
|
||||
{ "exec", CLuaInstance::MessageboxExec },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
luaL_newmetatable(L, "messagebox");
|
||||
luaL_setfuncs(L, meth, 0);
|
||||
lua_pushvalue(L, -1);
|
||||
lua_setfield(L, -1, "__index");
|
||||
lua_setglobal(L, "messagebox");
|
||||
}
|
||||
|
||||
// messagebox.exec{caption="Title", text="text", icon="settings", width=500,timeout=-1,return_default_on_timeout=0,
|
||||
// default = "yes", buttons = { "yes", "no", "cancel", "all", "back", "ok" }, align="center1|center2|left|right" }
|
||||
int CLuaInstance::MessageboxExec(lua_State *L)
|
||||
{
|
||||
lua_assert(lua_istable(L,1));
|
||||
|
||||
std::string name, text, icon = std::string(NEUTRINO_ICON_INFO);
|
||||
tableLookup(L, "name", name) || tableLookup(L, "title", name) || tableLookup(L, "caption", name);
|
||||
tableLookup(L, "text", text);
|
||||
tableLookup(L, "icon", icon);
|
||||
lua_Integer timeout = -1, width = 450, return_default_on_timeout = 0, show_buttons = 0, default_button = 0;
|
||||
tableLookup(L, "timeout", timeout);
|
||||
tableLookup(L, "width", width);
|
||||
tableLookup(L, "return_default_on_timeout", return_default_on_timeout);
|
||||
|
||||
std::string tmp;
|
||||
if (tableLookup(L, "align", tmp)) {
|
||||
lua_pushvalue(L, -2);
|
||||
const char *val = lua_tostring(L, -2);
|
||||
table_key mb[] = {
|
||||
{ "center1", CMessageBox::mbBtnAlignCenter1 },
|
||||
{ "center2", CMessageBox::mbBtnAlignCenter2 },
|
||||
{ "left", CMessageBox::mbBtnAlignLeft },
|
||||
{ "right", CMessageBox::mbBtnAlignRight },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
for (int i = 0; mb[i].name; i++)
|
||||
if (!strcmp(mb[i].name, val)) {
|
||||
show_buttons |= mb[i].code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lua_pushstring(L, "buttons");
|
||||
lua_gettable(L, -2);
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
|
||||
lua_pushvalue(L, -2);
|
||||
const char *val = lua_tostring(L, -2);
|
||||
table_key mb[] = {
|
||||
{ "yes", CMessageBox::mbYes },
|
||||
{ "no", CMessageBox::mbNo },
|
||||
{ "cancel", CMessageBox::mbCancel },
|
||||
{ "all", CMessageBox::mbAll },
|
||||
{ "back", CMessageBox::mbBack },
|
||||
{ "ok", CMessageBox::mbOk },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
for (int i = 0; mb[i].name; i++)
|
||||
if (!strcmp(mb[i].name, val)) {
|
||||
show_buttons |= mb[i].code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
||||
table_key mbr[] = {
|
||||
{ "yes", CMessageBox::mbrYes },
|
||||
{ "no", CMessageBox::mbrNo },
|
||||
{ "cancel", CMessageBox::mbrCancel },
|
||||
{ "back", CMessageBox::mbrBack },
|
||||
{ "ok", CMessageBox::mbrOk },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
if (tableLookup(L, "default", tmp)) {
|
||||
lua_pushvalue(L, -2);
|
||||
const char *val = lua_tostring(L, -2);
|
||||
for (int i = 0; mbr[i].name; i++)
|
||||
if (!strcmp(mbr[i].name, val)) {
|
||||
default_button = mbr[i].code;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int res = ShowMsg(name, text, (CMessageBox::result_) default_button, (CMessageBox::buttons_) show_buttons, icon.empty() ? NULL : icon.c_str(), width, timeout, return_default_on_timeout);
|
||||
|
||||
tmp = "cancel";
|
||||
for (int i = 0; mbr[i].name; i++)
|
||||
if (res == mbr[i].code) {
|
||||
tmp = mbr[i].name;
|
||||
break;
|
||||
}
|
||||
lua_pushstring(L, tmp.c_str());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
int CLuaInstance::checkVersion(lua_State *L)
|
||||
{
|
||||
int numargs = lua_gettop(L);
|
||||
|
@@ -26,8 +26,6 @@ extern "C" {
|
||||
#include <lualib.h>
|
||||
}
|
||||
#include <driver/fb_window.h>
|
||||
#include <gui/widget/hintbox.h>
|
||||
#include <gui/widget/messagebox.h>
|
||||
#include <vector>
|
||||
|
||||
#include "luainstance_helpers.h"
|
||||
@@ -35,24 +33,6 @@ extern "C" {
|
||||
#define LUA_API_VERSION_MAJOR 1
|
||||
#define LUA_API_VERSION_MINOR 22
|
||||
|
||||
|
||||
class CLuaHintbox
|
||||
{
|
||||
public:
|
||||
CHintBox *b;
|
||||
char *caption;
|
||||
CLuaHintbox();
|
||||
~CLuaHintbox();
|
||||
};
|
||||
|
||||
class CLuaMessagebox
|
||||
{
|
||||
public:
|
||||
CMessageBox *b;
|
||||
CLuaMessagebox();
|
||||
~CLuaMessagebox();
|
||||
};
|
||||
|
||||
/* inspired by Steve Kemp http://www.steve.org.uk/ */
|
||||
class CLuaInstance
|
||||
{
|
||||
@@ -105,18 +85,6 @@ private:
|
||||
static int strFind(lua_State *L);
|
||||
static int strSub(lua_State *L);
|
||||
|
||||
void HintboxRegister(lua_State *L);
|
||||
static int HintboxNew(lua_State *L);
|
||||
static int HintboxDelete(lua_State *L);
|
||||
static int HintboxExec(lua_State *L);
|
||||
static int HintboxPaint(lua_State *L);
|
||||
static int HintboxHide(lua_State *L);
|
||||
static CLuaHintbox *HintboxCheck(lua_State *L, int n);
|
||||
|
||||
void MessageboxRegister(lua_State *L);
|
||||
static int MessageboxExec(lua_State *L);
|
||||
static CLuaMessagebox *MessageboxCheck(lua_State *L, int n);
|
||||
|
||||
static int checkVersion(lua_State *L);
|
||||
static int createChannelIDfromUrl(lua_State *L);
|
||||
static int enableInfoClock(lua_State *L);
|
||||
|
Reference in New Issue
Block a user