From 26de348fe31a56a23a7860f1aa704edcc7dcb852 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Sun, 17 Jul 2016 16:52:56 +0200 Subject: [PATCH] convert eventview to template, make it more stable; remove obsolete scripting --- .gitignore | 1 + commonlib/commonlib.pri | 2 +- commonlib/commonlib.pro | 3 +- commonlib/files.qrc | 11 + commonlib/icon.qrc | 9 - commonlib/stick/stick.cpp | 431 ++++++++++++++++++++++++++++++++++ commonlib/stick/stick.h | 51 ++++ commonlib/stick/stick.pri | 7 + commonlib/stick/stick_p.h | 70 ++++++ commonlib/templates/odtrender.cpp | 12 +- commonlib/widgets/eventview.cpp | 75 ++----- commonlib/widgets/eventview.html | 48 ++++ iface/libs.pri | 2 +- iface/misc/formula.cpp | 1 + iface/smoke-ifc_de.ts | 468 ++++++++++++++++++------------------ iface/smoke-ifc_en.ts | 468 ++++++++++++++++++------------------ iface/templates/templates.cpp | 34 ++- iface/templates/templates.h | 18 ++- iface/wext/address.cpp | 6 +- iface/wext/address.h | 3 +- iface/wext/customer.cpp | 6 +- iface/wext/customer.h | 3 +- iface/wext/customerinfo.cpp | 6 +- iface/wext/customerinfo.h | 3 +- iface/wext/event.cpp | 14 +- iface/wext/event.h | 12 +- iface/wext/order.cpp | 9 +- iface/wext/order.h | 3 +- iface/wext/orderinfo.h | 5 +- iface/wext/ticket.cpp | 7 +- iface/wext/ticket.h | 3 +- iface/wext/voucher.h | 3 +- pack | 2 +- src/dialogs/dialogs.pri | 2 - src/dialogs/orderauditdlg_p.h | 27 ++- src/dialogs/wizard.cpp | 121 ---------- src/dialogs/wizard.h | 54 ----- src/libs.pri | 2 +- src/mwin/overview.cpp | 31 --- src/mwin/overview.h | 6 - src/mwin/tabwin.cpp | 3 - src/script/init.js | 15 -- src/script/jsengine.cpp | 243 ------------------- src/script/jsengine.h | 50 ---- src/script/script.pri | 9 - src/script/scriptfiles.qrc | 10 - src/script/startup.js | 9 - src/script/wizard.js | 151 ------------ src/smoke.pro | 1 - taurus | 2 +- tzone | 2 +- 51 files changed, 1228 insertions(+), 1306 deletions(-) create mode 100644 commonlib/files.qrc delete mode 100644 commonlib/icon.qrc create mode 100644 commonlib/stick/stick.cpp create mode 100644 commonlib/stick/stick.h create mode 100644 commonlib/stick/stick.pri create mode 100644 commonlib/stick/stick_p.h create mode 100644 commonlib/widgets/eventview.html delete mode 100644 src/dialogs/wizard.cpp delete mode 100644 src/dialogs/wizard.h delete mode 100644 src/script/init.js delete mode 100644 src/script/jsengine.cpp delete mode 100644 src/script/jsengine.h delete mode 100644 src/script/script.pri delete mode 100644 src/script/scriptfiles.qrc delete mode 100644 src/script/startup.js delete mode 100644 src/script/wizard.js diff --git a/.gitignore b/.gitignore index 8aa7caa..c5182c4 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ core core.* object_script* *.prl +.qmake.stash #generated sources, translations, docu doc/wob diff --git a/commonlib/commonlib.pri b/commonlib/commonlib.pri index 8b3f2c5..521017d 100644 --- a/commonlib/commonlib.pri +++ b/commonlib/commonlib.pri @@ -1,7 +1,7 @@ #Include PRI for the config library LIBS += -lmagicsmoke-common -INCLUDEPATH += $$PWD/../commonlib $$PWD/../commonlib/crypto $$PWD/../commonlib/widgets $$PWD/../commonlib/misc $$PWD/../commonlib/templates +INCLUDEPATH += $$PWD/../commonlib $$PWD/../commonlib/crypto $$PWD/../commonlib/widgets $$PWD/../commonlib/misc $$PWD/../commonlib/templates $$PWD/../commonlib/stick QT += gui widgets include($$PWD/../iface/iface.pri) diff --git a/commonlib/commonlib.pro b/commonlib/commonlib.pro index a361ba6..dc2379e 100644 --- a/commonlib/commonlib.pro +++ b/commonlib/commonlib.pro @@ -22,12 +22,13 @@ HEADERS += configdialog.h mapplication.h SOURCES += configdialog.cpp mapplication.cpp INCLUDEPATH += . DEPENDPATH += $$INCLUDEPATH -RESOURCES += icon.qrc +RESOURCES += files.qrc include(crypto/crypto.pri) include(widgets/widgets.pri) include(misc/misc.pri) include(templates/templates.pri) +include(stick/stick.pri) #make sure exports are ok diff --git a/commonlib/files.qrc b/commonlib/files.qrc new file mode 100644 index 0000000..8239445 --- /dev/null +++ b/commonlib/files.qrc @@ -0,0 +1,11 @@ + + + + + + ../src/images/icon.png + + widgets/eventview.html + + diff --git a/commonlib/icon.qrc b/commonlib/icon.qrc deleted file mode 100644 index 9be79e1..0000000 --- a/commonlib/icon.qrc +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - ../src/images/icon.png - - diff --git a/commonlib/stick/stick.cpp b/commonlib/stick/stick.cpp new file mode 100644 index 0000000..223730a --- /dev/null +++ b/commonlib/stick/stick.cpp @@ -0,0 +1,431 @@ +// +// C++ Implementation: Stick Renderer +// +// Description: Stick Renderer - Twig like renderer for Qt +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#include "stick.h" +#include "stick_p.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include "misc.h" +#include "msinterface.h" + + +MStickRenderer::MStickRenderer() +{ +} + +MStickRenderer::~MStickRenderer() +{ + if(mtemplate){ + delete mtemplate; + mtemplate=nullptr; + } +} + +QVariant MStickRenderer::property ( QString name ) const +{ + return mproperties[name]; +} + +QStringList MStickRenderer::propertyNames() const +{ + return mproperties.keys(); +} + +void MStickRenderer::setProperties ( QMap< QString, QVariant > properties ) +{ + mproperties=properties; +} + +void MStickRenderer::setProperty ( QString name, QVariant value ) +{ + mproperties.insert(name,value); +} + +void MStickRenderer::removeProperty ( QString name ) +{ + mproperties.remove(name); +} + +void MStickRenderer::setTemplate ( QString text ) +{ + if(mtemplate)delete mtemplate; + mtemplate=MStickTokenizer(text).createTokens(); +} + +void MStickRenderer::setTemplateFile ( QString filename ) +{ + QFile fd(filename); + fd.open(QIODevice::ReadOnly); + setTemplate(QString::fromUtf8(fd.readAll())); +} + +void MStickRenderer::initEngine ( ELAM::Engine&engine ) +{ + //add int, float, bool, string + ELAM::Engine::configureReflection(engine); + ELAM::BoolEngine::configureBoolEngine(engine); + ELAM::BoolEngine::configureLogicEngine(engine); + ELAM::IntEngine::configureIntEngine(engine); + ELAM::FloatEngine::configureFloatEngine(engine); + ELAM::StringEngine::configureStringEngine(engine); + + //add pipe and other properties + engine.setPipeOperator("|"); + engine.characterClasses().setDotChar('.'); + engine.setNamedOperatorsAllowed(true); + + //add MSmoke functions + //datetime + engine.setFunction("asDate",[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()!=1||!args[0].canConvert()) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 int argument"); + return unix2date(args[0].value()); + }); + engine.setFunction("asDateTime",[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()!=1||!args[0].canConvert()) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 int argument"); + return unix2dateTime(args[0].value()); + }); + //money + engine.setFunction("asMoney",[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()!=1||!args[0].canConvert()) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 int argument"); + return cent2str(args[0].value()); + }); + //html + auto html=[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()!=1||!args[0].canConvert()) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 string argument"); + return htmlize(args[0].value()); + }; + engine.setFunction("html",html); + engine.setFunction("escape",html); + engine.setFunction("e",html); + engine.setFunction("xml",[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()!=1||!args[0].canConvert()) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 string argument"); + return xmlize(args[0].value()); + }); + engine.setFunction("xml",[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()!=1||!args[0].canConvert()) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 string argument"); + return args[0]; + }); + //Access Rights + engine.setFunction("checkflags",[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()!=1) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 string (list) argument"); + if(args[0].canConvert()) + return req->checkFlags(args[0].toStringList()); + else if(args[0].canConvert()) + return req->checkFlags(args[0].toString().split(' ',QString::SkipEmptyParts)); + else + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 string (list) argument"); + }); + //string functions + engine.setFunction("startsWith",[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()!=2) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 2 string arguments"); + return args[0].toString().startsWith(args[1].toString()); + }); + engine.setFunction("substr",[](const QList&args,ELAM::Engine&)->QVariant{ + if(args.size()<2&&args.size()>3) + return ELAM::Exception(ELAM::Exception::ArgumentListError,"expecting 1 string and 1-2 int arguments: substr(string,start,count)"); + if(args.size()==2) + return args[0].toString().mid(args[1].toInt()); + else + return args[0].toString().mid(args[1].toInt(),args[2].toInt()); + }); +} + +QString MStickRenderer::render() +{ + if(!mtemplate)return QString(); + //init expression engine + ELAM::Engine engine; + initEngine(engine); + //add properties as constants + for(QString prop:mproperties.keys()) + engine.setConstant(prop,mproperties[prop]); + //render + return mtemplate->render(*this,engine); +} + +static inline QString toError(QString text) +{ + return QString("

