diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/client.pro | 2 | ||||
-rw-r--r-- | client/debug.cc | 5 | ||||
-rw-r--r-- | client/debug.h | 2 | ||||
-rw-r--r-- | client/formatparser.cc | 195 | ||||
-rw-r--r-- | client/formatparser.h | 38 | ||||
-rw-r--r-- | client/lua.cc | 30 | ||||
-rw-r--r-- | client/lua.h | 3 | ||||
-rw-r--r-- | client/mainwindow.cc | 4 | ||||
-rw-r--r-- | client/widgets/dbwidget.cc | 3 | ||||
-rw-r--r-- | client/widgets/metawidget.cc | 26 | ||||
-rw-r--r-- | client/widgets/widget.h | 3 |
11 files changed, 38 insertions, 273 deletions
diff --git a/client/client.pro b/client/client.pro index e507c4e..3758693 100644 --- a/client/client.pro +++ b/client/client.pro @@ -35,7 +35,6 @@ unix { HEADERS += \ collapser.h \ debug.h \ - formatparser.h \ lua.h \ luawidget.h \ macro.h \ @@ -72,7 +71,6 @@ SOURCES += \ pracro.cc \ collapser.cc \ debug.cc \ - formatparser.cc \ lua.cc \ luawidget.cc \ macro.cc \ diff --git a/client/debug.cc b/client/debug.cc index 282cf93..6eed1ad 100644 --- a/client/debug.cc +++ b/client/debug.cc @@ -129,6 +129,11 @@ void dbg_hide() if(debugwindow) debugwindow->hide(); } +bool dbg_enabled() +{ + return debugwindow != NULL; +} + void dbg_log(const char *func, const char *file, const int line, debug_class cl, const char *ch, const char *fmt, ...) { diff --git a/client/debug.h b/client/debug.h index 0508b31..e0de223 100644 --- a/client/debug.h +++ b/client/debug.h @@ -34,6 +34,8 @@ void dbg_show(); void dbg_toggle(); void dbg_hide(); +bool dbg_enabled(); + typedef enum { _debug, _error, diff --git a/client/formatparser.cc b/client/formatparser.cc deleted file mode 100644 index 71f80ee..0000000 --- a/client/formatparser.cc +++ /dev/null @@ -1,195 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * resumeparser.cc - * - * Mon Oct 1 11:17:35 CEST 2007 - * Copyright 2007 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of Pracro. - * - * Pracro 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. - * - * Pracro 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 Pracro; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#include "formatparser.h" - -#include <QSqlRecord> -#include <QVariant> -#include <string.h> - -#include "lua.h" -#include "macrowindow.h" -#include "widgets/widget.h" - -static QString format_parser_lua(QString format, Widget *w) -{ - /* - LUA lua(w); - - return lua.runParser(format); - */ - - format = format; - w = w; - - return "FIXME: formatparser.cc:44"; -} - -static QString format_parser_pracro(QString format, Widget *w) -{ - QString resume; - QString var; - - QChar *p = format.data(); - QChar *theend = p + format.size(); - while(p < theend) { - switch((*p).toLatin1()) { - case '$': - p++; - switch((*p).toLatin1()) { - case '$': - resume.append(*p); - break; - - case '{': - p++; - var = ""; - // Parser - while(p < theend && *p != '}') { - var.append(*p); - p++; - } - { - Widget *widget = w->findWidget(var, true); - if(widget) resume += widget->value(); - } - break; - - default: - resume.append(*p); - break; - } - p++; - break; - - case '\\': - p++; - switch((*p).toLatin1()) { - case 't': - resume.append('\t'); - break; - case 'n': - resume.append('\n'); - break; - case 'r': - resume.append('\r'); - break; - case '\\': - default: - resume.append(*p); - break; - } - p++; - break; - - default: - resume.append(QChar(*p)); - p++; - break; - } - } - - return resume; -} - - -QString format_parser(QString format, QSqlQuery &query) -{ - QString resume; - QString var; - - QChar *p = format.data(); - QChar *theend = p + format.size(); - while(p < theend) { - switch((*p).toLatin1()) { - case '$': - p++; - switch((*p).toLatin1()) { - case '$': - resume.append(*p); - break; - - case '{': - p++; - var = ""; - // Parser - while(p < theend && *p != '}') { - var.append(*p); - p++; - } - { - int idx = query.record().indexOf(var); - if(idx == -1) { - printf("Unknown field in format string %s\n", var.toStdString().c_str()); - } else { - resume += query.value(idx).toString(); - } - } - break; - - default: - resume.append(*p); - break; - } - p++; - break; - - case '\\': - p++; - switch((*p).toLatin1()) { - case 't': - resume.append('\t'); - break; - case 'n': - resume.append('\n'); - break; - case 'r': - resume.append('\r'); - break; - case '\\': - default: - resume.append(*p); - break; - } - p++; - break; - - default: - resume.append(QChar(*p)); - p++; - break; - } - } - - return resume; -} - -QString format_parser(QString format, Widget *w, QString language) -{ - if(language == "pracro") return format_parser_pracro(format, w); - if(language == "lua") return format_parser_lua(format, w); - return ""; -} diff --git a/client/formatparser.h b/client/formatparser.h deleted file mode 100644 index 120709e..0000000 --- a/client/formatparser.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * formatparser.h - * - * Mon Oct 1 11:17:35 CEST 2007 - * Copyright 2007 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of Pracro. - * - * Pracro 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. - * - * Pracro 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 Pracro; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ -#ifndef __PRACRO_FORMATPARSER_H__ -#define __PRACRO_FORMATPARSER_H__ - -#include <QString> -#include <QVector> -#include <QSqlQuery> - -class Widget; -QString format_parser(QString format, Widget *w, QString language); -QString format_parser(QString format, QSqlQuery &query); - -#endif/*__PRACRO_FORMATPARSER_H__*/ diff --git a/client/lua.cc b/client/lua.cc index 3607a26..af64efb 100644 --- a/client/lua.cc +++ b/client/lua.cc @@ -106,39 +106,47 @@ void LUA::clear() register_widget(L); } -QString LUA::runParser(QString program) +QString LUA::runScriptS(QString script, Widget *widget, QString name) { if(L == NULL) { ERROR(lua, "LUA state not initialized!"); - return false; + return ""; } - DEBUG(lua, "Running %s\n", program.toStdString().c_str()); - int top = lua_gettop(L); + DEBUG(lua, "Running %s script %s on %s widget.\n", + name.toStdString().c_str(), + script.toStdString().c_str(), + widget?widget->name().toStdString().c_str():"NULL"); + + if(widget) { + wdg_make_widget(L, widget); + lua_setglobal(L, "this"); + } + if(luaL_loadbuffer(L, - program.toStdString().c_str(), - program.size(), - "parser")) { + script.toStdString().c_str(), + script.size(), + name.toStdString().c_str())) { ERROR(lua, "%s", lua_tostring(L, lua_gettop(L))); - return false; + return ""; } // Run the loaded code if(lua_pcall(L, 0, LUA_MULTRET, 0)) { ERROR(lua, "%s", lua_tostring(L, lua_gettop(L))); - return false; + return ""; } if(top != lua_gettop(L) - 1) { ERROR(lua, "Program did not return a single value.\n"); - return false; + return ""; } if(lua_isstring(L, lua_gettop(L)) == false) { ERROR(lua, "Program did not return a boolean value.\n"); - return false; + return ""; } QString res = lua_tostring(L, lua_gettop(L)); diff --git a/client/lua.h b/client/lua.h index bacce14..8200873 100644 --- a/client/lua.h +++ b/client/lua.h @@ -39,9 +39,8 @@ public: LUA(Widget **rootwidget); ~LUA(); - QString runParser(QString program); - bool runScript(QString script, Widget *widget, QString name = ""); + QString runScriptS(QString script, Widget *widget, QString name = ""); Widget *getWidget(QString name); diff --git a/client/mainwindow.cc b/client/mainwindow.cc index e8a7f51..a908988 100644 --- a/client/mainwindow.cc +++ b/client/mainwindow.cc @@ -78,7 +78,9 @@ MainWindow::MainWindow(QString cpr, QString templ, QString host, QStatusBar *status = statusBar(); status->addPermanentWidget(new QLabel("Pracro v."VERSION)); - status->addPermanentWidget(new Dbg()); + if(dbg_enabled()) { + status->addPermanentWidget(new Dbg()); + } QToolBar *toolbar = addToolBar("controls"); toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); diff --git a/client/widgets/dbwidget.cc b/client/widgets/dbwidget.cc index 4d6240c..08107b1 100644 --- a/client/widgets/dbwidget.cc +++ b/client/widgets/dbwidget.cc @@ -36,7 +36,6 @@ #include <QLineEdit> #include <QComboBox> -#include "formatparser.h" #include "common.h" #define EMPTY_STRING "Write something in the searchfield" @@ -160,7 +159,7 @@ void DBWidget::update_list(QString prefix) QStringList lst; while(query.next()) { - lst << format_parser(format, query); + // lst << format_parser(format, query); } lst.sort(); diff --git a/client/widgets/metawidget.cc b/client/widgets/metawidget.cc index a179138..a866445 100644 --- a/client/widgets/metawidget.cc +++ b/client/widgets/metawidget.cc @@ -31,10 +31,11 @@ #include <QFrame> #include "messagebox.h" -#include "formatparser.h" #include "macrowindow.h" #include "common.h" +#include "debug.h" + MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow) : Widget(node, macrowindow) { @@ -59,24 +60,7 @@ MetaWidget::MetaWidget(QDomNode &node, MacroWindow *macrowindow) */ // addChildren(node); - // Setup format string - if(elem.hasAttribute("formatlanguage")) { - formatlanguage = elem.attribute("formatlanguage"); - } else { - formatlanguage = "pracro"; - } - - if(elem.hasAttribute("format")) { - format = elem.attribute("format"); - } else { - QVector< Widget* >::iterator i = widgets.begin(); - while (i != widgets.end()) { - Widget* w = *i; - if(format != "") format += ", "; - format += "${" + w->name() + "}"; - i++; - } - } + format = elem.attribute("format", ""); addChildren(node, frame->layout()); @@ -101,12 +85,12 @@ void MetaWidget::changed() QString MetaWidget::value() { - return format_parser(format, this, formatlanguage); + return lua->runScriptS(format, this, "format"); } void MetaWidget::setValue(QString, QString) { - // Nothing reasonable we can do here. + WARN(metawidget, "setValue was attempted on this widget."); } bool MetaWidget::preValid() diff --git a/client/widgets/widget.h b/client/widgets/widget.h index 3315c2e..d172543 100644 --- a/client/widgets/widget.h +++ b/client/widgets/widget.h @@ -95,6 +95,8 @@ protected: void addChildren(QDomNode &xml_node, QLayout *layout); + LUA *lua; + private: QVector< Widget* > children; void createWidget(QDomNode &xml_node, QLayout *layout); @@ -109,7 +111,6 @@ private: QString widget_type; bool widget_local; - LUA *lua; MacroWindow *macrowindow; bool hasOnChangeEvent; |