"+htmlize(text)+"

"); +} + +QString MStickToken::render(MStickRenderer&renderer,ELAM::Engine&engine) +{ + if(hasError()){ + return toError("Parser Error: "+merror); + } + switch(mtype){ + case Type::Text:{ + return mcontent; + } + case Type::CompoundToken:{ + QString r; + for(MStickToken&t:msubtokens) + r+=t.render(renderer,engine); + return r; + } + case Type::ForLoop:{ + if(msubtokens.size()<1) + return toError("Empty For-Loop"); + //resolve list expression + QVariant loop=engine.evaluate(mcontent); + //sanity check on type + if(loop.isNull()) + return toError("Void Loop Expression"); + if(loop.canConvert()) + return toError("Error in Loop Expression: "+loop.toString()+"; "+mcontent); + //convert to list + QVariantList looplist; + if(loop.canConvert())looplist=loop.toList(); + else looplist.append(loop); +// qDebug()<<"Loop has"<1) //optional loop-else + return msubtokens[1].render(renderer,engine); + //done + return res; + } + case Type::IfElse:{ + if(msubtokens.size()<1) + return toError("Empty If-Clause"); + //calculate + QVariant res=engine.evaluate(mcontent); + if(res.canConvert()) + return toError("Error in If-Expression: "+res.toString()+"; "+mcontent); + if(!res.canConvert()) + return toError("If-Expression must be boolean: "+mcontent); + //execute + if(res.toBool()) + return msubtokens[0].render(renderer,engine); + else + if(msubtokens.size()>1) + return msubtokens[1].render(renderer,engine); + else + return QString(); + } + case Type::PrintExpression:{ + QVariant res=engine.evaluate(mcontent); + return res.canConvert()?toError("Calculation Error: "+res.toString()+" in "+mcontent):res.toString(); + } + case Type::CalcExpression:{ + QVariant res=engine.evaluate(mcontent); + return res.canConvert()?toError("Calculation Error: "+res.toString()+" in "+mcontent):QString(); + } + default: + return QString(); + }; +} + +MStickTokenizer::MStickTokenizer(QString text) +{ + int par=0; + QString s;QChar quote='\0';bool bslash=false; + for(QChar c:text){ + if(par==0){//normal text - no special handling whats'o'ever + //start of special token? + if(c=='{'){ + if(!s.isEmpty()){mtokens<0)t.msubtokens.append(MStickToken(copy)); + return new MStickToken(t); +} + +MStickToken::MStickToken(QStringList&tokens) +{ + //get content + if(tokens.size()==0)return; + mcontent=tokens.takeFirst(); + //classify + if(mcontent.startsWith("{{")){ + mtype=Type::PrintExpression; + if(mcontent.endsWith("}}")) + mcontent=mcontent.mid(2,mcontent.size()-4).trimmed(); + else + merror="Invalid Expression in "+mcontent; + }else if(mcontent.startsWith("{#")){ + mtype=Type::Comment; + if(!mcontent.endsWith("#}")) + merror="Invalid comment in "+mcontent; + }else if(mcontent.startsWith("{%")){ + if(!mcontent.endsWith("%}")){ + mtype=Type::Comment; + merror="Invalid Command Expression in "+mcontent; + return; + } + mcontent=mcontent.mid(2,mcontent.size()-4).trimmed(); + parseCommand(tokens); + }else if(mcontent.startsWith("{")){ + mtype=Type::Comment; + merror="Invalid use of braces in "+mcontent; + }else{ + mtype=Type::Text; + } +} + +void MStickToken::parseCommand(QStringList&tokens) +{ + QStringList expr=mcontent.split(' ',QString::SkipEmptyParts); + if(expr.isEmpty()){ + mtype=Type::Comment; + merror="Empty command"; + return; + } + if(expr[0]=="set"){ + mtype=Type::CalcExpression; + mcontent=mcontent.mid(3).trimmed(); + return; + } + if(expr[0]=="for"){ + if(expr.size()<4){ + mtype=Type::Comment; + merror="Incomplete For Loop"; + return; + } + //syntax: {% for varname in expression... %} + mextra=expr[1]; + if(expr[2]!="in"){ + mtype=Type::Comment; + merror="Syntax error in For Loop, expecting 'for varname in expression...' in "+mcontent; + return; + } + mcontent=mcontent.mid(mcontent.indexOf(" in ")+4).trimmed(); + mtype=Type::ForLoop; + //look for else and endfor, coll + MStickToken sub; + while(true){ + if(tokens.isEmpty()){ + qDebug()<<"premature end of loop in "+mcontent; + msubtokens.append(sub); + return; + } + MStickToken detail(tokens); + if(detail.mtype==Type::Else){ + if(msubtokens.size()>0){ + mtype=Type::Comment; + merror="Syntax Error: Double Else in For Loop detected."; + return; + } + msubtokens.append(sub); + sub=MStickToken(); + }else if(detail.mtype==Type::EndFor){ + msubtokens.append(sub); + return; + }else + sub.msubtokens.append(detail); + } + //unreachable! + qDebug()<<"Reached unreachable code in MStickToken::parseCommand!"; + return; + } + if(expr[0]=="if"){ + //syntax if expr... + mcontent=mcontent.mid(2).trimmed(); + mtype=Type::IfElse; + //look for else and endif + MStickToken sub; + while(true){ + if(tokens.isEmpty()){ + qDebug()<<"premature end of conditional in "+mcontent; + msubtokens.append(sub); + return; + } + MStickToken detail(tokens); + if(detail.mtype==Type::Else){ + if(msubtokens.size()>0){ + mtype=Type::Comment; + merror="Syntax Error: Double Else in Conditional detected."; + return; + } + msubtokens.append(sub); + sub=MStickToken(); + }else if(detail.mtype==Type::EndIf){ + msubtokens.append(sub); + return; + }else + sub.msubtokens.append(detail); + } + //unreachable! + qDebug()<<"Reached unreachable code in MStickToken::parseCommand!"; + return; + } + if(expr[0]=="else"){ + mtype=Type::Else; + return; + } + if(expr[0]=="endif"){ + mtype=Type::EndIf; + return; + } + if(expr[0]=="endfor"){ + mtype=Type::EndFor; + return; + } + //unknown command + mtype=Type::Comment; + merror=QString("Unknown Command '%1' encountered, expecting one of set, if, for.").arg(expr[0]); +} diff --git a/commonlib/stick/stick.h b/commonlib/stick/stick.h new file mode 100644 index 0000000..3215751 --- /dev/null +++ b/commonlib/stick/stick.h @@ -0,0 +1,51 @@ +// +// C++ Interface: Stick Renderer +// +// Description: Stick Renderer for Qt, implements a twig-like syntax +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_STICK_H +#define MAGICSMOKE_STICK_H + +#include +#include +#include +#include + +#include "commonexport.h" + +class MStickToken; +namespace ELAM {class Engine;} + +///A Twig-like renderer for HTML pages. +class MAGICSMOKE_COMMON_EXPORT MStickRenderer +{ +public: + MStickRenderer(); + virtual ~MStickRenderer(); + + virtual void setTemplateFile(QString filename); + virtual void setTemplate(QString text); + + virtual void setProperty(QString name,QVariant value); + virtual void setProperties(QMapproperties); + virtual void removeProperty(QString name); + + virtual QVariant property(QString name)const; + virtual QStringList propertyNames()const; + + virtual QString render(); + +private: + QMapmproperties; + MStickToken*mtemplate=nullptr; + void initEngine(ELAM::Engine&); +}; + +#endif diff --git a/commonlib/stick/stick.pri b/commonlib/stick/stick.pri new file mode 100644 index 0000000..946b354 --- /dev/null +++ b/commonlib/stick/stick.pri @@ -0,0 +1,7 @@ +HEADERS += \ + $$PWD/stick.h $$PWD/stick_p.h + +SOURCES += \ + $$PWD/stick.cpp + +INCLUDEPATH += $$PWD diff --git a/commonlib/stick/stick_p.h b/commonlib/stick/stick_p.h new file mode 100644 index 0000000..a489f0a --- /dev/null +++ b/commonlib/stick/stick_p.h @@ -0,0 +1,70 @@ +// +// C++ Interface: Stick Renderer Private +// +// Description: Stick Renderer for Qt, implements a twig-like syntax +// +// +// Author: Konrad Rosenbaum , (C) 2016 +// +// Copyright: See README/COPYING.GPL files that come with this distribution +// +// + +#ifndef MAGICSMOKE_STICK_PH +#define MAGICSMOKE_STICK_PH + +#include +#include +#include +#include + +class MStickRenderer; +namespace ELAM {class Engine;} + +class MStickToken +{ +public: +// MStickToken(QString); + MStickToken()=default; + MStickToken(const MStickToken&)=default; + MStickToken(MStickToken&&)=default; + + MStickToken& operator=(const MStickToken&)=default; + MStickToken& operator=(MStickToken&&)=default; + + QString render(MStickRenderer&,ELAM::Engine&); + + bool hasError()const{return !merror.isEmpty();} + + enum class Type{ + CompoundToken, + ForLoop, + PrintExpression, + CalcExpression, + IfElse, + Else, + Comment, + Text, + EndIf, + EndFor + }; +private: + friend class MStickTokenizer; + MStickToken(QStringList&); + void parseCommand(QStringList&); + + Type mtype=Type::CompoundToken; + QListmsubtokens; + QString mcontent,mextra,merror; +}; + +class MStickTokenizer +{ +public: + MStickTokenizer(QString); + MStickToken* createTokens(); +private: + QStringList mtokens; +}; + +#endif diff --git a/commonlib/templates/odtrender.cpp b/commonlib/templates/odtrender.cpp index 18e8ba8..fcd5ee8 100644 --- a/commonlib/templates/odtrender.cpp +++ b/commonlib/templates/odtrender.cpp @@ -375,9 +375,15 @@ QString MOdtRendererPrivate::renderString(QString line) if(isvar){ //end of var? if(c=='@'){ - if(vname.size()>0) - ret+=calc->evaluate(vname).toString(); - else + if(vname.size()>0){ + QVariant v=calc->evaluate(vname); + qDebug()<<"!!!!!!!! Calculation"<()){ + Exception e=v.value(); + qDebug()<<" ?????? Exception detail: at"<, (C) 2007-2013 +// Author: Konrad Rosenbaum , (C) 2016 // // Copyright: See README/COPYING.GPL files that come with this distribution // @@ -13,6 +13,8 @@ #include "eventview.h" #include "misc.h" #include "msinterface.h" +#include "templates.h" +#include "stick.h" #include #include @@ -118,51 +120,11 @@ void MEventView::setEvent ( MOEvent event ) void MEventView::renderEvent() { - //generate HTML - QString detail="

"+htmlize(mCurrentEvent.title())+"

\n"; - detail+=tr("Artist: %1").arg(htmlize(mCurrentEvent.artist().value().name()))+"

\n"; - detail+=tr("Starttime: %1").arg(htmlize(mCurrentEvent.startTimeString()))+"
\n"; - detail+=tr("Endtime: %1").arg(htmlize(mCurrentEvent.endTimeString()))+"

\n"; - detail+=tr("Room: %1").arg(htmlize(mCurrentEvent.room()))+"
\n"; - detail+=tr("Seats: %1 max. (%2 sold out; %3 reserved; %4 free)").arg(mCurrentEvent.capacity()).arg(mCurrentEvent.amountSold()).arg(mCurrentEvent.amountReserved()).arg(mCurrentEvent.amountFree())+"

\n"; - - const QString bgsold=tr("

Sold Out!
","Colored display for sold out tickets"); - const QString bgavail=tr("
","Colored display for ordering tickets"); - const QString bghide=tr("
Unable to sell.
","Colored display for tickets unavailable to this user"); - - const bool showevent=req->checkFlags(mCurrentEvent.flags()); - if(showevent) - detail+=mCurrentEvent.amountFree()>0?bgavail.arg(QString("order:?ev=%1").arg(mCurrentEvent.id())):bgsold; - else - detail+=bghide; - detail+="

"+tr("Prices")+"

\n"; - detail+="" - "\n"; - QListprices=mCurrentEvent.price(); - qSort(prices.begin(),prices.end(),[](const MOEventPrice&p1,const MOEventPrice&p2){return p1.prio()checkFlags(ctg.flags())) - detail+=""; - } - detail+="
"+tr("Category")+""+tr("Price")+""+tr("Available")+""+tr("Max. Seats")+""+tr("Order")+"
"+ - (avail>0? - bgavail.arg(QString("order:?ev=%1&pr=%2").arg(mCurrentEvent.id()).arg(ctg.pricecategoryid())) - :bgsold); - else - detail+=""+bghide; - detail+="

\n"; - - detail+="

"+tr("Description")+"

\n"+mCurrentEvent.description()+"

\n"; - detail+="

"+tr("Comment")+"

\n"; - QString comment=mCurrentEvent.comment(); - if(!comment.trimmed().startsWith(""))comment=htmlize(comment); - detail+=comment; - //set value + MStickRenderer renderer; + renderer.setTemplate(mPattern); +// renderer.setTemplateFile(qApp->applicationDirPath()+"/../commonlib/widgets/eventview.html"); + renderer.setProperty("event",QVariant::fromValue(mCurrentEvent)); + QString detail=renderer.render(); setHtml(detail); } @@ -217,15 +179,14 @@ void MEventView::setPattern ( QString p ) void MEventView::resetPattern() { - mPattern=tr( - "

{event.name|html}

\n" - "Artist: {event.artist|html}

\n" - "Starttime: {event.startTimeString}
\n" - "Endtime: {event.endTimeString}

\n" - "Room: {event.room|html}
\n" - "Seats: {event.capacity} max. ({event.amountSold} sold out; {event.amountReserved} reserved; {event.amountFree} free)

\n" - "{% if(event.haveAccess) %}\n" - - "{% endif %}" - ); + MTemplate tmp=req->templateStore()->getTemplate("eventview",true); + QString fname; + if(!tmp.isValid()||!tmp.isHtml()){ + qDebug()<<"Unable to find valid eventview template"; + fname=":/eventview-pattern.html"; + }else + fname=tmp.cacheFileName(); + QFile fd(fname); + fd.open(QIODevice::ReadOnly); + mPattern=QString::fromUtf8(fd.readAll()); } diff --git a/commonlib/widgets/eventview.html b/commonlib/widgets/eventview.html new file mode 100644 index 0000000..3813535 --- /dev/null +++ b/commonlib/widgets/eventview.html @@ -0,0 +1,48 @@ +

{{event.title | html}}

+ +Artist: {{event.artist.name|html}}

+Starttime: {{event.start|asDateTime}}
+Endtime: {{event.end|asDateTime}}

+ +Room: {{event.room|html}}
+Seats: {{event.capacity}} max.; ({{event.amountSold}} sold out; {{event.amountReserved}} reserved; {{event.amountFree}} free)

+ +{% if event.flags|checkflags %} + +{% if int(event.amountFree)>0 %} +order tickets

+{% endif %} + +

Prices

+ + + + +{% for price in event.priceFiltered %} + + + + + +{% endfor %} +
CategoryPriceAvailableMax. SeatsOrder
{{price.pricecategory.name}}{{price.price|asMoney}} + {% set avail=int(price.maxavailable)-int(price.amountticketsblock) %}{{avail}}{{price.maxavailable}}{% if checkflags(price.flags) && avail>0 %} + order + {% else %} + unavailable + {% endif %}

+ +{% endif %} + + +

Description

+ +{{event.description}} + +

Comment

+ +{% if event.comment|startsWith("") %} +{{event.comment}} +{% else %} +{{event.comment|html}} +{% endif %} diff --git a/iface/libs.pri b/iface/libs.pri index 1cd0c66..5ad6c21 100644 --- a/iface/libs.pri +++ b/iface/libs.pri @@ -15,4 +15,4 @@ include($$PWD/../taurus/elam.pri) include($$PWD/../taurus/chester.pri) #make sure the correct Qt DLLs are used -QT += xml network script +QT += xml network diff --git a/iface/misc/formula.cpp b/iface/misc/formula.cpp index 98fa79c..4d13dad 100644 --- a/iface/misc/formula.cpp +++ b/iface/misc/formula.cpp @@ -141,6 +141,7 @@ MElamEngine::MElamEngine(QObject* parent): Engine(parent) setFunction("unix2date",unix2DateFunc); setFunction("unix2time",unix2TimeFunc); setFunction("unix2datetime",unix2DateTimeFunc); + setFunction("unix2dateTime",unix2DateTimeFunc); //legacy functions for ODF renderer setFunction("cent2str",[](const QList&args,Engine&)->QVariant{ if(args.size()!=1) diff --git a/iface/smoke-ifc_de.ts b/iface/smoke-ifc_de.ts index a0afb38..040131d 100644 --- a/iface/smoke-ifc_de.ts +++ b/iface/smoke-ifc_de.ts @@ -1318,7 +1318,7 @@ MOVoucher - + unlimited unbegrenzt @@ -1404,7 +1404,7 @@ MTemplateStore - + Retrieving templates from server. Hole Vorlagen vom Server. @@ -1412,242 +1412,242 @@ WobTransaction - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XML result parser error: empty response. XML Fehler: leere Antwort. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XML result parser error line %1 col %2: %3 XML Fehler in Antwort Zeile %1 Spalte %2: %3 diff --git a/iface/smoke-ifc_en.ts b/iface/smoke-ifc_en.ts index eca85c3..761cbbd 100644 --- a/iface/smoke-ifc_en.ts +++ b/iface/smoke-ifc_en.ts @@ -1289,7 +1289,7 @@ MOVoucher - + unlimited @@ -1375,7 +1375,7 @@ MTemplateStore - + Retrieving templates from server. @@ -1513,242 +1513,242 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XML result parser error: empty response. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XML result parser error line %1 col %2: %3 diff --git a/iface/templates/templates.cpp b/iface/templates/templates.cpp index e3f7773..fef5acd 100644 --- a/iface/templates/templates.cpp +++ b/iface/templates/templates.cpp @@ -60,7 +60,7 @@ MTemplateStore::MTemplateStore(QString p) profileid=p; } -MTemplate MTemplateStore::getTemplate(QString f) +MTemplate MTemplateStore::getTemplate(QString f,bool useFirst) { //syntax check f=f.toLower(); @@ -86,7 +86,8 @@ MTemplate MTemplateStore::getTemplate(QString f) } //check dir size if(tdir.size()==0)return MTemplate(); - if(tdir.size()==1)return MTemplate(dname+"/"+tdir[0], set.value(tdir[0]+"/checksum").toString(), set.value(tdir[0]+"/description").toString(), set.value(tdir[0]+"/flags").toString()); + if(tdir.size()==1 || useFirst) + return MTemplate(dname+"/"+tdir[0], set.value(tdir[0]+"/checksum").toString(), set.value(tdir[0]+"/description").toString(), set.value(tdir[0]+"/flags").toString()); //hmm, more than one choice QListtemplst; for(const QString&td:tdir) @@ -366,8 +367,10 @@ QString MTemplate::targetExtension()const } bool MTemplate::isOdf()const{return (type()&OdfTemplateMask)!=0;} - bool MTemplate::isLabel()const{return type()==LabelTemplate;} +bool MTemplate::isZip() const{return type()==ZipTemplate;} +bool MTemplate::isHtml() const{return type()==HtmlTemplate;} + MTemplate::Type MTemplate::type()const { QString x=extension(); @@ -381,6 +384,8 @@ MTemplate::Type MTemplate::type()const if(x=="xtt")return LabelTemplate; //script? if(x=="zip")return ZipTemplate; + //HTML? + if(x=="html")return HtmlTemplate; //hmm, unknown one return UnknownTemplate; } @@ -393,7 +398,7 @@ static QStringList tempBaseNames; QStringList MTemplate::legalBaseNames() { if(tempBaseNames.size()==0){ - tempBaseNames<<"ticket"<<"voucher"<<"bill"<<"eventsummary"<<"scripts"; + tempBaseNames<<"ticket"<<"voucher"<<"bill"<<"eventsummary"<<"scripts"<<"eventview"; } return tempBaseNames; } @@ -407,17 +412,24 @@ MTemplate::Types MTemplate::legalTypes(QString bn) return OdfTemplateMask; if(bn=="scripts") return ZipTemplate; + if(bn=="eventview") + return HtmlTemplate; return UnknownTemplate; } //static QStringList MTemplate::legalSuffixes(QString bn) { - if(bn=="ticket" || bn=="voucher") - return QStringList()<<"xtt"; - if(bn=="bill" || bn=="eventsummary") - return QStringList()<<"odtt"<<"odst"<<"odpt"<<"odgt"<<"odbt"; - if(bn=="scripts") - return QStringList()<<"zip"; - return QStringList(); + switch(legalTypes(bn)){ + case LabelTemplate: + return QStringList()<<"xtt"; + case OdfTemplateMask: + return QStringList()<<"odtt"<<"odst"<<"odpt"<<"odgt"<<"odbt"; + case ZipTemplate: + return QStringList()<<"zip"; + case HtmlTemplate: + return QStringList()<<"html"; + default: + return QStringList(); + } } diff --git a/iface/templates/templates.h b/iface/templates/templates.h index b5b1396..b9c0a7b 100644 --- a/iface/templates/templates.h +++ b/iface/templates/templates.h @@ -75,6 +75,12 @@ class MSIFACE_EXPORT MTemplate /**returns whether this is a label template*/ bool isLabel()const; + + ///returns whether this is a ZipTemplate + bool isZip()const; + + ///returns whether this is a HTML template + bool isHtml()const; ///returns the flags of this template QString flags()const{return m_flags;} @@ -98,7 +104,9 @@ class MSIFACE_EXPORT MTemplate /**Label template*/ LabelTemplate=0x100, /**Script-Zip template*/ - ZipTemplate=0x200 + ZipTemplate=0x200, + ///HTML patterns + HtmlTemplate=0x400 }; Q_DECLARE_FLAGS(Types,Type) @@ -164,15 +172,17 @@ class MSIFACE_EXPORT MTemplateStore private: /**unused, just here to remove it from accessability*/ - MTemplateStore(){} + MTemplateStore()=delete; /**helper for updateTemplates: retrieves a single file from the server*/ bool retrieveFile(QString,QString); public: /**returns a specific template by its base name, opens a template choice dialog if necessary - \param base the base name of the template to retrieve (eg. "ticket" or "voucher")*/ - MTemplate getTemplate(QString base); + \param base the base name of the template to retrieve (eg. "ticket" or "voucher") + \param useFirst if true: use the first match regardless of whether there are more candidates + */ + MTemplate getTemplate(QString base,bool useFirst=false); /**returns a specific template by its full name, opens a template choice dialog if necessary \param full the base name of the template to retrieve (eg. "ticket.xtt,1")*/ MTemplate getTemplateByFile(QString full); diff --git a/iface/wext/address.cpp b/iface/wext/address.cpp index b707748..66dd202 100644 --- a/iface/wext/address.cpp +++ b/iface/wext/address.cpp @@ -13,14 +13,16 @@ #include "MOAddress" #include -#include +#include -WOSCRIPT_IMP(MOAddress) static int moaid= qRegisterMetaType()+ qRegisterMetaType >()+ qRegisterMetaType >(); +static bool mocv= + QMetaType::registerConverter,MOAddress>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r< #include "MTGetCustomer" +#include static int mymeta= qRegisterMetaType()+ qRegisterMetaType >()+ qRegisterMetaType >(); +static bool mocv= + QMetaType::registerConverter,MOCustomer>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r< +#include static int mymeta= qRegisterMetaType()+ qRegisterMetaType >()+ qRegisterMetaType >(); -WOSCRIPT_IMP(MOCustomerInfo) +static bool mocv= + QMetaType::registerConverter,MOCustomerInfo>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r< #include #include -#include #include "msinterface.h" #include "MTGetEvent" #include "misc.h" +#include static int mymeta= qRegisterMetaType()+ qRegisterMetaType >()+ qRegisterMetaType >(); -WOSCRIPT_IMP(MOEvent) +static bool mocv= + QMetaType::registerConverter,MOEvent>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r< MOEvent::priceFiltered() const { + //get prices QList ep=price(); QList ret; + //filter for access MSInterface *ifc=MSInterface::instance(); - if(ifc==0)return ep; - foreach(MOEventPrice p,ep){ + if(ifc!=0) + for(MOEventPrice p:ep){ if(ifc->checkFlags(p.flags())) ret< eventid READ eventid) + Q_PROPERTY(QString startTimeString READ startTimeString) + Q_PROPERTY(QString startDateString READ startDateString) + Q_PROPERTY(QString endTimeString READ endTimeString) + Q_PROPERTY(QString priceString READ priceString) + Q_PROPERTY(QRegExp priceRegExp READ priceRegExp) + Q_PROPERTY(bool isValid READ isValid) + Q_PROPERTY(QList priceFiltered READ priceFiltered) public: /**get event directly from server*/ MOEvent(qint64); @@ -40,7 +47,6 @@ class MSIFACE_EXPORT MOEvent:public MOEventAbstract QString startDateString()const; /**returns the end time of the event as localized string*/ QString endTimeString()const; - /**returns the room of the event, the room must be one out of the list of valid rooms*/ /**returns the price as a localized string*/ QString priceString()const; diff --git a/iface/wext/order.cpp b/iface/wext/order.cpp index 424bbbe..7075407 100644 --- a/iface/wext/order.cpp +++ b/iface/wext/order.cpp @@ -17,7 +17,7 @@ #include "MTGetOrder" #include "msinterface.h" -#include +#include static int mymeta= qRegisterMetaType()+ @@ -29,6 +29,13 @@ static int mymeta= qRegisterMetaType()+ qRegisterMetaType >()+ qRegisterMetaType >(); +static bool mocv= + QMetaType::registerConverter,MOOrder>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<,MOOrderInfo>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<,MORole>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<) Q_DECLARE_METATYPE(Nullable) -#endif \ No newline at end of file +#endif diff --git a/iface/wext/ticket.cpp b/iface/wext/ticket.cpp index 0683f47..99773d0 100644 --- a/iface/wext/ticket.cpp +++ b/iface/wext/ticket.cpp @@ -13,8 +13,8 @@ #include "MOTicket" #include "MOVoucher" #include "msinterface.h" -#include #include "MTGetEvent" +#include static int mymeta= qRegisterMetaType()+ @@ -23,6 +23,11 @@ static int mymeta= qRegisterMetaType()+ qRegisterMetaType >()+ qRegisterMetaType >(); +static bool mocv= + QMetaType::registerConverter,MOTicket>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r<,MOVoucher>([](const Nullable&n){return n.value();})| + QMetaType::registerConverter,QVariantList>([](const QList&n){QVariantList r;for(auto v:n)r< #include -static bool hasMetaValue(QObject*obj,QString n) +template +static bool hasMetaValue(T*obj,QString n) { - const QMetaObject*mobj=obj->metaObject(); + Q_UNUSED(obj); + const QMetaObject mobj=T::staticMetaObject; //look for property - int id=mobj->indexOfProperty(n.toLatin1().data()); + int id=mobj.indexOfProperty(n.toLatin1().data()); if(id>=0)return true; //look for method - id=mobj->indexOfMethod(n.toLatin1().data()); + id=mobj.indexOfMethod(n.toLatin1().data()); if(id<0)return false; - QMetaMethod mm=mobj->method(id); + QMetaMethod mm=mobj.method(id); if(mm.parameterNames().size()!=0)return false; if(QString(mm.typeName()).isEmpty())return false; return true; } -static QVariant getMetaValue(QObject*obj,QString n) +template +static QVariant getMetaValue(T*obj,QString n) { - const QMetaObject*mobj=obj->metaObject(); + const QMetaObject mobj=T::staticMetaObject; //look for property - int id=mobj->indexOfProperty(n.toLatin1().data()); - if(id>=0)return mobj->property(id).read(obj); + int id=mobj.indexOfProperty(n.toLatin1().data()); + if(id>=0)return mobj.property(id).readOnGadget(obj); //look for method - id=mobj->indexOfMethod(n.toLatin1().data()); + id=mobj.indexOfMethod(n.toLatin1().data()); if(id<0)return QVariant(); - QMetaMethod mm=mobj->method(id); + QMetaMethod mm=mobj.method(id); if(mm.parameterNames().size()!=0)return QVariant(); if(QString(mm.typeName()).isEmpty())return QVariant(); //try to invoke int dataid=QMetaType::type(mm.typeName()); void *data=QMetaType::create(dataid); QVariant ret; - if(mm.invoke(obj, Qt::DirectConnection, QGenericReturnArgument(mm.typeName(),data))) + if(mm.invokeOnGadget(obj, QGenericReturnArgument(mm.typeName(),data))) ret=QVariant(dataid,data); QMetaType::destroy(dataid,data); return ret; diff --git a/src/dialogs/wizard.cpp b/src/dialogs/wizard.cpp deleted file mode 100644 index daf11ab..0000000 --- a/src/dialogs/wizard.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// -// C++ Implementation: order wizard -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "wizard.h" -#include "overview.h" -#include "msinterface.h" -#include "jsengine.h" - -#include -#include -#include -#include -#include - -MWizard::MWizard(MOverview* parent, Qt::WindowFlags f) - :QDialog(parent, f),m_parent(parent) -{ - setWindowTitle(tr("Wizard")); - - m_top=m_bottom=m_left=m_right=0; - - //main layout - QVBoxLayout*vl; - setLayout(m_mainlayout=new QGridLayout); - m_mainlayout->addLayout(m_stack=new QStackedLayout,1,1); - m_mainlayout->setColumnStretch(1,1); - m_mainlayout->setRowStretch(1,1); - QMargins mrg=m_stack->contentsMargins(); - m_mainlayout->setContentsMargins(0,0,0,0); - m_stack->setContentsMargins(mrg); - - //page: start - QWidget*w; - m_startid=m_stack->addWidget(w=new QWidget); - w->setLayout(vl=new QVBoxLayout); - vl->addStretch(1); - vl->addLayout(m_modelayout=new QVBoxLayout); - vl->addStretch(1); - - //mode mapping... - m_modemap=new QSignalMapper(this); - connect(m_modemap,SIGNAL(mapped(int)),this,SLOT(gotoPage(int))); - - //engine - m_jseng=new MScriptEngine(parent); - m_jseng->addObject("wizard",this); - m_jseng->evalFile("wizard.js"); -} - -MWizard::~MWizard() -{ - delete m_jseng; -} - -int MWizard::addMode(QString md) -{ - int r=addPage(); - QPushButton*p; - m_modelayout->addWidget(p=new QPushButton(md)); - m_modemap->setMapping(p,r); - connect(p,SIGNAL(clicked()),m_modemap,SLOT(map())); - return r; -} - -int MWizard::addPage() -{ - return m_stack->addWidget(new QWidget); -} - -void MWizard::gotoStart() -{ - m_stack->setCurrentIndex(m_startid); -} - -void MWizard::gotoPage(int pg) -{ - m_stack->setCurrentIndex(pg); -} - -QPushButton* MWizard::modeButton(int pg) -{ - return qobject_cast(m_modemap->mapping(pg)); -} - -QWidget* MWizard::pageWidget(int pg) -{ - return m_stack->widget(pg); -} - -void MWizard::setBottomWidget(QWidget* w) -{ - if(m_bottom)delete m_bottom; - m_mainlayout->addWidget(m_bottom=w,2,0,1,3); -} - -void MWizard::setTopWidget(QWidget* w) -{ - if(m_top)delete m_top; - m_mainlayout->addWidget(m_top=w,0,0,1,3); -} - -void MWizard::setLeftWidget(QWidget* w) -{ - if(m_left)delete m_left; - m_mainlayout->addWidget(m_left=w,1,0); -} - -void MWizard::setRightWidget(QWidget* w) -{ - if(m_right)delete m_right; - m_mainlayout->addWidget(m_right=w,1,2); -} diff --git a/src/dialogs/wizard.h b/src/dialogs/wizard.h deleted file mode 100644 index 8039f73..0000000 --- a/src/dialogs/wizard.h +++ /dev/null @@ -1,54 +0,0 @@ -// -// C++ Interface: order wizard -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_WIZARD_H -#define MAGICSMOKE_WIZARD_H - -#include - -class QGridLayout; -class QSignalMapper; -class QVBoxLayout; -class QStackedLayout; -class MScriptEngine; -class MOverview; -class MWizard:public QDialog -{ - Q_OBJECT - public: - MWizard(MOverview* parent = 0, Qt::WindowFlags f = 0); - virtual ~MWizard(); - - public slots: - int addPage(); - int addMode(QString); - void gotoStart(); - void gotoPage(int); - QWidget* pageWidget(int); - QPushButton* modeButton(int); - void setTopWidget(QWidget*); - void setBottomWidget(QWidget*); - void setRightWidget(QWidget*); - void setLeftWidget(QWidget*); - - private: - MOverview*m_parent; - MScriptEngine*m_jseng; - QStackedLayout*m_stack; - QVBoxLayout*m_modelayout; - QGridLayout*m_mainlayout; - QSignalMapper*m_modemap; - QWidget*m_top,*m_bottom,*m_left,*m_right; - int m_startid; -}; - -#endif diff --git a/src/libs.pri b/src/libs.pri index 196e9d9..1d7c86c 100644 --- a/src/libs.pri +++ b/src/libs.pri @@ -16,5 +16,5 @@ include($$PWD/../sesscli/sesscli.pri) include($$PWD/../commonlib/commonlib.pri) #make sure the correct Qt DLLs are used -QT += xml network script scripttools +QT += xml network QT += widgets printsupport diff --git a/src/mwin/overview.cpp b/src/mwin/overview.cpp index caf0881..af75956 100644 --- a/src/mwin/overview.cpp +++ b/src/mwin/overview.cpp @@ -16,7 +16,6 @@ #include "passwdchg.h" #include "shipping.h" #include "templatedlg.h" -#include "wizard.h" #include "backupdlg.h" #include "payedit.h" #include "orderauditdlg.h" @@ -35,8 +34,6 @@ #include "barcode-plugin.h" #include "labeldlg.h" -#include "jsengine.h" - #include #include @@ -95,8 +92,6 @@ MOverview::MOverview(QString pk) m->addAction(tr("Change my &Password"),this,SLOT(setMyPassword())) ->setEnabled(req->hasRight(req->RChangeMyPassword)); m->addSeparator(); - m->addAction(tr("Switch to &Wizard..."),this,SLOT(wizardMode())); - m->addSeparator(); m->addAction(tr("&Close Session"),this,SLOT(close())); //menus not connected to any specific tab... m=addMenu(tr("&Actions")); @@ -203,15 +198,6 @@ MOverview::MOverview(QString pk) } //make sure correct menu is displayed tabChanged(-1); - - //run init script - QTimer::singleShot(0,this,SLOT(runStartupScript())); -} - -void MOverview::runStartupScript() -{ - MScriptEngine engine(this); - engine.evalFile("startup.js"); } #define GEOGROUP "magicSmokeClient/MainWindow/state" @@ -558,14 +544,6 @@ void MOverview::displaySettings() osage->setRange(0,99999); osage->setValue(maxageos); - vl->addWidget(gbox=new QGroupBox(tr("Script settings"))); - gbox->setLayout(gl=new QGridLayout); - cl=-1; - QComboBox*udeb; - gl->addWidget(new QLabel(tr("Show script debugger:")),++cl,0); - gl->addWidget(udeb=new QComboBox,cl,1); - udeb->addItems(MScriptEngine::debugModes()); - udeb->setCurrentIndex(MScriptEngine::debugMode()); vl->addSpacing(15);vl->addStretch(1); vl->addLayout(hl=new QHBoxLayout); hl->addStretch(10); @@ -587,7 +565,6 @@ void MOverview::displaySettings() set.setValue("maxorderageevent",maxageoe); set.setValue("maxorderagecust",maxageoc); set.setValue("deforderagesince",maxageos); - MScriptEngine::setDebugMode(udeb->currentIndex()); } void MOverview::changeLang() @@ -690,14 +667,6 @@ void MOverview::editOdfTemplate() oe->show(); } -void MOverview::wizardMode() -{ - MWizard wiz(this); - hide(); - wiz.exec(); - show(); -} - void MOverview::orderAudit() { //get order ID diff --git a/src/mwin/overview.h b/src/mwin/overview.h index 8d4abd7..eae8874 100644 --- a/src/mwin/overview.h +++ b/src/mwin/overview.h @@ -82,9 +82,6 @@ class MOverview:public MTabWin ///language settings void changeLang(); - ///\internal run init scripts - void runStartupScript(); - ///start order audit void orderAudit(); ///ticket audit @@ -129,9 +126,6 @@ class MOverview:public MTabWin void editTemplates(); void editOdfTemplate(); - /**switch to wizard mode*/ - void wizardMode(); - private: friend class MWizard; //the profile associated with this session diff --git a/src/mwin/tabwin.cpp b/src/mwin/tabwin.cpp index 267ba6d..0fffed0 100644 --- a/src/mwin/tabwin.cpp +++ b/src/mwin/tabwin.cpp @@ -16,7 +16,6 @@ #include "passwdchg.h" #include "shipping.h" #include "templatedlg.h" -#include "wizard.h" #include "aclwin.h" #include "carttab.h" @@ -28,8 +27,6 @@ #include "centbox.h" #include "sclock.h" -#include "jsengine.h" - #include #include diff --git a/src/script/init.js b/src/script/init.js deleted file mode 100644 index dae0b12..0000000 --- a/src/script/init.js +++ /dev/null @@ -1,15 +0,0 @@ -//init.js -//this example script is in the public domain - -// This script is executed whenever a script engine starts up. -// Use it to load whatever extensions you often need or to shift things around -// in the environment... - -//initialize environment - -// loads wrappers for the QtCore classes -importExtension("qt.core"); -// loads wrappers for the QtGui classes (depends on qt.core being loaded first) -importExtension("qt.gui"); - -// other relevant extensions are: qt.xml qt.xmlpatterns qt.network diff --git a/src/script/jsengine.cpp b/src/script/jsengine.cpp deleted file mode 100644 index b3a8372..0000000 --- a/src/script/jsengine.cpp +++ /dev/null @@ -1,243 +0,0 @@ -// -// C++ Implementation: JScript Engine for MSmoke -// -// Description: -// -// -// Author: Konrad Rosenbaum , (C) 2010-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#include "jsengine.h" -#include "overview.h" -#include "msinterface.h" -#include "mapplication.h" -#include "templates.h" - -#include -#include -#include -#include -#include -#include -#include - -static QScriptValue importExtension(QScriptContext *context, QScriptEngine *engine) -{ - return engine->importExtension(context->argument(0).toString()); -} - -static QScriptValue evalFile(QScriptContext *context, QScriptEngine *engine_) -{ - MScriptEngine*engine=qobject_cast(engine_); - if(engine==0) - return context->throwError("Oops: Cannot use this engine."); - return engine->evalFile(context->argument(0).toString()); -} - -QStringList MScriptEngine::m_basepath; - -MScriptEngine::MScriptEngine(MOverview* par) - :QScriptEngine(par) -{ - qDebug()<<"creating script engine"<initScriptEngine(this); - //utility functions - globalObject().setProperty("importExtension", newFunction(::importExtension)); - globalObject().setProperty("evalFile", newFunction(::evalFile)); - //initialize script sources - if(m_basepath.size()<1)initScriptPath(); - //debugger anybody? - int dm=debugMode(); - if(dm>0){ - QScriptEngineDebugger* deb=new QScriptEngineDebugger(this); - deb->attachTo(this); - if(dm>1) - deb->action(QScriptEngineDebugger::InterruptAction)->trigger(); - } - //load init script - evalFile("init.js"); -} - -MScriptEngine::~MScriptEngine() -{ - qDebug()<<"deleting script engine"<metaObject())); - name[0]=name[0].toLower(); - gval.setProperty(name, newQObject(object, QScriptEngine::QtOwnership, QScriptEngine::ExcludeDeleteLater)); -} - -QStringList MScriptEngine::debugModes() -{ - //hint: the semantics of those entries must not change, because their indices are used - return QStringList() - <settingsGroup()+"/JSdebugMode",0).toInt(); -} - -void MScriptEngine::setDebugMode(int v) -{ - if(v>=0 && vsettingsGroup()+"/JSdebugMode",v); -} - -static inline bool normalizeFile(QString &fn) -{ - QStringList fnl=fn.replace("\\","/").split("/",QString::SkipEmptyParts); - QRegExp allow("[a-zA-Z0-9\\._]+"); - QStringList fnt; - for(int i=0;i0)h+=" "; - h+=s; - return *this; - } - MScriptEngine_DebugHelper& operator<<(long l) - { - if(h.size()>0)h+=" "; - h+=QString::number(l,16); - return *this; - } - ~MScriptEngine_DebugHelper(){qDebug()<throwError("Unable to normalize file name or illegal path component."); - } - //find file - for(int i=0;ithrowError("Unable to find this script."); -} - -static inline void clearDir(QString dn) -{ - QDir dir(dn); - if(!dir.exists())return; - QFileInfoList ifl=dir.entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot); - for(int i=0;iconfigSettingsGroup()+"/script"); - QMultiMappaths; - if(set.value("allowbuiltin",true).toBool()) - paths.insert(set.value("priobuiltin",10).toInt(),":/scripts"); - if(set.value("allowuser",false).toBool()) - paths.insert(set.value("priouser",0).toInt(), set.value("userpath",MApplication::dataDir()+"/userscripts").toString()); - bool allowserver=set.value("allowserver",false).toBool(); - QString mydir=req->dataDir()+"/scripts"; - if(allowserver) - paths.insert(set.value("prioserver",20).toInt(),mydir); - //sort and append to path - for(int i=0;i<=100;i++) - if(paths.contains(i)) - m_basepath<templateStore(); - if(store==0)return; - QString fn=store->getTemplate("scripts").cacheFileName(); - if(fn=="")return; - QFile fd(fn); - if(!fd.open(QIODevice::ReadOnly))return; - Unzip zip; - if(!zip.open(&fd))return; - //clear old directory - clearDir(mydir);QDir().mkpath(mydir);mydir+="/"; - if(!zip.firstFile())return; - do{ - //get file name - QString fn; - if((fn=zip.currentFile().fileName()).isEmpty())break; - if(!normalizeFile(fn)){ - qDebug()<<"Warning: cannot normalize script file name"<, (C) 2010-2011 -// -// Copyright: See README/COPYING.GPL files that come with this distribution -// -// - -#ifndef MAGICSMOKE_JSENGINE_H -#define MAGICSMOKE_JSENGINE_H - -#include -#include - -class MOverview; - -/**MagicSmoke Scripting Engine - -This class already wraps all important objects and functions necessary for MagicSmoke in general.*/ -class MScriptEngine:public QScriptEngine -{ - Q_OBJECT - public: - ///construct the engine with pointer to the main window - MScriptEngine(MOverview*); - ///delete engine - virtual ~MScriptEngine(); - - ///add another object and its meta object - void addObject(QString name,QObject*object); - ///execute a specific file, the engine searches for it - QScriptValue evalFile(QString); - - ///returns valid debugger modes - this decides when a debugger opens for a script - static QStringList debugModes(); - ///returns the index of the debug mode that is currently active - static int debugMode(); - ///sets the index of the debug mode - static void setDebugMode(int); - private: - static QStringList m_basepath; - ///helper: init m_basepath - static void initScriptPath(); -}; - -#endif diff --git a/src/script/script.pri b/src/script/script.pri deleted file mode 100644 index d2eddcf..0000000 --- a/src/script/script.pri +++ /dev/null @@ -1,9 +0,0 @@ -SOURCES += \ - script/jsengine.cpp - -HEADERS += \ - script/jsengine.h - -INCLUDEPATH += ./script - -RESOURCES += script/scriptfiles.qrc \ No newline at end of file diff --git a/src/script/scriptfiles.qrc b/src/script/scriptfiles.qrc deleted file mode 100644 index 9b6bf35..0000000 --- a/src/script/scriptfiles.qrc +++ /dev/null @@ -1,10 +0,0 @@ - - - - - init.js - startup.js - wizard.js - - diff --git a/src/script/startup.js b/src/script/startup.js deleted file mode 100644 index 4efa795..0000000 --- a/src/script/startup.js +++ /dev/null @@ -1,9 +0,0 @@ -//startup.js -//this example script is in the pubic domain - -// this startup code is executed as soon as the main window is initialized and visible; -// the engine executing it does not stay open - -// this example code switches to the wizard if the user has the _useWizard flag set -if(wob.interface.hasFlag("_useWizard")) - mainWindow.wizardMode(); diff --git a/src/script/wizard.js b/src/script/wizard.js deleted file mode 100644 index 944fe31..0000000 --- a/src/script/wizard.js +++ /dev/null @@ -1,151 +0,0 @@ -//wizard.js -//this example script is in the public domain -// -// This script is executed when the wizard starts. -// The engine stays active until the wizard is closed, you can use it to schedule -// actions and/or to react to GUI events. - -// The wizard contains a stack of pages that can be used create functionality for the user. -// The start page is controlled by the wizard itself, it contains buttons that start work flows. -// Around this stack there are four areas wher you can put widgets that are permanently visible. - -// The methods are: -// wizard.addMode("text") -> adds a button to the start page and an initial -// page for that work flow, it return the page ID of that initial page -// wizard.addPage() -> adds a page and returns its ID -// wizard.pageWidget(ID) -> returns the QWidget for the given page ID -// wizard.modeButton(ID) -> returns the QPushButton for the given mode, the -// ID supplied to it is the return value of addMode -// wizard.gotoStart() -> switches to the start page -// wizard.gotoPage(ID) -> switches to the given page, ID is the return value -// of addMode or addPage -// wizard.setTopWidget(widget) -> sets the top permanent widget -// wizard.setBottomWidget(widget) -> sets the bottom permanent widget -// wizard.setLeftWidget(widget) -> sets the left permanent widget -// wizard.setRightWidget(widget) -> sets the right permanent widget -// there are more methods: all the slots of QDialog are available - -// The wizard layout looks roughly like this: -// ____________________________________ -// | Wizard Title Bar [x] -// +----------------------------------+ -// | top permanent widget | -// +------+--------------------+------+ -// | left | wizard pages |right | -// | perm.| |perm. | -// |widget| |widget| -// . . . -// | | | | -// +------+--------------------+------+ -// | bottom permanent widget | -// +----------------------------------+ - -////////// -//lower buttons, those are always visible -function createButtons() -{ - var w=new QWidget; - wizard.setBottomWidget(w); - var hl; - var p; - w.setLayout(hl=new QHBoxLayout); - hl.addWidget(p=new QPushButton("Debug"),0,0); - p.clicked.connect(function(){debugger;}); - hl.addStretch(1); - hl.addWidget(p=new QPushButton("Start Over"),0,0); - p.clicked.connect(wizard.gotoStart); - hl.addWidget(p=new QPushButton("Close Wizard"),0,0); - p.clicked.connect(wizard.accept); - hl.addWidget(p=new QPushButton("Exit"),0,0); - p.clicked.connect(wizard.accept); - p.clicked.connect(mainWindow.close); -} -createButtons(); - -////////// -//example ticket sale wizard -function startSale() -{ - //main page - var ispg=wizard.addMode("Sell a Ticket"); - var spg=wizard.pageWidget(ispg); - var vl;var hl;var p; - spg.setLayout(vl=new QVBoxLayout); - vl.addWidget(new QLabel("Hallo Welt!"),1,0); - vl.addLayout(hl=new QHBoxLayout); - hl.addStretch(1); - hl.addWidget(p=new QPushButton("Continue>>"),0,0); - //customer pages - var icpg=wizard.addPage(); - var incpg=wizard.addPage(); - var ikcpg=wizard.addPage(); - p.clicked.connect(function(){wizard.gotoPage(icpg);}); - //customer fork - var cpg=wizard.pageWidget(icpg); - cpg.setLayout(vl=new QVBoxLayout); - vl.addWidget(new QLabel("Has this customer been here before?"),0,0); - vl.addWidget(new QPushButton("Yes, select from list of known customers..."),0,0); - vl.addWidget(new QPushButton("No, create new customer..."),0,0); - vl.addStretch(1); -} -startSale(); - -////////// -//dump built in scripts - -//you used this to dump these scripts.... ;-) -var dumpbtn; -var dumppath; -var dumplog; -function startDump() -{ - var idpg=wizard.addMode("Dump built in scripts"); - var dpg=wizard.pageWidget(idpg); - var vl;var p; - dpg.setLayout(vl=new QVBoxLayout); - vl.addWidget(dumpbtn=new QPushButton("Chose path..."),0,0) - dumpbtn.clicked.connect(dumpSelectPath); - vl.addWidget(dumppath=new QLineEdit,0,0); - vl.addSpacing(20); - vl.addWidget(p=new QPushButton("Start Dump"),0,0); - p.clicked.connect(dumpDump); - vl.addSpacing(20); - vl.addWidget(dumplog=new QTextEdit,0,0); - vl.addStretch(1); -} -function dumpSelectPath() -{ - var dp=QFileDialog.getExistingDirectory(); - if(dp!="")dumppath.setText(dp); -} -function dumpDump(path) -{ - if(!path){ - path=""; - dumplog.setPlainText("Starting dump..."); - } - var dir=new QDir(":/scripts/"+path); - var tdir=new QDir(dumppath.text+"/"+path); - var fls=dir.entryInfoList(QDir.Filters(QDir.AllEntries|QDir.NoDotAndDotDot), QDir.SortFlags(QDir.NoSort)); - dumplog.append("going into "+dir.absolutePath()); - for(var i=0;i